Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
et__zone_values.F90
Go to the documentation of this file.
1!> @file
2!! Contains the module \ref et__zone_values.
3
4!>
5!! Module \ref et__zone_values
6!! provides support for estimating reference ET given a zone map
7!! of ET_ZONE.
9
10 use iso_c_binding, only : c_short, c_int, c_float, c_double, c_bool
12 use data_catalog
14 use datetime
15 use dictionary
16 use exceptions
19 use fstring
20 use fstring_list
21
22 implicit none
23
24 private
25
27 public :: pet_grid, et_ratios
28
29 real (c_float), allocatable :: et_table_values(:,:)
30
31 type (data_catalog_entry_t), pointer :: pet_zone
32 type (data_catalog_entry_t), pointer :: pet_grid
33
34 integer (c_int), allocatable :: et_zone(:)
35
36 real (c_float), allocatable :: et_ratios(:)
37
38 contains
39
40 !> Initialize the ET grid.
41 !!
42 !! Read in a et zone grid.
43 !!
44 subroutine et_zone_values_initialize( lActive )
45
46 logical (c_bool), intent(in) :: lactive(:,:)
47
48 ! [ LOCALS ]
49 integer (c_int) :: istat
50 type (fstring_list_t) :: slstring
51
52 ! locate the data structure associated with ANNUAL gridded ET
53 pet_grid => dat%find("POTENTIAL_ET")
54 if ( .not. associated(pet_grid) ) then
55 pet_grid => dat%find("REFERENCE_ET0")
56 if (.not. associated(pet_grid) ) &
57 call die("A POTENTIAL_ET or REFERENCE_ET0 grid must be supplied in order to make" &
58 //" use of this option.", __file__, __line__)
59 endif
60
61! locate the data structure associated with the zone fog ratio entries
62 pet_zone => dat%find("ET_ZONE")
63 if ( .not. associated(pet_zone) ) &
64 call die("A ET_ZONE grid must be supplied in order to make use of this option.", __file__, __line__)
65
66 call pet_zone%getvalues( )
67
68 allocate ( et_zone( count( lactive ) ), stat=istat )
69 call assert(istat==0, "Failed to allocate memory for the ET_ZONE variable", __file__, __line__)
70
71 et_zone = pack( pet_zone%pGrdBase%iData, lactive )
72
73 allocate ( et_ratios( count( lactive ) ), stat=istat)
74 call assert(istat==0, "Failed to allocate memory for the ET_RATIOS variable", __file__, __line__)
75
76 ! look up the name of the fragments file in the control file dictionary
77 call cf_dict%get_values( skey="ET_RATIO_MONTHLY_FILE", slstring=slstring )
78
79 ! use the first entry in the string list slString as the filename to open for
80 ! use with the daily fragments routine
81 call read_et_ratio_table( slstring%get(1) )
82
83 end subroutine et_zone_values_initialize
84
85!--------------------------------------------------------------------------------------------------
86
87 subroutine read_et_ratio_table( sFilename )
88
89 character (len=*), intent(in) :: sFilename
90
91 ! [ LOCALS ]
92 character (len=65536) :: sRecord, sSubstring
93 integer (c_int) :: iStat
94 integer (c_int) :: iLineNum
95 integer (c_int) :: iFieldNum
96 integer (c_int) :: iIndex
97 integer (c_int) :: iNumLines
98 integer (c_int) :: iNumFields
99 type (ASCII_FILE_T) :: ET_RATIO_FILE
100
101 integer (c_int), parameter :: ET_ZONE_FIELD = 1
102
103 call et_ratio_file%open( sfilename = sfilename, &
104 scommentchars = "#%!", &
105 sdelimiters = "WHITESPACE", &
106 lhasheader = .false._c_bool )
107
108 inumlines = et_ratio_file%numLines()
109
110 ! read in next line of file
111 srecord = et_ratio_file%readLine()
112
113 inumfields = fieldcount( srecord )
114
115 allocate( et_table_values( inumlines, inumfields ), stat=istat )
116 call assert( istat == 0, "Problem allocating memory for et ratio table values", &
117 __file__, __line__ )
118
119 ilinenum = 0
120 ifieldnum = 0
121
122 do
123
124 ! read in next line of file
125 srecord = et_ratio_file%readLine()
126
127 if ( et_ratio_file%isEOF() ) exit
128
129 ilinenum = ilinenum + 1
130 ifieldnum = 0
131
132 ! read in ET_ZONE
133 call chomp(srecord, ssubstring, et_ratio_file%sDelimiters )
134
135 if ( len_trim(ssubstring) == 0 ) &
136 call die( "Missing ET ZONE in the monthly et ratio file", &
137 __file__, __line__, "Problem occured on line number " &
138 //ascharacter(et_ratio_file%currentLineNum() ) &
139 //" of file "//dquote(sfilename) )
140
141 et_table_values(et_zone_field, ilinenum ) = asint( ssubstring )
142
143 do iindex = 2, inumfields
144
145! ! read in ET for each month of yeat
146 call chomp(srecord, ssubstring, et_ratio_file%sDelimiters )
147
148 if ( len_trim(ssubstring) == 0 ) &
149 call die( "Missing or corrupt value in the et ratio file", &
150 __file__, __line__, "Problem occured on line number " &
151 //ascharacter(et_ratio_file%currentLineNum() ) &
152 //" of file "//dquote(sfilename) )
153
154 et_table_values(ilinenum, iindex ) = asfloat( ssubstring )
155
156 enddo
157
158 enddo
159
160 end subroutine read_et_ratio_table
161
162!--------------------------------------------------------------------------------------------------
163
165
166 ! [ LOCALS ]
167 integer (c_int) :: ilinenum
168 integer (c_int) :: ifieldnum
169 integer (c_int) :: iet_zone_id
170 real (c_float) :: ffactor
171 integer (c_int) :: icount
172
173 et_ratios = 0.0_c_float
174 icount = 0.0_c_float
175
176 associate( dt => sim_dt%curr )
177
178 call pet_grid%getvalues( dt )
179
180 ! this assumes the input file is structured such that fields 2-13
181 ! correspond to the ET ratios for months 1-12 (Jan-Dec)
182 ifieldnum = dt%iMonth + 1
183
184 ! if it is the first day of the month, update the ratio values
185 if ( dt%iDay == 1 ) then
186
187 do ilinenum = lbound(et_table_values, 1), ubound(et_table_values, 1)
188
189 iet_zone_id = et_table_values(ilinenum, 1)
190 icount = icount + count( et_zone == ifieldnum )
191
192 where ( et_zone == iet_zone_id )
193
194 et_ratios = et_table_values( ilinenum, ifieldnum )
195
196 end where
197
198 enddo
199
200 endif
201
202 end associate
203
204 end subroutine et_zone_values_calculate
205
206end module et__zone_values
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public false
Defines the DATA_CATALOG_T data type, which contains type-bound procedures to add,...
type(data_catalog_t), public dat
DAT is a global to hold data catalog entries.
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
type(dict_t), public cf_dict
Module et__zone_values provides support for estimating reference ET given a zone map of ET_ZONE.
real(c_float), dimension(:), allocatable, public et_ratios
subroutine read_et_ratio_table(sfilename)
subroutine, public et_zone_values_initialize(lactive)
Initialize the ET grid.
real(c_float), dimension(:,:), allocatable et_table_values
type(data_catalog_entry_t), pointer pet_zone
integer(c_int), dimension(:), allocatable et_zone
type(data_catalog_entry_t), pointer, public pet_grid
subroutine, public et_zone_values_calculate()
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
type(date_range_t), public sim_dt