Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
growing_degree_day_baskerville_emin.F90
Go to the documentation of this file.
2
3 use iso_c_binding
4
6 use datetime , only : mmdd2doy
7 use exceptions
9 use parameters
11 use fstring_list
12 implicit none
13
14 private
15
18
19 real (c_float), allocatable :: gdd_base(:)
20 real (c_float), allocatable :: gdd_max(:)
21 integer (c_int), allocatable :: gdd_reset_date(:)
22
23contains
24
25 subroutine growing_degree_day_be_initialize( is_cell_active, landuse_index )
26
27 logical (c_bool), intent(in) :: is_cell_active(:,:)
28 integer (c_int), intent(in) :: landuse_index(:)
29
30 ! [ LOCALS ]
31 integer (c_int) :: status
32 integer (c_int) :: indx
33 type (fstring_list_t) :: parameter_list
34 type (fstring_list_t) :: gdd_reset_val_list
35 character (len=32) :: sbuf
36 real (c_float), allocatable :: gdd_base_l(:)
37 real (c_float), allocatable :: gdd_max_l(:)
38 integer (c_int) :: number_of_landuse_codes
39 integer (c_int), allocatable :: landuse_code(:)
40
41 allocate( gdd_base( count( is_cell_active ) ), stat=status )
42 call assert( status == 0, "Problem allocating memory", __file__, __line__ )
43
44 allocate( gdd_max( count( is_cell_active ) ), stat=status )
45 call assert( status == 0, "Problem allocating memory", __file__, __line__ )
46
47 !> create string list that allows for alternate heading identifiers for the landuse code
48 call parameter_list%append("LU_Code")
49 call parameter_list%append("Landuse_Code")
50 call parameter_list%append("Landuse_Lookup_Code")
51
52 !> Determine how many landuse codes are present
53 call params%get_parameters( slkeys=parameter_list, ivalues=landuse_code )
54 number_of_landuse_codes = count( landuse_code >= 0 )
55 call parameter_list%clear()
56
57 call parameter_list%append("GDD_Base_Temp")
58 call parameter_list%append("GDD_Base_Temperature")
59 call parameter_list%append("GDD_Base")
60
61 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_base_l )
62 call parameter_list%clear()
63
64 call parameter_list%append("GDD_Max_Temp")
65 call parameter_list%append("GDD_Maximum_Temperature")
66 call parameter_list%append("GDD_Maximum_Temp")
67 call parameter_list%append("GDD_Max")
68
69 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_max_l )
70 call parameter_list%clear()
71
72 call parameter_list%append("GDD_Reset_Date")
73 call parameter_list%append("GDD_Reset")
74
75 call params%get_parameters( slkeys=parameter_list, slvalues=gdd_reset_val_list )
76 call parameter_list%clear()
77
78 allocate( gdd_reset_date( count( is_cell_active ) ), stat=status )
79 call assert( status==0, "Problem allocating memory.", __file__, __line__ )
80
81 if ( gdd_reset_val_list%count == number_of_landuse_codes &
82 .and. gdd_reset_val_list%count_matching("<NA>") == 0 ) then
83
84 ! retrieve gdd reset values; convert mm/dd to DOY
85 do indx=1, gdd_reset_val_list%count
86 sbuf = gdd_reset_val_list%get( indx )
87
88 where ( landuse_index == indx )
89 gdd_reset_date = mmdd2doy( sbuf, "GDD_RESET_DATE" )
90 end where
91
92 enddo
93
94 else
95
96 ! if no GDD_RESET_DATE found in parameter tables, assign the default: reset GDD at end of calendar year
97 gdd_reset_date = 365_c_int
98
99 endif
100
101
102 if ( ubound( gdd_max_l, 1 ) == number_of_landuse_codes &
103 .and. gdd_max_l(1) > rtinyval ) then
104
105 do indx=1, ubound( landuse_index, 1)
106 if( landuse_index( indx ) >= lbound( gdd_max, 1) .and. landuse_index( indx ) <= ubound( gdd_max, 1) ) then
107 gdd_max( indx ) = gdd_max_l( landuse_index( indx ) )
108 endif
109 enddo
110
111 else
112
113 ! if no GDD_MAX found in parameter tables, assign the default FAO-56 value
114 gdd_max = 86.0_c_float
115
116 endif
117
118 if ( ubound( gdd_base_l, 1 ) == number_of_landuse_codes &
119 .and. gdd_base_l(1) > rtinyval ) then
120
121 do indx=1, ubound( landuse_index, 1)
122 if( landuse_index( indx ) >= lbound( gdd_base, 1) .and. landuse_index( indx ) <= ubound( gdd_base, 1) ) then
123 gdd_base( indx ) = gdd_base_l( landuse_index( indx ) )
124 endif
125 enddo
126
127 else
128
129 ! if no GDD_Base found in parameter tables, assign the default FAO-56 value
130 gdd_base = 50.0_c_float
131
132 endif
133
135
136!--------------------------------------------------------------------------------------------------
137
138 subroutine growing_degree_day_be_calculate( gdd, tmean, tmin, tmax, order )
139
140 ! [ ARGUMENTS ]
141 real (c_float), intent(inout) :: gdd(:)
142 real (c_float), intent(in) :: tmean(:)
143 real (c_float), intent(in) :: tmin(:)
144 real (c_float), intent(in) :: tmax(:)
145 integer (c_int), intent(in) :: order(:)
146
147 ! [ LOCALS ]
148 real (c_float) :: tmax_l
149 real (c_float) :: dd
150 real (c_float) :: w
151 real (c_float) :: at
152 real (c_float) :: a
153 integer (c_int) :: indx
154
155 do indx=lbound(order,1),ubound(order,1)
156
157 if ( sim_dt%iDOY == gdd_reset_date( order(indx) ) ) gdd(indx) = 0.0_c_float
158
159 tmax_l = min( tmax(indx), gdd_max( order(indx) ) )
160
161 if ( tmax_l <= gdd_base( order(indx) ) ) then
162
163 dd = 0.0_c_float
164
165 elseif ( tmin(indx) >= gdd_base( order(indx) ) ) then
166
167 dd = min(( tmean(indx) - gdd_base( order(indx) )), (gdd_max( order(indx) ) - gdd_base( order(indx) ) ) )
168
169 else
170
171 w = ( tmax_l - tmin(indx)) / 2.0_c_float
172
173 at = ( gdd_base( order(indx) ) - tmean(indx) ) / w
174
175 if ( at > 1 ) at = 1.0_c_float
176 if ( at < -1 ) at = -1._c_float
177
178 a = asin( at )
179
180 dd = real(( ( w * cos( a ) ) - ( ( gdd_base( order(indx) ) - tmean(indx) ) &
181 * ( real( pi / 2._c_double, c_float ) - a ) ) ) / pi, c_float)
182
183 endif
184
185 gdd(indx) = gdd(indx) + dd
186
187 enddo
188
190
191!--------------------------------------------------------------------------------------------------
192
This module contains physical constants and convenience functions aimed at performing unit conversion...
real(c_float), parameter, public rtinyval
real(c_double), parameter, public pi
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
integer(c_int) function, public mmdd2doy(smmdd, sinputitemname)
integer(c_int), dimension(:), allocatable, public gdd_reset_date
subroutine, public growing_degree_day_be_calculate(gdd, tmean, tmin, tmax, order)
real(c_float), dimension(:), allocatable, public gdd_base
subroutine, public growing_degree_day_be_initialize(is_cell_active, landuse_index)
real(c_float), dimension(:), allocatable, public gdd_max
Provide support for use of netCDF files as input for time-varying, gridded meteorlogic data,...
type(parameters_t), public params
type(date_range_t), public sim_dt