← back to index

src/framework/MOM_get_input.F90

portedportable, not yet portedexecuted, not portableexecutable, not hit by this run

1! This file is part of MOM6, the Modular Ocean Model version 6.
2! See the LICENSE file for licensing information.
3! SPDX-License-Identifier: Apache-2.0
4
5!> \brief Reads the only Fortran name list needed to boot-strap the model.
6!!
7!! The name list parameters indicate which directories to use for
8!! certain types of input and output, and which files to look in for
9!! the full parsable input parameter file(s).
10module MOM_get_input
11
12use MOM_error_handler, only : MOM_mesg, MOM_error, FATAL, WARNING, is_root_pe
13use MOM_file_parser, only : open_param_file, param_file_type
14use MOM_io, only : file_exists, close_file, slasher, ensembler
15use MOM_io, only : open_namelist_file, check_nml_error
16use posix, only : mkdir, stat, stat_buf
17
18implicit none ; private
19
20public get_MOM_input
21
22!> Container for paths and parameter file names.
23type, public :: directories
24 character(len=240) :: &
25 restart_input_dir = ' ',& !< The directory to read restart and input files.
26 restart_output_dir = ' ',&!< The directory into which to write restart files.
27 output_directory = ' ' !< The directory to use to write the model output.
28 character(len=2048) :: &
29 input_filename = ' ' !< A string that indicates the input files or how
30 !! the run segment should be started.
31end type directories
32
33contains
34
35!> Get the names of the I/O directories and initialization file.
36!! Also calls the subroutine that opens run-time parameter files.
3713subroutine get_MOM_input(param_file, dirs, check_params, default_input_filename, ensemble_num)
38 type(param_file_type), optional, intent(out) :: param_file !< A structure to parse for run-time parameters.
39 type(directories), optional, intent(out) :: dirs !< Container for paths and parameter file names.
40 logical, optional, intent(in) :: check_params !< If present and False will stop error checking for
41 !! run-time parameters.
42 character(len=*), optional, intent(in) :: default_input_filename !< If present, is the value assumed for
43 !! input_filename if input_filename is not listed
44 !! in the namelist MOM_input_nml.
45 integer, optional, intent(in) :: ensemble_num !< The ensemble id of the current member
46 ! Local variables
47 integer, parameter :: npf = 5 ! Maximum number of parameter files
48
49 character(len=240) :: &
50 parameter_filename(npf), & ! List of files containing parameters.
51 output_directory, & ! Directory to use to write the model output.
52 restart_input_dir, & ! Directory for reading restart and input files.
53 restart_output_dir ! Directory into which to write restart files.
54 character(len=2048) :: &
55 input_filename ! A string that indicates the input files or how
56 ! the run segment should be started.
57 character(len=240) :: output_dir
58 integer :: unit, io, ierr, valid_param_files
59
60 type(stat_buf) :: buf
61
62 namelist /MOM_input_nml/ output_directory, input_filename, parameter_filename, &
63 restart_input_dir, restart_output_dir
64
65 ! Default values in case parameter is not set in file input.nml
6612 parameter_filename(:) = ' '
672 output_directory = ' '
682 restart_input_dir = ' '
692 restart_output_dir = ' '
702 input_filename = ' '
712 if (present(default_input_filename)) input_filename = trim(default_input_filename)
72
73 ! Open namelist
742 if (file_exists('input.nml')) then
752 unit = open_namelist_file(file='input.nml')
76 else
770 call MOM_error(FATAL,'Required namelist file input.nml does not exist.')
78 endif
79
80 ! Read namelist parameters
81 ! NOTE: Every rank is reading MOM_input_nml
824 ierr=1 ; do while (ierr /= 0)
832 read(unit, nml=MOM_input_nml, iostat=io, end=10)
842 ierr = check_nml_error(io, 'MOM_input_nml')
85 enddo
86210 call close_file(unit)
87
88 ! Store parameters in container
892 if (present(dirs)) then
902 if (present(ensemble_num)) then
910 dirs%output_directory = slasher(ensembler(output_directory,ensemble_num))
920 dirs%restart_output_dir = slasher(ensembler(restart_output_dir,ensemble_num))
930 dirs%restart_input_dir = slasher(ensembler(restart_input_dir,ensemble_num))
940 dirs%input_filename = ensembler(input_filename,ensemble_num)
95 else
962 dirs%output_directory = slasher(ensembler(output_directory))
972 dirs%restart_output_dir = slasher(ensembler(restart_output_dir))
982 dirs%restart_input_dir = slasher(ensembler(restart_input_dir))
992 dirs%input_filename = ensembler(input_filename)
100 endif
101
102 ! Create the RESTART directory if absent
1032 if (is_root_PE()) then
1042 if (stat(trim(dirs%restart_output_dir), buf) == -1) then
1051 ierr = mkdir(trim(dirs%restart_output_dir), int(o'700'))
1061 if (ierr == -1) &
1070 call MOM_error(FATAL, 'Restart directory could not be created.')
108 endif
109 endif
110 endif
111
112 ! Open run-time parameter file(s)
1132 if (present(param_file)) then
1141 output_dir = slasher(ensembler(output_directory))
1151 valid_param_files = 0
1166 do io = 1, npf
1176 if (len_trim(trim(parameter_filename(io))) > 0) then
1182 if (present(ensemble_num)) then
119 call open_param_file(ensembler(parameter_filename(io),ensemble_num), param_file, &
1200 check_params, doc_file_dir=output_dir, ensemble_num=ensemble_num)
121 else
122 call open_param_file(ensembler(parameter_filename(io)), param_file, &
1232 check_params, doc_file_dir=output_dir)
124 endif
1252 valid_param_files = valid_param_files + 1
126 endif
127 enddo
1281 if (valid_param_files == 0) call MOM_error(FATAL, "There must be at "//&
1290 "least 1 valid entry in input_filename in MOM_input_nml in input.nml.")
130 endif
131
1322end subroutine get_MOM_input
133
1340end module MOM_get_input