Index: trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 5930)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asmbkg.F90	(revision 6140)
@@ -33,5 +33,5 @@
    USE eosbn2             ! Equation of state (eos_bn2 routine)
    USE zdfmxl             ! Mixed layer depth
-   USE dom_oce, ONLY :   ndastp
+   USE dom_oce     , ONLY :   ndastp
    USE in_out_manager     ! I/O manager
    USE iom                ! I/O module
@@ -44,4 +44,5 @@
    USE ice
 #endif
+
    IMPLICIT NONE
    PRIVATE
Index: trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 5930)
+++ trunk/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 6140)
@@ -11,9 +11,10 @@
    !!             -   ! 2010-05  (D. Lea)  add calc_month_len routine based on day_init 
    !!            3.4  ! 2012-10  (A. Weaver and K. Mogensen) Fix for direct initialization
+   !!                 ! 2014-09  (D. Lea)  Local calc_date removed use routine from OBS
+   !!                 ! 2015-11  (D. Lea)  Handle non-zero initial time of day
    !!----------------------------------------------------------------------
 
    !!----------------------------------------------------------------------
    !!   asm_inc_init   : Initialize the increment arrays and IAU weights
-   !!   calc_date      : Compute the calendar date YYYYMMDD on a given step
    !!   tra_asm_inc    : Apply the tracer (T and S) increments
    !!   dyn_asm_inc    : Apply the dynamic (u and v) increments
@@ -38,4 +39,5 @@
 #endif
    USE sbc_oce          ! Surface boundary condition variables.
+   USE diaobs, ONLY: calc_date     ! Compute the calendar date on a given step
 
    IMPLICIT NONE
@@ -43,5 +45,4 @@
    
    PUBLIC   asm_inc_init   !: Initialize the increment arrays and IAU weights
-   PUBLIC   calc_date      !: Compute the calendar date YYYYMMDD on a given step
    PUBLIC   tra_asm_inc    !: Apply the tracer (T and S) increments
    PUBLIC   dyn_asm_inc    !: Apply the dynamic (u and v) increments
@@ -87,8 +88,7 @@
 
    !! * Substitutions
-#  include "domzgr_substitute.h90"
 #  include "vectopt_loop_substitute.h90"
    !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
    !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
@@ -111,10 +111,10 @@
       INTEGER :: iiauper         ! Number of time steps in the IAU period
       INTEGER :: icycper         ! Number of time steps in the cycle
-      INTEGER :: iitend_date     ! Date YYYYMMDD of final time step
-      INTEGER :: iitbkg_date     ! Date YYYYMMDD of background time step for Jb term
-      INTEGER :: iitdin_date     ! Date YYYYMMDD of background time step for DI
-      INTEGER :: iitiaustr_date  ! Date YYYYMMDD of IAU interval start time step
-      INTEGER :: iitiaufin_date  ! Date YYYYMMDD of IAU interval final time step
-      !
+      REAL(KIND=dp) :: ditend_date     ! Date YYYYMMDD.HHMMSS of final time step
+      REAL(KIND=dp) :: ditbkg_date     ! Date YYYYMMDD.HHMMSS of background time step for Jb term
+      REAL(KIND=dp) :: ditdin_date     ! Date YYYYMMDD.HHMMSS of background time step for DI
+      REAL(KIND=dp) :: ditiaustr_date  ! Date YYYYMMDD.HHMMSS of IAU interval start time step
+      REAL(KIND=dp) :: ditiaufin_date  ! Date YYYYMMDD.HHMMSS of IAU interval final time step
+
       REAL(wp) :: znorm        ! Normalization factor for IAU weights
       REAL(wp) :: ztotwgt      ! Value of time-integrated IAU weights (should be equal to one)
@@ -178,10 +178,19 @@
       icycper = nitend      - nit000      + 1  ! Cycle interval length
 
-      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
-      !
+      ! Date of final time step
+      CALL calc_date( nitend, ditend_date )
+
+      ! Background time for Jb referenced to ndate0
+      CALL calc_date( nitbkg_r, ditbkg_date )
+
+      ! Background time for DI referenced to ndate0
+      CALL calc_date( nitdin_r, ditdin_date )
+
+      ! IAU start time referenced to ndate0
+      CALL calc_date( nitiaustr_r, ditiaustr_date )
+
+      ! IAU end time referenced to ndate0
+      CALL calc_date( nitiaufin_r, ditiaufin_date )
+
       IF(lwp) THEN
          WRITE(numout,*)
