Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | version | |||
logical, | intent(out) | :: | print_output_variables | |||
character(len=*), | intent(out) | :: | print_defaults |
subroutine parse_commandline_arguments(version, print_output_variables, print_defaults)
character(len=*), intent(in) :: version
logical, intent(out) :: print_output_variables
character(len=*), intent(out) :: print_defaults
character(len=path_max_length) :: arg
integer i, iarg
! Number of commandline arguments
iarg = iargc()
! without arguments only show help
if (iarg == 0) call print_help("parameter-nml is missing")
print_output_variables = .False.
print_defaults = " "
do i = 1, iarg
call getarg(i, arg)
! Options
if (arg(:1) == "-") then
! remove first - if long form
if (arg(1:2) == "--") arg = arg(2:)
select case (trim(arg(2:)))
case ("h", "help")
call print_splash(version)
call print_help
case ("d", "defaults")
! Interpret next argument as module
call getarg(i + 1, print_defaults)
if (trim(print_defaults) == "") print_defaults = "all"
case ("o", "output-variables")
print_output_variables = .True.
case ("v", "version")
write(*, "(A)") version
stop
case default
call print_help("Unknown option: "//trim(arg))
end select
else ! Positional argument
config_file_path = arg
end if
end do
end subroutine parse_commandline_arguments