Index: NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90
===================================================================
--- NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90	(revision 13360)
+++ NEMO/branches/2020/dev_r13333_KERNEL-08_techene_gm_HPG_SPG/src/OCE/DIA/diawri.F90	(revision 14037)
@@ -118,4 +118,5 @@
       INTEGER ::   ji, jj, jk       ! dummy loop indices
       INTEGER ::   ikbot            ! local integer
+      REAL(wp)::   ze3
       REAL(wp)::   zztmp , zztmpx   ! local scalar
       REAL(wp)::   zztmp2, zztmpy   !   -      -
@@ -175,5 +176,5 @@
       CALL iom_put(  "sst", ts(:,:,1,jp_tem,Kmm) )    ! surface temperature
       IF ( iom_use("sbt") ) THEN
-         DO_2D( 1, 1, 1, 1 )
+         DO_2D( 0, 0, 0, 0 )
             ikbot = mbkt(ji,jj)
             z2d(ji,jj) = ts(ji,jj,ikbot,jp_tem,Kmm)
@@ -185,5 +186,5 @@
       CALL iom_put(  "sss", ts(:,:,1,jp_sal,Kmm) )    ! surface salinity
       IF ( iom_use("sbs") ) THEN
-         DO_2D( 1, 1, 1, 1 )
+         DO_2D( 0, 0, 0, 0 )
             ikbot = mbkt(ji,jj)
             z2d(ji,jj) = ts(ji,jj,ikbot,jp_sal,Kmm)
@@ -207,5 +208,4 @@
             !
          END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1.0_wp )
          CALL iom_put( "taubot", z2d )           
       ENDIF
@@ -214,5 +214,5 @@
       CALL iom_put(  "ssu", uu(:,:,1,Kmm) )            ! surface i-current
       IF ( iom_use("sbu") ) THEN
-         DO_2D( 1, 1, 1, 1 )
+         DO_2D( 0, 0, 0, 0 )
             ikbot = mbku(ji,jj)
             z2d(ji,jj) = uu(ji,jj,ikbot,Kmm)
@@ -224,5 +224,5 @@
       CALL iom_put(  "ssv", vv(:,:,1,Kmm) )            ! surface j-current
       IF ( iom_use("sbv") ) THEN
-         DO_2D( 1, 1, 1, 1 )
+         DO_2D( 0, 0, 0, 0 )
             ikbot = mbkv(ji,jj)
             z2d(ji,jj) = vv(ji,jj,ikbot,Kmm)
@@ -253,6 +253,22 @@
       IF( iom_use('logavs') )   CALL iom_put( "logavs", LOG( MAX( 1.e-20_wp, avs(:,:,:) ) ) )
 
+      IF ( iom_use("socegrad") .OR. iom_use("socegrad2") ) THEN
+         z3d(:,:,jpk) = 0.
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            zztmp  = ts(ji,jj,jk,jp_sal,Kmm)
+            zztmpx = (ts(ji+1,jj,jk,jp_sal,Kmm) - zztmp) * r1_e1u(ji,jj) + (zztmp - ts(ji-1,jj  ,jk,jp_sal,Kmm)) * r1_e1u(ji-1,jj)
+            zztmpy = (ts(ji,jj+1,jk,jp_sal,Kmm) - zztmp) * r1_e2v(ji,jj) + (zztmp - ts(ji  ,jj-1,jk,jp_sal,Kmm)) * r1_e2v(ji,jj-1)
+            z3d(ji,jj,jk) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
+               &                 * umask(ji,jj,jk) * umask(ji-1,jj,jk) * vmask(ji,jj,jk) * umask(ji,jj-1,jk)
+         END_3D
+         CALL iom_put( "socegrad2",  z3d )          ! square of module of sal gradient
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            z3d(ji,jj,jk) = SQRT( z3d(ji,jj,jk) )
+         END_3D
+         CALL iom_put( "socegrad" ,  z3d )          ! module of sal gradient
+      ENDIF
+         
       IF ( iom_use("sstgrad") .OR. iom_use("sstgrad2") ) THEN
