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