Index: branches/2014/dev_r4650_UKMO11_restart_functionality/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- branches/2014/dev_r4650_UKMO11_restart_functionality/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 4763)
+++ branches/2014/dev_r4650_UKMO11_restart_functionality/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90	(revision 5208)
@@ -44,5 +44,4 @@
    USE in_out_manager  ! I/O manager
    USE diadimg         ! dimg direct access file format output
-   USE diaar5, ONLY :   lk_diaar5
    USE iom
    USE ioipsl
@@ -88,7 +87,5 @@
       INTEGER, DIMENSION(2) :: ierr
       !!----------------------------------------------------------------------
-      !
       ierr = 0
-      !
       ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
          &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
@@ -131,5 +128,4 @@
       !!
       REAL(wp), POINTER, DIMENSION(:,:)   :: z2d      ! 2D workspace
-      REAL(wp), POINTER, DIMENSION(:,:)   :: z2ds     ! 2D workspace
       REAL(wp), POINTER, DIMENSION(:,:,:) :: z3d      ! 3D workspace
       !!----------------------------------------------------------------------
@@ -137,5 +133,5 @@
       IF( nn_timing == 1 )   CALL timing_start('dia_wri')
       ! 
-      CALL wrk_alloc( jpi , jpj      , z2d , z2ds )
+      CALL wrk_alloc( jpi , jpj      , z2d )
       CALL wrk_alloc( jpi , jpj, jpk , z3d )
       !
@@ -149,27 +145,75 @@
          z3d(:,:,:) = tsn(:,:,:,jp_tem) * fse3t_n(:,:,:)
          CALL iom_put( "toce" , z3d                        )   ! heat content
-         CALL iom_put( "sst"  , z3d(:,:,1)                 )   ! sea surface heat content
-         z3d(:,:,1) = tsn(:,:,1,jp_tem) * z3d(:,:,1)
-         CALL iom_put( "sst2" , z3d(:,:,1)                 )   ! sea surface content of squared temperature
+         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      
+         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
-         CALL iom_put( "sss"  , z3d(:,:,1)                 )   ! sea surface salinity content
-         z3d(:,:,1) = tsn(:,:,1,jp_sal) * z3d(:,:,1)
-         CALL iom_put( "sss2" , z3d(:,:,1)                 )   ! sea surface content of squared salinity
+         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
+         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
-         CALL iom_put( "sst"  , tsn(:,:,1,jp_tem)          )   ! sea surface temperature
-         CALL iom_put( "sst2" , tsn(:,:,1,jp_tem) * tsn(:,:,1,jp_tem) ) ! square of sea surface temperature
+         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
-         CALL iom_put( "sss"  , tsn(:,:,1,jp_sal)          )   ! sea surface salinity
-         CALL iom_put( "sss2" , tsn(:,:,1,jp_sal) * tsn(:,:,1,jp_sal) ) ! square of sea surface 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" , un(:,:,:) * fse3u_n(:,:,:) )    ! i-transport
-         CALL iom_put( "voce" , vn(:,:,:) * fse3v_n(:,:,:) )    ! j-transport
+         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" , un                         )    ! i-current
-         CALL iom_put( "voce" , vn                         )    ! j-current
-      END IF
+         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.
@@ -178,37 +222,72 @@
       ENDIF
 
