67 logical (c_bool),
intent(in) :: is_active(:,:)
71 integer (c_int) :: number_of_landuse_codes
72 integer (c_int),
allocatable :: landuse_table_codes(:)
73 integer (c_int) :: num_records
74 logical (c_bool) :: are_lengths_unequal
75 integer (c_int) :: index
77 integer (c_int) :: status
78 character (len=256) :: str_buffer
84 character (len=31) :: temp_str
87 call assert( status==0,
"Failed to allocate memory.", __file__, __line__ )
90 call assert( status==0,
"Failed to allocate memory.", __file__, __line__ )
93 call sl_temp_list%append(
"LU_Code" )
94 call sl_temp_list%append(
"Landuse_Lookup_Code" )
97 call params%get_parameters( slkeys=sl_temp_list, ivalues=landuse_table_codes )
98 number_of_landuse_codes = count( landuse_table_codes >= 0 )
101 call sl_temp_list%clear()
102 call sl_temp_list%append(
"Monthly_Irrigation_Schedule" )
103 call sl_temp_list%append(
"Monthly_Irr_Schedule" )
104 call sl_temp_list%append(
"Irrigation_Application_Schedule" )
105 call sl_temp_list%append(
"Monthly_Application_Schedule" )
108 call params%get_parameters( slkeys=sl_temp_list, slvalues=sl_monthly_irrigation_schedule )
111 call sl_temp_list%clear()
112 call sl_temp_list%append(
"Fraction_irrigation_from_GW")
113 call sl_temp_list%append(
"Frac_irr_fm_GW")
114 call sl_temp_list%append(
"Fraction_irrigation_from_groundwater")
115 call sl_temp_list%append(
"Frac_irrigation_from_GW")
116 call sl_temp_list%append(
"Fraction_of_irrigation_from_GW")
117 call sl_temp_list%append(
"Fraction_of_irrigation_from_groundwater")
122 call sl_temp_list%clear()
123 call sl_temp_list%append(
"Max_allowable_depletion")
124 call sl_temp_list%append(
"Maximum_allowable_depletion")
125 call sl_temp_list%append(
"MAD")
127 call params%get_parameters( slkeys=sl_temp_list, &
133 call sl_temp_list%clear()
134 call sl_temp_list%append(
"Irrigation_length")
135 call sl_temp_list%append(
"Irrigation_days")
136 call sl_temp_list%append(
"Irrigation_days_since_planting")
138 call params%get_parameters( slkeys=sl_temp_list, slvalues=sl_irrigation_days, lfatal=
false )
142 call sl_temp_list%clear()
143 call sl_temp_list%append(
"First_day_of_irrigation")
144 call sl_temp_list%append(
"First_DOY_irrigation")
145 call sl_temp_list%append(
"Irrigation_start")
146 call sl_temp_list%append(
"Irrigation_start_date")
148 call params%get_parameters( slkeys=sl_temp_list, slvalues=sl_irrigation_begin, lfatal=
true )
152 call sl_temp_list%clear()
153 call sl_temp_list%append(
"Last_day_of_irrigation")
154 call sl_temp_list%append(
"Last_DOY_irrigation")
155 call sl_temp_list%append(
"Irrigation_end")
156 call sl_temp_list%append(
"Irrigation_end_date")
158 call params%get_parameters( slkeys=sl_temp_list, slvalues=sl_irrigation_end, lfatal=
true )
159 call sl_temp_list%clear()
163 call sl_temp_list%clear()
164 call sl_temp_list%append(
"Irrigation_efficiency")
165 call sl_temp_list%append(
"Irrigation_application_efficiency")
167 call params%get_parameters( slkeys=sl_temp_list, &
173 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
175 if ( are_lengths_unequal ) &
176 call warn( smessage=
"The number of values specifying irrigation application" &
178 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
180 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
186 call assert( status==0,
"Problem allocating memory.", __file__, __line__ )
189 if ( sl_irrigation_begin%count_matching(
"<NA>") == 0 )
then
191 do index = 1, sl_irrigation_begin%count
192 str_buffer = sl_irrigation_begin%get( index )
193 if ( scan(str_buffer,
"/-") /= 0 )
then
202 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
204 if ( are_lengths_unequal ) &
205 call warn( smessage=
"The number of values specifying first day of irrigation (" &
206 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
208 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
214 call warn(
"No value was found to define the first day of irrigation " &
215 //
"('first_day_of_irrigation' or 'irrigation_start').", &
216 shints=
"Make sure there is a lookup table with the column name " &
217 //
"'first_day_of_irrigation' or 'irrigation_start'.", lfatal=
true )
223 call assert( status==0,
"Problem allocating memory.", __file__, __line__ )
225 if ( sl_irrigation_end%count_matching(
"<NA>") == 0 )
then
227 do index = 1, sl_irrigation_end%count
228 str_buffer = sl_irrigation_end%get( index )
229 if ( scan(str_buffer,
"/-") /= 0 )
then
238 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
240 if ( are_lengths_unequal ) &
241 call warn( smessage=
"The number of values specifying last day of irrigation (" &
242 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
244 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
249 call warn(
"No value was found to define the last day of irrigation " &
250 //
"('last_day_of_irrigation' or 'irrigation_end').", &
251 shints=
"Make sure there is a lookup table with the column name " &
252 //
"'last_day_of_irrigation' or 'irrigation_end'.", lfatal=
true )
257 call assert( status==0,
"Problem allocating memory.", __file__, __line__ )
261 if ( sl_irrigation_days%count_matching(
"<NA>") == 0 )
then
265 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
267 if ( are_lengths_unequal ) &
268 call warn( smessage=
"The number of values specifying 'irrigation_length' (" &
269 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
271 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
277 call warn(
"No value was found to define the maximum number of days of irrigation ('irrigation_length').", &
278 shints=
"Make sure there is a lookup table with the column name " &
279 //
"'irrigation_length'.", lfatal=
true )
284 call sl_temp_list%clear()
285 call sl_temp_list%append(
"Irrigation_application_method")
286 call sl_temp_list%append(
"Irrigation_application_scheme")
287 call sl_temp_list%append(
"Irrigation_application_option")
288 call sl_temp_list%append(
"Application_method")
289 call sl_temp_list%append(
"Application_scheme")
290 call sl_temp_list%append(
"Application_option")
292 call params%get_parameters( slkeys=sl_temp_list, slvalues=sl_application_method, lfatal=
true )
293 call sl_temp_list%clear()
296 call assert( status==0,
"Problem allocating memory.", __file__, __line__ )
300 call sl_temp_list%clear()
301 call sl_temp_list%append(
"Application_amount")
302 call sl_temp_list%append(
"Irrigation_amount")
305 call sl_temp_list%clear()
309 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
311 if ( are_lengths_unequal ) &
312 call warn( smessage=
"The number of values specifying date of first " &
313 //
"irrigation application (" &
314 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
316 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
319 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
321 if ( are_lengths_unequal ) &
322 call warn( smessage=
"The number of values specifying date of last irrigation" &
324 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
326 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
329 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
331 if ( are_lengths_unequal ) &
332 call warn( smessage=
"The number of values specifying the fraction of irrigation" &
333 //
" from groundwater (" &
334 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
336 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
339 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
341 if ( are_lengths_unequal ) &
342 call warn( smessage=
"The number of values for the maximum allowable depletion " &
344 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
346 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
349 num_records = sl_monthly_irrigation_schedule%count
350 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
353 call assert( status==0,
"Problem allocating memory")
355 if ( are_lengths_unequal )
then
356 call warn( smessage=
"The number of values defining monthly irrigation application" &
357 //
" timing ("//
ascharacter( num_records )//
")~does not match the number of" &
358 //
" landuse codes ("//
ascharacter( number_of_landuse_codes )//
"). ~Assuming" &
359 //
" that irrigation is applied *every* day [default].", &
360 smodule=__file__, iline=__line__, lecho=.
true._c_bool, iloglevel=
log_all )
368 do index=1, number_of_landuse_codes
369 temp_str = sl_monthly_irrigation_schedule%get( index )
379 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
381 if ( are_lengths_unequal ) &
382 call warn( smessage=
"The number of values for the irrigation application option (" &
383 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
385 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
389 are_lengths_unequal = ( num_records /= number_of_landuse_codes )
391 if ( are_lengths_unequal ) &
392 call warn( smessage=
"The number of values for the irrigation application amount (" &
393 //
ascharacter( num_records )//
") does not match the number of landuse values (" &
395 smodule=__file__, iline=__line__, lfatal=.
true._c_bool )
411 call logs%write(
" ## Initializing irrigation application rules and application schedules ##", ilinesbefore=1, &
412 ilinesafter=1, iloglevel=
log_all )
414 do index = 1, sl_application_method%count
416 str_buffer = sl_application_method%get( index )
418 if ( str_buffer .contains.
"capacity")
then
420 elseif ( str_buffer .contains.
"deficit")
then
422 elseif ( str_buffer .contains.
"constant")
then
424 elseif ( str_buffer .contains.
"demand")
then
431 call logs%write(
" landuse "//
ascharacter( landuse_table_codes( index ) )//
": " &
458 total_available_water, &
463 num_days_since_planting, &
468 real (c_float),
intent(inout) :: irrigation_amount
469 integer (c_int),
intent(in) :: landuse_index
470 real (c_double),
intent(in) :: soil_storage
471 real (c_float),
intent(in) :: soil_storage_max
472 real (c_double),
intent(in) :: total_available_water
473 real (c_float),
intent(in) :: rainfall
474 real (c_float),
intent(in) :: runoff
475 real (c_float),
intent(in) :: crop_etc
476 real (c_float),
intent(in) :: irrigation_mask
477 integer (c_int),
intent(in) :: num_days_since_planting
478 real (c_float),
intent(in),
optional :: monthly_rainfall
479 real (c_float),
intent(in),
optional :: monthly_runoff
482 real (c_float) :: depletion_fraction
484 integer (c_int) :: month
485 integer (c_int) :: day
486 integer (c_int) :: year
489 integer (c_int) :: days_in_month
490 integer (c_int) :: num_days_from_origin
491 integer (c_int) :: irrigation_days_per_month
492 real (c_float) :: efficiency
493 real (c_float) :: interim_irrigation_amount
494 integer (c_int) :: option
500 associate( dt =>
sim_dt%curr )
503 month =
asint( dt%iMonth )
504 day =
asint( dt%iDay )
506 days_in_month =
sim_dt%iDaysInMonth
508 num_days_from_origin =
sim_dt%iNumDaysFromOrigin
523 irrigation_amount = 0.0_c_float
524 interim_irrigation_amount = 0.0_c_float
525 depletion_fraction = 0.0_c_float
531 if ( soil_storage_max <= 0.0_c_float )
exit
532 if ( irrigation_mask < 1.0e-6_c_float )
exit
538 if ( total_available_water > 0.0_c_float )
then
539 depletion_fraction = real(min( ( soil_storage_max - soil_storage ) / total_available_water, 1.0_c_double ), c_float)
541 depletion_fraction = real(min( ( soil_storage_max - soil_storage ) / soil_storage_max, 1.0_c_double ), c_float)
546 select case ( option )
551 interim_irrigation_amount = real(max( 0.0_c_double, real(soil_storage_max, c_double) - soil_storage ), c_float)
558 interim_irrigation_amount = real(max( 0.0_c_double, real(
application_amount( landuse_index ), c_double) &
559 * soil_storage_max - soil_storage ), c_float)
570 if (
present( monthly_runoff ) .and.
present( monthly_rainfall ) )
then
574 if ( irrigation_days_per_month <= 0 )
then
575 interim_irrigation_amount = 0.0_c_float
577 interim_irrigation_amount = max( 0.0_c_float, &
578 ( crop_etc * real( days_in_month, c_float) + monthly_runoff - monthly_rainfall ) ) &
579 / real( irrigation_days_per_month, c_float )
584 interim_irrigation_amount = max( 0.0_c_float, crop_etc + runoff - rainfall )
590 interim_irrigation_amount = 0.0_c_float
596 irrigation_amount = interim_irrigation_amount &