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