24 integer(I4B),
public :: iuactive
25 integer(I4B),
private :: inunit
26 integer(I4B),
private :: iuext
27 integer(I4B),
private :: iout
28 integer(I4B),
private :: linesread
29 integer(I4B),
private :: lloc
30 character(len=LINELENGTH),
private :: blockname
31 character(len=LINELENGTH),
private :: blocknamefound
32 character(len=LENHUGELINE),
private :: laststring
33 character(len=:),
allocatable,
private :: line
67 integer(I4B),
intent(in) :: inunit
68 integer(I4B),
intent(in) :: iout
73 this%iuactive = inunit
92 if (this%inunit > 0)
then
93 inquire (unit=this%inunit, opened=lop)
99 if (this%iuext /= this%inunit .and. this%iuext > 0)
then
100 inquire (unit=this%iuext, opened=lop)
115 deallocate (this%line)
124 subroutine getblock(this, blockName, isFound, ierr, supportOpenClose, &
125 blockRequired, blockNameFound)
128 character(len=*),
intent(in) :: blockName
129 logical,
intent(out) :: isFound
130 integer(I4B),
intent(out) :: ierr
131 logical,
intent(in),
optional :: supportOpenClose
132 logical,
intent(in),
optional :: blockRequired
133 character(len=*),
intent(inout),
optional :: blockNameFound
135 logical :: continueRead
136 logical :: supportOpenCloseLocal
137 logical :: blockRequiredLocal
140 if (
present(supportopenclose))
then
141 supportopencloselocal = supportopenclose
143 supportopencloselocal = .false.
146 if (
present(blockrequired))
then
147 blockrequiredlocal = blockrequired
149 blockrequiredlocal = .true.
151 continueread = blockrequiredlocal
152 this%blockName = blockname
153 this%blockNameFound =
''
155 if (blockname ==
'*')
then
157 isfound, this%lloc, this%line, blocknamefound, &
160 this%blockNameFound = blocknamefound
166 call uget_block(this%line_reader, this%inunit, this%iout, &
167 this%blockName, ierr, isfound, &
168 this%lloc, this%line, this%iuext, continueread, &
169 supportopencloselocal)
170 if (isfound) this%blockNameFound = this%blockName
172 this%iuactive = this%iuext
184 logical,
intent(out) :: endOfBlock
188 integer(I4B) :: istart
189 integer(I4B) :: istop
191 character(len=10) :: key
201 if (lineread)
exit loop1
202 call this%line_reader%rdcom(this%iuext, this%iout, this%line, ierr)
204 call urword(this%line, this%lloc, istart, istop, 0, ival, rval, &
205 this%iout, this%iuext)
206 key = this%line(istart:istop)
208 if (key ==
'END' .or. key ==
'BEGIN')
then
210 this%blockNameFound, this%lloc, this%line, &
212 this%iuactive = this%iuext
215 elseif (key ==
'')
then
219 if (this%iuext /= this%inunit)
then
221 this%iuext = this%inunit
222 this%iuactive = this%inunit
224 errmsg =
'Unexpected end of file reached.'
226 call this%StoreErrorUnit()
230 this%linesRead = this%linesRead + 1
247 integer(I4B) :: istart
248 integer(I4B) :: istop
252 call urword(this%line, this%lloc, istart, istop, 2, i, rval, &
253 this%iout, this%iuext)
256 if (istart == istop .and. istop == len(this%line))
then
257 call this%ReadScalarError(
'INTEGER')
268 integer(I4B) :: nlines
273 nlines = this%linesRead
288 integer(I4B) :: istart
289 integer(I4B) :: istop
293 call urword(this%line, this%lloc, istart, istop, 3, ival, r, &
294 this%iout, this%iuext)
297 if (istart == istop .and. istop == len(this%line))
then
298 call this%ReadScalarError(
'DOUBLE PRECISION')
306 real(DP),
intent(inout) :: r
307 logical(LGP),
intent(inout) :: success
309 integer(I4B) :: istart
310 integer(I4B) :: istop
313 call urword(this%line, this%lloc, istart, istop, 3, ival, r, &
314 this%iout, this%iuext)
317 if (istart == istop .and. istop == len(this%line))
then
326 integer(I4B),
intent(inout) :: i
327 logical(LGP),
intent(inout) :: success
329 integer(I4B) :: istart
330 integer(I4B) :: istop
333 call urword(this%line, this%lloc, istart, istop, 2, i, rval, &
334 this%iout, this%iuext)
337 if (istart == istop .and. istop == len(this%line))
then
351 character(len=*),
intent(in) :: vartype
353 character(len=MAXCHARLEN - 100) :: linetemp
359 write (
errmsg,
'(3a)')
'Error in block ', trim(this%blockName),
'.'
361 trim(
errmsg),
' Could not read variable of type ', trim(vartype), &
362 " from the following line: '"
364 trim(
errmsg), trim(adjustl(this%line)),
"'."
366 call this%StoreErrorUnit()
378 character(len=*),
intent(out) :: string
379 logical,
optional,
intent(in) :: convertToUpper
381 integer(I4B) :: istart
382 integer(I4B) :: istop
384 integer(I4B) :: ncode
388 if (
present(converttoupper))
then
389 if (converttoupper)
then
398 call urword(this%line, this%lloc, istart, istop, ncode, &
399 ival, rval, this%iout, this%iuext)
400 string = this%line(istart:istop)
401 this%laststring = this%line(istart:istop)
413 character(len=*),
intent(out) :: string
416 call this%GetString(string, converttoupper=.true.)
427 character(len=:),
allocatable,
intent(out) :: line
429 integer(I4B) :: lastpos
430 integer(I4B) :: newlinelen
433 lastpos = len_trim(this%line)
434 newlinelen = lastpos - this%lloc + 2
435 newlinelen = max(newlinelen, 1)
436 allocate (
character(len=newlinelen) :: line)
437 line(:) = this%line(this%lloc:lastpos)
438 line(newlinelen:newlinelen) =
' '
450 logical :: endofblock
453 call this%GetNextLine(endofblock)
454 if (.not. endofblock)
then
455 errmsg =
"LOOKING FOR 'END "//trim(this%blockname)// &
456 "'. FOUND: "//
"'"//trim(this%line)//
"'."
458 call this%StoreErrorUnit()
470 integer(I4B),
intent(in) :: ndim
471 character(len=*),
intent(out) :: cellid
472 logical,
optional,
intent(in) :: flag_string
477 integer(I4B) :: istart
478 integer(I4B) :: istop
480 integer(I4B) :: istat
482 character(len=10) :: cint
483 character(len=100) :: firsttoken
486 if (
present(flag_string))
then
488 call urword(this%line, lloc, istart, istop, 0, ival, rval, this%iout, &
490 firsttoken = this%line(istart:istop)
491 read (firsttoken, *, iostat=istat) ival
501 j = this%GetInteger()
502 write (cint,
'(i0)') j
506 cellid = trim(cellid)//
' '//cint
519 character(len=*),
intent(out) :: line
534 logical,
intent(in),
optional :: terminate
536 logical :: lterminate
539 if (
present(terminate))
then
540 lterminate = terminate
574 errmsg =
"Invalid keyword '"//trim(this%laststring)// &
575 "' detected in block '"//trim(this%blockname)//
"'."
586 subroutine uget_block(line_reader, iin, iout, ctag, ierr, isfound, &
587 lloc, line, iuext, blockRequired, supportopenclose)
591 integer(I4B),
intent(in) :: iin
592 integer(I4B),
intent(in) :: iout
593 character(len=*),
intent(in) :: ctag
594 integer(I4B),
intent(out) :: ierr
595 logical,
intent(inout) :: isfound
596 integer(I4B),
intent(inout) :: lloc
597 character(len=:),
allocatable,
intent(inout) :: line
598 integer(I4B),
intent(inout) :: iuext
599 logical,
optional,
intent(in) :: blockrequired
600 logical,
optional,
intent(in) :: supportopenclose
602 integer(I4B) :: istart
603 integer(I4B) :: istop
605 integer(I4B) :: lloc2
607 character(len=:),
allocatable :: line2
608 character(len=LINELENGTH) :: fname
609 character(len=MAXCHARLEN) :: ermsg
610 logical :: supportoc, blockrequiredlocal
613 if (
present(blockrequired))
then
614 blockrequiredlocal = blockrequired
616 blockrequiredlocal = .true.
619 if (
present(supportopenclose))
then
620 supportoc = supportopenclose
626 call line_reader%rdcom(iin, iout, line, ierr)
628 if (blockrequiredlocal)
then
629 ermsg =
'Required block "'//trim(ctag)// &
630 '" not found. Found end of file instead.'
637 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
638 if (line(istart:istop) ==
'BEGIN')
then
639 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
640 if (line(istart:istop) == ctag)
then
644 call line_reader%rdcom(iin, iout, line2, ierr)
647 call urword(line2, lloc2, istart, istop, 1, ival, rval, iin, iout)
648 if (line2(istart:istop) ==
'OPEN/CLOSE')
then
650 call urword(line2, lloc2, istart, istop, 0, ival, rval, iin, iout)
651 fname = line2(istart:istop)
654 call urword(line2, lloc2, istart, istop, 1, ival, rval, iin, iout)
655 if (line2(istart:istop) ==
'')
exit chk
656 if (line2(istart:istop) ==
'(BINARY)' .or. &
657 line2(istart:istop) ==
'SFAC')
then
658 call line_reader%bkspc(iin)
663 call openfile(iuext, iout, fname,
'OPEN/CLOSE')
665 call line_reader%bkspc(iin)
669 if (blockrequiredlocal)
then
670 ermsg =
'Error: Required block "'//trim(ctag)// &
671 '" not found. Found block "'//line(istart:istop)// &
676 call line_reader%bkspc(iin)
680 else if (line(istart:istop) ==
'END')
then
681 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
682 if (line(istart:istop) == ctag)
then
683 ermsg =
'Error: Looking for BEGIN '//trim(ctag)// &
684 ' but found END '//line(istart:istop)// &
700 lloc, line, ctagfound, iuext)
704 integer(I4B),
intent(in) :: iin
705 integer(I4B),
intent(in) :: iout
706 logical,
intent(inout) :: isfound
707 integer(I4B),
intent(inout) :: lloc
708 character(len=:),
allocatable,
intent(inout) :: line
709 character(len=*),
intent(out) :: ctagfound
710 integer(I4B),
intent(inout) :: iuext
712 integer(I4B) :: ierr, istart, istop
713 integer(I4B) :: ival, lloc2
715 character(len=100) :: ermsg
716 character(len=:),
allocatable :: line2
717 character(len=LINELENGTH) :: fname
725 call line_reader%rdcom(iin, iout, line, ierr)
727 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
728 if (line(istart:istop) ==
'BEGIN')
then
729 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
730 if (line(istart:istop) /=
'')
then
732 ctagfound = line(istart:istop)
733 call line_reader%rdcom(iin, iout, line2, ierr)
736 call urword(line2, lloc2, istart, istop, 1, ival, rval, iout, iin)
737 if (line2(istart:istop) ==
'OPEN/CLOSE')
then
739 call urword(line2, lloc2, istart, istop, 0, ival, rval, iout, iin)
740 fname = line2(istart:istop)
741 call openfile(iuext, iout, fname,
'OPEN/CLOSE')
743 call line_reader%bkspc(iin)
746 ermsg =
'Block name missing in file.'
765 integer(I4B),
intent(in) :: iin
766 integer(I4B),
intent(in) :: iout
767 character(len=*),
intent(in) :: key
768 character(len=*),
intent(in) :: ctag
769 integer(I4B),
intent(inout) :: lloc
770 character(len=*),
intent(inout) :: line
771 integer(I4B),
intent(inout) :: ierr
772 integer(I4B),
intent(inout) :: iuext
774 character(len=LENBIGLINE) :: ermsg
775 integer(I4B) :: istart
776 integer(I4B) :: istop
780 1
format(
'ERROR. "', a,
'" DETECTED WITHOUT "', a,
'". ',
'"END', 1x, a, &
781 '" MUST BE USED TO END ', a,
'.')
782 2
format(
'ERROR. "', a,
'" DETECTED BEFORE "END', 1x, a,
'". ',
'"END', 1x, a, &
783 '" MUST BE USED TO END ', a,
'.')
789 call urword(line, lloc, istart, istop, 1, ival, rval, iout, iin)
790 if (line(istart:istop) /= ctag)
then
791 write (ermsg, 1) trim(key), trim(ctag), trim(ctag), trim(ctag)
796 if (iuext /= iin)
then
803 write (ermsg, 2) trim(key), trim(ctag), trim(ctag), trim(ctag)
This module contains block parser methods.
subroutine trygetdouble(this, r, success)
subroutine getstring(this, string, convertToUpper)
@ brief Get a string
integer(i4b) function getlinesread(this)
@ brief Get the number of lines read
subroutine initialize(this, inunit, iout)
@ brief Initialize the block parser
integer(i4b) function getunit(this)
@ brief Get the unit number
subroutine, public uterminate_block(iin, iout, key, ctag, lloc, line, ierr, iuext)
Evaluate if the end of a block has been found.
integer(i4b) function getinteger(this)
@ brief Get a integer
subroutine, public uget_any_block(line_reader, iin, iout, isfound, lloc, line, ctagfound, iuext)
Find the next block in a file.
subroutine, public uget_block(line_reader, iin, iout, ctag, ierr, isfound, lloc, line, iuext, blockRequired, supportopenclose)
Find a block in a file.
subroutine readscalarerror(this, vartype)
@ brief Issue a read error
subroutine getnextline(this, endOfBlock)
@ brief Get the next line
subroutine getstringcaps(this, string)
@ brief Get an upper case string
subroutine clear(this)
@ brief Close the block parser
subroutine getremainingline(this, line)
@ brief Get the rest of a line
subroutine getcurrentline(this, line)
@ brief Get the current line
subroutine terminateblock(this)
@ brief Ensure that the block is closed
subroutine trygetinteger(this, i, success)
subroutine storeerrorunit(this, terminate)
@ brief Store the unit number
real(dp) function getdouble(this)
@ brief Get a double precision real
subroutine devopt(this)
@ brief Disable development option in release mode
subroutine getblock(this, blockName, isFound, ierr, supportOpenClose, blockRequired, blockNameFound)
@ brief Get block
subroutine getcellid(this, ndim, cellid, flag_string)
@ brief Get a cellid
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
integer(i4b), parameter lenhugeline
maximum length of a huge line
integer(i4b), parameter lenbigline
maximum length of a big line
integer(i4b), parameter maxcharlen
maximum length of char string
Disable development features in release mode.
subroutine, public developmode(errmsg, iunit)
Terminate if in release mode (guard development features)
This module defines variable data types.
This module contains the LongLineReaderType.
This module contains simulation methods.
subroutine, public store_error(msg, terminate)
Store an error message.
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string