Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5997)
@@ -31,4 +31,5 @@
    nn_itend    =    5475   !  last  time step (std 5475)
    nn_date0    =  010101   !  date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_time0    =       0   !  initial time of day in hhmm
    nn_leapy    =       0   !  Leap year calendar (1) or not (0)
    ln_rstart   = .false.   !  start from rest (F) or from a restart file (T)
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/ASM/asminc.F90	(revision 5997)
@@ -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
@@ -111,10 +112,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 +179,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,9 +208,10 @@
          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
 
@@ -360,15 +371,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' )
@@ -490,9 +501,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 +534,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 )
       !!----------------------------------------------------------------------
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/BDY/bdytides.F90	(revision 5997)
@@ -57,5 +57,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id$ 
+   !! $Id$
    !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
@@ -323,7 +323,7 @@
       ENDIF
 
-      IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. zflag==1 ) THEN
+      IF ( (nsec_day == NINT(0.5_wp * rdttra(1)) .OR. kt==nit000) .AND. zflag==1 ) THEN
         !
-        kt_tide = kt
+        kt_tide = kt - (nsec_day - 0.5_wp * rdttra(1))/rdttra(1)
         !
         IF(lwp) THEN
@@ -438,7 +438,7 @@
             ! We refresh nodal factors every day below
             ! This should be done somewhere else
-            IF ( nsec_day == NINT(0.5_wp * rdttra(1)) .AND. lk_first_btstp ) THEN
-               !
-               kt_tide = kt               
+            IF ( ( nsec_day == NINT(0.5_wp * rdttra(1)) .OR. kt==nit000 ) .AND. lk_first_btstp ) THEN
+               !
+               kt_tide = kt - (nsec_day - 0.5_wp * rdttra(1))/rdttra(1)
                !
                IF(lwp) THEN
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90	(revision 5997)
@@ -11,4 +11,5 @@
    !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj
    !!                 ! 2006-08  (G. Madec)  surface module major update
+   !!                 ! 2015-11  (D. Lea) Allow non-zero initial time of day
    !!----------------------------------------------------------------------
 
@@ -95,7 +96,10 @@
       nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 )
 
-      CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00
+      nhour   =   nn_time0 / 100
+      nminute = ( nn_time0 - nhour * 100 )
+
+      CALL ymds2ju( nyear, nmonth, nday, nhour*3600._wp+nminute*60._wp, fjulday )  
       IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error
-      fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1)
+      IF( nn_time0*3600 - ndt05 .lt. 0 ) fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1)
 
       nsec1jan000 = 0
@@ -118,16 +122,27 @@
       !compute number of days between last monday and today
       CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday)
-      inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day
+      inbday = FLOOR(fjulday - zjul)            ! compute nb day between  01.01.1900 and start of current day
       idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day
+      IF (idweek .lt. 0) idweek=idweek+7       ! Avoid negative values for dates before 01.01.1900
 
       ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step
-      nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step
-      nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step
-      nsec_week  = idweek    * nsecd - ndt05
-      nsec_day   =             nsecd - ndt05
+      IF (nhour*3600+nminute*60-ndt05 .gt. 0) THEN
+         ! 1 timestep before current middle of first time step is still the same day
+         nsec_year  = (nday_year-1) * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = (nday-1)      * nsecd + nhour*3600+nminute*60 - ndt05    
+      ELSE
+         ! 1 time step before the middle of the first time step is the previous day 
+         nsec_year  = nday_year * nsecd + nhour*3600+nminute*60 - ndt05 
+         nsec_month = nday      * nsecd + nhour*3600+nminute*60 - ndt05   
+      ENDIF
+      nsec_week  = idweek    * nsecd + nhour*3600+nminute*60 - ndt05
+      nsec_day   =             nhour*3600+nminute*60 - ndt05 
+      IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd
+      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7
 
       ! control print
