Index: branches/UKMO/dev_r5518_obs_oper_update/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- branches/UKMO/dev_r5518_obs_oper_update/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 14591)
+++ branches/UKMO/dev_r5518_obs_oper_update/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 15254)
@@ -12,4 +12,5 @@
    !!   ini_date     : Compute the initial date YYYYMMDD.HHMMSS
    !!   fin_date     : Compute the final date YYYYMMDD.HHMMSS
+   !!   calc_date    : Get date in YYYYMMDD.HHMMSS format
    !!----------------------------------------------------------------------
    !! * Modules used
@@ -40,8 +41,9 @@
    !! * Routine accessibility
    PRIVATE
-   PUBLIC dia_obs_init, &  ! Initialize and read observations
-      &   dia_obs,      &  ! Compute model equivalent to observations
-      &   dia_obs_wri,  &  ! Write model equivalent to observations
-      &   dia_obs_dealloc  ! Deallocate dia_obs data
+   PUBLIC dia_obs_init,    &  ! Initialize and read observations
+      &   dia_obs,         &  ! Compute model equivalent to observations
+      &   dia_obs_wri,     &  ! Write model equivalent to observations
+      &   dia_obs_dealloc, &  ! Deallocate dia_obs data
+      &   calc_date           ! Compute the date of a timestep
 
    !! * Module variables
@@ -2014,13 +2016,13 @@
    END SUBROUTINE dia_obs_dealloc
 
-   SUBROUTINE ini_date( ddobsini )
+   SUBROUTINE calc_date( kstp, ddobs )
       !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE ini_date  ***
+      !!                    ***  ROUTINE calc_date  ***
+      !!         
+      !! ** Purpose : Get date in double precision YYYYMMDD.HHMMSS format
       !!
-      !! ** Purpose : Get initial date in double precision YYYYMMDD.HHMMSS format
+      !! ** Method  : Get date in double precision YYYYMMDD.HHMMSS format
       !!
-      !! ** Method  : Get initial date in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Action  : Get initial date in double precision YYYYMMDD.HHMMSS format
+      !! ** Action  : Get date in double precision YYYYMMDD.HHMMSS format
       !!
       !! History :
@@ -2030,15 +2032,16 @@
       !!        !  06-10  (G. Smith) Calculates initial date the same as method for final date
       !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!        !  2014-09  (D. Lea) New generic routine now deals with arbitrary initial time of day
       !!----------------------------------------------------------------------
       USE phycst, ONLY : &            ! Physical constants
          & rday
+!      USE daymod, ONLY : &            ! Time variables
+!         & nmonth_len           
       USE dom_oce, ONLY : &           ! Ocean space and time domain variables
          & rdt
-
       IMPLICIT NONE
-
       !! * Arguments
-      REAL(dp), INTENT(OUT) :: ddobsini  ! Initial date in YYYYMMDD.HHMMSS
-
+      REAL(KIND=dp), INTENT(OUT) :: ddobs                        ! Date in YYYYMMDD.HHMMSS
+      INTEGER :: kstp
       !! * Local declarations
       INTEGER :: iyea        ! date - (year, month, day, hour, minute)
@@ -2047,34 +2050,35 @@
       INTEGER :: ihou
       INTEGER :: imin
-      INTEGER :: imday       ! Number of days in month.
-      INTEGER, DIMENSION(12) :: &
-         &       imonth_len  ! Length in days of the months of the current year
-      REAL(wp) :: zdayfrc    ! Fraction of day
-
-      !----------------------------------------------------------------------
-      ! Initial date initialization (year, month, day, hour, minute)
-      ! (This assumes that the initial date is for 00z))
-      !----------------------------------------------------------------------
+      INTEGER :: imday         ! Number of days in month.
+      REAL(KIND=wp) :: zdayfrc ! Fraction of day
+      INTEGER, DIMENSION(12) ::   imonth_len    !: length in days of the months of the current year
+      !!----------------------------------------------------------------------
+      !! Initial date initialization (year, month, day, hour, minute)
+      !!----------------------------------------------------------------------
       iyea =   ndate0 / 10000
       imon = ( ndate0 - iyea * 10000 ) / 100
       iday =   ndate0 - iyea * 10000 - imon * 100
-      ihou = 0
-      imin = 0
-
-      !----------------------------------------------------------------------
-      ! Compute number of days + number of hours + min since initial time
-      !----------------------------------------------------------------------
-      iday = iday + ( nit000 -1 ) * rdt / rday
-      zdayfrc = ( nit000 -1 ) * rdt / rday
+      ihou =   nn_time0 / 100
+      imin = ( nn_time0 - ihou * 100 ) 
+      !!----------------------------------------------------------------------
+      !! Compute number of days + number of hours + min since initial time
+      !!----------------------------------------------------------------------
+      zdayfrc = kstp * rdt / rday
       zdayfrc = zdayfrc - aint(zdayfrc)
-      ihou = int( zdayfrc * 24 )
-      imin = int( (zdayfrc * 24 - ihou) * 60 )
-
-      !-----------------------------------------------------------------------
-      ! Convert number of days (iday) into a real date
-      !----------------------------------------------------------------------
-
+      imin = imin + int( zdayfrc * 24 * 60 ) 
+      DO WHILE (imin >= 60) 
+        imin=imin-60
+        ihou=ihou+1
+      END DO
+      DO WHILE (ihou >= 24)
+        ihou=ihou-24
+        iday=iday+1
+      END DO
+      iday = iday + kstp * rdt / rday 
+      !!-----------------------------------------------------------------------
+      !! Convert number of days (iday) into a real date
+      !!----------------------------------------------------------------------
       CALL calc_month_len( iyea, imonth_len )
