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 15254 for branches/UKMO/dev_r5518_obs_oper_update/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90 – NEMO

Ignore:
Timestamp:
2021-09-14T13:37:21+02:00 (3 years ago)
Author:
jroberts
Message:

Changes manually merged from https://forge.ipsl.jussieu.fr/nemo/browser/branches/UKMO/dev_r5518_GO6_package_STARTHOUR?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/UKMO/dev_r5518_obs_oper_update/NEMOGCM/NEMO/OPA_SRC/DOM/daymod.F90

    r7960 r15254  
    7373      !!---------------------------------------------------------------------- 
    7474      ! 
     75      ! max number of seconds between each restart 
     76      IF( REAL( nitend - nit000 + 1 ) * rdt > REAL( HUGE( nsec1jan000 ) ) ) THEN 
     77         CALL ctl_stop( 'The number of seconds between each restart exceeds the integer 4 max value: 2^31-1. ',   & 
     78            &           'You must do a restart at higher frequency (or remove this stop and recompile the code in I8)' ) 
     79      ENDIF 
    7580      ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0 
    7681      IF( MOD( rday     , rdttra(1) ) /= 0. )   CALL ctl_stop( 'the time step must devide the number of second of in a day' ) 
     
    9095      nday    =   ndastp - (nyear * 10000) - ( nmonth * 100 ) 
    9196 
    92       CALL ymds2ju( nyear, nmonth, nday, 0.0, fjulday )  ! we assume that we start run at 00:00 
     97      nhour   =   nn_time0 / 100 
     98      nminute = ( nn_time0 - nhour * 100 ) 
     99 
     100      CALL ymds2ju( nyear, nmonth, nday, nhour*3600._wp+nminute*60._wp, fjulday )   
    93101      IF( ABS(fjulday - REAL(NINT(fjulday),wp)) < 0.1 / rday )   fjulday = REAL(NINT(fjulday),wp)   ! avoid truncation error 
    94       fjulday = fjulday + 1.                             ! move back to the day at nit000 (and not at nit000 - 1) 
     102      IF(nhour*3600 + nminute*60 - ndt05 .lt. 0)   fjulday = fjulday + 1.                    ! move back to the day at nit000 (and not at nit000 - 1) 
    95103 
    96104      nsec1jan000 = 0 
     
    113121      !compute number of days between last monday and today 
    114122      CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (our reference that was a Monday) 
    115       inbday = NINT(fjulday - zjul)            ! compute nb day between  01.01.1900 and current day 
     123      inbday = FLOOR(fjulday - zjul)            ! compute nb day between  01.01.1900 and start of current day 
    116124      idweek = MOD(inbday, 7)                  ! compute nb day between last monday and current day 
     125      IF (idweek .lt. 0) idweek=idweek+7       ! Avoid negative values for dates before 01.01.1900 
    117126 
    118127      ! number of seconds since the beginning of current year/month/week/day at the middle of the time-step 
    119       nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step 
    120       nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step 
    121       nsec_week  = idweek    * nsecd - ndt05 
    122       nsec_day   =             nsecd - ndt05 
     128      IF (nhour*3600+nminute*60-ndt05 .gt. 0) THEN 
     129         ! 1 timestep before current middle of first time step is still the same day 
     130         nsec_year  = (nday_year-1) * nsecd + nhour*3600+nminute*60 - ndt05  
     131         nsec_month = (nday-1)      * nsecd + nhour*3600+nminute*60 - ndt05     
     132      ELSE 
     133         ! 1 time step before the middle of the first time step is the previous day  
     134         nsec_year  = nday_year * nsecd + nhour*3600+nminute*60 - ndt05  
     135         nsec_month = nday      * nsecd + nhour*3600+nminute*60 - ndt05    
     136      ENDIF 
     137      nsec_week  = idweek    * nsecd + nhour*3600+nminute*60 - ndt05 
     138      nsec_day   =             nhour*3600+nminute*60 - ndt05  
     139      IF( nsec_day .lt. 0 ) nsec_day = nsec_day + nsecd 
     140      IF( nsec_week .lt. 0 ) nsec_week = nsec_week + nsecd*7 
    123141 
    124142      ! control print 
    125       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 = ',   & 
    126            &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week 
     143      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 = ',   & 
     144           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week, '  & 
     145           &                   nsec_month:', nsec_month , '  nsec_year:' , nsec_year 
    127146 
    128147      ! Up to now, calendar parameters are related to the end of previous run (nit000-1) 
     
    238257               nday_year = 1 
    239258               nsec_year = ndt05 
    240                IF( nsec1jan000 >= 2 * (2**30 - nsecd * nyear_len(1) / 2 ) ) THEN   ! test integer 4 max value 
    241                   CALL ctl_stop( 'The number of seconds between Jan. 1st 00h of nit000 year and Jan. 1st 00h ',   & 
    242                      &           'of the current year is exceeding the INTEGER 4 max VALUE: 2^31-1 -> 68.09 years in seconds', & 
    243                      & 'You must do a restart at higher frequency (or remove this STOP and recompile everything in I8)' ) 
    244                ENDIF 
    245259               nsec1jan000 = nsec1jan000 + nsecd * nyear_len(1) 
    246260               IF( nleapy == 1 )   CALL day_mth 
     
    302316      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag 
    303317      ! 
    304       REAL(wp) ::   zkt, zndastp 
     318      REAL(wp) ::   zkt, zndastp, zdayfrac, ksecs, ktime 
     319      INTEGER  ::   ihour, iminute 
    305320      !!---------------------------------------------------------------------- 
    306321 
     
    309324         IF( iom_varid( numror, 'kt', ldstop = .FALSE. ) > 0 ) THEN 
    310325            ! Get Calendar informations 
     326            IF(nn_timing == 2)  CALL timing_start('iom_rstget') 
    311327            CALL iom_get( numror, 'kt', zkt )   ! last time-step of previous run 
     328            IF(nn_timing == 2)  CALL timing_stop('iom_rstget') 
    312329            IF(lwp) THEN 
    313330               WRITE(numout,*) ' *** Info read in restart : ' 
     
    327344            ! define ndastp and adatrj 
    328345            IF ( nrstdt == 2 ) THEN 
     346               IF(nn_timing == 2)  CALL timing_start('iom_rstget') 
    329347               ! read the parameters correspondting to nit000 - 1 (last time step of previous run) 
    330348               CALL iom_get( numror, 'ndastp', zndastp ) 
    331349               ndastp = NINT( zndastp ) 
    332350               CALL iom_get( numror, 'adatrj', adatrj  ) 
     351          CALL iom_get( numror, 'ntime', ktime ) 
     352               IF(nn_timing == 2)  CALL timing_stop('iom_rstget') 
     353          nn_time0=INT(ktime) 
     354               ! calculate start time in hours and minutes 
     355          zdayfrac=adatrj-INT(adatrj) 
     356          ksecs = NINT(zdayfrac*86400)        ! Nearest second to catch rounding errors in adatrj          
     357          ihour = INT(ksecs/3600) 
     358          iminute = ksecs/60-ihour*60 
     359            
     360               ! Add to nn_time0 
     361               nhour   =   nn_time0 / 100 
     362               nminute = ( nn_time0 - nhour * 100 ) 
     363          nminute=nminute+iminute 
     364           
     365          IF( nminute >= 60 ) THEN 
     366             nminute=nminute-60 
     367        nhour=nhour+1 
     368          ENDIF 
     369          nhour=nhour+ihour 
     370          IF( nhour >= 24 ) THEN 
     371        nhour=nhour-24 
     372             adatrj=adatrj+1 
     373          ENDIF           
     374          nn_time0 = nhour * 100 + nminute 
     375          adatrj = INT(adatrj)                    ! adatrj set to integer as nn_time0 updated           
    333376            ELSE 
    334                ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day) 
    335                ndastp = ndate0 - 1     ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00 
     377               ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day) 
     378               ndastp = ndate0        ! ndate0 read in the namelist in dom_nam 
     379               nhour   =   nn_time0 / 100 
     380               nminute = ( nn_time0 - nhour * 100 ) 
     381               IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
    336382               adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
    337383               ! note this is wrong if time step has changed during run 
    338384            ENDIF 
    339385         ELSE 
    340             ! parameters correspondting to nit000 - 1 (as we start the step loop with a call to day) 
    341             ndastp = ndate0 - 1        ! ndate0 read in the namelist in dom_nam, we assume that we start run at 00:00 
     386            ! parameters corresponding to nit000 - 1 (as we start the step loop with a call to day) 
     387            ndastp = ndate0           ! ndate0 read in the namelist in dom_nam 
     388            nhour   =   nn_time0 / 100 
     389            nminute = ( nn_time0 - nhour * 100 ) 
     390            IF( nhour*3600+nminute*60-ndt05 .lt. 0 )  ndastp=ndastp-1      ! Start hour is specified in the namelist (default 0) 
    342391            adatrj = ( REAL( nit000-1, wp ) * rdttra(1) ) / rday 
    343392         ENDIF 
     
    348397            WRITE(numout,*) '   date ndastp                                      : ', ndastp 
    349398            WRITE(numout,*) '   number of elapsed days since the begining of run : ', adatrj 
     399            WRITE(numout,*) '   nn_time0                                         : ',nn_time0 
    350400            WRITE(numout,*) 
    351401         ENDIF 
     
    359409         ENDIF 
    360410         ! calendar control 
     411         IF(nn_timing == 2)  CALL timing_start('iom_rstput') 
    361412         CALL iom_rstput( kt, nitrst, numrow, 'kt'     , REAL( kt    , wp) )   ! time-step 
    362413         CALL iom_rstput( kt, nitrst, numrow, 'ndastp' , REAL( ndastp, wp) )   ! date 
    363414         CALL iom_rstput( kt, nitrst, numrow, 'adatrj' , adatrj            )   ! number of elapsed days since 
    364415         !                                                                     ! the begining of the run [s] 
     416         CALL iom_rstput( kt, nitrst, numrow, 'ntime'  , REAL( nn_time0, wp) ) ! time 
     417         IF(nn_timing == 2)  CALL timing_stop('iom_rstput') 
    365418      ENDIF 
    366419      ! 
Note: See TracChangeset for help on using the changeset viewer.