Millepede-II V04-17-04
mptext.f90
Go to the documentation of this file.
1
2! Code converted using TO_F90 by Alan Miller
3! Date: 2012-03-16 Time: 11:09:16
4
27
29MODULE mptext
30 USE mpdef
31
32 IMPLICIT NONE
33 SAVE
34 INTEGER(mpi) :: keya
35 INTEGER(mpi) :: keyb
36 INTEGER(mpi) :: keyc
37
38END MODULE mptext
39
49
50SUBROUTINE ratext(text,nums,dnum,mnum)
51 USE mptext
52
53 IMPLICIT NONE
54 INTEGER(mpi) :: i
55 INTEGER(mpi) :: ia
56 INTEGER(mpi) :: ib
57 INTEGER(mpi) :: ic
58 INTEGER(mpi) :: ich
59 INTEGER(mpi) :: icl
60 INTEGER(mpi) :: icode
61 INTEGER(mpi) :: j
62 INTEGER(mpi) :: k
63
64 INTEGER(mpi) :: lent
65 INTEGER(mpi) :: num
66
67 CHARACTER (LEN=*), INTENT(IN) :: text
68 INTEGER(mpi), INTENT(OUT) :: nums
69 INTEGER(mpi), INTENT(IN) :: mnum
70 REAL(mpd), INTENT(OUT) :: dnum(mnum)
71
72 INTEGER(mpi) :: last ! last non-blank character
73 INTEGER(mpi), PARAMETER :: ndim=1000
74 INTEGER(mpi), DIMENSION(2,ndim):: icd
75 CHARACTER (LEN=1) :: ch
76 REAL(mpd) :: dic(ndim)
77 REAL(mpd) :: dumber
78 INTEGER(mpi) :: icdt(ndim)
79 SAVE
80 ! ...
81 nums=0
82 last=0
83 keya=0
84 keyb=0
85 keyc=0
86 IF(text(1:1) == '*') RETURN
87 num=ichar('0')
88 lent=0
89 last=0
90 DO i=1,len(text) ! find comment and end
91 IF(lent == 0.AND.(text(i:i) == '!'.OR.text(i:i) == '%')) lent=i
92 IF(text(i:i) /= ' ') last=i
93 END DO
94 IF(lent == 0) lent=last+1
95 icd(1,1)=lent
96
97 j=1
98 icdt(1)=0
99 icl=0
100 DO i=1,lent-1
101 ch =text(i:i)
102 ich=ichar(ch)
103 ic=0
104 IF(ch == '.') ic=1
105 IF(ch == '+') ic=2
106 IF(ch == '-') ic=3
107 IF(ch == 'E') ic=4
108 IF(ch == 'D') ic=4
109 IF(ch == 'e') ic=4
110 IF(ch == 'd') ic=4
111 IF(ic > 0) THEN
112 j=j+1
113 icd(1,j)=i
114 icd(2,j)=i
115 icdt(j)=ic
116 ELSE
117 ic=6
118 IF(ich >= num.AND.ich <= num+9) ic=5 ! digit
119 IF(ic /= icl) THEN
120 j=j+1
121 icd(1,j)=i
122 icdt(j)=ic
123 END IF
124 icd(2,j)=i
125 END IF
126 icl=ic ! previous IC
127 END DO
128 icdt(j+1)=0
129
130 DO i=1,j ! define number
131 IF(icdt(i) == 5) THEN
132 dumber=0.0d0
133 DO k=icd(1,i),icd(2,i)
134 dumber=10.0_mpd*dumber+real(ichar(text(k:k))-num,mpd)
135 END DO
136 dic(i)=dumber
137 END IF
138 END DO
139 icdt(j+1)=0
140
141 DO i=2,j ! get dots
142 IF(icdt(i) == 1) THEN
143 icode=0
144 IF(icdt(i-1) == 5.AND.icd(2,i-1)+1 == icd(1,i)) icode=1
145 IF(icdt(i+1) == 5.AND.icd(1,i+1)-1 == icd(2,i)) icode=icode+2
146 IF(icode == 1) THEN ! 123.
147 icd(2,i-1)=icd(2,i)
148 icdt(i)=0
149 ELSE IF(icode == 2) THEN ! .456
150 dic(i)=10.0d0**(icd(1,i+1)-icd(2,i+1)-1)*dic(i+1)
151 icdt(i)=5
152 icd(2,i)=icd(2,i+1)
153 icdt(i+1)=0
154 ELSE IF(icode == 3) THEN ! 123.456
155 dic(i-1)=dic(i-1)+ 10.0d0**(icd(1,i+1)-icd(2,i+1)-1)*dic(i+1)
156 icd(2,i-1)=icd(2,i+1)
157 icdt(i)=0
158 icdt(i+1)=0
159 END IF
160 END IF
161 END DO
162
163 k=1 ! remove blanks, compress
164 DO i=2,j
165 IF(icdt(i) == 6.AND.text(icd(1,i):icd(2,i)) == ' ') icdt(i)=0
166 IF(icdt(i) /= 0) THEN
167 k=k+1
168 icd(1,k)=icd(1,i)
169 icd(2,k)=icd(2,i)
170 icdt(k)=icdt(i)
171 dic(k)=dic(i)
172 END IF
173 END DO
174 j=k
175
176 DO i=2,j-1
177 IF(icdt(i) == 2.OR.icdt(i) == 3) THEN ! +-
178 IF(icdt(i+1) == 5) THEN
179 icd(1,i+1)=icd(1,i)
180 IF(icdt(i) == 3) dic(i+1)=-dic(i+1)
181 icdt(i)=0
182 END IF
183 END IF
184 END DO
185
186 k=1 ! compress
187 DO i=2,j
188 IF(icdt(i) == 6.AND.text(icd(1,i):icd(2,i)) == ' ') icdt(i)=0
189 IF(icdt(i) /= 0) THEN
190 k=k+1
191 icd(1,k)=icd(1,i)
192 icd(2,k)=icd(2,i)
193 icdt(k)=icdt(i)
194 dic(k)=dic(i)
195 END IF
196 END DO
197 j=k
198
199 DO i=2,j-1
200 IF(icdt(i) == 4) THEN ! E or D
201 IF(icdt(i-1) == 5.AND.icdt(i+1) == 5) THEN
202 icd(2,i-1)=icd(2,i+1)
203 dic(i-1)=dic(i-1)*10.0d0**dic(i+1)
204 icdt(i)=0
205 icdt(i+1)=0
206 END IF
207 END IF
208 END DO
209
210 nums=0 ! compress
211 DO i=1,j
212 IF(icdt(i) == 5) THEN
213 nums=nums+1
214 icd(1,nums)=icd(1,i)
215 icd(2,nums)=icd(2,i)
216 dnum(nums)=dic(i)
217 IF (nums >= mnum) EXIT
218 END IF
219 END DO
220
221 ! range of keyword (and optional text argument)
222 ia=0
223 ib=0
224 ic=0
225 k=0
226 DO i=1,icd(1,1)-1
227 ! (still) leading blanks ?
228 IF(ia == 0) THEN
229 IF(text(i:i) /= ' ') THEN
230 ia=i ! first non blank char
231 ELSE
232 cycle ! skip
233 END IF
234 END IF
235 ! non blank char ?
236 IF(text(i:i) /= ' ') THEN
237 ic=i ! last non blank char
238 ELSE
239 k=i ! new blank
240 END IF
241 IF(k == 0) ib=i ! last non blank char in keyword
242 END DO
243 keya=ia
244 keyb=ib
245 keyc=ic
246END SUBROUTINE ratext
247
254
255SUBROUTINE rltext(text,ia,ib,nab)
256 USE mpdef
257
258 IMPLICIT NONE
259 INTEGER(mpi) :: i
260 INTEGER(mpi) :: lim
261
262 CHARACTER (LEN=*), INTENT(IN) :: text
263 INTEGER(mpi), INTENT(OUT) :: ia
264 INTEGER(mpi), INTENT(OUT) :: ib
265 INTEGER(mpi), INTENT(OUT) :: nab
266
267 SAVE
268 ! ...
269 ia=0
270 ib=0
271 nab=0
272 lim=0
273 DO i=1,len(text)
274 IF(text(i:i) /= ' ') nab=i
275 IF((i == 1.AND.text(1:1) == '*').OR.text(i:i) == '!') THEN
276 IF(lim == 0) lim=i
277 END IF
278 END DO
279 IF(lim == 0) THEN
280 lim=nab
281 ELSE
282 lim=lim-1
283 END IF
284 DO i=1,lim
285 IF(ia == 0.AND.text(i:i) /= ' ') ia=i
286 IF(text(i:i) /= ' ') ib=i
287 END DO
288END SUBROUTINE rltext
289
307
308INTEGER(mpi) FUNCTION matint(pat,text,npat,ntext)
309 USE mpdef
310
311 IMPLICIT NONE
312 INTEGER(mpi) :: i
313 INTEGER(mpi) :: ic
314 INTEGER(mpi) :: ip
315 INTEGER(mpi) :: ipa
316 INTEGER(mpi) :: ipb
317 INTEGER(mpi) :: ita
318 INTEGER(mpi) :: itb
319 INTEGER(mpi) :: j
320 INTEGER(mpi) :: jc
321 INTEGER(mpi) :: jt
322 INTEGER(mpi) :: last
323
324 CHARACTER (LEN=*), INTENT(IN) :: pat
325 CHARACTER (LEN=*), INTENT(IN) :: text
326 INTEGER(mpi), INTENT(OUT) :: npat
327 INTEGER(mpi), INTENT(OUT) :: ntext
328
329 LOGICAL :: start ! for case conversion
330 CHARACTER (LEN=26) :: chu
331 CHARACTER (LEN=26) :: chl
332 INTEGER(mpi) :: nj(0:255)
333 SAVE
334 DATA chu/'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
335 DATA chl/'abcdefghijklmnopqrstuvwxyz'/
336 DATA start/.true./
337 DATA nj/256*0/
338 ! ...
339 IF(start) THEN
340 start=.false.
341 DO j=0,255
342 nj(j)=j
343 END DO
344 DO i=1,26
345 nj(ichar(chl(i:i)))=ichar(chu(i:i))
346 END DO
347 END IF
348 ! ...
349 matint=0
350 ntext=0
351 DO i=1,len(text) ! find indices ITA...ITB
352 IF(text(i:i) /= ' ') GO TO 10
353 END DO
354 GO TO 15
35510 ita=i
356 DO i=ita,len(text)
357 IF(text(i:i) /= ' ') itb=i
358 END DO
359 ntext=itb-ita+1 ! number of charcaters in TEXT
360
36115 npat=0
362 DO i=1,len(pat) ! find indices IPA...IPB
363 IF(pat(i:i) /= ' ') GO TO 20
364 END DO
365 RETURN
36620 ipa=i
367 DO i=ipa,len(pat)
368 IF(pat(i:i) /= ' ') ipb=i
369 END DO
370 npat=ipb-ipa+1
371
372 ! parallel matching
373 ip=ipa
374 jt=ita
375 last=0
376 DO WHILE (ip <= ipb.AND.jt <= itb)
377 jc=nj(ichar(text(jt:jt)))
378 ic=nj(ichar(pat(ip:ip)))
379 IF (ic == jc) THEN ! match, increment both
380 matint=matint+1
381 ip=ip+1
382 jt=jt+1
383 ELSE ! check remaining length
384 IF (ipb-ip == itb-jt) THEN ! equal, increment other than last
385 ip=ip+last
386 last=1-last ! 'invert' last
387 jt=jt+last
388 ELSE IF (ipb-ip > itb-jt) THEN ! increment ip (remaing pattern is larger)
389 ip=ip+1
390 last=0 ! ip was incremented last
391 ELSE ! increment jt (remaing text is larger)
392 jt=jt+1
393 last=1 ! jt was incremented last
394 ENDIF
395 END IF
396 END DO
397END FUNCTION matint
398
399
integer(mpi) function matint(pat, text, npat, ntext)
Approximate string matching.
Definition: mptext.f90:309
subroutine ratext(text, nums, dnum, mnum)
Translate text.
Definition: mptext.f90:51
subroutine rltext(text, ia, ib, nab)
Analyse text range.
Definition: mptext.f90:256
Definition of constants.
Definition: mpdef.f90:24
Keyword position.
Definition: mptext.f90:29
integer(mpi) keyb
end (position) of first keyword
Definition: mptext.f90:35
integer(mpi) keya
start (position) of first keyword
Definition: mptext.f90:34
integer(mpi) keyc
end (position) of last keyword
Definition: mptext.f90:36