c23456789012345678901234567890123456789012345678901234567890123456789012


      SUBROUTINE new_sta 

c     ******************************************************************
c
c     This routine updates the state variables
c
c     ******************************************************************

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

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

c---- Local variables

      integer	i,j,k,kcomp




c     --------------------
c     New state variables 
c     --------------------

c---- Initialization

      kcomp = 0


c---- New densities

      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
           r(i,j,k) = x(kcomp)
         endif

      enddo
      enddo
      enddo


c---- New transport components U

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

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

      enddo
      enddo
      enddo


c---- New transport components V

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

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

      enddo
      enddo
      enddo


c---- New transport components W 

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

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

      enddo
      enddo
      enddo


c---- New tracer values 

      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
           p(i,j,k) = x(kcomp)
         endif

      enddo
      enddo
      enddo


c---- Test

      if (kcomp.ne.n_o) then
         write(*,*)
         write(*,*) 'Wrong update'
         write(*,*)
         stop 'STOP'
      endif




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

      return

      end

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

