MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
commandarguments Module Reference

Functions/Subroutines

subroutine, public getcommandlinearguments ()
 Get command line arguments. More...
 
subroutine write_usage (header, cexe)
 Write command line argument usage. More...
 

Function/Subroutine Documentation

◆ getcommandlinearguments()

subroutine, public commandarguments::getcommandlinearguments

Subroutine to get and write information on command line arguments.

Definition at line 28 of file comarg.f90.

29  ! -- dummy variables
30  ! -- local variables
31  character(len=LINELENGTH) :: tag
32  character(len=LINELENGTH) :: uctag
33  character(len=LENHUGELINE) :: line
34  character(len=LINELENGTH) :: clevel
35  character(len=LINELENGTH) :: cmode
36  character(len=LINELENGTH) :: header
37  character(len=LINELENGTH) :: errmsg
38  character(len=LINELENGTH) :: cexe
39  character(len=LENBIGLINE) :: compiler
40  character(len=20) :: cdate
41  character(len=LENBIGLINE) :: coptions
42  logical :: ltyp
43  logical :: lexist
44  logical :: lstop
45  integer(I4B) :: icountcmd
46  integer(I4B) :: ipos
47  integer(I4B) :: ilen
48  integer(I4B) :: iarg
49  !
50  ! -- initialize local variables
51  lstop = .false.
52  !
53  ! -- set mf6 executable name
54  icountcmd = command_argument_count()
55  call get_command_argument(0, cexe)
56  cexe = adjustl(cexe)
57  !
58  ! -- find the program basename, not including the path (this should be
59  ! mf6.exe, mf6d.exe, etc.)
60  ipos = index(cexe, '/', back=.true.)
61  if (ipos == 0) then
62  ipos = index(cexe, '\', back=.true.)
63  end if
64  if (ipos == 0) then
65  ipos = 1
66  else
67  ipos = ipos + 1
68  end if
69  cexe = cexe(ipos:)
70  !
71  ! -- write header
72  call get_compile_date(cdate)
73  write (header, '(a,4(1x,a),a)') &
74  trim(adjustl(cexe)), '- MODFLOW', &
75  trim(adjustl(version)), '(compiled', trim(adjustl(cdate)), ')'
76  !
77  ! -- check for silent option
78  do iarg = 1, icountcmd
79  call get_command_argument(iarg, uctag)
80  call upcase(uctag)
81  if (trim(adjustl(uctag)) == '-S' .or. &
82  trim(adjustl(uctag)) == '--SILENT') then
83  !
84  ! -- get file unit and open mfsim.stdout
85  istdout = getunit()
86  open (unit=istdout, file=trim(adjustl(simstdout)))
87  !
88  ! -- exit loop
89  exit
90  end if
91  end do
92  !
93  ! -- Read remaining arguments
94  iarg = 0
95  do
96  !
97  ! -- increment iarg and determine if loop should be terminated
98  iarg = iarg + 1
99  if (iarg > icountcmd) then
100  exit
101  end if
102  !
103  ! -- get command line argument
104  call get_command_argument(iarg, tag)
105  uctag = tag
106  call upcase(uctag)
107  !
108  ! -- skip commands without - or --
109  ipos = index(uctag, '-')
110  if (ipos < 1) then
111  cycle
112  end if
113  !
114  ! -- parse level string, if necessary
115  clevel = ' '
116  ipos = index(uctag, '--LEVEL=')
117  if (ipos > 0) then
118  ipos = index(tag, '=')
119  ilen = len_trim(tag)
120  clevel = tag(ipos + 1:ilen)
121  call upcase(clevel)
122  uctag = tag(1:ipos - 1)
123  call upcase(uctag)
124  end if
125  !
126  ! -- parse mode string, if necessary
127  cmode = ' '
128  ipos = index(uctag, '--MODE=')
129  if (ipos > 0) then
130  ipos = index(tag, '=')
131  ilen = len_trim(tag)
132  cmode = tag(ipos + 1:ilen)
133  call upcase(cmode)
134  uctag = tag(1:ipos - 1)
135  call upcase(uctag)
136  end if
137  !
138  ! -- evaluate the command line argument (uctag)
139  select case (trim(adjustl(uctag)))
140  case ('-H', '-?', '--HELP')
141  lstop = .true.
142  call write_usage(trim(adjustl(header)), trim(adjustl(cexe)))
143  case ('-V', '--VERSION')
144  lstop = .true.
145  write (line, '(2a,2(1x,a))') &
146  trim(adjustl(cexe)), ':', trim(adjustl(version))
147  call write_message_counter(line, skipbefore=1, skipafter=1)
148  case ('-DEV', '--DEVELOP')
149  lstop = .true.
150  write (line, '(2a,g0)') &
151  trim(adjustl(cexe)), ': develop version ', ltyp
152  call write_message_counter(line, skipbefore=1, skipafter=1)
153  case ('-C', '--COMPILER')
154  lstop = .true.
155  call get_compiler(compiler)
156  write (line, '(2a,1x,a)') &
157  trim(adjustl(cexe)), ':', trim(adjustl(compiler))
158  call write_message_counter(line, skipbefore=1, skipafter=1)
159  case ('-S', '--SILENT')
160  write (line, '(2a,1x,a)') &
161  trim(adjustl(cexe)), ':', 'all screen output sent to mfsim.stdout'
162  call write_message_counter(line, skipbefore=1, skipafter=1)
163  case ('-D', '--DISCLAIMER')
164  lstop = .true.
165  call write_message('', fmt=fmtdisclaimer)
166  case ('-P', '--PARALLEL')
167  simulation_mode = 'PARALLEL'
168  case ('-LIC', '--LICENSE')
169  lstop = .true.
170  call write_license()
171  case ('-CO', '--COMPILER-OPT')
172  lstop = .true.
173  call get_compile_options(coptions)
174  call write_message_counter(coptions, skipbefore=1, skipafter=1)
175  case ('-L', '--LEVEL')
176  if (len_trim(clevel) < 1) then
177  iarg = iarg + 1
178  call get_command_argument(iarg, clevel)
179  call upcase(clevel)
180  end if
181  select case (trim(adjustl(clevel)))
182  case ('SUMMARY')
183  isim_level = vsummary
184  case ('DEBUG')
185  isim_level = vdebug
186  case default
187  call write_usage(trim(adjustl(header)), trim(adjustl(cexe)))
188  write (errmsg, '(2a,1x,a)') &
189  trim(adjustl(cexe)), ': illegal STDOUT level option -', &
190  trim(adjustl(clevel))
191  call store_error(errmsg)
192  end select
193  !
194  ! -- write message to stdout
195  write (line, '(2a,2(1x,a))') &
196  trim(adjustl(cexe)), ':', 'stdout output level', &
197  trim(adjustl(clevel))
198  call write_message_counter(line, skipbefore=1, skipafter=1)
199  case ('-M', '--MODE')
200  if (len_trim(cmode) < 1) then
201  iarg = iarg + 1
202  call get_command_argument(iarg, cmode)
203  call upcase(cmode)
204  end if
205  select case (trim(adjustl(cmode)))
206  case ('VALIDATE')
207  isim_mode = mvalidate
208  case default
209  call write_usage(trim(adjustl(header)), trim(adjustl(cexe)))
210  errmsg = trim(adjustl(cexe))//': illegal MODFLOW 6 '// &
211  'simulation mode option - '//trim(adjustl(cmode))
212  call store_error(errmsg, terminate=.true.)
213  end select
214  !
215  ! -- write message to stdout
216  line = trim(adjustl(cexe))//': MODFLOW 6 simulation mode '// &
217  trim(adjustl(cmode))//'. Model input will be checked for all '// &
218  'stress periods but the matrix equations will not be '// &
219  'assembled or solved.'
220  call write_message_counter(line, skipbefore=1, skipafter=1)
221  case default
222  lstop = .true.
223  call write_usage(trim(adjustl(header)), trim(adjustl(cexe)))
224  write (errmsg, '(2a,1x,a)') &
225  trim(adjustl(cexe)), ': illegal option -', trim(adjustl(tag))
226  call store_error(errmsg, terminate=.true.)
227  end select
228  end do
229  !
230  ! -- check if simfile exists, only if the model should be run
231  if (.not. lstop) then
232  inquire (file=trim(adjustl(simfile)), exist=lexist)
233  if (.NOT. lexist) then
234  lstop = .true.
235  write (errmsg, '(2a,2(1x,a))') &
236  trim(adjustl(cexe)), ':', trim(adjustl(simfile)), &
237  'is not present in working directory.'
238  call store_error(errmsg, terminate=.true.)
239  end if
240  end if
241  !
242  ! -- terminate program if lstop
243  if (lstop) then
244  call ustop()
245  end if
246  !
247  ! -- write blank line to stdout
248  if (icountcmd > 0) then
249  call write_message('')
250  end if
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_usage()

subroutine commandarguments::write_usage ( character(len=*), intent(in)  header,
character(len=*), intent(in)  cexe 
)
private

Subroutine to write usage information for command line arguments.

Parameters
[in]headerheader for usage
[in]cexeexecutable name

Definition at line 258 of file comarg.f90.

259  ! -- dummy variables
260  character(len=*), intent(in) :: header !< header for usage
261  character(len=*), intent(in) :: cexe !< executable name
262  ! -- local variables
263  character(len=LINELENGTH) :: line
264  ! -- format
265  character(len=*), parameter :: OPTIONSFMT = &
266  "(/,&
267  &'Options GNU long option Meaning ',/,&
268  &' -h, -? --help Show this message',/,&
269  &' -v --version Display program version information.',/,&
270  &' -dev --develop Display program develop option mode.',/,&
271  &' -d --disclaimer Display program disclaimer.',/,&
272  &' -p --parallel Run program in parallel mode.',/,&
273  &' -lic --license Display program license information.',/,&
274  &' -c --compiler Display compiler information.',/,&
275  &' -co --compiler-opt Display compiler options.',/,&
276  &' -s --silent All STDOUT to mfsim.stdout.',/,"// &
277  "' -l <str> --level <str> STDOUT output to screen based on <str>.',/,&
278  &' <str>=summary Limited output to STDOUT.',/,&
279  &' <str>=debug Enhanced output to STDOUT.',/,&
280  &' -m <str> --mode <str> MODFLOW 6 simulation mode based on <str>.',/,&
281  &' <str>=validate Check model input for',/,&
282  &' errors but do not ',/,&
283  &' assemble or solve matrix ',/,&
284  &' equations or write ',/,&
285  &' solution output.',/,"// &
286  "' ',/,&
287  &'Bug reporting and contributions are welcome from the community. ',/,&
288  &'Questions can be asked on the issues page[1]. Before creating a new',/,&
289  &'issue, please take a moment to search and make sure a similar issue',/,&
290  &'does not already exist. If one does exist, you can comment (most',/,&
291  &'simply even with just :+1:) to show your support for that issue.',/,&
292  &' ',/,&
293  &'[1] https://github.com/MODFLOW-USGS/modflow6/issues',/)"
294  !
295  ! -- write command line usage information to the screen
296  call write_message(header)
297  write (line, '(a,1x,a,15x,a,2(1x,a),2a)') &
298  'usage:', cexe, 'run MODFLOW', trim(adjustl(mfvnam)), &
299  'using "', trim(adjustl(simfile)), '"'
300  call write_message(line)
301  write (line, '(a,1x,a,1x,a,5x,a)') &
302  ' or:', cexe, '[options]', &
303  'retrieve program information'
304  call write_message(line)
305  call write_message('', fmt=optionsfmt)
Here is the call graph for this function:
Here is the caller graph for this function: