serialize_bundle Subroutine

subroutine serialize_bundle(bundle, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_FieldBundle) :: bundle
integer, optional :: rc

Source Code

    subroutine serialize_bundle(bundle, rc)
        ! inout variables
        type(ESMF_FieldBundle)                      :: bundle
        integer, optional                           :: rc

        ! local variables
        type(ESMF_FieldBundle)                      :: bundle1

        character, pointer                          :: buffer(:)
        integer                                     :: buff_size, offset, localrc

        localrc = ESMF_SUCCESS
        rc = ESMF_SUCCESS

        ! Inquire for buffer size
        buff_size = 1
        offset = 0
        allocate (buffer(buff_size))
        call ESMF_FieldBundleSerialize(bundle, buffer, buff_size, offset, &
            inquireflag=ESMF_INQUIREONLY, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        deallocate (buffer)


        ! call serialize and deserialize and verify again
        buff_size = offset
        print *, 'ESMF_FieldBundleCrGetUTest: computed serialization buffer size =', buff_size
        allocate (buffer(buff_size))
        offset = 0
        call ESMF_FieldBundleSerialize(bundle, buffer, buff_size, offset, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        offset = 0

        bundle1 = ESMF_FieldBundleDeserialize(buffer, offset, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        call ESMF_FieldBundleValidate(bundle1, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        call ESMF_FieldBundleDestroy(bundle1, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        deallocate(buffer)

        if(present(rc)) rc = ESMF_SUCCESS
    end subroutine serialize_bundle