-      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
+      IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i8,a,i8,a,i8,a,i8)')' =======>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  &
+           &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year
 
       ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
@@ -302,5 +317,6 @@
       CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
       !
-      REAL(wp) ::   zkt, zndastp
+      REAL(wp) ::   zkt, zndastp, zdayfrac, ksecs, ktime
+      INTEGER  ::   ihour, iminute
       !!----------------------------------------------------------------------
 
@@ -327,17 +343,47 @@
             ! define ndastp and adatrj
             IF ( nrstdt == 2 ) THEN
-               ! read the parameters correspondting to nit000 - 1 (last time step of previous run)
+               ! read the parameters corresponding to nit000 - 1 (last time step of previous run)
                CALL iom_get( numror, 'ndastp', zndastp )
                ndastp = NINT( zndastp )
                CALL iom_get( numror, 'adatrj', adatrj  )
+	       CALL iom_get( numror, 'ntime', ktime )
+	       nn_time0=INT(ktime)
+               ! calculate start time in hours and minutes
+	       zdayfrac=adatrj-INT(adatrj)
+	       ksecs = NINT(zdayfrac*86400)	       ! Nearest second to catch rounding errors in adatrj	       
+	       ihour = INT(ksecs/3600)
+	       iminute = ksecs/60-ihour*60
+ 	        
+               ! Add to nn_time0
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+	       nminute=nminute+iminute
+	       
+	       IF( nminute >= 60 ) THEN
+	          nminute=nminute-60
+		  nhour=nhour+1
+	       ENDIF
+	       nhour=nhour+ihour
+	       IF( nhour >= 24 ) THEN
+		  nhour=nhour-24
+	          adatrj=adatrj+1
+	       ENDIF	       
+	       nn_time0 = nhour * 100 + nminute
+	       adatrj = INT(adatrj)                    ! adatrj set to integer as nn_time0 updated	       
             ELSE
-               ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-               ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
+               ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam
+               nhour   =   nn_time0 / 100
+               nminute = ( nn_time0 - nhour * 100 )
+               IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
                adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
                ! note this is wrong if time step has changed during run
             ENDIF
          ELSE
-            ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day)
-            ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00
+            ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day)
+            ndastp = ndate0           ! ndate0 read in the namelist in dom_nam
+            nhour   =   nn_time0 / 100
+	    nminute = ( nn_time0 - nhour * 100 )
+            IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0)
             adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday
          ENDIF
@@ -348,4 +394,5 @@
             WRITE(numout,*) '   date ndastp                                      : ', ndastp
             WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj
+	    WRITE(numout,*) '   nn_time0                                         : ',nn_time0
             WRITE(numout,*)
          ENDIF
@@ -363,4 +410,5 @@
          CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since
          !                                                                     ! the begining of the run [s]
+	 CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time
       ENDIF
       !
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 5997)
@@ -271,4 +271,6 @@
    INTEGER , PUBLIC ::   nmonth        !: current month
    INTEGER , PUBLIC ::   nday          !: current day of the month
+   INTEGER , PUBLIC ::   nhour         !: current hour
+   INTEGER , PUBLIC ::   nminute       !: current minute
    INTEGER , PUBLIC ::   ndastp        !: time step date in yyyymmdd format
    INTEGER , PUBLIC ::   nday_year     !: current day counted from jan 1st of the current year
@@ -307,5 +309,5 @@
    !!----------------------------------------------------------------------
    !! NEMO/OPA 4.0 , NEMO Consortium (2011)
-   !! $Id$ 
+   !! $Id$
    !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
    !!----------------------------------------------------------------------
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/DOM/domain.F90	(revision 5997)
@@ -136,7 +136,8 @@
       USE ioipsl
       NAMELIST/namrun/ cn_ocerst_indir, cn_ocerst_outdir, nn_stocklist, ln_rst_list,               &
