CoordInfoFromCoordDep Subroutine

private subroutine CoordInfoFromCoordDep(dimCount, coordDep1, coordDep2, coordDep3, coordDimCount, coordDimMap, rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: dimCount
integer, intent(in), optional :: coordDep1(:)
integer, intent(in), optional :: coordDep2(:)
integer, intent(in), optional :: coordDep3(:)
integer, intent(out), optional :: coordDimCount(:)
integer, intent(out), optional :: coordDimMap(:,:)
integer, optional :: rc

Source Code

    subroutine CoordInfoFromCoordDep(dimCount, coordDep1, coordDep2, coordDep3,&
                                     coordDimCount, coordDimMap, rc)
      integer,                intent(in)            :: dimCount
      integer,               intent(in),  optional :: coordDep1(:)
      integer,               intent(in),  optional :: coordDep2(:)
      integer,               intent(in),  optional :: coordDep3(:)
      integer,               intent(out),  optional :: coordDimCount(:)
      integer,               intent(out),  optional :: coordDimMap(:,:)
      integer,optional                               :: rc
      integer :: i

      ! Initialize return code; assume failure until success is certain
      if (present(rc)) rc = ESMF_RC_NOT_IMPL


      ! Error checking
      if ((dimCount .lt. 3) .and. present(coordDep3)) then
         call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
              msg="- coordDep3 not allowed when grid is less than dimCount 3", &
              ESMF_CONTEXT, rcToReturn=rc)
         return
      endif

      if (present(coordDep1)) then
         if ((size(coordDep1) < 1) .or. (size(coordDep1)>dimCount)) then
            call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
                 msg="- coordDep1 size incompatible with grid dimCount", &
                 ESMF_CONTEXT, rcToReturn=rc)
            return
         endif
      endif

      if (present(coordDep2)) then
         if ((size(coordDep2) < 1) .or. (size(coordDep2)>dimCount)) then
            call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
                 msg="- coordDep2 size incompatible with grid dimCount", &
                 ESMF_CONTEXT, rcToReturn=rc)
            return
         endif
      endif

      if (present(coordDep3)) then
         if ((size(coordDep3) < 1) .or. (size(coordDep3)>dimCount)) then
            call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
                 msg="- coordDep3 size incompatible with grid dimCount", &
                 ESMF_CONTEXT, rcToReturn=rc)
            return
         endif
      endif


      ! Set coordDimCount and coordDimMap
      if (present(coordDep1)) then
         coordDimCount(1)=size(coordDep1)
         coordDimMap(1,:)=0
         do i=1,size(coordDep1)
            coordDimMap(1,i)=coordDep1(i)
         enddo
      else
         coordDimCount(1)=dimCount
         do i=1,dimCount
            coordDimMap(1,i)=i
         enddo
      endif

      if (present(coordDep2)) then
         coordDimCount(2)=size(coordDep2)
         coordDimMap(2,:)=0
         do i=1,size(coordDep2)
            coordDimMap(2,i)=coordDep2(i)
         enddo
      else
         coordDimCount(2)=dimCount
         do i=1,dimCount
            coordDimMap(2,i)=i
         enddo
      endif

      if (dimCount > 2) then
         if (present(coordDep3)) then
            coordDimCount(3)=size(coordDep3)
            coordDimMap(3,:)=0
            do i=1,size(coordDep3)
               coordDimMap(3,i)=coordDep3(i)
            enddo
         else
            coordDimCount(3)=dimCount
            do i=1,dimCount
               coordDimMap(3,i)=i
            enddo
         endif
      endif

    ! Return successfully
    if (present(rc)) rc = ESMF_SUCCESS

    end subroutine CoordInfoFromCoordDep