ESMF_XGridSerialize Subroutine

public subroutine ESMF_XGridSerialize(xgrid, buffer, length, offset, attreconflag, inquireflag, rc)

Arguments

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

Source Code

      subroutine ESMF_XGridSerialize(xgrid, buffer, length, offset, &
                                    attreconflag, inquireflag, rc) 
!
! !ARGUMENTS:
      type(ESMF_XGrid), intent(in)                      :: xgrid 
      character, pointer, dimension(:)                  :: buffer
      integer, intent(inout)                            :: length
      integer, intent(inout)                            :: offset
      type(ESMF_AttReconcileFlag), intent(in), optional :: attreconflag
      type(ESMF_InquireFlag), intent(in), optional      :: inquireflag
      integer, intent(out), optional                    :: rc 
!
! !DESCRIPTION:
!      Takes an {\tt ESMF\_XGrid} object and adds all the information needed
!      to save the information to a stream or recreate the object based on this
!      information.   Expected to be used by {\tt ESMF\_StateReconcile()}.
!
!     The arguments are:
!     \begin{description}
!     \item [xgrid]
!           {\tt ESMF\_XGrid} 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[{[attreconflag]}]
!           Flag to tell if Attribute serialization is to be done
!     \item[{[inquireflag]}]
!           Flag to tell if serialization is to be done (ESMF_NOINQUIRE)
!           or if this is simply a size inquiry (ESMF_INQUIREONLY)
!     \item [{[rc]}]
!           Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     \end{description}
!
!EOPI

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

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

      ! check variables
      ESMF_INIT_CHECK_DEEP(ESMF_XGridGetInit,xgrid,rc)

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

      if (present (inquireflag)) then
        linquireflag = inquireflag
      else
        linquireflag = ESMF_NOINQUIRE
      end if

      ! shortcut to internals
      fp => xgrid%xgtypep

      call ESMF_BaseSerialize(fp%base, buffer, offset, &
                                 lattreconflag, linquireflag, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return

      ! set up the association status array and other meta-data
      s = 0
      ngridA = 0
      ngridB = 0
      if(associated(fp%distgridA)) s(XG_S_DGA) = 1
      if(associated(fp%distgridB)) s(XG_S_DGB) = 1
      if(associated(fp%sideA)) then
        s(XG_S_GA) = 1
        ngridA = size(fp%sideA,1)
      endif
      if(associated(fp%sideB)) then
        s(XG_S_GB) = 1
        ngridB = size(fp%sideB,1)
      endif

      ! call into the C api first to serialize this status array and other meta-data
      ! this ensures consistency when deserialization
      flag = 0
      if(fp%storeOverlay) flag = 1
      call c_ESMC_XGridSerialize(s, ngridA, ngridB, fp%online, flag, &
                                 buffer, length, offset, linquireflag, localrc)
      if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return

      ! serialize the balanced distgrid
      call c_ESMC_DistGridSerialize(fp%distgridM, buffer, length, offset, &
                                   linquireflag, localrc)
      if (ESMF_LogFoundError(localrc, &
                               ESMF_ERR_PASSTHRU, &
                               ESMF_CONTEXT, rcToReturn=rc)) return

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

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

      ! serialize the Grids
      if(associated(fp%sideA)) then
          ngridA = size(fp%sideA,1)
          do i = 1, ngridA
            call ESMF_XGridGeomBaseSerialize(fp%sideA(i), buffer=buffer, &
                         length=length, offset=offset, &
                         attreconflag=lattreconflag, inquireflag=linquireflag, &
                         rc=localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%sideB)) then
          ngridB = size(fp%sideB,1)
          do i = 1, ngridB
            call ESMF_XGridGeomBaseSerialize(fp%sideB(i), buffer=buffer, &
                         length=length, offset=offset, &
                         attreconflag=lattreconflag, inquireflag=linquireflag, &
                         rc=localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      ! serialize the Fracs
      if(associated(fp%fracA2X)) then
          ngridA = size(fp%fracA2X,1)
          do i = 1, ngridA
            call c_esmc_arrayserialize (fp%fracA2X(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%fracB2X)) then
          ngridB = size(fp%fracB2X,1)
          do i = 1, ngridB
            call c_esmc_arrayserialize (fp%fracB2X(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      ! serialize the Fracs
      if(associated(fp%fracX2A)) then
          ngridA = size(fp%fracX2A,1)
          do i = 1, ngridA
            call c_esmc_arrayserialize (fp%fracX2A(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%fracX2B)) then
          ngridB = size(fp%fracX2B,1)
          do i = 1, ngridB
            call c_esmc_arrayserialize (fp%fracX2B(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(fp%online == 1) then
        call c_esmc_arrayserialize (fp%fracX, buffer, length, offset,  &
            lattreconflag, linquireflag, localrc)

        if (ESMF_LogFoundError(localrc, &
                                 ESMF_ERR_PASSTHRU, &
                                 ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      ! serialize the Frac2s
      if(associated(fp%frac2A)) then
          ngridA = size(fp%frac2A,1)
          do i = 1, ngridA
            call c_esmc_arrayserialize (fp%frac2A(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(associated(fp%frac2B)) then
          ngridB = size(fp%frac2B,1)
          do i = 1, ngridB
            call c_esmc_arrayserialize (fp%frac2B(i), buffer, length, offset,  &
                lattreconflag, linquireflag, localrc)
            if (ESMF_LogFoundError(localrc, &
                                     ESMF_ERR_PASSTHRU, &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
          enddo
      endif

      if(fp%storeOverlay) then
        call ESMF_MeshSerialize(mesh=fp%mesh, buffer=buffer, &
           length=length, offset=offset, &
           inquireflag=linquireflag, &
           rc=localrc)
        if (ESMF_LogFoundError(localrc, &
           ESMF_ERR_PASSTHRU, &
           ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      if  (present(rc)) rc = ESMF_SUCCESS

      end subroutine ESMF_XGridSerialize