Parse command line arguments for geometry file and basis set
Extracts XYZ file path and basis set name from command line, validates arguments, and handles help requests.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(cli_args_type), | intent(out) | :: | args |
Parsed argument container |
||
| type(error_t), | intent(out) | :: | error |
Error object |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=256), | private | :: | arg_buffer |
Temporary argument buffer |
|||
| integer, | private | :: | arg_len |
Length of current argument |
|||
| integer, | private | :: | nargs |
Number of command line arguments |
|||
| integer, | private | :: | stat |
Local status for intrinsic calls |
subroutine parse_command_line(args, error) !! Parse command line arguments for geometry file and basis set !! !! Extracts XYZ file path and basis set name from command line, !! validates arguments, and handles help requests. type(cli_args_type), intent(out) :: args !! Parsed argument container type(error_t), intent(out) :: error !! Error object integer :: nargs !! Number of command line arguments character(len=256) :: arg_buffer !! Temporary argument buffer integer :: arg_len !! Length of current argument integer :: stat !! Local status for intrinsic calls ! Get number of command line arguments nargs = command_argument_count() ! Check for help flag if (nargs >= 1) then call get_command_argument(1, arg_buffer, arg_len, stat) if (stat /= 0) then call error%set(ERROR_PARSE, "Error reading command line argument 1") return end if arg_buffer = trim(arg_buffer) if (arg_buffer == "-h" .or. arg_buffer == "--help") then call print_usage() call error%set(ERROR_PARSE, "HELP_REQUESTED") ! Special marker for help return end if end if ! Validate number of arguments if (nargs < 2) then call error%set(ERROR_PARSE, "Error: Insufficient arguments. Expected 2 arguments (geometry.xyz basis_name)") call print_usage() return end if if (nargs > 2) then call error%set(ERROR_PARSE, "Error: Too many arguments. Expected 2 arguments (geometry.xyz basis_name)") call print_usage() return end if ! Parse argument 1: XYZ file call get_command_argument(1, arg_buffer, arg_len, stat) if (stat /= 0) then call error%set(ERROR_PARSE, "Error reading geometry file argument") return end if args%xyz_file = trim(arg_buffer) ! Parse argument 2: Basis set name call get_command_argument(2, arg_buffer, arg_len, stat) if (stat /= 0) then call error%set(ERROR_PARSE, "Error reading basis set name argument") return end if args%basis_name = trim(arg_buffer) end subroutine parse_command_line