1 |
c $Header: /u/gcmpack/MITgcm/pkg/exf/exf_getffieldrec.F,v 1.13 2005/05/19 21:46:15 ce107 Exp $ |
2 |
|
3 |
#include "EXF_OPTIONS.h" |
4 |
|
5 |
|
6 |
subroutine exf_GetFFieldRec( |
7 |
I fldstartdate, fldperiod, |
8 |
I fldstartdate1, fldstartdate2, |
9 |
I usefldyearlyfields, |
10 |
O fac, |
11 |
O first, |
12 |
O changed, |
13 |
O count0, |
14 |
O count1, |
15 |
O yp, |
16 |
O yf, |
17 |
I mytime, |
18 |
I myiter, |
19 |
I mythid |
20 |
& ) |
21 |
|
22 |
c ================================================================== |
23 |
c SUBROUTINE exf_GetFFieldRec |
24 |
c ================================================================== |
25 |
c |
26 |
c o Get flags, counters, and the linear interpolation factor for a |
27 |
c given field. |
28 |
c |
29 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
30 |
c |
31 |
c changed: Christian Eckert eckert@mit.edu 14-Jan-2000 |
32 |
c - Restructured the code in order to create a package |
33 |
c for the MITgcmUV. |
34 |
c |
35 |
c Christian Eckert eckert@mit.edu 12-Feb-2000 |
36 |
c - Changed Routine names (package prefix: exf_) |
37 |
c |
38 |
c Curtis Heisey cheisey@mit.edu 19-Dec-2002 |
39 |
c - added "repeatPeriod" for cycling of forcing datasets |
40 |
c |
41 |
c menemenlis@jpl.nasa.gov |
42 |
c 27-Dec-2002 bug fix for verification/global_with_exf |
43 |
c 8-Oct-2003 speed-up computations for long integration interval |
44 |
c |
45 |
c ================================================================== |
46 |
c SUBROUTINE exf_GetFFieldRec |
47 |
c ================================================================== |
48 |
|
49 |
implicit none |
50 |
|
51 |
c == global variables == |
52 |
|
53 |
c cal: modelstart, modelstep |
54 |
#include "EEPARAMS.h" |
55 |
#include "cal.h" |
56 |
#include "exf_param.h" |
57 |
|
58 |
c == routine arguments == |
59 |
|
60 |
_RL fldstartdate |
61 |
_RL fldperiod |
62 |
integer fldstartdate1 |
63 |
integer fldstartdate2 |
64 |
logical usefldyearlyfields |
65 |
_RL fac |
66 |
logical first |
67 |
logical changed |
68 |
integer count0 |
69 |
integer count1 |
70 |
_RL mytime |
71 |
integer myiter |
72 |
integer mythid |
73 |
|
74 |
c == local variables == |
75 |
|
76 |
integer mydate(4) |
77 |
integer previousdate(4) |
78 |
integer nextperiod(4) |
79 |
integer difftime(4) |
80 |
|
81 |
integer fldcount |
82 |
_RL fldsecs |
83 |
_RL fldsectot |
84 |
_RL fldsecs0 |
85 |
_RL fldsecs1 |
86 |
_RL prevfldsecs |
87 |
integer prevfldcount |
88 |
|
89 |
integer iprint |
90 |
integer date_array(4) |
91 |
integer startinyear(4) |
92 |
integer yi,yf,yp,yn |
93 |
integer mi,mf,mp,mn |
94 |
integer di,df,dp,dn |
95 |
integer si,sf,sp,sn |
96 |
integer li,lf,lp,ln |
97 |
integer wi,wf,wp,wn |
98 |
integer nextiter |
99 |
_RL nexttime |
100 |
|
101 |
#ifdef EXF_VERBOSE |
102 |
character*(max_len_mbuf) msgbuf |
103 |
#endif |
104 |
|
105 |
c == end of interface == |
106 |
|
107 |
c Determine offset in seconds from beginning of input data |
108 |
c to current date. |
109 |
|
110 |
c This is very slow for a long integration interval. |
111 |
c call cal_GetDate( myiter, mytime, mydate, mythid ) |
112 |
c call cal_TimePassed( fldstartdate, mydate, difftime, mythid ) |
113 |
c call cal_ToSeconds( difftime, fldsecs, mythid ) |
114 |
|
115 |
fldsecs = mytime - fldstartdate |
116 |
|
117 |
c Variables needed to set switches for reading new records. |
118 |
first = ((mytime - modelstart) .lt. 0.5*modelstep) |
119 |
if ( .not. first ) then |
120 |
|
121 |
c This is very slow for a long integration interval. |
122 |
c call cal_GetDate(myiter-1,mytime-modelstep,previousdate,mythid) |
123 |
c call cal_TimePassed(fldstartdate,previousdate,difftime,mythid ) |
124 |
c call cal_ToSeconds( difftime, prevfldsecs, mythid ) |
125 |
|
126 |
prevfldsecs = fldsecs - modelstep |
127 |
|
128 |
else |
129 |
prevfldsecs = 0 |
130 |
endif |
131 |
|
132 |
c Determine the flux records just before and after mycurrentdate. |
133 |
if (repeatPeriod.eq.0.) then |
134 |
|
135 |
if ( fldsecs .lt. 0 ) then |
136 |
print *, 'flux data not available for this date' |
137 |
STOP 'ABNORMAL END: S/R EXF_GETFFIELDREC' |
138 |
endif |
139 |
count0 = int((fldsecs+0.5)/fldperiod) + 1 |
140 |
count1 = count0 + 1 |
141 |
prevfldcount= int((prevfldsecs+0.5)/fldperiod) + 1 |
142 |
fldsecs = fldsecs - int((fldsecs+0.5)/fldperiod)*fldperiod |
143 |
|
144 |
elseif (repeatPeriod.gt.0.) then |
145 |
|
146 |
c If using repeating data (e.g. monthly means) then make |
147 |
c fldsecs cycle around. |
148 |
do while ( fldsecs .lt. 0 ) |
149 |
fldsecs = fldsecs + repeatPeriod |
150 |
enddo |
151 |
fldsecs0 = mod(fldsecs,repeatPeriod) |
152 |
count0 = int((fldsecs0+0.5)/fldperiod) + 1 |
153 |
fldsecs1 = mod(fldsecs+fldperiod,repeatPeriod) |
154 |
count1 = int((fldsecs1+0.5)/fldperiod) + 1 |
155 |
do while ( prevfldsecs .lt. 0 ) |
156 |
prevfldsecs = prevfldsecs + repeatPeriod |
157 |
enddo |
158 |
prevfldsecs = mod(prevfldsecs,repeatPeriod) |
159 |
prevfldcount= int((prevfldsecs+0.5)/fldperiod) + 1 |
160 |
fldsecs = fldsecs0-int((fldsecs0+0.5)/fldperiod)*fldperiod |
161 |
|
162 |
else |
163 |
|
164 |
print *, 'repeatPeriod must be positive' |
165 |
STOP 'ABNORMAL END: S/R EXF_GETFFIELDREC' |
166 |
|
167 |
endif |
168 |
|
169 |
c Weight belonging to irec for linear interpolation purposes. |
170 |
fac = 1. - fldsecs/fldperiod |
171 |
|
172 |
c Set switches for reading new records. |
173 |
if ( first) then |
174 |
changed = .false. |
175 |
else |
176 |
if (count0 .ne. prevfldcount) then |
177 |
changed = .true. |
178 |
else |
179 |
changed = .false. |
180 |
endif |
181 |
endif |
182 |
|
183 |
c --------------------------------------------------------------------- |
184 |
c --------------------------------------------------------------------- |
185 |
|
186 |
if (usefldyearlyfields) then |
187 |
|
188 |
if (repeatPeriod.NE.0.) then |
189 |
print *, 'Use of usefldyearlyfields AND repeatPeriod', |
190 |
& 'not implemented' |
191 |
STOP 'ABNORMAL END: S/R EXF_GETFFIELDREC' |
192 |
endif |
193 |
|
194 |
cph( |
195 |
cph-exf-print iprint = yp |
196 |
cph) |
197 |
|
198 |
c overwrite count0/1 indices by those w.r.t. yearly files |
199 |
c fac, first, changed remain valid |
200 |
|
201 |
call cal_FullDate( fldstartdate1, fldstartdate2, |
202 |
& date_array, mythid ) |
203 |
call cal_ConvDate( date_array,yi,mi,di,si,li,wi,mythid ) |
204 |
|
205 |
call cal_GetDate( myiter, mytime, mydate, mythid ) |
206 |
call cal_ConvDate( mydate,yf,mf,df,sf,lf,wf,mythid ) |
207 |
|
208 |
if ( yf .EQ. yi ) then |
209 |
startinyear(1) = date_array(1) |
210 |
else if ( mf.EQ.1 .AND. df.EQ.1 .AND. |
211 |
& mydate(2) .LT. date_array(2) ) then |
212 |
if ( (yf-1) .EQ. yi ) then |
213 |
startinyear(1) = date_array(1) |
214 |
else |
215 |
startinyear(1) = (yf-1)*10000 + 100 + 1 |
216 |
endif |
217 |
else |
218 |
startinyear(1) = yf*10000 + 100 + 1 |
219 |
yi = yf |
220 |
if ( mf.EQ.1 .AND. df.EQ.1 .AND. |
221 |
& mydate(2) .EQ. date_array(2) ) then |
222 |
first = .TRUE. |
223 |
endif |
224 |
endif |
225 |
startinyear(2) = date_array(2) |
226 |
startinyear(3) = date_array(3) |
227 |
startinyear(4) = date_array(4) |
228 |
|
229 |
cph-exf-print if (iprint.EQ.3000) then |
230 |
cph-exf-print print *, 'ph-exf startin ', startinyear(1), startinyear(2) |
231 |
cph-exf-print print *, 'ph-exf mydate ', mydate(1), mydate(2) |
232 |
cph-exf-print endif |
233 |
|
234 |
call cal_TimePassed( startinyear, mydate, difftime, mythid ) |
235 |
call cal_ToSeconds( difftime, fldsectot, mythid ) |
236 |
fldsecs = int(fldsectot/fldperiod)*fldperiod |
237 |
fldcount = int(fldsecs/fldperiod) + 1 |
238 |
|
239 |
if ( first) then |
240 |
changed = .false. |
241 |
yp = yf |
242 |
else |
243 |
call cal_GetDate( myiter-1, mytime-modelstep, |
244 |
& previousdate, mythid ) |
245 |
call cal_ConvDate( previousdate,yp,mp,dp,sp,lp,wp,mythid ) |
246 |
|
247 |
if ( yp .NE. yf ) then |
248 |
startinyear(1) = yp*10000 + 100 + 1 |
249 |
startinyear(2) = date_array(2) |
250 |
startinyear(3) = previousdate(3) |
251 |
startinyear(4) = date_array(4) |
252 |
endif |
253 |
|
254 |
call cal_TimePassed( startinyear, previousdate, difftime, |
255 |
& mythid ) |
256 |
call cal_ToSeconds( difftime, prevfldsecs, mythid ) |
257 |
prevfldsecs = int(prevfldsecs/fldperiod)*fldperiod |
258 |
prevfldcount = int(prevfldsecs/fldperiod) + 1 |
259 |
|
260 |
if (fldcount .ne. prevfldcount) then |
261 |
changed = .true. |
262 |
else |
263 |
changed = .false. |
264 |
endif |
265 |
endif |
266 |
|
267 |
count0 = fldcount |
268 |
count1 = fldcount + 1 |
269 |
|
270 |
nexttime = mytime - (fldsectot-fldsecs) + fldperiod |
271 |
nextiter = INT(nexttime/modelstep +0.0001) |
272 |
|
273 |
cph-exf-print if (iprint.EQ.3000) then |
274 |
cph-exf-print print *, 'ph-exf fldsec ', fldsectot, fldsecs |
275 |
cph-exf-print print *, 'ph-exf next ', nexttime, nexttime-mytime, |
276 |
cph-exf-print & INT((nexttime-mytime)/modelstep) |
277 |
cph-exf-print endif |
278 |
|
279 |
call cal_GetDate( |
280 |
& nextiter, nexttime, nextperiod, mythid) |
281 |
call cal_ConvDate( nextperiod,yn,mn,dn,sn,ln,wn,mythid ) |
282 |
cph-exf-print if (iprint.EQ.3000) print *, 'ph-exf nextperiod ', |
283 |
cph-exf-print & nextiter, nextperiod(1), nextperiod(2) |
284 |
if ( yn.GT.yi ) then |
285 |
count1 = 1 |
286 |
yf = yn |
287 |
endif |
288 |
|
289 |
endif |
290 |
|
291 |
cph-exf-print if (iprint.EQ.3000) then |
292 |
cph-exf-print print *, 'ph-exf-rec yp, yf, yn ', |
293 |
cph-exf-print & yp, yf, yn |
294 |
cph-exf-print print *, 'ph-exf-rec myiter, c0, c1 ', |
295 |
cph-exf-print & myiter, count0, count1, changed |
296 |
cph-exf-print endif |
297 |
|
298 |
c --------------------------------------------------------------------- |
299 |
c --------------------------------------------------------------------- |
300 |
|
301 |
#ifdef EXF_VERBOSE |
302 |
c Do some printing for the protocol. |
303 |
_BEGIN_MASTER( mythid ) |
304 |
write(msgbuf,'(a)') ' exf_GetFFieldsRec:' |
305 |
call print_message( msgbuf, standardmessageunit, |
306 |
& SQUEEZE_RIGHT , mythid) |
307 |
write(msgbuf,'(a,2x,l2,2x,l2,2x,D15.8)') |
308 |
& ' exf_GetFFieldsRec: first, changed, fac:', |
309 |
& first, changed, fac |
310 |
call print_message( msgbuf, standardmessageunit, |
311 |
& SQUEEZE_RIGHT , mythid) |
312 |
write(msgbuf,'(a,3(1x,i6))') |
313 |
& ' exf_GetFFieldsRec: myiter, count0, count1:', |
314 |
& myiter, count0, count1 |
315 |
call print_message( msgbuf, standardmessageunit, |
316 |
& SQUEEZE_RIGHT , mythid) |
317 |
write(msgbuf,'(a)') ' exf_GetFFieldsRec:' |
318 |
call print_message( msgbuf, standardmessageunit, |
319 |
& SQUEEZE_RIGHT , mythid) |
320 |
_END_MASTER( mythid ) |
321 |
#endif |
322 |
|
323 |
end |