MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
Double1dReader.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_dbl1d
14 
16 
17  real(dp) :: constant_array_value = dzero
18  real(dp) :: factor = done
19  real(dp), dimension(:), contiguous, pointer :: dbl1d => 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 double1dreadertype
32 
33 contains
34 
35  subroutine read_dbl1d(parser, dbl1d, aname)
36  ! -- dummy
37  type(blockparsertype), intent(in), target :: parser
38  real(dp), dimension(:), contiguous, target :: dbl1d
39  character(len=*), intent(in) :: aname
40  ! -- local
41  type(double1dreadertype) :: this
42 
43  this%parser => parser
44  this%dbl1d => dbl1d
45  this%array_name = aname
46 
47  call this%read_array()
48 
49  end subroutine read_dbl1d
50 
51  subroutine reset_reader(this)
52  class(double1dreadertype) :: 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(double1dreadertype) :: this
60  this%constant_array_value = this%parser%GetDouble()
61  end subroutine set_constant
62 
63  subroutine fill_constant(this)
64  class(double1dreadertype) :: this
65  integer(I4B) :: i
66  do i = 1, size(this%dbl1d)
67  this%dbl1d(i) = this%constant_array_value
68  end do
69  end subroutine fill_constant
70 
71  subroutine read_ascii(this)
72  class(double1dreadertype) :: this
73  integer(I4B) :: i
74  integer(I4B) :: istat
75  read (this%input_unit, *, iostat=istat, iomsg=errmsg) &
76  (this%dbl1d(i), i=1, size(this%dbl1d))
77  if (istat /= 0) then
78  errmsg = 'Error reading data for array '//trim(this%array_name)// &
79  '. '//trim(errmsg)
80  call store_error(errmsg)
81  call store_error_unit(this%input_unit)
82  end if
83  end subroutine read_ascii
84 
85  subroutine read_binary(this)
86  class(double1dreadertype) :: this
87  integer(I4B) :: i
88  integer(I4B) :: nvals
89  integer(I4B) :: istat
90  call read_binary_header(this%input_unit, this%iout, this%array_name, nvals)
91  read (this%input_unit, iostat=istat, iomsg=errmsg) &
92  (this%dbl1d(i), i=1, size(this%dbl1d))
93  if (istat /= 0) then
94  errmsg = 'Error reading data for array '//trim(this%array_name)// &
95  '. '//trim(errmsg)
96  call store_error(errmsg)
97  call store_error_unit(this%input_unit)
98  end if
99  end subroutine read_binary
100 
101  subroutine set_factor(this)
102  class(double1dreadertype) :: this
103  this%factor = this%parser%GetDouble()
104  end subroutine set_factor
105 
106  subroutine apply_factor(this)
107  class(double1dreadertype) :: this
108  integer(I4B) :: i
109  if (this%factor /= dzero) then
110  do i = 1, size(this%dbl1d)
111  this%dbl1d(i) = this%dbl1d(i) * this%factor
112  end do
113  end if
114  end subroutine apply_factor
115 
116 end module double1dreadermodule
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 apply_factor(this)
subroutine set_constant(this)
subroutine set_factor(this)
subroutine, public read_dbl1d(parser, dbl1d, aname)
subroutine reset_reader(this)
subroutine read_binary(this)
subroutine fill_constant(this)
subroutine read_ascii(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