Index: trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 4624)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 4990)
@@ -156,5 +156,9 @@
 #if defined key_lim2 || defined key_lim3
             IF(( nn_ice == 2 ) .OR. ( nn_ice == 3 )) THEN
-               CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', 1.0 - frld(:,:)   )
+	       IF(ALLOCATED(frld)) THEN
+                  CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', 1.0 - frld(:,:)   )
+               ELSE
+		  CALL ctl_warn('Ice concentration not written to background as ice variable frld not allocated on this timestep')
+	       ENDIF
             ENDIF
 #endif
Index: trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4624)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 4990)
@@ -109,8 +109,7 @@
       !! ** Action  : 
       !!----------------------------------------------------------------------
-      INTEGER :: ji, jj, jk
-      INTEGER :: jt
-      INTEGER :: imid
-      INTEGER :: inum
+      INTEGER :: ji, jj, jk, jt  ! dummy loop indices
+      INTEGER :: imid, inum      ! local integers
+      INTEGER :: ios             ! Local integer output status for namelist read
       INTEGER :: iiauper         ! Number of time steps in the IAU period
       INTEGER :: icycper         ! Number of time steps in the cycle
@@ -120,15 +119,13 @@
       INTEGER :: iitiaustr_date  ! Date YYYYMMDD of IAU interval start time step
       INTEGER :: iitiaufin_date  ! Date YYYYMMDD of IAU interval final time step
-      INTEGER :: ios             ! Local integer output status for namelist read
-
+      !
       REAL(wp) :: znorm        ! Normalization factor for IAU weights
-      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights 
-                               ! (should be equal to one)
+      REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
       REAL(wp) :: z_inc_dateb  ! Start date of interval on which increment is valid
       REAL(wp) :: z_inc_datef  ! End date of interval on which increment is valid
       REAL(wp) :: zdate_bkg    ! Date in background state file for DI
       REAL(wp) :: zdate_inc    ! Time axis in increments file
-
-      REAL(wp), POINTER, DIMENSION(:,:) :: hdiv
+      !
+      REAL(wp), POINTER, DIMENSION(:,:) ::   hdiv   ! 2D workspace
       !!
       NAMELIST/nam_asminc/ ln_bkgwri,                                      &
@@ -136,6 +133,5 @@
          &                 ln_asmdin, ln_asmiau,                           &
          &                 nitbkg, nitdin, nitiaustr, nitiaufin, niaufn,   &
-         &                 ln_salfix, salfixmin,                &
-         &                 nn_divdmp
+         &                 ln_salfix, salfixmin, nn_divdmp
       !!----------------------------------------------------------------------
 
@@ -143,5 +139,4 @@
       ! Read Namelist nam_asminc : assimilation increment interface
       !-----------------------------------------------------------------------
-
       ln_seaiceinc = .FALSE.
       ln_temnofreeze = .FALSE.
@@ -186,19 +181,10 @@
       icycper = nitend      - nit000      + 1  ! Cycle interval length
 
-      ! Date of final time step
-      CALL calc_date( nit000, nitend, ndate0, iitend_date )
-
-      ! Background time for Jb referenced to ndate0
-      CALL calc_date( nit000, nitbkg_r, ndate0, iitbkg_date )
-
-      ! Background time for DI referenced to ndate0
-      CALL calc_date( nit000, nitdin_r, ndate0, iitdin_date )
-
-      ! IAU start time referenced to ndate0
-      CALL calc_date( nit000, nitiaustr_r, ndate0, iitiaustr_date )
-
-      ! IAU end time referenced to ndate0
-      CALL calc_date( nit000, nitiaufin_r, ndate0, iitiaufin_date )
-
+      CALL calc_date( nit000, nitend     , ndate0, iitend_date    )     ! Date of final time step
+      CALL calc_date( nit000, nitbkg_r   , ndate0, iitbkg_date    )     ! Background time for Jb referenced to ndate0
+      CALL calc_date( nit000, nitdin_r   , ndate0, iitdin_date    )     ! Background time for DI referenced to ndate0
+      CALL calc_date( nit000, nitiaustr_r, ndate0, iitiaustr_date )     ! IAU start time referenced to ndate0
+      CALL calc_date( nit000, nitiaufin_r, ndate0, iitiaufin_date )     ! IAU end time referenced to ndate0
+      !
       IF(lwp) THEN
          WRITE(numout,*)
