c23456789012345678901234567890123456789012345678901234567890123456789012


      SUBROUTINE xo_fill

c     ******************************************************************
c
c     This routine fills the a priori estimate of the state xo
c
c     ******************************************************************

c     -------------
c     Declarations
c     -------------

c     ''''''''''''''''''''''
      implicit none
      include 'commonvar.f'      
c     ''''''''''''''''''''''

c---- Local variables

      integer	i,j,k,kcomp




c     ------------------------------
c     A priori estimate of the state
c     ------------------------------

c---- Initialization

      kcomp = 0


c---- Density 

      do i=1,itot+1
      do j=1,jtot+1
      do k=1,ktot+1

         if (flag_r(i,j,k)) then
           kcomp     = kcomp + 1
           xo(kcomp) = r(i,j,k) 
         endif

      enddo
      enddo
      enddo


c---- Transport component U

      do i=1,itot+1	
      do j=1,jtot
      do k=1,ktot

         if (flag_U(i,j,k)) then
           kcomp     = kcomp + 1
           xo(kcomp) = U(i,j,k)
         endif

      enddo
      enddo
      enddo


c---- Transport component V

      do i=1,itot
      do j=1,jtot+1
      do k=1,ktot

         if (flag_V(i,j,k)) then
           kcomp     = kcomp + 1
           xo(kcomp) = V(i,j,k)
         endif

      enddo
      enddo
      enddo


c---- Transport component W

      do i=1  ,itot
      do j=1  ,jtot
      do k=1+1,ktot+1		! W(i,j,1) is NOT in state vector

         if (flag_W(i,j,k)) then
           kcomp     = kcomp + 1
           xo(kcomp) = W(i,j,k)
         endif

      enddo
      enddo
      enddo


c---- Tracer 

      do i=1,itot+1
      do j=1,jtot+1
      do k=1,ktot+1

         if (flag_p(i,j,k)) then
           kcomp     = kcomp + 1
           xo(kcomp) = p(i,j,k) 
         endif

      enddo
      enddo
      enddo


c---- Test the order of matrix

      if (kcomp.ne.n_o) then
        write(*,*)
        write(*,*) 'Co and xo are not conformable'
        write(*,*)
        stop 'STOP'
      endif




c     -------------------
c     End of the routine
c     -------------------

      return

      end

c     ******************************************************************

