process_command_line Subroutine

public subroutine process_command_line(regridder, rc)

Type Bound

RegridSupport

Arguments

Type IntentOptional Attributes Name
class(RegridSupport) :: regridder
integer, intent(out), optional :: rc

Calls

proc~~process_command_line~2~~CallsGraph proc~process_command_line~2 RegridSupport%process_command_line interface~mapl_assert MAPL_Assert proc~process_command_line~2->interface~mapl_assert push_back push_back proc~process_command_line~2->push_back

Called by

proc~~process_command_line~2~~CalledByGraph proc~process_command_line~2 RegridSupport%process_command_line program~main~9 main program~main~9->proc~process_command_line~2

Source Code

   subroutine process_command_line(regridder, rc)
      class (RegridSupport) :: regridder
      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 ('-i', '--ifile')
            regridder%in_file = get_next_argument()
            _ASSERT(regridder%in_file(1:1) /= '-','bad format')
         case ('-o', '--ofile')
             regridder%out_file = get_next_argument()
            _ASSERT(regridder%in_file(1:1) /= '-','bad format')
         case ('--nlats')
            buffer  = get_next_argument()
            _ASSERT(buffer(1:1) /= '-','bad format')
            read(buffer,*) regridder%JM
         case ('--nlons')
            buffer  = get_next_argument()
            _ASSERT(buffer(1:1) /= '-','bad format')
            read(buffer,*) regridder%IM
         case ('--vars')
            buffer = get_next_argument()
            _ASSERT(buffer(1:1) /= '-','bad format')
            regridder%requested_variables = parse_vars(buffer)
         case ('-d', '--debug')
            regridder%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