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). | |
| 10 | module MOM_get_input | |
| 11 | ||
| 12 | use MOM_error_handler, only : MOM_mesg, MOM_error, FATAL, WARNING, is_root_pe | |
| 13 | use MOM_file_parser, only : open_param_file, param_file_type | |
| 14 | use MOM_io, only : file_exists, close_file, slasher, ensembler | |
| 15 | use MOM_io, only : open_namelist_file, check_nml_error | |
| 16 | use posix, only : mkdir, stat, stat_buf | |
| 17 | ||
| 18 | implicit none ; private | |
| 19 | ||
| 20 | public get_MOM_input | |
| 21 | ||
| 22 | !> Container for paths and parameter file names. | |
| 23 | type, 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. | |
| 31 | end type directories | |
| 32 | ||
| 33 | contains | |
| 34 | ||
| 35 | !> Get the names of the I/O directories and initialization file. | |
| 36 | !! Also calls the subroutine that opens run-time parameter files. | |
| 37 | 13 | subroutine 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 | |
| 66 | 12 | parameter_filename(:) = ' ' |
| 67 | 2 | output_directory = ' ' |
| 68 | 2 | restart_input_dir = ' ' |
| 69 | 2 | restart_output_dir = ' ' |
| 70 | 2 | input_filename = ' ' |
| 71 | 2 | if (present(default_input_filename)) input_filename = trim(default_input_filename) |
| 72 | ||
| 73 | ! Open namelist | |
| 74 | 2 | if (file_exists('input.nml')) then |
| 75 | 2 | unit = open_namelist_file(file='input.nml') |
| 76 | else | |
| 77 | 0 | 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 | |
| 82 | 4 | ierr=1 ; do while (ierr /= 0) |
| 83 | 2 | read(unit, nml=MOM_input_nml, iostat=io, end=10) |
| 84 | 2 | ierr = check_nml_error(io, 'MOM_input_nml') |
| 85 | enddo | |
| 86 | 2 | 10 call close_file(unit) |
| 87 | ||
| 88 | ! Store parameters in container | |
| 89 | 2 | if (present(dirs)) then |
| 90 | 2 | if (present(ensemble_num)) then |
| 91 | 0 | dirs%output_directory = slasher(ensembler(output_directory,ensemble_num)) |
| 92 | 0 | dirs%restart_output_dir = slasher(ensembler(restart_output_dir,ensemble_num)) |
| 93 | 0 | dirs%restart_input_dir = slasher(ensembler(restart_input_dir,ensemble_num)) |
| 94 | 0 | dirs%input_filename = ensembler(input_filename,ensemble_num) |
| 95 | else | |
| 96 | 2 | dirs%output_directory = slasher(ensembler(output_directory)) |
| 97 | 2 | dirs%restart_output_dir = slasher(ensembler(restart_output_dir)) |
| 98 | 2 | dirs%restart_input_dir = slasher(ensembler(restart_input_dir)) |
| 99 | 2 | dirs%input_filename = ensembler(input_filename) |
| 100 | endif | |
| 101 | ||
| 102 | ! Create the RESTART directory if absent | |
| 103 | 2 | if (is_root_PE()) then |
| 104 | 2 | if (stat(trim(dirs%restart_output_dir), buf) == -1) then |
| 105 | 1 | ierr = mkdir(trim(dirs%restart_output_dir), int(o'700')) |
| 106 | 1 | if (ierr == -1) & |
| 107 | 0 | call MOM_error(FATAL, 'Restart directory could not be created.') |
| 108 | endif | |
| 109 | endif | |
| 110 | endif | |
| 111 | ||
| 112 | ! Open run-time parameter file(s) | |
| 113 | 2 | if (present(param_file)) then |
| 114 | 1 | output_dir = slasher(ensembler(output_directory)) |
| 115 | 1 | valid_param_files = 0 |
| 116 | 6 | do io = 1, npf |
| 117 | 6 | if (len_trim(trim(parameter_filename(io))) > 0) then |
| 118 | 2 | if (present(ensemble_num)) then |
| 119 | call open_param_file(ensembler(parameter_filename(io),ensemble_num), param_file, & | |
| 120 | 0 | check_params, doc_file_dir=output_dir, ensemble_num=ensemble_num) |
| 121 | else | |
| 122 | call open_param_file(ensembler(parameter_filename(io)), param_file, & | |
| 123 | 2 | check_params, doc_file_dir=output_dir) |
| 124 | endif | |
| 125 | 2 | valid_param_files = valid_param_files + 1 |
| 126 | endif | |
| 127 | enddo | |
| 128 | 1 | if (valid_param_files == 0) call MOM_error(FATAL, "There must be at "//& |
| 129 | 0 | "least 1 valid entry in input_filename in MOM_input_nml in input.nml.") |
| 130 | endif | |
| 131 | ||
| 132 | 2 | end subroutine get_MOM_input |
| 133 | ||
| 134 | 0 | end module MOM_get_input |