Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
growing_degree_day.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
19
20 real (c_float), allocatable :: gdd_base(:)
21 real (c_float), allocatable :: gdd_max(:)
22 integer (c_int), allocatable :: gdd_reset_date(:)
23
24contains
25
26 subroutine growing_degree_day_initialize( is_cell_active, landuse_index )
27
28 logical (c_bool), intent(in) :: is_cell_active(:,:)
29 integer (c_int), intent(in) :: landuse_index(:)
30
31 ! [ LOCALS ]
32 integer (c_int) :: status
33 integer (c_int) :: indx
34 type (fstring_list_t) :: parameter_list
35 type (fstring_list_t) :: gdd_reset_val_list
36 character (len=32) :: sbuf
37 real (c_float), allocatable :: gdd_base_l(:)
38 real (c_float), allocatable :: gdd_max_l(:)
39 integer (c_int) :: number_of_landuse_codes
40 integer (c_int), allocatable :: landuse_code(:)
41
42 allocate( gdd_base( count( is_cell_active ) ), stat=status )
43 call assert( status == 0, "Problem allocating memory", __file__, __line__ )
44
45 allocate( gdd_max( count( is_cell_active ) ), stat=status )
46 call assert( status == 0, "Problem allocating memory", __file__, __line__ )
47
48 !> create string list that allows for alternate heading identifiers for the landuse code
49 call parameter_list%append("LU_Code")
50 call parameter_list%append("Landuse_Code")
51 call parameter_list%append("Landuse_Lookup_Code")
52
53 !> Determine how many landuse codes are present
54 call params%get_parameters( slkeys=parameter_list, ivalues=landuse_code )
55 number_of_landuse_codes = count( landuse_code >= 0 )
56 call parameter_list%clear()
57
58 call parameter_list%append("GDD_Base_Temp")
59 call parameter_list%append("GDD_Base_Temperature")
60 call parameter_list%append("GDD_Base")
61
62 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_base_l )
63 call parameter_list%clear()
64
65 call parameter_list%append("GDD_Max_Temp")
66 call parameter_list%append("GDD_Maximum_Temperature")
67 call parameter_list%append("GDD_Maximum_Temp")
68 call parameter_list%append("GDD_Max")
69
70 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_max_l )
71 call parameter_list%clear()
72
73 call parameter_list%append("GDD_Reset_Date")
74 call parameter_list%append("GDD_Reset")
75
76 call params%get_parameters( slkeys=parameter_list, slvalues=gdd_reset_val_list )
77 call parameter_list%clear()
78
79 allocate( gdd_reset_date( count( is_cell_active ) ), stat=status )
80 call assert( status==0, "Problem allocating memory.", __file__, __line__ )
81
82 if ( gdd_reset_val_list%count == number_of_landuse_codes &
83 .and. gdd_reset_val_list%count_matching("<NA>") == 0 ) then
84
85 ! retrieve gdd reset values; convert mm/dd to DOY
86 do indx=1, gdd_reset_val_list%count
87 sbuf = gdd_reset_val_list%get( indx )
88
89 where ( landuse_index == indx )
90 gdd_reset_date = mmdd2doy( sbuf, "GDD_RESET_DATE" )
91 end where
92
93 enddo
94
95 else
96
97 ! if no GDD_RESET_DATE found in parameter tables, assign the default: reset GDD at end of calendar year
98 gdd_reset_date = 365_c_int
99
100 endif
101
102
103 if ( ubound( gdd_max_l, 1 ) == number_of_landuse_codes &
104 .and. gdd_max_l(1) > rtinyval ) then
105
106 do indx=1, ubound( landuse_index, 1)
107 gdd_max( indx ) = gdd_max_l( landuse_index( indx ) )
108 enddo
109
110 else
111
112 ! if no GDD_MAX found in parameter tables, assign the default FAO-56 value
113 gdd_max = 86.0_c_float
114
115 endif
116
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 gdd_base( indx ) = gdd_base_l( landuse_index( indx ) )
123 enddo
124
125 else
126
127 ! if no GDD_Base found in parameter tables, assign the default FAO-56 value
128 gdd_base = 50.0_c_float
129
130 endif
131
132 end subroutine growing_degree_day_initialize
133
134!--------------------------------------------------------------------------------------------------
135
136 impure elemental subroutine growing_degree_day_calculate( gdd, tmean, order )
137
138 ! [ ARGUMENTS ]
139 real (c_float), intent(inout) :: gdd
140 real (c_float), intent(in) :: tmean
141 integer (c_int), intent(in) :: order
142
143 associate( doy_to_reset_gdd => gdd_reset_date( order ), &
144 gdd_max => gdd_max( order ), &
145 gdd_base => gdd_base( order ) )
146
147 if ( sim_dt%iDOY == doy_to_reset_gdd ) gdd = 0.0_c_float
148
149 gdd = gdd + max(tmean, gdd_base) - gdd_base
150
151 end associate
152
153 end subroutine growing_degree_day_calculate
154
155!--------------------------------------------------------------------------------------------------
156
157 impure elemental subroutine modified_growing_degree_day_calculate( gdd, tmin, tmax, order )
158
159 ! [ ARGUMENTS ]
160 real (c_float), intent(inout) :: gdd
161 real (c_float), intent(in) :: tmin
162 real (c_float), intent(in) :: tmax
163 integer (c_int), intent(in) :: order
164
165 associate( doy_to_reset_gdd => gdd_reset_date( order ), &
166 gdd_max => gdd_max( order ), &
167 gdd_base => gdd_base( order ) )
168
169 if ( sim_dt%iDOY == doy_to_reset_gdd ) gdd = 0.0_c_float
170
171 gdd = gdd + max((max(tmin, gdd_base) + min(tmax,gdd_max))/2.0_c_float, gdd_base) - gdd_base
172
173 end associate
174
176
177end module growing_degree_day
This module contains physical constants and convenience functions aimed at performing unit conversion...
real(c_float), parameter, public rtinyval
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)
subroutine, public growing_degree_day_initialize(is_cell_active, landuse_index)
impure elemental subroutine, public modified_growing_degree_day_calculate(gdd, tmin, tmax, order)
real(c_float), dimension(:), allocatable, public gdd_max
integer(c_int), dimension(:), allocatable, public gdd_reset_date
real(c_float), dimension(:), allocatable, public gdd_base
impure elemental subroutine, public growing_degree_day_calculate(gdd, tmean, order)
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