-
+     
       DO WHILE ( iday > imonth_len(imon) )
          iday = iday - imonth_len(imon)
@@ -2086,12 +2090,33 @@
          ENDIF
       END DO
-
-      !----------------------------------------------------------------------
-      ! Convert it into YYYYMMDD.HHMMSS format.
-      !----------------------------------------------------------------------
-      ddobsini = iyea * 10000_dp + imon * 100_dp + &
-         &       iday + ihou * 0.01_dp + imin * 0.0001_dp
-
-
+      !!----------------------------------------------------------------------
+      !! Convert it into YYYYMMDD.HHMMSS format.
+      !!----------------------------------------------------------------------
+      ddobs = iyea * 10000_dp + imon * 100_dp + &
+         &    iday + ihou * 0.01_dp + imin * 0.0001_dp
+   END SUBROUTINE calc_date
+
+   SUBROUTINE ini_date( ddobsini )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE ini_date  ***
+      !!         
+      !! ** Purpose : Get initial data in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : Get initial data in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Action  : Get initial data in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! History :
+      !!        !  06-03  (K. Mogensen)  Original code
+      !!        !  06-05  (K. Mogensen)  Reformatted
+      !!        !  06-10  (A. Weaver) Cleaning
+      !!        !  06-10  (G. Smith) Calculates initial date the same as method for final date
+      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!    `   !  2014-09  (D. Lea) New generic routine now deals with arbitrary initial time of day
+      !!----------------------------------------------------------------------
+      IMPLICIT NONE
+      !! * Arguments
+      REAL(KIND=dp), INTENT(OUT) :: ddobsini                   ! Initial date in YYYYMMDD.HHMMSS
+      CALL calc_date( nit000 - 1, ddobsini )
    END SUBROUTINE ini_date
 
@@ -2099,10 +2124,10 @@
       !!----------------------------------------------------------------------
       !!                    ***  ROUTINE fin_date  ***
+      !!         
+      !! ** Purpose : Get final data in double precision YYYYMMDD.HHMMSS format
       !!
-      !! ** Purpose : Get final date in double precision YYYYMMDD.HHMMSS format
+      !! ** Method  : Get final data in double precision YYYYMMDD.HHMMSS format
       !!
-      !! ** Method  : Get final date in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Action  : Get final date in double precision YYYYMMDD.HHMMSS format
+      !! ** Action  : Get final data in double precision YYYYMMDD.HHMMSS format
       !!
       !! History :
@@ -2111,68 +2136,11 @@
       !!        !  06-10  (A. Weaver) Cleaning
       !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!    `   !  2014-09  (D. Lea) New generic routine now deals with arbitrary initial time of day
       !!----------------------------------------------------------------------
-      USE phycst, ONLY : &            ! Physical constants
-         & rday
-      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
-         & rdt
-
       IMPLICIT NONE
-
       !! * Arguments
-      REAL(dp), INTENT(OUT) :: ddobsfin ! Final date in YYYYMMDD.HHMMSS
-
-      !! * Local declarations
-      INTEGER :: iyea        ! date - (year, month, day, hour, minute)
-      INTEGER :: imon
-      INTEGER :: iday
-      INTEGER :: ihou
-      INTEGER :: imin
-      INTEGER :: imday       ! Number of days in month.
-      INTEGER, DIMENSION(12) :: &
-         &       imonth_len  ! Length in days of the months of the current year
-      REAL(wp) :: zdayfrc    ! Fraction of day
-
-      !-----------------------------------------------------------------------
-      ! Initial date initialization (year, month, day, hour, minute)
-      ! (This assumes that the initial date is for 00z)
-      !-----------------------------------------------------------------------
-      iyea =   ndate0 / 10000
-      imon = ( ndate0 - iyea * 10000 ) / 100
-      iday =   ndate0 - iyea * 10000 - imon * 100
-      ihou = 0
-      imin = 0
-
-      !-----------------------------------------------------------------------
-      ! Compute number of days + number of hours + min since initial time
-      !-----------------------------------------------------------------------
-      iday    = iday +  nitend  * rdt / rday
-      zdayfrc =  nitend  * rdt / rday
-      zdayfrc = zdayfrc - AINT( zdayfrc )
-      ihou    = INT( zdayfrc * 24 )
-      imin    = INT( ( zdayfrc * 24 - ihou ) * 60 )
-
-      !-----------------------------------------------------------------------
-      ! Convert number of days (iday) into a real date
-      !----------------------------------------------------------------------
-
-      CALL calc_month_len( iyea, imonth_len )
-
-      DO WHILE ( iday > imonth_len(imon) )
-         iday = iday - imonth_len(imon)
-         imon = imon + 1 
-         IF ( imon > 12 ) THEN
-            imon = 1
-            iyea = iyea + 1
-            CALL calc_month_len( iyea, imonth_len )  ! update month lengths
-         ENDIF
-      END DO
-
-      !-----------------------------------------------------------------------
-      ! Convert it into YYYYMMDD.HHMMSS format
-      !-----------------------------------------------------------------------
-      ddobsfin = iyea * 10000_dp + imon * 100_dp    + iday &
-         &     + ihou * 0.01_dp  + imin * 0.0001_dp
-
-    END SUBROUTINE fin_date
+      REAL(KIND=dp), INTENT(OUT) :: ddobsfin                   ! Final date in YYYYMMDD.HHMMSS
+      CALL calc_date( nitend, ddobsfin )
+   END SUBROUTINE fin_date
 
     SUBROUTINE obs_settypefiles( ntypes, jpmaxnfiles, ifiles, cobstypes, cfiles )
