parse_command_line Subroutine

public 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.

Arguments

Type IntentOptional Attributes Name
type(cli_args_type), intent(out) :: args

Parsed argument container

type(error_t), intent(out) :: error

Error object


Calls

proc~~parse_command_line~~CallsGraph proc~parse_command_line parse_command_line proc~error_set error_t%error_set proc~parse_command_line->proc~error_set proc~print_usage print_usage proc~parse_command_line->proc~print_usage

Variables

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


Source Code

   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