Skip to content

Commit

Permalink
Clean up variable P:C and N:C logic
Browse files Browse the repository at this point in the history
Some settings in marbl_settings_mod.F90 only need to be defined if
lvariable_PtoC (or NtoC) is true. Also, found a couple block in
marbl_init_tracer_metadata_mod.F90 that wasn't verifying N_ind > 0 before
modifying N tracers (N_ind = 0 if lvariable_NtoC = .false.)
  • Loading branch information
mnlevy1981 committed May 25, 2024
1 parent d3a3cdb commit 46a90f6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 53 deletions.
6 changes: 6 additions & 0 deletions defaults/json/settings_latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
"((autotroph_sname)) == \"sp\"": 0.17,
"default": "1e34"
},
"dependencies": "lvariable_NtoC",
"longname": "Initial N/C ratio for growth",
"subcategory": "10. autotrophs",
"units": "unitless"
Expand All @@ -240,6 +241,7 @@
"((autotroph_sname)) == \"sp\"": 0.11,
"default": "1e34"
},
"dependencies": "lvariable_NtoC",
"longname": "Minimum N/C ratio for growth",
"subcategory": "10. autotrophs",
"units": "unitless"
Expand All @@ -252,6 +254,7 @@
"((autotroph_sname)) == \"sp\"": 0.011,
"default": "1e34"
},
"dependencies": "lvariable_PtoC",
"longname": "Initial P/C ratio for growth",
"subcategory": "10. autotrophs",
"units": "unitless"
Expand All @@ -264,6 +267,7 @@
"((autotroph_sname)) == \"sp\"": 0.0075,
"default": "1e34"
},
"dependencies": "lvariable_PtoC",
"longname": "Minimum P/C ratio for growth",
"subcategory": "10. autotrophs",
"units": "unitless"
Expand Down Expand Up @@ -1300,6 +1304,7 @@
"units": "unitless"
},
"lvariable_NtoC": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"dependencies": "base_bio_on",
Expand All @@ -1308,6 +1313,7 @@
"units": "unitless"
},
"lvariable_PtoC": {
"_append_to_config_keywords": true,
"datatype": "logical",
"default_value": ".true.",
"dependencies": "base_bio_on",
Expand Down
6 changes: 6 additions & 0 deletions defaults/settings_latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,15 @@ general_parms :
units : unitless
datatype : logical
default_value : .true.
_append_to_config_keywords : true
lvariable_NtoC :
dependencies : base_bio_on
longname : Control if NtoC ratios in autotrophs vary
subcategory : 3. config flags
units : unitless
datatype : logical
default_value : .true.
_append_to_config_keywords : true
ladjust_bury_coeff :
dependencies : base_bio_on
longname : Control if bury coefficients are adjusted (rather than constant)
Expand Down Expand Up @@ -1048,6 +1050,7 @@ PFT_derived_types :
((autotroph_sname)) == "diat" : 1.8e-3
((autotroph_sname)) == "diaz" : 2.0e-3
gQp_max :
dependencies : lvariable_PtoC
longname : Initial P/C ratio for growth
subcategory : 10. autotrophs
units : unitless
Expand All @@ -1058,6 +1061,7 @@ PFT_derived_types :
((autotroph_sname)) == "diat" : 1.1e-2
((autotroph_sname)) == "diaz" : 8.3e-3
gQp_min :
dependencies : lvariable_PtoC
longname : Minimum P/C ratio for growth
subcategory : 10. autotrophs
units : unitless
Expand All @@ -1078,6 +1082,7 @@ PFT_derived_types :
((autotroph_sname)) == "diat" : 0.8
((autotroph_sname)) == "diaz" : 0.8
gQn_max :
dependencies : lvariable_NtoC
longname : Initial N/C ratio for growth
subcategory : 10. autotrophs
units : unitless
Expand All @@ -1088,6 +1093,7 @@ PFT_derived_types :
((autotroph_sname)) == "diat" : 1.7e-1
((autotroph_sname)) == "diaz" : 1.7e-1
gQn_min :
dependencies : lvariable_NtoC
longname : Minimum N/C ratio for growth
subcategory : 10. autotrophs
units : unitless
Expand Down
22 changes: 13 additions & 9 deletions src/marbl_init_tracer_metadata_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ subroutine marbl_init_tracer_metadata(unit_system, marbl_tracer_indices, marbl_t
marbl_tracer_metadata(n)%tracer_module_name = 'base_bio'

n = marbl_tracer_indices%auto_inds(auto_ind)%N_ind
marbl_tracer_metadata(n)%lfull_depth_tavg = lecovars_full_depth_tavg
marbl_tracer_metadata(n)%tracer_module_name = 'base_bio'
if (n > 0) then
marbl_tracer_metadata(n)%lfull_depth_tavg = lecovars_full_depth_tavg
marbl_tracer_metadata(n)%tracer_module_name = 'base_bio'
endif

n = marbl_tracer_indices%auto_inds(auto_ind)%P_ind
if (n > 0) then
marbl_tracer_metadata(n)%lfull_depth_tavg = lecovars_full_depth_tavg
marbl_tracer_metadata(n)%tracer_module_name = 'base_bio'
endif
endif

n = marbl_tracer_indices%auto_inds(auto_ind)%Fe_ind
marbl_tracer_metadata(n)%lfull_depth_tavg = lecovars_full_depth_tavg
Expand Down Expand Up @@ -263,11 +265,13 @@ subroutine init_autotroph_tracer_metadata(marbl_tracer_metadata, &
marbl_tracer_metadata(n)%flux_units = unit_system%conc_flux_units

n = marbl_tracer_indices%auto_inds(auto_ind)%N_ind
marbl_tracer_metadata(n)%short_name = trim(autotroph_settings(auto_ind)%sname) // 'N'
marbl_tracer_metadata(n)%long_name = trim(autotroph_settings(auto_ind)%lname) // ' Nitrogen'
marbl_tracer_metadata(n)%units = unit_system%conc_units
marbl_tracer_metadata(n)%tend_units = unit_system%conc_tend_units
marbl_tracer_metadata(n)%flux_units = unit_system%conc_flux_units
if (n.gt.0) then
marbl_tracer_metadata(n)%short_name = trim(autotroph_settings(auto_ind)%sname) // 'N'
marbl_tracer_metadata(n)%long_name = trim(autotroph_settings(auto_ind)%lname) // ' Nitrogen'
marbl_tracer_metadata(n)%units = unit_system%conc_units
marbl_tracer_metadata(n)%tend_units = unit_system%conc_tend_units
marbl_tracer_metadata(n)%flux_units = unit_system%conc_flux_units
endif

n = marbl_tracer_indices%auto_inds(auto_ind)%P_ind
if (n.gt.0) then
Expand Down Expand Up @@ -344,4 +348,4 @@ end subroutine init_autotroph_tracer_metadata

!***********************************************************************

end module marbl_init_tracer_metadata_mod
end module marbl_init_tracer_metadata_mod
96 changes: 52 additions & 44 deletions src/marbl_settings_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1548,26 +1548,6 @@ subroutine marbl_settings_define_PFT_derived_types(this, marbl_status_log)
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'Qp_fixed'
lname = 'P/C ratio when using fixed P/C ratios'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%Qp_fixed
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'Qn_fixed'
lname = 'P/C ratio when using fixed N/C ratios'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%Qn_fixed
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'SiOpt'
lname = 'Si threshold in uptake ratio computations'
units = 'nM'
Expand Down Expand Up @@ -1608,21 +1588,35 @@ subroutine marbl_settings_define_PFT_derived_types(this, marbl_status_log)
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'gQp_max'
lname = 'initial P/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQp_max
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)
if (lvariable_PtoC) then
write(sname, "(2A)") trim(prefix), 'gQp_max'
lname = 'initial P/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQp_max
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'gQp_min'
lname = 'minimum P/C ratio for growth'
write(sname, "(2A)") trim(prefix), 'gQp_min'
lname = 'minimum P/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQp_min
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)
endif

! This is only used when lvariable_PtoC = .false., but settings_file_class always includes it
! in the setting file because it doesn't (yet) have logic to check for false logical vars
write(sname, "(2A)") trim(prefix), 'Qp_fixed'
lname = 'P/C ratio when using fixed P/C ratios'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQp_min
rptr => autotroph_settings(n)%Qp_fixed
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
Expand All @@ -1638,21 +1632,35 @@ subroutine marbl_settings_define_PFT_derived_types(this, marbl_status_log)
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'gQn_max'
lname = 'initial N/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQn_max
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)
if (lvariable_NtoC) then
write(sname, "(2A)") trim(prefix), 'gQn_max'
lname = 'initial N/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQn_max
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)

write(sname, "(2A)") trim(prefix), 'gQn_min'
lname = 'minimum N/C ratio for growth'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQn_min
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
call check_and_log_add_var_error(marbl_status_log, sname, subname, labort_marbl_loc)
endif

write(sname, "(2A)") trim(prefix), 'gQn_min'
lname = 'minimum N/C ratio for growth'
! This is only used when lvariable_NtoC = .false., but settings_file_class always includes it
! in the setting file because it doesn't (yet) have logic to check for false logical vars
write(sname, "(2A)") trim(prefix), 'Qn_fixed'
lname = 'P/C ratio when using fixed N/C ratios'
units = 'unitless'
datatype = 'real'
rptr => autotroph_settings(n)%gQn_min
rptr => autotroph_settings(n)%Qn_fixed
call this%add_var(sname, lname, units, datatype, category, &
marbl_status_log, rptr=rptr, &
nondefault_required=(PFT_defaults .eq. 'user-specified'))
Expand Down

0 comments on commit 46a90f6

Please sign in to comment.