1 |
C $Header: /u/gcmpack/development/heimbach/ecco_env/pkg/cal/cal_timepassed.F,v 1.4 2001/02/02 16:57:22 heimbach Exp $ |
2 |
|
3 |
#include "CAL_CPPOPTIONS.h" |
4 |
|
5 |
subroutine cal_TimePassed( |
6 |
I initialdate, |
7 |
I finaldate, |
8 |
O numdays, |
9 |
I mythid |
10 |
& ) |
11 |
|
12 |
c ================================================================== |
13 |
c SUBROUTINE cal_TimePassed |
14 |
c ================================================================== |
15 |
c |
16 |
c o Calculate the time that passed between initialdate and |
17 |
c finaldate. |
18 |
c |
19 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
20 |
c |
21 |
c changed: Christian Eckert eckert@mit.edu 29-Dec-1999 |
22 |
c |
23 |
c - restructured the original version in order to have a |
24 |
c better interface to the MITgcmUV. |
25 |
c |
26 |
c Christian Eckert eckert@mit.edu 03-Feb-2000 |
27 |
c |
28 |
c - Introduced new routine and function names, cal_<NAME>, |
29 |
c for verion 0.1.3. |
30 |
c |
31 |
c ================================================================== |
32 |
c SUBROUTINE cal_TimePassed |
33 |
c ================================================================== |
34 |
|
35 |
implicit none |
36 |
|
37 |
c == global variables == |
38 |
|
39 |
#include "cal.h" |
40 |
|
41 |
c == routine arguments == |
42 |
|
43 |
integer initialdate(4) |
44 |
integer finaldate(4) |
45 |
integer numdays(4) |
46 |
integer mythid |
47 |
|
48 |
c == local variables == |
49 |
|
50 |
integer yi,yf |
51 |
integer mi,mf |
52 |
integer di,df |
53 |
integer si,sf |
54 |
integer li,lf |
55 |
integer wi,wf |
56 |
integer cdi,cdf |
57 |
integer csi,csf |
58 |
integer ndays |
59 |
integer nsecs |
60 |
integer hhmmss |
61 |
integer imon |
62 |
integer iyr |
63 |
integer ierr |
64 |
|
65 |
logical swap |
66 |
logical caldates |
67 |
logical nothingtodo |
68 |
|
69 |
c == external == |
70 |
|
71 |
integer cal_IsLeap |
72 |
external cal_IsLeap |
73 |
|
74 |
c == end of interface == |
75 |
|
76 |
nothingtodo = .false. |
77 |
|
78 |
c Initialise output. |
79 |
numdays(1) = 0 |
80 |
numdays(2) = 0 |
81 |
numdays(3) = 0 |
82 |
numdays(4) = -1 |
83 |
|
84 |
if ((initialdate(4) .gt. 0) .eqv. |
85 |
& ( finaldate(4) .gt. 0)) then |
86 |
|
87 |
caldates = (initialdate(4) .gt. 0) .and. |
88 |
& ( finaldate(4) .gt. 0) |
89 |
|
90 |
c Check relation between initial and final dates. |
91 |
if (initialdate(1) .eq. finaldate(1)) then |
92 |
if (initialdate(2) .eq. finaldate(2)) then |
93 |
nothingtodo = .true. |
94 |
else if (initialdate(2) .gt. finaldate(2)) then |
95 |
swap = .true. |
96 |
else |
97 |
swap = .false. |
98 |
endif |
99 |
else if (initialdate(1) .gt. finaldate(1)) then |
100 |
swap = .true. |
101 |
else |
102 |
swap = .false. |
103 |
endif |
104 |
|
105 |
if (.not. nothingtodo) then |
106 |
|
107 |
if (swap) then |
108 |
call cal_ConvDate( finaldate,yi,mi,di,si,li,wi,mythid ) |
109 |
call cal_ConvDate( initialdate,yf,mf,df,sf,lf,wf,mythid ) |
110 |
else |
111 |
call cal_ConvDate( initialdate,yi,mi,di,si,li,wi,mythid ) |
112 |
call cal_ConvDate( finaldate,yf,mf,df,sf,lf,wf,mythid ) |
113 |
endif |
114 |
|
115 |
c Determine the time interval. |
116 |
if (.not. caldates) then |
117 |
ndays = df - di |
118 |
nsecs = sf - si |
119 |
if (nsecs .lt. 0) then |
120 |
nsecs = nsecs + secondsperday |
121 |
ndays = ndays - 1 |
122 |
endif |
123 |
ndays = ndays + nsecs/secondsperday |
124 |
nsecs = mod(nsecs,secondsperday) |
125 |
else |
126 |
si = si + (di-1)*secondsperday |
127 |
sf = sf + (df-1)*secondsperday |
128 |
cdi = 0 |
129 |
do imon = 1,mod(mi-1,12) |
130 |
cdi = cdi + ndaymonth(imon,li) |
131 |
enddo |
132 |
csi = si |
133 |
cdf = 0 |
134 |
do imon = 1,mod(mf-1,12) |
135 |
cdf = cdf + ndaymonth(imon,lf) |
136 |
enddo |
137 |
csf = sf |
138 |
|
139 |
if (yi .eq. yf) then |
140 |
ndays = (cdf + csf/secondsperday) - |
141 |
& (cdi + csi/secondsperday) |
142 |
nsecs = (csf - (csf/secondsperday)*secondsperday) - |
143 |
& (csi - (csi/secondsperday)*secondsperday) |
144 |
if (nsecs .lt. 0) then |
145 |
nsecs = nsecs + secondsperday |
146 |
ndays = ndays - 1 |
147 |
endif |
148 |
else |
149 |
ndays = (ndaysnoleap - 1) + cal_IsLeap( yi, mythid ) - |
150 |
& cdi - ndaymonth(mi,li) |
151 |
do iyr = yi+1,yf-1 |
152 |
ndays = ndays + (ndaysnoleap - 1) + |
153 |
& cal_IsLeap( iyr, mythid ) |
154 |
enddo |
155 |
ndays = ndays + cdf |
156 |
csi = ndaymonth(mi,li)*secondsperday - csi |
157 |
nsecs = csi + csf |
158 |
endif |
159 |
endif |
160 |
|
161 |
c Convert to calendar format. |
162 |
numdays(1) = ndays + nsecs/secondsperday |
163 |
nsecs = mod(nsecs,secondsperday) |
164 |
hhmmss = nsecs/secondsperminute |
165 |
numdays(2) = hhmmss/minutesperhour*10000 + |
166 |
& mod(hhmmss,minutesperhour)*100 + |
167 |
& mod(nsecs,secondsperminute) |
168 |
if (swap) then |
169 |
numdays(1) = -numdays(1) |
170 |
numdays(2) = -numdays(2) |
171 |
endif |
172 |
|
173 |
else |
174 |
c Dates are equal. |
175 |
endif |
176 |
|
177 |
else |
178 |
|
179 |
ierr = 501 |
180 |
call cal_PrintError( ierr, mythid ) |
181 |
stop ' stopped in cal_TimePassed' |
182 |
|
183 |
endif |
184 |
|
185 |
return |
186 |
end |
187 |
|