1 |
% |
2 |
% $Id: assemble_ML.m,v 1.7 2006/03/14 03:10:42 edhill Exp $ |
3 |
% |
4 |
% Ed Hill |
5 |
% |
6 |
% Generate the APE ML01--ML07 and ME01--ME07 fields: |
7 |
% |
8 |
% For all time steps: |
9 |
% For all variables: |
10 |
% For all facets: |
11 |
% interpolate to the P17 pressure levels: |
12 |
% compute the "derived" fields: |
13 |
% sum: |
14 |
% Compute the averages from the sums: |
15 |
% Rotate vector components as necessary: |
16 |
% Convert units as necessary: |
17 |
% Regrid onto lat-lon: |
18 |
% Write netCDF output with all attributes: |
19 |
% |
20 |
|
21 |
%====================================================================== |
22 |
% |
23 |
% Define the connections between the APE "ML" variables and the |
24 |
% MITgcm diagnostics output |
25 |
% |
26 |
nfacets = 6; |
27 |
% bname = 'data/MLave.t%03d.nc'; |
28 |
bname = 'data/ML_ave_%d.nc'; |
29 |
gname = 'data/grid.t%03d.nc'; |
30 |
r_con_name = 'scrip_regrid/rmp_CS32_to_LL128x64_conserv.nc'; |
31 |
r_dwt_name = 'scrip_regrid/rmp_CS32_to_LL128x64_distwgt.nc'; |
32 |
oname = { 'ML_fields.nc' }; |
33 |
|
34 |
flags.regrid_type_for_vec = 2; |
35 |
flags.debug_lev = 0; |
36 |
flags.punits_conv = 0.01; |
37 |
|
38 |
% Get the following from: |
39 |
% ! (cd ../../ape_data_specs/ ; ./ml_parse.sh) |
40 |
vars = {}; |
41 |
vars{1} = {'ML01','ml_u','UVEL','eastward_wind','m s-1','u','1','ee'}; |
42 |
vars{2} = {'ML02','ml_v','VVEL','northward_wind','m s-1','v','1','ee'}; |
43 |
vars{3} = {'ML03','ml_t','ML03','air_temperature','K','-','1','ec'}; |
44 |
vars{4} = {'ML04','ml_om','WVEL','omega','Pa s-1','-','1','ee'}; |
45 |
vars{5} = {'ML05','ml_phi','ML05','geopotential_height','m','-','1','ee'}; |
46 |
vars{6} = {'ML06','ml_q','SALT','specific_humidity','kg kg-1','-','1','cc'}; |
47 |
vars{7} = {'ML07','ml_rh','RELHUM','relative_humidity','percent','-','1','cc'}; |
48 |
vars{8} = {'ML08','ml_th','THETA','potential_temperature','K','-','1','ec'}; |
49 |
|
50 |
% Geopotential reference values |
51 |
% load geopot_20 ; geopot = geopot_20(:,2); clear geopot_20 |
52 |
phiref = ... |
53 |
[ -0.739878953 646.302002 1338.38696 2894.67627 4099.63135 ... |
54 |
5484.93359 7116.62549 9115.08008 10321.4688 11741.3574 13494.4102 ... |
55 |
15862.4404 17833.5605 19667.8887 22136.1934 23854.2266 26366.9375 ]; |
56 |
|
57 |
%====================================================================== |
58 |
% |
59 |
% Open the input files and get the (minimum) number of time steps |
60 |
% available across all the files |
61 |
% |
62 |
disp('Finding available time steps') |
63 |
|
64 |
ncl = {}; |
65 |
nTmin = 0; |
66 |
ifacet = 1; |
67 |
for ifacet = 1:nfacets |
68 |
fname = sprintf(bname,ifacet); |
69 |
nc = netcdf(fname, 'nowrite'); |
70 |
ncl{ifacet} = nc; |
71 |
nT = length( nc('T') ); |
72 |
if (ifacet == 1) |
73 |
nTmin = nT; |
74 |
else |
75 |
nTmin = min(nTmin, nT); |
76 |
end |
77 |
nc = []; |
78 |
end |
79 |
disp(sprintf(' total iterations found = %d',nTmin)); |
80 |
|
81 |
|
82 |
%====================================================================== |
83 |
% |
84 |
% Interpolate to the reference pressure levels and then compute the |
85 |
% derived fields and the temporal sums of all fields on the original |
86 |
% MITgcm grid |
87 |
% |
88 |
disp('Computing Sums') |
89 |
|
90 |
Pref = [ 1 2 3 5 7 10 15 20 25 30 40 50 60 70 85 92.5 100 ] * 10; |
91 |
Pref = Pref(length(Pref):-1:1); |
92 |
|
93 |
dat = []; |
94 |
it = 1; |
95 |
iv = 1; |
96 |
ifacet = 1; |
97 |
it0 = 1; |
98 |
for it = [ 1 ] % months.i_start:min(nTmin,months.i_end) |
99 |
disp(sprintf(' iteration = %d',it)); |
100 |
|
101 |
for iv = 1:length(vars) |
102 |
for ifacet = 1:nfacets |
103 |
|
104 |
t0 = []; |
105 |
t1 = []; |
106 |
vtmp = []; |
107 |
|
108 |
% cull unknown variables |
109 |
if ( vars{iv}{3}(1) == '-' ) |
110 |
continue |
111 |
end |
112 |
|
113 |
% skip over computed quantities |
114 |
if strcmp( vars{iv}{1} , vars{iv}{3} ) |
115 |
continue |
116 |
end |
117 |
|
118 |
% WARN about missing variables |
119 |
nc = ncl{ifacet}; |
120 |
if prod(size(nc{vars{iv}{3}})) == 0 |
121 |
if it == 1 |
122 |
str = 'var "%s" does not exist in file "%s"'; |
123 |
disp(sprintf([' Warning: ' str], vars{iv}{3}, name(nc))); |
124 |
end |
125 |
continue |
126 |
end |
127 |
|
128 |
% get the data |
129 |
t0 = squeeze( nc{ vars{iv}{3} }(it,:,:,:) ); |
130 |
|
131 |
% horizontally interpolate to u,v to mass points |
132 |
% |
133 |
% this has changed so that now the "+1" points are garbage |
134 |
% and must be ignored |
135 |
switch vars{iv}{6} |
136 |
case 'u' |
137 |
t1 = t0(:,:,1:32); |
138 |
case 'v' |
139 |
t1 = t0(:,1:32,:); |
140 |
otherwise |
141 |
t1 = t0; |
142 |
end |
143 |
|
144 |
vtmp = t1; |
145 |
|
146 |
% sum for averages |
147 |
if it0 == 1 |
148 |
dat(iv,ifacet).n = 1; |
149 |
dat(iv,ifacet).a = vtmp; |
150 |
else |
151 |
dat(iv,ifacet).n = dat(iv,ifacet).n + 1; |
152 |
dat(iv,ifacet).a = dat(iv,ifacet).a + vtmp; |
153 |
end |
154 |
|
155 |
end |
156 |
end |
157 |
|
158 |
% fill in the derived fields |
159 |
for iv = 1:length(vars) |
160 |
for ifacet = 1:nfacets |
161 |
|
162 |
tmp = []; |
163 |
vtmp = []; |
164 |
nc = ncl{ifacet}; |
165 |
|
166 |
if strcmp(vars{iv}{1},'ML03') |
167 |
% ML03 = THETA * (P/P0)^0.286 |
168 |
tmp = squeeze( nc{ 'THETA' }(it,:,:,:) ); |
169 |
for ii = 1:32 |
170 |
for jj = 1:32 |
171 |
tmp(:,ii,jj) = tmp(:,ii,jj) .* ( Pref' ./ 1000 ).^0.286; |
172 |
end |
173 |
end |
174 |
end |
175 |
|
176 |
if strcmp(vars{iv}{1},'ML05') |
177 |
% ML05 = (PHIHYD/9.81) + ref |
178 |
tmp = squeeze( nc{ 'PHIHYD' }(it,:,:,:) ); |
179 |
nn = size(tmp); |
180 |
for ii = 1:32 |
181 |
for jj = 1:32 |
182 |
tmp(:,ii,jj) = squeeze(tmp(:,ii,jj))/9.81 + phiref'; % + geopot; |
183 |
end |
184 |
end |
185 |
end |
186 |
|
187 |
if prod(size(tmp)) > 0 |
188 |
|
189 |
if it0 == 1 |
190 |
dat(iv,ifacet).n = 1; |
191 |
dat(iv,ifacet).a = tmp; |
192 |
else |
193 |
dat(iv,ifacet).n = dat(iv,ifacet).n + 1; |
194 |
dat(iv,ifacet).a = dat(iv,ifacet).a + tmp; |
195 |
end |
196 |
end |
197 |
|
198 |
end |
199 |
end |
200 |
|
201 |
it0 = 0; |
202 |
|
203 |
end |
204 |
clear tmp |
205 |
|
206 |
% close the input files |
207 |
for ifacet = 1:nfacets |
208 |
nc = close( ncl{ifacet} ); |
209 |
end |
210 |
clear ncl; |
211 |
|
212 |
if 1 == 0 |
213 |
for iv = 1:length(vars) |
214 |
for ifacet = 1:nfacets |
215 |
for iz = 1:5:17 |
216 |
aa = squeeze( dat(iv,ifacet).a(iz,:,:) ); |
217 |
surf(aa), view(2), shading flat, colorbar |
218 |
disp([iv ifacet iz]); |
219 |
pause(1) |
220 |
end |
221 |
end |
222 |
end |
223 |
end |
224 |
|
225 |
% interpolate u,v to mass points |
226 |
nc = 32; |
227 |
ncp = nc + 1; |
228 |
|
229 |
for iv = 1:length(vars) |
230 |
switch vars{iv}{6} |
231 |
case 'u' |
232 |
|
233 |
nr = size(dat(iv,1).a,1); |
234 |
u3d = zeros(nc,nc,nr,6); |
235 |
v3d = zeros(nc,nc,nr,6); |
236 |
for fi = 1:6 |
237 |
u3d(:,:,:,fi) = permute( dat(iv, fi).a, [3 2 1] ); |
238 |
v3d(:,:,:,fi) = permute( dat(iv+1,fi).a, [3 2 1] ); |
239 |
end |
240 |
|
241 |
u6t=zeros(ncp,nc,nr,6); |
242 |
v6t=zeros(nc,ncp,nr,6); |
243 |
u6t([1:nc],:,:,:)=u3d(:,:,:,:); |
244 |
v6t(:,[1:nc],:,:)=v3d(:,:,:,:); |
245 |
|
246 |
u6t(ncp,[1:nc],:,1)=u3d(1,[1:nc],:,2); |
247 |
u6t(ncp,[1:nc],:,2)=v3d([nc:-1:1],1,:,4); |
248 |
u6t(ncp,[1:nc],:,3)=u3d(1,[1:nc],:,4); |
249 |
u6t(ncp,[1:nc],:,4)=v3d([nc:-1:1],1,:,6); |
250 |
u6t(ncp,[1:nc],:,5)=u3d(1,[1:nc],:,6); |
251 |
u6t(ncp,[1:nc],:,6)=v3d([nc:-1:1],1,:,2); |
252 |
|
253 |
v6t([1:nc],ncp,:,1)=u3d(1,[nc:-1:1],:,3); |
254 |
v6t([1:nc],ncp,:,2)=v3d([1:nc],1,:,3); |
255 |
v6t([1:nc],ncp,:,3)=u3d(1,[nc:-1:1],:,5); |
256 |
v6t([1:nc],ncp,:,4)=v3d([1:nc],1,:,5); |
257 |
v6t([1:nc],ncp,:,5)=u3d(1,[nc:-1:1],:,1); |
258 |
v6t([1:nc],ncp,:,6)=v3d([1:nc],1,:,1); |
259 |
|
260 |
for fi = 1:6 |
261 |
dat(iv, fi).a = permute( ... |
262 |
0.5*( u6t([1:nc],:,:,fi) + u6t([2:ncp],:,:,fi) ), [3 2 1] ); |
263 |
dat(iv+1,fi).a = permute( ... |
264 |
0.5*( v6t(:,[1:nc],:,fi) + v6t(:,[2:ncp],:,fi) ), [3 2 1] ); |
265 |
end |
266 |
|
267 |
end |
268 |
end |
269 |
|
270 |
%====================================================================== |
271 |
% |
272 |
% Compute the averages from the temporal sums |
273 |
% |
274 |
disp('Computing Averages from Sums') |
275 |
|
276 |
ave = []; |
277 |
for iv = 1:length(vars) |
278 |
ind = length(ave) + 1; |
279 |
for ifacet = 1:nfacets |
280 |
if length(dat(iv,ifacet).n) == 0 |
281 |
continue |
282 |
end |
283 |
ave(ind).v(:,:,:,ifacet) = dat(iv,ifacet).a ./ dat(iv,ifacet).n; |
284 |
ave(ind).ivar = iv; |
285 |
end |
286 |
|
287 |
if 1 == 0 |
288 |
aa = squeeze(ave(ind).v(1,:,:,1)); |
289 |
surf(aa), view(2), shading interp, colorbar, pause(3) |
290 |
close all |
291 |
end |
292 |
|
293 |
end |
294 |
|
295 |
clear dat; |
296 |
|
297 |
%====================================================================== |
298 |
% |
299 |
% Rotate vector components & convert units |
300 |
% |
301 |
clear ig; |
302 |
gvars = { 'XC','YC','dxF','dyF','rA','XG','YG','dxV', ... |
303 |
'dyU','rAz','dxC','dyC','rAw','rAs','dxG','dyG' }; |
304 |
for iface = 1:6 |
305 |
fname = sprintf(gname, iface); |
306 |
nc = netcdf(fname, 'nowrite'); |
307 |
if iface == 1 |
308 |
ig.ne = length(nc('X')); |
309 |
end |
310 |
for jj = 1:length(gvars) |
311 |
comm = [ 'ig.' gvars{jj} '(:,:,iface) = nc{''' ... |
312 |
gvars{jj} '''}(:);']; |
313 |
eval(comm); |
314 |
end |
315 |
nc = close(nc); |
316 |
end |
317 |
|
318 |
ne = ig.ne; |
319 |
n1 = ne - 1; |
320 |
dux = zeros(size(ig.XC)); |
321 |
duy = zeros(size(ig.XC)); |
322 |
dvx = zeros(size(ig.XC)); |
323 |
dvy = zeros(size(ig.XC)); |
324 |
% dux(:,:,:) = diff(ig.XG(:,1:ne,:),1,1); |
325 |
% dvx(:,:,:) = diff(ig.XG(1:ne,:,:),1,2); |
326 |
% duy(:,:,:) = diff(ig.YG(:,1:ne,:),1,1); |
327 |
% dvy(:,:,:) = diff(ig.YG(1:ne,:,:),1,2); |
328 |
% |
329 |
% Note the first two dimensions below are permuted relative to the |
330 |
% ordering in the *.mitgrid files (commented-out above). |
331 |
dux(:,:,:) = diff(ig.XG(1:ne,:,:),1,2); |
332 |
dvx(:,:,:) = diff(ig.XG(:,1:ne,:),1,1); |
333 |
duy(:,:,:) = diff(ig.YG(1:ne,:,:),1,2); |
334 |
dvy(:,:,:) = diff(ig.YG(:,1:ne,:),1,1); |
335 |
dux = dux + 360*double(dux < 180); |
336 |
dux = dux - 360*double(dux > 180); % squeeze([ min(min(dux)) max(max(dux)) ]) |
337 |
duy = duy + 360*double(duy < 180); |
338 |
duy = duy - 360*double(duy > 180); % squeeze([ min(min(duy)) max(max(duy)) ]) |
339 |
dvx = dvx + 360*double(dvx < 180); |
340 |
dvx = dvx - 360*double(dvx > 180); % squeeze([ min(min(dvx)) max(max(dvx)) ]) |
341 |
dvy = dvy + 360*double(dvy < 180); |
342 |
dvy = dvy - 360*double(dvy > 180); % squeeze([ min(min(dvy)) max(max(dvy)) ]) |
343 |
dut = sqrt(dux.^2 + duy.^2); % squeeze([ min(min(dut)) max(max(dut)) ]) |
344 |
dvt = sqrt(dvx.^2 + dvy.^2); % squeeze([ min(min(dvt)) max(max(dvt)) ]) |
345 |
ig.llux = dux ./ dut; % squeeze([ min(min(ig.llux)) max(max(ig.llux)) ]) |
346 |
ig.lluy = duy ./ dut; % squeeze([ min(min(ig.lluy)) max(max(ig.lluy)) ]) |
347 |
ig.llvx = dvx ./ dvt; % squeeze([ min(min(ig.llvx)) max(max(ig.llvx)) ]) |
348 |
ig.llvy = dvy ./ dvt; % squeeze([ min(min(ig.llvy)) max(max(ig.llvy)) ]) |
349 |
clear dux duy dvx dvy dut dvt ne n1 |
350 |
|
351 |
if flags.regrid_type_for_vec ~= 2 |
352 |
% Vector rotation |
353 |
for ia = 1:length(ave) |
354 |
if strcmp(vars{ ave(ia).ivar }{6}, 'u') |
355 |
% llu = u .* llux + v .* llvx; |
356 |
% llv = u .* lluy + v .* llvy; |
357 |
for iz = 1:size(ave(ia).v,1) |
358 |
llu = squeeze( ave(ia).v(iz,:,:,:) ) .* ig.llux ... |
359 |
+ squeeze( ave(ia+1).v(iz,:,:,:) ) .* ig.llvx; |
360 |
llv = squeeze( ave(ia).v(iz,:,:,:) ) .* ig.lluy ... |
361 |
+ squeeze( ave(ia+1).v(iz,:,:,:) ) .* ig.llvy; |
362 |
ave(ia).v(iz,:,:,:) = llu; |
363 |
ave(ia+1).v(iz,:,:,:) = llv; |
364 |
end |
365 |
end |
366 |
end |
367 |
end |
368 |
clear llu llv |
369 |
|
370 |
% Units conversion |
371 |
for ia = 1:length(ave) |
372 |
if strcmp(vars{ ave(ia).ivar }{7}, '-') ~= 1 |
373 |
eval(['fac = ' vars{ ave(ia).ivar }{7} ';']); |
374 |
if fac ~= 1 |
375 |
ave(ia).v = fac .* ave(ia).v; |
376 |
end |
377 |
else |
378 |
|
379 |
end |
380 |
end |
381 |
|
382 |
%====================================================================== |
383 |
% |
384 |
% Regrid |
385 |
% |
386 |
% JMC suggested an evenly spaced Lat-Lon at: 128x64 |
387 |
% |
388 |
disp('Regridding') |
389 |
|
390 |
og = []; |
391 |
og.nlat = 64; |
392 |
og.nlon = 128; |
393 |
og.latcell = 180/og.nlat; |
394 |
og.loncell = 360/og.nlon; |
395 |
og.lat = linspace(-90+og.latcell/2, 90-og.latcell/2, og.nlat); |
396 |
og.lon = linspace(0+og.loncell/2, 360-og.loncell/2, og.nlon); |
397 |
og.latbnd(:,1) = og.lat - og.latcell/2.0; |
398 |
og.latbnd(:,2) = og.lat + og.latcell/2.0; |
399 |
og.lonbnd(:,1) = og.lon - og.loncell/2.0; |
400 |
og.lonbnd(:,2) = og.lon + og.loncell/2.0; |
401 |
|
402 |
|
403 |
rgvar = { 'src_address', 'dst_address', 'remap_matrix' }; |
404 |
rtype = { { 'con', r_con_name}, {'dwt', r_dwt_name } }; |
405 |
for kk = 1:length(rtype) |
406 |
nc = netcdf(rtype{kk}{2}, 'nowrite'); |
407 |
for jj = 1:length(rgvar) |
408 |
comm = sprintf('rgrid.%s.%s = nc{''%s''}(:);',... |
409 |
rtype{kk}{1},rgvar{jj},rgvar{jj}); |
410 |
eval(comm); |
411 |
% disp(comm); |
412 |
end |
413 |
nc = close(nc); |
414 |
end |
415 |
|
416 |
if ( flags.regrid_type_for_vec > 0 ) |
417 |
% >> x=rdmds('XC'); |
418 |
% >> y=rdmds('YC'); |
419 |
% >> t=rdmds('Ttave.0000513360'); |
420 |
% >> xi=-179:2:180;yi=-89:2:90; |
421 |
% >> del=cube2latlon_preprocess(x,y,xi,yi); |
422 |
% >> ti=cube2latlon_fast(del,t); |
423 |
aa_regrid.x = rdmds('aa_regrid/XC'); |
424 |
aa_regrid.y = rdmds('aa_regrid/YC'); |
425 |
% u = rdmds('aa_regrid/U.0000000000'); |
426 |
% v = rdmds('aa_regrid/V.0000000000'); |
427 |
% del = cube2latlon_preprocess(LON,LAT,xc,yc); |
428 |
% |
429 |
% aa_regrid.del = ... |
430 |
% cube2latlon_preprocess(aa_regrid.x,aa_regrid.y, ... |
431 |
% og.lon,og.lat); |
432 |
end |
433 |
|
434 |
% save ML_ave |
435 |
|
436 |
ii = 1; |
437 |
for ii = 1:length(ave) |
438 |
|
439 |
for iz = 1:size( ave(ii).v, 1 ) |
440 |
|
441 |
siz = size( ave(ii).v ); |
442 |
dcp = zeros(prod(siz(2:4)),1); |
443 |
nn = 0; |
444 |
for fk = 1:size( ave(ii).v, 4 ) |
445 |
for jk = 1:size( ave(ii).v, 3 ) |
446 |
for ik = 1:size( ave(ii).v, 2 ) |
447 |
nn = nn + 1; |
448 |
dcp(nn) = ave(ii).v(iz,ik,jk,fk); |
449 |
end |
450 |
end |
451 |
end |
452 |
lld = zeros(og.nlat*og.nlon,1); |
453 |
|
454 |
if ( ( flags.regrid_type_for_vec > 0 ) ... |
455 |
&& ( vars{ave(ii).ivar}{6} == 'u' ... |
456 |
|| vars{ave(ii).ivar}{6} == 'v' ) ) |
457 |
|
458 |
if flags.regrid_type_for_vec == 1 |
459 |
|
460 |
% use distributed weights for vectors |
461 |
for jj = 1:length(rgrid.dwt.src_address) |
462 |
lld(rgrid.dwt.dst_address(jj)) = ... |
463 |
lld(rgrid.dwt.dst_address(jj)) ... |
464 |
+ ( dcp(rgrid.dwt.src_address(jj)) ... |
465 |
* rgrid.dwt.remap_matrix(jj,1) ); |
466 |
end |
467 |
ave(ii).r(iz,:,:) = reshape(lld',og.nlat,og.nlon); |
468 |
|
469 |
elseif ( flags.regrid_type_for_vec == 2 ... |
470 |
&& vars{ave(ii).ivar}{6} == 'u' ) |
471 |
|
472 |
% use Alistair's uvcube2latlon() for vectors |
473 |
nsiz = size(ave(ii).v); |
474 |
by6u = zeros([ nsiz(2)*nsiz(4) nsiz(3) ]); |
475 |
by6v = zeros([ nsiz(2)*nsiz(4) nsiz(3) ]); |
476 |
for kk = 1:size( ave(ii).v, 4 ) |
477 |
is = 1 + (kk-1)*nsiz(2); |
478 |
ie = is + nsiz(2) - 1; |
479 |
by6u(is:ie,:) = squeeze( ave(ii ).v(iz,:,:,kk) )'; |
480 |
by6v(is:ie,:) = squeeze( ave(ii+1).v(iz,:,:,kk) )'; |
481 |
end |
482 |
% xi=-179:2:180; yi=-89:2:90; |
483 |
xi = og.lon; |
484 |
ind = find(xi > 179.5); |
485 |
xi(ind) = xi(ind) - 360; |
486 |
yi = og.lat; |
487 |
[ul,vl] = uvacube2latlon(aa_regrid.x,aa_regrid.y, ... |
488 |
by6u,by6v, xi,yi); |
489 |
ave(ii ).r(iz,:,:) = ul'; |
490 |
ave(ii+1).r(iz,:,:) = vl'; |
491 |
|
492 |
if flags.debug_lev > 0 |
493 |
figure(1), subplot(1,1,1) |
494 |
subplot(2,1,1), surf(ul'), axis equal, view(2), shading flat |
495 |
subplot(2,1,2), surf(vl'), axis equal, view(2), shading flat |
496 |
end |
497 |
|
498 |
elseif ( vars{ave(ii).ivar}{6} == 'v' ) |
499 |
|
500 |
if iz == 1 |
501 |
disp(sprintf( ' %s was computed along with %s', ... |
502 |
vars{ave(ii).ivar}{2}, vars{ave(ii-1).ivar}{2} )); |
503 |
end |
504 |
|
505 |
elseif ( vars{ave(ii).ivar}{6} == 'u' ) |
506 |
|
507 |
disp('Error: please specify regrid type for vectors'); |
508 |
disp(' using "flags.regrid_type_for_vec"'); |
509 |
|
510 |
end |
511 |
else |
512 |
% conservative for scalars |
513 |
for jj = 1:length(rgrid.con.src_address) |
514 |
lld(rgrid.con.dst_address(jj)) = ... |
515 |
lld(rgrid.con.dst_address(jj)) ... |
516 |
+ ( dcp(rgrid.con.src_address(jj)) ... |
517 |
* rgrid.con.remap_matrix(jj,1) ); |
518 |
end |
519 |
ave(ii).r(iz,:,:) = reshape(lld',og.nlat,og.nlon); |
520 |
end |
521 |
|
522 |
end |
523 |
|
524 |
end |
525 |
|
526 |
|
527 |
%====================================================================== |
528 |
% |
529 |
% Write netCDF output |
530 |
% |
531 |
disp('Writing netCDF output') |
532 |
|
533 |
nc = netcdf(oname{1}, 'clobber'); |
534 |
nc.title = [ 'Aqua Planet: ' ... |
535 |
'Single-Level 2-D Means from "Example" Experiment' ]; |
536 |
nc.institution = 'MIT Dept. of EAPS, Cambridge, MA, USA'; |
537 |
nc.source = [ 'MITgcm: ' ]; |
538 |
nc.Conventions = 'CF-1.0'; |
539 |
nc.history = [ 'Original data produced: ' '2002/08/20' ]; |
540 |
|
541 |
nc('pres') = length(Pref); |
542 |
nc('lon') = og.nlon; |
543 |
nc('lat') = og.nlat; |
544 |
nc('bnd') = 2; |
545 |
|
546 |
nc{'pres'} = ncdouble('pres'); |
547 |
nc{'pres'}.standard_name = 'air_pressure'; |
548 |
nc{'pres'}.units = 'Pa'; |
549 |
nc{'pres'}(:) = Pref*100; |
550 |
|
551 |
nc{'lon'} = ncdouble('lon'); |
552 |
nc{'lon'}.standard_name = 'longitude'; |
553 |
nc{'lon'}.units = 'degrees_east'; |
554 |
nc{'lon'}.bounds = 'lon_bnds'; |
555 |
nc{'lon'}(:) = og.lon; |
556 |
|
557 |
nc{'lat'} = ncdouble('lat'); |
558 |
nc{'lat'}.standard_name = 'latitude'; |
559 |
nc{'lat'}.units = 'degrees_north'; |
560 |
nc{'lat'}.bounds = 'lat_bnds'; |
561 |
nc{'lat'}(:) = og.lat; |
562 |
|
563 |
nc{'lon_bnds'} = ncdouble('lon','bnd'); |
564 |
nc{'lon_bnds'}.ape_name = 'longitude cell bounds'; |
565 |
nc{'lon_bnds'}.units = 'degrees_east'; |
566 |
nc{'lon_bnds'}(:) = og.lonbnd; |
567 |
|
568 |
nc{'lat_bnds'} = ncdouble('lat','bnd'); |
569 |
nc{'lat_bnds'}.ape_name = 'latitude cell bounds'; |
570 |
nc{'lat_bnds'}.units = 'degrees_north'; |
571 |
nc{'lat_bnds'}(:) = og.latbnd; |
572 |
|
573 |
for ii = 1:length(ave) |
574 |
|
575 |
iv = ave(ii).ivar; |
576 |
nc{ vars{iv}{2} } = ncfloat( 'pres', 'lat', 'lon' ); |
577 |
nc{ vars{iv}{2} }.ape_name = vars{iv}{4}; |
578 |
nc{ vars{iv}{2} }.units = vars{iv}{5}; |
579 |
nc{ vars{iv}{2} }.FillValue_ = 1.0e20; |
580 |
|
581 |
nc{ vars{iv}{2} }(:) = ave(ii).r; |
582 |
|
583 |
end |
584 |
|
585 |
nc = close(nc); |