@@ -237,8 +223,4 @@
          &                ' Inconsistent options')
 
-      IF ( ( ln_bkgwri ).AND.( ( ln_asmdin ).OR.( ln_asmiau ) ) )  &
-         & CALL ctl_stop( ' ln_bkgwri and either ln_asmdin or ln_asmiau are set to .true.:', &
-         &                ' The background state must be written before applying the increments')
-
       IF ( ( niaufn /= 0 ).AND.( niaufn /= 1 ) ) &
          & CALL ctl_stop( ' niaufn /= 0 or niaufn /=1 :',  &
@@ -675,7 +657,7 @@
       ! used to prevent the applied increments taking the temperature below the local freezing point 
 
-      DO jk=1, jpkm1
-         fzptnz (:,:,jk) = tfreez( tsn(:,:,jk,jp_sal), fsdept(:,:,jk) )
-      ENDDO
+      DO jk = 1, jpkm1
+         fzptnz(:,:,jk) = eos_fzp( tsn(:,:,jk,jp_sal), fsdept(:,:,jk) )
+      END DO
 
       IF ( ln_asmiau ) THEN
@@ -692,6 +674,5 @@
             IF(lwp) THEN
                WRITE(numout,*) 
-               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', &
-                  &  kt,' with IAU weight = ', wgtiau(it)
+               WRITE(numout,*) 'tra_asm_inc : Tracer IAU at time step = ', kt,' with IAU weight = ', wgtiau(it)
                WRITE(numout,*) '~~~~~~~~~~~~'
             ENDIF
@@ -741,6 +722,5 @@
             IF (ln_temnofreeze) THEN
                ! Do not apply negative increments if the temperature will fall below freezing
-               WHERE(t_bkginc(:,:,:) > 0.0_wp .OR. &
-                  &   tsn(:,:,:,jp_tem) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
+               WHERE( t_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_tem) + t_bkginc(:,:,:) > fzptnz(:,:,:) ) 
                   tsn(:,:,:,jp_tem) = t_bkg(:,:,:) + t_bkginc(:,:,:)   
                END WHERE
@@ -751,6 +731,5 @@
                ! Do not apply negative increments if the salinity will fall below a specified
                ! minimum value salfixmin
-               WHERE(s_bkginc(:,:,:) > 0.0_wp .OR. &
-                  &   tsn(:,:,:,jp_sal) + s_bkginc(:,:,:) > salfixmin ) 
+               WHERE( s_bkginc(:,:,:) > 0.0_wp .OR. tsn(:,:,:,jp_sal) + s_bkginc(:,:,:) > salfixmin ) 
                   tsn(:,:,:,jp_sal) = s_bkg(:,:,:) + s_bkginc(:,:,:)   
                END WHERE
@@ -759,15 +738,20 @@
             ENDIF
 
-            tsb(:,:,:,:) = tsn(:,:,:,:)               ! Update before fields
-
-            CALL eos( tsb, rhd, rhop, gdept_0(:,:,:) )                ! Before potential and in situ densities
-         
+            tsb(:,:,:,:) = tsn(:,:,:,:)                 ! Update before fields
+
+            CALL eos( tsb, rhd, rhop, gdept_0(:,:,:) )  ! Before potential and in situ densities
+!!gm  fabien
+!            CALL eos( tsb, rhd, rhop )                ! Before potential and in situ densities
+!!gm
+
+
             IF( ln_zps .AND. .NOT. lk_c1d ) &
-               &  CALL zps_hde( nit000, jpts, tsb, &  ! Partial steps: before horizontal derivative
-               &                gtsu, gtsv, rhd,   &  ! of T, S, rd at the bottom ocean level
-               &                gru , grv )
+               &  CALL zps_hde( nit000, jpts, tsb, gtsu, gtsv,  &        ! Partial steps: before horizontal gradient
+               &                rhd, gru , grv, aru, arv, gzu, gzv, ge3ru, ge3rv,  &             !
+               &                gtui, gtvi, grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi  )  ! of t, s, rd at the last ocean level
 
 #if defined key_zdfkpp
             CALL eos( tsn, rhd, fsdept_n(:,:,:) )                      ! Compute rhd
+!!gm fabien            CALL eos( tsn, rhd )                      ! Compute rhd
 #endif
 
