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), allocatable :: ET_RATIO_FILE
100
101 integer (c_int), parameter :: ET_ZONE_FIELD = 1
102
103 allocate(et_ratio_file)
104
105 call et_ratio_file%open( sfilename = sfilename, &
106 scommentchars = "#%!", &
107 sdelimiters = "WHITESPACE", &
108 lhasheader = .false._c_bool )
109
110 inumlines = et_ratio_file%numLines()
111
112 ! read in next line of file
113 srecord = et_ratio_file%readLine()
114
115 inumfields = fieldcount( srecord )
116
117 allocate( et_table_values( inumlines, inumfields ), stat=istat )
118 call assert( istat == 0, "Problem allocating memory for et ratio table values", &
119 __file__, __line__ )
120
121 ilinenum = 0
122 ifieldnum = 0
123
124 do
125
126 ! read in next line of file
127 srecord = et_ratio_file%readLine()
128
129 if ( et_ratio_file%isEOF() ) exit
130
131 ilinenum = ilinenum + 1
132 ifieldnum = 0
133
134 ! read in ET_ZONE
135 call chomp(srecord, ssubstring, et_ratio_file%sDelimiters )
136
137 if ( len_trim(ssubstring) == 0 ) &
138 call die( "Missing ET ZONE in the monthly et ratio file", &
139 __file__, __line__, "Problem occured on line number " &
140 //ascharacter(et_ratio_file%currentLineNum() ) &
141 //" of file "//dquote(sfilename) )
142
143 et_table_values(et_zone_field, ilinenum ) = asint( ssubstring )
144
145 do iindex = 2, inumfields
146
147! ! read in ET for each month of yeat
148 call chomp(srecord, ssubstring, et_ratio_file%sDelimiters )
149
150 if ( len_trim(ssubstring) == 0 ) &
151 call die( "Missing or corrupt value in the et ratio file", &
152 __file__, __line__, "Problem occured on line number " &
153 //ascharacter(et_ratio_file%currentLineNum() ) &
154 //" of file "//dquote(sfilename) )
155
156 et_table_values(ilinenum, iindex ) = asfloat( ssubstring )
157
158 enddo
159
160 enddo
161
162 end subroutine read_et_ratio_table
163
164!--------------------------------------------------------------------------------------------------
165
167
168 ! [ LOCALS ]
169 integer (c_int) :: ilinenum
170 integer (c_int) :: ifieldnum
171 integer (c_int) :: iet_zone_id
172 integer (c_int) :: icount
173
174 et_ratios = 0.0_c_float
175 icount = 0.0_c_float
176
177 associate( dt => sim_dt%curr )
178
179 call pet_grid%getvalues( dt )
180
181 ! this assumes the input file is structured such that fields 2-13
182 ! correspond to the ET ratios for months 1-12 (Jan-Dec)
183 ifieldnum = dt%iMonth + 1
184
185 ! if it is the first day of the month, update the ratio values
186 if ( dt%iDay == 1 ) then
187
188 do ilinenum = lbound(et_table_values, 1), ubound(et_table_values, 1)
189
190 iet_zone_id = int(et_table_values(ilinenum, 1), c_int)
191 icount = icount + count( et_zone == ifieldnum )
192
193 where ( et_zone == iet_zone_id )
194
195 et_ratios = et_table_values( ilinenum, ifieldnum )
196
197 end where
198
199 enddo
200
201 endif
202
203 end associate
204
205 end subroutine et_zone_values_calculate
206
207end 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