Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:38:17 UTC

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
6d54cf9ca1 Ed H*0001 #include "CAL_OPTIONS.h"
a63ed37559 Patr*0002 
d0c66b198b Jean*0003       SUBROUTINE CAL_TOSECONDS(
a63ed37559 Patr*0004      I                          date,
                0005      O                          timeint,
d0c66b198b Jean*0006      I                          myThid )
                0007 
                0008 C     ==================================================================
                0009 C     SUBROUTINE cal_ToSeconds
                0010 C     ==================================================================
                0011 C
                0012 C     o Given a time interval as a date array return the number of
                0013 C       seconds in that time interval.
                0014 C
                0015 C       If one wanted to use calendar dates in this routine, then
                0016 C       the date should be after the calendar refdate and timeint
                0017 C       would be the number of seconds that have elapsed since the
                0018 C       refdate. Of course this can also be done by first calling
                0019 C       sub cal_TimePassed and then calling this routine with the
                0020 C       resulting time interval array.
                0021 C
                0022 C     started: Christian Eckert eckert@mit.edu  30-Jun-1999
                0023 C     changed: Christian Eckert eckert@mit.edu  29-Dec-1999
                0024 C              - restructured the original version in order to have a
                0025 C                better interface to the MITgcmUV.
                0026 C              Christian Eckert eckert@mit.edu  03-Feb-2000
                0027 C              - Introduced new routine and function names, cal_<NAME>,
                0028 C                for verion 0.1.3.
                0029 C              21-Sep-2003: fixed check_sign logic to work with
                0030 C              negative intervals (menemenlis@jpl.nasa.gov)
                0031 C
                0032 C     ==================================================================
                0033 C     SUBROUTINE cal_ToSeconds
                0034 C     ==================================================================
                0035 
                0036       IMPLICIT NONE
                0037 
                0038 C     == global variables ==
                0039 #include "EEPARAMS.h"
a63ed37559 Patr*0040 #include "cal.h"
                0041 
d0c66b198b Jean*0042 C     == routine arguments ==
                0043       INTEGER date(4)
a63ed37559 Patr*0044       _RL     timeint
d0c66b198b Jean*0045       INTEGER myThid
a63ed37559 Patr*0046 
d0c66b198b Jean*0047 C     == local variables ==
434c2252b7 Dimi*0048       _RL     fac, nsecs, ndays
d0c66b198b Jean*0049       INTEGER ierr, check_sign, hhmmss
                0050       CHARACTER*(MAX_LEN_MBUF) msgBuf
                0051 C     == end of interface ==
a63ed37559 Patr*0052 
df219ab40a Curt*0053 c     print *,'cal_toseconds: date',date
                0054 c     print *,'cal_toseconds: timeint',timeint
a63ed37559 Patr*0055 
d0c66b198b Jean*0056       IF ( cal_setStatus .LT. 1 ) THEN
                0057         WRITE( msgBuf,'(2A,4I9)') 'CAL_TOSECONDS: ',
                0058      &       'date=',date(1),date(2),date(3),date(4)
                0059         CALL PRINT_ERROR( msgBuf, myThid )
                0060         WRITE( msgBuf,'(2A,I2,A)') 'CAL_TOSECONDS: ',
                0061      &    'called too early (cal_setStatus=',cal_setStatus,' )'
                0062         CALL PRINT_ERROR( msgBuf, myThid )
                0063         STOP 'ABNORMAL END: S/R CAL_CONVDATE'
                0064       ENDIF
                0065 
b52b3e8d0d Dimi*0066       check_sign = 1
                0067       if ( ( (date(1).lt.0) .and. date(2).gt.0 ) .or.
                0068      &     ( (date(1).gt.0) .and. date(2).lt.0 ) )
                0069      &     check_sign = -1
                0070 
df219ab40a Curt*0071       if (((date(4) .eq. -1) .and.
a63ed37559 Patr*0072      &    (date(3) .eq.  0) .and.
34fdea0d95 Dimi*0073      &    (check_sign .ge. 0)) .or.
df219ab40a Curt*0074      &    usingModelCalendar) then
a63ed37559 Patr*0075         if ((date(1) .lt. 0) .or.
                0076      &      (date(2) .lt. 0)) then
                0077           ndays  = -date(1)
                0078           hhmmss = -date(2)
                0079           fac    = -1
                0080         else
                0081           ndays  = date(1)
                0082           hhmmss = date(2)
                0083           fac    = 1
                0084         endif
                0085         nsecs   = ndays*secondsperday +
                0086      &            (hhmmss/10000)*secondsperhour +
                0087      &            mod(hhmmss/100,100)*secondsperminute +
                0088      &            mod(hhmmss,100)
                0089         timeint = fac*nsecs
                0090       else
                0091 
                0092         ierr = 1001
d0c66b198b Jean*0093         call cal_PrintError( ierr, myThid )
a63ed37559 Patr*0094         stop ' stopped in cal_ToSeconds.'
                0095 
                0096       endif
                0097 
d0c66b198b Jean*0098       RETURN
                0099       END