New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 5872 for branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90 – NEMO

Ignore:
Timestamp:
2015-11-09T19:20:54+01:00 (8 years ago)
Author:
djlea
Message:

Fixes to enable restartability for runs of less than one day.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2014/dev_r4650_UKMO7_STARTHOUR/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90

    r5164 r5872  
    1111   !!                 ! 2004-01  (A.M. Treguier) new calculation based on adatrj 
    1212   !!                 ! 2006-08  (G. Madec)  surface module major update 
     13   !!                 ! 2015-11  (D. Lea) Allow non-zero initial time of day 
    1314   !!---------------------------------------------------------------------- 
    1415 
     
    9091      nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
    9192 
    92       CALL ymds2ju( nyear, nmonth, nday, nn_time0*3600._wp, fjulday )   
     93      nhour   =   nn_time0 / 100 
     94      nminute = ( nn_time0 - nhour * 100 ) 
     95 
     96      CALL ymds2ju( nyear, nmonth, nday, nhour*3600._wp+nminute*60._wp, fjulday )   
    9397      IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error 
    9498      IF( nn_time0*3600 - ndt05 .lt. 0 ) fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1) 
     
    118122 
    119123      ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step 
    120       IF (nn_time0*3600-ndt05 .gt. 0) THEN 
     124      IF (nhour*3600+nminute*60-ndt05 .gt. 0) THEN 
    121125         ! 1 timestep before current middle of first time step is still the same day 
    122          nsec_year  = (nday_year-1) * nsecd + nn_time0*3600._wp - ndt05  
    123          nsec_month = (nday-1)      * nsecd + nn_time0*3600._wp - ndt05     
     126         nsec_year  = (nday_year-1) * nsecd + nhour*3600+nminute*60 - ndt05  
     127         nsec_month = (nday-1)      * nsecd + nhour*3600+nminute*60 - ndt05     
    124128      ELSE 
    125129         ! 1 time step before the middle of the first time step is the previous day  
    126          nsec_year  = nday_year * nsecd + nn_time0*3600._wp - ndt05  
    127          nsec_month = nday      * nsecd + nn_time0*3600._wp - ndt05    
    128       ENDIF 
    129       nsec_week  = idweek    * nsecd + nn_time0*3600._wp - ndt05 
    130       nsec_day   =             nn_time0*3600._wp - ndt05  
     130         nsec_year  = nday_year * nsecd + nhour*3600+nminute*60 - ndt05  
     131         nsec_month = nday      * nsecd + nhour*3600+nminute*60 - ndt05    
     132      ENDIF 
     133      nsec_week  = idweek    * nsecd + nhour*3600+nminute*60 - ndt05 
     134      nsec_day   =             nhour*3600+nminute*60 - ndt05  
    131135      IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd 
    132136      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7 
     
    313317      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag 
    314318      ! 
    315       REAL(wp) ::   zkt, zndastp 
     319      REAL(wp) ::   zkt, zndastp, zdayfrac, ksecs, ktime 
     320      INTEGER  ::   ihour, iminute 
    316321      !!---------------------------------------------------------------------- 
    317322 
     
    342347               ndastp = NINT( zndastp ) 
    343348               CALL iom_get( numror, 'adatrj', adatrj  ) 
     349          CALL iom_get( numror, 'ntime', ktime ) 
     350          nn_time0=INT(ktime) 
     351               ! calculate start time in hours and minutes 
     352          zdayfrac=adatrj-INT(adatrj) 
     353          ksecs = NINT(zdayfrac*86400)        ! Nearest second to catch rounding errors in adatrj          
     354          ihour = INT(ksecs/3600) 
     355          iminute = ksecs/60-ihour*60 
     356            
     357               ! Add to nn_time0 
     358               nhour   =   nn_time0 / 100 
     359               nminute = ( nn_time0 - nhour * 100 ) 
     360          nminute=nminute+iminute 
     361           
     362          IF( nminute >= 60 ) THEN 
     363             nminute=nminute-60 
     364        nhour=nhour+1 
     365          ENDIF 
     366          nhour=nhour+ihour 
     367          IF( nhour >= 24 ) THEN 
     368        nhour=nhour-24 
     369             adatrj=adatrj+1 
     370          ENDIF           
     371          nn_time0 = nhour * 100 + nminute 
     372          adatrj = INT(adatrj)                    ! adatrj set to integer as nn_time0 updated           
    344373            ELSE 
    345374               ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day) 
    346375               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam 
    347                IF( nn_time0*3600-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
     376               nhour   =   nn_time0 / 100 
     377               nminute = ( nn_time0 - nhour * 100 ) 
     378               IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
    348379               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
    349380               ! note this is wrong if time step has changed during run 
     
    352383            ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day) 
    353384            ndastp = ndate0           ! ndate0 read in the namelist in dom_nam 
    354             IF( nn_time0*3600-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
     385            nhour   =   nn_time0 / 100 
     386       nminute = ( nn_time0 - nhour * 100 ) 
     387            IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
    355388            adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
    356389         ENDIF 
     
    361394            WRITE(numout,*) '   date ndastp                                      : ', ndastp 
    362395            WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj 
     396       WRITE(numout,*) '   nn_time0                                         : ',nn_time0 
    363397            WRITE(numout,*) 
    364398         ENDIF 
     
    376410         CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since 
    377411         !                                                                     ! the begining of the run [s] 
     412    CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time 
    378413      ENDIF 
    379414      ! 
Note: See TracChangeset for help on using the changeset viewer.