Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(CommandLineOptions), | intent(inout) | :: | options | |||
integer, | intent(out), | optional | :: | rc |
subroutine process_command_line(options, rc) type (CommandLineOptions), intent(inout) :: options integer, optional, intent(out) :: rc integer :: n_args integer :: i_arg character(len=:), allocatable :: argument character(len=:), allocatable :: buffer n_args = command_argument_count() i_arg = 0 do if (i_arg > n_args) exit argument = get_next_argument() select case (argument) case ('-nc', '--npes_client') buffer = get_next_argument() _ASSERT(buffer /= '-', "no -") read(buffer,*) options%npes_client case ('-ns', '--npes_server') buffer = get_next_argument() _ASSERT(buffer /= '-', "no -") read(buffer,*) options%npes_server case ('-f1', '--file_1') options%file_1 = get_next_argument() _ASSERT(options%file_1(1:1) /= '-', "too many ") case ('-f2', '--file_2') options%file_2 = get_next_argument() _ASSERT(options%file_2(1:1) /= '-', "too many -") case ('-v', '--var') buffer = get_next_argument() _ASSERT(buffer(1:1) /= '-', "too many -") options%requested_variables = parse_vars(buffer) case ('-s', '--server_type') options%server_type = get_next_argument() _ASSERT(options%server_type /= '-', "too many -") case ('-d', '--debug') options%debug = .true. case default ! ignore end select end do contains function get_next_argument() result(argument) character(len=:), allocatable :: argument integer :: length i_arg = i_arg + 1 call get_command_argument(i_arg, length=length) allocate(character(len=length) :: argument) call get_command_argument(i_arg, value=argument) end function get_next_argument function parse_vars(buffer) result(vars) type (StringVector) :: vars character(len=*), intent(in) :: buffer integer :: idx character(len=1), parameter :: COMMA = ',' character(len=:), allocatable :: string string = buffer // COMMA do if (len(string) == 0) exit idx = index(string,COMMA) call vars%push_back(string(1:idx-1)) string = string(idx+1:) end do end function parse_vars end subroutine process_command_line