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