source: redstr.f@ cb47b9c

Last change on this file since cb47b9c was cb47b9c, checked in by baerbaer <baerbaer@…>, 14 years ago

Explicitly declare variables.

All variables should be declared so that we can remove the implicit statements
from the beginning of the INCL.H file.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/smmp/trunk@25 26dc1dd8-5c4e-0410-9ffe-d298b4865968

  • Property mode set to 100644
File size: 7.8 KB
Line 
1!**************************************************************
2!
3! This file contains the subroutines: extstr,ibegst,iendst,
4! iredin,iredrl,iopfil,
5! tolost,toupst
6!
7! Copyright 2003-2005 Frank Eisenmenger, U.H.E. Hansmann,
8! Shura Hayryan, Chin-Ku
9! Copyright 2007 Frank Eisenmenger, U.H.E. Hansmann,
10! Jan H. Meinke, Sandipan Mohanty
11!
12! **************************************************************
13
14
15 subroutine extstr(spr,ib,ie,str,strn,l)
16
17! ..........................................................
18! PURPOSE: Extract substring preceeding separator 'spr'
19! from 'str' searching from position 'ib' up to
20! position 'ie' and put it into 'strn(1:l)'.
21! 'ib' is shifted to position following 'spr' or
22! to 'ie+1', if 'spr' is not found
23!
24! ! 'spr' should not be blank
25!
26! CALLS: ibegst,iendst
27! ..........................................................
28 integer ib, ie, l
29 character spr,blnk,str*(*),strn*(*)
30
31 data blnk/' '/
32
33 integer i, ic, ish, ii
34
35 if (spr.eq.blnk) then
36 write (*,*) ' extstr> Separator should not be blank'
37 stop
38 endif
39
40 l=0
41 ln=len(strn)
42 strn=blnk
43 is=index(str(ib:ie),spr) ! position of spr
44
45 if (is.lt.1) then ! _________ no separator
46
47 l=ie-ib+1
48 if (ln.lt.l) goto 1
49 strn(1:l)=str(ib:ie)
50 ib=ie+1
51 elseif (is.eq.1) then ! _________ empty substring
52 ib=ib+1
53 return
54 else ! _________ found separator
55 l=is-1
56 if (ln.lt.l) goto 1
57 strn(1:l)=str(ib:ib+l-1)
58 ib=ib+is
59 endif
60
61 i=ibegst(strn)
62
63 if (i.lt.1) then ! empty substring
64
65 l=0
66 strn=blnk
67! ____________________________ make string in 'strn' left justified
68 elseif (i.gt.1) then
69 j=iendst(strn)
70 l=j-i+1
71 strn(1:l)=strn(i:j)
72 strn(l+1:ln)=blnk
73 else
74 l=iendst(strn)
75 endif
76
77 return
78! ______________________________________________________________ Error
79 1 write (*,'(a)') ' extstr> Substring to be extracted is too long !'
80 stop
81
82 end
83! **********************************
84 integer*4 function ibegst(str)
85
86! .............................................................
87! PURPOSE: returns position of 1st non-blank character in 'str'
88!
89! CALLS: none
90!
91! .............................................................
92
93 implicit integer*4 (i-n)
94
95 character blnk,str*(*)
96 data blnk/' '/
97
98 do i=1,len(str)
99 if (str(i:i).ne.blnk) then
100 ibegst=i
101 return
102 endif
103 enddo
104
105 ibegst=0
106
107 return
108 end
109! **********************************
110 integer*4 function iendst(str)
111
112! ..............................................................
113! PURPOSE: returns position of last non-blank character in 'str'
114!
115! CALLS: none
116!
117! ..............................................................
118
119 implicit integer*4 (i-n)
120
121 character blnk,str*(*)
122 data blnk/' '/
123
124 do i=len(str),1,-1
125 if (str(i:i).ne.blnk) then
126 iendst=i
127 return
128 endif
129 enddo
130
131 iendst=0
132
133 return
134 end
135! **************************************
136 integer*4 function iredin(line,in)
137
138! ..........................................
139! PURPOSE: Read integer*4 value 'in' from 'line'
140! with format 'i9'
141!
142! iredin=0 : error status
143! iredin=1 : success
144!
145! CALLS: ibegst,iendst
146! ..........................................
147
148 implicit integer*4 (i-n)
149
150 parameter (mxd=9) ! max. # of digits
151
152 character blnk,value*(mxd),line*(*)
153 data blnk/' '/
154
155 iredin=0
156 ib=ibegst(line)
157 if (ib.gt.0) then
158 ie=iendst(line)
159 il=ie-ib
160 if (il.lt.mxd) then
161 i0=ichar('0')
162 i9=ichar('9')
163 do i=ib,ie
164 ii=ichar(line(i:i))
165 if (ii.lt.i0.or.ii.gt.i9) goto 1
166 enddo
167 value=blnk
168 value(mxd-il:mxd)=line(ib:ie)
169 read(value,'(i9)',err=1) in
170 iredin=1
171 endif
172 endif
173 1 return
174 end
175! *************************************
176 integer*4 function iredrl(line,r)
177
178! ..........................................
179! PURPOSE: Read real*8 value 'r' from 'line'
180! with format 'd17.6'
181!
182! iredrl=0 : error status
183! iredrl=1 : success
184!
185! CALLS: ibegst,iendst
186! ..........................................
187
188 implicit integer*4 (i-n)
189
190 parameter (mxd =17, ! max. # of digits
191 & mxap= 6, ! max. # of digits after period
192 & mxip=mxd-mxap)
193
194 real*8 r
195 character per,blnk,value*(mxd),line*(*)
196 data per/'.'/,blnk/' '/
197
198 iredrl=0
199
200 ib=ibegst(line)
201 if (ib.gt.0) then
202 ie=iendst(line)
203 if (index(line(ib:ie),',').gt.0) return
204 il=ie-ib+1
205 ip=index(line,per)
206 value=blnk
207 if (ip.gt.0) then ! found period
208 ibp=ip-ib
209 if (il.le.mxd.and.ibp.lt.mxip.and.ie-ip.le.mxap) then
210 value(mxip-ibp:)=line(ib:ie)
211 read (value,'(d17.6)',err=1) r
212 iredrl=1
213 endif
214 else ! no period
215 if (il.lt.mxip) then
216 value(mxip-il:)=line(ib:ie)//per
217 read (value,'(d17.6)',err=1) r
218 iredrl=1
219 endif
220 endif
221 endif
222
223 1 return
224 end
225! **************************
226 subroutine tolost(str)
227
228! ..........................................
229! PURPOSE: converts 'string' to lower-case
230! INPUT: str - string to be converted
231! CALLS: ibegst,iendst
232! ..........................................
233
234 include 'INCL.H'
235
236 character*(*) str
237
238 integer ibegst, iendst
239
240 integer i, ic, ii, ish
241 ii=ibegst(str)
242 if (ii.gt.0) then
243 ish=idupa-idloa
244 do i=ii,iendst(str)
245 ic=ichar(str(i:i))
246 if (ic.ge.idupa.and.ic.le.idupz) str(i:i)=char(ic-ish)
247 enddo
248 endif
249
250 return
251 end
252! **************************
253 subroutine toupst(str)
254
255! ..........................................
256! PURPOSE: converts 'string' to upper-case
257! INPUT: str - string to be converted
258! CALLS: ibegst,iendst
259! ..........................................
260
261 include 'INCL.H'
262
263 character str*(*)
264
265 integer iendst, ibegst
266
267 integer i, ii, ic, ish
268
269 ii=ibegst(str)
270 if (ii.gt.0) then
271 ish=idupa-idloa
272 do i=ii,iendst(str)
273 ic=ichar(str(i:i))
274 if (ic.ge.idloa.and.ic.le.idloz) str(i:i)=char(ic+ish)
275 enddo
276 endif
277
278 return
279 end
280! *****************************************************
281 integer*4 function iopfil(lun,filnam,stat,format)
282
283! ........................................................
284! PURPOSE: open 'lun' with 'filnam' 'stat' 'format'
285!
286! returns: 1 = file successful opened
287! 0 = error during open of existing file
288! -1 = file does not exist
289!
290! CALLS: ibegst
291! ........................................................
292
293 integer lun
294
295 logical exs
296 character*(*) filnam,stat,format
297
298 iopfil=0
299
300 if (lun.gt.0.and.lun.lt.100) then
301 i=ibegst(filnam)
302 if (i.gt.0) then
303 inquire(file=filnam(i:),exist=exs)
304 if (exs) then
305 j=ibegst(stat)
306 k=ibegst(format)
307 if (j.gt.0.and.k.gt.0) then
308 open(lun,file=filnam(i:),status=stat(j:),
309 & form=format(k:),err=1)
310 iopfil=1
311 endif
312 else
313 iopfil=-1
314 endif
315 endif
316 endif
317
318 1 return
319 end
320
Note: See TracBrowser for help on using the repository browser.