recursive subroutine MAPL_ExportStateGet(export, name, result, rc)
type (ESMF_State), intent(IN ) :: export(:)
character(len=*), intent(IN ) :: name
type (ESMF_State), intent( OUT) :: result
integer, intent( OUT) :: rc
character(len=ESMF_MAXSTR), parameter :: IAm="MAPL_ExportStateGet"
integer :: status
integer :: n, i, ni, k, j
logical :: have_ens
character(len=ESMF_MAXSTR) :: sname
type (ESMF_StateItem_Flag), pointer :: ITEMTYPES(:)
character(len=ESMF_MAXSTR ), pointer :: ITEMNAMES(:)
type (ESMF_State), pointer :: exptmp(:)
n = size(export)
have_ens = index(name,":") /= 0
do i = 1, n
call ESMF_StateGet(export(i), name=sname, itemcount = ni, rc=status)
_VERIFY(status)
if (have_ens) then
if (sname == trim(name) // '_Exports') then
result = export(i)
_RETURN(ESMF_SUCCESS)
end if
else
if (sname(index(sname,":")+1:) == trim(name) // '_Exports') then
result = export(i)
_RETURN(ESMF_SUCCESS)
end if
end if
allocate(itemtypes(ni), itemnames(ni), stat=status)
_VERIFY(status)
call ESMF_StateGet(export(i), ITEMNAMELIST=ITEMNAMES,ITEMTYPELIST=ITEMTYPES,RC=status)
_VERIFY(status)
j = 0
do k = 1, ni
if (itemtypes(k) == ESMF_StateItem_State) then
j = j+1
end if
end do
allocate(exptmp(j), stat=status)
_VERIFY(status)
j = 0
do k = 1, ni
if (itemtypes(k) == ESMF_StateItem_State) then
j = j+1
call ESMF_StateGet(export(i), itemnames(k), exptmp(j) , rc=status)
_VERIFY(status)
end if
end do
call MAPL_ExportStateGet(exptmp, name, result, rc=status)
deallocate(exptmp)
deallocate(itemtypes, itemnames)
if (status == ESMF_SUCCESS) then
_RETURN(ESMF_SUCCESS)
end if
end do
rc = ESMF_FAILURE
return
end subroutine MAPL_ExportStateGet