@@ -198,15 +207,12 @@
          WRITE(numout,*) '       ndastp         = ', ndastp
          WRITE(numout,*) '       ndate0         = ', ndate0
-         WRITE(numout,*) '       iitend_date    = ', iitend_date
-         WRITE(numout,*) '       iitbkg_date    = ', iitbkg_date
-         WRITE(numout,*) '       iitdin_date    = ', iitdin_date
-         WRITE(numout,*) '       iitiaustr_date = ', iitiaustr_date
-         WRITE(numout,*) '       iitiaufin_date = ', iitiaufin_date
+         WRITE(numout,*) '       nn_time0       = ', nn_time0
+         WRITE(numout,*) '       ditend_date    = ', ditend_date
+         WRITE(numout,*) '       ditbkg_date    = ', ditbkg_date
+         WRITE(numout,*) '       ditdin_date    = ', ditdin_date
+         WRITE(numout,*) '       ditiaustr_date = ', ditiaustr_date
+         WRITE(numout,*) '       ditiaufin_date = ', ditiaufin_date
       ENDIF
 
-      IF ( nacc /= 0 ) &
-         & CALL ctl_stop( ' nacc /= 0 and key_asminc :',  &
-         &                ' Assimilation increments have only been implemented', &
-         &                ' for synchronous time stepping' )
 
       IF ( ( ln_asmdin ).AND.( ln_asmiau ) )   &
@@ -360,15 +366,15 @@
             WRITE(numout,*) 
             WRITE(numout,*) 'asm_inc_init : Assimilation increments valid ', &
-               &            ' between dates ', NINT( z_inc_dateb ),' and ',  &
-               &            NINT( z_inc_datef )
+               &            ' between dates ', z_inc_dateb,' and ',  &
+               &            z_inc_datef
             WRITE(numout,*) '~~~~~~~~~~~~'
          ENDIF
 
-         IF (     ( NINT( z_inc_dateb ) < ndastp      ) &
-            & .OR.( NINT( z_inc_datef ) > iitend_date ) ) &
+         IF (     ( z_inc_dateb < ndastp + nn_time0*0.0001_wp ) &
+            & .OR.( z_inc_datef > ditend_date ) ) &
             & CALL ctl_warn( ' Validity time of assimilation increments is ', &
             &                ' outside the assimilation interval' )
 
-         IF ( ( ln_asmdin ).AND.( NINT( zdate_inc ) /= iitdin_date ) ) &
+         IF ( ( ln_asmdin ).AND.( zdate_inc /= ditdin_date ) ) &
             & CALL ctl_warn( ' Validity time of assimilation increments does ', &
             &                ' not agree with Direct Initialization time' )
@@ -430,14 +436,12 @@
          DO jt = 1, nn_divdmp
             !
