Skip to content

Commit ce5fcef

Browse files
authored
Merge pull request #11 from GEOS-ESM/feature/mathomp4/Jason-3_1
Update to code from Jason-3_1
2 parents 519c21a + 6de123d commit ce5fcef

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

MAPL_Base/MAPL_CFIO.F90

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ module MAPL_CFIOMod
213213
integer, pointer :: Krank(:)=>null()
214214
integer :: rootRank = 0
215215
real, pointer :: levs(:)=>null()
216+
real, pointer :: unmodifiedLevs(:)=>null()
216217
type(MAPL_CommRequest), &
217218
pointer :: reqs(:)=>null()
218219
class (AbstractRegridder), pointer :: regridder => null()
@@ -230,6 +231,8 @@ module MAPL_CFIOMod
230231
integer :: collection_id
231232
integer :: fraction
232233
integer :: regrid_type
234+
real, pointer :: surfaceLayer(:,:) => null()
235+
logical :: ascending
233236
end type MAPL_CFIO
234237
!EOC
235238
!EOP
@@ -1145,9 +1148,10 @@ subroutine MAPL_CFIOCreateFromBundle ( MCFIO, NAME, CLOCK, BUNDLE, OFFSET,
11451148
LEV = (/(L, L=1,LM)/)
11461149
end if
11471150

1148-
allocate(mCFIO%levs(size(lev)), stat=status)
1151+
allocate(mCFIO%levs(size(lev)),mcfio%unmodifiedLevs(size(lev)), stat=status)
11491152
VERIFY_(STATUS)
11501153
mCFIO%levs = lev
1154+
mCFIO%unmodifiedLevs = lev
11511155
if (HAVE_ungrd) then
11521156
call ESMF_CFIOGridSet(cfiogrid, levUnit=ungridded_unit, RC=STATUS)
11531157
VERIFY_(STATUS)
@@ -1164,6 +1168,7 @@ subroutine MAPL_CFIOCreateFromBundle ( MCFIO, NAME, CLOCK, BUNDLE, OFFSET,
11641168
else
11651169
mCFIO%levs = lev* MCFIO%vscale
11661170
end if
1171+
mCFIO%unmodifiedLevs=mCFIO%unmodifiedLevs*MCFIO%vscale
11671172

11681173
if( trim(vunits).eq."" ) then
11691174
call ESMF_AttributeGet(FIELD, NAME="UNITS", VALUE=units, RC=STATUS)
@@ -1735,9 +1740,10 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
17351740
real, target, allocatable :: Ple3d(:,:,:)
17361741
real, allocatable :: Pl3d(:,:,:)
17371742
real, allocatable :: Ptrx(:,:,:)
1738-
real, pointer :: layer(:,:)
1743+
real, pointer :: layer(:,:),ps0(:,:)
17391744
logical :: PrePost_
1740-
1745+
integer :: globalcount(3)
1746+
type(ESMF_VM) :: vm
17411747

17421748
! ---
17431749

@@ -1763,6 +1769,19 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
17631769
allocate( LAYER(size(Ptr3,1),size(Ptr3,2) ), stat=status)
17641770
VERIFY_(STATUS)
17651771

1772+
if (associated(mcfio%regridder)) then
1773+
call ESMF_VMGetCurrent(vm,rc=status)
1774+
VERIFY_(status)
1775+
call MAPL_GridGet(mcfio%grid,globalCellCountPerDim=globalCount,rc=status)
1776+
VERIFY_(status)
1777+
call MAPL_AllocNodeArray(ps0,[globalCount(1),globalCount(2)],rc=status)
1778+
if(STATUS==MAPL_NoShm) allocate(ps0(globalCount(1),globalCount(2)),stat=status)
1779+
VERIFY_(status)
1780+
call MAPL_AllocNodeArray(mcfio%surfaceLayer,[mcfio%im,mcfio%jm],rc=status)
1781+
if(STATUS==MAPL_NoShm) allocate(mcfio%surfaceLayer(mcfio%im,mcfio%jm),stat=status)
1782+
VERIFY_(STATUS)
1783+
end if
1784+
17661785
! The Ptr3 interpolating variable is a zero-based (0-LM) edge variable
17671786
!---------------------------------------------------------------------
17681787
if(lbound(PTR3,3)==0) then
@@ -1781,6 +1800,11 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
17811800
ple3D = Ptr3
17821801
pl3D = ( 0.5*(Ptr3(:,:,1:)+Ptr3(:,:,0:ubound(Ptr3,3)-1)) )
17831802
end if
1803+
if (associated(mCFIO%regridder)) then
1804+
mcfio%ascending = (ptr3(1,1,0)<ptr3(1,1,1))
1805+
call ArrayGather(ptr3(:,:,ubound(ptr3,3)),ps0,mcfio%grid,rc=status)
1806+
VERIFY_(status)
1807+
end if
17841808

17851809
else
17861810

@@ -1808,9 +1832,31 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
18081832
pl3D = ( 0.5*(Ptrx(:,:,1:)+Ptrx(:,:,0:ubound(Ptrx,3)-1)) )
18091833
end if
18101834

1835+
if (associated(mCFIO%regridder)) then
1836+
mcfio%ascending = (ptrx(1,1,0)<ptrx(1,1,1))
1837+
call ArrayGather(ptrx(:,:,ubound(ptrx,3)),ps0,mcfio%grid,rc=status)
1838+
VERIFY_(status)
1839+
1840+
end if
18111841
deallocate(Ptrx)
18121842
end if
18131843

1844+
if (associated(mCFIO%regridder)) then
1845+
call MAPL_BcastShared(vm,data=ps0,N=globalCount(1)*globalCount(2),root=0,RootOnly=.false.,rc=status)
1846+
VERIFY_(status)
1847+
if (MAPL_AmNodeRoot .or. (.not. MAPL_ShmInitialized)) then
1848+
call mCFIO%regridder%regrid(ps0,mcfio%surfaceLayer,rc=status)
1849+
VERIFY_(status)
1850+
end if
1851+
1852+
if (MAPL_ShmInitialized) then
1853+
call MAPL_DeAllocNodeArray(ps0,rc=status)
1854+
VERIFY_(status)
1855+
else
1856+
deallocate(ps0)
1857+
end if
1858+
end if
1859+
18141860
end if
18151861

18161862
call MAPL_CFIOSetVectorPairs(mCFIO,rc=status)
@@ -2106,6 +2152,13 @@ subroutine TransShaveAndSend(PtrIn,PtrOut,request,doTrans,idxOut)
21062152
call mCFIO%regridder%regrid(Gin, Gout, rc=status)
21072153
VERIFY_(status)
21082154
end if
2155+
if (mcfio%vinterp .and. (lm .ne. 1) ) then
2156+
if (mcfio%ascending) then
2157+
where(mcfio%surfaceLayer<mcfio%unmodifiedLevs(k)) gout=MAPL_UNDEF
2158+
else
2159+
where(mcfio%surfaceLayer>mcfio%unmodifiedLevs(k)) gout=MAPL_UNDEF
2160+
endif
2161+
end if
21092162
else
21102163
ASSERT_( all(shape(gout)==shape(gin)) )
21112164
gout=gin
@@ -2166,6 +2219,15 @@ subroutine TransShaveAndSend(PtrIn,PtrOut,request,doTrans,idxOut)
21662219
call mCFIO%regridder%set_undef_value(MAPL_undef)
21672220
call mCFIO%regridder%regrid(uin, vin, uout, vout, rc=status)
21682221
VERIFY_(status)
2222+
if (mcfio%vinterp .and. (lm .ne. 1)) then
2223+
if (mcfio%ascending) then
2224+
where(mcfio%surfaceLayer<mcfio%unmodifiedLevs(k)) uout(:,:,1)=MAPL_UNDEF
2225+
where(mcfio%surfaceLayer<mcfio%unmodifiedLevs(k)) vout(:,:,1)=MAPL_UNDEF
2226+
else
2227+
where(mcfio%surfaceLayer>mcfio%unmodifiedLevs(k)) uout(:,:,1)=MAPL_UNDEF
2228+
where(mcfio%surfaceLayer>mcfio%unmodifiedLevs(k)) vout(:,:,1)=MAPL_UNDEF
2229+
end if
2230+
end if
21692231

21702232
deallocate(PtrIn(1)%ptr)
21712233
nullify(PtrIn(1)%ptr)

0 commit comments

Comments
 (0)