28 logical (c_bool),
intent(in) :: is_cell_active(:,:)
29 integer (c_int),
intent(in) :: landuse_index(:)
32 integer (c_int) :: status
33 integer (c_int) :: indx
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(:)
42 allocate(
gdd_base( count( is_cell_active ) ), stat=status )
43 call assert( status == 0,
"Problem allocating memory", __file__, __line__ )
45 allocate(
gdd_max( count( is_cell_active ) ), stat=status )
46 call assert( status == 0,
"Problem allocating memory", __file__, __line__ )
49 call parameter_list%append(
"LU_Code")
50 call parameter_list%append(
"Landuse_Code")
51 call parameter_list%append(
"Landuse_Lookup_Code")
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()
58 call parameter_list%append(
"GDD_Base_Temp")
59 call parameter_list%append(
"GDD_Base_Temperature")
60 call parameter_list%append(
"GDD_Base")
62 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_base_l )
63 call parameter_list%clear()
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")
70 call params%get_parameters( slkeys=parameter_list, fvalues=gdd_max_l )
71 call parameter_list%clear()
73 call parameter_list%append(
"GDD_Reset_Date")
74 call parameter_list%append(
"GDD_Reset")
76 call params%get_parameters( slkeys=parameter_list, slvalues=gdd_reset_val_list )
77 call parameter_list%clear()
80 call assert( status==0,
"Problem allocating memory.", __file__, __line__ )
82 if ( gdd_reset_val_list%count == number_of_landuse_codes &
83 .and. gdd_reset_val_list%count_matching(
"<NA>") == 0 )
then
86 do indx=1, gdd_reset_val_list%count
87 sbuf = gdd_reset_val_list%get( indx )
89 where ( landuse_index == indx )
103 if ( ubound( gdd_max_l, 1 ) == number_of_landuse_codes &
104 .and. gdd_max_l(1) >
rtinyval )
then
106 do indx=1, ubound( landuse_index, 1)
107 if( landuse_index( indx ) >= lbound(
gdd_max, 1) .and. landuse_index( indx ) <= ubound(
gdd_max, 1) )
then
108 gdd_max( indx ) = gdd_max_l( landuse_index( indx ) )
119 if ( ubound( gdd_base_l, 1 ) == number_of_landuse_codes &
120 .and. gdd_base_l(1) >
rtinyval )
then
122 do indx=1, ubound( landuse_index, 1)
123 if( landuse_index( indx ) >= lbound(
gdd_base, 1) .and. landuse_index( indx ) <= ubound(
gdd_base, 1) )
then
124 gdd_base( indx ) = gdd_base_l( landuse_index( indx ) )
142 real (c_float),
intent(inout) :: gdd(:)
143 real (c_float),
intent(in) :: tmean(:)
144 real (c_float),
intent(in) :: tmin(:)
145 real (c_float),
intent(in) :: tmax(:)
146 integer (c_int),
intent(in) :: order(:)
149 real (c_float) :: delta
150 real (c_float) :: tmax_l
155 integer (c_int) :: indx
157 do indx=lbound(order,1),ubound(order,1)
161 tmax_l = min( tmax(indx),
gdd_max( order(indx) ) )
163 if ( tmax_l <=
gdd_base( order(indx) ) )
then
167 elseif ( tmin(indx) >=
gdd_base( order(indx) ) )
then
173 w = ( tmax_l - tmin(indx)) / 2.0_c_float
175 at = (
gdd_base( order(indx) ) - tmean(indx) ) / w
177 if ( at > 1 ) at = 1.0_c_float
178 if ( at < -1 ) at = -1._c_float
182 dd = ( ( w * cos( a ) ) - ( (
gdd_base( order(indx) ) - tmean(indx) ) &
183 * ( real(
pi / 2._c_double, c_float ) - a ) ) ) /
pi
187 gdd(indx) = gdd(indx) + dd