17 integer(I4B),
public :: inunit
19 character(len=10),
public :: grid_type
20 integer(I4B),
public :: version
22 integer(I4B) :: lentxt
28 integer(I4B),
allocatable :: shp(:)
29 character(len=10),
allocatable,
public :: keys(:)
49 integer(I4B),
intent(in) :: iu
56 allocate (this%shp(0))
57 call this%read_header()
77 call this%read_header_meta()
78 call this%read_header_body()
86 character(len=50) :: line
87 integer(I4B) :: lloc, istart, istop
92 read (this%inunit) line
94 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
95 if (line(istart:istop) /=
'GRID')
then
96 call store_error(
'Binary grid file must begin with "GRID". '//&
97 &
'Found: '//line(istart:istop))
100 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
101 this%grid_type = line(istart:istop)
104 read (this%inunit) line
106 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
107 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
111 read (this%inunit) line
113 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
114 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
118 read (this%inunit) line
120 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
121 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
132 character(len=:),
allocatable :: body
133 character(len=:),
allocatable :: line
134 character(len=10) :: key, dtype
136 integer(I4B) :: i, lloc, istart, istop, ival, pos
137 integer(I4B) :: nvars, ndim, dim, ishp
138 integer(I4B),
allocatable :: shp(:)
140 allocate (this%keys(this%ntxt))
141 allocate (
character(len=this%lentxt*this%ntxt) :: body)
142 allocate (
character(len=this%lentxt) :: line)
145 read (this%inunit) body
146 inquire (this%inunit, pos=pos)
147 do i = 1, this%lentxt * this%ntxt, this%lentxt
148 line = body(i:i + this%lentxt - 1)
153 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
154 key = line(istart:istop)
156 this%keys(nvars) = key
159 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
160 dtype = line(istart:istop)
161 if (dtype ==
"INTEGER")
then
162 call this%typ%add(key, 1)
163 else if (dtype ==
"DOUBLE")
then
164 call this%typ%add(key, 2)
165 else if (dtype ==
"CHARACTER")
then
166 call this%typ%add(key, 3)
170 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
171 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
173 call this%dim%add(key, ndim)
176 if (
allocated(shp))
deallocate (shp)
180 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
183 ishp =
size(this%shp)
185 this%shp(ishp + 1:ishp + ndim) = shp
186 call this%shp_idx%add(key, ishp + 1)
190 call this%pos%add(key, pos)
192 if (dtype ==
"INTEGER")
then
194 else if (dtype ==
"DOUBLE")
then
198 if (dtype ==
"INTEGER")
then
199 pos = pos + (product(shp) * 4)
200 else if (dtype ==
"DOUBLE")
then
201 pos = pos + (product(shp) * 8)
202 else if (dtype ==
"CHARACTER")
then
203 pos = pos + (product(shp) * 8)
215 character(len=*),
intent(in) :: key
218 integer(I4B) :: ndim, pos, typ
219 character(len=:),
allocatable :: msg
221 msg =
'Variable '//trim(key)//
' is not an integer scalar'
222 ndim = this%dim%get(key)
227 typ = this%typ%get(key)
232 pos = this%pos%get(key)
233 read (this%inunit, pos=pos) v
241 character(len=*),
intent(in) :: key
244 integer(I4B) :: ndim, pos, typ
245 character(len=:),
allocatable :: msg
247 msg =
'Variable '//trim(key)//
' is not a double precision scalar'
248 ndim = this%dim%get(key)
253 typ = this%typ%get(key)
258 pos = this%pos%get(key)
259 read (this%inunit, pos=pos) v
267 character(len=*),
intent(in) :: key
268 integer(I4B),
allocatable :: v(:)
270 integer(I4B) :: idx, ndim, nvals, pos, typ
271 character(len=:),
allocatable :: msg
273 msg =
'Variable '//trim(key)//
' is not a 1D integer array'
274 ndim = this%dim%get(key)
279 typ = this%typ%get(key)
284 idx = this%shp_idx%get(key)
285 pos = this%pos%get(key)
286 nvals = this%shp(idx)
288 read (this%inunit, pos=pos) v
296 character(len=*),
intent(in) :: key
297 real(dp),
allocatable :: v(:)
299 integer(I4B) :: idx, ndim, nvals, pos, typ
300 character(len=:),
allocatable :: msg
302 msg =
'Variable '//trim(key)//
' is not a 1D double array'
303 ndim = this%dim%get(key)
308 typ = this%typ%get(key)
313 idx = this%shp_idx%get(key)
314 pos = this%pos%get(key)
315 nvals = this%shp(idx)
317 read (this%inunit, pos=pos) v
325 character(len=*),
intent(in) :: key
326 character(len=:),
allocatable :: charstr
328 integer(I4B) :: idx, ndim, nvals, pos, typ
329 character(len=:),
allocatable :: msg
331 msg =
'Variable '//trim(key)//
' is not a character array'
332 ndim = this%dim%get(key)
337 typ = this%typ%get(key)
342 idx = this%shp_idx%get(key)
343 pos = this%pos%get(key)
344 nvals = this%shp(idx)
345 allocate (
character(nvals) :: charstr)
346 read (this%inunit, pos=pos) charstr
354 integer(I4B),
allocatable :: v(:)
356 select case (this%grid_type)
359 v(1) = this%read_int(
"NLAY")
360 v(2) = this%read_int(
"NROW")
361 v(3) = this%read_int(
"NCOL")
364 v(1) = this%read_int(
"NLAY")
365 v(2) = this%read_int(
"NCPL")
368 v(1) = this%read_int(
"NODES")
371 v(1) = this%read_int(
"NROW")
372 v(2) = this%read_int(
"NCOL")
375 v(1) = this%read_int(
"NODES")
378 v(1) = this%read_int(
"NCELLS")
This module contains simulation constants.
integer(i4b), parameter linelength
maximum length of a standard line
subroutine initialize(this, iu)
@Brief Initialize the grid file reader.
subroutine read_header(this)
Read the file's self-describing header. Internal use only.
subroutine read_header_meta(this)
Read self-describing metadata (first four lines). Internal use only.
integer(i4b) function read_int(this, key)
Read an integer scalar from a grid file.
subroutine read_header_body(this)
Read the header body section (text following first.
subroutine finalize(this)
Finalize the grid file reader.
real(dp) function, dimension(:), allocatable read_dbl_1d(this, key)
Read a 1D double array from a grid file.
character(len=:) function, allocatable read_charstr(this, key)
Read a character string from a grid file.
integer(i4b) function, dimension(:), allocatable read_int_1d(this, key)
Read a 1D integer array from a grid file.
real(dp) function read_dbl(this, key)
Read a double precision scalar from a grid file.
integer(i4b) function, dimension(:), allocatable read_grid_shape(this)
Read the grid shape from a grid file.
A chaining hash map for integers.
subroutine, public hash_table_cr(map)
Create a hash table.
subroutine, public hash_table_da(map)
Deallocate the hash table.
This module defines variable data types.
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