/[MITgcm]/MITgcm/verification/fizhi-cs-aqualev20/scripts/assemble_TR.m
ViewVC logotype

Annotation of /MITgcm/verification/fizhi-cs-aqualev20/scripts/assemble_TR.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Mon Apr 3 20:55:29 2006 UTC (18 years, 1 month ago) by molod
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint58l_post, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint58e_post, checkpoint58u_post, checkpoint58w_post, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63g, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint64, checkpoint65, checkpoint60, checkpoint61, checkpoint62, checkpoint63, checkpoint58r_post, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint58n_post, checkpoint58x_post, checkpoint58t_post, checkpoint58h_post, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint58q_post, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint58j_post, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint59j, checkpoint59, checkpoint58f_post, checkpoint58d_post, checkpoint58i_post, checkpoint58g_post, checkpoint58o_post, checkpoint62c, checkpoint62b, checkpoint62a, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint58y_post, checkpoint58k_post, checkpoint58v_post, checkpoint58s_post, checkpoint61f, checkpoint61g, checkpoint61d, checkpoint61e, checkpoint61b, checkpoint61c, checkpoint58p_post, checkpoint61a, checkpoint61n, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i, checkpoint61v, checkpoint61w, checkpoint61t, checkpoint61u, checkpoint61r, checkpoint61s, checkpoint61p, checkpoint61q, checkpoint61z, checkpoint61x, checkpoint61y, checkpoint58m_post, HEAD
New check-in for fizhi aquaplanet experiment to match the APE control (will replace fizhi-cs-aqualev10)

