MOM6
mom_get_input Module Reference

Detailed Description

Reads the only Fortran name list needed to boot-strap the model.

The name list parameters indicate which directories to use for certain types of input and output, and which files to look in for the full parsable input parameter file(s).

Data Types

type  directories
 Container for paths and parameter file names. More...
 

Functions/Subroutines

subroutine, public get_mom_input (param_file, dirs, check_params, default_input_filename, ensemble_num)
 Get the names of the I/O directories and initialization file. Also calls the subroutine that opens run-time parameter files. More...
 

Function/Subroutine Documentation

◆ get_mom_input()

subroutine, public mom_get_input::get_mom_input ( type(param_file_type), intent(out), optional  param_file,
type(directories), intent(out), optional  dirs,
logical, intent(in), optional  check_params,
character(len=*), intent(in), optional  default_input_filename,
integer, intent(in), optional  ensemble_num 
)

Get the names of the I/O directories and initialization file. Also calls the subroutine that opens run-time parameter files.

Parameters
[out]param_fileA structure to parse for run-time parameters.
[out]dirsContainer for paths and parameter file names.
[in]check_paramsIf present and False will stop error checking for run-time parameters.
[in]default_input_filenameIf present, is the value assumed for input_filename if input_filename is not listed in the namelist MOM_input_nml.
[in]ensemble_numThe ensemble id of the current member

Definition at line 34 of file MOM_get_input.F90.

34  type(param_file_type), optional, intent(out) :: param_file !< A structure to parse for run-time parameters.
35  type(directories), optional, intent(out) :: dirs !< Container for paths and parameter file names.
36  logical, optional, intent(in) :: check_params !< If present and False will stop error checking for
37  !! run-time parameters.
38  character(len=*), optional, intent(in) :: default_input_filename !< If present, is the value assumed for
39  !! input_filename if input_filename is not listed
40  !! in the namelist MOM_input_nml.
41  integer, optional, intent(in) :: ensemble_num !< The ensemble id of the current member
42  ! Local variables
43  integer, parameter :: npf = 5 ! Maximum number of parameter files
44  character(len=240) :: &
45  parameter_filename(npf), & ! List of files containing parameters.
46  output_directory, & ! Directory to use to write the model output.
47  restart_input_dir, & ! Directory for reading restart and input files.
48  restart_output_dir, & ! Directory into which to write restart files.
49  input_filename ! A string that indicates the input files or how
50  ! the run segment should be started.
51  character(len=240) :: output_dir
52  integer :: unit, io, ierr, valid_param_files
53 
54  namelist /mom_input_nml/ output_directory, input_filename, parameter_filename, &
55  restart_input_dir, restart_output_dir
56 
57  ! Default values in case parameter is not set in file input.nml
58  parameter_filename(:) = ' '
59  output_directory = ' '
60  restart_input_dir = ' '
61  restart_output_dir = ' '
62  input_filename = ' '
63  if (present(default_input_filename)) input_filename = trim(default_input_filename)
64 
65  ! Open namelist
66  if (file_exists('input.nml')) then
67  unit = open_namelist_file(file='input.nml')
68  else
69  call mom_error(fatal,'Required namelist file input.nml does not exist.')
70  endif
71 
72  ! Read namelist parameters
73  ierr=1 ; do while (ierr /= 0)
74  read(unit, nml=mom_input_nml, iostat=io, end=10)
75  ierr = check_nml_error(io, 'MOM_input_nml')
76  enddo
77 10 call close_file(unit)
78 
79  ! Store parameters in container
80  if (present(dirs)) then
81  if (present(ensemble_num)) then
82  dirs%output_directory = slasher(ensembler(output_directory,ensemble_num))
83  dirs%restart_output_dir = slasher(ensembler(restart_output_dir,ensemble_num))
84  dirs%restart_input_dir = slasher(ensembler(restart_input_dir,ensemble_num))
85  dirs%input_filename = ensembler(input_filename,ensemble_num)
86  else
87  dirs%output_directory = slasher(ensembler(output_directory))
88  dirs%restart_output_dir = slasher(ensembler(restart_output_dir))
89  dirs%restart_input_dir = slasher(ensembler(restart_input_dir))
90  dirs%input_filename = ensembler(input_filename)
91  endif
92  endif
93 
94  ! Open run-time parameter file(s)
95  if (present(param_file)) then
96  output_dir = slasher(ensembler(output_directory))
97  valid_param_files = 0
98  do io = 1, npf
99  if (len_trim(trim(parameter_filename(io))) > 0) then
100  if (present(ensemble_num)) then
101  call open_param_file(ensembler(parameter_filename(io),ensemble_num), param_file, &
102  check_params, doc_file_dir=output_dir)
103  else
104  call open_param_file(ensembler(parameter_filename(io)), param_file, &
105  check_params, doc_file_dir=output_dir)
106  endif
107  valid_param_files = valid_param_files + 1
108  endif
109  enddo
110  if (valid_param_files == 0) call mom_error(fatal, "There must be at "//&
111  "least 1 valid entry in input_filename in MOM_input_nml in input.nml.")
112  endif
113