NCEPLIBS-w3emc  2.11.0
w3as00.f
Go to the documentation of this file.
1 C> @file
2 C> @brief Get parm field from command-line.
3 C> @author David Shimomura @date 1995-05-23
4 
5 C> To get the one command-line argument which starts with
6 C> "parm="; returning the parm field (without the keyword "parm=")
7 C> as a null-terminated string in the character string:cparm.
8 C>
9 C> Program history log:
10 C> - David Shimomura 1995-05-23
11 C> - Boi Vuong 1998-03-10 Remove the cdir$ integer=64 directive
12 C>
13 C> @param[out] NCH_PARM No. of characters in the parm field
14 C> @param[out] CPARM C*(*) cparm -- the destination for the parmfield
15 C> obtained from the command line; user should define the character string for
16 C> a size .le. 101-bytes, which would be big enough for the 100-char ibm
17 C> limit plus one extra byte for my null-terminator.
18 C> @param[out] iret_parm - Return code
19 C> - = 0; Normal return
20 C> - = -1; Abnormal exit. the user has failed
21 C> to define the cparm destination as a character string.
22 C>
23 C> - = +1; A Warning:
24 C> the given arg in the command line was
25 C> too long to fit in the destination: cparm,
26 C> so i have truncated it.
27 C>
28 C> - = +2; A warning: no args at all on command line,
29 C> so i could not fetch the parm field.
30 C>
31 C> - = +3; A warning: no "parm="-argument exists
32 C> among the args on the command line,
33 C> so i could not fetch the parm field.
34 C>
35 C> - OKL:
36 C> - FT06F001 - Some checkout printout
37 C>
38 C> @note To emulate the ibm parm field, the user should key_in on the
39 C> command line:
40 C> - parm='in between the single_quotes is the parm field'
41 C> what is returned from w3as00() from the parm= arg is
42 C> the parm field: which starts with the location beyond the
43 C> equal_sign of the keyword "parm=", and includes everything
44 C> which was within the bounds of the single-quote signs.
45 C> But the quote signs themselves will disappear; and a null-
46 C> terminator will be added.
47 C> The starting "parm=" is a key word for the parms, and should
48 C> not be used to start any other argument.
49 C>
50 C> @note I have changed the call sequence by adding a return code.
51 C>
52 C> @author David Shimomura @date 1995-05-23
53  subroutine w3as00(nch_parm,cparm,iret_parm)
54 C
55  integer kbytpwrd
56  parameter(kbytpwrd=8)
57  integer maxnbyt
58  parameter(maxnbyt=112)
59 C ... WHERE 112 CHARACTERS IS SIZE OF CWORK FOR 100 CHARACTERS
60 C ... WITHIN QUOTES + 'PARM=' + BACKSLASHES + LINEFEEDS
61 
62  integer maxnwrds
63  parameter(maxnwrds=maxnbyt/kbytpwrd)
64 
65 C ... call seq. args ...
66  INTEGER NCH_PARM
67  CHARACTER*(*) CPARM
68  integer iret_parm
69 
70 C
71 C ... FUNCTIONS ...
72  external lastch
73  integer lastch
74  external notrail
75  integer notrail
76 C -------------------------------------------------------------
77  integer jwork(maxnwrds)
78  character*112 cwork
79  equivalence(jwork,cwork)
80 
81  integer(4) nargsinline,iargc,iar
82  integer nchars
83  integer lmt_txt
84  integer non_parm
85 
86  LOGICAL LPARMQQ
87  character*1 KLF
88  character*1 NULLCHR
89  character*1 lonech
90 
91 C . . . . . . . . S T A R T . . . . . . . . . . . . . . . .
92 
93  nullchr = char(0)
94  klf = char(10)
95 C
96  iret_parm = 0
97  non_parm = 0
98 
99  lparmqq = .false.
100  nch_parm = 0
101 
102  lmt_dest = len(cparm)
103  write(6,103)lmt_dest
104  103 format(1h ,'W3AS00: dimensioned size (in bytes) of dest strng=',
105  1 i11)
106  if(lmt_dest .le. 0) then
107  write(6,105)
108  105 format(1h ,'W3AS00:FAILED on undefined destination ',
109  1 'character string: CPARM')
110  iret_parm = -1
111  nch_parm = 0
112  go to 999
113  else if (lmt_dest .gt. 101) then
114  lmt_dest = 101
115  endif
116  lmt_txt = lmt_dest - 1
117 
118  cparm(1:lmt_dest) = ' '
119 
120  narg_got = 0
121 C
122  nargsinline = iargc()
123 
124  write(6,115) nargsinline
125  115 format(1h ,'W3AS00: count of args found in command line =', i3)
126 
127  if(nargsinline .gt. 0) then
128 C ... to scan every argument, looking only for the Arg which
129 C ... starts with "PARM="
130  do iar = 1,nargsinline
131  lparmqq = .false.
132 
133  cwork(1:) = ' '
134 
135  call getarg(iar,cwork)
136 
137  narg_got = narg_got + 1
138  nchars = lastch(cwork)
139 
140  if(nchars .le. 0) then
141  write(6,125)iar
142  125 format(1h ,'W3AS00:getarg() returned an empty arg for',
143  a ' no.',i3 )
144  else
145 C ... SOME TEXT EXISTS IN THIS ARG ...
146 C ... DOES IT START WITH "PARM=" ???
147  if((cwork(1:5) .EQ. 'PARM=') .OR.
148  1 (cwork(1:5) .EQ. 'parm=') ) then
149  lparmqq = .true.
150 C ... this arg is special case of PARM=
151 C ... which can include blanks, so cannot lastch() it ...
152  nchars = notrail(cwork)
153  endif
154 C ... iwdss = ((nchars-1)/kbytpwrd) + 1
155 C ... where iwdss points to last word so I could hex dump
156 C ... that last word, to see if NULL is there
157 C ... There was no NULL; only blank fill.
158  IF(lparmqq) THEN
159 C ... FILTER OUT ANY BACKSLASH or LINE_FEED ...
160  ioutc = 0
161  do inc = 6,nchars
162  if(ioutc .LT. lmt_txt) then
163  lonech = cwork(inc:inc)
164  if((lonech .EQ. '\\') .OR.
165  1 (lonech .EQ. klf)) then
166  else
167  ioutc = ioutc + 1
168  cparm(ioutc:ioutc) = lonech
169  endif
170  else
171 C ... comes here if ioutc .GE. lmt_txt,
172 C ... so I cannot increment ioutc for this inc char
173 C ... so truncate the string at (1:ioutc)
174 C ... a warning be return-coded ...
175  iret_parm = +1
176  go to 155
177  endif
178  enddo
179  155 continue
180  nch_parm = ioutc
181  np1 = nchars+1
182  cparm(np1:np1) = nullchr
183  go to 999
184 C ... jump out of DO when PARM has been processed ...
185  else
186 C ... this is .not. a PARM field, do nothing w/ those,
187  non_parm = non_parm + 1
188  endif
189 
190  endif
191  enddo
192 C ... IF IT FALLS THRU BOTTOM OF DO, THEN IT DID NOT FIND
193 C ... THE PARM FIELD AMONG THE EXISTING ARGS
194  iret_parm = 3
195  nch_parm = 0
196 
197  ELSE
198 C ... COMES HERE IF nargsinline = 0, so there were no args at all
199  iret_parm = 2
200  nch_parm = 0
201  endif
202  go to 999
203 
204  999 continue
205  return
206  end
207  integer function lastch(str)
208 C ... lastch() ... to point to the last character of a character
209 C ... string
210 C ... String terminators are first BLANK or NULL character
211 C ... encountered.
212 C ... Caution: I will limit scan on LEN(str)
213 C so you must give me a character string.
214 C
215 
216  character*(*) str
217 
218  character*1 NULLCHR
219  character*1 BLANK
220 C
221  integer i
222  integer limit
223 C
224  nullchr = char(0)
225  blank = ' '
226  limit = len(str)
227  i = 0
228  do while(i .LT. limit .AND. str(i+1:i+1) .NE. nullchr
229  1 .AND. str(i+1:i+1) .NE. blank)
230  i = i + 1
231  enddo
232 
233  lastch = i
234  return
235  end
236  integer function notrail(str)
237 C ... mods for CRAY version 8-Dec-1994/dss
238 C
239 C ... notrail() ... to point to the last non-blank character of a
240 C ... character string (which can have leading
241 C blanks and intermediate blanks); but after
242 C ignoring all trailing blank characters.
243 C ... String terminators are last BLANK or first NULL
244 C ... character encountered.
245 C
246 C ... This differs from LASTCH() which stops on first
247 C ... BLANK encountered when scanning from the start;
248 C ... NOTRAIL() will scan backwards from the end of the
249 C ... string, skipping over trailing blanks, until the
250 C ... last non-blank character is hit.
251 C ...
252 C ... Caution: I will limit scan on LEN(str)
253 C so you must give me a character string.
254 C
255 
256  character*(*) str
257 
258  character*1 BLANK
259  parameter(blank = ' ')
260 C
261  integer i
262  integer limit
263  integer limitnl
264  character*1 NULLCHR
265 C
266  nullchr = char(0)
267  i = 0
268  limitnl = 0
269  limit = len(str)
270  if(limit .le. 0) go to 999
271 C ... otherwise, at least one char len string ...
272  limitnl = index(str(1:limit),nullchr)
273  if(limitnl .le. 0) then
274 C ... no NULLCHR exists in str(1:limit) ...
275 C ... so go scan from limit
276  go to 300
277 
278  else if(limitnl .eq. 1) then
279  go to 999
280 C ... which jumped out w/ pointer=0 if NULL in first position
281  else
282 C ... a NULLCHR existed within str(1:limit); so
283 C ... I want to scan backwards from before that NULLCHR
284 C ... which is located at limitnl
285  limit = limitnl - 1
286  endif
287  if(limit .le. 0) go to 999
288  300 continue
289 C ... otherwise, we have a string of at least one char to look at
290 C ... which has no NULLCHR in interval (1:limit)
291  i = limit
292  do while((i .GT. 0) .AND. (str(i:i) .EQ. blank))
293  i = i - 1
294  enddo
295 
296  999 continue
297  notrail = i
298  return
299  end
subroutine w3as00(nch_parm, cparm, iret_parm)
To get the one command-line argument which starts with "parm="; returning the parm field (without the...
Definition: w3as00.f:54