@@ -213,6 +213,7 @@ module MAPL_CFIOMod
213
213
integer , pointer :: Krank(:)= >null ()
214
214
integer :: rootRank = 0
215
215
real , pointer :: levs(:)= >null ()
216
+ real , pointer :: unmodifiedLevs(:)= >null ()
216
217
type (MAPL_CommRequest), &
217
218
pointer :: reqs(:)= >null ()
218
219
class (AbstractRegridder), pointer :: regridder = > null ()
@@ -230,6 +231,8 @@ module MAPL_CFIOMod
230
231
integer :: collection_id
231
232
integer :: fraction
232
233
integer :: regrid_type
234
+ real , pointer :: surfaceLayer(:,:) = > null ()
235
+ logical :: ascending
233
236
end type MAPL_CFIO
234
237
! EOC
235
238
! EOP
@@ -1145,9 +1148,10 @@ subroutine MAPL_CFIOCreateFromBundle ( MCFIO, NAME, CLOCK, BUNDLE, OFFSET,
1145
1148
LEV = (/ (L, L= 1 ,LM)/ )
1146
1149
end if
1147
1150
1148
- allocate (mCFIO% levs(size (lev)), stat= status)
1151
+ allocate (mCFIO% levs(size (lev)),mcfio % unmodifiedLevs( size (lev)), stat= status)
1149
1152
VERIFY_(STATUS)
1150
1153
mCFIO% levs = lev
1154
+ mCFIO% unmodifiedLevs = lev
1151
1155
if (HAVE_ungrd) then
1152
1156
call ESMF_CFIOGridSet(cfiogrid, levUnit= ungridded_unit, RC= STATUS)
1153
1157
VERIFY_(STATUS)
@@ -1164,6 +1168,7 @@ subroutine MAPL_CFIOCreateFromBundle ( MCFIO, NAME, CLOCK, BUNDLE, OFFSET,
1164
1168
else
1165
1169
mCFIO% levs = lev* MCFIO% vscale
1166
1170
end if
1171
+ mCFIO% unmodifiedLevs= mCFIO% unmodifiedLevs* MCFIO% vscale
1167
1172
1168
1173
if ( trim (vunits).eq. " " ) then
1169
1174
call ESMF_AttributeGet(FIELD, NAME= " UNITS" , VALUE= units, RC= STATUS)
@@ -1735,9 +1740,10 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
1735
1740
real , target , allocatable :: Ple3d(:,:,:)
1736
1741
real , allocatable :: Pl3d(:,:,:)
1737
1742
real , allocatable :: Ptrx(:,:,:)
1738
- real , pointer :: layer(:,:)
1743
+ real , pointer :: layer(:,:),ps0(:,:)
1739
1744
logical :: PrePost_
1740
-
1745
+ integer :: globalcount(3 )
1746
+ type (ESMF_VM) :: vm
1741
1747
1742
1748
! ---
1743
1749
@@ -1763,6 +1769,19 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
1763
1769
allocate ( LAYER(size (Ptr3,1 ),size (Ptr3,2 ) ), stat= status)
1764
1770
VERIFY_(STATUS)
1765
1771
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
+
1766
1785
! The Ptr3 interpolating variable is a zero-based (0-LM) edge variable
1767
1786
!- --------------------------------------------------------------------
1768
1787
if (lbound (PTR3,3 )==0 ) then
@@ -1781,6 +1800,11 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
1781
1800
ple3D = Ptr3
1782
1801
pl3D = ( 0.5 * (Ptr3(:,:,1 :)+ Ptr3(:,:,0 :ubound (Ptr3,3 )- 1 )) )
1783
1802
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
1784
1808
1785
1809
else
1786
1810
@@ -1808,9 +1832,31 @@ subroutine MAPL_CFIOWriteBundlePost( MCFIO, PrePost, RC )
1808
1832
pl3D = ( 0.5 * (Ptrx(:,:,1 :)+ Ptrx(:,:,0 :ubound (Ptrx,3 )- 1 )) )
1809
1833
end if
1810
1834
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
1811
1841
deallocate (Ptrx)
1812
1842
end if
1813
1843
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
+
1814
1860
end if
1815
1861
1816
1862
call MAPL_CFIOSetVectorPairs(mCFIO,rc= status)
@@ -2106,6 +2152,13 @@ subroutine TransShaveAndSend(PtrIn,PtrOut,request,doTrans,idxOut)
2106
2152
call mCFIO% regridder% regrid(Gin, Gout, rc= status)
2107
2153
VERIFY_(status)
2108
2154
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
2109
2162
else
2110
2163
ASSERT_( all (shape (gout)==shape (gin)) )
2111
2164
gout= gin
@@ -2166,6 +2219,15 @@ subroutine TransShaveAndSend(PtrIn,PtrOut,request,doTrans,idxOut)
2166
2219
call mCFIO% regridder% set_undef_value(MAPL_undef)
2167
2220
call mCFIO% regridder% regrid(uin, vin, uout, vout, rc= status)
2168
2221
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
2169
2231
2170
2232
deallocate (PtrIn(1 )% ptr)
2171
2233
nullify(PtrIn(1 )% ptr)
0 commit comments