Skip to content

Commit

Permalink
Merge pull request #900 from GEOS-ESM/hotfix/rmontuoro/convert-coordi…
Browse files Browse the repository at this point in the history
…nates

Ensure grid coordinates are always provided in radians
  • Loading branch information
tclune authored Jun 24, 2021
2 parents 18193a2 + 220cc25 commit a7bb471
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
### Fixed

- Ensure grid coordinates are always provided in radians

## [2.7.2] - 2021-06-23

### Fixed
Expand Down
18 changes: 14 additions & 4 deletions base/ESMFL_Mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ end subroutine ESMFL_StateGetField

!BOP

! !IROUTINE: ESMFL_GridCoordGet - retrieves the coordinates of a particular axis
! !IROUTINE: ESMFL_GridCoordGet - retrieves the coordinates of a particular axis in radians

! !INTERFACE:
subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)
Expand All @@ -317,11 +317,13 @@ subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)

! local variables
integer :: rank
type(ESMF_CoordSys_Flag) :: crdSys
type(ESMF_TypeKind_Flag) :: tk
integer :: counts(ESMF_MAXDIM)
integer :: crdOrder
real(ESMF_KIND_R4), pointer :: r4d2(:,:)
real(ESMF_KIND_R8), pointer :: r8d2(:,:)
real(ESMF_KIND_R8) :: conv2rad
integer :: STATUS
integer :: i
integer :: j
Expand All @@ -331,7 +333,7 @@ subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)

_UNUSED_DUMMY(Units)

call ESMF_GridGet(grid, coordTypeKind=tk, &
call ESMF_GridGet(grid, coordSys=crdSys, coordTypeKind=tk, &
dimCount=rank, coordDimCount=coordDimCount, rc=status)
_VERIFY(STATUS)

Expand Down Expand Up @@ -372,6 +374,14 @@ subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)
_RETURN(ESMF_SUCCESS)
end if

if (crdSys == ESMF_COORDSYS_SPH_DEG) then
conv2rad = MAPL_PI_R8 / 180._ESMF_KIND_R8
else if (crdSys == ESMF_COORDSYS_SPH_RAD) then
conv2rad = 1._ESMF_KIND_R8
else
_FAIL('Unsupported coordinate system: ESMF_COORDSYS_CART')
end if

if (tk == ESMF_TYPEKIND_R4) then
if (coordDimCount(crdOrder)==2) then
call ESMF_GridGetCoord(grid, localDE=0, coordDim=crdOrder, &
Expand All @@ -381,7 +391,7 @@ subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)
_VERIFY(STATUS)
allocate(coord(counts(1), counts(2)), STAT=status)
_VERIFY(STATUS)
coord = R4D2
coord = conv2rad * R4D2
else
_RETURN(ESMF_FAILURE)
endif
Expand All @@ -394,7 +404,7 @@ subroutine ESMFL_GridCoordGet(GRID, coord, name, Location, Units, rc)
_VERIFY(STATUS)
allocate(coord(counts(1), counts(2)), STAT=status)
_VERIFY(STATUS)
coord = R8D2
coord = conv2rad * R8D2
else
_RETURN(ESMF_FAILURE)
endif
Expand Down

0 comments on commit a7bb471

Please sign in to comment.