c***********************************************************************
c***********************************************************************
      subroutine outputm2(iter,kd,seckd,delt,nn,nnv,ne,x,y,in,hdown,   
     & zeta,ubar,vbar,z,u,v,zetaold,DomegaDxi,DomegaDrho,lrvs,nr,
     & nsteps,ntbc,casco_iter)

      include 'CASCO.DIM'

c fixed global variables
      integer iter
      integer kd
      real    seckd
      real    delt
      integer nn,nnv,ne
      real    x(nndim),y(nndim),hdown(nndim)
      integer in(3,nedim)
      real    zeta(nndim),ubar(nndim),vbar(nndim)
      real    z(nndim,nnvdim),u(nndim,nnvdim),v(nndim,nnvdim)
      real    zetaold(nndim)
      integer lrvs(nndim),nr
      real    DomegaDxi(nrdim,nstepdim)
      real    DomegaDrho(nrdim,ntbcdim)
      integer nsteps, ntbc
      integer casco_iter
c-----------------------------------------------------------------------
C Output of the adjoint variables. 
c this user subroutine is supplied to act as an interface for the
c   user to output the 2-d and 3-d results at a particular time in the
c   simulation.
c
c index range:  i=1,nn, j=1,nnv, k=1,ne, l=1,nev
c
c   nn - number of horizontal nodes
c   ne - number of horizontal elements
c   nnv - number of vertical nodes
c   nev - number of vertical elements (nev=nnv-1)
c
c timing parameters:
c
c   kd,seckd - gregorian calendar day and seconds since the beginning
c     of that calendar day.
c   iter - iteration number for the current time step
c   delt - time step size in seconds
c 
c constant information regarding the horizontal mesh
c
c   x(i),y(i) - horizontal cartesian nodal coordinates
c   hdown(i) - horizintal nodal bathymetry
c   in(i,k) - horizontal triangular element incidence list
c
c the following arrays contain the 2-d and 3-d solution at the end of
c   each iteration, at the time indicated by kd and seckd:
c
c   zeta(i) -  free surface elevation
c   ubar(i),vbar(i) - vertically averaged velocity
c   z(i,j) - nodal coordinate locations in 3-d
c   u(i,j),v(i,j) - nodal values of the x and y components
c     of velocity.
c
c the following arrays contain the 2-d and 3-d solution at one time
c   step prior to the end of the simulation.  they are particularly 
c   useful in the construction of ".icq4" hot-start files:
c
c   zetaold(i) - free surface elevation
c
c z and j are positive upward:
c          bottom:  z(i,1)=-hdown(i); j=1
c          surface: z(i,nnv)= 0  
c
c
c this subroutine is called at the beginning of the simulation 
c   (with iter=0) for initialization purposes, after each time step
c   (with iter>0) to facilitate any recording of results desired by the
c   user and finally at the successful completion of the simulation
c   (with iter set to -1) to facilitate any remaining post-processing
c   or recording.
c-----------------------------------------------------------------------
c================beginning-of-user-specified-instructions===============
c
c array assignments and save parameters for subroutine decompose

c
c echo the iteration number to standard out
c       return  
c     write(*,*)'output: casco_iter,iter, kd, seckd',
c    &                   casco_iter,iter,kd,seckd
c      write(*,*)iter
c

       call  ts1_moody_write(casco_iter,kd,seckd,iter,delt,nn,
     $                       zeta,ubar,vbar)

c      call Domega1_write(casco_iter,kd,seckd,iter,delt,DomegaDxi,
c    $                    lrvs,nr,nsteps) 

c       if(iter.eq.-1) then 
c	  write(*,*)'Outputm2: ntbc ', ntbc
c          call Domega2_write(casco_iter,DomegaDrho,lrvs,nr,ntbc) 
c      endif

c
c end of routine
c
      return
      end
