Index: branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 5075)
+++ branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 5980)
@@ -46,4 +46,6 @@
    USE iom
    USE ioipsl
+   USE dynspg_oce, ONLY: un_adv, vn_adv ! barotropic velocities     
+
 #if defined key_lim2
    USE limwri_2 
@@ -78,5 +80,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id $
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -125,4 +127,5 @@
       !!
       INTEGER                      ::   ji, jj, jk              ! dummy loop indices
+      INTEGER                      ::   jkbot                   !
       REAL(wp)                     ::   zztmp, zztmpx, zztmpy   ! 
       !!
@@ -142,85 +145,104 @@
       ENDIF
 
-      IF( lk_vvl ) THEN
-         z3d(:,:,:) = tsn(:,:,:,jp_tem) * fse3t_n(:,:,:)
-         CALL iom_put( "toce" , z3d                        )   ! heat content
+      IF( .NOT.lk_vvl ) THEN
+         CALL iom_put( "e3t" , fse3t_n(:,:,:) )
+         CALL iom_put( "e3u" , fse3u_n(:,:,:) )
+         CALL iom_put( "e3v" , fse3v_n(:,:,:) )
+         CALL iom_put( "e3w" , fse3w_n(:,:,:) )
+      ENDIF
+
+      CALL iom_put( "ssh" , sshn )                 ! sea surface height
+      if( iom_use('ssh2') )   CALL iom_put( "ssh2", sshn(:,:) * sshn(:,:) )   ! square of sea surface height
+      
+      CALL iom_put( "toce", tsn(:,:,:,jp_tem) )    ! 3D temperature
+      CALL iom_put(  "sst", tsn(:,:,1,jp_tem) )    ! surface temperature
+      IF ( iom_use("sbt") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_tem) * fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO  
-         CALL iom_put( "sst"  , z2d(:,:)                 )   ! sea surface heat content      
+               jkbot = mbkt(ji,jj)
+               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_tem)
+            END DO
+         END DO
+         CALL iom_put( "sbt", z2d )                ! bottom temperature
+      ENDIF
+      
+      CALL iom_put( "soce", tsn(:,:,:,jp_sal) )    ! 3D salinity
+      CALL iom_put(  "sss", tsn(:,:,1,jp_sal) )    ! surface salinity
+      IF ( iom_use("sbs") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_tem)**2 * fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO  
-         CALL iom_put( "sst2" , z2d(:,:)      )   ! sea surface content of squared temperature
-         z3d(:,:,:) = tsn(:,:,:,jp_sal) * fse3t_n(:,:,:)            
-         CALL iom_put( "soce" , z3d                        )   ! salinity content
+               jkbot = mbkt(ji,jj)
+               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_sal)
+            END DO
+         END DO
+         CALL iom_put( "sbs", z2d )                ! bottom salinity
+      ENDIF
+
+      IF ( iom_use("taubot") ) THEN                ! bottom stress
+         z2d(:,:) = 0._wp
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zztmpx = (  bfrua(ji  ,jj) * un(ji  ,jj,mbku(ji  ,jj))  &
+                      &  + bfrua(ji-1,jj) * un(ji-1,jj,mbku(ji-1,jj))  )      
+               zztmpy = (  bfrva(ji,  jj) * vn(ji,jj  ,mbkv(ji,jj  ))  &
+                      &  + bfrva(ji,jj-1) * vn(ji,jj-1,mbkv(ji,jj-1))  ) 
+               z2d(ji,jj) = rau0 * SQRT( zztmpx * zztmpx + zztmpy * zztmpy ) * tmask(ji,jj,1) 
+               !
+            ENDDO
+         ENDDO
+         CALL lbc_lnk( z2d, 'T', 1. )
+         CALL iom_put( "taubot", z2d )           
+      ENDIF
+         
+      CALL iom_put( "uoce", un(:,:,:)         )    ! 3D i-current
+      CALL iom_put(  "ssu", un(:,:,1)         )    ! surface i-current
+      IF ( iom_use("sbu") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_sal) * fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO  
-         CALL iom_put( "sss"  , z2d(:,:)                 )   ! sea surface salinity content
+               jkbot = mbku(ji,jj)
+               z2d(ji,jj) = un(ji,jj,jkbot)
+            END DO
+         END DO
+         CALL iom_put( "sbu", z2d )                ! bottom i-current
+      ENDIF
+#if defined key_dynspg_ts
+      CALL iom_put(  "ubar", un_adv(:,:)      )    ! barotropic i-current
+#else
+      CALL iom_put(  "ubar", un_b(:,:)        )    ! barotropic i-current
+#endif
+      
+      CALL iom_put( "voce", vn(:,:,:)         )    ! 3D j-current
+      CALL iom_put(  "ssv", vn(:,:,1)         )    ! surface j-current
+      IF ( iom_use("sbv") ) THEN
          DO jj = 1, jpj
             DO ji = 1, jpi
