1 |
C $Header: $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "COST_CPPOPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine cost_AveragesFlags( |
8 |
I myiter, |
9 |
I mytime, |
10 |
I mythid, |
11 |
O first, |
12 |
O last, |
13 |
O startofday, |
14 |
O startofmonth, |
15 |
O startofyear, |
16 |
O inday, |
17 |
O inmonth, |
18 |
O inyear, |
19 |
O endofday, |
20 |
O endofmonth, |
21 |
O endofyear, |
22 |
O sum1day, |
23 |
O dayrec, |
24 |
O sum1mon, |
25 |
O monrec, |
26 |
O sum1year, |
27 |
O yearrec |
28 |
& ) |
29 |
|
30 |
c ================================================================== |
31 |
c SUBROUTINE cost_AveragesFlags |
32 |
c ================================================================== |
33 |
c |
34 |
c o Get flags for the daily and monthly time averaging. |
35 |
c |
36 |
c started: Christian Eckert eckert@mit.edu 24-Feb-2000 |
37 |
c |
38 |
c - Introduced in order to create a package for the |
39 |
c MITgcmUV. |
40 |
c |
41 |
c changed: |
42 |
c |
43 |
c ================================================================== |
44 |
c SUBROUTINE cost_AveragesFlags |
45 |
c ================================================================== |
46 |
|
47 |
implicit none |
48 |
|
49 |
c == global variables == |
50 |
|
51 |
#include "EEPARAMS.h" |
52 |
#include "SIZE.h" |
53 |
|
54 |
#include "cal.h" |
55 |
|
56 |
c == routine arguments == |
57 |
|
58 |
integer myiter |
59 |
_RL mytime |
60 |
integer mythid |
61 |
logical first |
62 |
logical startofday |
63 |
logical startofmonth |
64 |
logical startofyear |
65 |
logical inday |
66 |
logical inmonth |
67 |
logical inyear |
68 |
logical last |
69 |
logical endofday |
70 |
logical endofmonth |
71 |
logical endofyear |
72 |
integer sum1day |
73 |
integer dayrec |
74 |
integer sum1mon |
75 |
integer monrec |
76 |
integer sum1year |
77 |
integer yearrec |
78 |
|
79 |
c == local variables == |
80 |
|
81 |
integer mydate(4) |
82 |
integer nextdate(4) |
83 |
integer prevdate(4) |
84 |
integer timediff(4) |
85 |
integer datediff(4) |
86 |
integer targetdate(4) |
87 |
integer targetdate1 |
88 |
integer targetdate2 |
89 |
integer mydateday |
90 |
integer mydatemonth |
91 |
integer mydateyear |
92 |
integer nextdateday |
93 |
integer nextdatemonth |
94 |
integer nextdateyear |
95 |
integer prevdateday |
96 |
integer prevdatemonth |
97 |
integer prevdateyear |
98 |
|
99 |
logical equal |
100 |
|
101 |
c == external functions == |
102 |
|
103 |
logical cal_CompDates |
104 |
external cal_CompDates |
105 |
|
106 |
integer cal_NumInts |
107 |
external cal_NumInts |
108 |
|
109 |
c == end of interface == |
110 |
|
111 |
c-- First, get some dates. |
112 |
call cal_GetDate( myiter, mytime, mydate, mythid ) |
113 |
call cal_GetDate( myiter+1, mytime+modelstep, nextdate, mythid ) |
114 |
|
115 |
call cal_TimeInterval( -modelstep, 'secs', timediff, mythid ) |
116 |
call cal_AddTime( mydate, timediff, prevdate, mythid ) |
117 |
|
118 |
ce print*,' time average flags: mydate = ', mydate |
119 |
ce print*,' time average flags: nextdate = ', nextdate |
120 |
ce print*,' time average flags: prevdate = ', prevdate |
121 |
|
122 |
c-- Where are we with respect to the calendar? |
123 |
|
124 |
c-- The very first model step? |
125 |
equal = cal_CompDates(modelstartdate,mydate,mythid) |
126 |
if ( equal ) then |
127 |
first = .true. |
128 |
dayrec = 0 |
129 |
monrec = 0 |
130 |
yearrec = 0 |
131 |
else |
132 |
first = .false. |
133 |
endif |
134 |
|
135 |
c-- The very last model step? |
136 |
equal = cal_CompDates(modelenddate,mydate,mythid) |
137 |
if ( equal ) then |
138 |
last = .true. |
139 |
else |
140 |
last = .false. |
141 |
endif |
142 |
|
143 |
c-- Start of a calendar day? |
144 |
mydateday = mod(mydate(1),100) |
145 |
prevdateday = mod(prevdate(1),100) |
146 |
if ( mydateday .ne. prevdateday ) then |
147 |
startofday = .true. |
148 |
else |
149 |
startofday = .false. |
150 |
endif |
151 |
|
152 |
c-- End of a calendar day? |
153 |
mydateday = mod(mydate(1),100) |
154 |
nextdateday = mod(nextdate(1),100) |
155 |
if ( mydateday .ne. nextdateday ) then |
156 |
endofday = .true. |
157 |
else |
158 |
endofday = .false. |
159 |
endif |
160 |
|
161 |
c-- In a calendar day? As coded here, inday can not be true |
162 |
c-- for either the first or the last timestep in the day. |
163 |
c-- So the cases are mutually exclusive. |
164 |
if ( ( mydateday .eq. prevdateday ) .and. |
165 |
& ( mydateday .eq. nextdateday ) ) then |
166 |
inday = .true. |
167 |
else |
168 |
inday = .false. |
169 |
endif |
170 |
|
171 |
c-- Determine sum1day and dayrec explicitly. |
172 |
if ( last .or. endofday ) then |
173 |
if ( mydate(1) .eq. modelstartdate(1) ) then |
174 |
call cal_CopyDate( modelstartdate, targetdate, mythid ) |
175 |
dayrec = 1 |
176 |
else |
177 |
targetdate(1) = mydate(1) |
178 |
targetdate(2) = 0 |
179 |
targetdate(3) = mydate(3) |
180 |
targetdate(4) = mydate(4) |
181 |
call cal_TimePassed( modelstartdate, targetdate, datediff, |
182 |
& mythid ) |
183 |
if ( datediff(2) .eq. 0) then |
184 |
dayrec = datediff(1) + 1 |
185 |
else |
186 |
dayrec = datediff(1) + 2 |
187 |
endif |
188 |
endif |
189 |
call cal_TimeInterval( modelstep, 'secs', timediff, mythid ) |
190 |
|
191 |
sum1day = |
192 |
& cal_NumInts( targetdate, mydate, timediff, mythid ) + 1 |
193 |
else |
194 |
sum1day = 0 |
195 |
endif |
196 |
|
197 |
c-- Start of a calendar month? |
198 |
mydatemonth = mod(mydate(1)/100,100) |
199 |
prevdatemonth = mod(prevdate(1)/100,100) |
200 |
if ( mydatemonth .ne. prevdatemonth ) then |
201 |
startofmonth = .true. |
202 |
else |
203 |
startofmonth = .false. |
204 |
endif |
205 |
|
206 |
c-- End of a calendar month? |
207 |
mydatemonth = mod(mydate(1)/100,100) |
208 |
nextdatemonth = mod(nextdate(1)/100,100) |
209 |
if ( mydatemonth .ne. nextdatemonth ) then |
210 |
endofmonth = .true. |
211 |
else |
212 |
endofmonth = .false. |
213 |
endif |
214 |
|
215 |
c-- In a calendar month? As coded here, inmonth can not be true |
216 |
c-- for either the first or the last timestep in the month. |
217 |
c-- So the cases are mutually exclusive. |
218 |
if ( ( mydatemonth .eq. prevdatemonth ) .and. |
219 |
& ( mydatemonth .eq. nextdatemonth ) ) then |
220 |
inmonth = .true. |
221 |
else |
222 |
inmonth = .false. |
223 |
endif |
224 |
|
225 |
c-- Determine sum1mon and monrec explicitly. |
226 |
if ( last .or. endofmonth ) then |
227 |
if ( (mydate(1)/100)*100 .eq. (modelstartdate(1)/100)*100 ) then |
228 |
call cal_CopyDate( modelstartdate, targetdate, mythid ) |
229 |
monrec = 1 |
230 |
else |
231 |
targetdate1 = (mydate(1)/100)*100+1 |
232 |
targetdate2 = 0 |
233 |
call cal_FullDate( targetdate1, targetdate2, targetdate, |
234 |
& mythid ) |
235 |
if ( mydate(1)/10000 .eq. modelstartdate(1)/10000 ) then |
236 |
monrec = mod( mydate(1)/100, 100 ) |
237 |
& - mod( modelstartdate(1)/100, 100 ) + 1 |
238 |
else |
239 |
monrec = mod( mydate(1)/100, 100 ) |
240 |
& + nmonthyear - mod(modelstartdate(1)/100,100) + 1 |
241 |
& + ( mydate(1)/10000 - modelstartdate(1)/10000 - 1)* |
242 |
& nmonthyear |
243 |
endif |
244 |
endif |
245 |
call cal_TimeInterval( modelstep, 'secs', timediff, mythid ) |
246 |
|
247 |
sum1mon = |
248 |
& cal_NumInts( targetdate, mydate, timediff, mythid ) + 1 |
249 |
else |
250 |
sum1mon = 0 |
251 |
endif |
252 |
|
253 |
c-- Start of a Year? |
254 |
mydateyear = int(mydate(1)/10000) |
255 |
prevdateyear = int(prevdate(1)/10000) |
256 |
if ( mydateyear .ne. prevdateyear ) then |
257 |
startofyear = .true. |
258 |
else |
259 |
startofyear = .false. |
260 |
endif |
261 |
|
262 |
c-- End of a Year? |
263 |
mydateyear = int(mydate(1)/10000) |
264 |
nextdateyear = int(nextdate(1)/10000) |
265 |
if ( mydateyear .ne. nextdateyear ) then |
266 |
endofyear = .true. |
267 |
else |
268 |
endofyear = .false. |
269 |
endif |
270 |
|
271 |
c-- In a calendar year? As coded here, inyear can not be true |
272 |
c-- for either the first or the last timestep in the year. |
273 |
c-- So the cases are mutually exclusive. |
274 |
if ( ( mydateyear .eq. prevdateyear ) .and. |
275 |
& ( mydateyear .eq. nextdateyear ) ) then |
276 |
inyear = .true. |
277 |
else |
278 |
inyear = .false. |
279 |
endif |
280 |
|
281 |
c-- Determine sum1year and yearrec explicitly. |
282 |
if ( last .or. endofyear ) then |
283 |
if ( int(mydate(1)/10000) .eq. |
284 |
& int(modelstartdate(1)/10000) ) then |
285 |
call cal_CopyDate( modelstartdate, targetdate, mythid ) |
286 |
yearrec = 1 |
287 |
else |
288 |
targetdate1 = int(mydate(1)/10000)*10000+101 |
289 |
targetdate2 = 0 |
290 |
call cal_FullDate( targetdate1, targetdate2, targetdate, |
291 |
& mythid ) |
292 |
yearrec = mydate(1)/10000 - modelstartdate(1)/10000 + 1 |
293 |
endif |
294 |
c |
295 |
call cal_TimeInterval( modelstep, 'secs', timediff, mythid ) |
296 |
|
297 |
sum1year = |
298 |
& cal_NumInts( targetdate, mydate, timediff, mythid ) + 1 |
299 |
else |
300 |
sum1year = 0 |
301 |
endif |
302 |
|
303 |
end |