Skip to content

Commit

Permalink
Merge pull request #576 from GEOS-ESM/hotfix/bmauer/fix_coarse_grid_io
Browse files Browse the repository at this point in the history
Fix coarse grid IO
  • Loading branch information
bena-nasa authored Oct 14, 2020
2 parents c32de28 + 1885590 commit 0234226
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix bug with using coarse grids in History and ExtData

### Added
### Changed
### Fixed
Expand Down
140 changes: 103 additions & 37 deletions base/MAPL_newCFIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,31 @@ subroutine RegridScalar(this,itemName,rc)
real, pointer :: ptr2d(:,:), outptr2d(:,:)
real, allocatable, target :: ptr3d_inter(:,:,:)
type(ESMF_Grid) :: gridIn,gridOut
logical :: hasDE_in, hasDE_out

call ESMF_FieldBundleGet(this%output_bundle,itemName,field=outField,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%input_bundle,grid=gridIn,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%output_bundle,grid=gridOut,rc=status)
_VERIFY(status)
hasDE_in = MAPL_GridHasDE(gridIn,rc=status)
_VERIFY(status)
hasDE_out = MAPL_GridHasDE(gridOut,rc=status)
_VERIFY(status)

if (this%doVertRegrid) then
call ESMF_FieldBundleGet(this%input_bundle,itemName,field=field,rc=status)
_VERIFY(status)
call ESMF_FieldGet(Field,rank=fieldRank,rc=status)
_VERIFY(status)
if (fieldRank==3) then
call ESMF_FieldGet(field,farrayPtr=ptr3d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call ESMF_FieldGet(field,farrayPtr=ptr3d,rc=status)
_VERIFY(status)
else
allocate(ptr3d(0,0,0))
end if
allocate(ptr3d_inter(size(ptr3d,1),size(ptr3d,2),this%vdata%lm),stat=status)
_VERIFY(status)
if (this%vdata%regrid_type==VERTICAL_METHOD_SELECT) then
Expand All @@ -438,19 +451,23 @@ subroutine RegridScalar(this,itemName,rc)
if (associated(ptr3d)) nullify(ptr3d)
end if

call ESMF_FieldBundleGet(this%input_bundle,grid=gridIn,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%output_bundle,grid=gridOut,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%input_bundle,itemName,field=field,rc=status)
_VERIFY(status)
call ESMF_FieldGet(field,rank=fieldRank,rc=status)
_VERIFY(status)
if (fieldRank==2) then
call MAPL_FieldGetPointer(field,ptr2d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(OutField,outptr2d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call MAPL_FieldGetPointer(field,ptr2d,rc=status)
_VERIFY(status)
else
allocate(ptr2d(0,0))
end if
if (hasDE_out) then
call MAPL_FieldGetPointer(OutField,outptr2d,rc=status)
_VERIFY(status)
else
allocate(outptr2d(0,0))
end if
if (gridIn==gridOut) then
outPtr2d=ptr2d
else
Expand All @@ -460,11 +477,19 @@ subroutine RegridScalar(this,itemName,rc)
end if
else if (fieldRank==3) then
if (.not.associated(ptr3d)) then
call MAPL_FieldGetPointer(field,ptr3d,rc=status)
if (hasDE_in) then
call ESMF_FieldGet(field,farrayPtr=ptr3d,rc=status)
_VERIFY(status)
else
allocate(ptr3d(0,0,0))
end if
end if
if (hasDE_out) then
call MAPL_FieldGetPointer(OutField,outptr3d,rc=status)
_VERIFY(status)
else
allocate(outptr3d(0,0,0))
end if
call MAPL_FieldGetPointer(OutField,outptr3d,rc=status)
_VERIFY(status)
if (gridIn==gridOut) then
outPtr3d=Ptr3d
else
Expand Down Expand Up @@ -498,20 +523,33 @@ subroutine RegridVector(this,xName,yName,rc)
real, pointer :: yptr2d(:,:), youtptr2d(:,:)
real, allocatable, target :: yptr3d_inter(:,:,:)
type(ESMF_Grid) :: gridIn, gridOut
logical :: hasDE_in, hasDE_out

call ESMF_FieldBundleGet(this%output_bundle,xName,field=xoutField,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%output_bundle,yName,field=youtField,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%input_bundle,grid=gridIn,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%output_bundle,grid=gridOut,rc=status)
_VERIFY(status)
hasDE_in = MAPL_GridHasDE(gridIn,rc=status)
_VERIFY(status)
hasDE_out = MAPL_GridHasDE(gridOut,rc=status)
_VERIFY(status)

if (this%doVertRegrid) then
call ESMF_FieldBundleGet(this%input_bundle,xName,field=xfield,rc=status)
_VERIFY(status)
call ESMF_FieldGet(xField,rank=fieldRank,rc=status)
_VERIFY(status)
if (fieldRank==3) then
call ESMF_FieldGet(xfield,farrayPtr=xptr3d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call ESMF_FieldGet(xfield,farrayPtr=xptr3d,rc=status)
_VERIFY(status)
else
allocate(xptr3d(0,0,0))
end if
allocate(xptr3d_inter(size(xptr3d,1),size(xptr3d,2),this%vdata%lm),stat=status)
_VERIFY(status)
if (this%vdata%regrid_type==VERTICAL_METHOD_SELECT) then
Expand All @@ -528,8 +566,12 @@ subroutine RegridVector(this,xName,yName,rc)
call ESMF_FieldGet(yField,rank=fieldRank,rc=status)
_VERIFY(status)
if (fieldRank==3) then
call ESMF_FieldGet(yfield,farrayPtr=yptr3d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call ESMF_FieldGet(yfield,farrayPtr=yptr3d,rc=status)
_VERIFY(status)
else
allocate(yptr3d(0,0,0))
end if
allocate(yptr3d_inter(size(yptr3d,1),size(yptr3d,2),this%vdata%lm),stat=status)
_VERIFY(status)
if (this%vdata%regrid_type==VERTICAL_METHOD_SELECT) then
Expand All @@ -546,26 +588,33 @@ subroutine RegridVector(this,xName,yName,rc)
if (associated(yptr3d)) nullify(yptr3d)
end if

call ESMF_FieldBundleGet(this%input_bundle,grid=gridIn,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%output_bundle,grid=gridOut,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%input_bundle,xname,field=xfield,rc=status)
_VERIFY(status)
call ESMF_FieldBundleGet(this%input_bundle,yname,field=yfield,rc=status)
_VERIFY(status)
call ESMF_FieldGet(xfield,rank=fieldRank,rc=status)
_VERIFY(status)
if (fieldRank==2) then
call MAPL_FieldGetPointer(xfield,xptr2d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(xOutField,xoutptr2d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call MAPL_FieldGetPointer(xfield,xptr2d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(yfield,yptr2d,rc=status)
_VERIFY(status)
else
allocate(xptr2d(0,0))
allocate(yptr2d(0,0))
end if

if (hasDE_in) then
call MAPL_FieldGetPointer(xOutField,xoutptr2d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(yOutField,youtptr2d,rc=status)
_VERIFY(status)
else
allocate(xoutptr2d(0,0))
allocate(youtptr2d(0,0))
end if

call MAPL_FieldGetPointer(yfield,yptr2d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(yOutField,youtptr2d,rc=status)
_VERIFY(status)

if (gridIn==gridOut) then
xoutPtr2d=xptr2d
Expand All @@ -576,18 +625,31 @@ subroutine RegridVector(this,xName,yName,rc)
end if
else if (fieldRank==3) then
if (.not.associated(xptr3d)) then
call MAPL_FieldGetPointer(xfield,xptr3d,rc=status)
_VERIFY(status)
if (hasDE_in) then
call MAPL_FieldGetPointer(xfield,xptr3d,rc=status)
_VERIFY(status)
else
allocate(xptr3d(0,0,0))
end if
end if
call MAPL_FieldGetPointer(xOutField,xoutptr3d,rc=status)
_VERIFY(status)

if (.not.associated(yptr3d)) then
call MAPL_FieldGetPointer(yfield,yptr3d,rc=status)
if (hasDE_in) then
call MAPL_FieldGetPointer(yfield,yptr3d,rc=status)
_VERIFY(status)
else
allocate(yptr3d(0,0,0))
end if
end if

if (hasDE_out) then
call MAPL_FieldGetPointer(xOutField,xoutptr3d,rc=status)
_VERIFY(status)
call MAPL_FieldGetPointer(yOutField,youtptr3d,rc=status)
_VERIFY(status)
else
allocate(xoutptr3d(0,0,0))
allocate(youtptr3d(0,0,0))
end if
call MAPL_FieldGetPointer(yOutField,youtptr3d,rc=status)
_VERIFY(status)

if (gridIn==gridOut) then
xoutPtr3d=xptr3d
Expand Down Expand Up @@ -717,6 +779,8 @@ subroutine stageData(this, field, fileName, tIndex, oClients, rc)
call pFIO_DownBit(ptr2d,ptr2d,this%nbits,undef=MAPL_undef,rc=status)
_VERIFY(status)
end if
else
allocate(ptr2d(0,0))
end if
ref = factory%generate_file_reference2D(Ptr2D)
allocate(localStart,source=[gridLocalStart,1])
Expand All @@ -730,6 +794,8 @@ subroutine stageData(this, field, fileName, tIndex, oClients, rc)
call pFIO_DownBit(ptr3d,ptr3d,this%nbits,undef=MAPL_undef,rc=status)
_VERIFY(status)
end if
else
allocate(ptr3d(0,0,0))
end if
ref = factory%generate_file_reference3D(Ptr3D)
allocate(localStart,source=[gridLocalStart,1,1])
Expand Down

0 comments on commit 0234226

Please sign in to comment.