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