Index: branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90
===================================================================
--- branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 8637)
+++ branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/LIM_SRC_3/icerst.F90	(revision 8817)
@@ -6,5 +6,6 @@
    !! History:   3.0  ! 2005-04 (M. Vancoppenolle) Original code
    !!             -   ! 2008-03 (C. Ethe) restart files in using IOM interface
-   !!            4.0  ! 2011-02 (G. Madec) dynamical allocation
+   !!            3.4  ! 2011-02 (G. Madec) dynamical allocation
+   !!            4.0  ! 2017-11 (M. Andrejczuk) Extend IOM interface to write 3D ice fields
    !!----------------------------------------------------------------------
 #if defined key_lim3
@@ -82,5 +83,5 @@
             ENDIF
             !
-            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib )
+            CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpl )
             lrst_ice = .TRUE.
          ENDIF
@@ -88,4 +89,5 @@
       !
       IF( ln_icectl )   CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' )   ! control print
+      !
    END SUBROUTINE ice_rst_opn
 
@@ -103,5 +105,5 @@
       CHARACTER(len=25) ::   znam
       CHARACTER(len=2)  ::   zchar, zchar1
-      REAL(wp), DIMENSION(jpi,jpj) :: z2d
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -120,54 +122,30 @@
       CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter   , wp ) )      ! date
 
-!!gm   It is possible and easy to define a 3D domain size (jpi,jpj,jpl) or use a SIZE( tab, DIM=3) in iom_rtput )
-!!gm         ===>>> just a simple   iom_rstput( iter, nitrst, numriw, 'v_i', v_i )  etc...
-!!gm   "just" ask Sebatien
-
-      ! Prognostic variables 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'v_i'//'_htc'//zchar
-         z2d(:,:) = v_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_i
-         znam = 'v_s'//'_htc'//zchar
-         z2d(:,:) = v_s(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_s
-         znam = 'sv_i'//'_htc'//zchar
-         z2d(:,:) = sv_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! sv_i
-         znam = 'oa_i'//'_htc'//zchar
-         z2d(:,:) = oa_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! oa_i
-         znam = 'a_i'//'_htc'//zchar
-         z2d(:,:) = a_i(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! a_i
-         znam = 't_su'//'_htc'//zchar
-         z2d(:,:) = t_su(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! t_su
+      ! Prognostic variables
+      CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s  )
+      CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i )
+      CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i )
+      CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i  )
+      CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su )
+      !
+      ! Melt ponds
+      CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip )
+      CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip )
+      !
+!!gm dangerous !!!!!  ===>>>> better reading writing all snow layers !
+      ! Snow enthalpy (1st snow layer only)
+      z3d = e_s(:,:,1,:)
+      CALL iom_rstput( iter, nitrst, numriw, 'tempt_sl1' , z3d )
+      !
+      ! Ice enthalpy (all ice layers)
+      DO jk = 1, nlay_i 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'tempt'//'_il'//zchar1
+         z3d(:,:,:) = e_i(:,:,jk,:)
+         CALL iom_rstput( iter, nitrst, numriw, znam , z3d )
       END DO
