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