subroutine ESMFL_StateFreePointers(STATE, RC)
type(ESMF_State), intent(INOUT) :: STATE
integer, optional, intent( OUT) :: RC
integer :: STATUS
type(ESMF_Array) :: ARRAY
type(ESMF_Field) :: FIELD
integer :: RANK
integer :: I
integer :: ITEMCOUNT
real, pointer :: PTR1(:)
real, pointer :: PTR2(:,:)
real, pointer :: PTR3(:,:,:)
real, pointer :: PTR4(:,:,:,:)
logical :: NEEDED
character (len=ESMF_MAXSTR), pointer :: ITEMNAMELIST(:)
type(ESMF_StateItem_Flag) , pointer :: ITEMTYPELIST(:)
type (ESMF_LocalArray), target :: larrayList(1)
type (ESMF_LocalArray), pointer :: larray
integer :: localDeCount
logical :: isPresent
! Get information from state
!---------------------------
call ESMF_StateGet(STATE,ITEMCOUNT=ITEMCOUNT,RC=STATUS)
_VERIFY(STATUS)
if(ITEMCOUNT==0) then
_RETURN(ESMF_SUCCESS)
end if
allocate(ITEMNAMELIST(ITEMCOUNT),STAT=STATUS)
_VERIFY(STATUS)
allocate(ITEMTYPELIST(ITEMCOUNT),STAT=STATUS)
_VERIFY(STATUS)
call ESMF_StateGet(STATE,ITEMNAMELIST=ITEMNAMELIST,ITEMTYPELIST=ITEMTYPELIST,RC=STATUS)
_VERIFY(STATUS)
do I=1,ITEMCOUNT
if(ITEMTYPELIST(I)==ESMF_STATEITEM_FIELD) then
call ESMF_StateGet(STATE, trim(ITEMNAMELIST(I)), FIELD, RC=STATUS)
_VERIFY(STATUS)
call ESMF_AttributeGet (FIELD, NAME="Needed", isPresent=isPresent, RC=STATUS)
_VERIFY(STATUS)
if(isPresent) then
call ESMF_AttributeGet (FIELD, NAME="Needed",VALUE=NEEDED, RC=STATUS)
_VERIFY(STATUS)
else
NEEDED = .false.
end if
if( NEEDED .eqv. .false. ) then
call ESMF_FieldGet(FIELD, Array=ARRAY, RC=STATUS)
_VERIFY(STATUS)
call ESMF_ArrayGet (ARRAY, rank=RANK, RC=STATUS)
_VERIFY(STATUS)
call ESMF_ArrayGet(array, localDeCount=localDeCount, rc=status)
_VERIFY(STATUS)
_ASSERT(localDeCount == 1, 'MAPL does not currently support multiple DEs per PET')
call ESMF_ArrayGet(array, localarrayList=larrayList, rc=status)
_VERIFY(STATUS)
larray => lArrayList(1) ! alias
select case (rank)
case (1)
call ESMF_LocalArrayGet(larray, PTR1, RC=status)
_VERIFY(STATUS)
if(associated(PTR1)) deallocate(PTR1)
case (2)
call ESMF_LocalArrayGet(larray, PTR2, RC=status)
_VERIFY(STATUS)
if(associated(PTR2)) deallocate(PTR2)
case (3)
call ESMF_LocalArrayGet(larray, PTR3, RC=status)
_VERIFY(STATUS)
if(associated(PTR3)) deallocate(PTR3)
case (4)
call ESMF_LocalArrayGet(larray, PTR4, RC=status)
_VERIFY(STATUS)
if(associated(PTR4)) deallocate(PTR4)
end select
end if
end if
end do
deallocate(itemNameList,STAT=STATUS)
_VERIFY(STATUS)
deallocate(itemtypeList,STAT=STATUS)
_VERIFY(STATUS)
_RETURN(ESMF_SUCCESS)
end subroutine ESMFL_StateFreePointers