-         &             nn_no   , cn_exp    , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl,   &
-         &             nn_it000, nn_itend  , nn_date0    , nn_leapy     , nn_istate , nn_stock ,   &
-         &             nn_write, ln_dimgnnn, ln_mskland  , ln_cfmeta    , ln_clobber, nn_chunksz, nn_euler
+                       nn_no   , cn_exp  , cn_ocerst_in, cn_ocerst_out, ln_rstart , nn_rstctl ,  &
+         &             nn_it000, nn_itend, nn_date0    , nn_time0     , nn_leapy  , nn_istate ,  &
+         &             nn_stock, nn_write, ln_dimgnnn  , ln_mskland   , ln_clobber, nn_chunksz,  &
+         &             nn_euler, ln_cfmeta
       NAMELIST/namdom/ nn_bathy, rn_bathy , rn_e3zps_min, rn_e3zps_rat, nn_msh, rn_hmin,   &
          &             nn_acc   , rn_atfp     , rn_rdt      , rn_rdtmin ,                  &
@@ -178,4 +179,5 @@
          WRITE(numout,*) '      number of the last time step    nn_itend   = ', nn_itend
          WRITE(numout,*) '      initial calendar date aammjj    nn_date0   = ', nn_date0
+         WRITE(numout,*) '      initial time of day in hhmm     nn_time0   = ', nn_time0
          WRITE(numout,*) '      leap year calendar (0/1)        nn_leapy   = ', nn_leapy
          WRITE(numout,*) '      initial state output            nn_istate  = ', nn_istate
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/IOM/in_out_manager.F90	(revision 5997)
@@ -37,4 +37,5 @@
    INTEGER       ::   nn_itend         !: index of the last time step
    INTEGER       ::   nn_date0         !: initial calendar date aammjj
+   INTEGER       ::   nn_time0         !: initial time of day in hhmm
    INTEGER       ::   nn_leapy         !: Leap year calendar flag (0/1 or 30)
    INTEGER       ::   nn_istate        !: initial state output flag (0/1)
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/diaobs.F90	(revision 5997)
@@ -12,4 +12,5 @@
    !!   dia_obs      : Compute model equivalent to observations
    !!   dia_obs_wri  : Write observational diagnostics
+   !!   calc_date    : Compute the date of timestep in YYYYMMDD.HHMMSS format
    !!   ini_date     : Compute the initial date YYYYMMDD.HHMMSS
    !!   fin_date     : Compute the final date YYYYMMDD.HHMMSS
@@ -51,5 +52,6 @@
       &   dia_obs,      &  ! Compute model equivalent to observations
       &   dia_obs_wri,  &  ! Write model equivalent to observations
-      &   dia_obs_dealloc  ! Deallocate dia_obs data
+      &   dia_obs_dealloc, &  ! Deallocate dia_obs data
+      &   calc_date           ! Compute the date of a timestep
 
    !! * Shared Module variables
@@ -218,28 +220,29 @@
       !-----------------------------------------------------------------------
       
-      !Initalise all values in namelist arrays 
-      enactfiles(:) = '' 
-      coriofiles(:) = '' 
-      profbfiles(:) = '' 
-      slafilesact(:) = '' 
-      slafilespas(:) = '' 
-      slafbfiles(:) = '' 
-      sstfiles(:)   = '' 
-      sstfbfiles(:) = '' 
-      seaicefiles(:) = '' 
-      velcurfiles(:) = '' 
-      velavcurfiles(:) = '' 
-      velhrcurfiles(:) = '' 
-      velavadcpfiles(:) = '' 
-      velhradcpfiles(:) = '' 
-      velfbfiles(:) = '' 
+      !Initalise all values in namelist arrays
+      enactfiles(:) = ''
+      coriofiles(:) = ''
+      profbfiles(:) = ''
+      slafilesact(:) = ''
+      slafilespas(:) = ''
+      slafbfiles(:) = ''
+      sstfiles(:)   = ''
+      sstfbfiles(:) = ''
+      seaicefiles(:) = ''
+      velcurfiles(:) = ''
       veladcpfiles(:) = ''