-      DO jj = 2, jpjm1                                    ! sst gradient
-         DO ji = fs_2, fs_jpim1   ! vector opt.
-            zztmp      = tsn(ji,jj,1,jp_tem)
-            zztmpx     = ( tsn(ji+1,jj  ,1,jp_tem) - zztmp ) / e1u(ji,jj) + ( zztmp - tsn(ji-1,jj  ,1,jp_tem) ) / e1u(ji-1,jj  )
-            zztmpy     = ( tsn(ji  ,jj+1,1,jp_tem) - zztmp ) / e2v(ji,jj) + ( zztmp - tsn(ji  ,jj-1,1,jp_tem) ) / e2v(ji  ,jj-1)
-            z2d(ji,jj) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
-               &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
-         END DO
-      END DO
-      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
-
+      IF ( iom_use("sstgrad2") .OR. iom_use("sstgrad2") ) THEN
+         DO jj = 2, jpjm1                                    ! sst gradient
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zztmp      = tsn(ji,jj,1,jp_tem)
+               zztmpx     = ( tsn(ji+1,jj  ,1,jp_tem) - zztmp ) / e1u(ji,jj) + ( zztmp - tsn(ji-1,jj  ,1,jp_tem) ) / e1u(ji-1,jj  )
+               zztmpy     = ( tsn(ji  ,jj+1,1,jp_tem) - zztmp ) / e2v(ji,jj) + ( zztmp - tsn(ji  ,jj-1,1,jp_tem) ) / e2v(ji  ,jj-1)
+               z2d(ji,jj) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
+                  &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
+            END DO
+         END DO
+         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
+      ENDIF
+         
       ! clem: heat and salt content
-      z2d(:,:)  = 0._wp 
-      z2ds(:,:) = 0._wp 
-      DO jk = 1, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               z2d(ji,jj) = z2d(ji,jj) + rau0 * rcp * fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
-               z2ds(ji,jj) = z2ds(ji,jj) + rau0 * 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 lbc_lnk( z2ds, 'T', 1. )
-      CALL iom_put( "heatc", z2d )    ! vertically integrated heat content (J/m2)
-      CALL iom_put( "saltc", z2ds )   ! vertically integrated salt content (PSU*kg/m2)
-      
-
-      IF( lk_diaar5 ) THEN
+      IF( iom_use("heatc") ) THEN
+         z2d(:,:)  = 0._wp 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  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
+
+      IF( iom_use("saltc") ) THEN
+         z2d(:,:)  = 0._wp 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  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
+      !
+      IF ( iom_use("eken") ) THEN
+         rke(:,:,jk) = 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 
+                  !
+                  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) )  &
+                     &          *  zztmp 
+                  !
+                  rke(ji,jj,jk) = 0.5_wp * ( zztmpx + zztmpy )
+                  !
+               ENDDO
+            ENDDO
+         ENDDO
+         CALL lbc_lnk( rke, 'T', 1. )
+         CALL iom_put( "eken", rke )           
+      ENDIF
+         
+      IF( iom_use("u_masstr") .OR. iom_use("u_heattr") .OR. iom_use("u_salttr") ) THEN
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
@@ -216,21 +295,34 @@
          END DO
          CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
-
-         zztmp = 0.5 * rcp
+      ENDIF
+      
+      IF( iom_use("u_heattr") ) THEN
          z2d(:,:) = 0.e0 
-         z2ds(:,:) = 0.e0 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
-                  z2ds(ji,jj) = z2ds(ji,jj) + z3d(ji,jj,jk) * 0.5_wp * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'U', -1. )
-         CALL lbc_lnk( z2ds, 'U', -1. )
-         CALL iom_put( "u_heattr", z2d )                  ! heat transport in i-direction
-         CALL iom_put( "u_salttr", z2ds )                 ! salt transport in i-direction
-
+         CALL iom_put( "u_heattr", (0.5 * rcp) * z2d )    ! heat transport in i-direction
+      ENDIF
+
+      IF( iom_use("u_salttr") ) THEN
+         z2d(:,:) = 0.e0 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( z2d, 'U', -1. )
+         CALL iom_put( "u_salttr", 0.5 * z2d )            ! heat transport in i-direction
+      ENDIF
+
+      
+      IF( iom_use("v_masstr") .OR. iom_use("v_heattr") .OR. iom_use("v_salttr") ) THEN
          z3d(:,:,jpk) = 0.e0
          DO jk = 1, jpkm1
@@ -238,22 +330,33 @@
          END DO
          CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
-
+      ENDIF
+      
+      IF( iom_use("v_heattr") ) THEN
          z2d(:,:) = 0.e0 
-         z2ds(:,:) = 0.e0 
          DO jk = 1, jpkm1
             DO jj = 2, jpjm1
                DO ji = fs_2, fs_jpim1   ! vector opt.
