1 |
jmc |
1.6 |
C $Header: /u/gcmpack/MITgcm/pkg/cal/cal_convdate.F,v 1.5 2012/04/07 16:21:05 jmc Exp $ |
2 |
edhill |
1.4 |
C $Name: $ |
3 |
heimbach |
1.1 |
|
4 |
edhill |
1.4 |
#include "CAL_OPTIONS.h" |
5 |
heimbach |
1.1 |
|
6 |
jmc |
1.5 |
SUBROUTINE CAL_CONVDATE( |
7 |
heimbach |
1.1 |
I date, |
8 |
|
|
O yy, mm, dd, ss, |
9 |
|
|
O lp, wd, |
10 |
jmc |
1.5 |
I myThid ) |
11 |
heimbach |
1.1 |
|
12 |
jmc |
1.5 |
C ================================================================== |
13 |
|
|
C SUBROUTINE cal_ConvDate |
14 |
|
|
C ================================================================== |
15 |
|
|
C |
16 |
|
|
C o Decompose the first part of a date array. |
17 |
|
|
C |
18 |
|
|
C started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
19 |
|
|
C changed: Christian Eckert eckert@mit.edu 29-Dec-1999 |
20 |
|
|
C - restructured the original version in order to have a |
21 |
|
|
C better interface to the MITgcmUV. |
22 |
|
|
C Christian Eckert eckert@mit.edu 03-Feb-2000 |
23 |
|
|
C - Introduced new routine and function names, cal_<NAME>, |
24 |
|
|
C for verion 0.1.3. |
25 |
|
|
C 21-Sep-2003: fixed check_sign logic to work with |
26 |
|
|
C negative intervals (menemenlis@jpl.nasa.gov) |
27 |
|
|
C |
28 |
|
|
C ================================================================== |
29 |
|
|
C SUBROUTINE cal_ConvDate |
30 |
|
|
C ================================================================== |
31 |
heimbach |
1.1 |
|
32 |
jmc |
1.5 |
IMPLICIT NONE |
33 |
heimbach |
1.1 |
|
34 |
jmc |
1.5 |
C == global variables == |
35 |
|
|
#include "EEPARAMS.h" |
36 |
heimbach |
1.1 |
#include "cal.h" |
37 |
|
|
|
38 |
jmc |
1.5 |
C == routine arguments == |
39 |
|
|
INTEGER date(4) |
40 |
jmc |
1.6 |
INTEGER yy, mm, dd |
41 |
|
|
INTEGER ss, lp, wd |
42 |
jmc |
1.5 |
INTEGER myThid |
43 |
|
|
|
44 |
|
|
C == local variables == |
45 |
|
|
INTEGER fac |
46 |
|
|
INTEGER date_1 |
47 |
|
|
INTEGER date_2 |
48 |
|
|
INTEGER ierr |
49 |
jmc |
1.6 |
LOGICAL wrong_sign |
50 |
jmc |
1.5 |
CHARACTER*(MAX_LEN_MBUF) msgBuf |
51 |
|
|
C == end of interface == |
52 |
|
|
|
53 |
|
|
IF ( cal_setStatus .LT. 1 ) THEN |
54 |
|
|
WRITE( msgBuf,'(2A,4I9)') 'CAL_CONVDATE: ', |
55 |
|
|
& 'date=',date(1),date(2),date(3),date(4) |
56 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
57 |
|
|
WRITE( msgBuf,'(2A,I2,A)') 'CAL_CONVDATE: ', |
58 |
|
|
& 'called too early (cal_setStatus=',cal_setStatus,' )' |
59 |
|
|
CALL PRINT_ERROR( msgBuf, myThid ) |
60 |
|
|
STOP 'ABNORMAL END: S/R CAL_CONVDATE' |
61 |
|
|
ENDIF |
62 |
heimbach |
1.1 |
|
63 |
jmc |
1.6 |
C Check the sign of the date. |
64 |
heimbach |
1.1 |
fac = 1 |
65 |
jmc |
1.6 |
wrong_sign = ( (date(1).lt.0) .and. date(2).gt.0 ) |
66 |
|
|
& .OR. ( (date(1).gt.0) .and. date(2).lt.0 ) |
67 |
heimbach |
1.1 |
|
68 |
jmc |
1.6 |
if ( wrong_sign ) then |
69 |
|
|
ierr = 901 |
70 |
|
|
call cal_PrintError( ierr, myThid ) |
71 |
|
|
stop ' stopped in cal_ConvDate.' |
72 |
|
|
else |
73 |
|
|
if ( date(1).lt.0 .OR. date(2).lt.0 ) then |
74 |
heimbach |
1.1 |
date_1 = -date(1) |
75 |
|
|
date_2 = -date(2) |
76 |
|
|
fac = -1 |
77 |
|
|
else |
78 |
|
|
date_1 = date(1) |
79 |
|
|
date_2 = date(2) |
80 |
|
|
fac = 1 |
81 |
|
|
endif |
82 |
|
|
endif |
83 |
|
|
|
84 |
jmc |
1.5 |
C Decompose the entries. |
85 |
heimbach |
1.1 |
if (date(4) .ne. -1) then |
86 |
|
|
yy = date_1/10000 |
87 |
|
|
mm = mod(date_1/100,100) |
88 |
|
|
dd = mod(date_1,100) |
89 |
|
|
else |
90 |
|
|
yy = 0 |
91 |
|
|
mm = 0 |
92 |
|
|
dd = date_1 |
93 |
|
|
endif |
94 |
|
|
ss = mod(date_2,100) + |
95 |
jmc |
1.6 |
& mod(date_2/100,100)*secondsPerMinute + |
96 |
|
|
& date_2/10000*secondsPerHour |
97 |
heimbach |
1.1 |
|
98 |
jmc |
1.5 |
C Include the sign. |
99 |
heimbach |
1.1 |
yy = fac*yy |
100 |
|
|
mm = fac*mm |
101 |
|
|
dd = fac*dd |
102 |
|
|
ss = fac*ss |
103 |
|
|
|
104 |
|
|
lp = date(3) |
105 |
|
|
wd = date(4) |
106 |
|
|
|
107 |
jmc |
1.5 |
RETURN |
108 |
|
|
END |