error_check_coordsys Subroutine

private subroutine error_check_coordsys(sideAGrid, sideAMesh, sideBGrid, sideBMesh, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(in), optional :: sideAGrid(:)
type(ESMF_Mesh), intent(in), optional :: sideAMesh(:)
type(ESMF_Grid), intent(in), optional :: sideBGrid(:)
type(ESMF_Mesh), intent(in), optional :: sideBMesh(:)
integer, intent(out), optional :: rc

Source Code

subroutine error_check_coordsys(sideAGrid, sideAMesh, sideBGrid, sideBMesh, rc)
  type(ESMF_Grid),      intent(in), optional :: sideAGrid(:)
  type(ESMF_Mesh),      intent(in), optional :: sideAMesh(:)
  type(ESMF_Grid),      intent(in), optional :: sideBGrid(:)
  type(ESMF_Mesh),      intent(in), optional :: sideBMesh(:)
  integer,              intent(out),optional :: rc

  type(ESMF_CoordSys_Flag) :: coordSys
  integer :: localrc,i
  logical :: isSphere, isCart

  ! Init both to false
  isSphere=.false.
  isCart=.false.
  
  ! SideAGrid coordSys
  if(present(sideAGrid)) then
     do i = 1, size(sideAGrid, 1)
        call ESMF_GridGet(sideAGrid(i), coordSys=coordSys, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
             ESMF_CONTEXT, rcToReturn=rc)) return
        
        ! Check coordSys
        if (coordSys==ESMF_COORDSYS_SPH_DEG) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_SPH_RAD) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_CART) isCart=.true.
     enddo
  endif

  ! SideAMesh coordSys
  if(present(sideAMesh)) then
     do i = 1, size(sideAMesh, 1)
        call ESMF_MeshGet(sideAMesh(i), coordSys=coordSys, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
             ESMF_CONTEXT, rcToReturn=rc)) return
        
        ! Check coordSys
        if (coordSys==ESMF_COORDSYS_SPH_DEG) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_SPH_RAD) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_CART) isCart=.true.
     enddo
  endif

  ! SideAGrid coordSys
  if(present(sideBGrid)) then
     do i = 1, size(sideBGrid, 1)
        call ESMF_GridGet(sideBGrid(i), coordSys=coordSys, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
             ESMF_CONTEXT, rcToReturn=rc)) return
        
        ! Check coordSys
        if (coordSys==ESMF_COORDSYS_SPH_DEG) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_SPH_RAD) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_CART) isCart=.true.
     enddo
  endif

  ! SideAMesh coordSys
  if(present(sideBMesh)) then
     do i = 1, size(sideBMesh, 1)
        call ESMF_MeshGet(sideBMesh(i), coordSys=coordSys, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
             ESMF_CONTEXT, rcToReturn=rc)) return
        
        ! Check coordSys
        if (coordSys==ESMF_COORDSYS_SPH_DEG) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_SPH_RAD) isSphere=.true.
        if (coordSys==ESMF_COORDSYS_CART) isCart=.true.
     enddo
  endif

  ! Shouldn't have both 
  if (isSphere .and. isCart) then
      call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, & 
         msg=" A mix of Cartesian and spherical Grids and Meshes can not be used in XGrid creation.", &
         ESMF_CONTEXT, rcToReturn=rc) 
      return
  endif

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

end subroutine error_check_coordsys