*IF DEF,CONTROL,OR,DEF,RECON,OR,DEF,SETUP,OR,DEF,COMB,OR,DEF,FLDC          TIM2STP1.2      
C ******************************COPYRIGHT******************************    GTS2F400.10333  
C (c) CROWN COPYRIGHT 1995, METEOROLOGICAL OFFICE, All Rights Reserved.    GTS2F400.10334  
C                                                                          GTS2F400.10335  
C Use, duplication or disclosure of this code is subject to the            GTS2F400.10336  
C restrictions as set forth in the contract.                               GTS2F400.10337  
C                                                                          GTS2F400.10338  
C                Meteorological Office                                     GTS2F400.10339  
C                London Road                                               GTS2F400.10340  
C                BRACKNELL                                                 GTS2F400.10341  
C                Berkshire UK                                              GTS2F400.10342  
C                RG12 2SZ                                                  GTS2F400.10343  
C                                                                          GTS2F400.10344  
C If no contract has been raised with this copy of the code, the use,      GTS2F400.10345  
C duplication or disclosure of it is strictly prohibited.  Permission      GTS2F400.10346  
C to do so must first be obtained in writing from the Head of Numerical    GTS2F400.10347  
C Modelling at the above address.                                          GTS2F400.10348  
C ******************************COPYRIGHT******************************    GTS2F400.10349  
C                                                                          GTS2F400.10350  
CLL  Routine: TIM2STEP -------------------------------------------------   TIM2STP1.3      
CLL                                                                        TIM2STP1.4      
CLL  Purpose: Converts from an integer number of elapsed whole days and    TIM2STP1.5      
CLL           seconds since the model basis time to elapsed timesteps,     TIM2STP1.6      
CLL           given a general definition of the submodel timestep.         TIM2STP1.7      
CLL           Forms a service routine for model date/time and internal     TIM2STP1.8      
CLL           clock purposes, written for 32-bit portability.              TIM2STP1.9      
CLL                                                                        TIM2STP1.10     
CLL  Tested under compiler:   cft77                                        TIM2STP1.11     
CLL  Tested under OS version: UNICOS 6.0                                   TIM2STP1.12     
CLL                                                                        TIM2STP1.13     
CLL  Author:   T.C.Johns                                                   TIM2STP1.14     
CLL                                                                        TIM2STP1.15     
CLL  Model            Modification history from model version 3.2:         TIM2STP1.16     
CLL version  date                                                          TIM2STP1.17     
CLL   3.3  08/02/94  Introduced as new deck in association with changes    TIM2STP1.18     
CLL                  to internal clock for 32-bit portability. TCJ         TIM2STP1.19     
CLL   3.5  07/04/95  Generalise code to allow SECS_IN_PERIOD to be a       GRR2F305.698    
CLL                  value corresponding to an exact multiple or exact     GRR2F305.699    
CLL                  numerator of seconds in a day. Previous code was      GRR2F305.700    
CLL                  only correct for a period of exactly 1 day.           GRR2F305.701    
CLL                  R.Rawlins                                             GRR2F305.702    
CLL                                                                        TIM2STP1.21     
CLL  Programming standard: UM Doc Paper 3, version 1 (15/1/90)             TIM2STP1.22     
CLL                                                                        TIM2STP1.23     
CLL  Logical components covered: S620                                      TIM2STP1.24     
CLL                                                                        TIM2STP1.25     
CLL  Project task: S62                                                     TIM2STP1.26     
CLL                                                                        TIM2STP1.27     
CLL  External documentation: On-line UM document C0 - The top-level        TIM2STP1.28     
CLL                          control system                                TIM2STP1.29     
CLL                                                                        TIM2STP1.30     
CLL  -------------------------------------------------------------------   TIM2STP1.31     
C*L  Interface and arguments: ------------------------------------------   TIM2STP1.32     
C                                                                          TIM2STP1.33     

      SUBROUTINE TIM2STEP(ELAPSED_DAYS,ELAPSED_SECS,                        11TIM2STP1.34     
     &                    STEPS_IN_PERIOD,SECS_IN_PERIOD,                  TIM2STP1.35     
     &                    ELAPSED_STEPS)                                   TIM2STP1.36     
C                                                                          TIM2STP1.37     
      IMPLICIT NONE                                                        TIM2STP1.38     
C                                                                          TIM2STP1.39     
      INTEGER                                                              TIM2STP1.40     
     &     ELAPSED_DAYS,           ! IN  - elapsed days since ref time     TIM2STP1.41     
     &     ELAPSED_SECS,           ! IN  - elapsed secs in part of day     TIM2STP1.42     
C                                  !       or days since ref time          TIM2STP1.43     
     &     STEPS_IN_PERIOD,        ! IN  - steps in period defining T/S    TIM2STP1.44     
     &     SECS_IN_PERIOD,         ! IN  - secs  in period defining T/S    TIM2STP1.45     
     &     ELAPSED_STEPS           ! OUT - elapsed steps since ref time    TIM2STP1.46     
C Local Parameters                                                         GRR2F305.703    
      INTEGER   SECS_IN_DAY        ! no. of seconds in 1 day               GRR2F305.704    
      PARAMETER(SECS_IN_DAY=3600*24)                                       GRR2F305.705    
C Local Scalars                                                            GRR2F305.706    
      INTEGER   FACTOR             ! ratio of integers is exact factor     GRR2F305.707    
CL----------------------------------------------------------------------   TIM2STP1.47     
CL 1. Perform integer arithmetic to compute elapsed steps from elapsed     TIM2STP1.48     
CL    days/seconds and timestep definition.  The subroutine assumes        TIM2STP1.49     
CL    that SECS_IN_PERIOD is a whole number multiple of a day, or a        GRR2F305.708    
CL    whole number divisor of a day, but does not check explicitly.        GRR2F305.709    
CL                                                                         TIM2STP1.52     
      IF(SECS_IN_PERIOD.GE.SECS_IN_DAY) THEN                               GRR2F305.710    
         FACTOR       = SECS_IN_PERIOD/SECS_IN_DAY ! no. days in period    GRR2F305.711    
         ELAPSED_STEPS =                                                   GRR2F305.712    
     *      STEPS_IN_PERIOD*(ELAPSED_DAYS/FACTOR) +                        GRR2F305.713    
     *      (((ELAPSED_DAYS-(ELAPSED_DAYS/FACTOR)*FACTOR)*SECS_IN_DAY +    GRR2F305.714    
     *        ELAPSED_SECS)*STEPS_IN_PERIOD)/SECS_IN_PERIOD                GRR2F305.715    
      ELSE          ! period is less than 1 day                            GRR2F305.716    
         FACTOR       = SECS_IN_DAY/SECS_IN_PERIOD ! no. periods in day    GRR2F305.717    
         ELAPSED_STEPS = ELAPSED_DAYS*STEPS_IN_PERIOD*FACTOR +             GRR2F305.718    
     *                  ELAPSED_SECS/(SECS_IN_PERIOD/STEPS_IN_PERIOD)      GRR2F305.719    
      ENDIF                                                                GRR2F305.720    
C                                                                          TIM2STP1.57     
      RETURN                                                               TIM2STP1.58     
      END                                                                  TIM2STP1.59     
*ENDIF                                                                     TIM2STP1.60