1 |
C $Header: /u/gcmpack/MITgcm/pkg/aim_v23/aim_fields_load.F,v 1.3 2004/11/14 19:54:01 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "AIM_OPTIONS.h" |
5 |
|
6 |
CStartOfInterface |
7 |
SUBROUTINE AIM_FIELDS_LOAD( |
8 |
I myTime, myIter, myThid ) |
9 |
C *==========================================================* |
10 |
C | SUBROUTINE AIM_FIELDS_LOAD |
11 |
C | o Control reading of AIM fields from external source. |
12 |
C *==========================================================* |
13 |
C | Loads surface boundary condition datasets for AIM. |
14 |
C | The routine is called every timetep and periodically |
15 |
C | loads a set of external fields. |
16 |
C | Monthly climatology files are read either for |
17 |
C | a) a direct use (useMMsurfFc): |
18 |
C | Albedo, Soil moisture, Surface Temperature |
19 |
C | b) time interpolation (useFMsurfBC): |
20 |
C | Sea & Land surf. Temp, snow, sea-ice, soil-water (2-lev) |
21 |
C | + (1rst.iter) ground albedo, vegetation, land-sea fraction |
22 |
C | Most of the work is done by the master the thread while |
23 |
C | the other threads spin. |
24 |
C *==========================================================* |
25 |
IMPLICIT NONE |
26 |
|
27 |
C === Global variables === |
28 |
#include "SIZE.h" |
29 |
#include "EEPARAMS.h" |
30 |
#include "PARAMS.h" |
31 |
#include "GRID.h" |
32 |
#include "AIM_PARAMS.h" |
33 |
c #include "AIM_GRID.h" |
34 |
#include "AIM_FFIELDS.h" |
35 |
|
36 |
C === Routine arguments === |
37 |
C myThid - Thread no. that called this routine. |
38 |
C myTime - Simulation time |
39 |
C myIter - Simulation timestep number |
40 |
INTEGER myThid |
41 |
_RL myTime |
42 |
INTEGER myIter |
43 |
CEndOfInterface |
44 |
|
45 |
C === Functions === |
46 |
|
47 |
#ifdef ALLOW_AIM |
48 |
C === Local variables === |
49 |
C bi,bj, i,j - Loop counters |
50 |
C tYear - Fraction within year of myTime |
51 |
C mnthIndex - Current time in whole months |
52 |
C prevMnthIndex |
53 |
C fNam - Strings used in constructing file names |
54 |
C mnthNam |
55 |
C pfact - used to convert Pot.Temp. to in-situ Temp. |
56 |
INTEGER bi,bj, i, j |
57 |
c _RL pfact |
58 |
INTEGER prevMnthIndex |
59 |
DATA prevMnthIndex / 0 / |
60 |
SAVE prevMnthIndex |
61 |
C-- for use with useMMsurfFc: |
62 |
_RL tYear, yearLength |
63 |
INTEGER mnthIndex |
64 |
CHARACTER*(MAX_LEN_FNAM) fNam |
65 |
CHARACTER*3 mnthNam(12) |
66 |
DATA mnthNam / |
67 |
& 'jan', 'feb', 'mar', 'apr', 'may', 'jun', |
68 |
& 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' / |
69 |
SAVE mnthNam |
70 |
C-- for use with useFMsurfBC: |
71 |
INTEGER aim_surfForc_NppCycle, nm0, nm1, nm2, nm3 |
72 |
_RL aim_surfForc_TimePeriod, aim_surfForc_TransRatio |
73 |
_RL t0prd, tNcyc, tmprd, dTprd |
74 |
|
75 |
IF (aim_useMMsurfFc) THEN |
76 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
77 |
C-- Use Monthly Mean surface forcing fields: |
78 |
|
79 |
C- Calculate offset into a year |
80 |
c tYear = myTime/(86400.*360.) - |
81 |
c & FLOAT(INT(myTime/(86400.*360.))) |
82 |
yearLength = 86400.*360. |
83 |
tYear = MOD(myTime/yearLength, 1. _d 0) |
84 |
mnthIndex = INT(tYear*12.)+1 |
85 |
|
86 |
IF ( mnthIndex .NE. prevMnthIndex .OR. |
87 |
& myIter.EQ.nIter0 ) THEN |
88 |
C- New month so load in data |
89 |
|
90 |
C Prevent loading of new data before everyone has finished with it |
91 |
CALL BAR2(myThid) |
92 |
|
93 |
C Master thread coordinates loading of AIM datasets |
94 |
_BEGIN_MASTER( myThid ) |
95 |
prevMnthIndex = mnthIndex |
96 |
|
97 |
C o Albedo ( convert % to fraction ) |
98 |
WRITE(fNam,'(A,A,A)' ) 'salb.', |
99 |
& mnthNam(mnthIndex), aim_MMsufx(1:aim_MMsufxLength) |
100 |
CALL MDSREADFIELD(fNam,readBinaryPrec,'RS',1, |
101 |
O aim_albedo, |
102 |
I 1,myThid) |
103 |
|
104 |
C o Surface temperature ( in kelvin ) |
105 |
IF (aim_surfPotTemp) THEN |
106 |
WRITE(fNam,'(A,A,A)' ) 'stheta.', |
107 |
& mnthNam(mnthIndex), aim_MMsufx(1:aim_MMsufxLength) |
108 |
ELSE |
109 |
WRITE(fNam,'(A,A,A)' ) 'sTemp.', |
110 |
& mnthNam(mnthIndex), aim_MMsufx(1:aim_MMsufxLength) |
111 |
ENDIF |
112 |
CALL MDSREADFIELD(fNam,readBinaryPrec,'RS',1, |
113 |
O aim_surftemp, |
114 |
I 1,myThid) |
115 |
|
116 |
C o Soil moisture |
117 |
WRITE(fNam,'(A,A,A)' ) 'smoist.', |
118 |
& mnthNam(mnthIndex), aim_MMsufx(1:aim_MMsufxLength) |
119 |
CALL MDSREADFIELD(fNam,readBinaryPrec,'RS',1, |
120 |
O aim_soilWater, |
121 |
I 1,myThid) |
122 |
|
123 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
124 |
|
125 |
C-- Converts fields for direct use in Atmos. Physics routine. |
126 |
C better here rather than in "aim_do_atmos" since: |
127 |
C a) change together conversion factor and input file name. |
128 |
C b) conversion applied only 1 time / month ; |
129 |
C c) easy to check here (variable in common). |
130 |
|
131 |
DO bj=1,nSy |
132 |
DO bi=1,nSx |
133 |
|
134 |
C- Converts surface albedo : input data is in % 0-100 |
135 |
C and Franco s package needs a fraction between 0-1 |
136 |
DO j=1,sNy |
137 |
DO i=1,sNx |
138 |
aim_albedo(I,J,bi,bj) = aim_albedo(I,J,bi,bj)/100. |
139 |
ENDDO |
140 |
ENDDO |
141 |
|
142 |
C- Converts soil moisture (case input is in cm in bucket of depth 20cm.) |
143 |
c DO j=1,sNy |
144 |
c DO i=1,sNx |
145 |
c aim_soilWater(I,J,bi,bj) = aim_soilWater(I,J,bi,bj) |
146 |
c & /20. |
147 |
c ENDDO |
148 |
c ENDDO |
149 |
|
150 |
C-- Correct for truncation (because of hFacMin) of surface reference |
151 |
C pressure Ro_surf that affects Surf.Temp. : |
152 |
DO j=1,sNy |
153 |
DO i=1,sNx |
154 |
c pfact = (Ro_surf(i,j,bi,bj)/atm_Po)**atm_kappa |
155 |
aim_surftemp(i,j,bi,bj) = aim_surftemp(i,j,bi,bj) |
156 |
& * truncSurfP(i,j,bi,bj) |
157 |
ENDDO |
158 |
ENDDO |
159 |
|
160 |
C-- end bi,bj loops |
161 |
ENDDO |
162 |
ENDDO |
163 |
|
164 |
IF (myIter.EQ.nIter0) |
165 |
& CALL WRITE_FLD_XY_RL('aim_Tsurf',' ',aim_surfTemp,0,myThid) |
166 |
|
167 |
_END_MASTER( myThid ) |
168 |
|
169 |
C Stop anyone leaving until all data is read |
170 |
CALL BAR2(myThid) |
171 |
|
172 |
C- endif New month - load in data |
173 |
ENDIF |
174 |
|
175 |
ELSEIF (aim_useFMsurfBC) THEN |
176 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
177 |
C-- Use Franco Molteni surface BC: |
178 |
C take part of S/R INFORC + part of S/R FORDATE (albedo) |
179 |
C of the F.Molteni SPEEDY code (ver23) |
180 |
|
181 |
IF ( myIter.EQ.nIter0 ) THEN |
182 |
DO bj = myByLo(myThid), myByHi(myThid) |
183 |
DO bi = myBxLo(myThid), myBxHi(myThid) |
184 |
DO j=1-Oly,sNy+Oly |
185 |
DO i=1-Olx,sNx+Olx |
186 |
c aim_landFr(i,j,bi,bj)= 0. |
187 |
aim_albedo(i,j,bi,bj)= 0. |
188 |
aim_veget(i,j,bi,bj) = 0. |
189 |
aim_sst0(i,j,bi,bj) =300. |
190 |
aim_lst0(i,j,bi,bj) =300. |
191 |
aim_oic0(i,j,bi,bj) = 0. |
192 |
aim_snw0(i,j,bi,bj) = 0. |
193 |
aim_sw10(i,j,bi,bj) = 0. |
194 |
aim_sw20(i,j,bi,bj) = 0. |
195 |
aim_sst1(i,j,bi,bj) =300. |
196 |
aim_lst1(i,j,bi,bj) =300. |
197 |
aim_oic1(i,j,bi,bj) = 0. |
198 |
aim_snw1(i,j,bi,bj) = 0. |
199 |
aim_sw11(i,j,bi,bj) = 0. |
200 |
aim_sw21(i,j,bi,bj) = 0. |
201 |
ENDDO |
202 |
ENDDO |
203 |
ENDDO |
204 |
ENDDO |
205 |
ENDIF |
206 |
|
207 |
C- Length (s) of one time period: |
208 |
aim_surfForc_TimePeriod = 30.*86400. |
209 |
C- Number of time period per Cycle: |
210 |
aim_surfForc_NppCycle = 12 |
211 |
C- define how fast the (linear) transition is from one month to the next |
212 |
C = 1 -> linear between 2 midle month |
213 |
C > TimePeriod/deltaT -> jump from one month to the next one |
214 |
aim_surfForc_TransRatio = 1. |
215 |
|
216 |
t0prd = myTime / aim_surfForc_TimePeriod |
217 |
tNcyc = aim_surfForc_NppCycle |
218 |
tmprd = t0prd - 0.5 _d 0 + tNcyc |
219 |
tmprd = MOD(tmprd,tNcyc) |
220 |
C- indices of previous month and next month: |
221 |
nm0 = 1 + INT(tmprd) |
222 |
nm1 = 1 + MOD(nm0,aim_surfForc_NppCycle) |
223 |
C- interpolation weight: |
224 |
dTprd = tmprd - (nm0 - 1) |
225 |
aim_sWght1 = 0.5 _d 0+(dTprd-0.5 _d 0)*aim_surfForc_TransRatio |
226 |
aim_sWght1 = MAX( 0. _d 0, MIN(1. _d 0, aim_sWght1) ) |
227 |
aim_sWght0 = 1. _d 0 - aim_sWght1 |
228 |
|
229 |
IF (myIter.EQ.nIter0 .OR. nm0.NE.prevMnthIndex) THEN |
230 |
C- Load new data: |
231 |
|
232 |
C Prevent loading of new data before everyone has finished with it |
233 |
CALL BAR2(myThid) |
234 |
|
235 |
C Master thread coordinates loading of AIM datasets |
236 |
_BEGIN_MASTER( myThid ) |
237 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
238 |
prevMnthIndex = nm0 |
239 |
|
240 |
IF ( myIter.EQ.nIter0 ) THEN |
241 |
C-- Load Fixed Forcing only at the 1rst iter: |
242 |
|
243 |
c IF ( aim_LandFile .NE. ' ' ) THEN |
244 |
c CALL READ_REC_XY_RS(aim_LandFile,aim_landFr,1,myIter,myThid) |
245 |
c ENDIF |
246 |
IF ( aim_albFile .NE. ' ' ) THEN |
247 |
CALL READ_REC_XY_RS(aim_albFile,aim_albedo, 1,myIter,myThid) |
248 |
ENDIF |
249 |
c alb0(i,j) = 0.01*r4inp(i,j) |
250 |
IF ( aim_vegFile .NE. ' ' ) THEN |
251 |
CALL READ_REC_XY_RS(aim_vegFile,aim_veget,1,myIter,myThid) |
252 |
ENDIF |
253 |
|
254 |
DO bj=1,nSy |
255 |
DO bi=1,nSx |
256 |
|
257 |
C- Converts surface albedo : from % (input data) to a fraction [0-1} |
258 |
c alb0(i,j) = 0.01*r4inp(i,j) |
259 |
DO j=1,sNy |
260 |
DO i=1,sNx |
261 |
aim_albedo(i,j,bi,bj) = aim_albedo(I,J,bi,bj)/100. _d 0 |
262 |
ENDDO |
263 |
ENDDO |
264 |
|
265 |
C- Converts vegetation fraction: from % (input data) to a fraction [0-1] |
266 |
c veg(i,j)=max(0.,0.01*veg(i,j)) |
267 |
DO j=1,sNy |
268 |
DO i=1,sNx |
269 |
aim_veget(i,j,bi,bj) = |
270 |
& MAX(0. _d 0, aim_veget(i,j,bi,bj)/100. _d 0) |
271 |
ENDDO |
272 |
ENDDO |
273 |
|
274 |
ENDDO |
275 |
ENDDO |
276 |
|
277 |
C-- endif 1rst iter. |
278 |
ENDIF |
279 |
|
280 |
IF ( aim_sstFile .NE. ' ' ) THEN |
281 |
CALL READ_REC_XY_RS(aim_sstFile,aim_sst0,nm0,myIter,myThid) |
282 |
CALL READ_REC_XY_RS(aim_sstFile,aim_sst1,nm1,myIter,myThid) |
283 |
ENDIF |
284 |
IF ( aim_lstFile .NE. ' ' ) THEN |
285 |
CALL READ_REC_XY_RS(aim_lstFile,aim_lst0,nm0,myIter,myThid) |
286 |
CALL READ_REC_XY_RS(aim_lstFile,aim_lst1,nm1,myIter,myThid) |
287 |
ENDIF |
288 |
IF ( aim_oiceFile .NE. ' ' ) THEN |
289 |
CALL READ_REC_XY_RS(aim_oiceFile,aim_oic0,nm0,myIter,myThid) |
290 |
CALL READ_REC_XY_RS(aim_oiceFile,aim_oic1,nm1,myIter,myThid) |
291 |
ENDIF |
292 |
IF ( aim_snowFile .NE. ' ' ) THEN |
293 |
CALL READ_REC_XY_RS(aim_snowFile,aim_snw0,nm0,myIter,myThid) |
294 |
CALL READ_REC_XY_RS(aim_snowFile,aim_snw1,nm1,myIter,myThid) |
295 |
ENDIF |
296 |
IF ( aim_swcFile .NE. ' ' ) THEN |
297 |
CALL READ_REC_XY_RS(aim_swcFile,aim_sw10,nm0,myIter,myThid) |
298 |
CALL READ_REC_XY_RS(aim_swcFile,aim_sw11,nm1,myIter,myThid) |
299 |
nm2 = nm0 + aim_surfForc_NppCycle |
300 |
nm3 = nm1 + aim_surfForc_NppCycle |
301 |
CALL READ_REC_XY_RS(aim_swcFile,aim_sw20,nm2,myIter,myThid) |
302 |
CALL READ_REC_XY_RS(aim_swcFile,aim_sw21,nm3,myIter,myThid) |
303 |
ENDIF |
304 |
|
305 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
306 |
_END_MASTER( myThid ) |
307 |
|
308 |
C Stop anyone leaving until all data is read |
309 |
CALL BAR2(myThid) |
310 |
|
311 |
C-- Correct for truncation (because of hFacMin) of surface reference |
312 |
C pressure Ro_surf that affects Surf.Temp. : |
313 |
DO bj = myByLo(myThid), myByHi(myThid) |
314 |
DO bi = myBxLo(myThid), myBxHi(myThid) |
315 |
DO j=1,sNy |
316 |
DO i=1,sNx |
317 |
c pfact = (Ro_surf(i,j,bi,bj)/atm_Po)**atm_kappa |
318 |
aim_lst0(i,j,bi,bj) = aim_lst0(i,j,bi,bj) |
319 |
& * truncSurfP(i,j,bi,bj) |
320 |
aim_lst1(i,j,bi,bj) = aim_lst1(i,j,bi,bj) |
321 |
& * truncSurfP(i,j,bi,bj) |
322 |
ENDDO |
323 |
ENDDO |
324 |
ENDDO |
325 |
ENDDO |
326 |
|
327 |
C- endif load new data. |
328 |
ENDIF |
329 |
|
330 |
ENDIF |
331 |
|
332 |
#endif /* ALLOW_AIM */ |
333 |
|
334 |
RETURN |
335 |
END |