29 character :: name*(99)
30 character :: value*(99)
48 integer,
intent(in) :: nArg
49 integer,
intent(out) :: arg
50 integer,
intent(out),
optional :: status
52 character :: str*(199)
54 call get_command_argument(narg, str)
55 read(str,*, iostat=lstatus) arg
57 if(
present(status)) status = lstatus
74 integer,
intent(in) :: nArg
75 integer(long),
intent(out) :: arg
76 integer,
intent(out),
optional :: status
78 character :: str*(199)
80 call get_command_argument(narg, str)
81 read(str,*, iostat=lstatus) arg
83 if(
present(status)) status = lstatus
100 integer,
intent(in) :: nArg
101 real(double),
intent(out) :: arg
102 integer,
intent(out),
optional :: status
104 character :: str*(199)
106 call get_command_argument(narg, str)
107 read(str,*, iostat=lstatus) arg
109 if(
present(status)) status = lstatus
124 integer,
intent(in) :: nArg
125 real,
intent(out) :: arg
126 integer,
intent(out),
optional :: status
128 character :: str*(199)
130 call get_command_argument(narg, str)
131 read(str,*, iostat=lstatus) arg
133 if(
present(status)) status = lstatus
150 integer,
intent(in) :: verbose, narg_max
151 integer,
intent(out) :: nargs
152 character,
intent(out) :: arguments(narg_max)*(*)
155 character :: arg*(len(arguments))
161 nargs = command_argument_count()
162 if(verbose.ge.1)
write(*,
'(/,A,I6)')
' Arguments found:',nargs
163 if(nargs.eq.0)
return
165 if(nargs.gt.narg_max)
then
166 write(0,
'(A,I6,A)')
' * WARNING: narg_max is too small; only the first',narg_max,
' arguments will be read!'
171 call get_command_argument(ia,arg)
172 arguments(ia) = trim(arg)
173 if(verbose.ge.3)
write(*,
'(A,I3,A)')
' argument',ia,
': '//trim(arg)
196 integer,
intent(in) :: verbose, nargs
197 integer,
intent(out) :: types(nargs)
198 character,
intent(in) :: arguments(nargs)*(*)
200 integer :: ia,il, typ, oldtyp, ltypes(0:nargs)
201 character :: arg*(len(arguments)), abc*(52)
202 logical :: has_letters
204 abc =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
208 arg = trim(arguments(ia))
210 has_letters = .false.
212 if(index(arg,abc(il:il)).ne.0)
then
219 if(index(arg,
'--',.false.).eq.1)
then
221 else if(index(arg,
'-',.false.).eq.1 .and. has_letters)
then
225 if(oldtyp.eq.20 .or. oldtyp.eq.30)
then
226 ltypes(ia-1) = oldtyp + 1
236 if(verbose.ge.3)
then
238 write(*,
'(A,I6,A15,3I6)')
'Types:',ia,trim(arguments(ia)),ltypes(ia),ltypes(ia)/10,mod(ltypes(ia),10)
242 types(1:nargs) = ltypes(1:nargs)
265 integer,
intent(in) :: verbose, narg_max
266 integer,
intent(out) :: nargs
267 character,
intent(inout) :: arguments(narg_max)*(*)
268 integer,
intent(inout) :: types(narg_max)
270 integer :: ia1,ia2, typ1, dn0, ib
271 character :: arg1*(len(arguments)), arg2*(len(arguments))
272 character :: new_args(narg_max)*(len(arguments))
273 integer :: new_types(narg_max)
274 logical :: found_duplicate
279 arg1 = trim(arguments(ia1))
281 if(typ1.eq.20.or.typ1.eq.21)
then
282 dn0 = dn0 + len_trim(arg1) - 2
284 if(verbose.ge.3) print*,
'Extra parameters: ', arg1, typ1, dn0
286 if(dn0+nargs.gt.narg_max)
call quit_program(
'Command-line argument arrays too small')
290 arg1 = trim(arguments(ia1))
293 if(typ1.eq.20.or.typ1.eq.21)
then
294 do ib=2,len_trim(arg1)
296 new_args(ia2) =
'-'//arg1(ib:ib)
297 new_types(ia2) = typ1
298 if(ib.ne.len_trim(arg1)) new_types(ia2) = 20
302 new_args(ia2) = arguments(ia1)
303 new_types(ia2) = typ1
316 do while(ia1.lt.nargs)
318 arg1 = trim(arguments(ia1))
321 if(typ1.eq.20.or.typ1.eq.21)
then
323 found_duplicate = .false.
325 arg2 = trim(arguments(ia2))
327 if(trim(arg1).eq.trim(arg2))
then
328 found_duplicate = .true.
329 if(verbose.ge.3)
write(*,
'(A)')
'Removing duplicate short option '//trim(arg1)
334 if(found_duplicate)
then
335 if(typ1.eq.21) ia1 = ia1 + 1
338 new_args(ib) = trim(arg1)
344 new_args(ib) = trim(arg1)
374 integer,
intent(in) :: verbose, narg_max
375 integer,
intent(out) :: nopts, optypes(narg_max)
376 character,
intent(out) :: options(narg_max)*(*),values(narg_max)*(*)
377 type(
cl_options),
intent(out) :: cl_option(narg_max)
379 character :: arg*( max(len(options),len(values)) ), arguments(narg_max)*( max(len(options),len(values)) )
380 integer :: ia, io, nargs, typ, argtypes(narg_max)
390 cl_option(1:narg_max)%name =
''
391 cl_option(1:narg_max)%value =
''
392 cl_option(1:narg_max)%has_val = .false.
393 cl_option(1:narg_max)%short = .false.
394 cl_option(1:narg_max)%long = .false.
399 arg = trim(arguments(ia))
400 typ = mod(argtypes(ia),10)
403 options(io) = trim(arg)
404 optypes(io) = argtypes(ia)
405 cl_option(io)%name = trim(arg)
407 if(nint(dble(optypes(io)-typ)/10.d0) .eq. 2) cl_option(io)%short = .true.
408 if(nint(dble(optypes(io)-typ)/10.d0) .eq. 3) cl_option(io)%long = .true.
409 else if(typ.eq.2)
then
410 values(io) = trim(arg)
411 cl_option(io)%value = trim(arg)
412 cl_option(io)%has_val = .true.
415 write(0,
'(A,2I3)')
' * Error in argument type:',ia,argtypes(ia)
423 if(verbose.ge.2)
then
426 write(*,
'(I6,5x,2A20,I6)') io,options(io),values(io),optypes(io)
430 if(verbose.ge.1)
then
433 if(mod(optypes(io),10).eq.0)
then
434 write(*,
'(1x,A)', advance=
'no') trim(options(io))
436 write(*,
'(2(1x,A))', advance=
'no') trim(options(io)),trim(values(io))
458 integer,
intent(in) :: Nopts, optypes(nOpts)
459 character,
intent(in) :: options(nOpts)*(*),values(nOpts)*(*)
460 type(
cl_options),
intent(in) :: cl_option(nOpts)
465 write(*,
'(/,A)')
' Options found:'
467 write(*,
'(2I5,9(5x,A19))') io,optypes(io),options(io),values(io)
468 write(*,
'(I5,2(5x,A19),3(3x,L3))') io,cl_option(io)%name, cl_option(io)%value, cl_option(io)%short, cl_option(io)%long, &
469 cl_option(io)%has_val
486 character,
intent(in) :: option*(*)
487 integer,
intent(in),
optional :: verbose
490 integer,
parameter :: narg_max = 99
492 integer :: i, lverbose, nopts, optypes(narg_max)
493 character :: options(narg_max)*(len(option)+2), values(narg_max)*(len(option)+2)
496 if(
present(verbose)) lverbose = verbose
501 if(nopts.eq.0)
return
507 if(lverbose.ge.2)
then
509 write(*,
'(2x,A)')
'Command-line option '//trim(option)//
' was found.'
511 write(*,
'(2x,A)')
'Command-line option '//trim(option)//
' was not found.'
530 character,
intent(in) :: option*(*)
531 character,
intent(out) :: string*(*)
534 integer,
parameter :: narg_max = 99
536 integer :: i, verbose, nopts, types(narg_max)
537 character :: options(narg_max)*(len(option)+2)
538 character :: values(narg_max)*(len(string))
544 if(nopts.eq.0)
return
547 if(trim(options(i)).eq.trim(option))
then
548 if(mod(types(i),10).ne.1)
then
552 string = trim(values(i))
571 character,
intent(in) :: option*(*)
572 integer,
intent(out) :: intarg
575 integer,
parameter :: narg_max = 99
577 integer :: i, verbose, nopts, types(narg_max)
578 character :: options(narg_max)*(len(option)+2)
579 character :: values(narg_max)*(99)
585 if(nopts.eq.0)
return
589 if(trim(options(i)).eq.trim(option))
then
590 if(mod(types(i),10).ne.1)
then
594 read(values(i),
'(I99)') intarg
615 character,
intent(in) :: option*(*)
616 real(
double),
intent(out) :: dblarg
619 integer,
parameter :: narg_max = 99
621 integer :: i, verbose, nopts, types(narg_max)
622 character :: options(narg_max)*(len(option)+2)
623 character :: values(narg_max)*(99)
629 if(nopts.eq.0)
return
633 if(trim(options(i)).eq.trim(option))
then
634 if(mod(types(i),10).ne.1)
then
638 read(values(i), *) dblarg
Procedures to handle command-line options and arguments.
subroutine get_command_argument_r(narg, arg, status)
Get a single-precision real from the command line.
subroutine split_short_cl_options(verbose, narg_max, nargs, arguments, types)
If short command-line options are found (i.e., starting with one dash), split them,...
logical function cl_option_present(option, verbose)
Check whether a command-line option is present.
subroutine print_commandline_options_values(nopts, options, values, optypes, cl_option)
Print all command-line options and values found to stdOut for debugging.
subroutine get_commandline_argument_types(verbose, nargs, arguments, types)
Determine the type of each command-line argument found:
logical function cl_option_var_string(option, string)
Retrieve the string argument/variable of a command-line option, if it exists.
subroutine get_commandline_options_values(verbose, narg_max, nopts, options, values, optypes, cl_option)
Obtain command-line arguments and reduce them to options, values and types.
subroutine get_command_argument_d(narg, arg, status)
Get a double-precision real from the command line.
logical function cl_option_var_int(option, intarg)
Retrieve the integer argument/variable of a command-line option, if it exists.
subroutine get_command_argument_i(narg, arg, status)
Get an integer from the command line.
subroutine get_command_argument_l(narg, arg, status)
Get a long integer from the command line.
logical function cl_option_var_dbl(option, dblarg)
Retrieve the floating-point argument/variable of a command-line option, if it exists.
subroutine read_all_commandline_arguments(verbose, narg_max, nargs, arguments)
Read all the command-line arguments and return them in a character array.
Provides kinds and related constants/routines.
integer, parameter double
Double-precision float. Precision = 15, range = 307.
integer, parameter long
Long integer.
System-related procedures.
subroutine quit_program(message)
Print a message to StdOut and stop the execution of the current program.
Struct to store command-line options.