1 molod 1.1 %
2     % $Id: assemble_TR.m,v 1.5 2006/02/06 13:19:21 edhill Exp $
3     %
4     % Ed Hill
5     %
6     % Generate the APE TR fields:
7     %
8    
9     %======================================================================
10     %
11     % Define the connections between the APE "ML" variables and the
12     % MITgcm diagnostics output
13     %
14     nfacets = 6;
15     months.i_start = 7;
16     months.i_end = 42;
17     bname = 'data/TRall.t%03d.nc';
18     gname = 'data/grid.t%03d.nc';
19     r_con_name = 'scrip_regrid/rmp_CS32_to_LL128x64_conserv.nc';
20     r_dwt_name = 'scrip_regrid/rmp_CS32_to_LL128x64_distwgt.nc';
21     oname = { 'TR_fields.nc' };
22    
23     flags.regrid_type_for_vec = 2;
24     flags.debug_lev = 0;
25     flags.punits_conv = 0.01;
26    
27     % Get the following from:
28     % ! (cd ../../ape_data_specs/ ; ./tr_parse.sh)
29     vars = {};
30     vars{1} = {'TR01','tr_tppn','PREACC','precipitation_flux','kg m-2 s-1','-','0.000011574074','ee'};
31     vars{2} = {'TR02','tr_lw_toa','OLR','toa_outgoing_longwave_flux','W m-2','-','1','cc'};
32     vars{3} = {'TR03','tr_om500','WVEL','omega','Pa s-1','-','1','ec'};
33     vars{4} = {'TR04','tr_u250','UVEL','eastward_wind','m s-1','u','1','ee'};
34     vars{5} = {'TR05','tr_v250','VVEL','northward_wind','m s-1','v','1','ee'};
35     vars{6} = {'TR06','tr_mslp','RSURF','air_pressure_at_sea_level','Pa','-','1','cc'};
36    
37    
38     %======================================================================
39     %
40     % Open the input files and get the (minimum) number of time steps
41     % available across all the files
42     %
43     disp('Finding available time steps')
44    
45     ncl = {};
46     nTmin = 0;
47     ifacet = 1;
48     for ifacet = 1:nfacets
49     fname = sprintf(bname,ifacet);
50     nc = netcdf(fname, 'nowrite');
51     ncl{ifacet} = nc;
52     T = nc{'T'}(:);
53     nT = length(T);
54     if (ifacet == 1)
55     nTmin = nT;
56     else
57     nTmin = min(nTmin, nT);
58     end
59     nc = [];
60     end
61     disp(sprintf(' total iterations found = %d',nTmin));
62    
63    
64     %======================================================================
65     %
66     og = [];
67     og.nlat = 64;
68     og.nlon = 128;
69     og.latcell = 180/og.nlat;
70     og.loncell = 360/og.nlon;
71     og.lat = linspace(-90+og.latcell/2, 90-og.latcell/2, og.nlat);
72     og.lon = linspace(0+og.loncell/2, 360-og.loncell/2, og.nlon);
73     og.latbnd(:,1) = og.lat - og.latcell/2.0;
74     og.latbnd(:,2) = og.lat + og.latcell/2.0;
75     og.lonbnd(:,1) = og.lon - og.loncell/2.0;
76     og.lonbnd(:,2) = og.lon + og.loncell/2.0;
77    
78     rgvar = { 'src_address', 'dst_address', 'remap_matrix' };
79     rtype = { { 'con', r_con_name}, {'dwt', r_dwt_name } };
80     for kk = 1:length(rtype)
81     nc = netcdf(rtype{kk}{2}, 'nowrite');
82     for jj = 1:length(rgvar)
83     comm = sprintf('rgrid.%s.%s = nc{''%s''}(:);',...
84     rtype{kk}{1},rgvar{jj},rgvar{jj});
85     eval(comm);
86     % disp(comm);
87     end
88     nc = close(nc);
89     end
90    
91     aa_regrid.x = rdmds('aa_regrid/XC');
92     aa_regrid.y = rdmds('aa_regrid/YC');
93    
94     disp('Reading -- Regridding -- Writing')
95    
96     nc_outf = netcdf(oname{1}, 'clobber');
97     nc_outf.title = [ 'Aqua Planet: ' ...
98     'TR Fields' ];
99     nc_outf.institution = 'MIT Dept. of EAPS, Cambridge, MA, USA';
100     nc_outf.source = [ 'MITgcm: ' ];
101     nc_outf.Conventions = 'CF-1.0';
102     nc_outf.history = [ 'Original data produced: ' '' ];
103    
104     nc_outf('time') = 0; % record dim
105     nc_outf('lon') = og.nlon;
106     nc_outf('lat') = og.nlat;
107     nc_outf('bnd') = 2;
108    
109     nc_outf{'time'} = ncdouble('time');
110     nc_outf{'time'}.standard_name = 'time';
111     nc_outf{'time'}.units = 'days since 0000-01-01 00:00';
112     nc_outf{'time'}.bounds = 'time_bnds';
113     % nc_outf{'time'}(:) = og.lon;
114    
115     nc_outf{'lon'} = ncdouble('lon');
116     nc_outf{'lon'}.standard_name = 'longitude';
117     nc_outf{'lon'}.units = 'degrees_east';
118     nc_outf{'lon'}.bounds = 'lon_bnds';
119     nc_outf{'lon'}(:) = og.lon;
120    
121     nc_outf{'lat'} = ncdouble('lat');
122     nc_outf{'lat'}.standard_name = 'latitude';
123     nc_outf{'lat'}.units = 'degrees_north';
124     nc_outf{'lat'}.bounds = 'lat_bnds';
125     nc_outf{'lat'}(:) = og.lat;
126    
127     nc_outf{'time_bnds'} = ncdouble('time','bnd');
128     nc_outf{'time_bnds'}.ape_name = 'time interval endpoints';
129     % nc_outf{'time_bnds'}(:) = og.lonbnd;
130    
131     nc_outf{'lon_bnds'} = ncdouble('lon','bnd');
132     nc_outf{'lon_bnds'}.ape_name = 'longitude cell bounds';
133     nc_outf{'lon_bnds'}.units = 'degrees_east';
134     nc_outf{'lon_bnds'}(:) = og.lonbnd;
135    
136     nc_outf{'lat_bnds'} = ncdouble('lat','bnd');
137     nc_outf{'lat_bnds'}.ape_name = 'latitude cell bounds';
138     nc_outf{'lat_bnds'}.units = 'degrees_north';
139     nc_outf{'lat_bnds'}(:) = og.latbnd;
140    
141    
142     for iv = 1:length(vars)
143     nc_outf{ vars{iv}{2} } = ncfloat( 'time', 'lat', 'lon' );
144     nc_outf{ vars{iv}{2} }.ape_name = vars{iv}{4};
145     nc_outf{ vars{iv}{2} }.units = vars{iv}{5};
146     nc_outf{ vars{iv}{2} }.FillValue_ = 1.0e20;
147     end
148    
149     ne = 32;
150    
151     dat = [];
152     it = 1;
153     iv = 1;
154     ifacet = 1;
155     it0 = 2880;
156     for it = [ (it0+1):nTmin ]
157    
158     if mod(it-1,50) == 0
159     disp(sprintf([ ' iteration = %6d ' datestr(now) ],it));
160     end
161    
162     for iv = 1:length(vars)
163     for ifacet = 1:nfacets
164    
165     t0 = [];
166     vtmp = [];
167    
168     % WARN about missing variables
169     nc = ncl{ifacet};
170     if prod(size(nc{vars{iv}{3}})) == 0
171     if it == 1
172     str = 'var "%s" does not exist in file "%s"';
173     disp(sprintf([' Warning: ' str], vars{iv}{3}, name(nc)));
174     end
175     continue
176     end
177    
178     % get the data
179     t0 = nc{ vars{iv}{3} }(it,:,:);
180    
181     % horizontally interpolate to u,v to mass points
182     %
183     % this has changed so that now the "+1" points are garbage
184     % and must be ignored
185     dat(iv,ifacet).a = zeros([1 32 32]);
186     switch vars{iv}{6}
187     case 'u'
188     dat(iv,ifacet).a(1,:,:) = t0(:,1:ne);
189     case 'v'
190     dat(iv,ifacet).a(1,:,:) = t0(1:ne,:);
191     otherwise
192     dat(iv,ifacet).a(1,:,:) = t0;
193     end
194    
195     dat(iv,ifacet).n = 1;
196    
197     end
198     end
199    
200     % interpolate u,v to mass points
201     nc = ne;
202     ncp = nc + 1;
203     for iv = 1:length(vars)
204     switch vars{iv}{6}
205     case 'u'
206    
207     nr = size(dat(iv,1).a,1);
208     u3d = zeros(nc,nc,nr,6);
209     v3d = zeros(nc,nc,nr,6);
210     for fi = 1:6
211     u3d(:,:,:,fi) = permute( dat(iv, fi).a, [3 2 1] );
212     v3d(:,:,:,fi) = permute( dat(iv+1,fi).a, [3 2 1] );
213     end
214    
215     u6t=zeros(ncp,nc,nr,6);
216     v6t=zeros(nc,ncp,nr,6);
217     u6t([1:nc],:,:,:)=u3d(:,:,:,:);
218     v6t(:,[1:nc],:,:)=v3d(:,:,:,:);
219    
220     u6t(ncp,[1:nc],:,1)=u3d(1,[1:nc],:,2);
221     u6t(ncp,[1:nc],:,2)=v3d([nc:-1:1],1,:,4);
222     u6t(ncp,[1:nc],:,3)=u3d(1,[1:nc],:,4);
223     u6t(ncp,[1:nc],:,4)=v3d([nc:-1:1],1,:,6);
224     u6t(ncp,[1:nc],:,5)=u3d(1,[1:nc],:,6);
225     u6t(ncp,[1:nc],:,6)=v3d([nc:-1:1],1,:,2);
226    
227     v6t([1:nc],ncp,:,1)=u3d(1,[nc:-1:1],:,3);
228     v6t([1:nc],ncp,:,2)=v3d([1:nc],1,:,3);
229     v6t([1:nc],ncp,:,3)=u3d(1,[nc:-1:1],:,5);
230     v6t([1:nc],ncp,:,4)=v3d([1:nc],1,:,5);
231     v6t([1:nc],ncp,:,5)=u3d(1,[nc:-1:1],:,1);
232     v6t([1:nc],ncp,:,6)=v3d([1:nc],1,:,1);
233    
234     for fi = 1:6
235     dat(iv, fi).a = permute( ...
236     0.5*( u6t([1:nc],:,:,fi) + u6t([2:ncp],:,:,fi) ), [3 2 1] );
237     dat(iv+1,fi).a = permute( ...
238     0.5*( v6t(:,[1:nc],:,fi) + v6t(:,[2:ncp],:,fi) ), [3 2 1] );
239     end
240    
241     end
242     end
243    
244     % Units conversion
245     ave = [];
246     for iv = 1:length(vars)
247     ind = length(ave) + 1;
248     for ifacet = 1:nfacets
249     ave(ind).v(1,:,:,ifacet) = dat(iv,ifacet).a;
250     ave(ind).ivar = iv;
251     end
252     end
253     for ia = 1:length(ave)
254     if strcmp(vars{ ave(ia).ivar }{7}, '-') ~= 1
255     eval(['fac = ' vars{ ave(ia).ivar }{7} ';']);
256     if fac ~= 1
257     ave(ia).v = fac .* ave(ia).v;
258     end
259     end
260     end
261    
262     % regrid
263     ii = 1;
264     for ii = 1:length(ave)
265    
266     for iz = 1:size( ave(ii).v, 1 )
267    
268     siz = size( ave(ii).v );
269     dcp = zeros(prod(siz(2:4)),1);
270     nn = 0;
271     for fk = 1:size( ave(ii).v, 4 )
272     for jk = 1:size( ave(ii).v, 3 )
273     for ik = 1:size( ave(ii).v, 2 )
274     nn = nn + 1;
275     dcp(nn) = ave(ii).v(iz,ik,jk,fk);
276     end
277     end
278     end
279     lld = zeros(og.nlat*og.nlon,1);
280    
281     if ( ( flags.regrid_type_for_vec > 0 ) ...
282     && ( vars{ave(ii).ivar}{6} == 'u' ...
283     || vars{ave(ii).ivar}{6} == 'v' ) )
284    
285     if flags.regrid_type_for_vec == 1
286    
287     % use distributed weights for vectors
288     for jj = 1:length(rgrid.dwt.src_address)
289     lld(rgrid.dwt.dst_address(jj)) = ...
290     lld(rgrid.dwt.dst_address(jj)) ...
291     + ( dcp(rgrid.dwt.src_address(jj)) ...
292     * rgrid.dwt.remap_matrix(jj,1) );
293     end
294     ave(ii).r(iz,:,:) = reshape(lld',og.nlat,og.nlon);
295    
296     elseif ( flags.regrid_type_for_vec == 2 ...
297     && vars{ave(ii).ivar}{6} == 'u' )
298    
299     % use Alistair's uvcube2latlon() for vectors
300     nsiz = size(ave(ii).v);
301     by6u = zeros([ nsiz(2)*nsiz(4) nsiz(3) ]);
302     by6v = zeros([ nsiz(2)*nsiz(4) nsiz(3) ]);
303     for kk = 1:size( ave(ii).v, 4 )
304     is = 1 + (kk-1)*nsiz(2);
305     ie = is + nsiz(2) - 1;
306     by6u(is:ie,:) = squeeze( ave(ii ).v(iz,:,:,kk) )';
307     by6v(is:ie,:) = squeeze( ave(ii+1).v(iz,:,:,kk) )';
308     end
309     % xi=-179:2:180; yi=-89:2:90;
310     xi = og.lon;
311     ind = find(xi > 179.5);
312     xi(ind) = xi(ind) - 360;
313     yi = og.lat;
314     [ul,vl] = uvacube2latlon(aa_regrid.x,aa_regrid.y, ...
315     by6u,by6v, xi,yi);
316     ave(ii ).r(iz,:,:) = ul';
317     ave(ii+1).r(iz,:,:) = vl';
318    
319     if flags.debug_lev > 0
320     figure(1), subplot(1,1,1)
321     subplot(2,1,1), surf(ul'), axis equal, view(2), shading flat
322     subplot(2,1,2), surf(vl'), axis equal, view(2), shading flat
323     end
324    
325     elseif ( vars{ave(ii).ivar}{6} == 'v' )
326    
327     % if iz == 1
328     % disp(sprintf( ' %s was computed along with %s', ...
329     % vars{ave(ii).ivar}{2}, vars{ave(ii-1).ivar}{2} ));
330     % end
331    
332     elseif ( vars{ave(ii).ivar}{6} == 'u' )
333    
334     disp('Error: please specify regrid type for vectors');
335     disp(' using "flags.regrid_type_for_vec"');
336    
337     end
338     else
339     % conservative for scalars
340     for jj = 1:length(rgrid.con.src_address)
341     lld(rgrid.con.dst_address(jj)) = ...
342     lld(rgrid.con.dst_address(jj)) ...
343     + ( dcp(rgrid.con.src_address(jj)) ...
344     * rgrid.con.remap_matrix(jj,1) );
345     end
346     ave(ii).r(iz,:,:) = reshape(lld',og.nlat,og.nlon);
347     end
348    
349     end
350    
351     end
352    
353    
354     % write the regridded fields to netCDF
355     tcurr = 0.25 * it;
356     nc_outf{'time'}(it-it0) = tcurr;
357     nc_outf{'time_bnds'}(it-it0,:) = [ tcurr tcurr+0.25 ];
358     for ii = 1:length(ave)
359    
360     iv = ave(ii).ivar;
361     nc_outf{ vars{iv}{2} }(it-it0,:,:) = ave(ii).r(1,:,:);
362    
363     end
364    
365    
366     end
367     clear tmp
368    
369     % close the input files
370     for ifacet = 1:nfacets
371     nc = close( ncl{ifacet} );
372     end
373     clear ncl;
374    
375     % close output file
376     nc_outf = close(nc_outf);
377    
378    

  ViewVC Help
Powered by ViewVC 1.1.22