Index: NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90
===================================================================
--- NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 10076)
+++ NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaar5.F90	(revision 10115)
@@ -81,5 +81,5 @@
       !
       REAL(wp), POINTER, DIMENSION(:,:)     :: zarea_ssh , zbotpres       ! 2D workspace 
-      REAL(wp), POINTER, DIMENSION(:,:)     :: pe                         ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:)     :: zpe                        ! 2D workspace 
       REAL(wp), POINTER, DIMENSION(:,:,:)   :: zrhd , zrhop               ! 3D workspace
       REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztsn                       ! 4D workspace
@@ -91,7 +91,7 @@
       IF( kt == nit000 )     CALL dia_ar5_init
  
-      CALL wrk_alloc( jpi , jpj              , zarea_ssh , zbotpres, pe )
-      CALL wrk_alloc( jpi , jpj , jpk        , zrhd      , zrhop    )
-      CALL wrk_alloc( jpi , jpj , jpk , jpts , ztsn                 )
+      CALL wrk_alloc( jpi , jpj              , zarea_ssh , zbotpres, zpe )
+      CALL wrk_alloc( jpi , jpj , jpk        , zrhd      , zrhop         )
+      CALL wrk_alloc( jpi , jpj , jpk , jpts , ztsn                      )
 
       zarea_ssh(:,:) = area(:,:) * sshn(:,:)
@@ -206,38 +206,39 @@
       ! Exclude points where rn2 is negative as convection kicks in here and
       ! work is not being done against stratification
-          pe(:,:) = 0._wp
-          IF( lk_zdfddm ) THEN
-             DO ji=1,jpi
-                DO jj=1,jpj
-                   DO jk=1,jpk
-                      zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
-                         &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) )
-                      !
-                      zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
-                      zbw = rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal)* zrw
-                      !
-                      pe(ji, jj) = pe(ji, jj) - MIN(0._wp, rn2(ji,jj,jk)) * &
-                           &       grav * (avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
-                           &       - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
-
-                   ENDDO
-                ENDDO
-             ENDDO
+         zpe(:,:) = 0._wp
+         IF( lk_zdfddm ) THEN
+            DO jk = 2, jpk
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( rn2(ji,jj,jk) > 0._wp ) THEN
+                        zrw =   ( fsdepw(ji,jj,jk  ) - fsdept(ji,jj,jk) )   &
+                           &  / ( fsdept(ji,jj,jk-1) - fsdept(ji,jj,jk) )
+                        !
+                        zaw = rab_n(ji,jj,jk,jp_tem) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_tem)* zrw
+                        zbw = rab_n(ji,jj,jk,jp_sal) * (1. - zrw) + rab_n(ji,jj,jk-1,jp_sal)* zrw
+                        !
+                        zpe(ji, jj) = zpe(ji, jj)            &
+                           &        -  grav * (    avt(ji,jj,jk) * zaw * (tsn(ji,jj,jk-1,jp_tem) - tsn(ji,jj,jk,jp_tem) )  &
+                           &                   - fsavs(ji,jj,jk) * zbw * (tsn(ji,jj,jk-1,jp_sal) - tsn(ji,jj,jk,jp_sal) ) )
+                     ENDIF
+                  END DO
+               END DO
+             END DO
           ELSE
-             DO ji=1,jpi
-                DO jj=1,jpj
-                   DO jk=1,jpk
-                       pe(ji,jj) = pe(ji,jj) + avt(ji, jj, jk) * MIN(0._wp,rn2(ji, jj, jk)) * rau0 * fse3w(ji, jj, jk)
-                   ENDDO
-                ENDDO
-             ENDDO
-          ENDIF
-          CALL lbc_lnk(pe, 'T', 1._wp)         
-          CALL iom_put( 'tnpeo', pe )
+            DO jk = 1, jpk
+               DO ji = 1, jpi
+                  DO jj = 1, jpj
+                     zpe(ji,jj) = zpe(ji,jj) + avt(ji, jj, jk) * MIN(0._wp,rn2(ji, jj, jk)) * rau0 * fse3w(ji, jj, jk)
+                  END DO
+               END DO
+            END DO
+         ENDIF
+         CALL lbc_lnk(zpe, 'T', 1._wp)         
+         CALL iom_put( 'tnpeo', zpe  )
       ENDIF
       !
-      CALL wrk_dealloc( jpi , jpj              , zarea_ssh , zbotpres, pe )
-      CALL wrk_dealloc( jpi , jpj , jpk        , zrhd      , zrhop    )
-      CALL wrk_dealloc( jpi , jpj , jpk , jpts , ztsn                 )
+      CALL wrk_dealloc( jpi , jpj              , zarea_ssh , zbotpres, zpe )
+      CALL wrk_dealloc( jpi , jpj , jpk        , zrhd      , zrhop         )
+      CALL wrk_dealloc( jpi , jpj , jpk , jpts , ztsn                      )
       !
       IF( nn_timing == 1 )   CALL timing_stop('dia_ar5')
