subroutine MAPL_CFIOReadBundleWait(MCFIO,rc)
type(MAPL_CFIO ), intent(INOUT) :: MCFIO
integer, optional, intent( OUT) :: RC
integer :: nn,k,l
logical :: myGlobal
type(ESMF_Field) :: field
real, pointer :: ptr3d(:,:,:) => null()
integer :: status
nn = 0
VARS: do L=1,size(MCFIO%VarDims)
RANK: if (MCFIO%VarDims(L)==2) then
nn=nn+1
myGlobal = (mcfio%mype == mcfio%krank(nn))
call MAPL_CollectiveWait(mcfio%reqs(nn),rc=status)
_VERIFY(STATUS)
if (myGlobal) then
deallocate(mcfio%buffer(nn)%ptr)
end if
else if (MCFIO%VarDims(L)==3) then
do k = 1,MCFIO%lm
nn=nn+1
myGlobal = (mcfio%mype == mcfio%krank(nn))
call MAPL_CollectiveWait(mcfio%reqs(nn),rc=status)
_VERIFY(STATUS)
if (myGlobal) then
deallocate(mcfio%buffer(nn)%ptr)
!ALT these two have been cleaned earlier
! deallocate(mcfio%reqs(nn)%read_array)
! nullify(mcfio%reqs(nn)%read_array)
end if
end do
if (mcfio%gsiMode) then
call ESMF_FieldBundleGet(MCFIO%BUNDLE, trim(mcfio%varname(L)), field=FIELD, RC=STATUS)
_VERIFY(STATUS)
call ESMF_FieldGet(field,0,farrayptr=ptr3d,rc=status)
call SwapV_(ptr3d)
end if
end if RANK
end do VARS
_RETURN(ESMF_SUCCESS)
contains
subroutine SwapV_(fld)
implicit none
real,intent(inout) :: fld(:,:,:)
real,allocatable :: work(:,:,:)
integer im, jm, km
im = size(fld,1)
jm = size(fld,2)
km = size(fld,3)
allocate (work(im,jm,km))
work = fld
fld(:,:,km:1:-1) = work(:,:,1:km:+1)
deallocate (work)
end subroutine SwapV_
end subroutine MAPL_CFIOReadBundleWait