MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
Double2dReader.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
10 
11  implicit none
12  private
13  public :: read_dbl2d
14 
16 
17  real(dp) :: constant_array_value = dzero
18  real(dp) :: factor = done
19  real(dp), dimension(:, :), contiguous, pointer :: dbl2d => null()
20 
21  contains
22 
23  procedure :: reset_reader
24  procedure :: set_constant ! must be overridden
25  procedure :: fill_constant ! must be overridden
26  procedure :: read_ascii ! must be overridden
27  procedure :: read_binary ! must be overridden
28  procedure :: set_factor ! must be overridden
29  procedure :: apply_factor ! must be overridden
30 
31  end type double2dreadertype
32 
33 contains
34 
35  subroutine read_dbl2d(parser, dbl2d, aname)
36  ! -- dummy
37  type(blockparsertype), intent(in), target :: parser
38  real(dp), dimension(:, :), contiguous, target :: dbl2d
39  character(len=*), intent(in) :: aname
40  ! -- local
41  type(double2dreadertype) :: this
42 
43  this%parser => parser
44  this%dbl2d => dbl2d
45  this%array_name = aname
46 
47  call this%read_array()
48 
49  end subroutine read_dbl2d
50 
51  subroutine reset_reader(this)
52  class(double2dreadertype) :: this
53  call this%ArrayReaderBaseType%reset_reader()
54  this%constant_array_value = dzero
55  this%factor = done
56  end subroutine reset_reader
57 
58  subroutine set_constant(this)
59  class(double2dreadertype) :: this
60  this%constant_array_value = this%parser%GetDouble()
61  end subroutine set_constant
62 
63  subroutine fill_constant(this)
64  class(double2dreadertype) :: this
65  integer(I4B) :: i, j
66  do i = 1, size(this%dbl2d, dim=2)
67  do j = 1, size(this%dbl2d, dim=1)
68  this%dbl2d(j, i) = this%constant_array_value
69  end do
70  end do
71  end subroutine fill_constant
72 
73  subroutine read_ascii(this)
74  class(double2dreadertype) :: this
75  integer(I4B) :: i, j
76  integer(I4B) :: istat
77  do i = 1, size(this%dbl2d, dim=2)
78  read (this%input_unit, *, iostat=istat, iomsg=errmsg) &
79  (this%dbl2d(j, i), j=1, size(this%dbl2d, dim=1))
80  end do
81  if (istat /= 0) then
82  errmsg = 'Error reading data for array '//trim(this%array_name)// &
83  '. '//trim(errmsg)
84  call store_error(errmsg)
85  call store_error_unit(this%input_unit)
86  end if
87  end subroutine read_ascii
88 
89  subroutine read_binary(this)
90  class(double2dreadertype) :: this
91  integer(I4B) :: i, j
92  integer(I4B) :: nvals
93  integer(I4B) :: istat
94  call read_binary_header(this%input_unit, this%iout, this%array_name, nvals)
95  read (this%input_unit, iostat=istat, iomsg=errmsg) &
96  ((this%dbl2d(j, i), j=1, size(this%dbl2d, dim=1)), &
97  i=1, size(this%dbl2d, dim=2))
98  if (istat /= 0) then
99  errmsg = 'Error reading data for array '//trim(this%array_name)// &
100  '. '//trim(errmsg)
101  call store_error(errmsg)
102  call store_error_unit(this%input_unit)
103  end if
104  end subroutine read_binary
105 
106  subroutine set_factor(this)
107  class(double2dreadertype) :: this
108  this%factor = this%parser%GetDouble()
109  end subroutine set_factor
110 
111  subroutine apply_factor(this)
112  class(double2dreadertype) :: this
113  integer(I4B) :: i, j
114  if (this%factor /= dzero) then
115  do i = 1, size(this%dbl2d, dim=2)
116  do j = 1, size(this%dbl2d, dim=1)
117  this%dbl2d(j, i) = this%dbl2d(j, i) * this%factor
118  end do
119  end do
120  end if
121  end subroutine apply_factor
122 
123 end module double2dreadermodule
subroutine, public read_binary_header(locat, iout, arrname, nval)
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_dbl2d(parser, dbl2d, aname)
subroutine read_binary(this)
subroutine read_ascii(this)
subroutine reset_reader(this)
subroutine apply_factor(this)
subroutine fill_constant(this)
subroutine set_constant(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