| 1 |
jmc |
1.9 |
C $Header: /u/gcmpack/MITgcm/pkg/cal/cal_toseconds.F,v 1.8 2010/03/16 00:11:46 jmc Exp $ |
| 2 |
edhill |
1.5 |
C $Name: $ |
| 3 |
heimbach |
1.1 |
|
| 4 |
edhill |
1.5 |
#include "CAL_OPTIONS.h" |
| 5 |
heimbach |
1.1 |
|
| 6 |
jmc |
1.9 |
SUBROUTINE CAL_TOSECONDS( |
| 7 |
heimbach |
1.1 |
I date, |
| 8 |
|
|
O timeint, |
| 9 |
jmc |
1.9 |
I myThid ) |
| 10 |
heimbach |
1.1 |
|
| 11 |
jmc |
1.9 |
C ================================================================== |
| 12 |
|
|
C SUBROUTINE cal_ToSeconds |
| 13 |
|
|
C ================================================================== |
| 14 |
|
|
C |
| 15 |
|
|
C o Given a time interval as a date array return the number of |
| 16 |
|
|
C seconds in that time interval. |
| 17 |
|
|
C |
| 18 |
|
|
C If one wanted to use calendar dates in this routine, then |
| 19 |
|
|
C the date should be after the calendar refdate and timeint |
| 20 |
|
|
C would be the number of seconds that have elapsed since the |
| 21 |
|
|
C refdate. Of course this can also be done by first calling |
| 22 |
|
|
C sub cal_TimePassed and then calling this routine with the |
| 23 |
|
|
C resulting time interval array. |
| 24 |
|
|
C |
| 25 |
|
|
C started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
| 26 |
|
|
C changed: Christian Eckert eckert@mit.edu 29-Dec-1999 |
| 27 |
|
|
C - restructured the original version in order to have a |
| 28 |
|
|
C better interface to the MITgcmUV. |
| 29 |
|
|
C Christian Eckert eckert@mit.edu 03-Feb-2000 |
| 30 |
|
|
C - Introduced new routine and function names, cal_<NAME>, |
| 31 |
|
|
C for verion 0.1.3. |
| 32 |
|
|
C 21-Sep-2003: fixed check_sign logic to work with |
| 33 |
|
|
C negative intervals (menemenlis@jpl.nasa.gov) |
| 34 |
|
|
C |
| 35 |
|
|
C ================================================================== |
| 36 |
|
|
C SUBROUTINE cal_ToSeconds |
| 37 |
|
|
C ================================================================== |
| 38 |
heimbach |
1.1 |
|
| 39 |
jmc |
1.9 |
IMPLICIT NONE |
| 40 |
heimbach |
1.1 |
|
| 41 |
jmc |
1.9 |
C == global variables == |
| 42 |
|
|
#include "EEPARAMS.h" |
| 43 |
heimbach |
1.1 |
#include "cal.h" |
| 44 |
|
|
|
| 45 |
jmc |
1.9 |
C == routine arguments == |
| 46 |
|
|
INTEGER date(4) |
| 47 |
heimbach |
1.1 |
_RL timeint |
| 48 |
jmc |
1.9 |
INTEGER myThid |
| 49 |
heimbach |
1.1 |
|
| 50 |
jmc |
1.9 |
C == local variables == |
| 51 |
dimitri |
1.7 |
_RL fac, nsecs, ndays |
| 52 |
jmc |
1.9 |
INTEGER ierr, check_sign, hhmmss |
| 53 |
|
|
CHARACTER*(MAX_LEN_MBUF) msgBuf |
| 54 |
|
|
C == end of interface == |
| 55 |
heimbach |
1.1 |
|
| 56 |
cheisey |
1.2 |
c print *,'cal_toseconds: date',date |
| 57 |
|
|
c print *,'cal_toseconds: timeint',timeint |
| 58 |
heimbach |
1.1 |
|
| 59 |
jmc |
1.9 |
IF ( cal_setStatus .LT. 1 ) THEN |
| 60 |
|
|
WRITE( msgBuf,'(2A,4I9)') 'CAL_TOSECONDS: ', |
| 61 |
|
|
& 'date=',date(1),date(2),date(3),date(4) |
| 62 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
| 63 |
|
|
WRITE( msgBuf,'(2A,I2,A)') 'CAL_TOSECONDS: ', |
| 64 |
|
|
& 'called too early (cal_setStatus=',cal_setStatus,' )' |
| 65 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
| 66 |
|
|
STOP 'ABNORMAL END: S/R CAL_CONVDATE' |
| 67 |
|
|
ENDIF |
| 68 |
|
|
|
| 69 |
dimitri |
1.4 |
check_sign = 1 |
| 70 |
|
|
if ( ( (date(1).lt.0) .and. date(2).gt.0 ) .or. |
| 71 |
|
|
& ( (date(1).gt.0) .and. date(2).lt.0 ) ) |
| 72 |
|
|
& check_sign = -1 |
| 73 |
|
|
|
| 74 |
cheisey |
1.2 |
if (((date(4) .eq. -1) .and. |
| 75 |
heimbach |
1.1 |
& (date(3) .eq. 0) .and. |
| 76 |
dimitri |
1.3 |
& (check_sign .ge. 0)) .or. |
| 77 |
cheisey |
1.2 |
& usingModelCalendar) then |
| 78 |
heimbach |
1.1 |
if ((date(1) .lt. 0) .or. |
| 79 |
|
|
& (date(2) .lt. 0)) then |
| 80 |
|
|
ndays = -date(1) |
| 81 |
|
|
hhmmss = -date(2) |
| 82 |
|
|
fac = -1 |
| 83 |
|
|
else |
| 84 |
|
|
ndays = date(1) |
| 85 |
|
|
hhmmss = date(2) |
| 86 |
|
|
fac = 1 |
| 87 |
|
|
endif |
| 88 |
|
|
nsecs = ndays*secondsperday + |
| 89 |
|
|
& (hhmmss/10000)*secondsperhour + |
| 90 |
|
|
& mod(hhmmss/100,100)*secondsperminute + |
| 91 |
|
|
& mod(hhmmss,100) |
| 92 |
|
|
timeint = fac*nsecs |
| 93 |
|
|
else |
| 94 |
|
|
|
| 95 |
|
|
ierr = 1001 |
| 96 |
jmc |
1.9 |
call cal_PrintError( ierr, myThid ) |
| 97 |
heimbach |
1.1 |
stop ' stopped in cal_ToSeconds.' |
| 98 |
|
|
|
| 99 |
|
|
endif |
| 100 |
|
|
|
| 101 |
jmc |
1.9 |
RETURN |
| 102 |
|
|
END |