ESMF_DistGridSeqIndex Function

public function ESMF_DistGridSeqIndex(minIndex, maxIndex, index, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: minIndex(:)
integer, intent(in) :: maxIndex(:)
integer, intent(in) :: index(:)
integer, intent(out), optional :: rc

Return Value integer


Calls

proc~~esmf_distgridseqindex~~CallsGraph proc~esmf_distgridseqindex ESMF_DistGridSeqIndex proc~esmf_logseterror ESMF_LogSetError proc~esmf_distgridseqindex->proc~esmf_logseterror esmf_breakpoint esmf_breakpoint proc~esmf_logseterror->esmf_breakpoint proc~esmf_logrc2msg ESMF_LogRc2Msg proc~esmf_logseterror->proc~esmf_logrc2msg proc~esmf_logwrite ESMF_LogWrite proc~esmf_logseterror->proc~esmf_logwrite c_esmc_loggeterrormsg c_esmc_loggeterrormsg proc~esmf_logrc2msg->c_esmc_loggeterrormsg c_esmc_vmwtime c_esmc_vmwtime proc~esmf_logwrite->c_esmc_vmwtime proc~esmf_logclose ESMF_LogClose proc~esmf_logwrite->proc~esmf_logclose proc~esmf_logflush ESMF_LogFlush proc~esmf_logwrite->proc~esmf_logflush proc~esmf_logopenfile ESMF_LogOpenFile proc~esmf_logwrite->proc~esmf_logopenfile proc~esmf_utiliounitflush ESMF_UtilIOUnitFlush proc~esmf_logwrite->proc~esmf_utiliounitflush proc~esmf_utilstring2array ESMF_UtilString2Array proc~esmf_logwrite->proc~esmf_utilstring2array proc~esmf_logclose->proc~esmf_logflush proc~esmf_logflush->proc~esmf_utiliounitflush proc~esmf_utilarray2string ESMF_UtilArray2String proc~esmf_logflush->proc~esmf_utilarray2string proc~esmf_logopenfile->proc~esmf_utiliounitflush proc~esmf_utiliounitget ESMF_UtilIOUnitGet proc~esmf_logopenfile->proc~esmf_utiliounitget

Called by

proc~~esmf_distgridseqindex~~CalledByGraph proc~esmf_distgridseqindex ESMF_DistGridSeqIndex proc~esmf_gridcreatedistgridarb ESMF_GridCreateDistgridArb proc~esmf_gridcreatedistgridarb->proc~esmf_distgridseqindex proc~esmf_gridcreate1peridima ESMF_GridCreate1PeriDimA proc~esmf_gridcreate1peridima->proc~esmf_gridcreatedistgridarb proc~esmf_gridcreate2peridima ESMF_GridCreate2PeriDimA proc~esmf_gridcreate2peridima->proc~esmf_gridcreatedistgridarb proc~esmf_gridcreateedgeconna ESMF_GridCreateEdgeConnA proc~esmf_gridcreateedgeconna->proc~esmf_gridcreatedistgridarb proc~esmf_gridcreatenoperidima ESMF_GridCreateNoPeriDimA proc~esmf_gridcreatenoperidima->proc~esmf_gridcreatedistgridarb proc~esmf_gridemptycompleteeconna ESMF_GridEmptyCompleteEConnA proc~esmf_gridemptycompleteeconna->proc~esmf_gridcreatedistgridarb interface~esmf_gridcreate ESMF_GridCreate interface~esmf_gridcreate->proc~esmf_gridcreateedgeconna interface~esmf_gridcreate1peridim ESMF_GridCreate1PeriDim interface~esmf_gridcreate1peridim->proc~esmf_gridcreate1peridima interface~esmf_gridcreate2peridim ESMF_GridCreate2PeriDim interface~esmf_gridcreate2peridim->proc~esmf_gridcreate2peridima interface~esmf_gridcreatenoperidim ESMF_GridCreateNoPeriDim interface~esmf_gridcreatenoperidim->proc~esmf_gridcreatenoperidima interface~esmf_gridemptycomplete ESMF_GridEmptyComplete interface~esmf_gridemptycomplete->proc~esmf_gridemptycompleteeconna

Source Code

  function ESMF_DistGridSeqIndex(minIndex, maxIndex, index, rc) 
!
! !RETURN VALUE:
    integer :: ESMF_DistGridSeqIndex   
!
! !ARGUMENTS:
    integer,                        intent(in)            :: minIndex(:)
    integer,                        intent(in)            :: maxIndex(:)
    integer,                        intent(in)            :: index(:)
    integer,                        intent(out), optional :: rc
!
! !DESCRIPTION:
!   Compute the canonical sequence index (single integer number) associated
!   with the index tuple passed in as {\tt index}. Canonical indices start
!   at 1 for the starting corner, specified via the {\tt minIndex} argument,
!   and increase from there in column major fashion up to the end corner. The
!   end corner is defined by the {\tt maxIndex} argument.
!
!   If the {\tt index} tuple is not within the index space defined by
!   {\tt minIndex} and {\tt maxIndex}, an invalid sequence index value 
!   of -1 is returned by this function.
!
!   The size of {\tt minIndex}, {\tt maxIndex}, and {\tt index} must all be
!   the same, or an error is returned in the return code.
!
!   The arguments are:
!   \begin{description}
!   \item[minIndex]
!        Index space tuple of the lower corner of the single tile.
!   \item[maxIndex]
!        Index space tuple of the upper corner of the single tile.
!   \item[index]
!        index space tuple of the index point to be converted into the 
!        sequence index.
!   \item[{[rc]}]
!        Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOPI
!------------------------------------------------------------------------------
    integer                 :: localrc            ! local return code
    integer                 :: seqIndex
    integer                 :: i, count

    ! initialize return code; assume routine not implemented
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL
    
    ESMF_DistGridSeqIndex = -1 ! initialize to an invalid value
    
    ! error checking of the input
    count = size(minIndex)
    if (count /= size(maxIndex)) then
      call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
        msg="size(maxIndex) must match size(minIndex)", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif
    if (count /= size(index)) then
      call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
        msg="size(index) must match size(minIndex)", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif
    
    seqIndex = 0 ! initialize to base 0
    do i = count, 1, -1
      ! error check:
      if (index(i)<minIndex(i) .or. index(i)>maxIndex(i)) then
        seqIndex = -2 ! will come out as -1 after the shift below
        exit
      endif
      ! first time multiply with zero intentionally:
      seqIndex = seqIndex * (maxIndex(i)-minIndex(i)+1)
      seqIndex = seqIndex + index(i)-minIndex(i)
    enddo
    seqIndex = seqIndex+1 ! shift sequence index to base 1 
 
    ! return successfully
    ESMF_DistGridSeqIndex = seqIndex
    if (present(rc)) rc = ESMF_SUCCESS

  end function ESMF_DistGridSeqIndex