-      sstbias_files(:) = ''  
-      endailyavtypes(:) = -1 
-      endailyavtypes(1) = 820 
-      ln_profb_ena(:) = .FALSE. 
-      ln_profb_enatim(:) = .TRUE. 
-      ln_velfb_av(:) = .FALSE. 
-      ln_ignmis = .FALSE. 
+      velavcurfiles(:) = ''
+      velhrcurfiles(:) = ''
+      velavadcpfiles(:) = ''
+      velhradcpfiles(:) = ''
+      velfbfiles(:) = ''
+      velcurfiles(:) = ''
+      veladcpfiles(:) = ''
+      endailyavtypes(:) = -1
+      endailyavtypes(1) = 820
+      ln_profb_ena(:) = .FALSE.
+      ln_profb_enatim(:) = .TRUE.
+      ln_velfb_av(:) = .FALSE.
+      ln_ignmis = .FALSE.      
 
       CALL ini_date( dobsini )
@@ -1484,13 +1487,13 @@
    END SUBROUTINE dia_obs_dealloc
 
-   SUBROUTINE ini_date( ddobsini )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE ini_date  ***
+   SUBROUTINE calc_date( kstp, ddobs )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE calc_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
+      !! ** Purpose : Get date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : Get date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Action  : Get date in double precision YYYYMMDD.HHMMSS format
       !!
       !! History :
@@ -1500,4 +1503,5 @@
       !!        !  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
@@ -1511,5 +1515,6 @@
 
       !! * Arguments
-      REAL(KIND=dp), INTENT(OUT) :: ddobsini                         ! Initial date in YYYYMMDD.HHMMSS
+      REAL(KIND=dp), INTENT(OUT) :: ddobs                        ! Date in YYYYMMDD.HHMMSS
+      INTEGER :: kstp
 
       !! * Local declarations
@@ -1526,20 +1531,26 @@
       !!----------------------------------------------------------------------
       !! 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
+      ihou =   nn_time0 / 100
+      imin = ( nn_time0 - ihou * 100 ) 
 
       !!----------------------------------------------------------------------
       !! Compute number of days + number of hours + min since initial time
       !!----------------------------------------------------------------------
-      iday = iday + ( nit000 -1 ) * rdt / rday
-      zdayfrc = ( nit000 -1 ) * rdt / rday
+      zdayfrc = kstp * rdt / rday
       zdayfrc = zdayfrc - aint(zdayfrc)
-      ihou = int( zdayfrc * 24 )
-      imin = int( (zdayfrc * 24 - ihou) * 60 )
+      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 
 
       !!-----------------------------------------------------------------------
@@ -1562,19 +1573,18 @@
       !! Convert it into YYYYMMDD.HHMMSS format.
       !!----------------------------------------------------------------------
-      ddobsini = iyea * 10000_dp + imon * 100_dp + &
-         &       iday + ihou * 0.01_dp + imin * 0.0001_dp
-
-
-   END SUBROUTINE ini_date
-
-   SUBROUTINE fin_date( ddobsfin )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE fin_date  ***
+      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 final data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Method  : Get final data in double precision YYYYMMDD.HHMMSS format
-      !!
-      !! ** Action  : Get final data in double precision YYYYMMDD.HHMMSS format
+      !! ** Purpose : Get initial date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
       !!
       !! History :
@@ -1583,11 +1593,33 @@
       !!        !  06-10  (A. Weaver) Cleaning
       !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
