20 use base_strings,
only : lowercase, parse
23 use,
intrinsic :: iso_fortran_env, only : error_unit
35 use stubs,
only : print_help_switches
37 character(len=LABEL_LEN) :: t_string
40 character(LABEL_LEN),
dimension(:),
allocatable :: cmd_args
47 n_args = command_argument_count()
48 allocate(cmd_args(n_args))
52 call get_command_argument(number = i,
value = cmd_args(i))
53 cmd_args(i) = lowercase(cmd_args(i))
60 if ( any(cmd_args==
"-h") .or. &
61 any(cmd_args==
"--help") .or. &
62 any(cmd_args==
"-help") .or. &
63 any(cmd_args==
"/h") .or. &
64 any(cmd_args==
"/help") )
then
65 call print_help_switches()
73 if ( any(cmd_args==
"-q") .or. any(cmd_args==
"--quiet") .or. &
74 any(cmd_args==
"/q") .or. any(cmd_args==
"/quiet") )
then
83 call get_environment_variable( name=
"FFA_MODEL_PARAMETER_FILE", &
85 if ( len_trim(t_string)==0 )
then
96 call get_environment_variable( name=
"FFA_MODEL_OUTPUT_DEST", &
98 if ( len_trim(t_string)==0 )
then
113 use stubs,
only : cmd_iface_process_commands
114 use csv_io,
only : get_free_funit
116 logical :: is_exit_program
118 integer :: stats_file_unit, file_error_status
119 logical :: is_model_stats_save_header_done, file_exists
134 is_model_stats_save_header_done = .false.
137 if (file_exists)
then
138 is_model_stats_save_header_done = .true.
141 if (is_model_stats_save_header_done)
then
143 " exists, data will be appended."
145 stats_file_unit = get_free_funit()
147 status=
"old", position=
"append", action=
"write", &
148 iostat=file_error_status)
149 if (file_error_status /= 0)
then
150 write(error_unit,*) &
151 ">>> ERROR: file write error! Use `output statistics` " // &
152 "command first, check free space or permissions."
156 close(stats_file_unit)
159 stats_file_unit = get_free_funit()
161 status=
"replace", action=
"write", iostat=file_error_status)
162 if (file_error_status /= 0)
then
163 write(error_unit,*) &
164 ">>> ERROR: file write error! Use `output statistics` " // &
165 "command first, check free space or permissions."
167 write(stats_file_unit,
"(a)") &
170 close(stats_file_unit)
179 use csv_io,
only : get_free_funit, fs_unlink
181 integer,
parameter :: param_funit = 254
183 logical :: config_file_exist, config_param_is_missing
184 logical :: iface_is_gui, is_scale_relative
185 integer :: iin, f_unit_tmp, iostat_f_tmp
186 character(len=:),
allocatable :: tmp_parse
187 character(len=*),
parameter :: f_name_tmp =
".tmpfile"
190 real(srp),
allocatable,
dimension(:):: get_transport_pattern_t
195 if (.not. config_file_exist )
then
216 ptread_r(cf,
'baseline_activity_day', missing)
219 ptread_r(cf,
'baseline_activity_night', missing)
244 ptread_r(cf,
'appetite_threshold_stomach', missing)
251 ptread_r(cf,
'activity_appetite_factor', 0.3_srp)
256 ptread_r(cf,
'branchial_ammonia_rate', missing)
262 "NOTE: branchial and urinal energy loss is fixed rate: ", &
269 write(*,*)
"NOTE: branchial and urinal energy loss zero"
276 ptread_r(cf,
'sda_absorption_rate_max', 0.0_srp )
281 get_transport_pattern_t = ptread_rvec( cf,
'transport_pattern_t' )
286 check_scale:
if ( get_transport_pattern_t(2) > 120.0_srp )
then
291 write(*,*)
"NOTE: transport_pattern_t in raw sec"
297 write(error_unit,
"(a)")
"NOTE: transport_pattern_t in hours"
304 " must have same dimensions", no_exit=.false. )
309 ptread_r(cf,
'transport_pattern_base_temp', missing)
312 ptread_r(cf,
'transport_pattern_base_mass', missing)
330 " must have same dimensions", no_exit=.false. )
339 [1.0_srp, 10.0_srp, 25.0_srp])
342 [1.0_srp, 1.0_srp, 1.0_srp])
347 'stomach_midgut_automatic', .false. )
354 'food_provision_file_repeat', .true. )
357 'food_provisioning_file_by_s', .false. )
367 ptread_s(cf,
"stomach_emptying_matrix",
"")
371 "WARNING: stomach emptying grid matrix is not set, use default:" // &
375 exist=config_file_exist )
376 if (.not. config_file_exist )
then
377 write(error_unit,
"(a)")
"WARNING: stomach emptying grid file " // &
379 write(error_unit,
"(a)")
" use default matrix"
386 write(error_unit,
"(a)")
"WARNING: stomach emptying grid file: " // &
388 write(error_unit,
"(a)") &
389 " does not seem to contain correct data, "// &
399 "stress_grid_hour", [missing, missing])
401 "stress_grid_fact", [missing, missing])
413 write(error_unit,
"(a)") &
414 "WARNING: Stress grid arrays 'stress_grid_hour' and"
415 write(error_unit,
"(a)") &
416 " 'stress_grid_fact' non-conformant, " // &
424 get_stress_array: block
425 integer(LONG),
allocatable,
dimension(:) :: stress_timing_in
426 stress_timing_in = ptread_ivec(cf,
"stress", [unknown])
427 if ( any(stress_timing_in==unknown .or. any(stress_timing_in<0)) )
then
436 end block get_stress_array
448 f_unit_tmp = get_free_funit()
450 status=
'replace', iostat=iostat_f_tmp )
451 if (iostat_f_tmp /= 0)
then
454 " is NOT writeable, reset to default."
459 end if check_write_dir
467 config_param_is_missing = .false.
470 call exit_with_error(
"baseline_activity_day is MISSING", no_exit=.true.)
471 config_param_is_missing = .true.
475 call exit_with_error(
"baseline_activity_night is MISSING", no_exit=.true.)
476 config_param_is_missing = .true.
481 config_param_is_missing = .true.
488 "WARNING: FILE_PARAMETERS: stomach_capacity from body_mass:", &
496 "WARNING: FILE_PARAMETERS: midgut_capacity from body_mass:", &
502 config_param_is_missing = .true.
507 config_param_is_missing = .true.
512 config_param_is_missing = .true.
517 config_param_is_missing = .true.
532 config_param_is_missing = .true.
537 config_param_is_missing = .true.
542 config_param_is_missing = .true.
547 if (config_param_is_missing) &
555 use stubs,
only : exit_with_error_cmd
559 character(len=*),
intent(in) :: message
563 logical,
optional,
intent(in) :: no_exit
566 logical :: no_exit_loc
568 if (
present(no_exit))
then
569 no_exit_loc = no_exit
571 no_exit_loc = .false.
574 call exit_with_error_cmd(message, no_exit_loc)
590 character(*),
intent(in) :: svn_version_string
591 character(len=:),
allocatable :: sversion
595 character(len=len(svn_version_string)) :: svn_string_copy
597 character(len=3) :: delims =
" :$"
599 character(len=len(svn_version_string)),
dimension(3) :: sargs
608 svn_string_copy = svn_version_string
609 call parse(svn_string_copy, delims, sargs, n_args)
610 sversion = trim(sargs(n_args))
619 real(srp) :: check_calc, check_last_param
621 real(srp),
parameter :: hour_diff_max = 1.0_srp
624 real( stomach_emptying_time(global_body_mass, global_temperature), srp)
626 real(global_transport_pattern_t(size(global_transport_pattern_t)),srp)
628 if (abs(check_calc / hour - check_last_param / hour) < hour_diff_max)
then
This module defines global parameters and general-level computational utilities.
character(len=file_name_len), public global_food_pattern_file
Global variable that keeps the file name for the food provisioning pattern see environ::food_provisio...
logical, public global_stress_intervention_is_minutes
Global logical flag setting the time unit for the stress intervention parameter array defined by glob...
character(len= *), parameter, public output_dest_dir
Default output directory: all plot and data file will be saved into this directory by default (local ...
integer, dimension(:), allocatable, public global_transport_pattern_t
Food transport in stomach: Time grid array for interpolation. Configuration file example:
real(srp), public global_food_input_rate
Standard rate of food item input, per minute. Configuration file example:
real(srp), public global_food_item_mass
Standard mass of one food item. Configuration file example:
integer, public global_digestion_delay_min
Delay of digestion, min. It is the delay of absorption after a food item was transmitted to the mid-g...
real(srp), public global_water_uptake_a
Parameters of the logistic water uptake function that defines the temporary pattern of water uptake c...
real(srp), public global_baseline_activity_day
Global baseline locomotor activity pattern (swimming speed) for each time step consists of two compon...
integer, dimension(2), public global_interval_food_param
Parameters of the food provisioning pattern:
logical, public global_food_pattern_file_is_propagate
Global logical flag that defines if the feed scheduling pattern defined by the global_interval_food_p...
character(len= *), parameter, public def_stats_output_file
Default value of the general simulation statistics file defined in commondata::global_stats_output_fi...
real(srp), public global_midgut_mass
Fish mid-gut mass capacity, max. filling capacity. Configuration file example:
integer, public global_day_starts_hour
Default hour at which the "daytime" is normally started. This means, in particular,...
real(srp), public global_appetite_fish_night
Fish appetite at night. This value is normally low because the fish do not feed at night....
real(srp), public global_sda_absorp_rate_max
Defines the specific dynamic action (SDA) that depends on the absorption rate. There are two paramete...
character(len= *), parameter, public output_arrays_csv_file
Default file base-name for saving model output arrays.
real(srp), dimension(:), allocatable, public global_oxygen_grid_y_o2std
This parameter defines the Y axis of the grid: oxygen consumption. See commondata::oxygen_rate_std() ...
logical, public global_stomach_midgut_mass_is_automatic
Logical flag that specifies that the stomach and midgut mass (capacity) are automatically recalculate...
integer, public global_transport_dim
Food transport in stomach: Dimensionality of the transport pattern in the stomach.
integer, public global_run_model_hours
Default duration of the model run in hours. Note that parameter file uses hours as unit....
real(srp), public global_body_mass
Fish body mass, g, at the start of the simulation Configuration file example:
type(stomach_emptying_pattern), public global_stomach_emptying_pattern
Default stomach emptying pattern.
logical, parameter, public is_debug
Logical flag that sets the DEBUG mode. When the program is running in the DEBUG mode,...
real(srp), public global_mid_gut_mm_k_m
Michaelis-Meneten food absorption parameter in mid-gut, (see the_fish::michaelis_menten()) relative ...
character(len= *), parameter, public output_rate_data_csv_file
Default file base-name for saving model rate data.
real(srp), public global_ue_ze_ammonia_excretion
A parameter defining branchial and urine (ZE+UE) energy consumption as a fixed ammonia excretion rate...
character(len=file_name_len), public global_param_file_name
Defines the name of the file that keeps global parameters. This name is normally defined by the envir...
real(srp), public global_stress_activity_decr
Maximum value of the suppressive effect of stress on baseline activity. The actual suppression of the...
integer, public global_run_model_feed_offset
The offset (delay) to start feeding at the beginning of the simulation, Note that the parameter file ...
real(srp), public global_stomach_mass
Fish stomach mass, max. filling capacity. Configuration file example:
real(srp), public global_baseline_activity_night
impure character(len=:) function, allocatable model_parameters_txt()
Produce a text string containing all global parameters of the model.
integer, parameter, public minute
integer, public global_maximum_duration_midgut_min
The maximum duration a food item can be processed in the fish mid-gut, min. If it stays in the mid-gu...
character(len=file_name_len), public global_stats_output_file
Global variable keeping the file name for saving general simulation statistics. Data (rows) for each ...
real(srp), public global_stress_cost_smr
Maximum value of the metabolic cost of stress in units of resting metabolic rate (SMR)....
real(srp), public global_absorption_ratio
Maximum absorption ratio relative to the original dry food item mass. Configuration file example:
real(srp), dimension(*), parameter trout_oxygen_grid_x_temp
Interpolation grid defining the function calculating standard oxygen consumption in rainbow trout bas...
character(len=file_name_len), public global_output_dest
Output directory: all plot and output files will be saved into this directory, default value is set b...
integer, public global_ingestion_delay_min
Delay of ingestion, min.
real(srp), dimension(:), allocatable, public global_temp_factor_midgut_m
Temperature adjustment for absorption is controlled by the two parameters below that define the tempe...
integer, parameter, public hour
Global time constants, number of sec in hour and min.
character(len= *), parameter, public param_file_name_def
Defines the name of the file that keeps global parameters. The parameter file contains the coupled pa...
real(srp), public global_appetite_stomach_threshold
Protective appetite threshold for stomach: this is the maximum value of the the_fish::stomach::appeti...
real(srp), dimension(:), allocatable, public global_stress_fact_suppress
The pattern of stress effect on the appetite is described by two grid arrays global_stress_factor_hou...
real(srp), public global_transport_baseline_fish_mass
The baseline fish mass that applies to the stomach transport pattern defined by global_transport_patt...
character(len=file_name_len), public global_stomach_emptying_matrix_file
Global variable keeping the file name for the baseline stomach emptying matrix file that keeps the st...
real(srp), public global_food_gross_energy
Gross energy content of the feed, MJ/kg (=kJ7g) Configuration file example:
logical, public global_output_stats_is_long
Define if the output stats are saved using the long or short format. In the first case,...
real(srp), dimension(:), allocatable, public global_stress_factor_hour
The pattern of stress effect on the appetite is described by two grid arrays global_stress_factor_hou...
real(srp), dimension(:), allocatable, public global_temp_factor_midgut_t
Temperature adjustment for absorption is controlled by the two parameters below that define the tempe...
logical, public global_is_ue_ze_fixed_rate
Logical flag to choose how branchial and urinal (ZE+UE) energy loss is calculated.
real(srp), public global_temperature
Ambient temperature Configuration file example:
real(srp), public global_sda_factor_max
Defines the specific dynamic action (SDA) that depends on the absorption rate. There are two paramete...
integer, public global_rate_interval
Default rate discretization interval in minutes, this interval is used to plot the ingestion rate.
real(srp), public global_mid_gut_mm_r_max
Michaelis-Meneten food absorption parameter in mid-gut, (see the_fish::michaelis_menten()) relative ...
integer(long), dimension(:), allocatable, public global_stress_intervention_time
The time of stress intervention is set by this array. It is the start points of stressful effects (s)...
real(srp), public global_appetite_activity_factor
Activity appetite factor determining how fish locomotor activity increases with increasing appetite....
real(srp), public global_energy_appetite_rate
The steepness parameter of the Logistic energy component of appetite.
real(srp), public global_appetite_logist_r
Logistic function parameter R for the appetite factor. See the_fish::appetite_func().
character, parameter, public crlf
real(srp), public global_energy_appetite_shift
The shift parameter of the Logistic energy component of appetite.
real(srp), public global_appetite_logist_a
Logistic function parameter A for the appetite factor. See the_fish::appetite_func().
logical, public verbose
Global logical flag to suppress extra text diagnostics and messages, the "quiet mode" or the "verbose...
pure type(stomach_emptying_pattern) function stomach_emptying_def_default()
Define the default stomach emptying data structure ::stomach_emptying_pattern in case the input data ...
real(srp), dimension(:), allocatable, public global_transport_pattern_r
Food transport in stomach: Proportion of food mass left in stomach. Configuration file example:
integer, public global_hours_daytime_feeding
Default duration of the day time in hours, night duration is defined as 24 - ::global_hours_day_feedi...
real(srp), public global_water_uptake_r
Parameters of the logistic water uptake function that defines the temporary pattern of water uptake c...
real(srp), public global_ue_ze_factor
A parameter defining branchial and urine (ZE+UE) energy consumption as a factor to SMR,...
impure character(len=:) function, allocatable stomach_emptying_txt(is_raw_s)
Show the stomach emptying data structure.
real(srp), dimension(:), allocatable, public global_oxygen_grid_x_temp
This parameter defines the X axis of the grid: temperature. See commondata::oxygen_rate_std() for det...
real(srp), public global_transport_baseline_temperature
The baseline temperature that applies to the stomach transport pattern defined by global_transport_pa...
real(srp), dimension(*), parameter trout_oxygen_grid_y_o2std
Interpolation grid defining the function calculating standard oxygen consumption in rainbow trout bas...
logical, public global_food_pattern_file_is_steps
Global logical flag that defines if the feed scheduling pattern defined by the global_food_pattern_fi...
real(srp), public global_water_uptake
Proportion of water uptake, relative of dry mass of the food item. Configuration file example:
Module that defines the runtime behaviour of the model.
elemental logical function check_stomach_transport_emptying_agree()
Check if the stomach pattern matrix agrees with the stomach emptying partameter matrix,...
impure subroutine exit_with_error(message, no_exit)
A wrapper subroutine that will produce error message and halt.
impure subroutine system_run_main()
This subroutine starts and schedules the model.
impure subroutine read_parameters()
The subroutine read_parameters reads global parameters defined in the commondata module from configur...
impure subroutine system_init
This procedure performs basic initialisation of the system:
character(len=:) function, allocatable parse_svn_version(svn_version_string)
Parse and cut revision number in form of string from the whole SVN revision string....
Module that defines the runtime behaviour of the model.
impure subroutine test_run()
The procedure below is TEMPORARY, for testing and debugging.
impure subroutine output_arrays_save_csv(file_name, is_gui_dialog, is_write_error)
Save the model output arrays to a CSV data file.
character(len=:) function, allocatable model_output_stats_row_csv(show_header)
Produce a text string containing general model output statistics.
pure character(len=:) function, allocatable model_output_stats_txt()
Produce a text string containing general model output statistics.
impure subroutine output_arrays_save_rate_data_csv(file_name, is_gui_dialog, is_write_error)
Save the rate data arrays to a CSV data file.
This module defines the fish and its components. The model is discrete, time is based on time steps,...
impure type(stomach_emptying_pattern) function get_stomach_emptying_matrix_csv(csv_file)
Get the stomach emptying time base matrix from a CSV input data file.