-                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * zztmp * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
-                  z2ds(ji,jj) = z2ds(ji,jj) + z3d(ji,jj,jk) * 0.5_wp * ( tsn(ji,jj,jk,jp_sal) + tsn(ji,jj+1,jk,jp_sal) )
+                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
                END DO
             END DO
          END DO
          CALL lbc_lnk( z2d, 'V', -1. )
-         CALL lbc_lnk( z2ds, 'V', -1. )
-         CALL iom_put( "v_heattr", z2d )                  !  heat transport in j-direction
-         CALL iom_put( "v_salttr", z2ds )                 !  salt transport in j-direction
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi , jpj      , z2d , z2ds )
+         CALL iom_put( "v_heattr", (0.5 * rcp) * z2d )    !  heat transport in j-direction
+      ENDIF
+
+      IF( iom_use("v_salttr") ) THEN
+         z2d(:,:) = 0.e0 
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji,jj+1,jk,jp_sal) )
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( z2d, 'V', -1. )
+         CALL iom_put( "v_salttr", 0.5 * z2d )            !  heat transport in j-direction
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi , jpj      , z2d )
       CALL wrk_dealloc( jpi , jpj, jpk , z3d )
       !
@@ -518,23 +621,22 @@
          ENDIF
 
-#if ! defined key_coupled 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
-
-
-
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-         CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-#endif
+         IF( .NOT. lk_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 )
+            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
+
+         IF( lk_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 )
+            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+            CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
+         
          clmx ="l_max(only(x))"    ! max index on a period
          CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX 
@@ -551,15 +653,10 @@
 #endif
 
-#if defined key_coupled 
-# if defined key_lim3
-         Must be adapted to LIM3
-# endif 
-# if defined key_lim2
-         CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-         CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
-            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
-# endif 
-#endif 
+         IF( lk_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 )
+            CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
+               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
+         ENDIF
 
          CALL histend( nid_T, snc4chunks=snc4set )
@@ -652,5 +749,4 @@
       ENDIF
 
-      ! Write fields on T grid
       IF( lk_vvl ) THEN
          CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! heat content
@@ -663,5 +759,4 @@
          CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) , ndim_hT, ndex_hT )   ! sea surface temperature
          CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) , ndim_hT, ndex_hT )   ! sea surface salinity
-
       ENDIF
       IF( lk_vvl ) THEN
@@ -713,18 +808,18 @@
       ENDIF
 
-#if ! defined key_coupled
-      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
-      IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
-#if ( defined key_coupled && ! defined key_lim3 && ! defined key_lim2 ) 
-      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
+      IF( .NOT. lk_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
          IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
-#endif
-      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
-      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
+         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+      ENDIF
+      IF( lk_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
+         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
+         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
+      ENDIF
+!      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
+!      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
 
 #if defined key_diahth
@@ -735,16 +830,9 @@
 #endif
 
-#if defined key_coupled 
-# if defined key_lim3
-      Must be adapted for LIM3
-      CALL histwrite( nid_T, "soicetem", it, tn_ice        , ndim_hT, ndex_hT )   ! surf. ice temperature
-      CALL histwrite( nid_T, "soicealb", it, alb_ice       , ndim_hT, ndex_hT )   ! ice albedo
-# endif
-# if defined key_lim2
-      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
-# endif
-#endif
-         ! Write fields on U grid
+      IF( lk_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
+      ENDIF
+
       CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
       IF( ln_traldf_gdia ) THEN
@@ -768,5 +856,4 @@
       CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
 
-         ! Write fields on V grid
       CALL histwrite( nid_V, "vomecrty", it, vn            , ndim_V , ndex_V  )   ! j-current
       IF( ln_traldf_gdia ) THEN
@@ -783,5 +870,4 @@
       CALL histwrite( nid_V, "sometauy", it, vtau          , ndim_hV, ndex_hV )   ! j-wind stress
 
-         ! Write fields on W grid
       CALL histwrite( nid_W, "vovecrtz", it, wn             , ndim_T, ndex_T )    ! vert. current
       IF( ln_traldf_gdia ) THEN
