MOM6
MOM_get_input.F90
Go to the documentation of this file.
2 !***********************************************************************
3 !* GNU General Public License *
4 !* This file is a part of MOM. *
5 !* *
6 !* MOM is free software; you can redistribute it and/or modify it and *
7 !* are expected to follow the terms of the GNU General Public License *
8 !* as published by the Free Software Foundation; either version 2 of *
9 !* the License, or (at your option) any later version. *
10 !* *
11 !* MOM is distributed in the hope that it will be useful, but WITHOUT *
12 !* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
13 !* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public *
14 !* License for more details. *
15 !* *
16 !* For the full text of the GNU General Public License, *
17 !* write to: Free Software Foundation, Inc., *
18 !* 675 Mass Ave, Cambridge, MA 02139, USA. *
19 !* or see: http://www.gnu.org/licenses/gpl.html *
20 !***********************************************************************
21 
22 !********+*********+*********+*********+*********+*********+*********+**
23 !* *
24 !* By Robert Hallberg, April 2013 *
25 !* *
26 !* The subroutine in this file reads the MOM6 namelist input, which *
27 !* indicates which directories to use for certain types of input and *
28 !* output, and where to look for the full parsable input file(s). *
29 !* *
30 !********+*********+*********+*********+*********+*********+*********+**
31 
32 use mom_error_handler, only : mom_mesg, mom_error, fatal, warning, is_root_pe
34 use mom_io, only : file_exists, close_file, slasher, ensembler
35 use mom_io, only : open_namelist_file, check_nml_error
36 
37 implicit none ; private
38 
39 public get_mom_input
40 
41 ! This structure is to simplify communication with the calling code.
42 
43 type, public :: directories
44  character(len=240) :: &
45  restart_input_dir = ' ',& ! The directory to read restart and input files.
46  restart_output_dir = ' ',&! The directory into which to write restart files.
47  output_directory = ' ', & ! The directory to use to write the model output.
48  input_filename = ' ' ! A string that indicates the input files or how
49  ! the run segment should be started.
50 end type directories
51 
52 contains
53 
54 subroutine get_mom_input(param_file, dirs, check_params)
55  type(param_file_type), optional, intent(out) :: param_file !< A structure to parse for run-time parameters
56  type(directories), optional, intent(out) :: dirs
57  logical, optional, intent(in) :: check_params
58 
59 ! See if the run is to be started from saved conditions, and get !
60 ! the names of the I/O directories and initialization file. This !
61 ! subroutine also calls the subroutine that allows run-time changes !
62 ! in parameters. !
63  integer, parameter :: npf = 5 ! Maximum number of parameter files
64  character(len=240) :: &
65  parameter_filename(npf) = ' ', & ! List of files containing parameters.
66  output_directory = ' ', & ! Directory to use to write the model output.
67  restart_input_dir = ' ', & ! Directory for reading restart and input files.
68  restart_output_dir = ' ', & ! Directory into which to write restart files.
69  input_filename = ' ' ! A string that indicates the input files or how
70  ! the run segment should be started.
71  character(len=240) :: output_dir
72  integer :: unit, io, ierr, valid_param_files
73 
74  namelist /mom_input_nml/ output_directory, input_filename, parameter_filename, &
75  restart_input_dir, restart_output_dir
76 
77  if (file_exists('input.nml')) then
78  unit = open_namelist_file(file='input.nml')
79  else
80  call mom_error(fatal,'Required namelist file input.nml does not exist.')
81  endif
82 
83  ierr=1 ; do while (ierr /= 0)
84  read(unit, nml=mom_input_nml, iostat=io, end=10)
85  ierr = check_nml_error(io, 'MOM_input_nml')
86  enddo
87 10 call close_file(unit)
88 
89  if (present(dirs)) then
90  dirs%output_directory = slasher(ensembler(output_directory))
91  dirs%restart_output_dir = slasher(ensembler(restart_output_dir))
92  dirs%restart_input_dir = slasher(ensembler(restart_input_dir))
93  dirs%input_filename = ensembler(input_filename)
94  endif
95 
96  if (present(param_file)) then
97  output_dir = slasher(ensembler(output_directory))
98  valid_param_files = 0
99  do io = 1, npf
100  if (len_trim(trim(parameter_filename(io))) > 0) then
101  call open_param_file(ensembler(parameter_filename(io)), param_file, &
102  check_params, doc_file_dir=output_dir)
103  valid_param_files = valid_param_files + 1
104  endif
105  enddo
106  if (valid_param_files == 0) call mom_error(fatal, "There must be at "//&
107  "least 1 valid entry in input_filename in MOM_input_nml in input.nml.")
108  endif
109 
110 end subroutine get_mom_input
111 
112 end module mom_get_input
character(len=len(name)) function, public ensembler(name, ens_no_in)
Returns a name with "%#E" or "%E" replaced with the ensemble member number.
Definition: MOM_io.F90:724
subroutine, public get_mom_input(param_file, dirs, check_params)
subroutine, public open_param_file(filename, CS, checkable, component, doc_file_dir)
This module contains I/O framework code.
Definition: MOM_io.F90:2
logical function, public is_root_pe()
subroutine, public mom_mesg(message, verb, all_print)
subroutine, public mom_error(level, message, all_print)