Index: NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90
===================================================================
--- NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 10076)
+++ NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diadct.F90	(revision 10115)
@@ -249,5 +249,5 @@
            !debug this section computing ?
            lldebug=.FALSE.
-           IF( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND.  kt==nit000+nn_dct-1 .AND. lwp ) lldebug=.TRUE. 
+           IF( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND.  kt==nit000+nn_dct-1 ) lldebug=.TRUE. 
 
            !Compute transport through section  
@@ -258,5 +258,5 @@
         IF( MOD(kt,nn_dctwri)==0 )THEN
 
-           IF( lwp .AND. kt==nit000+nn_dctwri-1 )WRITE(numout,*)"      diadct: average transports and write at kt = ",kt         
+           IF( kt==nit000+nn_dctwri-1 )WRITE(numout,*)"      diadct: average transports and write at kt = ",kt         
   
            !! divide arrays by nn_dctwri/nn_dct to obtain average 
@@ -344,5 +344,5 @@
      DO jsec=1,nb_sec_max      !loop on the nb_sec sections
 
-        IF ( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) ) &
+        IF ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) &
            & WRITE(numout,*)'debuging for section number: ',jsec 
 
@@ -364,5 +364,5 @@
         IF( jsec .NE. isec )  CALL ctl_stop( cltmp )
 
-        IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )WRITE(numout,*)"isec ",isec 
+        IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )WRITE(numout,*)"isec ",isec 
 
         READ(numdct_in)secs(jsec)%name
@@ -383,5 +383,5 @@
         !-----
 
-        IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+        IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
           
             WRITE(clformat,'(a,i2,a)') '(A40,', nb_class_max,'(f8.3,1X))' 
@@ -416,5 +416,5 @@
            !debug
            !-----
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points in global domain:"
               DO jpt=1,iptglo
@@ -450,5 +450,5 @@
            !debug
            !-----
-           IF(   lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points selected by the proc:"
               DO jpt = 1,iptloc
@@ -468,5 +468,5 @@
            !remove redundant points between processors
            !------------------------------------------
-           lldebug = .FALSE. ; IF ( (jsec==nn_secdebug .OR. nn_secdebug==-1) .AND. lwp ) lldebug = .TRUE.
+           lldebug = .FALSE. ; IF ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) lldebug = .TRUE.
            IF( iptloc .NE. 0 )THEN
               CALL removepoints(secs(jsec),'I','top_list',lldebug)
@@ -484,5 +484,5 @@
            !debug
            !-----
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )THEN
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )THEN
               WRITE(numout,*)"      List of points after removepoints:"
               iptloc = secs(jsec)%nb_point
@@ -496,5 +496,5 @@
 
         ELSE  ! iptglo = 0
-           IF( lwp .AND. ( jsec==nn_secdebug .OR. nn_secdebug==-1 ) )&
+           IF( jsec==nn_secdebug .OR. nn_secdebug==-1 )&
               WRITE(numout,*)'   No points for this section.'
         ENDIF
Index: NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaprod.F90
===================================================================
--- NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaprod.F90	(revision 10076)
+++ NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diaprod.F90	(revision 10115)
@@ -238,9 +238,11 @@
    !!   Default option :                                         NO diaprod
    !!----------------------------------------------------------------------
+   USE in_out_manager  ! I/O manager
    LOGICAL, PUBLIC, PARAMETER :: lk_diaprod = .FALSE.   ! coupled flag
 CONTAINS
    SUBROUTINE dia_prod( kt )   ! Empty routine
       INTEGER ::   kt
-      WRITE(*,*) 'dia_prod: You should not have seen this print! error?', kt
+      IF( kt == nit000 .AND. lwp ) &
+         WRITE(*,*) 'dia_prod: You should not have seen this print! error?', kt
    END SUBROUTINE dia_prod
 #endif
Index: NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 10076)
+++ NEMO/branches/2018/dev_r5003_MERCATOR6_CRS/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 10115)
@@ -296,15 +296,15 @@
       !
       IF ( iom_use("eken") ) THEN
-         rke(:,:,jk) = 0._wp                               !      kinetic energy 
+         rke(:,:,jpk) = 0._wp                               !      kinetic energy 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  zztmp   = 1._wp / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)    &
-                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk) )  &
+                  zztmp   =  1 / (e1e2t(ji,jj) * fse3t(ji,jj,jk))
+                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e1u(ji-1,jj) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)    &
+                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e1u(ji,  jj) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk) )  &
                      &          *  zztmp 
                   !
-                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * fse3v(ji,jj-1,jk)    &
-                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * fse3v(ji,jj  ,jk) )  &
+                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * e2v(ji,jj-1) * fse3v(ji,jj-1,jk)    &
+                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * e2v(ji,jj  ) * fse3v(ji,jj  ,jk) )  &
                      &          *  zztmp 
                   !
