Blame view

SRC/GENERAL_MODULES/convert_case.F90 4.11 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
!
! This file is part of SACAMOS, State of the Art CAble MOdels in Spice. 
! It was developed by the University of Nottingham and the Netherlands Aerospace 
! Centre (NLR) for ESA under contract number 4000112765/14/NL/HK.
! 
! Copyright (C) 2016-2017 University of Nottingham
! 
! SACAMOS is free software: you can redistribute it and/or modify it under the 
! terms of the GNU General Public License as published by the Free Software 
! Foundation, either version 3 of the License, or (at your option) any later 
! version.
! 
! SACAMOS is distributed in the hope that it will be useful, but 
! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
! for more details.
! 
! A copy of the GNU General Public License version 3 can be found in the 
! file GNU_GPL_v3 in the root or at <http://www.gnu.org/licenses/>.
! 
! SACAMOS uses the EISPACK library (in /SRC/EISPACK). EISPACK is subject to 
! the GNU Lesser General Public License. A copy of the GNU Lesser General Public 
! License version can be found in the file GNU_LGPL in the root of EISPACK 
! (/SRC/EISPACK ) or at <http://www.gnu.org/licenses/>.
! 
! The University of Nottingham can be contacted at: ggiemr@nottingham.ac.uk
!
! NAME
!    convert_to_lower_case
!
! DESCRIPTION
!     returns the input string with all characters converted to lower case
!
! HISTORY
!
!     started 10/02/09 CJS
!
! COMMENTS
!     
SUBROUTINE convert_to_lower_case(input_string,input_string_length)

IMPLICIT NONE

! variables passed to subroutine

  integer,intent(IN)                               :: input_string_length
  character(LEN=input_string_length),intent(INOUT) :: input_string
  
! local variables

  character(LEN=input_string_length) ::  output_string   ! local output string
  
  integer :: i                   ! loop variable
  integer :: na,nCA,nz,nCZ,diff  ! character numbers of lower case a, upper case A, lower case z, upper case Z
  integer :: c                   ! character number
  
! START

  na=IACHAR('a')
  nCA=IACHAR('A')
  nz=IACHAR('z')
  nCZ=IACHAR('Z')
  
  diff=na-nCA   ! diff is the difference in character number between lower case and upper case i.e. what has to be added to convert to lower case
  
  do i=1,input_string_length
  
    c=IACHAR(input_string(i:i))
    if ((c.ge.nCA).AND.(c.le.nCZ)) then    ! this is an upper case character which needs conversions
      c=c+diff
      output_string(i:i)=ACHAR(c)
    else
      output_string(i:i)=input_string(i:i) ! this is not an upper case so leave this alone
    end if 
    
  end do

! copy the output string to the input string
  input_string=output_string
  
  RETURN
  
END SUBROUTINE convert_to_lower_case
!
! NAME
!    convert_to_upper_case
!
! DESCRIPTION
!     returns the input string with all characters converted to upper case
!
! HISTORY
!
!     started 26/02/09 CJS
!
! COMMENTS
!     
SUBROUTINE convert_to_upper_case(input_string,input_string_length)

IMPLICIT NONE

! variables passed to subroutine

  integer,intent(IN)                               :: input_string_length
  character(LEN=input_string_length),intent(INOUT) :: input_string
  
! local variables

  character(LEN=input_string_length) ::  output_string   ! local output string
  
  integer :: i                   ! loop variable
  integer :: na,nCA,nz,nCZ,diff  ! character numbers of lower case a, upper case A, lower case z, upper case Z
  integer :: c                   ! character number
  
! START

  na=IACHAR('a')
  nCA=IACHAR('A')
  nz=IACHAR('z')
  nCZ=IACHAR('Z')
  
  diff=nCA-na ! diff is the difference in character number between lower case and upper case i.e. what has to be added to convert to upper case
  
  do i=1,input_string_length
  
    c=IACHAR(input_string(i:i))
    if ((c.ge.na).AND.(c.le.nz)) then      ! this is a lower case character which needs conversions
      c=c+diff
      output_string(i:i)=ACHAR(c)
    else
      output_string(i:i)=input_string(i:i) ! this is not a lower case so leave this alone
    end if
    
  end do
  
! copy the output string to the input string
  input_string=output_string
  
  RETURN
  
END SUBROUTINE convert_to_upper_case