1 |
dimitri |
1.23 |
C $Header: /u/gcmpack/MITgcm/pkg/exf/exf_set_gen.F,v 1.22 2007/11/30 22:22:06 jmc Exp $ |
2 |
jmc |
1.18 |
C $Name: $ |
3 |
|
|
|
4 |
edhill |
1.7 |
#include "EXF_OPTIONS.h" |
5 |
heimbach |
1.2 |
|
6 |
|
|
subroutine exf_set_gen( |
7 |
heimbach |
1.10 |
& genfile, genstartdate, genperiod, |
8 |
|
|
& genstartdate1, genstartdate2, |
9 |
heimbach |
1.13 |
& exf_inscal_gen, genremove_intercept, genremove_slope, |
10 |
dimitri |
1.3 |
& genfld, gen0, gen1, genmask, |
11 |
|
|
#ifdef USE_EXF_INTERPOLATION |
12 |
|
|
& gen_lon0, gen_lon_inc, gen_lat0, gen_lat_inc, |
13 |
dimitri |
1.11 |
& gen_nlon, gen_nlat, gen_xout, gen_yout, interp_method, |
14 |
dimitri |
1.3 |
#endif |
15 |
heimbach |
1.13 |
& mytime, myiter, mythid ) |
16 |
heimbach |
1.2 |
|
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 |
dimitri |
1.4 |
c 20-Dec-2002: mods for pkg/seaice, menemenlis@jpl.nasa.gov |
26 |
heimbach |
1.2 |
c heimbach@mit.edu: totally re-organized exf_set_... |
27 |
|
|
c replaced all routines by one generic routine |
28 |
dimitri |
1.4 |
c 5-Aug-2003: added USE_EXF_INTERPOLATION for arbitrary |
29 |
|
|
c input grid capability |
30 |
dimitri |
1.15 |
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 |
heimbach |
1.2 |
|
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 |
heimbach |
1.13 |
#include "PARAMS.h" |
45 |
heimbach |
1.2 |
#include "GRID.h" |
46 |
|
|
|
47 |
jmc |
1.18 |
#include "EXF_PARAM.h" |
48 |
|
|
#include "EXF_CONSTANTS.h" |
49 |
heimbach |
1.2 |
|
50 |
|
|
c == routine arguments == |
51 |
|
|
|
52 |
heimbach |
1.10 |
integer genstartdate1, genstartdate2 |
53 |
heimbach |
1.13 |
_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 |
heimbach |
1.2 |
character*1 genmask |
60 |
dimitri |
1.16 |
character*(128) genfile |
61 |
heimbach |
1.13 |
_RL mytime |
62 |
|
|
integer myiter |
63 |
heimbach |
1.2 |
integer mythid |
64 |
dimitri |
1.16 |
|
65 |
dimitri |
1.3 |
#ifdef USE_EXF_INTERPOLATION |
66 |
dimitri |
1.4 |
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 |
dimitri |
1.3 |
_RL gen_lon0, gen_lon_inc |
73 |
|
|
_RL gen_lat0, gen_lat_inc(MAX_LAT_INC) |
74 |
|
|
INTEGER gen_nlon, gen_nlat |
75 |
dimitri |
1.4 |
_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 |
dimitri |
1.11 |
integer interp_method |
78 |
dimitri |
1.16 |
#endif /* USE_EXF_INTERPOLATION */ |
79 |
heimbach |
1.2 |
|
80 |
|
|
c == local variables == |
81 |
|
|
|
82 |
|
|
logical first, changed |
83 |
|
|
integer count0, count1 |
84 |
heimbach |
1.10 |
integer year0, year1 |
85 |
dimitri |
1.16 |
integer bi, bj, i, j, il |
86 |
heimbach |
1.2 |
_RL fac |
87 |
dimitri |
1.16 |
character*(128) genfile0, genfile1 |
88 |
heimbach |
1.10 |
|
89 |
|
|
c == external == |
90 |
|
|
|
91 |
|
|
integer ilnblnk |
92 |
|
|
external ilnblnk |
93 |
heimbach |
1.2 |
|
94 |
|
|
c == end of interface == |
95 |
|
|
|
96 |
dimitri |
1.16 |
if ( genfile .NE. ' ' .and. genperiod .ne. 0 ) then |
97 |
heimbach |
1.2 |
|
98 |
heimbach |
1.10 |
cph( |
99 |
|
|
cph-exf-print if (genfile .EQ. hfluxfile) year0 = 3000 |
100 |
|
|
cph) |
101 |
dimitri |
1.15 |
|
102 |
dimitri |
1.16 |
if ( genperiod .eq. -12 ) then |
103 |
dimitri |
1.15 |
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 |
dimitri |
1.23 |
STOP 'ABNORMAL END: S/R EXF_SET_GEN' |
115 |
dimitri |
1.15 |
|
116 |
|
|
else |
117 |
heimbach |
1.2 |
c get record numbers and interpolation factor for gen |
118 |
dimitri |
1.15 |
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 |
heimbach |
1.2 |
|
129 |
|
|
if ( first ) then |
130 |
dimitri |
1.15 |
if (useExfYearlyFields.and.genperiod.gt.0) then |
131 |
dimitri |
1.12 |
C Complete filename with YR or _YEAR extension |
132 |
heimbach |
1.10 |
il = ilnblnk( genfile ) |
133 |
dimitri |
1.12 |
if (twoDigitYear) then |
134 |
|
|
if (year0.ge.2000) then |
135 |
|
|
write(genfile0(1:128),'(a,i2.2)') |
136 |
|
|
& genfile(1:il),year0-2000 |
137 |
|
|
else |
138 |
|
|
write(genfile0(1:128),'(a,i2.2)') |
139 |
|
|
& genfile(1:il),year0-1900 |
140 |
|
|
endif |
141 |
|
|
else |
142 |
|
|
write(genfile0(1:128),'(2a,i4.4)') |
143 |
|
|
& genfile(1:il),'_',year0 |
144 |
|
|
endif |
145 |
heimbach |
1.10 |
else |
146 |
|
|
genfile0 = genfile |
147 |
|
|
endif |
148 |
dimitri |
1.15 |
|
149 |
dimitri |
1.3 |
#ifdef USE_EXF_INTERPOLATION |
150 |
heimbach |
1.10 |
call exf_interp( genfile0, exf_iprec |
151 |
dimitri |
1.4 |
& , gen1, count0, gen_xout, gen_yout |
152 |
dimitri |
1.3 |
& , gen_lon0,gen_lon_inc |
153 |
|
|
& , gen_lat0,gen_lat_inc |
154 |
dimitri |
1.5 |
& , gen_nlon,gen_nlat,interp_method,mythid |
155 |
dimitri |
1.3 |
& ) |
156 |
|
|
#else |
157 |
jmc |
1.22 |
_BARRIER |
158 |
heimbach |
1.10 |
call mdsreadfield( genfile0, exf_iprec, exf_yftype, 1 |
159 |
heimbach |
1.2 |
& , gen1, count0, mythid |
160 |
|
|
& ) |
161 |
jmc |
1.22 |
_BARRIER |
162 |
dimitri |
1.16 |
#endif /* USE_EXF_INTERPOLATION */ |
163 |
heimbach |
1.2 |
|
164 |
|
|
if (exf_yftype .eq. 'RL') then |
165 |
|
|
call exf_filter_rl( gen1, genmask, mythid ) |
166 |
|
|
else |
167 |
|
|
call exf_filter_rs( gen1, genmask, mythid ) |
168 |
|
|
end if |
169 |
|
|
endif |
170 |
|
|
|
171 |
|
|
if (( first ) .or. ( changed )) then |
172 |
|
|
call exf_SwapFFields( gen0, gen1, mythid ) |
173 |
|
|
|
174 |
dimitri |
1.15 |
if (useExfYearlyFields.and.genperiod.gt.0) then |
175 |
dimitri |
1.12 |
C Complete filename with YR or _YEAR extension |
176 |
heimbach |
1.10 |
il = ilnblnk( genfile ) |
177 |
dimitri |
1.12 |
if (twoDigitYear) then |
178 |
|
|
if (year1.ge.2000) then |
179 |
|
|
write(genfile1(1:128),'(a,i2.2)') |
180 |
|
|
& genfile(1:il),year1-2000 |
181 |
|
|
else |
182 |
|
|
write(genfile1(1:128),'(a,i2.2)') |
183 |
|
|
& genfile(1:il),year1-1900 |
184 |
|
|
endif |
185 |
|
|
else |
186 |
|
|
write(genfile1(1:128),'(2a,i4.4)') |
187 |
|
|
& genfile(1:il),'_',year1 |
188 |
|
|
endif |
189 |
heimbach |
1.10 |
else |
190 |
|
|
genfile1 = genfile |
191 |
|
|
endif |
192 |
dimitri |
1.3 |
#ifdef USE_EXF_INTERPOLATION |
193 |
heimbach |
1.10 |
call exf_interp( genfile1, exf_iprec |
194 |
dimitri |
1.4 |
& , gen1, count1, gen_xout, gen_yout |
195 |
dimitri |
1.3 |
& , gen_lon0,gen_lon_inc |
196 |
|
|
& , gen_lat0,gen_lat_inc |
197 |
dimitri |
1.5 |
& , gen_nlon,gen_nlat,interp_method,mythid |
198 |
dimitri |
1.3 |
& ) |
199 |
|
|
#else |
200 |
jmc |
1.22 |
_BARRIER |
201 |
heimbach |
1.10 |
call mdsreadfield( genfile1, exf_iprec, exf_yftype, 1 |
202 |
heimbach |
1.2 |
& , gen1, count1, mythid |
203 |
|
|
& ) |
204 |
jmc |
1.22 |
_BARRIER |
205 |
dimitri |
1.16 |
#endif /* USE_EXF_INTERPOLATION */ |
206 |
heimbach |
1.2 |
|
207 |
|
|
if (exf_yftype .eq. 'RL') then |
208 |
|
|
call exf_filter_rl( gen1, genmask, mythid ) |
209 |
|
|
else |
210 |
|
|
call exf_filter_rs( gen1, genmask, mythid ) |
211 |
|
|
end if |
212 |
|
|
endif |
213 |
|
|
|
214 |
|
|
c Loop over tiles. |
215 |
|
|
do bj = mybylo(mythid),mybyhi(mythid) |
216 |
heimbach |
1.13 |
do bi = mybxlo(mythid),mybxhi(mythid) |
217 |
|
|
do j = 1,sny |
218 |
|
|
do i = 1,snx |
219 |
|
|
c Interpolate linearly onto the time. |
220 |
|
|
genfld(i,j,bi,bj) = exf_inscal_gen * ( |
221 |
|
|
& fac * gen0(i,j,bi,bj) + |
222 |
|
|
& (exf_one - fac) * gen1(i,j,bi,bj) ) |
223 |
|
|
genfld(i,j,bi,bj) = |
224 |
|
|
& genfld(i,j,bi,bj) - |
225 |
|
|
& exf_inscal_gen * ( genremove_intercept + |
226 |
|
|
& genremove_slope*(mytime-starttime) ) |
227 |
heimbach |
1.2 |
enddo |
228 |
heimbach |
1.20 |
enddo |
229 |
|
|
enddo |
230 |
heimbach |
1.2 |
enddo |
231 |
|
|
|
232 |
|
|
endif |
233 |
|
|
|
234 |
jmc |
1.22 |
RETURN |
235 |
|
|
END |
236 |
heimbach |
1.2 |
|
237 |
dimitri |
1.16 |
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
238 |
|
|
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
239 |
heimbach |
1.2 |
|
240 |
|
|
subroutine exf_init_gen ( |
241 |
dimitri |
1.17 |
& genfile, genperiod, exf_inscal_gen, genmask, |
242 |
dimitri |
1.16 |
& genconst, genfld, gen0, gen1, |
243 |
|
|
#ifdef USE_EXF_INTERPOLATION |
244 |
|
|
& gen_lon0, gen_lon_inc, gen_lat0, gen_lat_inc, |
245 |
|
|
& gen_nlon, gen_nlat, gen_xout, gen_yout, interp_method, |
246 |
|
|
#endif |
247 |
|
|
& mythid ) |
248 |
|
|
|
249 |
heimbach |
1.2 |
|
250 |
|
|
c ================================================================== |
251 |
|
|
c SUBROUTINE exf_init_gen |
252 |
|
|
c ================================================================== |
253 |
|
|
c |
254 |
|
|
c o |
255 |
|
|
c |
256 |
|
|
c started: Ralf.Giering@FastOpt.de 25-Mai-2000 |
257 |
|
|
c changed: heimbach@mit.edu 10-Jan-2002 |
258 |
|
|
c heimbach@mit.edu: totally re-organized exf_set_... |
259 |
|
|
c replaced all routines by one generic routine |
260 |
|
|
c |
261 |
|
|
c ================================================================== |
262 |
|
|
c SUBROUTINE exf_init_gen |
263 |
|
|
c ================================================================== |
264 |
|
|
|
265 |
|
|
implicit none |
266 |
|
|
|
267 |
|
|
c == global variables == |
268 |
|
|
|
269 |
|
|
#include "EEPARAMS.h" |
270 |
|
|
#include "SIZE.h" |
271 |
|
|
|
272 |
jmc |
1.18 |
#include "EXF_PARAM.h" |
273 |
heimbach |
1.2 |
|
274 |
|
|
c == routine arguments == |
275 |
|
|
|
276 |
dimitri |
1.17 |
_RL genperiod, exf_inscal_gen, genconst |
277 |
heimbach |
1.2 |
_RL genfld(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
278 |
|
|
_RL gen0 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
279 |
|
|
_RL gen1 (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
280 |
dimitri |
1.16 |
character*1 genmask |
281 |
|
|
character*(128) genfile |
282 |
heimbach |
1.2 |
integer mythid |
283 |
|
|
|
284 |
dimitri |
1.16 |
#ifdef USE_EXF_INTERPOLATION |
285 |
|
|
c gen_lon_0 ,gen_lat_0 :: longitude and latitude of SouthWest |
286 |
|
|
c corner of global input grid |
287 |
|
|
c gen_nlon, gen_nlat :: input x-grid and y-grid size |
288 |
|
|
c gen_lon_inc :: scalar x-grid increment |
289 |
|
|
c gen_lat_inc :: vector y-grid increments |
290 |
|
|
c gen_xout, gen_yout :: coordinates for output grid |
291 |
|
|
_RL gen_lon0, gen_lon_inc |
292 |
|
|
_RL gen_lat0, gen_lat_inc(MAX_LAT_INC) |
293 |
|
|
INTEGER gen_nlon, gen_nlat |
294 |
|
|
_RS gen_xout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
295 |
|
|
_RS gen_yout (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
296 |
|
|
integer interp_method |
297 |
|
|
#endif /* USE_EXF_INTERPOLATION */ |
298 |
|
|
|
299 |
heimbach |
1.2 |
c == local variables == |
300 |
|
|
|
301 |
dimitri |
1.16 |
integer bi, bj, i, j, count |
302 |
heimbach |
1.2 |
|
303 |
|
|
c == end of interface == |
304 |
|
|
|
305 |
|
|
do bj = mybylo(mythid), mybyhi(mythid) |
306 |
|
|
do bi = mybxlo(mythid), mybxhi(mythid) |
307 |
heimbach |
1.9 |
do j = 1-oly, sny+oly |
308 |
|
|
do i = 1-olx, snx+olx |
309 |
heimbach |
1.2 |
genfld(i,j,bi,bj) = genconst |
310 |
heimbach |
1.9 |
gen0(i,j,bi,bj) = genconst |
311 |
|
|
gen1(i,j,bi,bj) = genconst |
312 |
heimbach |
1.2 |
enddo |
313 |
|
|
enddo |
314 |
|
|
enddo |
315 |
|
|
enddo |
316 |
|
|
|
317 |
dimitri |
1.17 |
if ( genfile .NE. ' ' .and. genperiod .eq. 0. ) then |
318 |
dimitri |
1.16 |
count = 1 |
319 |
|
|
|
320 |
|
|
#ifdef USE_EXF_INTERPOLATION |
321 |
|
|
call exf_interp( genfile, exf_iprec |
322 |
|
|
& , genfld, count, gen_xout, gen_yout |
323 |
|
|
& , gen_lon0,gen_lon_inc |
324 |
|
|
& , gen_lat0,gen_lat_inc |
325 |
|
|
& , gen_nlon,gen_nlat,interp_method,mythid |
326 |
|
|
& ) |
327 |
|
|
#else |
328 |
jmc |
1.22 |
_BARRIER |
329 |
dimitri |
1.16 |
call mdsreadfield( genfile, exf_iprec, exf_yftype, 1 |
330 |
|
|
& , genfld, count, mythid |
331 |
|
|
& ) |
332 |
jmc |
1.22 |
_BARRIER |
333 |
dimitri |
1.16 |
#endif /* USE_EXF_INTERPOLATION */ |
334 |
|
|
|
335 |
|
|
if (exf_yftype .eq. 'RL') then |
336 |
|
|
call exf_filter_rl( genfld, genmask, mythid ) |
337 |
|
|
else |
338 |
|
|
call exf_filter_rs( genfld, genmask, mythid ) |
339 |
|
|
end if |
340 |
|
|
|
341 |
dimitri |
1.23 |
c Loop over tiles and scale genfld |
342 |
dimitri |
1.16 |
do bj = mybylo(mythid),mybyhi(mythid) |
343 |
|
|
do bi = mybxlo(mythid),mybxhi(mythid) |
344 |
|
|
do j = 1,sny |
345 |
|
|
do i = 1,snx |
346 |
|
|
genfld(i,j,bi,bj) = |
347 |
|
|
& exf_inscal_gen * genfld(i,j,bi,bj) |
348 |
|
|
enddo |
349 |
|
|
enddo |
350 |
|
|
enddo |
351 |
|
|
enddo |
352 |
|
|
|
353 |
heimbach |
1.14 |
endif |
354 |
|
|
|
355 |
jmc |
1.22 |
RETURN |
356 |
|
|
END |