-
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'a_ip'//'_htc'//zchar
-         z2d(:,:) = a_ip(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! a_ip
-         znam = 'v_ip'//'_htc'//zchar
-         z2d(:,:) = v_ip(:,:,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! v_ip
-      END DO
-
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'tempt_sl1'//'_htc'//zchar
-         z2d(:,:) = e_s(:,:,1,jl)
-         CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_s
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I2.2)') jk
-            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
-            z2d(:,:) = e_i(:,:,jk,jl)
-            CALL iom_rstput( iter, nitrst, numriw, znam , z2d ) ! e_i
-         END DO
-      END DO
-
+      !
+      ! ice velocity
       CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice
       CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice
@@ -189,12 +167,12 @@
       !! ** purpose  :   read restart file
       !!----------------------------------------------------------------------
-      INTEGER  ::   jk, jl
-      INTEGER  ::   id1            ! local integer
-      REAL(wp) ::   zfice, ziter
-      REAL(wp), DIMENSION(jpi,jpj) ::   z2d
+      INTEGER           ::   jk, jl
+      LOGICAL           ::   llok
+      INTEGER           ::   id1            ! local integer
+      INTEGER           ::   jlibalt = jprstlib
       CHARACTER(len=25) ::   znam
       CHARACTER(len=2)  ::   zchar, zchar1
-      INTEGER           ::   jlibalt = jprstlib
-      LOGICAL           ::   llok
+      REAL(wp)          ::   zfice, ziter
+      REAL(wp), DIMENSION(jpi,jpj,jpl) ::   z3d   ! 3D workspace
       !!----------------------------------------------------------------------
 
@@ -205,5 +183,5 @@
       ENDIF
 
-      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib )
+      CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl )
 
       CALL iom_get( numrir, 'nn_fsbc', zfice )
@@ -223,56 +201,36 @@
 
       ! Prognostic variables 
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'v_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         v_i(:,:,jl) = z2d(:,:)
-         znam = 'v_s'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         v_s(:,:,jl) = z2d(:,:) 
-         znam = 'sv_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         sv_i(:,:,jl) = z2d(:,:)
-         znam = 'oa_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         oa_i(:,:,jl) = z2d(:,:)
-         znam = 'a_i'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         a_i(:,:,jl) = z2d(:,:)
-         znam = 't_su'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         t_su(:,:,jl) = z2d(:,:)
-      END DO
-
+      CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i  )
+      CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s  )
+      CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i )
+      CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i )
+      CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i  )
+      CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su )
+      !
+      ! Melt ponds
       id1 = iom_varid( numrir, 'a_ip_htc01' , ldstop = .FALSE. )
       IF( id1 > 0 ) THEN                       ! fields exist (melt ponds)
-         DO jl = 1, jpl 
-            WRITE(zchar,'(I2.2)') jl
-            znam = 'a_ip'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            a_ip(:,:,jl) = z2d(:,:)
-            znam = 'v_ip'//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            v_ip(:,:,jl) = z2d(:,:)
-         END DO
+         CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip )
+         CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip )
       ELSE                                     ! start from rest
-         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it'
+         IF(lwp) WRITE(numout,*) '   ==>>   previous run without melt ponds output then set it to zero'
          a_ip(:,:,:) = 0._wp
          v_ip(:,:,:) = 0._wp
       ENDIF
-
-      DO jl = 1, jpl 
-         WRITE(zchar,'(I2.2)') jl
-         znam = 'tempt_sl1'//'_htc'//zchar
-         CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-         e_s(:,:,1,jl) = z2d(:,:)
-         DO jk = 1, nlay_i 
-            WRITE(zchar1,'(I2.2)') jk
-            znam = 'tempt'//'_il'//zchar1//'_htc'//zchar
-            CALL iom_get( numrir, jpdom_autoglo, znam , z2d )
-            e_i(:,:,jk,jl) = z2d(:,:)
-         END DO
+      !
+!!gm dangerous !!!!!  ===>>>> better reading writing all snow layers !
+      ! Snow enthalpy (1st snow layer only)
+      CALL iom_get( numrir, jpdom_autoglo, 'tempt_sl1' , z3d )
+      e_s(:,:,1,:) = z3d
+      !
+      ! Ice enthalpy (all ice layers)
+      DO jk = 1, nlay_i 
+         WRITE(zchar1,'(I2.2)') jk
+         znam = 'tempt'//'_il'//zchar1
+         CALL iom_get( numrir, jpdom_autoglo, znam , z3d )
+         e_i(:,:,jk,:) = z3d(:,:,:)
       END DO
-
+      !
+      ! ice velocity
       CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice )
       CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice )
