Index: /branches/TAM_V3_0/NEMO/OPA_SRC/TAM/tamtrj.F90
===================================================================
--- /branches/TAM_V3_0/NEMO/OPA_SRC/TAM/tamtrj.F90	(revision 1946)
+++ /branches/TAM_V3_0/NEMO/OPA_SRC/TAM/tamtrj.F90	(revision 1946)
@@ -0,0 +1,183 @@
+MODULE tamtrj
+   !!======================================================================
+   !!                       ***  MODULE tamtrj  ***
+   !! Tangent and adjoint  trajectory interface: Write to file 
+   !!                                    the model state trajectory
+   !!======================================================================
+   !!----------------------------------------------------------------------
+   !!   tam_trj_ini  : init: read the namelist
+   !!   tam_trj_wri  : Write out the model state trajectory 
+   !!----------------------------------------------------------------------
+   !! * Modules used   
+   USE oce                ! Dynamics and active tracers defined in memory
+   USE sbc_oce            ! Ocean surface boundary conditions
+   USE zdf_oce            ! Vertical mixing variables
+#if defined key_zdfddm 
+   USE zdfddm, ONLY : &   ! Double diffusion mixing parameterization
+      & avs               ! Salinity vertical diffusivity coeff. at w-point
+#endif
+   USE ldftra_oce         ! Lateral tracer mixing coefficient defined in memory
+   USE ldfslp, ONLY : &   ! Slopes of neutral surfaces
+      & uslp, wslpi,  &   ! i_slope at U- and W-points
+      & vslp, wslpj       ! j-slope at V- and W-points
+   USE tradmp             ! Tracer damping
+   USE sol_oce, ONLY : &  ! Solver variables defined in memory
+      & gcx
+   USE in_out_manager, ONLY : &  ! I/O manager
+      & lwp,     &
+      & numout
+   USE daymod, ONLY : &
+      & ndastp
+   USE iom                 ! I/O module
+   USE zdfmxl, ONLY : &   ! mixed layer depth
+      & hmlp
+
+   IMPLICIT NONE
+
+   !! * Routine accessibility
+   PRIVATE
+   PUBLIC tam_trj_ini, &  !: Write out the background state
+      &   tam_trj_wri     !: Write out the background state
+
+   LOGICAL, PUBLIC :: & 
+      & ln_trjwri = .FALSE.   !: No output of the state trajectory fields
+
+   CHARACTER (LEN=40), PUBLIC, PARAMETER :: &
+      & c_asmtrj = 'tam_trajectory'                !: Filename for storing the 
+                                                   !: reference trajectory
+   INTEGER, PUBLIC :: &          
+      & nittrjfrq         !: Frequency of trajectory output for 4D-VAR
+
+CONTAINS
+   SUBROUTINE tam_trj_ini
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tam_trj_ini ***
+      !!
+      !! ** Purpose : initialize the model state trajectory 
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 10-01 (A. Vidard) 
+      !!-----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Modules used
+      NAMELIST/namtam/ nittrjfrq, ln_trjwri
+
+      ln_trjwri = .FALSE.
+      nittrjfrq = 1
+
+      REWIND ( numnam )
+      READ   ( numnam, namtam )
+
+      ! Control print
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'tam_trj_ini : Trajectory handling:'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '          Namelist namtam : set trajectory parameters'
+         WRITE(numout,*) '             Logical switch for writing out state trajectory         ', &
+            &            ' ln_trjwri = ', ln_trjwri
+         WRITE(numout,*) '             Frequency of trajectory output                          ', &
+            &            ' nittrjfrq = ', nittrjfrq
+      END IF
+   END SUBROUTINE tam_trj_ini
+   SUBROUTINE tam_trj_wri( kt )
+      !!-----------------------------------------------------------------------
+      !!
+      !!                  ***  ROUTINE tam_trj_wri ***
+      !!
+      !! ** Purpose : Write to file the model state trajectory 
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  :
+      !!                   
+      !! References : 
+      !!
+      !! History :
+      !!        ! 07-04 (A. Weaver) 
+      !!        ! 09-03 (F. Vigilant) Add hmlp (zdfmxl) for no tracer nmldp=2 
+      !!        ! 09-06 (F. Vigilant) special case when kt=nit000-1
+      !!        ! 09-07 (F. Vigilant) add computation of eiv at restart
+      !!        ! 10-01 (A. Vidard) asm_trj_wri->tam_trj_wri
+      !!-----------------------------------------------------------------------
+
+      !! * Arguments
+      INTEGER, INTENT( IN ) :: &
+         & kt                    ! Current time-step
+
+      !! * Local declarations
+      INTEGER :: &
+         & inum                  ! File unit number
+      INTEGER :: &
+         & it
+      CHARACTER (LEN=50) :: &
+         & cl_asmtrj
+      REAL(wp) :: &
+         & zdate            ! Date
+
+      !------------------------------------------------------------------------
+      ! Write a single file for each trajectory time step
+      !------------------------------------------------------------------------
+      IF ( ( MOD( kt - nit000 + 1, nittrjfrq ) == 0 ) .OR. &
+         & ( kt == nitend ) ) THEN
+         
+         it = kt - nit000 + 1
+
+         ! Define the output file        
+         WRITE(cl_asmtrj, FMT='(A,A,I5.5)' ) TRIM( c_asmtrj ), '_', it
+         cl_asmtrj = TRIM( cl_asmtrj )
+         CALL iom_open( cl_asmtrj, inum, ldwrt = .TRUE., kiolib = jprstlib)
+
+         ! Output trajectory fields
+         CALL iom_rstput( it, it, inum, 'emp'   , emp    )
+         CALL iom_rstput( it, it, inum, 'emps'  , emps   )
+         CALL iom_rstput( it, it, inum, 'un'    , un     )
+         CALL iom_rstput( it, it, inum, 'vn'    , vn     )
+         CALL iom_rstput( it, it, inum, 'tn'    , tn     )
+         CALL iom_rstput( it, it, inum, 'sn'    , sn     )
+         CALL iom_rstput( it, it, inum, 'avmu'  , avmu   )
+         CALL iom_rstput( it, it, inum, 'avmv'  , avmv   )
+         CALL iom_rstput( it, it, inum, 'avt'   , avt    )
+#if defined key_ldfslp
+         CALL iom_rstput( it, it, inum, 'uslp'  , uslp   )
+         CALL iom_rstput( it, it, inum, 'vslp'  , vslp   )
+         CALL iom_rstput( it, it, inum, 'wslpi' , wslpi  )
+         CALL iom_rstput( it, it, inum, 'wslpj' , wslpj  )
+#endif
+#if defined key_zdfddm
+         CALL iom_rstput( it, it, inum, 'avs'   , avs    )
+#endif
+	 IF ( kt == nit000 -1 ) THEN
+            ! ta, sa not available at restart
+            ! but need to ensure non-zero values due to subsequent interpolation
+            ! issue should be solved with next version of IOM (current 3.0) 
+            CALL iom_rstput( it, it, inum, 'ta'    , tn     )
+            CALL iom_rstput( it, it, inum, 'sa'    , sn     )
+         ELSE
+            CALL iom_rstput( it, it, inum, 'ta'    , ta     )
+            CALL iom_rstput( it, it, inum, 'sa'    , sa     )
+         ENDIF
+         CALL iom_rstput( it, it, inum, 'tb'    , tb     )
+         CALL iom_rstput( it, it, inum, 'sb'    , sb     )
+#if defined key_tradmp
+         CALL iom_rstput( it, it, inum, 'hmlp'  , hmlp   )
+#endif
+         CALL iom_rstput( it, it, inum, 'aeiu'  , aeiu   )
+         CALL iom_rstput( it, it, inum, 'aeiv'  , aeiv   )
+         CALL iom_rstput( it, it, inum, 'aeiw'  , aeiw   )
+
+         CALL iom_close( inum )
+         
+      ENDIF
+
+   END SUBROUTINE tam_trj_wri
+END MODULE tamtrj
