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