Skip to content

Commit d1ba5a0

Browse files
authored
Merge pull request #4261 from GEOS-ESM/bugfix/pchakrab/grid-get-temp-fix
This is a temporary fix for the original dangling pointer bug in returning grid co-ordinates
2 parents f3679ad + 9484985 commit d1ba5a0

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

geom/GridGet.F90

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "MAPL.h"
22

33
module mapl3g_GridGet
4+
45
use esmf
56
use mapl_KeywordEnforcer
67
use mapl_ErrorHandling
8+
79
implicit none
810
private
911

@@ -17,31 +19,24 @@ module mapl3g_GridGet
1719
interface GridGetCoordinates
1820
procedure :: grid_get_coordinates_r4
1921
procedure :: grid_get_coordinates_r8
22+
procedure :: grid_get_coordinates_r8ptr
2023
end interface GridGetCoordinates
2124

2225
contains
2326

24-
subroutine grid_get(grid, unusable, &
25-
name, &
26-
dimCount, coordDimCount, &
27-
im, jm, &
28-
longitudes, latitudes, &
29-
rc)
30-
27+
subroutine grid_get(grid, unusable, name, dimCount, coordDimCount, im, jm, rc)
3128
type(esmf_Grid), intent(in) :: grid
3229
class(KeywordEnforcer), optional, intent(in) :: unusable
33-
character(:), optional, allocatable :: name
30+
character(:), optional, allocatable, intent(out) :: name
3431
integer, optional, intent(out) :: dimCount
3532
integer, optional, allocatable, intent(out) :: coordDimCount(:)
3633
integer, optional, intent(out) :: im, jm
37-
real(kind=ESMF_KIND_R4), optional, pointer :: longitudes(:,:), latitudes(:,:)
3834
integer, optional, intent(out) :: rc
3935

4036
integer :: dimCount_
4137
character(ESMF_MAXSTR) :: name_
4238
integer :: status
4339
real(kind=ESMF_KIND_R8), pointer :: coords(:,:)
44-
real(kind=ESMF_KIND_R4), allocatable, target :: lons(:,:), lats(:,:)
4540
logical :: has_de
4641

4742
call esmf_GridGet(grid, dimCount=dimCount_, _RC)
@@ -65,16 +60,8 @@ subroutine grid_get(grid, unusable, &
6560
if (present(jm)) jm = size(coords,2)
6661
end if
6762

68-
if (present(longitudes) .or. present(latitudes)) then
69-
call GridGetCoordinates(grid, longitudes=lons, latitudes=lats, _RC)
70-
if (present(longitudes)) then
71-
longitudes => lons
72-
end if
73-
if (present(latitudes)) then
74-
latitudes => lats
75-
end if
76-
end if
7763
_RETURN(_SUCCESS)
64+
_UNUSED_DUMMY(unusable)
7865
end subroutine grid_get
7966

8067
logical function grid_has_DE(grid,rc) result(has_DE)
@@ -128,7 +115,20 @@ subroutine grid_get_coordinates_r8(grid, longitudes, latitudes, rc)
128115
latitudes = ptr
129116

130117
_RETURN(_SUCCESS)
131-
132118
end subroutine grid_get_coordinates_r8
133119

120+
subroutine grid_get_coordinates_r8ptr(grid, longitudes, latitudes, rc)
121+
type(esmf_Grid), intent(in) :: grid
122+
real(ESMF_KIND_R8), pointer, intent(out) :: longitudes(:,:)
123+
real(ESMF_KIND_R8), pointer, intent(out) :: latitudes(:,:)
124+
integer, optional, intent(out) :: rc
125+
126+
integer :: status
127+
128+
call esmf_GridGetCoord(grid, coordDim=1, farrayPtr=longitudes, _RC)
129+
call esmf_GridGetCoord(grid, coordDim=2, farrayPtr=latitudes, _RC)
130+
131+
_RETURN(_SUCCESS)
132+
end subroutine grid_get_coordinates_r8ptr
133+
134134
end module mapl3g_GridGet

0 commit comments

Comments
 (0)