-               z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_sal)**2 * fse3t_n(ji,jj,mikt(ji,jj))
-            END DO
-         END DO  
-         CALL iom_put( "sss2" , z2d(:,:)                 )   ! sea surface content of squared salinity
-      ELSE
-         CALL iom_put( "toce" , tsn(:,:,:,jp_tem)        )   ! temperature
-         IF ( iom_use("sst") ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_tem)
-               END DO
-            END DO
-            CALL iom_put( "sst"  , z2d(:,:)            ) ! sea surface temperature
-         ENDIF
-         IF ( iom_use("sst2") )   CALL iom_put( "sst2" , z2d(:,:) * z2d(:,:) ) ! square of sea surface temperature
-         CALL iom_put( "soce" , tsn(:,:,:,jp_sal)          )   ! salinity
-         IF ( iom_use("sss") ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = tsn(ji,jj,mikt(ji,jj),jp_sal)
-               END DO
-            END DO
-            CALL iom_put( "sss"  , z2d(:,:)            ) ! sea surface salinity
-         ENDIF
-         CALL iom_put( "sss2" , z2d(:,:) * z2d(:,:) ) ! square of sea surface salinity
-      END IF
-      IF( lk_vvl .AND. (.NOT. ln_dynadv_vec) ) THEN
-         CALL iom_put( "uoce" , umask(:,:,:) * un(:,:,:) * fse3u_n(:,:,:) )    ! i-transport
-         CALL iom_put( "voce" , vmask(:,:,:) * vn(:,:,:) * fse3v_n(:,:,:) )    ! j-transport
-      ELSE
-         CALL iom_put( "uoce" , umask(:,:,:) * un(:,:,:)                  )    ! i-current
-         CALL iom_put( "voce" , vmask(:,:,:) * vn(:,:,:)                  )    ! j-current
-         IF ( iom_use("ssu") ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = un(ji,jj,miku(ji,jj))
-               END DO
-            END DO
-            CALL iom_put( "ssu"   , z2d                                    )    ! i-current
-         ENDIF
-         IF ( iom_use("ssv") ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  z2d(ji,jj) = vn(ji,jj,mikv(ji,jj))
-               END DO
-            END DO
-            CALL iom_put( "ssv"   , z2d                                    )    ! j-current
-         ENDIF
-      ENDIF
-      CALL iom_put(    "avt"  , avt                        )    ! T vert. eddy diff. coef.
-      CALL iom_put(    "avm"  , avmu                       )    ! T vert. eddy visc. coef.
-      IF( lk_zdfddm ) THEN
-         CALL iom_put( "avs" , fsavs(:,:,:)                          )    ! S vert. eddy diff. coef.
-      ENDIF
-
-      IF ( iom_use("sstgrad2") .OR. iom_use("sstgrad2") ) THEN
+               jkbot = mbkv(ji,jj)
+               z2d(ji,jj) = vn(ji,jj,jkbot)
+            END DO
+         END DO
+         CALL iom_put( "sbv", z2d )                ! bottom j-current
+      ENDIF
+#if defined key_dynspg_ts
+      CALL iom_put(  "vbar", vn_adv(:,:)      )    ! barotropic j-current
+#else
+      CALL iom_put(  "vbar", vn_b(:,:)        )    ! barotropic j-current
+#endif
+
+      CALL iom_put( "woce", wn )                   ! vertical velocity
+      IF( iom_use('w_masstr') .OR. iom_use('w_masstr2') ) THEN   ! vertical mass transport & its square value
+         ! Caution: in the VVL case, it only correponds to the baroclinic mass transport.
+         z2d(:,:) = rau0 * e12t(:,:)
+         DO jk = 1, jpk
+            z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
+         END DO
+         CALL iom_put( "w_masstr" , z3d )  
+         IF( iom_use('w_masstr2') )   CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )
+      ENDIF
+
+      CALL iom_put( "avt" , avt                        )    ! T vert. eddy diff. coef.
+      CALL iom_put( "avm" , avmu                       )    ! T vert. eddy visc. coef.
+      CALL iom_put( "avs" , fsavs(:,:,:)               )    ! S vert. eddy diff. coef. (useful only with key_zdfddm)
+
+      IF ( iom_use("sstgrad") .OR. iom_use("sstgrad2") ) THEN
          DO jj = 2, jpjm1                                    ! sst gradient
             DO ji = fs_2, fs_jpim1   ! vector opt.
@@ -234,5 +256,4 @@
          CALL lbc_lnk( z2d, 'T', 1. )
          CALL iom_put( "sstgrad2",  z2d               )    ! square of module of sst gradient
-         !CDIR NOVERRCHK<
          z2d(:,:) = SQRT( z2d(:,:) )
          CALL iom_put( "sstgrad" ,  z2d               )    ! module of sst gradient
@@ -243,11 +264,10 @@
          z2d(:,:)  = 0._wp 
          DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
+            DO jj = 1, jpj
+               DO ji = 1, jpi
                   z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
                END DO
             END DO
          END DO
-         CALL lbc_lnk( z2d, 'T', 1. )
          CALL iom_put( "heatc", (rau0 * rcp) * z2d )    ! vertically integrated heat content (J/m2)
       ENDIF
@@ -256,11 +276,10 @@
          z2d(:,:)  = 0._wp 
          DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
+            DO jj = 1, jpj
+               DO ji = 1, jpi
                   z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
                END DO
             END DO
          END DO
-         CALL lbc_lnk( z2d, 'T', 1. )
          CALL iom_put( "saltc", rau0 * z2d )   ! vertically integrated salt content (PSU*kg/m2)
       ENDIF
@@ -621,5 +640,5 @@
          ENDIF
 
-         IF( .NOT. lk_cpl ) THEN
+         IF( .NOT. ln_cpl ) THEN
             CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -630,5 +649,5 @@
          ENDIF
 
-         IF( lk_cpl .AND. nn_ice <= 1 ) THEN
+         IF( ln_cpl .AND. nn_ice <= 1 ) THEN
             CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -653,5 +672,5 @@
 #endif
 
-         IF( lk_cpl .AND. nn_ice == 2 ) THEN
+         IF( ln_cpl .AND. nn_ice == 2 ) THEN
             CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
                &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
@@ -808,5 +827,5 @@
       ENDIF
 
-      IF( .NOT. lk_cpl ) THEN
+      IF( .NOT. ln_cpl ) THEN
          CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
          CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
@@ -814,5 +833,5 @@
          CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
       ENDIF
-      IF( lk_cpl .AND. nn_ice <= 1 ) THEN
+      IF( ln_cpl .AND. nn_ice <= 1 ) THEN
          CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
          CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
@@ -830,5 +849,5 @@
 #endif
 
-      IF( lk_cpl .AND. nn_ice == 2 ) THEN
+      IF( ln_cpl .AND. nn_ice == 2 ) THEN
          CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
          CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
