subroutine ESMF_LocStreamSerialize(locstream, buffer, length, offset, inquireflag, rc)
!
! !ARGUMENTS:
type(ESMF_LocStream), intent(inout) :: locstream
character, pointer, dimension(:) :: buffer
integer, intent(inout) :: length
integer, intent(inout) :: offset
type(ESMF_InquireFlag), intent(in), optional :: inquireflag
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Takes an {\tt ESMF\_Grid} object and adds all the information needed
! to recreate the object based on this information.
! Expected to be used by {\tt ESMF\_StateReconcile()}.
!
! The arguments are:
! \begin{description}
! \item [locstream]
! {\tt ESMF\_LocStream} object to be serialized.
! \item [buffer]
! Data buffer which will hold the serialized information.
! \item [length]
! Current length of buffer, in bytes. If the serialization
! process needs more space it will allocate it and update
! this length.
! \item [offset]
! Current write offset in the current buffer. This will be
! updated by this routine and return pointing to the next
! available byte in the buffer.
! \item [inquireflag]
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
type(ESMF_LocStreamType),pointer :: lstypep
integer :: i,localrc
type(ESMF_AttReconcileFlag) :: attreconflag
type(ESMF_InquireFlag) :: linquireflag
! Initialize
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! check variables
ESMF_INIT_CHECK_DEEP(ESMF_LocStreamGetInit,locstream,rc)
if (present (inquireflag)) then
linquireflag = inquireflag
else
linquireflag = ESMF_NOINQUIRE
end if
! Get internal pointer to locstream type
lstypep => locstream%lstypep
! Serialize Base
attreconflag = ESMF_ATTRECONCILE_OFF
call c_ESMC_BaseSerialize(lstypep%base, buffer, length, offset, &
attreconflag, linquireflag, localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Serialize Distgrid
call c_ESMC_DistgridSerialize(lstypep%distgrid, buffer, length, offset, &
linquireflag, localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Serialize other locstream items
call c_ESMC_LocStreamSerialize(lstypep%indexflag, &
lstypep%keyCount, &
lstypep%coordSys, &
buffer, length, offset, linquireflag, localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Serialize locstream key info
do i=1,lstypep%keyCount
! Serialize key info
call c_ESMC_LocStreamKeySerialize(&
len_trim(lstypep%keyNames(i)), lstypep%keyNames(i), &
len_trim(lstypep%keyUnits(i)), lstypep%keyUnits(i), &
len_trim(lstypep%keyLongNames(i)), lstypep%keyLongNames(i), &
buffer, length, offset, linquireflag, localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Serialize key Array
call c_ESMC_ArraySerialize(lstypep%keys(i), buffer, length, offset, &
attreconflag, linquireflag, localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
enddo
! return success
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_LocStreamSerialize