MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
InputOutput.f90
Go to the documentation of this file.
1! -- MODFLOW 6 utility routines.
2!
4
5 use kindmodule, only: dp, i4b, i8b
13 private
17 linear_interpolate, lowcase, read_line, getfilefrompath, &
21
22contains
23
24 !> @brief Open a file
25 !!
26 !! Subroutine to open a file using the specified arguments
27 !! @hidecallergraph
28 !<
29 subroutine openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, &
30 filstat_opt, mode_opt)
31 ! -- modules
32 use openspecmodule, only: action
33 implicit none
34 ! -- dummy
35 integer(I4B), intent(inout) :: iu !< unit number
36 integer(I4B), intent(in) :: iout !< output unit number to write a message (iout=0 does not print)
37 character(len=*), intent(in) :: fname !< name of the file
38 character(len=*), intent(in) :: ftype !< file type (e.g. WEL)
39 character(len=*), intent(in), optional :: fmtarg_opt !< file format, default is 'formatted'
40 character(len=*), intent(in), optional :: accarg_opt !< file access, default is 'sequential'
41 character(len=*), intent(in), optional :: filstat_opt !< file status, default is 'old'. Use 'REPLACE' for output file.
42 integer(I4B), intent(in), optional :: mode_opt !< simulation mode that is evaluated to determine if the file should be opened
43 ! -- local
44 character(len=20) :: fmtarg
45 character(len=20) :: accarg
46 character(len=20) :: filstat
47 character(len=20) :: filact
48 integer(I4B) :: imode
49 integer(I4B) :: iflen
50 integer(I4B) :: ivar
51 integer(I4B) :: iuop
52 ! -- formats
53 character(len=*), parameter :: fmtmsg = &
54 "(1x,/1x,'OPENED ',a,/1x,'FILE TYPE:',a,' UNIT ',I4,3x,'STATUS:',a,/ &
55 & 1x,'FORMAT:',a,3x,'ACCESS:',a/1x,'ACTION:',a/)"
56 character(len=*), parameter :: fmtmsg2 = &
57 "(1x,/1x,'DID NOT OPEN ',a,/)"
58 !
59 ! -- Process mode_opt
60 if (present(mode_opt)) then
61 imode = mode_opt
62 else
63 imode = isim_mode
64 end if
65 !
66 ! -- Evaluate if the file should be opened
67 if (isim_mode < imode) then
68 if (iout > 0) then
69 write (iout, fmtmsg2) trim(fname)
70 end if
71 else
72 !
73 ! -- Default is to read an existing text file
74 fmtarg = 'FORMATTED'
75 accarg = 'SEQUENTIAL'
76 filstat = 'OLD'
77 !
78 ! -- Override defaults
79 if (present(fmtarg_opt)) then
80 fmtarg = fmtarg_opt
81 call upcase(fmtarg)
82 end if
83 if (present(accarg_opt)) then
84 accarg = accarg_opt
85 call upcase(accarg)
86 end if
87 if (present(filstat_opt)) then
88 filstat = filstat_opt
89 call upcase(filstat)
90 end if
91 if (filstat == 'OLD') then
92 filact = action(1)
93 else
94 filact = action(2)
95 end if
96 !
97 ! -- size of fname
98 iflen = len_trim(fname)
99 !
100 ! -- Get a free unit number
101 if (iu <= 0) then
102 call freeunitnumber(iu)
103 end if
104 !
105 ! -- Check if file is already open
106 inquire (file=fname(1:iflen), number=iuop)
107 open (unit=iu, file=fname(1:iflen), form=fmtarg, access=accarg, &
108 status=filstat, action=filact, iostat=ivar)
109 !
110 ! -- Check for an error
111 if (ivar /= 0) then
112 write (errmsg, '(3a,1x,i0,a)') &
113 'Could not open "', fname(1:iflen), '" on unit', iu, '.'
114 if (iuop > 0) then
115 write (errmsg, '(a,1x,a,1x,i0,a)') &
116 trim(errmsg), 'File already open on unit', iuop, '.'
117 end if
118 write (errmsg, '(a,1x,a,1x,a,a)') &
119 trim(errmsg), 'Specified file status', trim(filstat), '.'
120 write (errmsg, '(a,1x,a,1x,a,a)') &
121 trim(errmsg), 'Specified file format', trim(fmtarg), '.'
122 write (errmsg, '(a,1x,a,1x,a,a)') &
123 trim(errmsg), 'Specified file access', trim(accarg), '.'
124 write (errmsg, '(a,1x,a,1x,a,a)') &
125 trim(errmsg), 'Specified file action', trim(filact), '.'
126 write (errmsg, '(a,1x,a,1x,i0,a)') &
127 trim(errmsg), 'IOSTAT error number', ivar, '.'
128 write (errmsg, '(a,1x,a)') &
129 trim(errmsg), 'STOP EXECUTION in subroutine openfile().'
130 call store_error(errmsg, terminate=.true.)
131 end if
132 !
133 ! -- Write a message
134 if (iout > 0) then
135 write (iout, fmtmsg) fname(1:iflen), ftype, iu, filstat, fmtarg, &
136 accarg, filact
137 end if
138 end if
139 end subroutine openfile
140
141 !> @brief Assign a free unopened unit number
142 !!
143 !! Subroutine to assign a free unopened unit number to the iu dummy argument
144 !<
145 subroutine freeunitnumber(iu)
146 ! -- modules
147 implicit none
148 ! -- dummy
149 integer(I4B), intent(inout) :: iu !< next free file unit number
150 ! -- local
151 integer(I4B) :: i
152 logical :: opened
153 !
154 do i = iunext, iulast
155 inquire (unit=i, opened=opened)
156 if (.not. opened) exit
157 end do
158 iu = i
159 iunext = iu + 1
160 end subroutine freeunitnumber
161
162 !> @brief Get a free unit number
163 !!
164 !! Function to get a free unit number that hasn't been used
165 !<
166 function getunit()
167 ! -- modules
168 implicit none
169 ! -- return
170 integer(I4B) :: getunit !< free unit number
171 ! -- local
172 integer(I4B) :: iunit
173 !
174 ! -- code
175 call freeunitnumber(iunit)
176 getunit = iunit
177 end function getunit
178
179 !> @brief assign io unit number
180 !!
181 !! Generic method to assign io unit number to unassigned integer
182 !! variable (initialized less than or equal to 0). Assigns a valid
183 !! number if unassigned, otherwise sets a terminating error.
184 !<
185 subroutine assign_iounit(iounit, errunit, description)
186 integer(I4B), intent(inout) :: iounit !< iounit variable
187 integer(I4B), intent(in) :: errunit !< input file inunit for error assignment
188 character(len=*), intent(in) :: description !< usage description for iounit
189 if (iounit > 0) then
190 write (errmsg, '(a,1x,i0)') &
191 trim(description)//' already assigned at unit: ', iounit
192 call store_error(errmsg)
193 call store_error_unit(errunit)
194 end if
195 iounit = getunit()
196 end subroutine assign_iounit
197
198 !> @brief Convert to upper case
199 !!
200 !! Subroutine to convert a character string to upper case.
201 !<
202 subroutine upcase(word)
203 implicit none
204 ! -- dummy
205 character(len=*), intent(inout) :: word !< word to convert to upper case
206 ! -- local
207 integer(I4B) :: l
208 integer(I4B) :: idiff
209 integer(I4B) :: k
210 !
211 ! -- Compute the difference between lowercase and uppercase.
212 l = len(word)
213 idiff = ichar('a') - ichar('A')
214 !
215 ! -- Loop through the string and convert any lowercase characters.
216 do k = 1, l
217 IF (word(k:k) >= 'a' .and. word(k:k) <= 'z') &
218 word(k:k) = char(ichar(word(k:k)) - idiff)
219 end do
220 end subroutine upcase
221
222 !> @brief Convert to lower case
223 !!
224 !! Subroutine to convert a character string to lower case.
225 !<
226 subroutine lowcase(word)
227 implicit none
228 ! -- dummy
229 character(len=*) :: word
230 ! -- local
231 integer(I4B) :: idiff, k, l
232 !
233 ! -- Compute the difference between lowercase and uppercase.
234 l = len(word)
235 idiff = ichar('a') - ichar('A')
236 !
237 ! -- Loop through the string and convert any uppercase characters.
238 do k = 1, l
239 if (word(k:k) >= 'A' .and. word(k:k) <= 'Z') then
240 word(k:k) = char(ichar(word(k:k)) + idiff)
241 end if
242 end do
243 end subroutine lowcase
244
245 !> @brief Append processor id to a string
246 !!
247 !! Subroutine to append the processor id to a string before the file extension
248 !! (extension is the string after the last '.' in the string. If there is
249 !! no '.' in the string the processor id is appended to the end of the string.
250 !<
251 subroutine append_processor_id(name, proc_id)
252 ! -- dummy
253 character(len=LINELENGTH), intent(inout) :: name !< file name
254 integer(I4B), intent(in) :: proc_id !< processor id
255 ! -- local
256 character(len=LINELENGTH) :: name_local
257 character(len=LINELENGTH) :: name_processor
258 character(len=LINELENGTH) :: extension_local
259 integer(I4B) :: ipos0
260 integer(I4B) :: ipos1
261 !
262 name_local = name
263 call lowcase(name_local)
264 ipos0 = index(name_local, ".", back=.true.)
265 ipos1 = len_trim(name)
266 if (ipos0 > 0) then
267 write (extension_local, '(a)') name(ipos0:ipos1)
268 else
269 ipos0 = ipos1
270 extension_local = ''
271 end if
272 write (name_processor, '(a,a,i0,a)') &
273 name(1:ipos0 - 1), '.p', proc_id, trim(adjustl(extension_local))
274 name = name_processor
275 end subroutine append_processor_id
276
277 !> @brief Create a formatted line
278 !!
279 !! Subroutine to create a formatted line with specified alignment and column
280 !! separators. Like URWORD, UWWORD works with strings, integers, and floats.
281 !! Can pass an optional format statement, alignment, and column separator.
282 !<
283 subroutine uwword(line, icol, ilen, ncode, c, n, r, fmt, alignment, sep)
284 implicit none
285 ! -- dummy
286 character(len=*), intent(inout) :: line !< line
287 integer(I4B), intent(inout) :: icol !< column to write to line
288 integer(I4B), intent(in) :: ilen !< current length of line
289 integer(I4B), intent(in) :: ncode !< code for data type to write
290 character(len=*), intent(in) :: c !< character data type
291 integer(I4B), intent(in) :: n !< integer data type
292 real(dp), intent(in) :: r !< float data type
293 character(len=*), optional, intent(in) :: fmt !< format statement
294 integer(I4B), optional, intent(in) :: alignment !< alignment specifier
295 character(len=*), optional, intent(in) :: sep !< column separator
296 ! -- local
297 character(len=16) :: cfmt
298 character(len=16) :: cffmt
299 character(len=ILEN) :: cval
300 integer(I4B) :: ialign
301 integer(I4B) :: i
302 integer(I4B) :: ispace
303 integer(I4B) :: istop
304 integer(I4B) :: ipad
305 integer(I4B) :: ireal
306 !
307 ! -- initialize locals
308 ipad = 0
309 ireal = 0
310 !
311 ! -- process dummy variables
312 if (present(fmt)) then
313 cfmt = fmt
314 else
315 select case (ncode)
316 case (tabstring, tabucstring)
317 write (cfmt, '(a,I0,a)') '(a', ilen, ')'
318 case (tabinteger)
319 write (cfmt, '(a,I0,a)') '(I', ilen, ')'
320 case (tabreal)
321 ireal = 1
322 i = ilen - 7
323 write (cfmt, '(a,I0,a,I0,a)') '(1PG', ilen, '.', i, ')'
324 if (r >= dzero) then
325 ipad = 1
326 end if
327 end select
328 end if
329 write (cffmt, '(a,I0,a)') '(a', ilen, ')'
330 !
331 if (present(alignment)) then
332 ialign = alignment
333 else
334 ialign = tabright
335 end if
336 !
337 if (ncode == tabstring .or. ncode == tabucstring) then
338 cval = c
339 if (ncode == tabucstring) then
340 call upcase(cval)
341 end if
342 else if (ncode == tabinteger) then
343 write (cval, cfmt) n
344 else if (ncode == tabreal) then
345 write (cval, cfmt) r
346 end if
347 !
348 ! -- Apply alignment to cval
349 if (len_trim(adjustl(cval)) > ilen) then
350 cval = adjustl(cval)
351 else
352 cval = trim(adjustl(cval))
353 end if
354 if (ialign == tabcenter) then
355 i = len_trim(cval)
356 ispace = (ilen - i) / 2
357 if (ireal > 0) then
358 if (ipad > 0) then
359 cval = ' '//trim(adjustl(cval))
360 else
361 cval = trim(adjustl(cval))
362 end if
363 else
364 cval = repeat(' ', ispace)//trim(cval)
365 end if
366 else if (ialign == tableft) then
367 cval = trim(adjustl(cval))
368 if (ipad > 0) then
369 cval = ' '//trim(adjustl(cval))
370 end if
371 else
372 cval = adjustr(cval)
373 end if
374 if (ncode == tabucstring) then
375 call upcase(cval)
376 end if
377 !
378 ! -- Increment istop to the end of the column
379 istop = icol + ilen - 1
380 !
381 ! -- Write final string to line
382 write (line(icol:istop), cffmt) cval
383 !
384 icol = istop + 1
385 !
386 if (present(sep)) then
387 i = len(sep)
388 istop = icol + i
389 write (line(icol:istop), '(a)') sep
390 icol = istop
391 end if
392 end subroutine uwword
393
394 !> @brief Extract a word from a string
395 !!
396 !! Subroutine to extract a word from a line of text, and optionally
397 !! convert the word to a number. The last character in the line is
398 !! set to blank so that if any problems occur with finding a word,
399 !! istart and istop will point to this blank character. Thus, a word
400 !! will always be returned unless there is a numeric conversion error.
401 !! Be sure that the last character in line is not an important character
402 !! because it will always be set to blank.
403 !!
404 !! A word starts with the first character that is not a space or
405 !! comma, and ends when a subsequent character that is a space
406 !! or comma. Note that these parsing rules do not treat two
407 !! commas separated by one or more spaces as a null word.
408 !!
409 !! For a word that begins with "'" or '"', the word starts with
410 !! the character after the quote and ends with the character preceding
411 !! a subsequent quote. Thus, a quoted word can include spaces and commas.
412 !! The quoted word cannot contain a quote character of the same type
413 !! within the word but can contain a different quote character. For
414 !! example, "WORD'S" or 'WORD"S'.
415 !!
416 !! Number conversion error is written to unit iout if iout is positive;
417 !! error is written to default output if iout is 0; no error message is
418 !! written if iout is negative.
419 !!
420 !! @hidecallergraph
421 !<
422 subroutine urword(line, icol, istart, istop, ncode, n, r, iout, in)
423 ! -- dummy
424 character(len=*) :: line !< line to parse
425 integer(I4B), intent(inout) :: icol !< current column in line
426 integer(I4B), intent(inout) :: istart !< starting character position of the word
427 integer(I4B), intent(inout) :: istop !< ending character position of the word
428 integer(I4B), intent(in) :: ncode !< word conversion flag (1) upper case, (2) integer, (3) real number
429 integer(I4B), intent(inout) :: n !< integer data type
430 real(dp), intent(inout) :: r !< float data type
431 integer(I4B), intent(in) :: iout !< output listing file unit
432 integer(I4B), intent(in) :: in !< input file unit number
433 ! -- local
434 character(len=20) string
435 character(len=1) tab
436 character(len=1) charend
437 character(len=200) :: msg
438 character(len=linelength) :: msg_line
439 ! -- formats
440 character(len=*), parameter :: fmtmsgout1 = &
441 "(1X,'FILE UNIT ',I4,' : ERROR CONVERTING ""',A, &
442 & '"" TO ',A,' IN LINE:')"
443 character(len=*), parameter :: fmtmsgout2 = "(1x, &
444 & 'KEYBOARD INPUT : ERROR CONVERTING ""',a,'"" TO ',a,' IN LINE:')"
445 character(len=*), parameter :: fmtmsgout3 = "('File unit ', &
446 & I0,': Error converting ""',a,'"" to ',A,' in following line:')"
447 character(len=*), parameter :: fmtmsgout4 = &
448 "('Keyboard input: Error converting ""',a, &
449 & '"" to ',A,' in following line:')"
450 !
451 tab = char(9)
452 !
453 ! -- Set last char in LINE to blank and set ISTART and ISTOP to point
454 ! to this blank as a default situation when no word is found. If
455 ! starting location in LINE is out of bounds, do not look for a word.
456 linlen = len(line)
457 line(linlen:linlen) = ' '
458 istart = linlen
459 istop = linlen
460 linlen = linlen - 1
461 if (icol < 1 .or. icol > linlen) go to 100
462 !
463 ! -- Find start of word, which is indicated by first character that
464 ! is not a blank, a comma, or a tab.
465 do i = icol, linlen
466 if (line(i:i) /= ' ' .and. line(i:i) /= ',' .and. &
467 line(i:i) /= tab) go to 20
468 end do
469 icol = linlen + 1
470 go to 100
471 !
472 ! -- Found start of word. Look for end.
473 ! When word is quoted, only a quote can terminate it.
474 ! search for a single (char(39)) or double (char(34)) quote
47520 if (line(i:i) == char(34) .or. line(i:i) == char(39)) then
476 if (line(i:i) == char(34)) then
477 charend = char(34)
478 else
479 charend = char(39)
480 end if
481 i = i + 1
482 if (i <= linlen) then
483 do j = i, linlen
484 if (line(j:j) == charend) go to 40
485 end do
486 end if
487 !
488 ! -- When word is not quoted, space, comma, or tab will terminate.
489 else
490 do j = i, linlen
491 if (line(j:j) == ' ' .or. line(j:j) == ',' .or. &
492 line(j:j) == tab) go to 40
493 end do
494 end if
495 !
496 ! -- End of line without finding end of word; set end of word to
497 ! end of line.
498 j = linlen + 1
499 !
500 ! -- Found end of word; set J to point to last character in WORD and
501 ! set ICOL to point to location for scanning for another word.
50240 icol = j + 1
503 j = j - 1
504 if (j < i) go to 100
505 istart = i
506 istop = j
507 !
508 ! -- Convert word to upper case and RETURN if NCODE is 1.
509 if (ncode == 1) then
510 idiff = ichar('a') - ichar('A')
511 do k = istart, istop
512 if (line(k:k) >= 'a' .and. line(k:k) <= 'z') &
513 line(k:k) = char(ichar(line(k:k)) - idiff)
514 end do
515 return
516 end if
517 !
518 ! -- Convert word to a number if requested.
519100 if (ncode == 2 .or. ncode == 3) then
520 l = istop - istart + 1
521 if (l < 1) go to 200
522 if (istart > linlen) then
523 ! support legacy urword behavior to return a zero value when
524 ! no more data is on the line
525 if (ncode == 2) n = 0
526 if (ncode == 3) r = dzero
527 else
528 if (ncode == 2) read (line(istart:istop), *, err=200) n
529 if (ncode == 3) read (line(istart:istop), *, err=200) r
530 end if
531 end if
532 return
533 !
534 ! -- Number conversion error.
535200 if (ncode == 3) then
536 string = 'a real number'
537 l = 13
538 else
539 string = 'an integer'
540 l = 10
541 end if
542 !
543 ! -- If output unit is negative, set last character of string to 'E'.
544 if (iout < 0) then
545 n = 0
546 r = 0.
547 line(linlen + 1:linlen + 1) = 'E'
548 return
549 !
550 ! -- If output unit is positive; write a message to output unit.
551 else if (iout > 0) then
552 if (in > 0) then
553 write (msg_line, fmtmsgout1) in, line(istart:istop), string(1:l)
554 else
555 write (msg_line, fmtmsgout2) line(istart:istop), string(1:l)
556 end if
557 call write_message(msg_line, iunit=iout, skipbefore=1)
558 call write_message(line, iunit=iout, fmt='(1x,a)')
559 !
560 ! -- If output unit is 0; write a message to default output.
561 else
562 if (in > 0) then
563 write (msg_line, fmtmsgout1) in, line(istart:istop), string(1:l)
564 else
565 write (msg_line, fmtmsgout2) line(istart:istop), string(1:l)
566 end if
567 call write_message(msg_line, iunit=iout, skipbefore=1)
568 call write_message(line, iunit=iout, fmt='(1x,a)')
569 end if
570 !
571 ! -- STOP after storing error message.
572 call lowcase(string)
573 if (in > 0) then
574 write (msg, fmtmsgout3) in, line(istart:istop), trim(string)
575 else
576 write (msg, fmtmsgout4) line(istart:istop), trim(string)
577 end if
578 !
579 call store_error(msg)
580 call store_error(trim(line))
581 call store_error_unit(in)
582 end subroutine urword
583
584 !> @brief Print a label for a list
585 !<
586 subroutine ulstlb(iout, label, caux, ncaux, naux)
587 ! -- dummy
588 character(len=*) :: label
589 character(len=16) :: caux(ncaux)
590 ! -- local
591 character(len=400) buf
592 ! -- constant
593 character(len=1) dash(400)
594 data dash/400*'-'/
595 ! -- formats
596 character(len=*), parameter :: fmtmsgout1 = "(1x, a)"
597 character(len=*), parameter :: fmtmsgout2 = "(1x, 400a)"
598 !
599 ! -- Construct the complete label in BUF. Start with BUF=LABEL.
600 buf = label
601 !
602 ! -- Add auxiliary data names if there are any.
603 nbuf = len(label) + 9
604 if (naux > 0) then
605 do i = 1, naux
606 n1 = nbuf + 1
607 nbuf = nbuf + 16
608 buf(n1:nbuf) = caux(i)
609 end do
610 end if
611 !
612 ! -- Write the label.
613 write (iout, fmtmsgout1) buf(1:nbuf)
614 !
615 ! -- Add a line of dashes.
616 write (iout, fmtmsgout2) (dash(j), j=1, nbuf)
617 end subroutine ulstlb
618
619 !> @brief Write header records for cell-by-cell flow terms for one component
620 !! of flow plus auxiliary data using a list structure
621 !!
622 !! Each item in the list is written by module UBDSVB
623 !<
624 subroutine ubdsv4(kstp, kper, text, naux, auxtxt, ibdchn, &
625 & ncol, nrow, nlay, nlist, iout, delt, pertim, totim)
626 ! -- dummy
627 character(len=16) :: text
628 character(len=16), dimension(:) :: auxtxt
629 real(dp), intent(in) :: delt, pertim, totim
630 ! -- formats
631 character(len=*), parameter :: fmt = &
632 & "(1X,'UBDSV4 SAVING ',A16,' ON UNIT',I7,' AT TIME STEP',I7,"// &
633 & "', STRESS PERIOD',I7)"
634 !
635 ! -- Write unformatted records identifying data
636 if (iout > 0) write (iout, fmt) text, ibdchn, kstp, kper
637 write (ibdchn) kstp, kper, text, ncol, nrow, -nlay
638 write (ibdchn) 5, delt, pertim, totim
639 write (ibdchn) naux + 1
640 if (naux > 0) write (ibdchn) (auxtxt(n), n=1, naux)
641 write (ibdchn) nlist
642 end subroutine ubdsv4
643
644 !> @brief Write one value of cell-by-cell flow plus auxiliary data using a
645 !! list structure
646 !<
647 subroutine ubdsvb(ibdchn, icrl, q, val, nvl, naux, laux)
648 ! -- dummy
649 real(dp), dimension(nvl) :: val
650 real(dp) :: q
651 !
652 ! -- Write cell number and flow rate
653 IF (naux > 0) then
654 n2 = laux + naux - 1
655 write (ibdchn) icrl, q, (val(n), n=laux, n2)
656 else
657 write (ibdchn) icrl, q
658 end if
659 end subroutine ubdsvb
660
661 !> @brief Output column numbers above a matrix printout
662 !!
663 !! nlbl1 is the start column label (number)
664 !! nlbl2 is the stop column label (number)
665 !! nspace is number of blank spaces to leave at start of line
666 !! ncpl is number of column numbers per line
667 !! ndig is number of characters in each column field
668 !! iout is output channel
669 !<
670 subroutine ucolno(nlbl1, nlbl2, nspace, ncpl, ndig, iout)
671 ! -- local
672 character(len=1) :: dot, space, dg, bf
673 dimension :: bf(1000), dg(10)
674 ! -- constants
675 data dg(1), dg(2), dg(3), dg(4), dg(5), dg(6), dg(7), dg(8), dg(9), dg(10)/ &
676 & '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'/
677 data dot, space/'.', ' '/
678 ! -- formats
679 character(len=*), parameter :: fmtmsgout1 = "(1x)"
680 character(len=*), parameter :: fmtmsgout2 = "(1x, 1000a1)"
681 !
682 ! -- Calculate # of columns to be printed (nlbl), width
683 ! of a line (ntot), number of lines (nwrap).
684 if (iout <= 0) return
685 write (iout, fmtmsgout1)
686 !
687 nlbl = nlbl2 - nlbl1 + 1
688 n = nlbl
689 !
690 if (nlbl < ncpl) n = ncpl
691 ntot = nspace + n * ndig
692 !
693 if (ntot > 1000) go to 50
694 nwrap = (nlbl - 1) / ncpl + 1
695 j1 = nlbl1 - ncpl
696 j2 = nlbl1 - 1
697 !
698 ! -- Build and print each line
699 do n = 1, nwrap
700 !
701 ! -- Clear the buffer (BF)
702 do i = 1, 1000
703 bf(i) = space
704 end do
705 nbf = nspace
706 !
707 ! -- Determine first (j1) and last (j2) column # for this line.
708 j1 = j1 + ncpl
709 j2 = j2 + ncpl
710 if (j2 > nlbl2) j2 = nlbl2
711 !
712 ! -- Load the column #'s into the buffer.
713 do j = j1, j2
714 nbf = nbf + ndig
715 i2 = j / 10
716 i1 = j - i2 * 10 + 1
717 bf(nbf) = dg(i1)
718 if (i2 == 0) go to 30
719 i3 = i2 / 10
720 i2 = i2 - i3 * 10 + 1
721 bf(nbf - 1) = dg(i2)
722 if (i3 == 0) go to 30
723 i4 = i3 / 10
724 i3 = i3 - i4 * 10 + 1
725 bf(nbf - 2) = dg(i3)
726 if (i4 == 0) go to 30
727 if (i4 > 9) then
728 ! -- If more than 4 digits, use "X" for 4th digit.
729 bf(nbf - 3) = 'X'
730 else
731 bf(nbf - 3) = dg(i4 + 1)
732 end if
73330 end do
734 !
735 ! -- Print the contents of the buffer (i.e. print the line).
736 write (iout, fmtmsgout2) (bf(i), i=1, nbf)
737 !
738 end do
739 !
740 ! -- Print a line of dots (for aesthetic purposes only).
74150 ntot = ntot
742 if (ntot > 1000) ntot = 1000
743 write (iout, fmtmsgout2) (dot, i=1, ntot)
744 end subroutine ucolno
745
746 !> @brief Print 1 layer array
747 !<
748 subroutine ulaprw(buf, text, kstp, kper, ncol, nrow, ilay, iprn, iout)
749 ! -- dummy
750 character(len=16) :: text
751 real(dp), dimension(ncol, nrow) :: buf
752 ! -- formats
753 character(len=*), parameter :: fmtmsgout1 = &
754 & "('1', /2x, a, ' IN LAYER ',I3,' AT END OF TIME STEP ',I3, &
755 & ' IN STRESS PERIOD ',I4/2x,75('-'))"
756 character(len=*), parameter :: fmtmsgout2 = &
757 & "('1',/1x,A,' FOR CROSS SECTION AT END OF TIME STEP',I3, &
758 & ' IN STRESS PERIOD ',I4/1x,79('-'))"
759 character(len=*), parameter :: fmtg10 = &
760 & "(1X,I3,2X,1PG10.3,10(1X,G10.3):/(5X,11(1X,G10.3)))"
761 character(len=*), parameter :: fmtg13 = &
762 & "(1x,I3,2x,1PG13.6,8(1x,G13.6):/(5x,9(1x,G13.6)))"
763 character(len=*), parameter :: fmtf7pt1 = &
764 & "(1x,I3,1x,15(1x,F7.1):/(5x,15(1x,F7.1)))"
765 character(len=*), parameter :: fmtf7pt2 = &
766 & "(1x,I3,1x,15(1x,F7.2):/(5x,15(1x,F7.2)))"
767 character(len=*), parameter :: fmtf7pt3 = &
768 & "(1x,I3,1x,15(1x,F7.3):/(5x,15(1x,F7.3)))"
769 character(len=*), parameter :: fmtf7pt4 = &
770 & "(1x,I3,1x,15(1x,F7.4):/(5x,15(1x,F7.4)))"
771 character(len=*), parameter :: fmtf5pt0 = &
772 & "(1x,I3,1x,20(1x,F5.0):/(5x,20(1x,F5.0)))"
773 character(len=*), parameter :: fmtf5pt1 = &
774 & "(1x,I3,1x,20(1x,F5.1):/(5x,20(1x,F5.1)))"
775 character(len=*), parameter :: fmtf5pt2 = &
776 & "(1x,I3,1x,20(1x,F5.2):/(5x,20(1x,F5.2)))"
777 character(len=*), parameter :: fmtf5pt3 = &
778 & "(1x,I3,1x,20(1x,F5.3):/(5x,20(1x,F5.3)))"
779 character(len=*), parameter :: fmtf5pt4 = &
780 & "(1x,I3,1x,20(1x,F5.4):/(5x,20(1x,F5.4)))"
781 character(len=*), parameter :: fmtg11 = &
782 & "(1x,I3,2x,1PG11.4,9(1x,G11.4):/(5x,10(1x,G11.4)))"
783 character(len=*), parameter :: fmtf6pt0 = &
784 & "(1x,I3,1x,10(1x,F6.0):/(5X,10(1x,F6.0)))"
785 character(len=*), parameter :: fmtf6pt1 = &
786 & "(1x,I3,1x,10(1x,F6.1):/(5x,10(1x,F6.1)))"
787 character(len=*), parameter :: fmtf6pt2 = &
788 & "(1x,I3,1x,10(1x,F6.2):/(5x,10(1x,F6.2)))"
789 character(len=*), parameter :: fmtf6pt3 = &
790 & "(1x,I3,1x,10(1x,F6.3):/(5x,10(1x,F6.3)))"
791 character(len=*), parameter :: fmtf6pt4 = &
792 & "(1x,I3,1x,10(1x,F6.4):/(5x,10(1x,F6.4)))"
793 character(len=*), parameter :: fmtf6pt5 = &
794 & "(1x,I3,1x,10(1x,F6.5):/(5x,10(1x,F6.5)))"
795 character(len=*), parameter :: fmtg12 = &
796 & "(1x,I3,2x,1PG12.5,4(1x,G12.5):/(5x,5(1x,G12.5)))"
797 character(len=*), parameter :: fmtg11pt4 = &
798 & "(1x,I3,2x,1PG11.4,5(1x,G11.4):/(5x,6(1x,G11.4)))"
799 character(len=*), parameter :: fmtg9pt2 = &
800 & "(1x,I3,2x,1PG9.2,6(1x,G9.2):/(5x,7(1x,G9.2)))"
801 !
802 if (iout <= 0) return
803 ! -- Print a header depending on ilay
804 if (ilay > 0) then
805 write (iout, fmtmsgout1) text, ilay, kstp, kper
806 else if (ilay < 0) then
807 write (iout, fmtmsgout2) text, kstp, kper
808 end if
809 !
810 ! -- Make sure the format code (ip or iprn) is between 1 and 21
811 ip = iprn
812 if (ip < 1 .or. ip > 21) ip = 12
813 !
814 ! -- Call the utility module ucolno to print column numbers.
815 if (ip == 1) call ucolno(1, ncol, 0, 11, 11, iout)
816 if (ip == 2) call ucolno(1, ncol, 0, 9, 14, iout)
817 if (ip >= 3 .and. ip <= 6) call ucolno(1, ncol, 3, 15, 8, iout)
818 if (ip >= 7 .and. ip <= 11) call ucolno(1, ncol, 3, 20, 6, iout)
819 if (ip == 12) call ucolno(1, ncol, 0, 10, 12, iout)
820 if (ip >= 13 .and. ip <= 18) call ucolno(1, ncol, 3, 10, 7, iout)
821 if (ip == 19) call ucolno(1, ncol, 0, 5, 13, iout)
822 if (ip == 20) call ucolno(1, ncol, 0, 6, 12, iout)
823 if (ip == 21) call ucolno(1, ncol, 0, 7, 10, iout)
824 !
825 ! -- Loop through the rows printing each one in its entirety.
826 do i = 1, nrow
827 select case (ip)
828 !
829 case (1)
830 ! -- format 11G10.3
831 write (iout, fmtg10) i, (buf(j, i), j=1, ncol)
832 !
833 case (2)
834 ! -- format 9G13.6
835 write (iout, fmtg13) i, (buf(j, i), j=1, ncol)
836 !
837 case (3)
838 ! -- format 15F7.1
839 write (iout, fmtf7pt1) i, (buf(j, i), j=1, ncol)
840 !
841 case (4)
842 ! -- format 15F7.2
843 write (iout, fmtf7pt2) i, (buf(j, i), j=1, ncol)
844 !
845 case (5)
846 ! -- format 15F7.3
847 write (iout, fmtf7pt3) i, (buf(j, i), j=1, ncol)
848 !
849 case (6)
850 ! -- format 15F7.4
851 write (iout, fmtf7pt4) i, (buf(j, i), j=1, ncol)
852 !
853 case (7)
854 ! -- format 20F5.0
855 write (iout, fmtf5pt0) i, (buf(j, i), j=1, ncol)
856 !
857 case (8)
858 ! -- format 20F5.1
859 write (iout, fmtf5pt1) i, (buf(j, i), j=1, ncol)
860 !
861 case (9)
862 ! -- format 20F5.2
863 write (iout, fmtf5pt2) i, (buf(j, i), j=1, ncol)
864 !
865 case (10)
866 ! -- format 20F5.3
867 write (iout, fmtf5pt3) i, (buf(j, i), j=1, ncol)
868 !
869 case (11)
870 ! -- format 20F5.4
871 write (iout, fmtf5pt4) i, (buf(j, i), j=1, ncol)
872 !
873 case (12)
874 ! -- format 10G11.4
875 write (iout, fmtg11) i, (buf(j, i), j=1, ncol)
876 !
877 case (13)
878 ! -- format 10F6.0
879 write (iout, fmtf6pt0) i, (buf(j, i), j=1, ncol)
880 !
881 case (14)
882 ! -- format 10F6.1
883 write (iout, fmtf6pt1) i, (buf(j, i), j=1, ncol)
884 !
885 case (15)
886 ! -- format 10F6.2
887 write (iout, fmtf6pt2) i, (buf(j, i), j=1, ncol)
888 !
889 case (16)
890 ! -- format 10F6.3
891 write (iout, fmtf6pt3) i, (buf(j, i), j=1, ncol)
892 !
893 case (17)
894 ! -- format 10F6.4
895 write (iout, fmtf6pt4) i, (buf(j, i), j=1, ncol)
896 !
897 case (18)
898 ! -- format 10F6.5
899 write (iout, fmtf6pt5) i, (buf(j, i), j=1, ncol)
900 !
901 case (19)
902 ! -- format 5G12.5
903 write (iout, fmtg12) i, (buf(j, i), j=1, ncol)
904 !
905 case (20)
906 ! -- format 6G11.4
907 write (iout, fmtg11pt4) i, (buf(j, i), j=1, ncol)
908 !
909 case (21)
910 ! -- format 7G9.2
911 write (iout, fmtg9pt2) i, (buf(j, i), j=1, ncol)
912 !
913 end select
914 end do
915 !
916 ! -- Flush file
917 flush (iout)
918 end subroutine ulaprw
919
920 !> @brief Save 1 layer array on disk
921 !<
922 subroutine ulasav(buf, text, kstp, kper, pertim, totim, ncol, nrow, &
923 ilay, ichn)
924 ! -- dummy
925 character(len=16) :: text
926 real(dp), dimension(ncol, nrow) :: buf
927 real(dp) :: pertim, totim
928 !
929 ! -- Write an unformatted record containing identifying information
930 write (ichn) kstp, kper, pertim, totim, text, ncol, nrow, ilay
931 !
932 ! -- Write an unformatted record containing array values. The array is
933 ! dimensioned (ncol,nrow)
934 write (ichn) ((buf(ic, ir), ic=1, ncol), ir=1, nrow)
935 !
936 ! -- flush file
937 flush (ichn)
938 end subroutine ulasav
939
940 !> @brief Record cell-by-cell flow terms for one component of flow as a 3-D
941 !! array with extra record to indicate delt, pertim, and totim
942 !<
943 subroutine ubdsv1(kstp, kper, text, ibdchn, buff, ncol, nrow, nlay, iout, &
944 delt, pertim, totim)
945 implicit none
946 ! -- dummy
947 integer(I4B), intent(in) :: kstp
948 integer(I4B), intent(in) :: kper
949 character(len=*), intent(in) :: text
950 integer(I4B), intent(in) :: ibdchn
951 real(dp), dimension(:), intent(in) :: buff
952 integer(I4B), intent(in) :: ncol
953 integer(I4B), intent(in) :: nrow
954 integer(I4B), intent(in) :: nlay
955 integer(I4B), intent(in) :: iout
956 real(dp), intent(in) :: delt
957 real(dp), intent(in) :: pertim
958 real(dp), intent(in) :: totim
959 ! -- format
960 character(len=*), parameter :: fmt = &
961 & "(1X,'UBDSV1 SAVING ',A16,' ON UNIT',I7,' AT TIME STEP',I7,"// &
962 & "', STRESS PERIOD',I7)"
963 !
964 ! -- Write records
965 if (iout > 0) write (iout, fmt) text, ibdchn, kstp, kper
966 write (ibdchn) kstp, kper, text, ncol, nrow, -nlay
967 write (ibdchn) 1, delt, pertim, totim
968 write (ibdchn) buff
969 !
970 ! -- flush file
971 flush (ibdchn)
972 end subroutine ubdsv1
973
974 !> @brief Write header records for cell-by-cell flow terms for one component
975 !! of flow.
976 !!
977 !! Each item in the list is written by module ubdsvc
978 !<
979 subroutine ubdsv06(kstp, kper, text, modelnam1, paknam1, modelnam2, paknam2, &
980 ibdchn, naux, auxtxt, ncol, nrow, nlay, nlist, iout, &
981 delt, pertim, totim)
982 implicit none
983 ! -- dummy
984 integer(I4B), intent(in) :: kstp
985 integer(I4B), intent(in) :: kper
986 character(len=*), intent(in) :: text
987 character(len=*), intent(in) :: modelnam1
988 character(len=*), intent(in) :: paknam1
989 character(len=*), intent(in) :: modelnam2
990 character(len=*), intent(in) :: paknam2
991 integer(I4B), intent(in) :: naux
992 character(len=16), dimension(:), intent(in) :: auxtxt
993 integer(I4B), intent(in) :: ibdchn
994 integer(I4B), intent(in) :: ncol
995 integer(I4B), intent(in) :: nrow
996 integer(I4B), intent(in) :: nlay
997 integer(I4B), intent(in) :: nlist
998 integer(I4B), intent(in) :: iout
999 real(dp), intent(in) :: delt
1000 real(dp), intent(in) :: pertim
1001 real(dp), intent(in) :: totim
1002 ! -- local
1003 integer(I4B) :: n
1004 ! -- format
1005 character(len=*), parameter :: fmt = &
1006 & "(1X,'UBDSV06 SAVING ',A16,' IN MODEL ',A16,' PACKAGE ',A16,"// &
1007 & "'CONNECTED TO MODEL ',A16,' PACKAGE ',A16,"// &
1008 & "' ON UNIT',I7,' AT TIME STEP',I7,', STRESS PERIOD',I7)"
1009 !
1010 ! -- Write unformatted records identifying data.
1011 if (iout > 0) write (iout, fmt) text, modelnam1, paknam1, modelnam2, &
1012 paknam2, ibdchn, kstp, kper
1013 write (ibdchn) kstp, kper, text, ncol, nrow, -nlay
1014 write (ibdchn) 6, delt, pertim, totim
1015 write (ibdchn) modelnam1
1016 write (ibdchn) paknam1
1017 write (ibdchn) modelnam2
1018 write (ibdchn) paknam2
1019 write (ibdchn) naux + 1
1020 if (naux > 0) write (ibdchn) (auxtxt(n), n=1, naux)
1021 write (ibdchn) nlist
1022 end subroutine ubdsv06
1023
1024 !> @brief Write one value of cell-by-cell flow using a list structure.
1025 !!
1026 !! From node (n) and to node (n2) are written to the file
1027 !<
1028 subroutine ubdsvc(ibdchn, n, q, naux, aux)
1029 implicit none
1030 ! -- dummy
1031 integer(I4B), intent(in) :: ibdchn
1032 integer(I4B), intent(in) :: n
1033 real(dp), intent(in) :: q
1034 integer(I4B), intent(in) :: naux
1035 real(dp), dimension(naux), intent(in) :: aux
1036 ! -- local
1037 integer(I4B) :: nn
1038 !
1039 ! -- Write record
1040 if (naux > 0) then
1041 write (ibdchn) n, q, (aux(nn), nn=1, naux)
1042 else
1043 write (ibdchn) n, q
1044 end if
1045 end subroutine ubdsvc
1046
1047 !> @brief Write one value of cell-by-cell flow using a list structure.
1048 !!
1049 !! From node (n) and to node (n2) are written to the file
1050 !<
1051 subroutine ubdsvd(ibdchn, n, n2, q, naux, aux)
1052 implicit none
1053 ! -- dummy
1054 integer(I4B), intent(in) :: ibdchn
1055 integer(I4B), intent(in) :: n
1056 integer(I4B), intent(in) :: n2
1057 real(dp), intent(in) :: q
1058 integer(I4B), intent(in) :: naux
1059 real(dp), dimension(naux), intent(in) :: aux
1060 ! -- local
1061 integer(I4B) :: nn
1062 !
1063 ! -- Write record
1064 if (naux > 0) then
1065 write (ibdchn) n, n2, q, (aux(nn), nn=1, naux)
1066 else
1067 write (ibdchn) n, n2, q
1068 end if
1069 end subroutine ubdsvd
1070
1071 !> @brief Perform a case-insensitive comparison of two words
1072 !<
1073 logical function same_word(word1, word2)
1074 implicit none
1075 ! -- dummy
1076 character(len=*), intent(in) :: word1, word2
1077 ! -- local
1078 character(len=200) :: upword1, upword2
1079 !
1080 upword1 = word1
1081 call upcase(upword1)
1082 upword2 = word2
1083 call upcase(upword2)
1084 same_word = (upword1 == upword2)
1085 end function same_word
1086
1087 !> @brief Function for string manipulation
1088 !<
1089 function str_pad_left(str, width) result(res)
1090 ! -- local
1091 character(len=*), intent(in) :: str
1092 integer, intent(in) :: width
1093 ! -- Return
1094 character(len=max(len_trim(str), width)) :: res
1095 !
1096 res = str
1097 res = adjustr(res)
1098 end function
1099
1100 subroutine unitinquire(iu)
1101 ! -- dummy
1102 integer(I4B) :: iu
1103 ! -- local
1104 character(len=LINELENGTH) :: line
1105 character(len=100) :: fname, ac, act, fm, frm, seq, unf
1106 ! -- format
1107 character(len=*), parameter :: fmta = &
1108 &"('unit:',i4,' name:',a,' access:',a,' action:',a)"
1109 character(len=*), parameter :: fmtb = &
1110 &"(' formatted:',a,' sequential:',a,' unformatted:',a,' form:',a)"
1111 !
1112 ! -- set strings using inquire statement
1113 inquire (unit=iu, name=fname, access=ac, action=act, formatted=fm, &
1114 sequential=seq, unformatted=unf, form=frm)
1115 !
1116 ! -- write the results of the inquire statement
1117 write (line, fmta) iu, trim(fname), trim(ac), trim(act)
1118 call write_message(line)
1119 write (line, fmtb) trim(fm), trim(seq), trim(unf), trim(frm)
1120 call write_message(line)
1121 end subroutine unitinquire
1122
1123 !> @brief Parse a line into words.
1124 !!
1125 !! Blanks and commas are recognized as delimiters. Multiple blanks between
1126 !! words is OK, but multiple commas between words is treated as an error.
1127 !! Quotation marks are not recognized as delimiters.
1128 !<
1129 subroutine parseline(line, nwords, words, inunit, filename)
1130 ! -- modules
1131 use constantsmodule, only: linelength
1132 implicit none
1133 ! -- dummy
1134 character(len=*), intent(in) :: line
1135 integer(I4B), intent(inout) :: nwords
1136 character(len=*), allocatable, dimension(:), intent(inout) :: words
1137 integer(I4B), intent(in), optional :: inunit
1138 character(len=*), intent(in), optional :: filename
1139 ! -- local
1140 integer(I4B) :: i, idum, istart, istop, linelen, lloc
1141 real(dp) :: rdum
1142 !
1143 nwords = 0
1144 if (allocated(words)) then
1145 deallocate (words)
1146 end if
1147 linelen = len(line)
1148 !
1149 ! -- get the number of words in a line and allocate words array
1150 nwords = get_nwords(line)
1151 allocate (words(nwords))
1152 !
1153 ! -- Populate words array and return
1154 lloc = 1
1155 do i = 1, nwords
1156 call urword(line, lloc, istart, istop, 0, idum, rdum, 0, 0)
1157 words(i) = line(istart:istop)
1158 end do
1159 end subroutine parseline
1160
1161 !> @brief Print 1 layer array with user formatting in wrap format
1162 !<
1163 subroutine ulaprufw(ncol, nrow, kstp, kper, ilay, iout, buf, text, userfmt, &
1164 nvalues, nwidth, editdesc)
1165 implicit none
1166 ! -- dummy
1167 integer(I4B), intent(in) :: ncol, nrow, kstp, kper, ilay, iout
1168 real(dp), dimension(ncol, nrow), intent(in) :: buf
1169 character(len=*), intent(in) :: text
1170 character(len=*), intent(in) :: userfmt
1171 integer(I4B), intent(in) :: nvalues, nwidth
1172 character(len=1), intent(in) :: editdesc
1173 ! -- local
1174 integer(I4B) :: i, j, nspaces
1175 ! -- formats
1176 character(len=*), parameter :: fmtmsgout1 = &
1177 "('1',/2X,A,' IN LAYER ',I3,' AT END OF TIME STEP ',I3, &
1178& ' IN STRESS PERIOD ',I4/2X,75('-'))"
1179 character(len=*), parameter :: fmtmsgout2 = &
1180 "('1',/1X,A,' FOR CROSS SECTION AT END OF TIME STEP',I3, &
1181& ' IN STRESS PERIOD ',I4/1X,79('-'))"
1182 !
1183 if (iout <= 0) return
1184 ! -- Print a header depending on ILAY
1185 if (ilay > 0) then
1186 write (iout, fmtmsgout1) trim(text), ilay, kstp, kper
1187 else if (ilay < 0) then
1188 write (iout, fmtmsgout2) trim(text), kstp, kper
1189 end if
1190 !
1191 ! -- Print column numbers.
1192 nspaces = 0
1193 if (editdesc == 'F') nspaces = 3
1194 call ucolno(1, ncol, nspaces, nvalues, nwidth + 1, iout)
1195 !
1196 ! -- Loop through the rows, printing each one in its entirety.
1197 do i = 1, nrow
1198 write (iout, userfmt) i, (buf(j, i), j=1, ncol)
1199 end do
1200 !
1201 ! -- flush file
1202 flush (iout)
1203 end subroutine ulaprufw
1204
1205 !> @brief This function reads a line of arbitrary length and returns it.
1206 !!
1207 !! The returned string can be stored in a deferred-length character variable,
1208 !! for example:
1209 !!
1210 !! integer(I4B) :: iu
1211 !! character(len=:), allocatable :: my_string
1212 !! logical :: eof
1213 !! iu = 8
1214 !! open(iu,file='my_file')
1215 !! my_string = read_line(iu, eof)
1216 !<
1217 function read_line(iu, eof) result(astring)
1218 !
1219 implicit none
1220 ! -- dummy
1221 integer(I4B), intent(in) :: iu
1222 logical, intent(out) :: eof
1223 character(len=:), allocatable :: astring
1224 ! -- local
1225 integer(I4B) :: isize, istat
1226 character(len=256) :: buffer
1227 character(len=1000) :: ermsg, fname
1228 character(len=7) :: fmtd
1229 logical :: lop
1230 ! -- formats
1231 character(len=*), parameter :: fmterrmsg1 = &
1232 & "('Error in read_line: File ',i0,' is not open.')"
1233 character(len=*), parameter :: fmterrmsg2 = &
1234 & "('Error in read_line: Attempting to read text ' // &
1235 & 'from unformatted file: ""',a,'""')"
1236 character(len=*), parameter :: fmterrmsg3 = &
1237 & "('Error reading from file ""',a,'"" opened on unit ',i0, &
1238 & ' in read_line.')"
1239 !
1240 astring = ''
1241 eof = .false.
1242 do
1243 read (iu, '(a)', advance='NO', iostat=istat, size=isize, end=99) buffer
1244 if (istat > 0) then
1245 ! Determine error if possible, report it, and stop.
1246 if (iu <= 0) then
1247 ermsg = 'Programming error in call to read_line: '// &
1248 'Attempt to read from unit number <= 0'
1249 else
1250 inquire (unit=iu, opened=lop, name=fname, formatted=fmtd)
1251 if (.not. lop) then
1252 write (ermsg, fmterrmsg1) iu
1253 elseif (fmtd == 'NO' .or. fmtd == 'UNKNOWN') then
1254 write (ermsg, fmterrmsg2) trim(fname)
1255 else
1256 write (ermsg, fmterrmsg3) trim(fname), iu
1257 end if
1258 end if
1259 call store_error(ermsg)
1260 call store_error_unit(iu)
1261 end if
1262 astring = astring//buffer(:isize)
1263 ! -- An end-of-record condition stops the loop.
1264 if (istat < 0) then
1265 return
1266 end if
1267 end do
1268 !
1269 return
127099 continue
1271 !
1272 ! An end-of-file condition returns an empty string.
1273 eof = .true.
1274 end function read_line
1275
1276 subroutine getfilefrompath(pathname, filename)
1277 implicit none
1278 ! -- dummy
1279 character(len=*), intent(in) :: pathname
1280 character(len=*), intent(out) :: filename
1281 ! -- local
1282 integer(I4B) :: i, istart, istop, lenpath
1283 character(len=1) :: fs = '/'
1284 character(len=1) :: bs = '\'
1285 !
1286 filename = ''
1287 lenpath = len_trim(pathname)
1288 istart = 1
1289 istop = lenpath
1290 loop: do i = lenpath, 1, -1
1291 if (pathname(i:i) == fs .or. pathname(i:i) == bs) then
1292 if (i == istop) then
1293 istop = istop - 1
1294 else
1295 istart = i + 1
1296 exit loop
1297 end if
1298 end if
1299 end do loop
1300 if (istop >= istart) then
1301 filename = pathname(istart:istop)
1302 end if
1303 end subroutine getfilefrompath
1304
1305 !> @brief Starting at position icol, define string as line(istart:istop).
1306 !!
1307 !! If string can be interpreted as an integer(I4B), return integer in idnum
1308 !! argument. If token is not an integer(I4B), assume it is a boundary name,
1309 !! return NAMEDBOUNDFLAG in idnum, convert string to uppercase and return it
1310 !! in bndname.
1311 !<
1312 subroutine extract_idnum_or_bndname(line, icol, istart, istop, idnum, bndname)
1313 implicit none
1314 ! -- dummy
1315 character(len=*), intent(inout) :: line
1316 integer(I4B), intent(inout) :: icol, istart, istop
1317 integer(I4B), intent(out) :: idnum
1318 character(len=LENBOUNDNAME), intent(out) :: bndname
1319 ! -- local
1320 integer(I4B) :: istat, ndum, ncode = 0
1321 real(dp) :: rdum
1322 !
1323 call urword(line, icol, istart, istop, ncode, ndum, rdum, 0, 0)
1324 read (line(istart:istop), *, iostat=istat) ndum
1325 if (istat == 0) then
1326 idnum = ndum
1327 bndname = ''
1328 else
1329 idnum = namedboundflag
1330 bndname = line(istart:istop)
1331 call upcase(bndname)
1332 end if
1333 end subroutine extract_idnum_or_bndname
1334
1335 !> @brief Read auxiliary variables from an input line
1336 !<
1337 subroutine urdaux(naux, inunit, iout, lloc, istart, istop, auxname, line, text)
1338 ! -- modules
1340 use constantsmodule, only: lenauxname
1341 ! -- implicit
1342 implicit none
1343 ! -- dummy
1344 integer(I4B), intent(inout) :: naux
1345 integer(I4B), intent(in) :: inunit
1346 integer(I4B), intent(in) :: iout
1347 integer(I4B), intent(inout) :: lloc
1348 integer(I4B), intent(inout) :: istart
1349 integer(I4B), intent(inout) :: istop
1350 character(len=LENAUXNAME), allocatable, dimension(:), intent(inout) :: auxname
1351 character(len=*), intent(inout) :: line
1352 character(len=*), intent(in) :: text
1353 ! -- local
1354 integer(I4B) :: n, linelen
1355 integer(I4B) :: iauxlen
1356 real(dp) :: rval
1357 !
1358 linelen = len(line)
1359 if (naux > 0) then
1360 write (errmsg, '(a)') 'Auxiliary variables already specified. '// &
1361 & 'Auxiliary variables must be specified on one line in the '// &
1362 & 'options block.'
1363 call store_error(errmsg)
1364 call store_error_unit(inunit)
1365 end if
1366 auxloop: do
1367 call urword(line, lloc, istart, istop, 1, n, rval, iout, inunit)
1368 if (istart >= linelen) exit auxloop
1369 iauxlen = istop - istart + 1
1370 if (iauxlen > lenauxname) then
1371 write (errmsg, '(a, a, a, i0, a, i0, a)') &
1372 'Found auxiliary variable (', line(istart:istop), &
1373 ') with a name of size ', iauxlen, &
1374 '. Auxiliary variable names must be len than or equal&
1375 & to ', lenauxname, ' characters.'
1376 call store_error(errmsg)
1377 call store_error_unit(inunit)
1378 end if
1379 naux = naux + 1
1380 call expandarray(auxname)
1381 auxname(naux) = line(istart:istop)
1382 if (iout > 0) then
1383 write (iout, "(4X,'AUXILIARY ',a,' VARIABLE: ',A)") &
1384 trim(adjustl(text)), auxname(naux)
1385 end if
1386 end do auxloop
1387 end subroutine urdaux
1388
1389 !> @brief Define the print or save format
1390 !!
1391 !! Define cdatafmp as a Fortran output format based on user input. Also define
1392 !! nvalues, nwidth, and editdesc.
1393 !!
1394 !! Syntax for linein:
1395 !! COLUMNS nval WIDTH nwid [DIGITS ndig [options]]
1396 !!
1397 !! Where:
1398 !! nval = Number of values per line.
1399 !! nwid = Number of character places to be used for each value.
1400 !! ndig = Number of digits to the right of the decimal point (required
1401 !! for real array).
1402 !! options are:
1403 !! editoption: One of [EXPONENTIAL, FIXED, GENERAL, SCIENTIFIC]
1404 !! A default value should be passed in for editdesc as G, I, E, F, or S.
1405 !! If I is passed in, then the fortran format will be for an integer variable.
1406 !<
1407 subroutine print_format(linein, cdatafmp, editdesc, nvaluesp, nwidthp, inunit)
1408 ! -- dummy
1409 character(len=*), intent(in) :: linein
1410 character(len=*), intent(inout) :: cdatafmp
1411 character(len=*), intent(inout) :: editdesc
1412 integer(I4B), intent(inout) :: nvaluesp
1413 integer(I4B), intent(inout) :: nwidthp
1414 integer(I4B), intent(in) :: inunit
1415 ! -- local
1416 character(len=len(linein)) :: line
1417 character(len=20), dimension(:), allocatable :: words
1418 character(len=100) :: ermsg
1419 integer(I4B) :: ndigits = 0, nwords = 0
1420 integer(I4B) :: i, ierr
1421 logical :: isint
1422 !
1423 ! -- Parse line and initialize values
1424 line(:) = linein(:)
1425 call parseline(line, nwords, words, inunit)
1426 ierr = 0
1427 i = 0
1428 isint = .false.
1429 if (editdesc == 'I') isint = .true.
1430 !
1431 ! -- Check array name
1432 if (nwords < 1) then
1433 ermsg = 'Could not build PRINT_FORMAT from line'//trim(line)
1434 call store_error(trim(ermsg))
1435 ermsg = 'Syntax is: COLUMNS <columns> WIDTH <width> DIGITS &
1436 &<digits> <format>'
1437 call store_error(trim(ermsg))
1438 call store_error_unit(inunit)
1439 end if
1440 !
1441 ermsg = 'Error setting PRINT_FORMAT. Syntax is incorrect in line:'
1442 if (nwords >= 4) then
1443 if (.not. same_word(words(1), 'COLUMNS')) ierr = 1
1444 if (.not. same_word(words(3), 'WIDTH')) ierr = 1
1445 ! -- Read nvalues and nwidth
1446 if (ierr == 0) then
1447 read (words(2), *, iostat=ierr) nvaluesp
1448 end if
1449 if (ierr == 0) then
1450 read (words(4), *, iostat=ierr) nwidthp
1451 end if
1452 else
1453 ierr = 1
1454 end if
1455 if (ierr /= 0) then
1456 call store_error(ermsg)
1457 call store_error(line)
1458 ermsg = 'Syntax is: COLUMNS <columns> WIDTH <width> &
1459 &DIGITS <digits> <format>'
1460 call store_error(trim(ermsg))
1461 call store_error_unit(inunit)
1462 end if
1463 i = 4
1464 !
1465 if (.not. isint) then
1466 ! -- Check for DIGITS specification
1467 if (nwords >= 5) then
1468 if (.not. same_word(words(5), 'DIGITS')) ierr = 1
1469 ! -- Read ndigits
1470 read (words(6), *, iostat=ierr) ndigits
1471 else
1472 ierr = 1
1473 end if
1474 i = i + 2
1475 end if
1476 !
1477 ! -- Check for EXPONENTIAL | FIXED | GENERAL | SCIENTIFIC option.
1478 ! -- Check for LABEL, WRAP, and STRIP options.
1479 do
1480 i = i + 1
1481 if (i <= nwords) then
1482 call upcase(words(i))
1483 select case (words(i))
1484 case ('EXPONENTIAL')
1485 editdesc = 'E'
1486 if (isint) ierr = 1
1487 case ('FIXED')
1488 editdesc = 'F'
1489 if (isint) ierr = 1
1490 case ('GENERAL')
1491 editdesc = 'G'
1492 if (isint) ierr = 1
1493 case ('SCIENTIFIC')
1494 editdesc = 'S'
1495 if (isint) ierr = 1
1496 case default
1497 ermsg = 'Error in format specification. Unrecognized option: '//words(i)
1498 call store_error(ermsg)
1499 ermsg = 'Valid values are EXPONENTIAL, FIXED, GENERAL, or SCIENTIFIC.'
1500 call store_error(ermsg)
1501 call store_error_unit(inunit)
1502 end select
1503 else
1504 exit
1505 end if
1506 end do
1507 if (ierr /= 0) then
1508 call store_error(ermsg)
1509 call store_error(line)
1510 call store_error_unit(inunit)
1511 end if
1512 !
1513 ! -- Build the output format.
1514 select case (editdesc)
1515 case ('I')
1516 call buildintformat(nvaluesp, nwidthp, cdatafmp)
1517 case ('F')
1518 call buildfixedformat(nvaluesp, nwidthp, ndigits, cdatafmp)
1519 case ('E', 'G', 'S')
1520 call buildfloatformat(nvaluesp, nwidthp, ndigits, editdesc, cdatafmp)
1521 end select
1522 end subroutine print_format
1523
1524 !> @brief Build a fixed format for printing or saving a real array
1525 !<
1526 subroutine buildfixedformat(nvalsp, nwidp, ndig, outfmt, prowcolnum)
1527 implicit none
1528 ! -- dummy
1529 integer(I4B), intent(in) :: nvalsp, nwidp, ndig
1530 character(len=*), intent(inout) :: outfmt
1531 logical, intent(in), optional :: prowcolnum ! default true
1532 ! -- local
1533 character(len=8) :: cvalues, cwidth, cdigits
1534 character(len=60) :: ufmt
1535 logical :: prowcolnumlocal
1536 ! -- formats
1537 character(len=*), parameter :: fmtndig = "(i8)"
1538 !
1539 if (present(prowcolnum)) then
1540 prowcolnumlocal = prowcolnum
1541 else
1542 prowcolnumlocal = .true.
1543 end if
1544 !
1545 ! -- Convert integers to characters and left-adjust
1546 write (cdigits, fmtndig) ndig
1547 cdigits = adjustl(cdigits)
1548 !
1549 ! -- Build format for printing to the list file in wrap format
1550 write (cvalues, fmtndig) nvalsp
1551 cvalues = adjustl(cvalues)
1552 write (cwidth, fmtndig) nwidp
1553 cwidth = adjustl(cwidth)
1554 if (prowcolnumlocal) then
1555 ufmt = '(1x,i3,1x,'
1556 else
1557 ufmt = '(5x,'
1558 end if
1559 !
1560 ufmt = trim(ufmt)//cvalues
1561 ufmt = trim(ufmt)//'(1x,f'
1562 ufmt = trim(ufmt)//cwidth
1563 ufmt = trim(ufmt)//'.'
1564 ufmt = trim(ufmt)//cdigits
1565 ufmt = trim(ufmt)//'):/(5x,'
1566 ufmt = trim(ufmt)//cvalues
1567 ufmt = trim(ufmt)//'(1x,f'
1568 ufmt = trim(ufmt)//cwidth
1569 ufmt = trim(ufmt)//'.'
1570 ufmt = trim(ufmt)//cdigits
1571 ufmt = trim(ufmt)//')))'
1572 outfmt = ufmt
1573 end subroutine buildfixedformat
1574
1575 !> @brief Build a floating-point format for printing or saving a real array
1576 !<
1577 subroutine buildfloatformat(nvalsp, nwidp, ndig, editdesc, outfmt, prowcolnum)
1578 implicit none
1579 ! -- dummy
1580 integer(I4B), intent(in) :: nvalsp, nwidp, ndig
1581 character(len=*), intent(in) :: editdesc
1582 character(len=*), intent(inout) :: outfmt
1583 logical, intent(in), optional :: prowcolnum ! default true
1584 ! -- local
1585 character(len=8) :: cvalues, cwidth, cdigits
1586 character(len=60) :: ufmt
1587 logical :: prowcolnumlocal
1588 ! -- formats
1589 character(len=*), parameter :: fmtndig = "(i8)"
1590 !
1591 if (present(prowcolnum)) then
1592 prowcolnumlocal = prowcolnum
1593 else
1594 prowcolnumlocal = .true.
1595 end if
1596 !
1597 ! -- Build the format
1598 write (cdigits, fmtndig) ndig
1599 cdigits = adjustl(cdigits)
1600 ! -- Convert integers to characters and left-adjust
1601 write (cwidth, fmtndig) nwidp
1602 cwidth = adjustl(cwidth)
1603 ! -- Build format for printing to the list file
1604 write (cvalues, fmtndig) (nvalsp - 1)
1605 cvalues = adjustl(cvalues)
1606 if (prowcolnumlocal) then
1607 ufmt = '(1x,i3,2x,1p,'//editdesc
1608 else
1609 ufmt = '(6x,1p,'//editdesc
1610 end if
1611 ufmt = trim(ufmt)//cwidth
1612 ufmt = trim(ufmt)//'.'
1613 ufmt = trim(ufmt)//cdigits
1614 if (nvalsp > 1) then
1615 ufmt = trim(ufmt)//','
1616 ufmt = trim(ufmt)//cvalues
1617 ufmt = trim(ufmt)//'(1x,'
1618 ufmt = trim(ufmt)//editdesc
1619 ufmt = trim(ufmt)//cwidth
1620 ufmt = trim(ufmt)//'.'
1621 ufmt = trim(ufmt)//cdigits
1622 ufmt = trim(ufmt)//')'
1623 end if
1624 !
1625 ufmt = trim(ufmt)//':/(5x,'
1626 write (cvalues, fmtndig) nvalsp
1627 cvalues = adjustl(cvalues)
1628 ufmt = trim(ufmt)//cvalues
1629 ufmt = trim(ufmt)//'(1x,'
1630 ufmt = trim(ufmt)//editdesc
1631 ufmt = trim(ufmt)//cwidth
1632 ufmt = trim(ufmt)//'.'
1633 ufmt = trim(ufmt)//cdigits
1634 ufmt = trim(ufmt)//')))'
1635 outfmt = ufmt
1636 end subroutine buildfloatformat
1637
1638 !> @brief Build a format for printing or saving an integer array
1639 !<
1640 subroutine buildintformat(nvalsp, nwidp, outfmt, prowcolnum)
1641 implicit none
1642 ! -- dummy
1643 integer(I4B), intent(in) :: nvalsp, nwidp
1644 character(len=*), intent(inout) :: outfmt
1645 logical, intent(in), optional :: prowcolnum ! default true
1646 ! -- local
1647 character(len=8) :: cvalues, cwidth
1648 character(len=60) :: ufmt
1649 logical :: prowcolnumlocal
1650 ! -- formats
1651 character(len=*), parameter :: fmtndig = "(i8)"
1652 !
1653 if (present(prowcolnum)) then
1654 prowcolnumlocal = prowcolnum
1655 else
1656 prowcolnumlocal = .true.
1657 end if
1658 !
1659 ! -- Build format for printing to the list file in wrap format
1660 write (cvalues, fmtndig) nvalsp
1661 cvalues = adjustl(cvalues)
1662 write (cwidth, fmtndig) nwidp
1663 cwidth = adjustl(cwidth)
1664 if (prowcolnumlocal) then
1665 ufmt = '(1x,i3,1x,'
1666 else
1667 ufmt = '(5x,'
1668 end if
1669 ufmt = trim(ufmt)//cvalues
1670 ufmt = trim(ufmt)//'(1x,i'
1671 ufmt = trim(ufmt)//cwidth
1672 ufmt = trim(ufmt)//'):/(5x,'
1673 ufmt = trim(ufmt)//cvalues
1674 ufmt = trim(ufmt)//'(1x,i'
1675 ufmt = trim(ufmt)//cwidth
1676 ufmt = trim(ufmt)//')))'
1677 outfmt = ufmt
1678 end subroutine buildintformat
1679
1680 !> @brief Get the number of words in a string
1681 !<
1682 function get_nwords(line)
1683 ! -- return
1684 integer(I4B) :: get_nwords !< number of words in a string
1685 ! -- dummy
1686 character(len=*), intent(in) :: line !< line
1687 ! -- local
1688 integer(I4B) :: linelen
1689 integer(I4B) :: lloc
1690 integer(I4B) :: istart
1691 integer(I4B) :: istop
1692 integer(I4B) :: idum
1693 real(dp) :: rdum
1694 !
1695 ! -- initialize variables
1696 get_nwords = 0
1697 linelen = len(line)
1698 !
1699 ! -- Count words in line and allocate words array
1700 lloc = 1
1701 do
1702 call urword(line, lloc, istart, istop, 0, idum, rdum, 0, 0)
1703 if (istart == linelen) exit
1705 end do
1706 end function get_nwords
1707
1708 !> @brief Move the file pointer.
1709 !!
1710 !! Patterned after fseek, which is not supported as part of the fortran
1711 !! standard. For this subroutine to work the file must have been opened with
1712 !! access='stream' and action='readwrite'.
1713 !<
1714 subroutine fseek_stream(iu, offset, whence, status)
1715 ! -- dummy
1716 integer(I4B), intent(in) :: iu
1717 integer(I4B), intent(in) :: offset
1718 integer(I4B), intent(in) :: whence
1719 integer(I4B), intent(inout) :: status
1720 ! -- local
1721 integer(I8B) :: ipos
1722 character(len=20) :: file_action
1723 !
1724 inquire (unit=iu, size=ipos)
1725 !
1726 select case (whence)
1727 case (0)
1728 !
1729 ! -- whence = 0, offset is relative to start of file
1730 ipos = 0 + offset
1731 case (1)
1732 !
1733 ! -- whence = 1, offset is relative to current pointer position
1734 inquire (unit=iu, pos=ipos)
1735 ipos = ipos + offset
1736 case (2)
1737 !
1738 ! -- whence = 2, offset is relative to end of file
1739 inquire (unit=iu, size=ipos)
1740 ipos = ipos + offset
1741 end select
1742 !
1743 ! -- position the file pointer to ipos using read or write depending
1744 ! on the file action, since write fails on read-only files and
1745 ! read fails on write-only files
1746 inquire (unit=iu, action=file_action)
1747 if (trim(file_action) == 'READ') then
1748 read (iu, pos=ipos, iostat=status)
1749 else
1750 write (iu, pos=ipos, iostat=status)
1751 end if
1752 inquire (unit=iu, pos=ipos)
1753 end subroutine fseek_stream
1754
1755 !> @brief Read until non-comment line found and then return line.
1756 !!
1757 !! Different from u8rdcom in that line is a deferred length character string,
1758 !! which allows any length lines to be read using the get_line subroutine.
1759 !<
1760 subroutine u9rdcom(iin, iout, line, ierr)
1761 ! -- module
1762 use, intrinsic :: iso_fortran_env, only: iostat_end
1763 implicit none
1764 ! -- dummy
1765 integer(I4B), intent(in) :: iin
1766 integer(I4B), intent(in) :: iout
1767 character(len=:), allocatable, intent(inout) :: line
1768 integer(I4B), intent(out) :: ierr
1769 ! -- local
1770 character(len=:), allocatable :: linetemp
1771 character(len=2), parameter :: comment = '//'
1772 character(len=1), parameter :: tab = char(9)
1773 logical :: iscomment
1774 integer(I4B) :: i, j, l, istart, lsize
1775 !
1776 !readerrmsg = ''
1777 line = comment
1778 pcomments: do
1779 call get_line(iin, line, ierr)
1780 if (ierr == iostat_end) then
1781 ! -- End of file reached. Return with ierr = IOSTAT_END
1782 ! and line as an empty string
1783 line = ' '
1784 exit pcomments
1785 elseif (ierr /= 0) then
1786 ! -- Other error...report it
1787 call unitinquire(iin)
1788 write (errmsg, *) 'u9rdcom: Could not read from unit: ', iin
1789 call store_error(errmsg, terminate=.true.)
1790 end if
1791 if (len_trim(line) < 1) then
1792 line = comment
1793 cycle
1794 end if
1795 !
1796 ! -- Ensure that any initial tab characters are treated as spaces
1797 cleartabs: do
1798 !
1799 ! -- adjustl manually to avoid stack overflow
1800 lsize = len(line)
1801 istart = 1
1802 allocate (character(len=lsize) :: linetemp)
1803 do j = 1, lsize
1804 if (line(j:j) /= ' ' .and. line(j:j) /= ',' .and. &
1805 line(j:j) /= char(9)) then
1806 istart = j
1807 exit
1808 end if
1809 end do
1810 linetemp(:) = ' '
1811 linetemp(:) = line(istart:)
1812 line(:) = linetemp(:)
1813 deallocate (linetemp)
1814 !
1815 ! -- check for comment
1816 iscomment = .false.
1817 select case (line(1:1))
1818 case ('#')
1819 iscomment = .true.
1820 exit cleartabs
1821 case ('!')
1822 iscomment = .true.
1823 exit cleartabs
1824 case (tab)
1825 line(1:1) = ' '
1826 cycle cleartabs
1827 case default
1828 if (line(1:2) == comment) iscomment = .true.
1829 if (len_trim(line) < 1) iscomment = .true.
1830 exit cleartabs
1831 end select
1832 end do cleartabs
1833 !
1834 if (.not. iscomment) then
1835 exit pcomments
1836 else
1837 if (iout > 0) then
1838 !find the last non-blank character.
1839 l = len(line)
1840 do i = l, 1, -1
1841 if (line(i:i) /= ' ') then
1842 exit
1843 end if
1844 end do
1845 ! -- print the line up to the last non-blank character.
1846 write (iout, '(1x,a)') line(1:i)
1847 end if
1848 end if
1849 end do pcomments
1850 end subroutine u9rdcom
1851
1852 !> @brief Read an unlimited length line from unit number lun into a deferred-
1853 !! length character string (line).
1854 !!
1855 !! Tack on a single space to the end so that routines like URWORD continue to
1856 !! function as before.
1857 !<
1858 subroutine get_line(lun, line, iostat)
1859 ! -- dummy
1860 integer(I4B), intent(in) :: lun
1861 character(len=:), intent(out), allocatable :: line
1862 integer(I4B), intent(out) :: iostat
1863 ! -- local
1864 integer(I4B), parameter :: buffer_len = maxcharlen
1865 character(len=buffer_len) :: buffer
1866 character(len=:), allocatable :: linetemp
1867 integer(I4B) :: size_read, linesize
1868 character(len=1), parameter :: cr = char(13)
1869 character(len=1), parameter :: lf = char(10)
1870 !
1871 ! -- initialize
1872 line = ''
1873 linetemp = ''
1874 !
1875 ! -- process
1876 do
1877 read (lun, '(A)', iostat=iostat, advance='no', size=size_read) buffer
1878 if (is_iostat_eor(iostat)) then
1879 linesize = len(line)
1880 deallocate (linetemp)
1881 allocate (character(len=linesize) :: linetemp)
1882 linetemp(:) = line(:)
1883 deallocate (line)
1884 allocate (character(len=linesize + size_read + 1) :: line)
1885 line(:) = linetemp(:)
1886 line(linesize + 1:) = buffer(:size_read)
1887 linesize = len(line)
1888 line(linesize:linesize) = ' '
1889 iostat = 0
1890 exit
1891 else if (iostat == 0) then
1892 linesize = len(line)
1893 deallocate (linetemp)
1894 allocate (character(len=linesize) :: linetemp)
1895 linetemp(:) = line(:)
1896 deallocate (line)
1897 allocate (character(len=linesize + size_read) :: line)
1898 line(:) = linetemp(:)
1899 line(linesize + 1:) = buffer(:size_read)
1900 else
1901 exit
1902 end if
1903 end do
1904 !
1905 ! -- look for undetected end-of-record with isolated CR or LF
1906 linesize = len(line)
1907 crlfcheck: do i = 1, linesize
1908 if (line(i:i) .eq. cr .or. line(i:i) .eq. lf) then
1909 if (line(i:i) .eq. cr) then
1910 write (errmsg, '(a)') &
1911 'get_line: Found an isolated Carriage Return.'
1912 end if
1913 if (line(i:i) .eq. lf) then
1914 write (errmsg, '(a)') &
1915 'get_line: Found an isolated Line Feed.'
1916 end if
1917 write (errmsg, '(a,1x,a,a)') trim(errmsg), &
1918 'Replace with Carriage Return and Line Feed to', &
1919 ' read as two separate lines.'
1920 write (errmsg, '(a,1x,5a)') trim(errmsg), &
1921 'Line: "', line(1:i - 1), '|', line(i + 1:linesize), '"'
1922 call store_error(errmsg, terminate=.false.)
1923 call store_error_unit(lun, terminate=.true.)
1924 end if
1925 end do crlfcheck
1926 end subroutine get_line
1927
1928end module inputoutputmodule
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
@ tabcenter
centered table column
@ tabright
right justified table column
@ tableft
left justified table column
@ tabucstring
upper case string table data
@ tabstring
string table data
@ tabreal
real table data
@ tabinteger
integer table data
integer(i4b), parameter iulast
maximum file unit number (this allows for 9000 open files)
Definition Constants.f90:58
integer(i4b), parameter namedboundflag
named bound flag
Definition Constants.f90:49
integer(i4b), parameter iustart
starting file unit number
Definition Constants.f90:57
integer(i4b), parameter lenbigline
maximum length of a big line
Definition Constants.f90:15
integer(i4b), parameter lenauxname
maximum length of a aux variable
Definition Constants.f90:35
integer(i4b), parameter lenboundname
maximum length of a bound name
Definition Constants.f90:36
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
integer(i4b), parameter maxcharlen
maximum length of char string
Definition Constants.f90:47
subroutine, public buildintformat(nvalsp, nwidp, outfmt, prowcolnum)
Build a format for printing or saving an integer array.
subroutine, public assign_iounit(iounit, errunit, description)
assign io unit number
subroutine, public urdaux(naux, inunit, iout, lloc, istart, istop, auxname, line, text)
Read auxiliary variables from an input line.
logical function, public same_word(word1, word2)
Perform a case-insensitive comparison of two words.
subroutine, public getfilefrompath(pathname, filename)
subroutine, public ubdsvc(ibdchn, n, q, naux, aux)
Write one value of cell-by-cell flow using a list structure.
subroutine, public extract_idnum_or_bndname(line, icol, istart, istop, idnum, bndname)
Starting at position icol, define string as line(istart:istop).
subroutine, public ucolno(nlbl1, nlbl2, nspace, ncpl, ndig, iout)
Output column numbers above a matrix printout.
subroutine, public ubdsv1(kstp, kper, text, ibdchn, buff, ncol, nrow, nlay, iout, delt, pertim, totim)
Record cell-by-cell flow terms for one component of flow as a 3-D array with extra record to indicate...
subroutine, public ubdsv4(kstp, kper, text, naux, auxtxt, ibdchn, ncol, nrow, nlay, nlist, iout, delt, pertim, totim)
Write header records for cell-by-cell flow terms for one component of flow plus auxiliary data using ...
subroutine, public ubdsvb(ibdchn, icrl, q, val, nvl, naux, laux)
Write one value of cell-by-cell flow plus auxiliary data using a list structure.
integer(i4b) function, public getunit()
Get a free unit number.
subroutine get_line(lun, line, iostat)
Read an unlimited length line from unit number lun into a deferred- length character string (line).
subroutine, public lowcase(word)
Convert to lower case.
subroutine, public ulaprw(buf, text, kstp, kper, ncol, nrow, ilay, iprn, iout)
Print 1 layer array.
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
subroutine, public buildfixedformat(nvalsp, nwidp, ndig, outfmt, prowcolnum)
Build a fixed format for printing or saving a real array.
subroutine, public buildfloatformat(nvalsp, nwidp, ndig, editdesc, outfmt, prowcolnum)
Build a floating-point format for printing or saving a real array.
subroutine, public upcase(word)
Convert to upper case.
integer(i4b) function, public get_nwords(line)
Get the number of words in a string.
subroutine, public u9rdcom(iin, iout, line, ierr)
Read until non-comment line found and then return line.
subroutine, public fseek_stream(iu, offset, whence, status)
Move the file pointer.
character(len=max(len_trim(str), width)) function, public str_pad_left(str, width)
Function for string manipulation.
subroutine, public print_format(linein, cdatafmp, editdesc, nvaluesp, nwidthp, inunit)
Define the print or save format.
subroutine, public ubdsvd(ibdchn, n, n2, q, naux, aux)
Write one value of cell-by-cell flow using a list structure.
subroutine, public ulstlb(iout, label, caux, ncaux, naux)
Print a label for a list.
character(len=:) function, allocatable, public read_line(iu, eof)
This function reads a line of arbitrary length and returns it.
subroutine, public append_processor_id(name, proc_id)
Append processor id to a string.
subroutine, public ulaprufw(ncol, nrow, kstp, kper, ilay, iout, buf, text, userfmt, nvalues, nwidth, editdesc)
Print 1 layer array with user formatting in wrap format.
subroutine freeunitnumber(iu)
Assign a free unopened unit number.
subroutine, public ubdsv06(kstp, kper, text, modelnam1, paknam1, modelnam2, paknam2, ibdchn, naux, auxtxt, ncol, nrow, nlay, nlist, iout, delt, pertim, totim)
Write header records for cell-by-cell flow terms for one component of flow.
subroutine, public ulasav(buf, text, kstp, kper, pertim, totim, ncol, nrow, ilay, ichn)
Save 1 layer array on disk.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
subroutine, public unitinquire(iu)
subroutine, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
subroutine, public uwword(line, icol, ilen, ncode, c, n, r, fmt, alignment, sep)
Create a formatted line.
This module defines variable data types.
Definition kind.f90:8
Store and issue logging messages to output units.
Definition Message.f90:2
subroutine, public write_message(text, iunit, fmt, skipbefore, skipafter, advance)
Write a message to an output unit.
Definition Message.f90:212
character(len=20) access
Definition OpenSpec.f90:7
character(len=20), dimension(2) action
Definition OpenSpec.f90:7
character(len=20) form
Definition OpenSpec.f90:7
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
Definition Sim.f90:172
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b) iout
file unit number for simulation output
integer(i4b) iunext
next file unit number to assign
integer(i4b) proc_id
integer(i4b) isim_mode
simulation mode