MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
Double2dReader.f90
Go to the documentation of this file.
2
3 use kindmodule, only: dp, i4b, lgp
13
14 implicit none
15 private
16 public :: read_dbl2d
17
19
20 real(dp) :: constant_array_value = dzero
21 real(dp) :: factor = done
22 real(dp), dimension(:, :), contiguous, pointer :: dbl2d => 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 double2dreadertype
35
36contains
37
38 subroutine read_dbl2d(parser, dbl2d, aname)
39 ! -- dummy
40 type(blockparsertype), intent(in), target :: parser
41 real(dp), dimension(:, :), contiguous, target :: dbl2d
42 character(len=*), intent(in) :: aname
43 ! -- local
44 type(double2dreadertype) :: this
45
46 this%parser => parser
47 this%dbl2d => dbl2d
48 this%array_name = aname
49
50 call this%read_array()
51
52 end subroutine read_dbl2d
53
54 subroutine reset_reader(this)
55 class(double2dreadertype) :: this
56 call this%ArrayReaderBaseType%reset_reader()
57 this%constant_array_value = dzero
58 this%factor = done
59 end subroutine reset_reader
60
61 subroutine set_constant(this)
62 class(double2dreadertype) :: this
63 this%constant_array_value = this%parser%GetDouble()
64 end subroutine set_constant
65
66 subroutine fill_constant(this)
67 class(double2dreadertype) :: this
68 integer(I4B) :: i, j
69 do i = 1, size(this%dbl2d, dim=2)
70 do j = 1, size(this%dbl2d, dim=1)
71 this%dbl2d(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(double2dreadertype) :: this
78 integer(I4B) :: i, j
79 integer(I4B) :: istat
80 do i = 1, size(this%dbl2d, dim=2)
81 read (this%input_unit, *, iostat=istat, iomsg=errmsg) &
82 (this%dbl2d(j, i), j=1, size(this%dbl2d, dim=1))
83 end do
84 if (istat /= 0) then
85 errmsg = 'Error reading data for array '//trim(this%array_name)// &
86 '. '//trim(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(double2dreadertype) :: 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%dbl2d) * binary_double_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%dbl2d(j, i), j=1, size(this%dbl2d, dim=1)), &
103 i=1, size(this%dbl2d, 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(double2dreadertype) :: this
114 this%factor = this%parser%GetDouble()
115 end subroutine set_factor
116
117 subroutine apply_factor(this)
118 class(double2dreadertype) :: this
119 integer(I4B) :: i, j
120 if (this%factor /= dzero) then
121 do i = 1, size(this%dbl2d, dim=2)
122 do j = 1, size(this%dbl2d, dim=1)
123 ! no data values are not scaled
124 if (this%dbl2d(j, i) == dnodata) cycle
125 this%dbl2d(j, i) = this%dbl2d(j, i) * this%factor
126 end do
127 end do
128 end if
129 end subroutine apply_factor
130
131end module double2dreadermodule
subroutine set_factor(this)
subroutine fill_constant(this)
subroutine reset_reader(this)
subroutine set_constant(this)
subroutine apply_factor(this)
subroutine read_binary(this)
subroutine read_ascii(this)
subroutine, public read_binary_header(locat, iout, arrname, nval)
subroutine, public check_binary_filesize(locat, expected_size, arrname)
integer(i4b), parameter, public binary_header_bytes
array text
integer(i4b), parameter, public binary_double_bytes
This module contains block parser methods.
This module contains simulation constants.
Definition Constants.f90:9
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
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)
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:94
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
Definition Sim.f90:172
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string