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
66 integer(I4B),
intent(in) :: inunit
67 integer(I4B),
intent(in) :: iout
72 this%iuactive = inunit
91 if (this%inunit > 0)
then
92 inquire (unit=this%inunit, opened=lop)
98 if (this%iuext /= this%inunit .and. this%iuext > 0)
then
99 inquire (unit=this%iuext, opened=lop)
114 deallocate (this%line)
123 subroutine getblock(this, blockName, isFound, ierr, supportOpenClose, &
124 blockRequired, blockNameFound)
127 character(len=*),
intent(in) :: blockName
128 logical,
intent(out) :: isFound
129 integer(I4B),
intent(out) :: ierr
130 logical,
intent(in),
optional :: supportOpenClose
131 logical,
intent(in),
optional :: blockRequired
132 character(len=*),
intent(inout),
optional :: blockNameFound
134 logical :: continueRead
135 logical :: supportOpenCloseLocal
136 logical :: blockRequiredLocal
139 if (
present(supportopenclose))
then
140 supportopencloselocal = supportopenclose
142 supportopencloselocal = .false.
145 if (
present(blockrequired))
then
146 blockrequiredlocal = blockrequired
148 blockrequiredlocal = .true.
150 continueread = blockrequiredlocal
151 this%blockName = blockname
152 this%blockNameFound =
''
154 if (blockname ==
'*')
then
156 isfound, this%lloc, this%line, blocknamefound, &
159 this%blockNameFound = blocknamefound
165 call uget_block(this%line_reader, this%inunit, this%iout, &
166 this%blockName, ierr, isfound, &
167 this%lloc, this%line, this%iuext, continueread, &
168 supportopencloselocal)
169 if (isfound) this%blockNameFound = this%blockName
171 this%iuactive = this%iuext
183 logical,
intent(out) :: endOfBlock
187 integer(I4B) :: istart
188 integer(I4B) :: istop
190 character(len=10) :: key
200 if (lineread)
exit loop1
201 call this%line_reader%rdcom(this%iuext, this%iout, this%line, ierr)
203 call urword(this%line, this%lloc, istart, istop, 0, ival, rval, &
204 this%iout, this%iuext)
205 key = this%line(istart:istop)
207 if (key ==
'END' .or. key ==
'BEGIN')
then
209 this%blockNameFound, this%lloc, this%line, &
211 this%iuactive = this%iuext
214 elseif (key ==
'')
then
218 if (this%iuext /= this%inunit)
then
220 this%iuext = this%inunit
221 this%iuactive = this%inunit
223 errmsg =
'Unexpected end of file reached.'
225 call this%StoreErrorUnit()
229 this%linesRead = this%linesRead + 1
246 integer(I4B) :: istart
247 integer(I4B) :: istop
251 call urword(this%line, this%lloc, istart, istop, 2, i, rval, &
252 this%iout, this%iuext)
255 if (istart == istop .and. istop == len(this%line))
then
256 call this%ReadScalarError(
'INTEGER')
267 integer(I4B) :: nlines
272 nlines = this%linesRead
287 integer(I4B) :: istart
288 integer(I4B) :: istop
292 call urword(this%line, this%lloc, istart, istop, 3, ival, r, &
293 this%iout, this%iuext)
296 if (istart == istop .and. istop == len(this%line))
then
297 call this%ReadScalarError(
'DOUBLE PRECISION')
305 real(DP),
intent(inout) :: r
306 logical(LGP),
intent(inout) :: success
308 integer(I4B) :: istart
309 integer(I4B) :: istop
312 call urword(this%line, this%lloc, istart, istop, 3, ival, r, &
313 this%iout, this%iuext)
316 if (istart == istop .and. istop == len(this%line))
then
330 character(len=*),
intent(in) :: vartype
332 character(len=MAXCHARLEN - 100) :: linetemp
338 write (
errmsg,
'(3a)')
'Error in block ', trim(this%blockName),
'.'
340 trim(
errmsg),
' Could not read variable of type ', trim(vartype), &
341 " from the following line: '"
343 trim(
errmsg), trim(adjustl(this%line)),
"'."
345 call this%StoreErrorUnit()
357 character(len=*),
intent(out) :: string
358 logical,
optional,
intent(in) :: convertToUpper
360 integer(I4B) :: istart
361 integer(I4B) :: istop
363 integer(I4B) :: ncode
367 if (
present(converttoupper))
then
368 if (converttoupper)
then
377 call urword(this%line, this%lloc, istart, istop, ncode, &
378 ival, rval, this%iout, this%iuext)
379 string = this%line(istart:istop)
380 this%laststring = this%line(istart:istop)
392 character(len=*),
intent(out) :: string
395 call this%GetString(string, converttoupper=.true.)
406 character(len=:),
allocatable,
intent(out) :: line
408 integer(I4B) :: lastpos
409 integer(I4B) :: newlinelen
412 lastpos = len_trim(this%line)
413 newlinelen = lastpos - this%lloc + 2
414 newlinelen = max(newlinelen, 1)
415 allocate (
character(len=newlinelen) :: line)
416 line(:) = this%line(this%lloc:lastpos)
417 line(newlinelen:newlinelen) =
' '
429 logical :: endofblock
432 call this%GetNextLine(endofblock)
433 if (.not. endofblock)
then
434 errmsg =
"LOOKING FOR 'END "//trim(this%blockname)// &
435 "'. FOUND: "//
"'"//trim(this%line)//
"'."
437 call this%StoreErrorUnit()
449 integer(I4B),
intent(in) :: ndim
450 character(len=*),
intent(out) :: cellid
451 logical,
optional,
intent(in) :: flag_string
456 integer(I4B) :: istart
457 integer(I4B) :: istop
459 integer(I4B) :: istat
461 character(len=10) :: cint
462 character(len=100) :: firsttoken
465 if (
present(flag_string))
then
467 call urword(this%line, lloc, istart, istop, 0, ival, rval, this%iout, &
469 firsttoken = this%line(istart:istop)
470 read (firsttoken, *, iostat=istat) ival
480 j = this%GetInteger()
481 write (cint,
'(i0)') j
485 cellid = trim(cellid)//
' '//cint
498 character(len=*),
intent(out) :: line
513 logical,
intent(in),
optional :: terminate
515 logical :: lterminate
518 if (
present(terminate))
then
519 lterminate = terminate
553 errmsg =
"Invalid keyword '"//trim(this%laststring)// &
554 "' detected in block '"//trim(this%blockname)//
"'."
565 subroutine uget_block(line_reader, iin, iout, ctag, ierr, isfound, &
566 lloc, line, iuext, blockRequired, supportopenclose)
570 integer(I4B),
intent(in) :: iin
571 integer(I4B),
intent(in) :: iout
572 character(len=*),
intent(in) :: ctag
573 integer(I4B),
intent(out) :: ierr
574 logical,
intent(inout) :: isfound
575 integer(I4B),
intent(inout) :: lloc
576 character(len=:),
allocatable,
intent(inout) :: line
577 integer(I4B),
intent(inout) :: iuext
578 logical,
optional,
intent(in) :: blockrequired
579 logical,
optional,
intent(in) :: supportopenclose
581 integer(I4B) :: istart
582 integer(I4B) :: istop
584 integer(I4B) :: lloc2
586 character(len=:),
allocatable :: line2
587 character(len=LINELENGTH) :: fname
588 character(len=MAXCHARLEN) :: ermsg
589 logical :: supportoc, blockrequiredlocal
592 if (
present(blockrequired))
then
593 blockrequiredlocal = blockrequired
595 blockrequiredlocal = .true.
598 if (
present(supportopenclose))
then
599 supportoc = supportopenclose
605 call line_reader%rdcom(iin, iout, line, ierr)
607 if (blockrequiredlocal)
then
608 ermsg =
'Required block "'//trim(ctag)// &
609 '" not found. Found end of file instead.'
616 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
617 if (line(istart:istop) ==
'BEGIN')
then
618 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
619 if (line(istart:istop) == ctag)
then
623 call line_reader%rdcom(iin, iout, line2, ierr)
626 call urword(line2, lloc2, istart, istop, 1, ival, rval, iin, iout)
627 if (line2(istart:istop) ==
'OPEN/CLOSE')
then
629 call urword(line2, lloc2, istart, istop, 0, ival, rval, iin, iout)
630 fname = line2(istart:istop)
633 call urword(line2, lloc2, istart, istop, 1, ival, rval, iin, iout)
634 if (line2(istart:istop) ==
'')
exit chk
635 if (line2(istart:istop) ==
'(BINARY)' .or. &
636 line2(istart:istop) ==
'SFAC')
then
637 call line_reader%bkspc(iin)
642 call openfile(iuext, iout, fname,
'OPEN/CLOSE')
644 call line_reader%bkspc(iin)
648 if (blockrequiredlocal)
then
649 ermsg =
'Error: Required block "'//trim(ctag)// &
650 '" not found. Found block "'//line(istart:istop)// &
655 call line_reader%bkspc(iin)
659 else if (line(istart:istop) ==
'END')
then
660 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
661 if (line(istart:istop) == ctag)
then
662 ermsg =
'Error: Looking for BEGIN '//trim(ctag)// &
663 ' but found END '//line(istart:istop)// &
679 lloc, line, ctagfound, iuext)
683 integer(I4B),
intent(in) :: iin
684 integer(I4B),
intent(in) :: iout
685 logical,
intent(inout) :: isfound
686 integer(I4B),
intent(inout) :: lloc
687 character(len=:),
allocatable,
intent(inout) :: line
688 character(len=*),
intent(out) :: ctagfound
689 integer(I4B),
intent(inout) :: iuext
691 integer(I4B) :: ierr, istart, istop
692 integer(I4B) :: ival, lloc2
694 character(len=100) :: ermsg
695 character(len=:),
allocatable :: line2
696 character(len=LINELENGTH) :: fname
704 call line_reader%rdcom(iin, iout, line, ierr)
706 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
707 if (line(istart:istop) ==
'BEGIN')
then
708 call urword(line, lloc, istart, istop, 1, ival, rval, iin, iout)
709 if (line(istart:istop) /=
'')
then
711 ctagfound = line(istart:istop)
712 call line_reader%rdcom(iin, iout, line2, ierr)
715 call urword(line2, lloc2, istart, istop, 1, ival, rval, iout, iin)
716 if (line2(istart:istop) ==
'OPEN/CLOSE')
then
718 call urword(line2, lloc2, istart, istop, 0, ival, rval, iout, iin)
719 fname = line2(istart:istop)
720 call openfile(iuext, iout, fname,
'OPEN/CLOSE')
722 call line_reader%bkspc(iin)
725 ermsg =
'Block name missing in file.'
744 integer(I4B),
intent(in) :: iin
745 integer(I4B),
intent(in) :: iout
746 character(len=*),
intent(in) :: key
747 character(len=*),
intent(in) :: ctag
748 integer(I4B),
intent(inout) :: lloc
749 character(len=*),
intent(inout) :: line
750 integer(I4B),
intent(inout) :: ierr
751 integer(I4B),
intent(inout) :: iuext
753 character(len=LENBIGLINE) :: ermsg
754 integer(I4B) :: istart
755 integer(I4B) :: istop
759 1
format(
'ERROR. "', a,
'" DETECTED WITHOUT "', a,
'". ',
'"END', 1x, a, &
760 '" MUST BE USED TO END ', a,
'.')
761 2
format(
'ERROR. "', a,
'" DETECTED BEFORE "END', 1x, a,
'". ',
'"END', 1x, a, &
762 '" MUST BE USED TO END ', a,
'.')
768 call urword(line, lloc, istart, istop, 1, ival, rval, iout, iin)
769 if (line(istart:istop) /= ctag)
then
770 write (ermsg, 1) trim(key), trim(ctag), trim(ctag), trim(ctag)
775 if (iuext /= iin)
then
782 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 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 dev_feature(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