MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
binaryfilereadermodule Module Reference

Data Types

type  binaryfileheadertype
type  binaryfilereadertype
interface  read_header_if
interface  read_record_if

Functions/Subroutines

character(len=:) function, allocatable get_str (this)
 Get a string representation of the header.
subroutine build_index (this)
 Build an index of record positions in the file.
subroutine seek_to_index (this, index)
 Position the file at the start of an indexed record.
subroutine peek_record (this)
 Peek to see if another record is available.
subroutine rewind (this)
 Rewind the file to the beginning.

Function/Subroutine Documentation

◆ build_index()

subroutine binaryfilereadermodule::build_index ( class(binaryfilereadertype), intent(inout) this)

Definition at line 68 of file BinaryFileReader.f90.

69 class(BinaryFileReaderType), intent(inout) :: this
70 ! local
71 logical(LGP) :: success
72 integer(I4B) :: i
73
74 this%indexed = .false.
75 this%nrecords = 0
76 call this%rewind()
77 if (allocated(this%record_positions)) deallocate (this%record_positions)
78
79 ! first pass: count
80 do
81 call this%read_record(success)
82 if (.not. success) exit
83 this%nrecords = this%nrecords + 1
84 end do
85
86 ! second pass: save positions (read first so header%pos is set)
87 call this%rewind()
88 allocate (this%record_positions(this%nrecords))
89 i = 0
90 do
91 call this%read_record(success)
92 if (.not. success) exit
93 i = i + 1
94 this%record_positions(i) = this%header%pos
95 end do
96 call this%rewind()
97
98 this%indexed = .true.

◆ get_str()

character(len=:) function, allocatable binaryfilereadermodule::get_str ( class(binaryfileheadertype), intent(in) this)

Definition at line 53 of file BinaryFileReader.f90.

54 class(BinaryFileHeaderType), intent(in) :: this
55 character(len=:), allocatable :: str
56
57 write (str, '(*(G0))') &
58 'Binary file header (pos: ', this%pos, &
59 ', kper: ', this%kper, &
60 ', kstp: ', this%kstp, &
61 ', pertim: ', this%pertim, &
62 ', totim: ', this%totim, &
63 ')'
64 str = trim(str)

◆ peek_record()

subroutine binaryfilereadermodule::peek_record ( class(binaryfilereadertype), intent(inout) this)

Definition at line 124 of file BinaryFileReader.f90.

125 class(BinaryFileReaderType), intent(inout) :: this
126 ! local
127 integer(I4B) :: iostat
128
129 if (.not. this%endoffile) then
130 inquire (this%inunit, pos=this%headernext%pos)
131 read (this%inunit, iostat=iostat) this%headernext%kstp, this%headernext%kper
132 if (iostat == 0) then
133 read (this%inunit, pos=this%headernext%pos, iostat=iostat)
134 else if (iostat < 0) then
135 this%endoffile = .true.
136 if (allocated(this%headernext)) deallocate (this%headernext)
137 end if
138 end if

◆ rewind()

subroutine binaryfilereadermodule::rewind ( class(binaryfilereadertype), intent(inout) this)

Definition at line 142 of file BinaryFileReader.f90.

143 class(BinaryFileReaderType), intent(inout) :: this
144
145 rewind(this%inunit)
146 if (allocated(this%header)) deallocate (this%header)
147 if (allocated(this%headernext)) deallocate (this%headernext)
148 allocate (binaryfileheadertype :: this%header)
149 allocate (binaryfileheadertype :: this%headernext)
150 this%header%pos = 1
151 this%headernext%pos = 1
152 this%endoffile = .false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ seek_to_index()

subroutine binaryfilereadermodule::seek_to_index ( class(binaryfilereadertype), intent(inout) this,
integer(i4b), intent(in) index )

Definition at line 102 of file BinaryFileReader.f90.

103 class(BinaryFileReaderType), intent(inout) :: this
104 integer(I4B), intent(in) :: index
105 ! local
106 integer(I4B) :: iostat
107
108 if (.not. this%indexed) &
109 call pstop(1, 'Cannot seek to index in unindexed file')
110 if (index < 1 .or. index > this%nrecords) then
111 this%endoffile = .true.
112 return
113 end if
114
115 read (this%inunit, pos=this%record_positions(index), iostat=iostat)
116 if (iostat /= 0) call pstop(1, 'Error seeking to index position')
117 ! peek_record deallocates headernext at end of file
118 if (.not. allocated(this%headernext)) &
119 allocate (this%headernext, mold=this%header)
120 this%endoffile = .false.
Here is the call graph for this function: