1 |
C $Header: /u/gcmpack/MITgcm/pkg/ctrl/ctrl_get_gen_rec.F,v 1.8 2011/01/19 08:31:21 mlosch Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PACKAGES_CONFIG.h" |
5 |
#include "CTRL_CPPOPTIONS.h" |
6 |
|
7 |
|
8 |
subroutine ctrl_get_gen_rec( |
9 |
I xx_genstartdate, |
10 |
I xx_genperiod, |
11 |
O fac, |
12 |
O first, |
13 |
O changed, |
14 |
O count0, |
15 |
O count1, |
16 |
I mytime, |
17 |
I myiter, |
18 |
I mythid |
19 |
& ) |
20 |
|
21 |
c ================================================================== |
22 |
c SUBROUTINE ctrl_get_gen_rec |
23 |
c ================================================================== |
24 |
c |
25 |
c o Get flags, counters, and the linear interpolation factor for a |
26 |
c given control vector contribution. |
27 |
c o New, generic, for new routine ctrl_get_gen |
28 |
c |
29 |
c ================================================================== |
30 |
c SUBROUTINE ctrl_get_gen_rec |
31 |
c ================================================================== |
32 |
|
33 |
implicit none |
34 |
|
35 |
c == global variables == |
36 |
|
37 |
#include "EEPARAMS.h" |
38 |
#include "SIZE.h" |
39 |
|
40 |
#include "ctrl.h" |
41 |
#ifdef ALLOW_CAL |
42 |
# include "cal.h" |
43 |
#endif |
44 |
#include "PARAMS.h" |
45 |
|
46 |
c == routine arguments == |
47 |
|
48 |
integer xx_genstartdate(4) |
49 |
_RL xx_genperiod |
50 |
_RL fac |
51 |
logical first |
52 |
logical changed |
53 |
integer count0 |
54 |
integer count1 |
55 |
_RL mytime |
56 |
integer myiter |
57 |
integer mythid |
58 |
|
59 |
c == local variables == |
60 |
|
61 |
#ifdef ALLOW_CAL |
62 |
|
63 |
integer mydate(4) |
64 |
integer previousdate(4) |
65 |
integer difftime(4) |
66 |
|
67 |
integer fldcount |
68 |
_RL fldsecs |
69 |
integer prevfldcount |
70 |
_RL prevfldsecs |
71 |
integer flddate(4) |
72 |
|
73 |
integer fldstartdate(4) |
74 |
_RL fldperiod |
75 |
|
76 |
integer startrec |
77 |
|
78 |
logical lArgErr |
79 |
#else |
80 |
C Declarations for code, adapted from external_fields_load, |
81 |
C for simplied default model calendar without exf/cal |
82 |
_RL rdt |
83 |
_RL tmp1Wght, tmp2Wght |
84 |
_RL myRelTime |
85 |
INTEGER nForcingPeriods,Imytm,Ifprd,Ifcyc,Iftm |
86 |
#endif |
87 |
|
88 |
#ifdef ECCO_VERBOSE |
89 |
character*(max_len_mbuf) msgbuf |
90 |
#endif |
91 |
|
92 |
c == end of interface == |
93 |
|
94 |
#ifdef ALLOW_CAL |
95 |
lArgErr = .true. |
96 |
fldperiod = 0. |
97 |
|
98 |
c Map the field parameters. |
99 |
|
100 |
call cal_CopyDate( |
101 |
I xx_genstartdate, |
102 |
O fldstartdate, |
103 |
I mythid |
104 |
& ) |
105 |
fldperiod = xx_genperiod |
106 |
lArgErr = .false. |
107 |
|
108 |
c-- Check the field argument. |
109 |
if ( lArgErr ) then |
110 |
print*,' The subroutine *ctrl_get_gen_rec* has been called' |
111 |
print*,' with an illegal field specification.' |
112 |
stop ' ... stopped in ctrl_get_gen_rec.' |
113 |
endif |
114 |
|
115 |
c-- Determine the current date. |
116 |
call cal_GetDate( myiter, mytime, mydate, mythid ) |
117 |
|
118 |
c Determine first record: |
119 |
call cal_TimePassed( fldstartdate, modelstartdate, |
120 |
& difftime, mythid ) |
121 |
call cal_ToSeconds ( difftime, fldsecs, mythid ) |
122 |
startrec = int((modelstart + startTime - fldsecs)/ |
123 |
& fldperiod) + 1 |
124 |
|
125 |
c Determine the flux record just before mycurrentdate. |
126 |
call cal_TimePassed( fldstartdate, mydate, difftime, |
127 |
& mythid ) |
128 |
call cal_ToSeconds( difftime, fldsecs, mythid ) |
129 |
fldsecs = int((fldsecs+0.5)/fldperiod)*fldperiod |
130 |
fldcount = int((fldsecs+0.5)/fldperiod) + 1 |
131 |
|
132 |
c Set switches for reading new records. |
133 |
first = ((mytime - modelstart) .lt. 0.5*modelstep) |
134 |
|
135 |
if ( first) then |
136 |
changed = .false. |
137 |
else |
138 |
call cal_GetDate( myiter-1, mytime-modelstep, |
139 |
& previousdate, mythid ) |
140 |
|
141 |
call cal_TimePassed( fldstartdate, previousdate, |
142 |
& difftime, mythid ) |
143 |
call cal_ToSeconds( difftime, prevfldsecs, mythid ) |
144 |
prevfldsecs = int((prevfldsecs+0.5)/fldperiod)*fldperiod |
145 |
prevfldcount = int((prevfldsecs+0.5)/fldperiod) + 1 |
146 |
|
147 |
if (fldcount .ne. prevfldcount) then |
148 |
changed = .true. |
149 |
else |
150 |
changed = .false. |
151 |
endif |
152 |
endif |
153 |
|
154 |
c count0 = fldcount |
155 |
c count1 = fldcount + 1 |
156 |
count0 = fldcount - startrec + 1 |
157 |
count1 = fldcount - startrec + 2 |
158 |
|
159 |
call cal_TimeInterval( fldsecs, 'secs', difftime, mythid ) |
160 |
call cal_AddTime( fldstartdate, difftime, flddate, mythid ) |
161 |
call cal_TimePassed( flddate, mydate, difftime, mythid ) |
162 |
call cal_ToSeconds( difftime, fldsecs, mythid ) |
163 |
|
164 |
c Weight belonging to irec for linear interpolation purposes. |
165 |
c Note: The weight as chosen here is 1. - fac of the "old" |
166 |
c MITgcm estimation program. |
167 |
fac = 1. - fldsecs/fldperiod |
168 |
|
169 |
#else /* not ALLOW_CAL */ |
170 |
C Code, adapted from external_fields_load, for simplied |
171 |
C default model calendar without exf/cal, but |
172 |
C based on myTime, myIter, deltaTclock, externForcingCycle, and startTime |
173 |
|
174 |
myRelTime = myTime - startTime |
175 |
first = (myRelTime .lt. 0.5*deltaTClock) |
176 |
if ( xx_genperiod .eq. 0. _d 0 |
177 |
& .or. externForcingCycle .eq. 0. _d 0 ) then |
178 |
C control parameter is constant in time and only needs to be updated |
179 |
C once in the beginning |
180 |
changed = .false. |
181 |
count0 = 1 |
182 |
count1 = 1 |
183 |
fac = 1. _d 0 |
184 |
else |
185 |
if ( first ) changed = .false. |
186 |
|
187 |
nForcingPeriods = NINT(externForcingCycle/xx_genperiod) |
188 |
|
189 |
rdt = 1. _d 0 / deltaTclock |
190 |
Imytm = NINT(myRelTime*rdt) |
191 |
Ifprd = NINT(xx_genperiod*rdt) |
192 |
Ifcyc = NINT(externForcingCycle*rdt) |
193 |
Imytm = Imytm + Ifcyc*( 1 - NINT(myRelTime/externForcingCycle) ) |
194 |
Iftm = MOD( Imytm+Ifcyc-Ifprd/2, Ifcyc) |
195 |
|
196 |
count0 = 1 + INT(Iftm/Ifprd) |
197 |
count1 = 1 + MOD(count0,nForcingPeriods) |
198 |
C-jmc: with some option of g77, FLOAT results in real*4 evaluation |
199 |
C of aWght; using DFLOAT always force real*8 computation: |
200 |
c aWght = DFLOAT( Iftm-Ifprd*(intime0 - 1) ) / DFLOAT( Ifprd ) |
201 |
C-ph: however, TAF doesnt recognize DFLOAT, |
202 |
C-jmc: so let me try this: |
203 |
tmp1Wght = FLOAT( Iftm-Ifprd*(count0 - 1) ) |
204 |
tmp2Wght = FLOAT( Ifprd ) |
205 |
fac = 1. _d 0 - tmp1Wght / tmp2Wght |
206 |
|
207 |
if ( Iftm-Ifprd*(count0-1) .eq. 0 |
208 |
& ) then |
209 |
changed = .true. |
210 |
else |
211 |
changed = .false. |
212 |
endif |
213 |
|
214 |
endif |
215 |
|
216 |
#endif /* ALLOW_CAL */ |
217 |
|
218 |
#ifdef ECCO_VERBOSE |
219 |
c Do some printing for the protocol. |
220 |
_BEGIN_MASTER( mythid ) |
221 |
write(msgbuf,'(a)') ' ' |
222 |
call print_message( msgbuf, standardmessageunit, |
223 |
& SQUEEZE_RIGHT , mythid) |
224 |
write(msgbuf,'(a,2x,l2,2x,l2,2x,D15.8)') |
225 |
& ' first, changed, fac:', |
226 |
& first, changed, fac |
227 |
call print_message( msgbuf, standardmessageunit, |
228 |
& SQUEEZE_RIGHT , mythid) |
229 |
write(msgbuf,'(a,i4,i4)') |
230 |
& ' count0, count1:', |
231 |
& count0, count1 |
232 |
call print_message( msgbuf, standardmessageunit, |
233 |
& SQUEEZE_RIGHT , mythid) |
234 |
write(msgbuf,'(a)') ' ' |
235 |
call print_message( msgbuf, standardmessageunit, |
236 |
& SQUEEZE_RIGHT , mythid) |
237 |
_END_MASTER( mythid ) |
238 |
#endif |
239 |
|
240 |
return |
241 |
end |