Skip to content

Commit

Permalink
Add support for a COBALT_param_doc file (#59)
Browse files Browse the repository at this point in the history
* Add cobalt_param_doc.F90

Using the file parser from MOM6, add the option to read parameters
from COBALT_input and COBALT_override files and write pramerters to
COBALT_param_doc files. The COBALT_input files must be specific in
the input.nml

* Replace most calls to g_tracer_add_param

Add a call to read the name and loaction of the COBALT param files
from the namelist to generic_COBALT

Replace calls to g_tracer_add_param with get_param but do not change deaults.
The descriptions are just the parameter name, and the units are included where
they were documenemted in the code.

* Add support for a COBALT_param_doc file

Using the file parser from MOM6, add the option to read parameters
from COBALT_input and COBALT_override files and write pramerters to
COBALT_param_doc files. The COBALT_input files must be specific in
the input.nml

* Replace most calls to g_tracer_add_param

Replace calls to g_tracer_add_param with get_param but do not change deaults.
The descriptions are just the parameter name, and the units are included where
they were documenemted in the code.

* Fix typo

Fix error in line continue statement.

* Add missing description

Add description for RHO_0 and NKML

* Cange parameters with sperd or spery

Remove unit changes from per-day or per-year to per-second from
the default values to do that calculation outside the get param
call. This should not change the solution.

* Use scale argument in get_param

Where default values were rescaled by time (sperd or spery), nutrients
(carbon to nitrogen), concentration (micromoles to moles) or light, the
optional argument scale is now set in get_param so that the values in
the parameter doc files are consistent with the literature.

---------

Co-authored-by: Theresa Morrison <[email protected]>
Co-authored-by: Theresa Morrison <[email protected]>
Co-authored-by: Theresa Morrison <[email protected]>
  • Loading branch information
4 people authored May 29, 2024
1 parent e62cd4c commit dbb5c88
Show file tree
Hide file tree
Showing 3 changed files with 548 additions and 362 deletions.
86 changes: 86 additions & 0 deletions generic_tracers/cobalt_param_doc.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
! this module will contain a few main routines: one to get the
module cobalt_param_doc

use MOM_cpu_clock, only : cpu_clock_id, cpu_clock_begin, cpu_clock_end, CLOCK_COMPONENT
use MOM_data_override, only : data_override
use MOM_domains, only : domain2D, same_domain
use MOM_error_handler, only : MOM_error, FATAL, WARNING, callTree_enter, callTree_leave
use MOM_file_parser, only : param_file_type, open_param_file, close_param_file
use MOM_file_parser, only : read_param, get_param, log_param, log_version
use MOM_io, only : file_exists, close_file, slasher, ensembler
use MOM_io, only : open_namelist_file, check_nml_error
use MOM_time_manager, only : time_type, time_type_to_real, real_to_time_type
use MOM_time_manager, only : operator(+), operator(-), operator(>)
use posix, only : mkdir, stat, stat_buf

implicit none ; private

public get_COBALT_param_file

!> Container for paths and parameter file names.
!type, public :: directories
! character(len=240) :: &
! restart_input_dir = ' ',& !< The directory to read restart and input files.
! restart_output_dir = ' ',&!< The directory into which to write restart files.
! output_directory = ' ' !< The directory to use to write the model output.
! character(len=2048) :: &
! input_filename = ' ' !< A string that indicates the input files or how
! !! the run segment should be started.
!end type directories

contains
!! This subroutine is analagous to the get_mom_input routine within the MOM_get_input module. There are additional
!> arguments used in the MOM version which are commented out and not used here. These features may be needed as we
!> add more complexity to the parameter files in COBALT so I have commented them out rather than deleting them.
subroutine get_COBALT_param_file(param_file)
type(param_file_type), optional, intent(out) :: param_file !< A structure to parse for run-time parameters.
!type(directories), optional, intent(out) :: dirs !< Container for paths and parameter filenames.
!logical, optional, intent(in) :: check_params !< If present and False will stop error checking for
! !! run-time parameters.
!character(len=*), optional, intent(in) :: default_input_filename !< If present, is the value assumed for
! !! input_filename if input_filename is no listed
! !! in the namelist MOM_input_nml.
! Local variables
integer, parameter :: npf = 5 ! Maximum number of parameter files

character(len=240) :: &
output_directory = ' ', & ! Directory to use to write the model output.
parameter_filename(npf) = ' ' ! List of files containing parameters.

character(len=2048) :: &
input_filename ! A string that indicates the input files or how
! the run segment should be started.
character(len=240) :: output_dir
integer :: unit, io, ierr, valid_param_files

type(stat_buf) :: buf

namelist /cobalt_input_nml/ parameter_filename

! Open namelist
if (file_exists('input.nml')) then
unit = open_namelist_file(file='input.nml')
else
call MOM_error(FATAL,'Required namelist file input.nml does not exist.')
endif

! Read namelist parameters
ierr=1 ; do while (ierr /= 0)
read(unit, nml=cobalt_input_nml, iostat=io, end=10)
ierr = check_nml_error(io, 'cobalt_input_nml')
enddo
10 call close_file(unit)

output_dir = trim(slasher(ensembler(output_directory)))
valid_param_files = 0
do io=1,npf
if (len_trim(trim(parameter_filename(io))) > 0) then
call open_param_file(trim(parameter_filename(io)), param_file, &
component="COBALT", doc_file_dir=output_dir)
valid_param_files = valid_param_files + 1
endif
enddo

end subroutine get_COBALT_param_file

end module cobalt_param_doc
6 changes: 6 additions & 0 deletions generic_tracers/cobalt_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ module cobalt_types
integer, parameter, public :: SMALL = 4 !< ID for small phytoplankton

real, parameter, public :: sperd = 24.0 * 3600.0 !< number of seconds in a day (sec)
real, parameter, public :: I_sperd = 1.0/sperd !< inverse of number of seconds in a day (sec)
real, parameter, public :: spery = 365.25 * sperd !< number of seconds in a year (sec)
real, parameter, public :: I_spery = 1.0/spery !< inverse of number of seconds in a year (sec)
real, parameter, public :: epsln=1.0e-30 !< small, but non-zero value for numerical stability
real, parameter, public :: missing_value1=-1.0e+10 !< large negative value to represent missing value in diags
real, parameter, public :: vb_nh3 = 25. !< Liquid molar volume at boiling point for NH3 (cm3 mol−1)
real, parameter, public :: micromol2mol = 1.0e6 !< convert micromoles to moles (used in concentration parameters)
real, parameter, public :: c2n = 106.0/16.0 !< convert nutrient ratios relative to carbon to ratios relative to nitrogen
real, parameter, public :: micromolQpersec2W = 2.77e18/6.022e17 !< convert photosynthetically available radiation (micromole quanta
!! per-second) to watts.

!> An auxiliary type for storing varible names
type vardesc
Expand Down
Loading

0 comments on commit dbb5c88

Please sign in to comment.