subroutine ESMF_UtilGetArgIndex(argvalue, keywordEnforcer, argindex, rc)
!
! !ARGUMENTS:
character(*), intent(in) :: argvalue
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: argindex
integer, intent(out), optional :: rc
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION:
! This method searches for, and returns the index of a desired command
! line argument. An example might be to find a specific keyword
! (e.g., -esmf\_path) so that its associated value argument could be
! obtained by adding 1 to the argindex and calling {\tt ESMF\_UtilGetArg()}.
!
! Some MPI implementations do not consistently provide command line
! arguments on PETs other than PET 0. It is therefore recommended
! that PET 0 call this method and broadcast the results to the other
! PETs by using the {\tt ESMF\_VMBroadcast()} method.
!
! The arguments are:
!
! \begin{description}
! \item [argvalue]
! A character string which will be searched for in the command line
! argument list.
! \item [{[argindex]}]
! If the {\tt value} string is found, the position will be returned
! as a non-negative integer. If the string is not found, a negative
! value will be returned.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!EOP
!-------------------------------------------------------------------------
integer :: argindex_local
integer :: i
integer :: len_local, len_max
integer :: localrc
integer :: nargs
! initialize return code; assume routine not implemented
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
call ESMF_UtilGetArgC (count=nargs)
! Find the maximum string length of all command line arguments
len_max = 0
do, i=0, nargs
call ESMF_UtilGetArg (i, arglength=len_local, rc=localrc)
if (ESMF_LogFoundError ( localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
return
len_max = max (len_max, len_local)
end do
! Call subroutine so that a proper string length can be used for
! comparison.
call arg_search_worker (len_max, argindex_local, rc1=localrc)
if (ESMF_LogFoundError ( localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
return
if (present (argindex)) &
argindex = argindex_local
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
contains
subroutine arg_search_worker (len_max, argindex1, rc1)
integer, intent(in) :: len_max
integer, intent(out) :: argindex1
integer, intent(out) :: rc1
character(len_max) :: string
integer :: i1
integer :: localrc1
do, i1=0, nargs
call ESMF_UtilGetArg (i1, argvalue=string, rc=localrc1)
if (ESMF_LogFoundError ( localrc1, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc1)) &
return
if (string == argvalue) exit
end do
if (i1 <= nargs) then
argindex1 = i1
else
argindex1 = -1
end if
end subroutine arg_search_worker
end subroutine ESMF_UtilGetArgIndex