-      !!----------------------------------------------------------------------
-      USE phycst, ONLY : &            ! Physical constants
-         & rday
-!      USE daymod, ONLY : &            ! Time variables
-!         & nmonth_len                
-      USE dom_oce, ONLY : &           ! Ocean space and time domain variables
-         & rdt
+      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
+      !!----------------------------------------------------------------------
+
+      IMPLICIT NONE
+
+      !! * Arguments
+      REAL(KIND=dp), INTENT(OUT) :: ddobsini                   ! Initial date in YYYYMMDD.HHMMSS
+
+      CALL calc_date( nit000 - 1, ddobsini )
+
+   END SUBROUTINE ini_date
+
+   SUBROUTINE fin_date( ddobsfin )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE fin_date  ***
+      !!          
+      !! ** Purpose : Get final date in double precision YYYYMMDD.HHMMSS format
+      !!
+      !! ** Method  : 
+      !!
+      !! ** Action  : 
+      !!
+      !! History :
+      !!        !  06-03  (K. Mogensen)  Original code
+      !!        !  06-05  (K. Mogensen)  Reformatted
+      !!        !  06-10  (A. Weaver) Cleaning
+      !!        !  10-05  (D. Lea) Update to month length calculation for NEMO vn3.2
+      !!        !  2014-09  (D. Lea) Change to call generic routine calc_date
+      !!----------------------------------------------------------------------
 
       IMPLICIT NONE
@@ -1596,57 +1628,7 @@
       REAL(KIND=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.
-      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)
-      ! (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
-    
+      CALL calc_date( nitend, ddobsfin )
+
+   END SUBROUTINE fin_date
+   
 END MODULE diaobs
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/OBS/obs_prep.F90	(revision 5997)
@@ -128,6 +128,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 =   nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -400,6 +400,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 =   nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -588,6 +588,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 =   nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -773,6 +773,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 =   nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
@@ -971,6 +971,6 @@
       imon0 = ( ndate0 - iyea0 * 10000 ) / 100
       iday0 =   ndate0 - iyea0 * 10000 - imon0 * 100
-      ihou0 = 0
-      imin0 = 0
+      ihou0 =   nn_time0 / 100
+      imin0 = ( nn_time0 - ihou0 * 100 )
 
       icycle = no     ! Assimilation cycle
Index: /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90
===================================================================
--- /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 5996)
+++ /branches/2015/dev_MetOffice_merge_2015/NEMOGCM/NEMO/OPA_SRC/SBC/sbctide.F90	(revision 5997)
@@ -46,7 +46,8 @@
       INTEGER, INTENT( in ) ::   kt     ! ocean time-step
       INTEGER               ::   jk     ! dummy loop index
+      INTEGER               ::   nsec_day_orig     ! Temporary variable
       !!----------------------------------------------------------------------
-
-      IF( nsec_day == NINT(0.5_wp * rdttra(1)) ) THEN      ! start a new day
+      
+      IF( nsec_day == NINT(0.5_wp * rdttra(1)) .OR. kt == nit000 ) THEN      ! start a new day
          !
          IF( kt == nit000 ) THEN
@@ -59,7 +60,16 @@
          pot_astro(:,:) = 0._wp
          !
+         ! If the run does not start from midnight then need to initialise tides
+         ! at the start of the current day (only occurs when kt==nit000)
+         ! Temporarily set nsec_day to beginning of day.
+         nsec_day_orig = nsec_day
+         IF ( nsec_day /= NINT(0.5_wp * rdttra(1)) ) THEN 
+            kt_tide = kt - (nsec_day - 0.5_wp * rdttra(1))/rdttra(1)
+            nsec_day = NINT(0.5_wp * rdttra(1))
+         ELSE
+            kt_tide = kt 
+         ENDIF
          CALL tide_harmo( omega_tide, v0tide, utide, ftide, ntide, nb_harmo )
          !
-         kt_tide = kt
          !
          IF(lwp) THEN
@@ -74,4 +84,6 @@
          IF( ln_tide_pot )   CALL tide_init_potential
          !
+         ! Reset nsec_day
+         nsec_day = nsec_day_orig 
       ENDIF
       !
