*IF DEF,SCMA                                                               S_TIMCAL.2      
C *****************************COPYRIGHT******************************     S_TIMCAL.3      
C (c) CROWN COPYRIGHT 1998, METEOROLOGICAL OFFICE, All Rights Reserved.    S_TIMCAL.4      
C                                                                          S_TIMCAL.5      
C Use, duplication or disclosure of this code is subject to the            S_TIMCAL.6      
C restrictions as set forth in the contract.                               S_TIMCAL.7      
C                                                                          S_TIMCAL.8      
C                Meteorological Office                                     S_TIMCAL.9      
C                London Road                                               S_TIMCAL.10     
C                BRACKNELL                                                 S_TIMCAL.11     
C                Berkshire UK                                              S_TIMCAL.12     
C                RG12 2SZ                                                  S_TIMCAL.13     
C                                                                          S_TIMCAL.14     
C If no contract has been raised with this copy of the code, the use,      S_TIMCAL.15     
C duplication or disclosure of it is strictly prohibited.  Permission      S_TIMCAL.16     
C to do so must first be obtained in writing from the Head of Numerical    S_TIMCAL.17     
C Modelling at the above address.                                          S_TIMCAL.18     
C ******************************COPYRIGHT******************************    S_TIMCAL.19     
C                                                                          S_TIMCAL.20     
C     Routine to calculate the year in run and actual time and             S_TIMCAL.21     
C     daynumber in year.                                                   S_TIMCAL.22     
C                                                                          S_TIMCAL.23     
C     Modification History:                                                S_TIMCAL.24     
C Version  Date                                                            S_TIMCAL.25     
C  4.5     07/98     SCM integrated as a standard UM configuration         S_TIMCAL.26     
C                    JC Thil.                                              S_TIMCAL.27     
C---------------------------------------------------------------------     S_TIMCAL.28     

      Subroutine TIMECALC(year_init, dayno_init, time_init, timestep        2,2S_TIMCAL.29     
     &  ,time_string, lcal360, year, day, time_sec)                        S_TIMCAL.30     
C                                                                          S_TIMCAL.31     
      Implicit none                                                        S_TIMCAL.32     
                                                                           S_TIMCAL.33     
C     Arguments                                                            S_TIMCAL.34     
      Integer                                                              S_TIMCAL.35     
     &  year_init               ! IN year at model start                   S_TIMCAL.36     
     &  ,dayno_init             ! IN daynumber in year of start of         S_TIMCAL.37     
                                !  of the model                            S_TIMCAL.38     
      Real                                                                 S_TIMCAL.39     
     &  time_init               ! IN start time in day of the              S_TIMCAL.40     
                                !  model (seconds).                        S_TIMCAL.41     
     &  ,timestep               ! IN no. of secs. between physics          S_TIMCAL.42     
      Logical                                                              S_TIMCAL.43     
     &  lcal360                 ! IN true in 360 idealized year            S_TIMCAL.44     
                                                                           S_TIMCAL.45     
      Real                                                                 S_TIMCAL.46     
     &  time_sec                ! OUT actual time of day in secs.          S_TIMCAL.47     
                                !    timesteps.                            S_TIMCAL.48     
      Integer                                                              S_TIMCAL.49     
     &  year                    ! OUT year                                 S_TIMCAL.50     
     &  ,day                    ! OUT day in year                          S_TIMCAL.51     
      Character*8                                                          S_TIMCAL.52     
     &  time_string             ! OUT actual time in day XX..XX..XX        S_TIMCAL.53     
                                !                        hr..mn..se        S_TIMCAL.54     
C     Local Variables                                                      S_TIMCAL.55     
      Integer                                                              S_TIMCAL.56     
     &  time,                   ! Seconds elapsed since model ref          S_TIMCAL.57     
                                !  time.                                   S_TIMCAL.58     
     &  timesec, timemin                                                   S_TIMCAL.59     
     &  ,timehr                                                            S_TIMCAL.60     
     &  ,elapsed_days           ! Days elapsed since model reference       S_TIMCAL.61     
                                !  time                                    S_TIMCAL.62     
     &  ,elapsed_secs           ! Seconds in day                           S_TIMCAL.63     
     &  ,month, day_m                                                      S_TIMCAL.64     
     &  ,basis_time_days        !                                          S_TIMCAL.65     
     &  ,basis_time_secs        ! Basis time of the model.                 S_TIMCAL.66     
     &  ,timestep_count         ! Counter for timesteps                    S_TIMCAL.67     
      Data timestep_count /0/   ! Initialise to 1                          S_TIMCAL.68     
C                                                                          S_TIMCAL.69     
      time_string = '00.00.00'  ! total secs. up to start                  S_TIMCAL.70     
                                !  of this timestep                        S_TIMCAL.71     
                                                                           S_TIMCAL.72     
      time = 24*3600*(dayno_init) + time_init                              S_TIMCAL.73     
     &  +    (timestep_count * timestep)                                   S_TIMCAL.74     
      elapsed_days = int(time/(24*3600))                                   S_TIMCAL.75     
      elapsed_secs = time - (elapsed_days * (24*3600))                     S_TIMCAL.76     
                                                                           S_TIMCAL.77     
      Call TIME2SEC(year_init-1, 12, 31, 0, 0, 0,                          S_TIMCAL.78     
     &  0, 0, basis_time_days, basis_time_secs, lcal360)                   S_TIMCAL.79     
                                                                           S_TIMCAL.80     
      Call SEC2TIME(elapsed_days, elapsed_secs                             S_TIMCAL.81     
     &  ,basis_time_days, basis_time_secs                                  S_TIMCAL.82     
     &  ,year, month, day_m, timehr, timemin, timesec                      S_TIMCAL.83     
     &  ,day, lcal360)                                                     S_TIMCAL.84     
                                                                           S_TIMCAL.85     
                                                                           S_TIMCAL.86     
C                                                                          S_TIMCAL.87     
C     Set up time string for O/P with diagnostics                          S_TIMCAL.88     
C                                                                          S_TIMCAL.89     
      Write (time_string(1:2), '(i2)') timehr                              S_TIMCAL.90     
      Write (time_string(4:5), '(i2)') timemin                             S_TIMCAL.91     
      Write (time_string(7:8), '(i2)') timesec                             S_TIMCAL.92     
      time_sec = timehr*3600 + timemin*60 + timesec                        S_TIMCAL.93     
C                                                                          S_TIMCAL.94     
C     Increase timestep count as routine entered every timestep.           S_TIMCAL.95     
C                                                                          S_TIMCAL.96     
      timestep_count = timestep_count + 1                                  S_TIMCAL.97     
C                                                                          S_TIMCAL.98     
      Return                                                               S_TIMCAL.99     
      End                       ! Subroutine TIMECALC                      S_TIMCAL.100    
*ENDIF                                                                     S_TIMCAL.101