46 character(len=:),
allocatable :: name
47 character(len=:),
allocatable :: value
48 logical :: has_value = .true.
53 character(len=:),
allocatable :: str
111 integer :: i_arg, i_tok, indx
112 type(
cmd_arg),
dimension(:),
allocatable :: all_args_tmp
113 character(len=max_string_len) :: arg, tmp, tmp_name, tmp_val
114 integer :: arg_in_length, tmp_len
135 call get_command_argument(i_tok, arg, length=arg_in_length)
142 indx = index(arg,
'=')
145 tmp = adjustl(arg(indx+1:))
146 tmp_len = len_trim(tmp)
147 if(indx > 1 .and. tmp_len > 0)
then
152 tmp_name = adjustl(arg(1:indx-1))
153 else if(indx > 1)
then
156 call get_command_argument(i_tok, tmp, length=arg_in_length)
160 tmp_val = adjustl(tmp)
161 tmp_name = adjustl(arg(1:indx-1))
164 tmp_name = adjustl(arg)
167 call get_command_argument(i_tok, tmp, length=arg_in_length)
170 indx = index(adjustl(tmp),
'=')
179 if(len_trim(adjustl(tmp)) > 1)
then
181 tmp_val = adjustl(tmp(2:))
184 call get_command_argument(i_tok, tmp, length=arg_in_length)
188 tmp_val = adjustl(tmp)
194 allocate(
character(len=len_trim(tmp_name)) :: all_args(i_arg)%name)
195 all_args(i_arg)%name = trim(tmp_name)
196 allocate(
character(len=len_trim(tmp_val)) :: all_args(i_arg)%value)
197 all_args(i_arg)%value = trim(tmp_val)
204 call move_alloc(all_args, all_args_tmp)
207 deallocate(all_args_tmp)
210 if(truncated) print
'(a,i0, a)',
"warning: very long argument truncated. to support arguments&
211 & longer than ",
max_string_len,
" increase the max_string_len parameter"
252 integer,
intent(in) :: num
253 logical,
intent(inout) :: val
254 logical,
intent(out),
optional :: exists
262 if(num <=
num_args .and. num > 0)
then
264 read(
all_args(num)%value, *, iostat=ierr) val
268 if(
present(exists))
then
294 character(len=*),
intent(in) :: name
295 logical,
intent(inout) :: val
297 logical,
intent(out),
optional :: exists
308 if(
all_args(i)%name == trim(adjustl(name)))
then
311 read(
all_args(i)%value, *, iostat=ierr) val
319 if(
present(exists))
then
343 integer,
intent(in) :: num
344 real(kind=
real64),
intent(inout) :: val
345 logical,
intent(out),
optional :: exists
353 if(num <=
num_args .and. num > 0)
then
355 read(
all_args(num)%value, *, iostat=ierr) val
359 if(
present(exists))
then
382 character(len=*),
intent(in) :: name
383 real(kind=
real64),
intent(inout) :: val
385 logical,
intent(out),
optional :: exists
394 if(
all_args(i)%name == trim(adjustl(name)))
then
396 read(
all_args(i)%value, *, iostat=ierr) val
401 if(
present(exists))
then
426 integer,
intent(in) :: num
427 real(kind=
real32),
intent(inout) :: val
429 logical,
intent(out),
optional :: exists
432 if( abs(tmp) < huge(val))
then
434 val = real(tmp, kind=
real32)
455 character(len=*),
intent(in) :: name
456 real(kind=
real32),
intent(inout) :: val
458 logical,
intent(out),
optional :: exists
461 if( abs(tmp) < huge(val))
then
463 val = real(tmp, kind=
real32)
485 integer,
intent(in) :: num
486 integer(kind=int32),
intent(inout) :: val
487 logical,
intent(out),
optional :: exists
495 if(num <=
num_args .and. num > 0)
then
498 read(
all_args(num)%value, *, iostat=ierr) val
502 if(
present(exists))
then
524 character(len=*),
intent(in) :: name
525 integer(kind=int32),
intent(inout) :: val
527 logical,
intent(out),
optional :: exists
536 if(
all_args(i)%name == trim(adjustl(name)))
then
538 read(
all_args(i)%value, *, iostat=ierr) val
543 if(
present(exists))
then
565 integer,
intent(in) :: num
566 integer(kind=int64),
intent(inout) :: val
567 logical,
intent(out),
optional :: exists
575 if(num <=
num_args .and. num > 0)
then
578 read(
all_args(num)%value, *, iostat=ierr) val
582 if(
present(exists))
then
604 character(len=*),
intent(in) :: name
605 integer(kind=int64),
intent(inout) :: val
607 logical,
intent(out),
optional :: exists
616 if(
all_args(i)%name == trim(adjustl(name)))
then
618 read(
all_args(i)%value, *, iostat=ierr) val
623 if(
present(exists))
then
646 integer,
intent(in) :: num
647 character(len=*),
intent(inout) :: val
648 logical,
intent(out),
optional :: exists
655 if(num <=
num_args .and. num > 0)
then
662 if(
present(exists))
then
689 character(len=*),
intent(in) :: name
690 character(len=*),
intent(inout) :: val
692 logical,
intent(out),
optional :: exists
699 if(
all_args(i)%name == trim(adjustl(name)))
then
706 if(
present(exists))
then
730 character(len=*),
intent(in) :: name
731 logical,
intent(out),
optional :: has_value
737 if(
present(has_value)) has_value = .false.
739 if(
all_args(i)%name == trim(adjustl(name)))
then
741 if(
present(has_value)) has_value =
all_args(i)%has_value
782 character(len=*),
intent(in) :: name
783 logical,
intent(out),
optional :: exists
792 if(
all_args(i)%name .eq. trim(adjustl(name)))
then
801 if(
present(exists))
then
read arguments by name or number
logical function get_arg_name_dbl(name, val, exists)
read by name for double precision values
type(cmd_arg), dimension(:), allocatable, private all_args
the argument list
logical function get_arg_num_float(num, val, exists)
Read by number for single precision (float) values.
logical function get_arg_num_long(num, val, exists)
read by number for long integer values
logical function, public arg_present(name, has_value)
check presence of an argument by name
logical function get_arg_num_str(num, val, exists)
read by number for string/character values
logical function get_arg_num_dbl(num, val, exists)
read by number for double precision values
logical function get_arg_name_float(name, val, exists)
read by name for single precision (float) values
subroutine parse_args()
Parse out command line args.
integer, private num_args
the number of arguments
subroutine initial_parse
helper function - do a parse if it hasn't been done yet
character(len=:) function, allocatable, public get_arg_value(name, exists)
lookup an argument by name and return the value as an (allocatable) string if the name is not present...
logical function get_arg_num_int(num, val, exists)
read by number for integer values
logical function get_arg_name_int(name, val, exists)
read by name for integer values
type(str_wrapper) function, dimension(:), allocatable, public dump_names()
get all the argument names (by copy) order will probably match input order, but this is not guarantee...
integer function, public arg_count()
get the number of arguments note: total count may not match command_argument_count due to parsing key...
logical function get_arg_name_long(name, val, exists)
read by name for long integer values
logical function get_arg_name_logical(name, val, exists)
Read by name for logical values.
logical function get_arg_num_logical(num, val, exists)
read by number for logical values
logical function get_arg_name_str(name, val, exists)
read by name for string values
logical initial_parse_done
integer, parameter max_string_len
integer, parameter real32
Normal "float" (32 bit = 4 bytes, approx -3.4e38 to 3.4e38 and covering values down to about 1e-38 ma...
integer, parameter real64
Longer "double" (64 bit, approx -1.8e308 to 1.8e308 and covering values down to about 2e-308 magnitud...
type containing a key-value pair
wrapper to allow array of allocatable strings