42 real(srp),
optional,
intent(in) :: mass
44 if (
present(mass))
then
64 class(
food_item),
intent(in) :: what_to_copy
66 this%mass = what_to_copy%mass
77 class(
food_item),
intent(in),
target :: this
80 integer(LONG),
optional,
intent(in) :: time_step
82 logical,
optional,
intent(out) :: is_provided
86 integer(LONG) :: time_step_loc
90 if (
present(time_step))
then
91 time_step_loc = time_step
102 if(
present(is_provided)) is_provided = .true.
105 if (
present(is_provided)) is_provided = .false.
111 if (
present(is_provided)) is_provided = .false.
123 integer(LONG),
intent(in) :: max_steps
127 logical,
allocatable,
dimension(:) :: is_day_now, is_offset
136 allocate(is_day_now(max_steps))
137 allocate(is_offset(max_steps))
145 if ( is_day_now(i) .and. .not. is_offset(i) )
then
167 use csv_io ,
only: csv_matrix_read
170 integer(LONG),
intent(in) :: max_steps
172 character(len=*),
intent(in) :: csv_file
174 integer,
optional,
intent(in) :: column
179 logical,
optional,
intent(in) :: is_single
181 real(srp),
allocatable,
dimension(:,:) :: raw_data_csv, raw_data_csv_get
182 logical,
allocatable,
dimension(:) :: pattern_sec
186 logical,
allocatable,
dimension(:) :: pattern_min
188 logical :: is_success, is_single_loc
189 integer :: column_loc
191 integer(LONG) :: i, j, k, l, fill_n
194 integer(LONG),
parameter :: day_sec = 24 *
hour
197 integer,
parameter :: minutes_hour = 60
199 integer(LONG) :: get_rows, get_cols, max_rows
201 if (
present(is_single) )
then
202 is_single_loc = is_single
204 is_single_loc = .false.
207 raw_data_csv_get = csv_matrix_read( csv_file, csv_file_status=is_success, &
208 missing_code=0.0_srp )
210 get_rows =
size(raw_data_csv_get,1)
211 get_cols =
size(raw_data_csv_get,2)
213 if (is_single_loc)
then
216 max_rows = min(get_rows, day_sec)
219 if (
present(column))
then
220 column_loc = min( column,
size(raw_data_csv_get,2) )
230 if (is_single_loc)
then
231 allocate(raw_data_csv(get_rows, get_cols))
233 allocate(raw_data_csv(day_sec, get_cols))
236 raw_data_csv = missing
237 raw_data_csv(:,column_loc) = 0.0_srp
238 raw_data_csv(1:max_rows,:) = raw_data_csv_get(1:max_rows,:)
239 deallocate(raw_data_csv_get)
248 allocate(pattern_sec(max_steps))
249 allocate ( pattern_min( 24 * minutes_hour ) )
252 pattern_sec = .false.
253 pattern_min = .false.
255 fill_n =
size(raw_data_csv,1)
257 if (is_single_loc)
then
259 do i = 1, min(fill_n, max_steps/
minute)
260 if (raw_data_csv(i,column_loc) /= 0.0_srp )
then
263 pattern_sec(l) = .true.
273 do i=1, min(
size(raw_data_csv, 1),
size(pattern_min) )
274 if ( raw_data_csv(i,column_loc) == 0.0_srp )
then
275 pattern_min(i) = .false.
277 pattern_min(i) = .true.
284 if ( j >= minutes_hour )
then
288 if ( k >
size(pattern_min) )
then
307 use csv_io ,
only: csv_matrix_read
310 integer(LONG),
intent(in) :: max_steps
312 character(len=*),
intent(in) :: csv_file
314 integer,
optional,
intent(in) :: column
319 logical,
optional,
intent(in) :: is_single
321 real(srp),
allocatable,
dimension(:,:) :: raw_data_csv, raw_data_csv_get
322 logical,
allocatable,
dimension(:) :: pattern_sec
324 logical :: is_success, is_single_loc
325 integer :: column_loc
327 integer(LONG) :: i, j, fill_n
330 integer(LONG),
parameter :: day_sec = 24 *
hour
332 integer(LONG) :: get_rows, get_cols, max_rows
334 if (
present(is_single) )
then
335 is_single_loc = is_single
337 is_single_loc = .false.
340 raw_data_csv_get = csv_matrix_read( csv_file, csv_file_status=is_success, &
341 missing_code=0.0_srp )
343 get_rows =
size(raw_data_csv_get,1)
344 get_cols =
size(raw_data_csv_get,2)
346 if (is_single_loc)
then
349 max_rows = min(get_rows, day_sec)
352 if (
present(column))
then
353 column_loc = min( column,
size(raw_data_csv_get,2) )
363 if (is_single_loc)
then
364 allocate(raw_data_csv(get_rows, get_cols))
366 allocate(raw_data_csv(day_sec, get_cols))
369 raw_data_csv = missing
370 raw_data_csv(:,column_loc) = 0.0_srp
371 raw_data_csv(1:max_rows,:) = raw_data_csv_get(1:max_rows,:)
372 deallocate(raw_data_csv_get)
381 allocate(pattern_sec(max_steps))
384 pattern_sec = .false.
386 fill_n = min(
size(raw_data_csv,1), max_steps)
388 if (is_single_loc)
then
390 if (raw_data_csv(i,column_loc) /= 0.0_srp )
then
391 pattern_sec(i) = .true.
398 if (j > day_sec) j = 1
399 if (raw_data_csv(j,column_loc) /= 0.0_srp )
then
400 pattern_sec(i) = .true.
417 integer(LONG),
intent(in) :: check_n
421 integer,
intent(in) :: int1
425 integer,
intent(in) :: int2
432 mod_n = mod( check_n, (int1+int2) )
434 if ( mod_n < int1 )
then
445 elemental function is_day(time_step)
result (is_day_now)
448 integer(LONG),
intent(in),
optional :: time_step
449 logical :: is_day_now
451 integer(LONG) :: time_step_loc
453 if (
present(time_step))
then
454 time_step_loc = time_step
This module defines global parameters and general-level computational utilities.
real(srp), public global_food_input_rate
Standard rate of food item input, per minute. Configuration file example:
integer, dimension(2), public global_interval_food_param
Parameters of the food provisioning pattern:
integer, public global_day_starts_hour
Default hour at which the "daytime" is normally started. This means, in particular,...
integer, public global_run_model_feed_offset
The offset (delay) to start feeding at the beginning of the simulation, Note that the parameter file ...
integer, parameter, public minute
integer, parameter, public hour
Global time constants, number of sec in hour and min.
integer(long), public global_time_step
Global variable that defines the current time step.
logical, dimension(:), allocatable, public global_interval_food_pattern
Global food provisioning pattern, logical TRUE/FALSE for each time step.
elemental integer(long) function rate2int(rate_min)
The function converts rate per min to interval in seconds.
integer, public global_hours_daytime_feeding
Default duration of the day time in hours, night duration is defined as 24 - ::global_hours_day_feedi...
Module defining the environment.
impure subroutine food_provisioning_pattern_init(max_steps)
Initialise and set up the global food provisioning pattern array commondata::global_interval_food_pat...
elemental subroutine food_item_copy_assign_to(this, what_to_copy)
Copy what_to_copy object to this (target) object.
impure subroutine food_provisioning_get_file(max_steps, csv_file, column, is_single)
Read the food provisioning pattern from a CSV file. This allows to get any arbitrary pattern of food ...
elemental logical function is_day(time_step)
Determine if the time step corresponds to day (returns true) or night (returns false).
elemental logical function schedule_2_int(check_n, int1, int2)
Schedule two intervals N1 = food given, steps, N2 = gap, steps.
elemental subroutine food_item_init(this, mass)
Initialise the food item with its parameters.
impure subroutine food_provisioning_get_raw(max_steps, csv_file, column, is_single)
Read the food provisioning pattern from a CSV file in raw format by s. This allows to get any arbitra...
impure class(food_item) function, pointer food_item_schedule_feed(this, time_step, is_provided)
Schedule the provision of food items depending on the time step. It returns a pointer to the food ite...