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(:)
48 integer(I4B),
intent(in) :: iu
55 allocate (this%shp(0))
56 call this%read_header()
76 call this%read_header_meta()
77 call this%read_header_body()
85 character(len=50) :: line
86 integer(I4B) :: lloc, istart, istop
91 read (this%inunit) line
93 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
94 if (line(istart:istop) /=
'GRID')
then
95 call store_error(
'Binary grid file must begin with "GRID". '//&
96 &
'Found: '//line(istart:istop))
99 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
100 this%grid_type = line(istart:istop)
103 read (this%inunit) line
105 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
106 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
110 read (this%inunit) line
112 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
113 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
117 read (this%inunit) line
119 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
120 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
131 character(len=:),
allocatable :: body
132 character(len=:),
allocatable :: line
133 character(len=10) :: key, dtype
135 integer(I4B) :: i, lloc, istart, istop, ival, pos
136 integer(I4B) :: nvars, ndim, dim, ishp
137 integer(I4B),
allocatable :: shp(:)
139 allocate (this%keys(this%ntxt))
140 allocate (
character(len=this%lentxt*this%ntxt) :: body)
141 allocate (
character(len=this%lentxt) :: line)
144 read (this%inunit) body
145 inquire (this%inunit, pos=pos)
146 do i = 1, this%lentxt * this%ntxt, this%lentxt
147 line = body(i:i + this%lentxt - 1)
152 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
153 key = line(istart:istop)
155 this%keys(nvars) = key
158 call urword(line, lloc, istart, istop, 1, ival, rval, 0, 0)
159 dtype = line(istart:istop)
160 if (dtype ==
"INTEGER")
then
161 call this%typ%add(key, 1)
162 else if (dtype ==
"DOUBLE")
then
163 call this%typ%add(key, 2)
167 call urword(line, lloc, istart, istop, 0, ival, rval, 0, 0)
168 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
170 call this%dim%add(key, ndim)
173 if (
allocated(shp))
deallocate (shp)
177 call urword(line, lloc, istart, istop, 2, ival, rval, 0, 0)
180 ishp =
size(this%shp)
182 this%shp(ishp + 1:ishp + ndim) = shp
183 call this%shp_idx%add(key, ishp + 1)
187 call this%pos%add(key, pos)
189 if (dtype ==
"INTEGER")
then
191 else if (dtype ==
"DOUBLE")
then
195 if (dtype ==
"INTEGER")
then
196 pos = pos + (product(shp) * 4)
197 else if (dtype ==
"DOUBLE")
then
198 pos = pos + (product(shp) * 8)
210 character(len=*),
intent(in) :: key
213 integer(I4B) :: ndim, pos, typ
214 character(len=:),
allocatable :: msg
216 msg =
'Variable '//trim(key)//
' is not an integer scalar'
217 ndim = this%dim%get(key)
222 typ = this%typ%get(key)
227 pos = this%pos%get(key)
228 read (this%inunit, pos=pos) v
236 character(len=*),
intent(in) :: key
239 integer(I4B) :: ndim, pos, typ
240 character(len=:),
allocatable :: msg
242 msg =
'Variable '//trim(key)//
' is not a double precision scalar'
243 ndim = this%dim%get(key)
248 typ = this%typ%get(key)
253 pos = this%pos%get(key)
254 read (this%inunit, pos=pos) v
262 character(len=*),
intent(in) :: key
263 integer(I4B),
allocatable :: v(:)
265 integer(I4B) :: idx, ndim, nvals, pos, typ
266 character(len=:),
allocatable :: msg
268 msg =
'Variable '//trim(key)//
' is not a 1D integer array'
269 ndim = this%dim%get(key)
274 typ = this%typ%get(key)
279 idx = this%shp_idx%get(key)
280 pos = this%pos%get(key)
281 nvals = this%shp(idx)
283 read (this%inunit, pos=pos) v
291 character(len=*),
intent(in) :: key
292 real(dp),
allocatable :: v(:)
294 integer(I4B) :: idx, ndim, nvals, pos, typ
295 character(len=:),
allocatable :: msg
297 msg =
'Variable '//trim(key)//
' is not a 1D double array'
298 ndim = this%dim%get(key)
303 typ = this%typ%get(key)
308 idx = this%shp_idx%get(key)
309 pos = this%pos%get(key)
310 nvals = this%shp(idx)
312 read (this%inunit, pos=pos) v
321 integer(I4B),
allocatable :: v(:)
323 select case (this%grid_type)
326 v(1) = this%read_int(
"NLAY")
327 v(2) = this%read_int(
"NROW")
328 v(3) = this%read_int(
"NCOL")
331 v(1) = this%read_int(
"NLAY")
332 v(2) = this%read_int(
"NCPL")
335 v(1) = this%read_int(
"NODES")
338 v(1) = this%read_int(
"NROW")
339 v(2) = this%read_int(
"NCOL")
342 v(1) = this%read_int(
"NODES")
345 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.
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