parse_commandline_arguments Subroutine

public subroutine parse_commandline_arguments(version, print_output_variables, print_defaults)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: version
logical, intent(out) :: print_output_variables
character(len=*), intent(out) :: print_defaults

Calls

proc~~parse_commandline_arguments~~CallsGraph proc~parse_commandline_arguments parse_commandline_arguments proc~print_splash print_splash proc~parse_commandline_arguments->proc~print_splash proc~print_help print_help proc~parse_commandline_arguments->proc~print_help proc~colourise colourise proc~print_splash->proc~colourise proc~log_error log_error proc~print_help->proc~log_error proc~string_index string_index proc~colourise->proc~string_index proc~log_message log_message proc~log_error->proc~log_message proc~log_write log_write proc~log_message->proc~log_write proc~log_format_message log_format_message proc~log_message->proc~log_format_message proc~to_string to_string proc~log_write->proc~to_string proc~log_format_message->proc~colourise proc~date_time_str date_time_str proc~log_format_message->proc~date_time_str

Called by

proc~~parse_commandline_arguments~~CalledByGraph proc~parse_commandline_arguments parse_commandline_arguments proc~initialise initialise proc~initialise->proc~parse_commandline_arguments program~swim swim program~swim->proc~initialise

Contents


Source Code

  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