ESMF_XGridDeserialize Function

public function ESMF_XGridDeserialize(buffer, offset, attreconflag, rc)

Arguments

Type IntentOptional Attributes Name
character(len=1), pointer, dimension(:) :: buffer
integer, intent(inout) :: offset
type(ESMF_AttReconcileFlag), optional :: attreconflag
integer, intent(out), optional :: rc

Return Value type(ESMF_XGrid)


Source Code

      function ESMF_XGridDeserialize(buffer, offset, &
                                    attreconflag, rc) 
!
! !RETURN VALUE:
      type(ESMF_XGrid)                      :: ESMF_XGridDeserialize   
!
! !ARGUMENTS:
      character, pointer, dimension(:)      :: buffer
      integer, intent(inout)                :: offset
      type(ESMF_AttReconcileFlag), optional :: attreconflag
      integer, intent(out), optional        :: rc 
!
! !DESCRIPTION:
!      Takes a byte-stream buffer and reads the information needed to
!      recreate a XGrid object.  Recursively calls the deserialize routines
!      needed to recreate the subobjects.
!      Expected to be used by {\tt ESMF\_StateReconcile()} and
!      by {\tt ESMF\_XGridWrite()} and {\tt ESMF\_XGridRead()}.
!
!     The arguments are:
!     \begin{description}
!     \item [buffer]
!           Data buffer which holds the serialized information.
!     \item [offset]
!           Current read offset in the current buffer.  This will be
!           updated by this routine and return pointing to the next
!           unread byte in the buffer.
!     \item[{[attreconflag]}]
!           Flag to tell if Attribute serialization is to be done
!     \item [{[rc]}]
!           Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     \end{description}
!
!EOPI

      integer :: localrc, ngridA, ngridB, i, step
      type(ESMF_XGridType), pointer :: fp    ! xgrid type
      integer staggerloc
      type(ESMF_AttReconcileFlag) :: lattreconflag
      integer :: s(4)               ! association status variables
      integer :: flag

      ! Initialize
      localrc = ESMF_RC_NOT_IMPL
      if  (present(rc)) rc = ESMF_RC_NOT_IMPL

      ! deal with optional attreconflag
      if (present(attreconflag)) then
        lattreconflag = attreconflag
      else
        lattreconflag = ESMF_ATTRECONCILE_OFF
      endif

      ! In case of error, make sure this is invalid.
      nullify(ESMF_XGridDeserialize%xgtypep)

      ! Shortcut to internals
      allocate(fp, stat=localrc)
      if (ESMF_LogFoundAllocError(localrc, &
                                     msg="space for new XGrid object", &
                                     ESMF_CONTEXT, rcToReturn=rc)) return

      call ESMF_XGridInitialize(fp, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return

      ! Deserialize Base
      fp%base = ESMF_BaseDeserialize(buffer, offset, lattreconflag, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return
                                 
      call ESMF_BaseSetInitCreated(fp%base, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return

      ! call into the C api to deserialize this status array and other meta-data
      flag = 0
      call c_ESMC_XGridDeserialize(s, ngridA, ngridB, fp%online, flag, &
                                 buffer, offset, localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return

      ! Deserialize the balanced distgrid
      call C_ESMC_DistGridDeserialize(fp%distgridM, buffer, offset, &
                                   localrc)
      if (ESMF_LogFoundError(localrc, &
                               ESMF_ERR_PASSTHRU, &
                               ESMF_CONTEXT, rcToReturn=rc)) return

      ! set up memory based on the association status array and other meta-data
      if(s(XG_S_DGA) == 1) allocate(fp%distgridA(ngridA))
      if(s(XG_S_DGB) == 1) allocate(fp%distgridB(ngridB))
      if(s(XG_S_GA) == 1) allocate(fp%sideA(ngridA))
      if(s(XG_S_GB) == 1) allocate(fp%sideB(ngridB))
      if(fp%online == 1) then
        allocate(fp%fracA2X(ngridA))
        allocate(fp%fracB2X(ngridB))
        allocate(fp%fracX2A(ngridA))
        allocate(fp%fracX2B(ngridB))
        allocate(fp%frac2A(ngridA))
        allocate(fp%frac2B(ngridB))
      endif

      ! Deserialize the rest of the XGrid members
      if(associated(fp%distgridA)) then
          do i = 1, ngridA
            call C_ESMC_DistGridDeserialize(fp%distgridA(i), buffer, offset, &
                                     localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%distgridB)) then
          do i = 1, ngridB
            call C_ESMC_DistGridDeserialize(fp%distgridB(i), buffer, offset, &
                                     localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      ! Deserialize the Grids
      if(associated(fp%sideA)) then
          do i = 1, ngridA
            fp%sideA(i) = ESMF_XGridGeomBaseDeserialize(buffer=buffer, offset=offset, &
                                     rc=localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%sideB)) then
          do i = 1, ngridB
            fp%sideB(i) = ESMF_XGridGeomBaseDeserialize(buffer=buffer, offset=offset, &
                                     rc=localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      ! Deserialize the Frac Arrays
      if(associated(fp%fracA2X)) then
          do i = 1, ngridA
            call c_ESMC_ArrayDeserialize(fp%fracA2X(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%fracB2X)) then
          do i = 1, ngridB
            call c_ESMC_ArrayDeserialize(fp%fracB2X(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif
      if(associated(fp%fracX2A)) then
          do i = 1, ngridA
            call c_ESMC_ArrayDeserialize(fp%fracX2A(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif
      if(associated(fp%fracX2B)) then
          do i = 1, ngridB
            call c_ESMC_ArrayDeserialize(fp%fracX2B(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif
      if(fp%online == 1) then
          call c_ESMC_ArrayDeserialize(fp%fracX, buffer, offset, &
              lattreconflag, localrc)
          if (ESMF_LogFoundError(localrc, &
                                   ESMF_ERR_PASSTHRU, &
                                   ESMF_CONTEXT, rcToReturn=rc)) return
      endif
      if(associated(fp%frac2A)) then
          do i = 1, ngridA
            call c_ESMC_ArrayDeserialize(fp%frac2A(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif
      if(associated(fp%frac2B)) then
          do i = 1, ngridB
            call c_ESMC_ArrayDeserialize(fp%frac2B(i), buffer, offset, &
                lattreconflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(flag == 1) then
        fp%storeOverlay = .true.
        fp%mesh = ESMF_MeshDeserialize(buffer=buffer, offset=offset, &
                                 rc=localrc)
        if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      fp%is_proxy = .true.
      ESMF_XGridDeserialize%xgtypep => fp
      
      ! Add copy of this object into ESMF garbage collection table
      call c_ESMC_VMAddFObject(ESMF_XGridDeserialize, ESMF_ID_XGRID%objectID)
      
      ESMF_INIT_SET_CREATED(ESMF_XGridDeserialize)

      if  (present(rc)) rc = ESMF_SUCCESS

      end function ESMF_XGridDeserialize