MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
Integer1dReader.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, i4b, lgp
5  use simvariablesmodule, only: errmsg
12 
13  implicit none
14  private
16 
18 
19  integer(I4B) :: constant_array_value = 0
20  integer(I4B) :: factor = 1
21  integer(I4B), dimension(:), contiguous, pointer :: int1d => null()
22 
23  contains
24 
25  procedure :: reset_reader
26  procedure :: set_constant ! must be overridden
27  procedure :: fill_constant ! must be overridden
28  procedure :: read_ascii ! must be overridden
29  procedure :: read_binary ! must be overridden
30  procedure :: set_factor ! must be overridden
31  procedure :: apply_factor ! must be overridden
32 
33  end type integer1dreadertype
34 
35 contains
36 
37  subroutine read_int1d(parser, int1d, aname)
38  ! -- dummy
39  type(blockparsertype), intent(in), target :: parser
40  integer(I4B), dimension(:), contiguous, target :: int1d
41  character(len=*), intent(in) :: aname
42  ! -- local
43  type(integer1dreadertype) :: this
44 
45  this%parser => parser
46  this%int1d => int1d
47  this%array_name = aname
48 
49  call this%read_array()
50 
51  end subroutine read_int1d
52 
53  subroutine read_int1d_layered(parser, int1d, aname, nlay, layer_shape)
55  ! -- dummy
56  type(blockparsertype), intent(in), target :: parser
57  integer(I4B), dimension(:), contiguous, target :: int1d
58  character(len=*), intent(in) :: aname
59  integer(I4B), intent(in) :: nlay
60  integer(I4B), dimension(:), intent(in) :: layer_shape
61  ! -- local
62  integer(I4B) :: k
63  integer(I4B) :: ncpl, nrow, ncol
64  integer(I4B) :: index_start, index_stop
65  integer(I4B), dimension(:, :), contiguous, pointer :: int2d_ptr
66 
67  ncpl = product(layer_shape)
68  index_start = 1
69  do k = 1, nlay
70  index_stop = index_start + ncpl - 1
71  if (size(layer_shape) == 2) then
72  ncol = layer_shape(1)
73  nrow = layer_shape(2)
74  int2d_ptr(1:ncol, 1:nrow) => int1d(index_start:index_stop)
75  call read_int2d(parser, int2d_ptr, aname)
76  else
77  call read_int1d(parser, int1d(index_start:index_stop), aname)
78  end if
79  index_start = index_stop + 1
80  end do
81 
82  end subroutine read_int1d_layered
83 
84  subroutine reset_reader(this)
85  class(integer1dreadertype) :: this
86  call this%ArrayReaderBaseType%reset_reader()
87  this%constant_array_value = 0
88  this%factor = 1
89  end subroutine reset_reader
90 
91  subroutine set_constant(this)
92  class(integer1dreadertype) :: this
93  this%constant_array_value = this%parser%GetInteger()
94  end subroutine set_constant
95 
96  subroutine fill_constant(this)
97  class(integer1dreadertype) :: this
98  integer(I4B) :: i
99  do i = 1, size(this%int1d)
100  this%int1d(i) = this%constant_array_value
101  end do
102  end subroutine fill_constant
103 
104  subroutine read_ascii(this)
105  class(integer1dreadertype) :: this
106  integer(I4B) :: i
107  integer(I4B) :: nvals
108  integer(I4B) :: istat
109  nvals = size(this%int1d)
110  read (this%input_unit, *, iostat=istat, iomsg=errmsg) &
111  (this%int1d(i), i=1, size(this%int1d))
112  if (istat /= 0) then
113  errmsg = 'Error reading data for array '//trim(this%array_name)// &
114  '. '//trim(errmsg)
115  call store_error(errmsg)
116  call store_error_unit(this%input_unit)
117  end if
118  end subroutine read_ascii
119 
120  subroutine read_binary(this)
121  class(integer1dreadertype) :: this
122  integer(I4B) :: i
123  integer(I4B) :: nvals
124  integer(I4B) :: istat
125  integer(I4B) :: expected_size
126  expected_size = binary_header_bytes + (size(this%int1d) * binary_int_bytes)
127  call read_binary_header(this%input_unit, this%iout, this%array_name, nvals)
128  call check_binary_filesize(this%input_unit, expected_size, this%array_name)
129  read (this%input_unit, iostat=istat, iomsg=errmsg) &
130  (this%int1d(i), i=1, size(this%int1d))
131  if (istat /= 0) then
132  errmsg = 'Error reading data for array '//trim(this%array_name)// &
133  '. '//trim(errmsg)
134  call store_error(errmsg)
135  call store_error_unit(this%input_unit)
136  end if
137  end subroutine read_binary
138 
139  subroutine set_factor(this)
140  class(integer1dreadertype) :: this
141  this%factor = this%parser%GetInteger()
142  end subroutine set_factor
143 
144  subroutine apply_factor(this)
145  class(integer1dreadertype) :: this
146  integer(I4B) :: i
147  if (this%factor /= 0) then
148  do i = 1, size(this%int1d)
149  this%int1d(i) = this%int1d(i) * this%factor
150  end do
151  end if
152  end subroutine apply_factor
153 
154 end module integer1dreadermodule
subroutine, public read_binary_header(locat, iout, arrname, nval)
subroutine, public check_binary_filesize(locat, expected_size, arrname)
integer(i4b), parameter, public binary_int_bytes
integer(i4b), parameter, public binary_header_bytes
array text
This module contains block parser methods.
Definition: BlockParser.f90:7
subroutine read_ascii(this)
subroutine read_binary(this)
subroutine apply_factor(this)
subroutine reset_reader(this)
subroutine set_constant(this)
subroutine set_factor(this)
subroutine, public read_int1d(parser, int1d, aname)
subroutine fill_constant(this)
subroutine, public read_int1d_layered(parser, int1d, aname, nlay, layer_shape)
subroutine, public read_int2d(parser, int2d, aname)
This module defines variable data types.
Definition: kind.f90:8
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
Definition: Sim.f90:168
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string