CoordInfoFromCoordDepArb Subroutine

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

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: dimCount
logical, intent(in) :: isDist(:)
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 CoordInfoFromCoordDepArb(dimCount, isDist, coordDep1, coordDep2, coordDep3,&
                                     coordDimCount, coordDimMap, rc)
      integer,               intent(in)            :: dimCount
      logical,               intent(in)            :: isDist(:)
      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
      logical :: found

      ! 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


      if (present(coordDep1)) then
         ! error checking, if this dimension is arbitrary, one of the
         ! coordinate dimension has to be be ESMF_DIM_ARB
         if (isDist(1)) then
            found = .false.
            do i=1,size(coordDep1)
               if (coordDep1(i) == ESMF_DIM_ARB) found = .true.
            enddo
            if (.not. found) then
               call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
                    msg="- coordDep1 does not contain ESMF_DIM_ARB", &
                    ESMF_CONTEXT, rcToReturn=rc)
               return
            endif
         endif
         coordDimCount(1)=size(coordDep1)
         coordDimMap(1,:)=0
         do i=1,size(coordDep1)
            coordDimMap(1,i)=coordDep1(i)
         enddo
      else
         coordDimCount(1)=1
         ! ESMF_DIM_ARB if 1 is distributed, otherwise 1
         if (isDist(1)) then
            coordDimMap(1,1)=ESMF_DIM_ARB
         else
            coordDimMap(1,1)=1
         endif
      endif

      if (present(coordDep2)) then
         ! error checking, one of the dimensions has to be ESMF_DIM_ARB
         ! if dimension 2 is arbitrary
         if (isDist(2)) then
            found = .false.
            do i=1,size(coordDep2)
               if (coordDep2(i) == ESMF_DIM_ARB) found = .true.
            enddo
            if (.not. found) then
               call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
                    msg="- coordDep2 does not contain ESMF_DIM_ARB", &
                    ESMF_CONTEXT, rcToReturn=rc)
               return
            endif
         endif
         coordDimCount(2)=size(coordDep2)
         coordDimMap(2,:)=0
         do i=1,size(coordDep2)
            coordDimMap(2,i)=coordDep2(i)
         enddo
      else
         coordDimCount(2)=1
         ! ESMF_DIM_ARB if 1 is distributed, otherwise 1
         if (isDist(2)) then
            coordDimMap(2,1)=ESMF_DIM_ARB
         else
            coordDimMap(2,1)=2
         endif
      endif

      if (dimCount > 2) then
         if (present(coordDep3)) then
            ! error checking, one of the dimensions has to be ESMF_DIM_ARB
            ! if dimension 3 is arbitrary
            if (isDist(3)) then
               found = .false.
               do i=1,size(coordDep3)
                  if (coordDep3(i) == ESMF_DIM_ARB) found = .true.
               enddo
               if (.not. found) then
                  call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
                       msg="- coordDep3 does not contain ESMF_DIM_ARB", &
                       ESMF_CONTEXT, rcToReturn=rc)
                  return
               endif
            endif
            coordDimCount(3)=size(coordDep3)
            coordDimMap(3,:)=0
            do i=1,size(coordDep3)
               coordDimMap(3,i)=coordDep3(i)
            enddo
         else
            coordDimCount(3)=1
            ! ESMF_DIM_ARB if 1 is distributed, otherwise 1
            if (isDist(3)) then
               coordDimMap(3,1)=ESMF_DIM_ARB
            else
               coordDimMap(3,1)=3
            endif
         endif
      endif

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

    end subroutine CoordInfoFromCoordDepArb