MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
Integer2dReader.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, i4b, lgp
4  use constantsmodule, only: dzero, done
6  use simvariablesmodule, only: errmsg
13 
14  implicit none
15  private
16  public :: read_int2d
17 
19 
20  integer(I4B) :: constant_array_value = dzero
21  integer(I4B) :: factor = done
22  integer(I4B), dimension(:, :), contiguous, pointer :: int2d => null()
23 
24  contains
25 
26  procedure :: reset_reader
27  procedure :: set_constant ! must be overridden
28  procedure :: fill_constant ! must be overridden
29  procedure :: read_ascii ! must be overridden
30  procedure :: read_binary ! must be overridden
31  procedure :: set_factor ! must be overridden
32  procedure :: apply_factor ! must be overridden
33 
34  end type integer2dreadertype
35 
36 contains
37 
38  subroutine read_int2d(parser, int2d, aname)
39  ! -- dummy
40  type(blockparsertype), intent(in), target :: parser
41  integer(I4B), dimension(:, :), contiguous, target :: int2d
42  character(len=*), intent(in) :: aname
43  ! -- local
44  type(integer2dreadertype) :: this
45 
46  this%parser => parser
47  this%int2d => int2d
48  this%array_name = aname
49 
50  call this%read_array()
51 
52  end subroutine read_int2d
53 
54  subroutine reset_reader(this)
55  class(integer2dreadertype) :: this
56  call this%ArrayReaderBaseType%reset_reader()
57  this%constant_array_value = 0
58  this%factor = 1
59  end subroutine reset_reader
60 
61  subroutine set_constant(this)
62  class(integer2dreadertype) :: this
63  this%constant_array_value = this%parser%GetInteger()
64  end subroutine set_constant
65 
66  subroutine fill_constant(this)
67  class(integer2dreadertype) :: this
68  integer(I4B) :: i, j
69  do i = 1, size(this%int2d, dim=2)
70  do j = 1, size(this%int2d, dim=1)
71  this%int2d(j, i) = this%constant_array_value
72  end do
73  end do
74  end subroutine fill_constant
75 
76  subroutine read_ascii(this)
77  class(integer2dreadertype) :: this
78  integer(I4B) :: i, j
79  integer(I4B) :: istat
80  do i = 1, size(this%int2d, dim=2)
81  read (this%input_unit, *, iostat=istat, iomsg=errmsg) &
82  (this%int2d(j, i), j=1, size(this%int2d, dim=1))
83  end do
84  if (istat /= 0) then
85  errmsg = 'Error reading data for array '//trim(this%array_name)// &
86  '. '//trim(errmsg)
87  call store_error(errmsg)
88  call store_error_unit(this%input_unit)
89  end if
90  end subroutine read_ascii
91 
92  subroutine read_binary(this)
93  class(integer2dreadertype) :: this
94  integer(I4B) :: i, j
95  integer(I4B) :: nvals
96  integer(I4B) :: istat
97  integer(I4B) :: expected_size
98  expected_size = binary_header_bytes + (size(this%int2d) * binary_int_bytes)
99  call read_binary_header(this%input_unit, this%iout, this%array_name, nvals)
100  call check_binary_filesize(this%input_unit, expected_size, this%array_name)
101  read (this%input_unit, iostat=istat, iomsg=errmsg) &
102  ((this%int2d(j, i), j=1, size(this%int2d, dim=1)), &
103  i=1, size(this%int2d, dim=2))
104  if (istat /= 0) then
105  errmsg = 'Error reading data for array '//trim(this%array_name)// &
106  '. '//trim(errmsg)
107  call store_error(errmsg)
108  call store_error_unit(this%input_unit)
109  end if
110  end subroutine read_binary
111 
112  subroutine set_factor(this)
113  class(integer2dreadertype) :: this
114  this%factor = this%parser%GetInteger()
115  end subroutine set_factor
116 
117  subroutine apply_factor(this)
118  class(integer2dreadertype) :: this
119  integer(I4B) :: i, j
120  if (this%factor /= dzero) then
121  do i = 1, size(this%int2d, dim=2)
122  do j = 1, size(this%int2d, dim=1)
123  this%int2d(j, i) = this%int2d(j, i) * this%factor
124  end do
125  end do
126  end if
127  end subroutine apply_factor
128 
129 end module integer2dreadermodule
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
This module contains simulation constants.
Definition: Constants.f90:9
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
real(dp), parameter done
real constant 1
Definition: Constants.f90:76
subroutine, public read_int2d(parser, int2d, aname)
subroutine apply_factor(this)
subroutine reset_reader(this)
subroutine fill_constant(this)
subroutine read_binary(this)
subroutine set_constant(this)
subroutine read_ascii(this)
subroutine set_factor(this)
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