Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
string_mod.F90
Go to the documentation of this file.
1 module string
2  implicit none
3 
4 ! integer, parameter :: * = 132
5 
6 contains
7 
8 !-----------------------------------------------------------------------
9 integer function i1_from_char(s1)
10  implicit none
11  character(*) :: s1
12 
13  character(10) :: n10 = '0123456789'
14 
15  i1_from_char = indx2(n10,10,s1,1)-1
16 
17  return
18 end function i1_from_char
19 
20 !-----------------------------------------------------------------------
21 integer function indx2(s1,l1,s2,l2)
22  implicit none
23  character(*) :: s1,s2
24  integer :: l1, l2
25  integer :: n1, i, i2
26 
27  n1=l1-l2+1
28  indx2=0
29  if (n1 < 1) return
30 
31  do i=1,n1
32  i2=i+l2-1
33  if (s1(i:i2) == s2(1:l2)) then
34  indx2=i
35  return
36  endif
37  enddo
38 
39  return
40 end function indx2
41 
42 !-----------------------------------------------------------------------
43 INTEGER FUNCTION indx1(S1,S2,L2)
44  implicit none
45  CHARACTER(*) :: S1,S2
46  integer :: l2
47  integer :: n1, i, i2
48 
49  n1=len_trim(s1)-l2+1
50  indx1=0
51  IF (n1 < 1) return
52 
53  DO 100 i=1,n1
54  i2=i+l2-1
55  IF (s1(i:i2) == s2(1:l2)) THEN
56  indx1=i
57  return
58  ENDIF
59  100 END DO
60 
61  return
62 END FUNCTION indx1
63 
64 !-----------------------------------------------------------------------
67 INTEGER FUNCTION indx_cut(S1,S2,L2)
68  implicit none
69  CHARACTER(*) :: S1,S2
70  integer :: l2
71 
72  integer :: i1, n1, i, i2, n2
73  i1=indx1(s1,s2,l2)
74 
75  IF (i1 /= 0) THEN
76 
77  n1=len_trim(s1)-l2
78  DO 100 i=i1,n1
79  i2=i+l2
80  ! remove the 1st occurance of S2 from S1.
81  s1(i:i)=s1(i2:i2)
82  100 END DO
83  n2=n1+1
84  DO 200 i=n2,len_trim(s1)
85  s1(i:i)=' '
86  200 END DO
87  ENDIF
88 
89  indx_cut=i1
90  return
91 END FUNCTION indx_cut
92 
93 !-----------------------------------------------------------------------
95 subroutine csplit(s0,s1,s2,l0)
96  implicit none
97  CHARACTER(*) :: S0,S1,S2
98  integer :: l0
99 
100  integer :: i2, i1
101 
102  i2=indx_cut(s1,s2,l0)
103  IF (i2 == 0) return
104 
105  i1=i2-1
106  CALL blank(s0,len(s0))
107  s0(1:i1)=s1(1:i1)
108  CALL lshft(s1,i2)
109 
110  return
111 end subroutine csplit
112 !-----------------------------------------------------------------------
116 subroutine lshft(string,ipt)
117  implicit none
118  CHARACTER(*) :: STRING
119  integer :: ipt
120  integer :: j, ij
121 
122  DO j=1,len(string)-ipt
123  ij=ipt+j-1
124  string(j:j)=string(ij:ij)
125  END DO
126  DO j=len(string)-ipt,len(string)
127  string(j:j)=' '
128  END DO
129  return
130 end subroutine lshft
131 
132 !-----------------------------------------------------------------------
134 subroutine ljust(string)
135  implicit none
136  CHARACTER(*) :: STRING
137  integer :: i, j, ij
138 
139  IF (string(1:1) /= ' ') return
140 
141  DO i=2,len(string)
142 
143  IF (string(i:i) /= ' ') THEN
144  DO j=1,133-i
145  ij=i+j-1
146  string(j:j)=string(ij:ij)
147  END DO
148  DO j=134-i,132
149  string(j:j)=' '
150  END DO
151  return
152  ENDIF
153 
154  END DO
155 
156  return
157 end subroutine ljust
158 
159 !-----------------------------------------------------------------------
161 subroutine capit(lettrs,n)
162  implicit none
163  CHARACTER(*) :: LETTRS
164  integer, optional :: n
165  integer :: i, int, ni
166 
167  if (present(n)) then
168  ni = n
169  else
170  ni = len(lettrs)
171  endif
172 
173  DO i=1,ni
174  int=ichar(lettrs(i:i))
175  IF(int >= 97 .AND. int <= 122) THEN
176  int=int-32
177  lettrs(i:i)=char(int)
178  ENDIF
179  END DO
180  return
181 end subroutine capit
182 
183 !-----------------------------------------------------------------------
188 LOGICAL FUNCTION ifgtrl(VALUE,LINE)
189  use kinds, only : dp
190  implicit none
191  real(DP) :: value
192  CHARACTER(*) :: LINE
193 
194  CHARACTER(len(line)) :: WORK
195  CHARACTER(8) :: FMAT
196  integer :: ifldw
197  real(DP) :: TVAL
198 
199 ! Note that the format Fn.0 is appropriate for fields of type:
200 ! 34 34.0 34.0e+00
201 ! The only difficulty would be with '34' but since we identify
202 ! the field width exactly, there is no problem.
203 
204  ifgtrl= .false.
205  VALUE=0.0
206 
207  work=line
208  CALL ljust(work)
209  ifldw=indx1(work,' ',1)-1
210 
211  IF (ifldw > 0) THEN
212  WRITE(fmat,10) ifldw
213  10 FORMAT('(F',i3.3,'.0)')
214  READ(work,fmat,err=100,end=100) tval
215  VALUE=tval
216  ifgtrl= .true.
217  return
218  ENDIF
219 
220  100 CONTINUE
221  return
222 END FUNCTION ifgtrl
223 
224 !-----------------------------------------------------------------------
229 LOGICAL FUNCTION ifgtil(IVALUE,LINE)
230  use kinds, only : dp
231  implicit none
232  integer :: ivalue
233  CHARACTER(*) :: LINE
234  CHARACTER(len(line)) :: WORK
235  CHARACTER(8) :: FMAT
236 
237  integer :: ifldw
238  real(DP) :: tval
239 
240  ifgtil= .false.
241  ivalue=0
242 
243  work=line
244  CALL ljust(work)
245  ifldw=indx1(work,' ',1)-1
246 
247  IF (ifldw > 0) THEN
248  WRITE(fmat,10) ifldw
249  10 FORMAT('(F',i3.3,'.0)')
250  READ(work,fmat,err=100,end=100) tval
251  ivalue=int(tval)
252  ifgtil= .true.
253  return
254  ENDIF
255 
256  100 CONTINUE
257  return
258 END FUNCTION ifgtil
259 
260 integer function ltrunc(string,l)
261  implicit none
262  integer :: l
263  CHARACTER(L) :: STRING
264  integer :: i, l1
265  CHARACTER(1) :: BLNK=' '
266 
267  DO 100 i=l,1,-1
268  l1=i
269  IF (string(i:i) /= blnk) goto 200
270  100 END DO
271  l1=0
272  200 CONTINUE
273  ltrunc=l1
274  return
275 end function ltrunc
276 
277 !-----------------------------------------------------------------------
278 subroutine cscan(sout,key,nk)
279  implicit none
280  character(*) :: sout,key
281  character(len(sout)) :: tmp_string
282  integer :: i, nk
283 
284  do i=1,100000000
285  call blank(tmp_string,len(sout))
286  read (nk,80,end=100,err=100) tmp_string
287  call chcopy(sout, tmp_string,len(sout))
288  ! write (6,*) tmp_string
289  if (indx1(tmp_string,key,nk) /= 0) return
290  enddo
291  100 continue
292 
293  80 format(a132)
294  return
295 
296 end subroutine cscan
297 !-----------------------------------------------------------------------
298 
299 
300 end module string
integer function i1_from_char(s1)
Definition: string_mod.F90:9
integer function indx1(S1, S2, L2)
Definition: string_mod.F90:43
integer function indx2(s1, l1, s2, l2)
Definition: string_mod.F90:21
subroutine lshft(string, ipt)
shift string from IPT to the left INPUT : "abcde...... test " OUTPUT: "e...... test " if ipt.eq.5
Definition: string_mod.F90:116
integer function indx_cut(S1, S2, L2)
INDX_CUT is returned with the location of S2 in S1 (0 if not found) S1 is returned with 1st occurance...
Definition: string_mod.F90:67
logical function ifgtrl(VALUE, LINE)
Read VALUE from LINE and set IFGTRL to .TRUE. if successful, IFGTRL to .FALSE. otherwise. This complicated function is necessary thanks to the Ardent, which won't allow free formatted reads (*) from internal strings!
Definition: string_mod.F90:188
subroutine capit(lettrs, n)
Capitalizes string of length n.
Definition: string_mod.F90:161
subroutine blank(A, N)
blank a string
Definition: math.F90:38
logical function ifgtil(IVALUE, LINE)
Read IVALUE from LINE and set IFGTIL to .TRUE. if successful, IFGTIL to .FALSE. otherwise. This complicated function is necessary thanks to the Ardent, which won't allow free formatted reads (*) from internal strings!
Definition: string_mod.F90:229
subroutine cscan(sout, key, nk)
Definition: string_mod.F90:278
subroutine csplit(s0, s1, s2, l0)
split string S1 into two parts, delimited by S2.
Definition: string_mod.F90:95
subroutine chcopy(a, b, n)
Definition: math.F90:63
subroutine ljust(string)
left justify string
Definition: string_mod.F90:134
integer function ltrunc(string, l)
Definition: string_mod.F90:260