Debian Codegraph @

packages/seacas/applications/blot/getins.f

raw
1 C Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 C NTESS, the U.S. Government retains certain rights in this software.
4 C
5 C See packages/seacas/LICENSE for details
6
7 c ======================================================================
8 c ======================================================================
9 c ======================================================================
10 c ======================================================================
11
12 c ROUTINE: getins
13
14 c DESCRIPTION: This routine is in charge of getting user
15 c input and keeping track of where
16 c it is coming from.
17
18 c AUTHOR: John H. Glick
19 c Sandia National Laboratories
20 c Division 1511
21
22 c DATE: December 20, 1988
23
24 c TYPE OF SUBPROGRAM: subroutine
25
26 c USAGE: call getins (id, maxfld, nfield,
27 c kvalue, cvalue, ivalue, rvalue,
28 c line, iostat, prompt,
29 c lprom, *)
30
31 c PARAMETERS:
32
33 c character*(*) id -- (input)
34 c = 'parse' if the input line should be read
35 c and parsed by the free field reader. If so,
36 c input information is returned in the nfield,
37 c kvalue, cvalue, ivalue, and rvalue parameters.
38 c = 'line' if the input line is to be read as
39 c one line. If so, the input line is returned
40 c in the parameter line.
41 c integer maxfld -- (input)
42 c Maximum number of fields returned by the
43 c free field reader (frefld).
44 c integer nfield -- (output)
45 c number of data fields returned by
46 c the free field reader (frefld).
47 c integer kvalue( maxfld ) -- ( output )
48 c Translation states of the data fields
49 c returned by the free field reader. The
50 c value of each element of this array is
51 c interpreted as follows:
52 c -1 = This is a null field.
53 c 0 = This is a nonnumeric field; only
54 c cvalue contains a specified value.
55 c 1 = This is a real numeric field;
56 c cvalue and rvalue contain specified
57 c values.
58 c 2 = This is an integer numeric field;
59 c cvalue, rvalue, and ivalue contain
60 c specified values.
61 c character*(*) cvalue( maxfld ) -- ( output )
62 c Character values of the data fields returned
63 c by the free field reader (frefld). The data
64 c will be left justified and either
65 c blank-filled or truncated. The value in
66 c this array is set by frefld to be blank
67 c for a null field.
68 c integer ivalue( maxfld ) -- ( output )
69 c Integer values of the data fields. The
70 c value in this array is set by frefld to
71 c be zero for a null or non-integer field.
72 c real rvalue( maxfld ) -- ( output )
73 c Floating-point values of the data fields.
74 c The value in this array is set by frefld
75 c to be zero for a null or non-real fields.
76 c character*(*) line -- ( output )
77 c If id = 'line', then the input line
78 c is returned in this parameter.
79 c integer iostat -- (output)
80 c iostat value returned by the frefld reader
81 c (if id = 'parse') or by the read
82 c statement (if id = 'line').
83 c character*(*) prompt -- (input)
84 c Prompt to be displayed to user.
85 c integer lprom -- (input)
86 c Length of prompt string.
87 c * -- Alternate return in case of fatal error.
88
89 c CALLS: prterr (etclib), filhnd (BLOT),
90 c lenstr (strlib),
91 c frefld (SUPES), exname (SUPES)
92
93 c GLOBAL VARIABLES REFERENCED:
94
95 c none
96
97 c CALLING ROUTINE(S): comand (BLOT)
98
99 c SYSTEM DEPENDENCIES: none
100
101 c ======================================================================
102 c ======================================================================
103
104 subroutine getins (id, maxfld, nfield, kvalue, cvalue,
105 & ivalue, rvalue, line, iostat, prompt, lprom, *)
106
107 c ***********************************************************************
108
109 c parameters
110
111 character*(*) id
112 integer maxfld
113 character*(*) cvalue( maxfld )
114 integer nfield, kvalue( maxfld ), ivalue( maxfld )
115 real rvalue( maxfld )
116 character*(*) line
117 integer iostat
118 character*(*) prompt
119 integer lprom
120
121 c ***********************************************************************
122
123 c local declarations
124
125 integer maxstk
126 parameter ( maxstk = 10 )
127 c the maximum number of files allowed in the stack of files
128 c containing instructions that are still to be read.
129 character*2048 file, filelc
130 c Name of file to be opened for reading instructions
131 character*2048 name( maxstk )
132 c the stack of file names containing instructions that are
133 c still to be read
134 integer recred( maxstk )
135 c recred(i) = the number of records that have already been
136 c processed in file i of the stack. That is, when file i
137 c is reopened as the source of instructions, the first
138 c recred(i) records (instructions) have already been read
139 c and so should be skipped.
140 integer stkpnt
141 c the number of files currently in the stack. That is,
142 c when the last instruction is read from a file,
143 c the file from the top of the stack, file( numstk ),
144 c is reopened. This is the file that called the last file.
145 save stkpnt, name, recred
146
147 logical first
148 c .TRUE. until after the first call to getins.
149 c .FALSE. thereafter.
150 save first
151 integer ln
152 c length of a file name or a command string
153 integer ios
154 c I/O status returned by and I/O statement or the free
155 c field reader (frefld).
156 logical gotins
157 c .TRUE. if an instruction was successfully read from
158 c the input stream.
159 c .FALSE. otherwise. ( e.g., an EOF mark was read from
160 c the input file.
161 logical ecode
162 c code returned by subroutine filhnd.
163 c .TRUE. if file handling proceeded properly.
164 c .FALSE. otherwise
165 integer temp
166 c temporary variable for saving integer variables.
167 logical try
168 c .TRUE. if an attempt to open an instruction file is to be made.
169 c .FALSE. otherwise.
170 logical quit
171 c .TRUE. if control should go back to the top of the routine
172 c to try to read another command line.
173 c .FALSE. if a command line has successfully been read and
174 c the program should exit.
175 character*2048 cmdfile
176 c Name of the command for directing command to a new file.
177 save cmdfile
178
179 logical parse
180 c .TRUE. if the input is to be read and parsed by the free
181 c field reader.
182 c .FALSE. if the input is to be read as a line.
183
184 logical instr
185
186 integer nin
187 c logical unit where instructions are currently being read from.
188 save nin
189
190 character*2048 cval2(80)
191 logical batch
192
193 c ***********************************************************************
194
195 c data statements
196
197 data recred / maxstk*0 /
198 data first / .TRUE. /
199 data cmdfile(1:7) / 'CMDFILE' /
200
201 c ***********************************************************************
202 c ***********************************************************************
203
204 iostat = 0
205 if ( id .eq. 'parse' ) then
206 parse = .TRUE.
207 else if ( id .eq. 'line' ) then
208 parse = .FALSE.
209 else
210 call prterr ('PROGRAM',
211 & 'illegal value for id parameter passed to getins')
212 return 1
213 endif
214
215 if ( first ) then
216 stkpnt = 0
217 c first call to getins
218
219 c find out if an instruction file was specified in the P4
220 c field of the command line
221
222 if ( instr() ) then
223 c an instruction file was specified
224 call exname ( 7, name( 1 ), ln )
225 c get name of file
226
227 c open file
228
229 if ( batch() ) then
230 call filhnd ( 7, name(1)(:ln), .TRUE., ecode,
231 & 'o', 'f', 's', 0, *150)
232 stkpnt = stkpnt + 1
233 c increment stack pointer
234 nin = 7
235 c set logical unit where instructions are to be read from
236 else
237 call filhnd ( 7, name(1)(:ln), .FALSE., ecode,
238 & 'o', 'f', 's', 0, *150)
239 if ( ecode ) then
240 c file opened properly
241 stkpnt = stkpnt + 1
242 c increment stack pointer
243 nin = 7
244 c set logical unit where instructions are to be read from
245 else
246 c instruction file wasn't there. prompt user for instructions.
247 nin = 0
248 endif
249 endif
250
251 else
252 c no instruction file was specified
253 if ( batch() ) then
254 call prterr ('FATAL',
255 & 'No instruction file was specified on the command line.')
256 return 1
257 else
258 nin = 0
259 endif
260 endif
261 first = .FALSE.
262
263 endif
264
265 c get an instruction
266
267 100 continue
268
269 gotins = .FALSE.
270
271 110 continue
272
273 if ( nin .eq. 7 )
274 & recred( stkpnt ) = recred( stkpnt ) + 1
275
276 c read instruction
277
278 if ( parse ) then
279 call frefld ( nin, 0, prompt(:lprom), maxfld, ios,
280 & nfield, kvalue, cval2, ivalue, rvalue )
281 else
282 if (nin .eq. 0) then
283 read (*, fmt=10010, iostat=ios ) line
284 else
285 read ( unit=nin, fmt=10010, iostat=ios ) line
286 end if
287 10010 format ( a )
288 endif
289
290 c check for an error in reading instruction
291
292 if ( ios .gt. 0 ) then
293 c error in reading instruction
294 call prterr ('FATAL',
295 & 'error reading an instruction in getins')
296 return 1
297 else if ( ios .lt. 0 ) then
298
299 c end of file read from input stream.
300
301 if ( nin .ne. 0 ) then
302 c EOF mark read from a file.
303 c Close the file and open the
304 c previous one on the stack, if
305 c one exists. If not, switch to
306 c interactive input.
307 call filhnd ( -nin, ' ', .TRUE., ecode,
308 & ' ', ' ', ' ', 0, *150)
309 stkpnt = stkpnt - 1
310 if ( stkpnt .gt. 0 ) then
311
312 c open previous file
313
314 call filhnd ( nin, name( stkpnt ), .TRUE., ecode,
315 & 'o', 'f', 's', 0, *150)
316
317 c skip records that have already been read
318
319 do 120 i = 1, recred( stkpnt )
320 read ( nin, * )
321 120 continue
322
323 else
324 c no more files on the stack. Switch
325 c to interactive input if an interactive
326 c job. If a batch job, print error.
327 if ( .not. batch() ) then
328 nin = 0
329 else
330 call prterr ('PROGRAM',
331 & ' End of file mark read in lowest level command file.')
332 return 1
333 endif
334
335 endif
336
337 endif
338
339 else
340 gotins = .TRUE.
341 endif
342
343 if ( .not. gotins ) go to 110
344
345 c if id = 'line', just return the line of input
346
347 if ( .not. parse ) then
348
349 try = .FALSE.
350 quit = .TRUE.
351
352 else
353
354 c check if command specifies that instructions
355 c are to be read from a different source
356
357 ln = lenstr ( cval2(1) )
358 if ( cval2(1)(1:ln) .eq. cmdfile(1:ln) ) then
359
360 if ( kvalue(2) .eq. 0 ) then
361 file = cval2(2)
362 C ... Convert filename to all lowercase -- FREFLD converts to all uppercase
363 call lowstr(filelc, file)
364 try = .TRUE.
365 else
366 if ( nin .eq. 0 ) then
367 write ( *, 10020 )
368 10020 format ( // 5x, 'Please enter an instruction file',
369 & ' to read from or ''a'' to ' / 5x,
370 & 'continue reading from the current unit. > ', $ )
371 read ( *, 10030 ) file
372 10030 format ( a )
373 else
374 recred( stkpnt ) = recred( stkpnt ) + 1
375 read ( nin, 10030 ) file
376 endif
377 call pack ( file, ln )
378 if ( file(1:1) .eq. 'A' .or.
379 & file(1:1) .eq. 'a' ) then
380 try = .FALSE.
381 quit = .FALSE.
382 else
383 try = .TRUE.
384 endif
385 endif
386 else
387 try = .FALSE.
388 quit = .TRUE.
389 do 130 i2 = 1, maxfld
390 cvalue(i2) = cval2(i2)
391 130 continue
392 endif
393
394 endif
395
396 if ( try ) then
397
398 quit = .FALSE.
399 c will want to return to the
400 c top of the routine to read
401 c an instruction.
402
403 temp = nin
404 c remember where instructions are coming from.
405
406 if ( nin .eq. 7 ) then
407 c instructions are currently coming
408 c from a file. This current file
409 c must be closed. The information
410 c on this file ( its name and the
411 c pointer to its current instruction
412 c has already been stored on the stack.
413 call filhnd ( -nin, ' ', .TRUE., ecode, ' ', ' ', ' ',
414 & 0, *150)
415 else
416 c instructions are currently coming
417 c from the terminal. Change unit
418 c of instructions to 7
419 nin = 7
420 endif
421
422 stkpnt = stkpnt + 1
423 c increment stack pointer
424
425 if ( stkpnt .gt. maxstk ) then
426 call prterr ('FATAL',
427 &'Nesting of instruction files is greater than maximum allowed')
428 return 1
429 endif
430
431 c open instruction file
432
433 C ... We have a problem on systems with case-sensitive file names.
434 C FREFLD converts all strings to uppercase. Therefore, the filename
435 C specified in 'file' will be all uppercase. Since the file is
436 C typically lowercase, we lowercase 'file' in variable 'filelc'.
437 C First, try to open 'file' (uppercase), if this fails, try to
438 C open 'filelc' (lowercase). NOTE: There is no way (yet) to deal
439 C with mixed-case filenames. GDS 7/1/91.
440
441 if ( batch() ) then
442 call filhnd ( nin, file, .FALSE., ecode,
443 & 'o', 'f', 's', 0, *150)
444 if (.not. ecode) then
445 call filhnd ( nin, filelc, .TRUE., ecode,
446 & 'o', 'f', 's', 0, *150)
447 end if
448 else
449 call filhnd ( nin, file, .FALSE., ecode,
450 & 'o', 'f', 's', 0, *150)
451
452 if (.not. ecode) then
453 call filhnd ( nin, filelc, .FALSE., ecode,
454 & 'o', 'f', 's', 0, *150)
455 end if
456 endif
457 if ( ecode ) then
458 c file was successfully opened
459 name( stkpnt ) = file
460 recred( stkpnt ) = 0
461 else
462 c file was not successfully opened
463 c reopen last instruction file ( if
464 c necessary ) and reset parameters.
465 call prterr ('ERROR',
466 & ' Command file could not be opened. Command ignored. ')
467
468 nin = temp
469 stkpnt = stkpnt - 1
470 if ( nin .eq. 7 ) then
471
472 call filhnd ( nin, name( stkpnt ), .TRUE., ecode,
473 & 'o', 'f', 's', 0, *150)
474
475 c skip records that have already been read
476
477 do 140 i = 1, recred( stkpnt )
478 call frefld ( nin, 0, ' ', maxfld, ios, nfield,
479 & kvalue, cval2, ivalue, rvalue )
480 if ( ios .ne. 0 ) then
481 call prterr ('PROGRAM',
482 & 'Error skipping previously read records in getins')
483 return 1
484 endif
485 140 continue
486 endif
487 endif
488
489 endif
490
491 c return to the top of the routine to read
492 c another instruction, if necessary
493
494 if ( .not. quit ) go to 100
495 return
496
497 c alternate return
498
499 150 continue
500 return 1
501 end