-            DO jk = 1, jpkm1
+            DO jk = 1, jpkm1           ! hdiv = e1e1 * div
                hdiv(:,:) = 0._wp
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     hdiv(ji,jj) =   &
-                        (  e2u(ji  ,jj  ) * fse3u(ji  ,jj  ,jk) * u_bkginc(ji  ,jj  ,jk)     &
-                         - e2u(ji-1,jj  ) * fse3u(ji-1,jj  ,jk) * u_bkginc(ji-1,jj  ,jk)     &
-                         + e1v(ji  ,jj  ) * fse3v(ji  ,jj  ,jk) * v_bkginc(ji  ,jj  ,jk)     &
-                         - e1v(ji  ,jj-1) * fse3v(ji  ,jj-1,jk) * v_bkginc(ji  ,jj-1,jk)  )  &
-                         / ( e1e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     hdiv(ji,jj) = (  e2u(ji  ,jj) * e3u_n(ji  ,jj,jk) * u_bkginc(ji  ,jj,jk)    &
+                        &           - e2u(ji-1,jj) * e3u_n(ji-1,jj,jk) * u_bkginc(ji-1,jj,jk)    &
+                        &           + e1v(ji,jj  ) * e3v_n(ji,jj  ,jk) * v_bkginc(ji,jj  ,jk)    &
+                        &           - e1v(ji,jj-1) * e3v_n(ji,jj-1,jk) * v_bkginc(ji,jj-1,jk)  ) / e3t_n(ji,jj,jk)
                   END DO
                END DO
@@ -446,10 +450,8 @@
                DO jj = 2, jpjm1
                   DO ji = fs_2, fs_jpim1   ! vector opt.
-                     u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk) + 0.2_wp * ( e1e2t(ji+1,jj) * hdiv(ji+1,jj)   &
-                        &                                               - e1e2t(ji  ,jj) * hdiv(ji  ,jj) ) &
-                        &                                             * r1_e1u(ji,jj) * umask(ji,jj,jk) 
-                     v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk) + 0.2_wp * ( e1e2t(ji,jj+1) * hdiv(ji,jj+1)   &
-                        &                                               - e1e2t(ji,jj  ) * hdiv(ji,jj  ) ) &
-                        &                                             * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
+                     u_bkginc(ji,jj,jk) = u_bkginc(ji,jj,jk)                         &
+                        &               + 0.2_wp * ( hdiv(ji+1,jj) - hdiv(ji  ,jj) ) * r1_e1u(ji,jj) * umask(ji,jj,jk)
+                     v_bkginc(ji,jj,jk) = v_bkginc(ji,jj,jk)                         &
+                        &               + 0.2_wp * ( hdiv(ji,jj+1) - hdiv(ji,jj  ) ) * r1_e2v(ji,jj) * vmask(ji,jj,jk) 
                   END DO
                END DO
@@ -490,9 +492,10 @@
          IF(lwp) THEN
             WRITE(numout,*) 
-            WRITE(numout,*) 'asm_inc_init : Assimilation background state valid at : ', NINT( zdate_bkg )
+            WRITE(numout,*) 'asm_inc_init : Assimilation background state valid at : ', &
+               &  zdate_bkg
             WRITE(numout,*) '~~~~~~~~~~~~'
          ENDIF
          !
-         IF ( NINT( zdate_bkg ) /= iitdin_date ) &
+         IF ( zdate_bkg /= ditdin_date ) &
             & CALL ctl_warn( ' Validity time of assimilation background state does', &
             &                ' not agree with Direct Initialization time' )
@@ -522,106 +525,4 @@
       !
    END SUBROUTINE asm_inc_init
-
-
-   SUBROUTINE calc_date( kit000, kt, kdate0, kdate )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE calc_date  ***
-      !!          
-      !! ** Purpose : Compute the calendar date YYYYMMDD at a given time step.
-      !!
-      !! ** Method  : Compute the calendar date YYYYMMDD at a given time step.
-      !!
-      !! ** Action  : 
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(IN) :: kit000  ! Initial time step
-      INTEGER, INTENT(IN) :: kt      ! Current time step referenced to kit000
-      INTEGER, INTENT(IN) :: kdate0  ! Initial date
-      INTEGER, INTENT(OUT) :: kdate  ! Current date reference to kdate0
-      !
-      INTEGER :: iyea0    ! Initial year
-      INTEGER :: imon0    ! Initial month
-      INTEGER :: iday0    ! Initial day
-      INTEGER :: iyea     ! Current year
-      INTEGER :: imon     ! Current month
-      INTEGER :: iday     ! Current day
-      INTEGER :: idaystp  ! Number of days between initial and current date
-      INTEGER :: idaycnt  ! Day counter
-
-      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
-
-      !-----------------------------------------------------------------------
-      ! Compute the calendar date YYYYMMDD
-      !-----------------------------------------------------------------------
-
-      ! Initial date
-      iyea0 =   kdate0 / 10000
-      imon0 = ( kdate0 - ( iyea0 * 10000 ) ) / 100
-      iday0 =   kdate0 - ( iyea0 * 10000 ) - ( imon0 * 100 ) 
-
-      ! Check that kt >= kit000 - 1
-      IF ( kt < kit000 - 1 ) CALL ctl_stop( ' kt must be >= kit000 - 1')
-
-      ! If kt = kit000 - 1 then set the date to the restart date
-      IF ( kt == kit000 - 1 ) THEN
-         kdate = ndastp
-         RETURN
-      ENDIF
-
-      ! Compute the number of days from the initial date
-      idaystp = INT( REAL( kt - kit000 ) * rdt / 86400. )
-   
-      iday    = iday0
-      imon    = imon0
-      iyea    = iyea0
-      idaycnt = 0
-
-      CALL calc_month_len( iyea, imonth_len )
-
-      DO WHILE ( idaycnt < idaystp )
-         iday = iday + 1
-         IF ( iday > imonth_len(imon) )  THEN
-            iday = 1
-            imon = imon + 1
-         ENDIF
-         IF ( imon > 12 ) THEN
-            imon = 1
-            iyea = iyea + 1
-            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
-         ENDIF                 
-         idaycnt = idaycnt + 1
-      END DO
-      !
-      kdate = iyea * 10000 + imon * 100 + iday
-      !
-   END SUBROUTINE
-
-
-   SUBROUTINE calc_month_len( iyear, imonth_len )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE calc_month_len  ***
-      !!          
-      !! ** Purpose : Compute the number of days in a months given a year.
-      !!
-      !! ** Method  : 
-      !!----------------------------------------------------------------------
-      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
-      INTEGER :: iyear         !: year
-      !!----------------------------------------------------------------------
-      !
-      ! length of the month of the current year (from nleapy, read in namelist)
-      IF ( nleapy < 2 ) THEN 
-         imonth_len(:) = (/ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /)
-         IF ( nleapy == 1 ) THEN   ! we are using calendar with leap years
-            IF ( MOD(iyear, 4) == 0 .AND. ( MOD(iyear, 400) == 0 .OR. MOD(iyear, 100) /= 0 ) ) THEN
-               imonth_len(2) = 29
-            ENDIF
-         ENDIF
-      ELSE
-         imonth_len(:) = nleapy   ! all months with nleapy days per year
-      ENDIF
-      !
-   END SUBROUTINE
-
-
    SUBROUTINE tra_asm_inc( kt )
       !!----------------------------------------------------------------------
