Soil Water Balance (SWB2)
Toggle main menu visibility
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.
8
module
et__zone_values
9
10
use
iso_c_binding,
only
: c_short, c_int, c_float, c_double, c_bool
11
use
constants_and_conversions
12
use
data_catalog
13
use
data_catalog_entry
14
use
datetime
15
use
dictionary
16
use
exceptions
17
use
file_operations
18
use
simulation_datetime
19
use
fstring
20
use
fstring_list
21
22
implicit none
23
24
private
25
26
public
::
et_zone_values_initialize
,
et_zone_values_calculate
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
166
subroutine
et_zone_values_calculate
( )
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
207
end module
et__zone_values
constants_and_conversions
This module contains physical constants and convenience functions aimed at performing unit conversion...
Definition
constants_and_conversions.F90:8
constants_and_conversions::false
logical(c_bool), parameter, public false
Definition
constants_and_conversions.F90:39
data_catalog
Defines the DATA_CATALOG_T data type, which contains type-bound procedures to add,...
Definition
data_catalog.F90:10
data_catalog::dat
type(data_catalog_t), public dat
DAT is a global to hold data catalog entries.
Definition
data_catalog.F90:65
data_catalog_entry
Definition
data_catalog_entry.F90:8
datetime
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition
datetime.F90:9
dictionary
Definition
dictionary.F90:1
dictionary::cf_dict
type(dict_t), public cf_dict
Definition
dictionary.F90:101
et__zone_values
Module et__zone_values provides support for estimating reference ET given a zone map of ET_ZONE.
Definition
et__zone_values.F90:8
et__zone_values::et_ratios
real(c_float), dimension(:), allocatable, public et_ratios
Definition
et__zone_values.F90:36
et__zone_values::read_et_ratio_table
subroutine read_et_ratio_table(sfilename)
Definition
et__zone_values.F90:88
et__zone_values::et_zone_values_initialize
subroutine, public et_zone_values_initialize(lactive)
Initialize the ET grid.
Definition
et__zone_values.F90:45
et__zone_values::et_table_values
real(c_float), dimension(:,:), allocatable et_table_values
Definition
et__zone_values.F90:29
et__zone_values::pet_zone
type(data_catalog_entry_t), pointer pet_zone
Definition
et__zone_values.F90:31
et__zone_values::et_zone
integer(c_int), dimension(:), allocatable et_zone
Definition
et__zone_values.F90:34
et__zone_values::pet_grid
type(data_catalog_entry_t), pointer, public pet_grid
Definition
et__zone_values.F90:32
et__zone_values::et_zone_values_calculate
subroutine, public et_zone_values_calculate()
Definition
et__zone_values.F90:167
exceptions
Definition
exceptions.F90:1
exceptions::die
subroutine, public die(smessage, smodule, iline, shints, scalledby, icalledbyline)
Definition
exceptions.F90:140
file_operations
Definition
file_operations.F90:1
fstring
Definition
fstring.F90:1
fstring_list
Definition
fstring_list.F90:1
simulation_datetime
Definition
simulation_datetime.F90:1
simulation_datetime::sim_dt
type(date_range_t), public sim_dt
Definition
simulation_datetime.F90:45
constants_and_conversions::asfloat
Definition
constants_and_conversions.F90:134
constants_and_conversions::asint
Definition
constants_and_conversions.F90:152
data_catalog_entry::data_catalog_entry_t
Definition
data_catalog_entry.F90:46
exceptions::assert
Definition
exceptions.F90:15
fstring::ascharacter
Definition
fstring.F90:44
fstring::chomp
Definition
fstring.F90:75
fstring::fieldcount
Definition
fstring.F90:80
fstring::dquote
Definition
fstring.F90:95
fstring_list::fstring_list_t
Definition
fstring_list.F90:21
src
et__zone_values.F90
Generated on
for Soil Water Balance (SWB2) by
1.17.0