1 |
C $Header: /u/gcmpack/MITgcm/pkg/exf/exf_set_gen.F,v 1.27 2009/09/01 19:33:55 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "EXF_OPTIONS.h" |
5 |
|
6 |
subroutine exf_set_gen( |
7 |
& genfile, genstartdate, genperiod, |
8 |
& exf_inscal_gen, genremove_intercept, genremove_slope, |
9 |
& genfld, gen0, gen1, genmask, |
10 |
#ifdef USE_EXF_INTERPOLATION |
11 |
& gen_lon0, gen_lon_inc, gen_lat0, gen_lat_inc, |
12 |
& gen_nlon, gen_nlat, gen_xout, gen_yout, interp_method, |
13 |
#endif |
14 |
& mytime, myiter, mythid ) |
15 |
|
16 |
c ================================================================== |
17 |
c SUBROUTINE exf_set_gen |
18 |
c ================================================================== |
19 |
c |
20 |
c o set external forcing gen |
21 |
c |
22 |
c started: Ralf.Giering@FastOpt.de 25-Mai-2000 |
23 |
c changed: heimbach@mit.edu 10-Jan-2002 |
24 |
c 20-Dec-2002: mods for pkg/seaice, menemenlis@jpl.nasa.gov |
25 |
c heimbach@mit.edu: totally re-organized exf_set_... |
26 |
c replaced all routines by one generic routine |
27 |
c 5-Aug-2003: added USE_EXF_INTERPOLATION for arbitrary |
28 |
c input grid capability |
29 |
c 11-Dec-2006 added time-mean and monthly-mean climatology options |
30 |
c genperiod=0 means input file is one time-constant field |
31 |
c genperiod=-12 means input file contains 12 monthly means |
32 |
|
33 |
c ================================================================== |
34 |
c SUBROUTINE exf_set_gen |
35 |
c ================================================================== |
36 |
|
37 |
implicit none |
38 |
|
39 |
c == global variables == |
40 |
|
41 |
#include "EEPARAMS.h" |
42 |
#include "SIZE.h" |
43 |
#include "PARAMS.h" |
44 |
#include "GRID.h" |
45 |
|
46 |
#include "EXF_PARAM.h" |
47 |
#include "EXF_CONSTANTS.h" |
48 |
|
49 |
c == routine arguments == |
50 |
|
51 |
_RL genstartdate, genperiod |
52 |
_RL exf_inscal_gen |
53 |
_RL genremove_intercept, genremove_slope |
54 |
_RL genfld(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
55 |
_RL gen0 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
56 |
_RL gen1 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
57 |
character*1 genmask |
58 |
character*(128) genfile |
59 |
_RL mytime |
60 |
integer myiter |
61 |
integer mythid |
62 |
|
63 |
#ifdef USE_EXF_INTERPOLATION |
64 |
c gen_lon_0 ,gen_lat_0 :: longitude and latitude of SouthWest |
65 |
c corner of global input grid |
66 |
c gen_nlon, gen_nlat :: input x-grid and y-grid size |
67 |
c gen_lon_inc :: scalar x-grid increment |
68 |
c gen_lat_inc :: vector y-grid increments |
69 |
c gen_xout, gen_yout :: coordinates for output grid |
70 |
_RL gen_lon0, gen_lon_inc |
71 |
_RL gen_lat0, gen_lat_inc(MAX_LAT_INC) |
72 |
INTEGER gen_nlon, gen_nlat |
73 |
_RS gen_xout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
74 |
_RS gen_yout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
75 |
integer interp_method |
76 |
#endif /* USE_EXF_INTERPOLATION */ |
77 |
|
78 |
c == local variables == |
79 |
|
80 |
logical first, changed |
81 |
integer count0, count1 |
82 |
integer year0, year1 |
83 |
integer bi, bj, i, j |
84 |
_RL fac |
85 |
character*(128) genfile0, genfile1 |
86 |
|
87 |
c == external == |
88 |
|
89 |
integer ilnblnk |
90 |
external ilnblnk |
91 |
|
92 |
c == end of interface == |
93 |
|
94 |
if ( genfile .NE. ' ' .and. genperiod .ne. 0 ) then |
95 |
|
96 |
cph( |
97 |
cph-exf-print if (genfile .EQ. hfluxfile) year0 = 3000 |
98 |
cph) |
99 |
|
100 |
if ( genperiod .eq. -12 ) then |
101 |
c genperiod=-12 means input file contains 12 monthly means |
102 |
c record numbers are assumed 1 to 12 corresponding to |
103 |
c Jan. through Dec. |
104 |
call cal_GetMonthsRec( |
105 |
O fac, first, changed, |
106 |
O count0, count1, |
107 |
I mytime, myiter, mythid |
108 |
& ) |
109 |
|
110 |
elseif ( genperiod .lt. 0 ) then |
111 |
print *, 'genperiod is out of range' |
112 |
STOP 'ABNORMAL END: S/R EXF_SET_GEN' |
113 |
|
114 |
else |
115 |
c get record numbers and interpolation factor for gen |
116 |
call exf_GetFFieldRec( |
117 |
I genstartdate, genperiod |
118 |
I , useExfYearlyFields |
119 |
O , fac, first, changed |
120 |
O , count0, count1, year0, year1 |
121 |
I , mytime, myiter, mythid |
122 |
& ) |
123 |
|
124 |
endif |
125 |
|
126 |
if ( first ) then |
127 |
call exf_GetYearlyFieldName( |
128 |
I useExfYearlyFields, twoDigitYear, genperiod, year0, |
129 |
I genfile, |
130 |
O genfile0, |
131 |
I mytime, myiter, mythid ) |
132 |
|
133 |
#ifdef USE_EXF_INTERPOLATION |
134 |
call exf_interp( genfile0, exf_iprec |
135 |
& , gen1, count0, gen_xout, gen_yout |
136 |
& , gen_lon0,gen_lon_inc |
137 |
& , gen_lat0,gen_lat_inc |
138 |
& , gen_nlon,gen_nlat,interp_method,mythid |
139 |
& ) |
140 |
#else |
141 |
IF (exf_yftype .EQ. 'RL') THEN |
142 |
CALL READ_REC_3D_RL( genfile0, exf_iprec, 1, |
143 |
& gen1, count0, myIter, myThid ) |
144 |
ELSE |
145 |
c CALL READ_REC_3D_RS( genfile0, exf_iprec, 1, |
146 |
c & gen1, count0, myIter, myThid ) |
147 |
STOP 'S/R EXF_SET_GEN: invalid exf_yftype' |
148 |
ENDIF |
149 |
#endif /* USE_EXF_INTERPOLATION */ |
150 |
|
151 |
if (exf_yftype .eq. 'RL') then |
152 |
call exf_filter_rl( gen1, genmask, mythid ) |
153 |
c else |
154 |
c call exf_filter_rs( gen1, genmask, mythid ) |
155 |
end if |
156 |
endif |
157 |
|
158 |
if (( first ) .or. ( changed )) then |
159 |
call exf_SwapFFields( gen0, gen1, mythid ) |
160 |
|
161 |
call exf_GetYearlyFieldName( |
162 |
I useExfYearlyFields, twoDigitYear, genperiod, year1, |
163 |
I genfile, |
164 |
O genfile1, |
165 |
I mytime, myiter, mythid ) |
166 |
|
167 |
#ifdef USE_EXF_INTERPOLATION |
168 |
call exf_interp( genfile1, exf_iprec |
169 |
& , gen1, count1, gen_xout, gen_yout |
170 |
& , gen_lon0,gen_lon_inc |
171 |
& , gen_lat0,gen_lat_inc |
172 |
& , gen_nlon,gen_nlat,interp_method,mythid |
173 |
& ) |
174 |
#else |
175 |
IF (exf_yftype .EQ. 'RL') THEN |
176 |
CALL READ_REC_3D_RL( genfile1, exf_iprec, 1, |
177 |
& gen1, count1, myIter, myThid ) |
178 |
ELSE |
179 |
c CALL READ_REC_3D_RS( genfile1, exf_iprec, 1, |
180 |
c & gen1, count1, myIter, myThid ) |
181 |
STOP 'S/R EXF_SET_GEN: invalid exf_yftype' |
182 |
ENDIF |
183 |
#endif /* USE_EXF_INTERPOLATION */ |
184 |
|
185 |
if (exf_yftype .eq. 'RL') then |
186 |
call exf_filter_rl( gen1, genmask, mythid ) |
187 |
c else |
188 |
c call exf_filter_rs( gen1, genmask, mythid ) |
189 |
end if |
190 |
endif |
191 |
|
192 |
c Loop over tiles. |
193 |
do bj = mybylo(mythid),mybyhi(mythid) |
194 |
do bi = mybxlo(mythid),mybxhi(mythid) |
195 |
do j = 1,sny |
196 |
do i = 1,snx |
197 |
c Interpolate linearly onto the time. |
198 |
genfld(i,j,bi,bj) = exf_inscal_gen * ( |
199 |
& fac * gen0(i,j,bi,bj) + |
200 |
& (exf_one - fac) * gen1(i,j,bi,bj) ) |
201 |
genfld(i,j,bi,bj) = |
202 |
& genfld(i,j,bi,bj) - |
203 |
& exf_inscal_gen * ( genremove_intercept + |
204 |
& genremove_slope*(mytime-starttime) ) |
205 |
enddo |
206 |
enddo |
207 |
enddo |
208 |
enddo |
209 |
|
210 |
endif |
211 |
|
212 |
RETURN |
213 |
END |
214 |
|
215 |
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
216 |
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
217 |
|
218 |
subroutine exf_init_gen ( |
219 |
& genfile, genperiod, exf_inscal_gen, genmask, |
220 |
& genconst, genfld, gen0, gen1, |
221 |
#ifdef USE_EXF_INTERPOLATION |
222 |
& gen_lon0, gen_lon_inc, gen_lat0, gen_lat_inc, |
223 |
& gen_nlon, gen_nlat, gen_xout, gen_yout, interp_method, |
224 |
#endif |
225 |
& mythid ) |
226 |
|
227 |
|
228 |
c ================================================================== |
229 |
c SUBROUTINE exf_init_gen |
230 |
c ================================================================== |
231 |
c |
232 |
c o |
233 |
c |
234 |
c started: Ralf.Giering@FastOpt.de 25-Mai-2000 |
235 |
c changed: heimbach@mit.edu 10-Jan-2002 |
236 |
c heimbach@mit.edu: totally re-organized exf_set_... |
237 |
c replaced all routines by one generic routine |
238 |
c |
239 |
c ================================================================== |
240 |
c SUBROUTINE exf_init_gen |
241 |
c ================================================================== |
242 |
|
243 |
implicit none |
244 |
|
245 |
c == global variables == |
246 |
|
247 |
#include "EEPARAMS.h" |
248 |
#include "SIZE.h" |
249 |
|
250 |
#include "EXF_PARAM.h" |
251 |
|
252 |
c == routine arguments == |
253 |
|
254 |
_RL genperiod, exf_inscal_gen, genconst |
255 |
_RL genfld(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
256 |
_RL gen0 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
257 |
_RL gen1 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
258 |
character*1 genmask |
259 |
character*(128) genfile |
260 |
integer mythid |
261 |
|
262 |
#ifdef USE_EXF_INTERPOLATION |
263 |
c gen_lon_0 ,gen_lat_0 :: longitude and latitude of SouthWest |
264 |
c corner of global input grid |
265 |
c gen_nlon, gen_nlat :: input x-grid and y-grid size |
266 |
c gen_lon_inc :: scalar x-grid increment |
267 |
c gen_lat_inc :: vector y-grid increments |
268 |
c gen_xout, gen_yout :: coordinates for output grid |
269 |
_RL gen_lon0, gen_lon_inc |
270 |
_RL gen_lat0, gen_lat_inc(MAX_LAT_INC) |
271 |
INTEGER gen_nlon, gen_nlat |
272 |
_RS gen_xout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
273 |
_RS gen_yout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
274 |
integer interp_method |
275 |
#endif /* USE_EXF_INTERPOLATION */ |
276 |
|
277 |
c == local variables == |
278 |
|
279 |
integer bi, bj, i, j, count |
280 |
|
281 |
c == end of interface == |
282 |
|
283 |
do bj = mybylo(mythid), mybyhi(mythid) |
284 |
do bi = mybxlo(mythid), mybxhi(mythid) |
285 |
do j = 1-oly, sny+oly |
286 |
do i = 1-olx, snx+olx |
287 |
genfld(i,j,bi,bj) = genconst |
288 |
gen0(i,j,bi,bj) = genconst |
289 |
gen1(i,j,bi,bj) = genconst |
290 |
enddo |
291 |
enddo |
292 |
enddo |
293 |
enddo |
294 |
|
295 |
if ( genfile .NE. ' ' .and. genperiod .eq. 0. ) then |
296 |
count = 1 |
297 |
|
298 |
#ifdef USE_EXF_INTERPOLATION |
299 |
call exf_interp( genfile, exf_iprec |
300 |
& , genfld, count, gen_xout, gen_yout |
301 |
& , gen_lon0,gen_lon_inc |
302 |
& , gen_lat0,gen_lat_inc |
303 |
& , gen_nlon,gen_nlat,interp_method,mythid |
304 |
& ) |
305 |
#else |
306 |
IF (exf_yftype .EQ. 'RL') THEN |
307 |
CALL READ_REC_3D_RL( genfile, exf_iprec, 1, |
308 |
& genfld, count, 0, myThid ) |
309 |
ELSE |
310 |
c CALL READ_REC_3D_RS( genfile, exf_iprec, 1, |
311 |
c & genfld, count, 0, myThid ) |
312 |
STOP 'S/R EXF_INIT_GEN: invalid exf_yftype' |
313 |
ENDIF |
314 |
#endif /* USE_EXF_INTERPOLATION */ |
315 |
|
316 |
if (exf_yftype .eq. 'RL') then |
317 |
call exf_filter_rl( genfld, genmask, mythid ) |
318 |
c else |
319 |
c call exf_filter_rs( genfld, genmask, mythid ) |
320 |
end if |
321 |
|
322 |
c Loop over tiles and scale genfld |
323 |
do bj = mybylo(mythid),mybyhi(mythid) |
324 |
do bi = mybxlo(mythid),mybxhi(mythid) |
325 |
do j = 1,sny |
326 |
do i = 1,snx |
327 |
genfld(i,j,bi,bj) = |
328 |
& exf_inscal_gen * genfld(i,j,bi,bj) |
329 |
enddo |
330 |
enddo |
331 |
enddo |
332 |
enddo |
333 |
|
334 |
endif |
335 |
|
336 |
RETURN |
337 |
END |