-         DO_2D( 0, 0, 0, 0 )
+         DO_2D( 0, 0, 0, 0 )                                 ! sst gradient
             zztmp  = ts(ji,jj,1,jp_tem,Kmm)
             zztmpx = ( ts(ji+1,jj,1,jp_tem,Kmm) - zztmp ) * r1_e1u(ji,jj) + ( zztmp - ts(ji-1,jj  ,1,jp_tem,Kmm) ) * r1_e1u(ji-1,jj)
@@ -261,7 +277,8 @@
                &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
          END_2D
-         CALL lbc_lnk( 'diawri', z2d, 'T', 1.0_wp )
          CALL iom_put( "sstgrad2",  z2d )          ! square of module of sst gradient
-         z2d(:,:) = SQRT( z2d(:,:) )
+         DO_2D( 0, 0, 0, 0 )
+            z2d(ji,jj) = SQRT( z2d(ji,jj) )
+         END_2D
          CALL iom_put( "sstgrad" ,  z2d )          ! module of sst gradient
       ENDIF
@@ -270,5 +287,5 @@
       IF( iom_use("heatc") ) THEN
          z2d(:,:)  = 0._wp 
-         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
             z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_tem,Kmm) * tmask(ji,jj,jk)
          END_3D
@@ -278,5 +295,5 @@
       IF( iom_use("saltc") ) THEN
          z2d(:,:)  = 0._wp 
-         DO_3D( 1, 1, 1, 1, 1, jpkm1 )
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
             z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_sal,Kmm) * tmask(ji,jj,jk)
          END_3D
@@ -284,18 +301,55 @@
       ENDIF
       !
-      IF ( iom_use("eken") ) THEN
+      IF( iom_use("salt2c") ) THEN
+         z2d(:,:)  = 0._wp 
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_sal,Kmm) * ts(ji,jj,jk,jp_sal,Kmm) * tmask(ji,jj,jk)
+         END_3D
+         CALL iom_put( "salt2c", rho0 * z2d )          ! vertically integrated salt content (PSU*kg/m2)
+      ENDIF
+      !
+      IF ( iom_use("ke") .OR. iom_use("ke_int") ) THEN
          z3d(:,:,jpk) = 0._wp 
          DO_3D( 0, 0, 0, 0, 1, jpkm1 )
-            zztmp  = 0.25_wp * r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kmm)
-            z3d(ji,jj,jk) = zztmp * (  uu(ji-1,jj,jk,Kmm)**2 * e2u(ji-1,jj) * e3u(ji-1,jj,jk,Kmm)   &
-               &                     + uu(ji  ,jj,jk,Kmm)**2 * e2u(ji  ,jj) * e3u(ji  ,jj,jk,Kmm)   &
-               &                     + vv(ji,jj-1,jk,Kmm)**2 * e1v(ji,jj-1) * e3v(ji,jj-1,jk,Kmm)   &
-               &                     + vv(ji,jj  ,jk,Kmm)**2 * e1v(ji,jj  ) * e3v(ji,jj  ,jk,Kmm)   )
-         END_3D
-         CALL lbc_lnk( 'diawri', z3d, 'T', 1.0_wp )
-         CALL iom_put( "eken", z3d )                 ! kinetic energy
+            zztmpx = 0.5 * ( uu(ji-1,jj  ,jk,Kmm) + uu(ji,jj,jk,Kmm) )
+            zztmpy = 0.5 * ( vv(ji  ,jj-1,jk,Kmm) + vv(ji,jj,jk,Kmm) )
+            z3d(ji,jj,jk) = 0.5 * ( zztmpx*zztmpx + zztmpy*zztmpy )
+         END_3D
+         CALL iom_put( "ke", z3d )                 ! kinetic energy
+
+         z2d(:,:)  = 0._wp 
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) * z3d(ji,jj,jk) * e1e2t(ji,jj) * tmask(ji,jj,jk)
+         END_3D
+         CALL iom_put( "ke_int", z2d )   ! vertically integrated kinetic energy
       ENDIF
       !
       CALL iom_put( "hdiv", hdiv )                  ! Horizontal divergence
