5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_mhm_cli.f90
Go to the documentation of this file.
1!> \file mo_mhm_cli.f90
2!> \brief \copybrief mo_mhm_cli
3!> \details \copydetails mo_mhm_cli
4
5!> \brief Module to parse command line arguments of mHM.
6!> \version 0.1
7!> \authors Sebastian Mueller
8!> \date Oct 2021
9!> \details A simple parser for command line arguments for mHM.
10!! You can pass the path to mhm.nml, mhm_parameters.nml, mhm_outputs.nml and mrm_outputs.nml
11!!
12!! You can also pass the CWD as plain last argument and get a help or version text.
13!!
14!! \code{.sh}
15!! The mesoscale hydrological model - mHM
16!!
17!! Usage: mhm [options] <cwd>
18!!
19!! Options:
20!! <cwd>
21!! Description: The desired working directory (optional).
22!!
23!! --help / -h
24!! Description: Print this help message.
25!!
26!! --version / -V
27!! Description: Print the version of the program.
28!!
29!! --nml / -n <path>
30!! Description: The mHM configuration namelist.
31!! Default: mhm.nml
32!!
33!! --parameter / -p <path>
34!! Description: The mHM parameter namelist.
35!! Default: mhm_parameter.nml
36!!
37!! --mhm_output / -o <path>
38!! Description: The mHM output namelist.
39!! Default: mhm_output.nml
40!!
41!! --mrm_output / -r <path>
42!! Description: The mRM output namelist.
43!! Default: mrm_output.nml
44!!
45!! --quiet / -q
46!! Description: Decrease verbosity level.
47!! Can be repeated.
48!! \endcode
49!!
50!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
51!! mHM is released under the LGPLv3+ license \license_note
52!> \ingroup f_mhm
54
55 use mo_kind, only: i4
56
57 implicit none
58
59 private
60
61 public :: parse_command_line
62 public :: set_verbosity_level
63
64contains
65
66 !> \brief parse the given command line arguments.
67 subroutine parse_command_line()
68 use mo_cli, only: cli_parser
70 use mo_mrm_file, only: mrm_file_defoutput => file_defoutput
71 use mo_os, only: change_dir
72
73 implicit none
74
75 type(cli_parser) :: parser
76
77 parser = cli_parser( &
78 description="The mesoscale hydrological model - mHM", &
79 add_version_option=.true., &
81
82 call parser%add_option( &
83 name="cwd", &
84 blank=.true., &
85 help="The desired working directory (optional).")
86
87 call parser%add_option( &
88 name="nml", &
89 s_name="n", &
90 has_value=.true., &
91 value_name="path", &
92 default="mhm.nml", &
93 help="The mHM configuration namelist.")
94
95 call parser%add_option( &
96 name="parameter", &
97 s_name="p", &
98 has_value=.true., &
99 value_name="path", &
100 default="mhm_parameter.nml", &
101 help="The mHM parameter namelist.")
102
103 call parser%add_option( &
104 name="mhm_output", &
105 s_name="o", &
106 has_value=.true., &
107 value_name="path", &
108 default="mhm_outputs.nml", &
109 help="The mHM output namelist.")
110
111 call parser%add_option( &
112 name="mrm_output", &
113 s_name="r", &
114 has_value=.true., &
115 value_name="path", &
116 default="mrm_outputs.nml", &
117 help="The mRM output namelist.")
118
119 call parser%add_option( &
120 name="quiet", &
121 s_name="q", &
122 repeated=.true., &
123 help="Decrease verbosity level.")
124
125 ! parse given command line arguments
126 call parser%parse()
127
128 ! set nml file paths
129 file_namelist_mhm = parser%option_value("nml")
130 file_namelist_mhm_param = parser%option_value("parameter")
131 file_defoutput = parser%option_value("mhm_output")
132 mrm_file_defoutput = parser%option_value("mrm_output")
133 call set_verbosity_level(2_i4 - parser%option_read_count("quiet"))
134 ! change working directory first
135 if (parser%option_was_read("cwd")) call change_dir(parser%option_value("cwd"))
136
137 end subroutine parse_command_line
138
139 !> \brief Set the verbosity level of mHM.
140 subroutine set_verbosity_level(level)
141 use mo_message, only: show_msg, show_err
142 implicit none
143 integer(i4), intent(in), optional :: level !< verbosity level (0: no output, 1: errors, 2: all)
144 integer(i4) :: level_
145 show_msg = .false.
146 show_err = .false.
147 level_ = 2_i4
148 if ( present(level) ) level_ = level
149 if ( level_ > 0 ) show_err = .true.
150 if ( level_ > 1 ) show_msg = .true.
151 end subroutine set_verbosity_level
152
153end module mo_mhm_cli
Provides file names and units for mHM.
Definition mo_file.F90:29
character(:), allocatable file_namelist_mhm_param
Parameter namelists file name.
Definition mo_file.F90:46
character(:), allocatable file_namelist_mhm
Namelist file name.
Definition mo_file.F90:42
character(len=*), parameter version
Current mHM model version (will be set to )
Definition mo_file.F90:33
character(:), allocatable file_defoutput
file defining mHM's outputs
Definition mo_file.F90:50
Module to parse command line arguments of mHM.
subroutine, public set_verbosity_level(level)
Set the verbosity level of mHM.
subroutine, public parse_command_line()
parse the given command line arguments.
Provides file names and units for mRM.