@@ -645,5 +546,5 @@
       ! used to prevent the applied increments taking the temperature below the local freezing point 
       DO jk = 1, jpkm1
-        CALL eos_fzp( tsn(:,:,jk,jp_sal), fzptnz(:,:,jk), fsdept(:,:,jk) )
+        CALL eos_fzp( tsn(:,:,jk,jp_sal), fzptnz(:,:,jk), gdept_n(:,:,jk) )
       END DO
          !
@@ -726,15 +627,11 @@
 !!gm
 
-            IF( ln_zps .AND. .NOT. lk_c1d ) THEN      ! Partial steps: before horizontal gradient
-               IF(ln_isfcav) THEN                        ! ocean cavities: top and bottom cells (ISF)
-                  CALL zps_hde_isf( nit000, jpts, tsb, gtsu, gtsv, gtui, gtvi,     &
-                     &                            rhd, gru , grv , aru , arv , gzu , gzv , ge3ru , ge3rv ,   &
-                     &                     grui, grvi, arui, arvi, gzui, gzvi, ge3rui, ge3rvi    )
-               ELSE                                      ! no ocean cavities: bottom cells
-                  CALL zps_hde    ( kt, jpts, tsb, gtsu, gtsv,        &  ! 
-                     &                        rhd, gru , grv          )  ! of t, s, rd at the last ocean level
-               ENDIF
-            ENDIF
-            !
+            IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav)      &
+               &  CALL zps_hde    ( kt, jpts, tsb, gtsu, gtsv,        &  ! Partial steps: before horizontal gradient
+               &                              rhd, gru , grv          )  ! of t, s, rd at the last ocean level
+            IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav)      &
+               &  CALL zps_hde_isf( nit000, jpts, tsb, gtsu, gtsv, gtui, gtvi,    &    ! Partial steps for top cell (ISF)
+               &                                  rhd, gru , grv , grui, grvi     )    ! of t, s, rd at the last ocean level
+
             DEALLOCATE( t_bkginc )
             DEALLOCATE( s_bkginc )
@@ -874,10 +771,6 @@
             !
             sshb(:,:) = sshn(:,:)                        ! Update before fields
-            !
-            IF( lk_vvl ) THEN
-               DO jk = 1, jpk
-                  fse3t_b(:,:,jk) = fse3t_n(:,:,jk)
-               END DO
-            ENDIF
+            e3t_b(:,:,:) = e3t_n(:,:,:)
+!!gm why not e3u_b, e3v_b, gdept_b ????
             !
             DEALLOCATE( ssh_bkg    )