+
+      IF ( iom_use("relvor") .OR. iom_use("absvor") .OR. iom_use("potvor") ) THEN
+         
+         z3d(:,:,jpk) = 0._wp 
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            z3d(ji,jj,jk) = (   e2v(ji+1,jj  ) * vv(ji+1,jj  ,jk,Kmm) - e2v(ji,jj) * vv(ji,jj,jk,Kmm)    &
+               &              - e1u(ji  ,jj+1) * uu(ji  ,jj+1,jk,Kmm) + e1u(ji,jj) * uu(ji,jj,jk,Kmm)  ) * r1_e1e2f(ji,jj)
+         END_3D
+         CALL iom_put( "relvor", z3d )                  ! relative vorticity
+
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            z3d(ji,jj,jk) = ff_f(ji,jj) + z3d(ji,jj,jk) 
+         END_3D
+         CALL iom_put( "absvor", z3d )                  ! absolute vorticity
+
+         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
+            ze3  = (  e3t(ji,jj+1,jk,Kmm)*tmask(ji,jj+1,jk) + e3t(ji+1,jj+1,jk,Kmm)*tmask(ji+1,jj+1,jk)   &
+               &    + e3t(ji,jj  ,jk,Kmm)*tmask(ji,jj  ,jk) + e3t(ji+1,jj  ,jk,Kmm)*tmask(ji+1,jj  ,jk)  )
+            IF( ze3 /= 0._wp ) THEN   ;   ze3 = 4._wp / ze3
+            ELSE                      ;   ze3 = 0._wp
+            ENDIF
+            z3d(ji,jj,jk) = ze3 * z3d(ji,jj,jk) 
+         END_3D
+         CALL iom_put( "potvor", z3d )                  ! potential vorticity
+
+      ENDIF
       !
       IF( iom_use("u_masstr") .OR. iom_use("u_masstr_vint") .OR. iom_use("u_heattr") .OR. iom_use("u_salttr") ) THEN
@@ -315,5 +369,4 @@
             z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( ts(ji,jj,jk,jp_tem,Kmm) + ts(ji+1,jj,jk,jp_tem,Kmm) )
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'U', -1.0_wp )
          CALL iom_put( "u_heattr", 0.5*rcp * z2d )    ! heat transport in i-direction
       ENDIF
@@ -324,5 +377,4 @@
             z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( ts(ji,jj,jk,jp_sal,Kmm) + ts(ji+1,jj,jk,jp_sal,Kmm) )
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'U', -1.0_wp )
          CALL iom_put( "u_salttr", 0.5 * z2d )        ! heat transport in i-direction
       ENDIF
@@ -342,5 +394,4 @@
             z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( ts(ji,jj,jk,jp_tem,Kmm) + ts(ji,jj+1,jk,jp_tem,Kmm) )
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'V', -1.0_wp )
          CALL iom_put( "v_heattr", 0.5*rcp * z2d )    !  heat transport in j-direction
       ENDIF
@@ -351,5 +402,4 @@
             z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( ts(ji,jj,jk,jp_sal,Kmm) + ts(ji,jj+1,jk,jp_sal,Kmm) )
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'V', -1.0_wp )
          CALL iom_put( "v_salttr", 0.5 * z2d )        !  heat transport in j-direction
       ENDIF
@@ -360,5 +410,4 @@
             z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) *  ts(ji,jj,jk,jp_tem,Kmm)
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'T', -1.0_wp )
          CALL iom_put( "tosmint", rho0 * z2d )        ! Vertical integral of temperature
       ENDIF
@@ -368,5 +417,4 @@
             z2d(ji,jj) = z2d(ji,jj) + e3t(ji,jj,jk,Kmm) * ts(ji,jj,jk,jp_sal,Kmm)
          END_3D
-         CALL lbc_lnk( 'diawri', z2d, 'T', -1.0_wp )
          CALL iom_put( "somint", rho0 * z2d )         ! Vertical integral of salinity
       ENDIF
