/[MITgcm]/MITgcm_contrib/high_res_cube/eddy_flux/c20a/plot_c20a.m
ViewVC logotype

Annotation of /MITgcm_contrib/high_res_cube/eddy_flux/c20a/plot_c20a.m

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


Revision 1.5 - (hide annotations) (download)
Wed Mar 2 13:40:44 2005 UTC (20 years, 5 months ago) by edhill
Branch: MAIN
Changes since 1.4: +79 -332 lines
 o ass v'b'/(db/dz)

1 edhill 1.1 %=======================================================
2     %
3 edhill 1.5 % $Header: /u/gcmpack/MITgcm_contrib/high_res_cube/eddy_flux/c20a/plot_c20a.m,v 1.4 2005/03/01 18:00:12 edhill Exp $
4 edhill 1.1 %
5     % Ed Hill
6     %
7    
8     % The following are the MatLAB commands used to create the various
9     % plots related to eddy fluxes using average velocities and densities
10     % (called bouyancy or "b" in many of the variables) from Dimitris'
11     % "cube_20a" or "c20a" integration.
12    
13     % Groups of commands contained within the following "UNUSED" comments
14     % we not used in this analyssis. They are "left over" from the
15     % previous temperature-based calculations and have been kept for
16     % reference purposes only.
17    
18     %------- UNUSED -----------------------
19     % ...Commands...
20     %------- UNUSED -----------------------
21    
22    
23     % ssh eddy
24     % cd /r/r0/edhill/eddy_stats/eddy_flux_c20a
25    
26     % matlab -nojvm
27     % matlab -nojvm -nodisplay
28    
29     clear all
30     close all
31    
32    
33 edhill 1.2 %==================================================================
34     % Read the tile00?.mitgrid files
35 edhill 1.1 gvars = { 'XC','YC','DXF','DYF','RA','XG','YG','DXV', ...
36     'DYU','RAZ','DXC','DYC','RAW','RAS','DXG','DYG' };
37    
38 edhill 1.2 ne = 510;
39     nep1 = ne + 1;
40 edhill 1.1 iface = 1;
41     for iface = 1:6
42     fname = sprintf('grid/tile%03d.mitgrid', iface);
43     gid = fopen(fname, 'r', 'ieee-be');
44 edhill 1.2 tmp = reshape(fread(gid,inf,'real*8',0,'ieee-be'),[nep1,nep1,16]);
45 edhill 1.1 fclose(gid);
46     % surf(tmp(:,:,1)), view(2), shading interp
47     % for jj = 1:length(gvars)
48     for jj = 1:7
49     comm = sprintf('%s(:,:,%d) = tmp(:,:,%d);', ...
50     [gvars{jj}], iface, jj);
51     eval(comm);
52     end
53     end
54     % surf(XC(:,:,1)), view(2), shading interp
55     % subplot(2,1,1), a = [1:10]; surf(XC(a,a,1)), view(2)
56 edhill 1.2 % subplot(2,1,2), a = [(nep1-10):nep1]; surf(XC(a,a,1)), view(2)
57 edhill 1.1 % surf(YC(:,:,1)), view(2), shading interp
58     % surf(XG(:,:,1)), view(2), shading interp
59     % surf(YG(:,:,1)), view(2), shading interp
60 edhill 1.2 is = [1:ne];
61     vs = { 'XC','YC','DXF','DYF','RA' };
62     for i = 1:length(vs)
63     eval(sprintf('%s = %s(is,is,:);',vs{i},vs{i}));
64 edhill 1.1 end
65    
66 edhill 1.2 delR = [ ...
67     10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
68     10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
69     31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
70     93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
71     139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
72     341.50,364.50,387.50,410.50,433.50,456.50 ];
73     R = cumsum(delR) - 0.5*delR;
74    
75     %==================================================================
76     % Project fields to lower-res 1-degree Lat-Lon and write
77     % as NetCDF for viewing with Ingrid
78     %
79 edhill 1.1 % !echo `ls -1 ave__92_99 | sed -e 's|\.ave||g' \
80     % | sed -e "s|^|'|g" | sed -e "s|$|',|g"`
81 edhill 1.2 fields_3d = { ...
82     'DRHODR', 'RHOANOSQ', 'RHOAnoma', 'SALT', ...
83     'SALTSQ', ...
84     'THETA', 'THETASQ', 'URHOMASS', ...
85 edhill 1.1 'USLTMASS', 'UTHMASS', 'UVEL', 'UVELMASS', 'UVELSQ', ...
86     'UV_VEL_Z', 'VRHOMASS', 'VSLTMASS', 'VTHMASS', ...
87     'VVEL', 'VVELMASS', 'VVELSQ', 'WRHOMASS', 'WSLTMASS', ...
88     'WTHMASS', 'WU_VEL', 'WVELMASS', 'WVELSQ', 'WV_VEL' };
89 edhill 1.2 fields_2d = { ...
90     'ETANSQ', 'SFLUX', 'SRELAX', 'TAUX', 'TAUY', 'TFLUX', ...
91     'TICE', 'TRELAX' };
92     % fid = fopen('ave__92_99/DRHODR.ave','r','ieee-be');
93     % tmp = fread(gid,inf,'real*4',0,'ieee-be');
94     % fclose(fid);
95    
96     ne = 510;
97     nf = 6;
98     nz = 50;
99     nslab = ne*ne*nf;
100     adir = 'ave__92_99';
101     lat = [-90:90];
102     lon = [0:360];
103    
104     % ! rm -f cube_20a_*.nc
105    
106     ifld = 5;
107     fields = union(fields_2d, fields_3d);
108     for ifld = 1:length(fields)
109    
110 edhill 1.4 ir = [ 1 2 3 5 10 15 20 25 30 35 40 50 ];
111 edhill 1.2 if ismember(fields{ifld},fields_2d)
112     ir = [ 1 ];
113     end
114    
115     disp([ ' ' fields{ifld} ' :' ]);
116    
117     nc = netcdf(['cube_20a_' fields{ifld} '.nc'], 'clobber');
118     nc.reference = [ 'Results from Dimitris Menemenlis''' ...
119     '"cube 20a" integrations' ];
120     nc.author = 'Ed Hill <eh3@mit.edu>';
121     nc.date = 'Feb 24, 2005';
122     nc('X') = length(lon);
123     nc('Y') = length(lat);
124     nc('Z') = length(ir);
125     nc{'X'} = 'X';
126     nc{'Y'} = 'Y';
127     nc{'Z'} = 'Z';
128     nc{'X'}.uniquename = 'X';
129     nc{'X'}.long_name = 'longitude';
130     nc{'X'}.gridtype = ncint(1);
131     nc{'X'}.units = 'degree_east';
132     nc{'Y'}.uniquename = 'Y';
133     nc{'Y'}.long_name = 'latitude';
134     nc{'Y'}.gridtype = ncint(0);
135     nc{'Y'}.units = 'degree_north';
136     nc{'Z'}.uniquename = 'Z';
137     nc{'Z'}.long_name = 'depth';
138     nc{'Z'}.gridtype = ncint(0);
139     nc{'Z'}.units = 'm';
140     nc{'X'}(:) = lon;
141     nc{'Y'}(:) = lat;
142     nc{'Z'}(:) = R(ir);
143    
144     fname = sprintf('%s/%s.ave',adir,fields{ifld});
145     fid = fopen(fname,'r','ieee-be');
146    
147     id = fields{ifld};
148     nc{ id } = { 'Z' 'Y' 'X' };
149     nc{ id }.missing_value = ncdouble(NaN);
150     nc{ id }.FillValue_ = ncdouble(0.0);
151    
152     ii = 1;
153     for ii = 1:length(ir)
154    
155     iz = ir(ii);
156     disp(sprintf(' iz = %g',iz));
157    
158     fseek(fid,nslab*4*(iz-1),'bof');
159     tmp = fread(fid,nslab,'real*4',0,'ieee-be');
160     tr = permute(reshape(tmp,[ 510 6 510 ]),[1 3 2]);
161     % surf(tr(:,:,1)), view(2), shading interp
162     xc360 = XC + 180;
163     trn = tr;
164     trn(find(tr == 0.0)) = NaN;
165     clear tmp tr
166     % v = sdac_regrid(xc360,YC,trn,lonm,latm);
167     v = ll_regrid(xc360,YC,trn,lon,lat);
168     % surf(lon,lat,v'), caxis([25 40]), view(2), shading interp, colorbar
169    
170     nc{ id }(ii,:,:) = permute(v,[2 1]);
171    
172     end
173    
174     fclose(fid);
175     nc = close(nc);
176 edhill 1.4
177 edhill 1.2 end
178 edhill 1.1
179 edhill 1.3 % ! ncdump cube_20a.nc | more
180     % ! rm -rf output_netCDF ; mkdir output_netCDF
181     % ! scp output_netCDF/*.nc channel.mit.edu:/home/edhill/INGRID_PEOPLE/EH3/eddy_flux/cube_20a/
182    
183    
184    
185    
186     %=======================================================
187     % Compute [uvw]'[tsb]'
188 edhill 1.1
189 edhill 1.5 clear all
190     close all
191    
192     ne = 510;
193     nep1 = ne + 1;
194     iface = 1;
195     for iface = 1:6
196     fname = sprintf('grid/tile%03d.mitgrid', iface);
197     gid = fopen(fname, 'r', 'ieee-be');
198     tmp = reshape(fread(gid,inf,'real*8',0,'ieee-be'),[nep1,nep1,16]);
199     fclose(gid);
200     % surf(tmp(:,:,1)), view(2), shading interp
201     % for jj = 1:length(gvars)
202     for jj = 1:7
203     comm = sprintf('%s(:,:,%d) = tmp(:,:,%d);', ...
204     [gvars{jj}], iface, jj);
205     eval(comm);
206     end
207     end
208     % surf(XC(:,:,1)), view(2), shading interp
209     % subplot(2,1,1), a = [1:10]; surf(XC(a,a,1)), view(2)
210     % subplot(2,1,2), a = [(nep1-10):nep1]; surf(XC(a,a,1)), view(2)
211     % surf(YC(:,:,1)), view(2), shading interp
212     % surf(XG(:,:,1)), view(2), shading interp
213     % surf(YG(:,:,1)), view(2), shading interp
214     is = [1:ne];
215     vs = { 'XC','YC','DXF','DYF','RA' };
216     for i = 1:length(vs)
217     eval(sprintf('%s = %s(is,is,:);',vs{i},vs{i}));
218     end
219    
220     delR = [ ...
221     10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
222     10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
223     31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
224     93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
225     139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
226     341.50,364.50,387.50,410.50,433.50,456.50 ];
227     R = cumsum(delR) - 0.5*delR;
228    
229     n1 = ne - 1;
230     dux = zeros(size(XC));
231     duy = zeros(size(XC));
232     dvx = zeros(size(XC));
233     dvy = zeros(size(XC));
234     dux(:,:,:) = diff(XG(:,1:ne,:),1,1);
235     dvx(:,:,:) = diff(XG(1:ne,:,:),1,2);
236     duy(:,:,:) = diff(YG(:,1:ne,:),1,1);
237     dvy(:,:,:) = diff(YG(1:ne,:,:),1,2);
238     dux = dux + 360*double(dux < 180);
239     dux = dux - 360*double(dux > 180); % [ min(min(dux)) max(max(dux)) ]
240     duy = duy + 360*double(duy < 180);
241     duy = duy - 360*double(duy > 180); % [ min(min(duy)) max(max(duy)) ]
242     dvx = dvx + 360*double(dvx < 180);
243     dvx = dvx - 360*double(dvx > 180); % [ min(min(dvx)) max(max(dvx)) ]
244     dvy = dvy + 360*double(dvy < 180);
245     dvy = dvy - 360*double(dvy > 180); % [ min(min(dvy)) max(max(dvy)) ]
246     llux = dux ./ sqrt(dux.^2 + duy.^2);
247     lluy = duy ./ sqrt(dux.^2 + duy.^2);
248     llvx = dvx ./ sqrt(dvx.^2 + dvy.^2);
249     llvy = dvy ./ sqrt(dvx.^2 + dvy.^2);
250 edhill 1.1
251 edhill 1.3 lpath = 'ave__92_04/';
252     u__id = fopen( [lpath 'UVEL.ave'], 'r', 'ieee-be'); % 1
253     v__id = fopen( [lpath 'VVEL.ave'], 'r', 'ieee-be'); % 2
254     %w__id = fopen( [lpath 'WVEL.ave'], 'r', 'ieee-be');
255     u2_id = fopen( [lpath 'UVELSQ.ave'], 'r', 'ieee-be'); % 3
256     v2_id = fopen( [lpath 'VVELSQ.ave'], 'r', 'ieee-be'); % 4
257     w2_id = fopen( [lpath 'WVELSQ.ave'], 'r', 'ieee-be'); % 5
258     um_id = fopen( [lpath 'UVELMASS.ave'], 'r', 'ieee-be'); % 6
259     vm_id = fopen( [lpath 'VVELMASS.ave'], 'r', 'ieee-be'); % 7
260     wm_id = fopen( [lpath 'WVELMASS.ave'], 'r', 'ieee-be'); % 8
261     t__id = fopen( [lpath 'THETA.ave'], 'r', 'ieee-be'); % 9
262     t2_id = fopen( [lpath 'THETASQ.ave'], 'r', 'ieee-be'); % 10
263     s__id = fopen( [lpath 'SALT.ave'], 'r', 'ieee-be'); % 11
264     s2_id = fopen( [lpath 'SALTSQ.ave'], 'r', 'ieee-be'); % 12
265     b__id = fopen( [lpath 'RHOAnoma.ave'], 'r', 'ieee-be'); % 13
266     b2_id = fopen( [lpath 'RHOANOSQ.ave'], 'r', 'ieee-be'); % 14
267     ut_id = fopen( [lpath 'UTHMASS.ave'], 'r', 'ieee-be'); % 15
268     vt_id = fopen( [lpath 'VTHMASS.ave'], 'r', 'ieee-be'); % 16
269     wt_id = fopen( [lpath 'WTHMASS.ave'], 'r', 'ieee-be'); % 17
270     us_id = fopen( [lpath 'USLTMASS.ave'], 'r', 'ieee-be'); % 18
271     vs_id = fopen( [lpath 'VSLTMASS.ave'], 'r', 'ieee-be'); % 19
272     ws_id = fopen( [lpath 'WSLTMASS.ave'], 'r', 'ieee-be'); % 20
273     ub_id = fopen( [lpath 'URHOMASS.ave'], 'r', 'ieee-be'); % 21
274     vb_id = fopen( [lpath 'VRHOMASS.ave'], 'r', 'ieee-be'); % 22
275     wb_id = fopen( [lpath 'WRHOMASS.ave'], 'r', 'ieee-be'); % 23
276     dr_id = fopen( [lpath 'DRHODR.ave'], 'r', 'ieee-be'); % 24
277     %_id = fopen( [lpath '.ave'], 'r', 'ieee-be'); %
278    
279     iids = [ u__id v__id u2_id v2_id w2_id um_id vm_id wm_id ...
280     t__id t2_id s__id s2_id b__id b2_id ...
281     ut_id vt_id wt_id us_id vs_id ws_id ...
282     ub_id vb_id wb_id dr_id ];
283     % !mkdir primes_92_04
284     opath = 'primes_92_04/';
285     up2___id = fopen([opath 'up2'], 'wb', 'ieee-be');
286     vp2___id = fopen([opath 'vp2'], 'wb', 'ieee-be');
287     wp2___id = fopen([opath 'wp2'], 'wb', 'ieee-be');
288     tp2___id = fopen([opath 'tp2'], 'wb', 'ieee-be');
289     sp2___id = fopen([opath 'sp2'], 'wb', 'ieee-be');
290     bp2___id = fopen([opath 'bp2'], 'wb', 'ieee-be');
291     uptp__id = fopen([opath 'uptp'], 'wb', 'ieee-be');
292     vptp__id = fopen([opath 'vptp'], 'wb', 'ieee-be');
293     wptp__id = fopen([opath 'wptp'], 'wb', 'ieee-be');
294     upsp__id = fopen([opath 'upsp'], 'wb', 'ieee-be');
295     vpsp__id = fopen([opath 'vpsp'], 'wb', 'ieee-be');
296     wpsp__id = fopen([opath 'wpsp'], 'wb', 'ieee-be');
297     upbp__id = fopen([opath 'upbp'], 'wb', 'ieee-be');
298     vpbp__id = fopen([opath 'vpbp'], 'wb', 'ieee-be');
299     wpbp__id = fopen([opath 'wpbp'], 'wb', 'ieee-be');
300 edhill 1.5 vpbpdzid = fopen([opath 'vpbp_dbdz'], 'wb', 'ieee-be');
301    
302 edhill 1.3 comm = [ 'permute(reshape(fread( id ,nslab,''real*4'',0,' ...
303     '''ieee-be''),[ne 6 ne]),[1 3 2]);' ];
304     readslab = inline(comm,'id','nslab','ne');
305    
306     ne = 510;
307     nslab = 6 * ne * ne;
308     nztot = 50;
309     iz = 1;
310     for iz = 1:nztot
311 edhill 1.1
312 edhill 1.3 disp(sprintf(' iz = %d',iz));
313    
314     offset = (iz - 1)*nslab*4;
315     for iid = 1:length(iids)
316     fseek(iids(iid), offset, 'bof');
317     end
318    
319     u = readslab(u__id,nslab,ne); u2 = readslab(u2_id,nslab,ne);
320     v = readslab(v__id,nslab,ne); v2 = readslab(v2_id,nslab,ne);
321     um = readslab(um_id,nslab,ne);
322     vm = readslab(vm_id,nslab,ne);
323 edhill 1.4 wm = readslab(wm_id,nslab,ne);
324     % surf(v2(:,:,1)), view(2), shading interp
325     if (iz < nztot)
326     wmp1 = readslab(wm_id,nslab,ne);
327     else
328     wmp1 = zeros(size(wm));
329     end
330     wmp05 = (wm + wmp1)/2.0;
331     w2 = readslab(w2_id,nslab,ne);
332 edhill 1.3 t = readslab(t__id,nslab,ne); t2 = readslab(t2_id,nslab,ne);
333     s = readslab(s__id,nslab,ne); s2 = readslab(s2_id,nslab,ne);
334     b = readslab(b__id,nslab,ne); b2 = readslab(b2_id,nslab,ne);
335    
336     % "simple squared" quantities
337     up2 = u2 - u.^2;
338     vp2 = v2 - v.^2;
339     wp2 = w2 - wm.^2;
340     fwrite(up2___id, up2, 'real*4');
341     fwrite(vp2___id, vp2, 'real*4');
342     fwrite(wp2___id, wp2, 'real*4');
343     clear up2 vp2 wp2 u2 v2 w2
344     tp2 = t2 - t.^2;
345     sp2 = s2 - s.^2;
346     bp2 = b2 - b.^2;
347     fwrite(tp2___id, tp2, 'real*4');
348     fwrite(sp2___id, sp2, 'real*4');
349     fwrite(bp2___id, bp2, 'real*4');
350     clear tp2 sp2 bp2 t2 s2 b2
351    
352     ut = readslab(ut_id,nslab,ne); vt = readslab(vt_id,nslab,ne);
353     us = readslab(us_id,nslab,ne); vs = readslab(vs_id,nslab,ne);
354     ub = readslab(ub_id,nslab,ne); vb = readslab(vb_id,nslab,ne);
355 edhill 1.5 drhodr = readslab(dr_id,nslab,ne);
356 edhill 1.3
357     [ tonu, tonv ] = mass_on_u_v(t);
358     [ sonu, sonv ] = mass_on_u_v(s);
359     [ bonu, bonv ] = mass_on_u_v(b);
360     uptp = ut - u .* tonu; vptp = vt - v .* tonv;
361     upsp = us - u .* sonu; vpsp = vs - v .* sonv;
362     upbp = ub - u .* bonu; vpbp = vb - v .* bonv;
363 edhill 1.5
364     llupbp = upbp .* llux + vpbp .* llvx;
365     llvpbp = upbp .* lluy + vpbp .* llvy;
366     vpbpdbdz = llvpbp ./ drhodr;
367    
368 edhill 1.3 fwrite(uptp__id, uptp, 'real*4');
369     fwrite(vptp__id, vptp, 'real*4');
370     fwrite(upsp__id, upsp, 'real*4');
371     fwrite(vpsp__id, vpsp, 'real*4');
372     fwrite(upbp__id, upbp, 'real*4');
373     fwrite(vpbp__id, vpbp, 'real*4');
374 edhill 1.5 fwrite(vpbpdzid, vpbp, 'real*4');
375     clear uptp vptp upsp vpsp upbp vpbp vpbpdbdz
376 edhill 1.1
377 edhill 1.4 wt = readslab(wt_id,nslab,ne); wptp = wt - wmp05 .* t;
378     ws = readslab(ws_id,nslab,ne); wpsp = ws - wmp05 .* s;
379     wb = readslab(wb_id,nslab,ne); wpbp = wb - wmp05 .* b;
380     fwrite(wptp__id, wptp, 'real*4');
381     fwrite(wpsp__id, wpsp, 'real*4');
382     fwrite(wpbp__id, wpbp, 'real*4');
383 edhill 1.5
384 edhill 1.3 end
385    
386 edhill 1.4
387     clear all
388     close all
389 edhill 1.3
390 edhill 1.4 %==================================================================
391     % Read the tile00?.mitgrid files
392     gvars = { 'XC','YC','DXF','DYF','RA','XG','YG','DXV', ...
393     'DYU','RAZ','DXC','DYC','RAW','RAS','DXG','DYG' };
394    
395     ne = 510;
396     nep1 = ne + 1;
397     iface = 1;
398     for iface = 1:6
399     fname = sprintf('grid/tile%03d.mitgrid', iface);
400     gid = fopen(fname, 'r', 'ieee-be');
401     tmp = reshape(fread(gid,inf,'real*8',0,'ieee-be'),[nep1,nep1,16]);
402     fclose(gid);
403     % surf(tmp(:,:,1)), view(2), shading interp
404     % for jj = 1:length(gvars)
405     for jj = 1:7
406     comm = sprintf('%s(:,:,%d) = tmp(:,:,%d);', ...
407     [gvars{jj}], iface, jj);
408     eval(comm);
409     end
410     end
411     % surf(XC(:,:,1)), view(2), shading interp
412     % subplot(2,1,1), a = [1:10]; surf(XC(a,a,1)), view(2)
413     % subplot(2,1,2), a = [(nep1-10):nep1]; surf(XC(a,a,1)), view(2)
414     % surf(YC(:,:,1)), view(2), shading interp
415     % surf(XG(:,:,1)), view(2), shading interp
416     % surf(YG(:,:,1)), view(2), shading interp
417     is = [1:ne];
418     vs = { 'XC','YC','DXF','DYF','RA' };
419     for i = 1:length(vs)
420     eval(sprintf('%s = %s(is,is,:);',vs{i},vs{i}));
421     end
422    
423     delR = [ ...
424     10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
425     10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
426     31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
427     93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
428     139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
429     341.50,364.50,387.50,410.50,433.50,456.50 ];
430     R = cumsum(delR) - 0.5*delR;
431    
432     n1 = ne - 1;
433     dux = zeros(size(XC));
434     duy = zeros(size(XC));
435     dvx = zeros(size(XC));
436     dvy = zeros(size(XC));
437     dux(:,:,:) = diff(XG(:,1:ne,:),1,1);
438     dvx(:,:,:) = diff(XG(1:ne,:,:),1,2);
439     duy(:,:,:) = diff(YG(:,1:ne,:),1,1);
440     dvy(:,:,:) = diff(YG(1:ne,:,:),1,2);
441     dux = dux + 360*double(dux < 180);
442     dux = dux - 360*double(dux > 180); % [ min(min(dux)) max(max(dux)) ]
443     duy = duy + 360*double(duy < 180);
444     duy = duy - 360*double(duy > 180); % [ min(min(duy)) max(max(duy)) ]
445     dvx = dvx + 360*double(dvx < 180);
446     dvx = dvx - 360*double(dvx > 180); % [ min(min(dvx)) max(max(dvx)) ]
447     dvy = dvy + 360*double(dvy < 180);
448     dvy = dvy - 360*double(dvy > 180); % [ min(min(dvy)) max(max(dvy)) ]
449     llux = dux ./ sqrt(dux.^2 + duy.^2);
450     lluy = duy ./ sqrt(dux.^2 + duy.^2);
451     llvx = dvx ./ sqrt(dvx.^2 + dvy.^2);
452     llvy = dvy ./ sqrt(dvx.^2 + dvy.^2);
453    
454     %==================================================================
455     % Project fields to lower-res 1-degree Lat-Lon and write
456     % as NetCDF for viewing with Ingrid
457     %
458     ne = 510;
459     nf = 6;
460     nz = 50;
461     nslab = ne*ne*nf;
462     adir = 'primes_92_04';
463     lat = [-90:90];
464     lon = [0:360];
465     ir = [ 1 2 3 5 10 15 20 25 30 35 40 50 ];
466     xc360 = XC + 180;
467    
468     % ! rm -f cube_20a_primes.nc
469     nc = netcdf(['cube_20a_primes.nc'], 'clobber');
470     nc.reference = [ 'Results from Dimitris Menemenlis''' ...
471     '"cube 20a" integrations' ];
472     nc.author = 'Ed Hill <eh3@mit.edu>';
473     nc.date = 'Feb 28, 2005';
474     nc('X') = length(lon);
475     nc('Y') = length(lat);
476     nc('Z') = length(ir);
477     nc{'X'} = 'X';
478     nc{'Y'} = 'Y';
479     nc{'Z'} = 'Z';
480     nc{'X'}.uniquename = 'X';
481     nc{'X'}.long_name = 'longitude';
482     nc{'X'}.gridtype = ncint(1);
483     nc{'X'}.units = 'degree_east';
484     nc{'Y'}.uniquename = 'Y';
485     nc{'Y'}.long_name = 'latitude';
486     nc{'Y'}.gridtype = ncint(0);
487     nc{'Y'}.units = 'degree_north';
488     nc{'Z'}.uniquename = 'Z';
489     nc{'Z'}.long_name = 'depth';
490     nc{'Z'}.gridtype = ncint(0);
491     nc{'Z'}.units = 'm';
492     nc{'X'}(:) = lon;
493     nc{'Y'}(:) = lat;
494     nc{'Z'}(:) = R(ir);
495    
496     f_s_3d = { {'tp2'}, {'sp2'}, {'bp2'} };
497    
498     ifg = 1;
499     for ifg = 1:length(f_s_3d)
500    
501     acell = f_s_3d{ifg};
502     tname = acell{1};
503     disp([ ' ' tname ' :' ]);
504    
505     fname = sprintf('%s/%s',adir,tname);
506     fid = fopen(fname,'r','ieee-be');
507    
508     id = tname;
509     nc{ id } = { 'Z' 'Y' 'X' };
510     nc{ id }.missing_value = ncdouble(NaN);
511     nc{ id }.FillValue_ = ncdouble(0.0);
512    
513     ii = 1;
514     for ii = 1:length(ir)
515    
516     iz = ir(ii);
517     disp(sprintf(' iz = %3d R(iz) = %g',iz,R(iz)));
518    
519     fseek(fid,nslab*4*(iz-1),'bof');
520     tmp = fread(fid,nslab,'real*4',0,'ieee-be');
521     tr = reshape(tmp,[ 510 510 6 ]);
522     % surf(tr(:,:,1)), view(2), shading interp
523     trn = tr;
524     trn(find(tr == 0.0)) = NaN;
525     clear tmp tr
526     % v = sdac_regrid(xc360,YC,trn,lonm,latm);
527     v = ll_regrid(xc360,YC,trn,lon,lat);
528     % surf(lon,lat,v'), caxis([25 40]), view(2), shading interp, colorbar
529    
530     nc{ id }(ii,:,:) = permute(v,[2 1]);
531    
532     end
533    
534     fclose(fid);
535    
536     end
537    
538     id = 'sum_up2_vp2';
539     nc{ id } = { 'Z' 'Y' 'X' };
540     nc{ id }.missing_value = ncdouble(NaN);
541     nc{ id }.FillValue_ = ncdouble(0.0);
542     fidu = fopen(sprintf('%s/%s',adir,'up2'),'r','ieee-be');
543     fidv = fopen(sprintf('%s/%s',adir,'vp2'),'r','ieee-be');
544     for ii = 1:length(ir)
545     iz = ir(ii);
546     disp(sprintf(' iz = %3d R(iz) = %g',iz,R(iz)));
547     fseek(fidu,nslab*4*(iz-1),'bof');
548     fseek(fidv,nslab*4*(iz-1),'bof');
549     tru = reshape(fread(fidu,nslab,'real*4',0,'ieee-be'),[510 510 6]);
550     trv = reshape(fread(fidv,nslab,'real*4',0,'ieee-be'),[510 510 6]);
551     trnu = tru; trnu(find(tru == 0.0)) = NaN;
552     trnv = trv; trnv(find(trv == 0.0)) = NaN;
553     clear tmp tru trv
554     lluv = ll_regrid(xc360,YC,trnu+trnv,lon,lat);
555     nc{ id }(ii,:,:) = permute(lluv,[2 1]);
556     end
557     fclose(fidu);
558     fclose(fidv);
559    
560 edhill 1.5 f_v_3d = { {'up2','vp2'}, ...
561     {'uptp','vptp'}, {'upsp','vpsp'}, {'upbp','vpbp'} };
562 edhill 1.4 for ip = 1:length(f_v_3d)
563     cell = f_v_3d{ip};
564     idu = cell{1};
565     idv = cell{2};
566 edhill 1.5 disp([' ' idu ' ' idv]);
567 edhill 1.4 nc{ idu } = { 'Z' 'Y' 'X' };
568     nc{ idu }.missing_value = ncdouble(NaN);
569     nc{ idu }.FillValue_ = ncdouble(0.0);
570     nc{ idv } = { 'Z' 'Y' 'X' };
571     nc{ idv }.missing_value = ncdouble(NaN);
572     nc{ idv }.FillValue_ = ncdouble(0.0);
573     fidu = fopen(sprintf('%s/%s',adir,idu),'r','ieee-be');
574     fidv = fopen(sprintf('%s/%s',adir,idv),'r','ieee-be');
575     for ii = 1:length(ir)
576     iz = ir(ii);
577     disp(sprintf(' iz = %3d R(iz) = %g',iz,R(iz)));
578     fseek(fidu,nslab*4*(iz-1),'bof');
579     fseek(fidv,nslab*4*(iz-1),'bof');
580     tru = reshape(fread(fidu,nslab,'real*4',0,'ieee-be'),[510 510 6]);
581     trv = reshape(fread(fidv,nslab,'real*4',0,'ieee-be'),[510 510 6]);
582     trnu = tru; trnu(find(tru == 0.0)) = NaN;
583     trnv = trv; trnv(find(trv == 0.0)) = NaN;
584     clear tmp tru trv
585     llru = trnu .* llux + trnv .* llvx;
586     llrv = trnu .* lluy + trnv .* llvy;
587     llu = ll_regrid(xc360,YC,llru,lon,lat);
588     llv = ll_regrid(xc360,YC,llrv,lon,lat);
589     nc{ idu }(ii,:,:) = permute(llu,[2 1]);
590     nc{ idv }(ii,:,:) = permute(llv,[2 1]);
591     end
592     end
593     fclose(fidu);
594     fclose(fidv);
595 edhill 1.5
596    
597 edhill 1.4
598     nc = close(nc);
599    
600     % ! scp cube_20a_primes.nc channel.mit.edu:/home/edhill/INGRID_PEOPLE/EH3/eddy_flux/cube_20a/primes/
601     % ! mv cube_20a_primes.nc primes_92_04
602    
603 edhill 1.1
604    
605    
606    
607    
608 edhill 1.5 %------- UNUSED -----------------------
609 edhill 1.1
610    
611     %=======================================================
612     % Calculate : (v'B')/(dB/dz)
613    
614     bid = fopen( 'b-ave-1992-2003', 'r', 'ieee-be');
615     bm1id = fopen('bm1-ave-1992-2003', 'r', 'ieee-be');
616    
617     iz = 1;
618     offset = (iz - 1)*nps*4;
619     fseek(upbpid, offset, 'bof');
620     fseek(vpbpid, offset, 'bof');
621     upbp = reshape(fread(upbpid, nps, 'real*4'),ne,ne,6);
622     vpbp = reshape(fread(vpbpid, nps, 'real*4'),ne,ne,6);
623     llvpbp = upbp .* lluy + vpbp .* llvy;
624     llvpbpm1 = llvpbp;
625     ne = 510; tx = 85; ty = 85; nt = 216;
626    
627     iz = 2;
628     iz = 15;
629     iz = 16;
630     for iz = 2:50,
631     izm1 = iz - 1;
632     disp(sprintf('iz = %d',iz));
633     % iz = 21;
634     offset = (iz - 1)*nps*4;
635     fseek(upbpid, offset, 'bof');
636     fseek(vpbpid, offset, 'bof');
637     upbp = reshape(fread(upbpid, nps, 'real*4'),ne,ne,6);
638     vpbp = reshape(fread(vpbpid, nps, 'real*4'),ne,ne,6);
639    
640     % v'B' on ll coords
641     llvpbp = upbp .* lluy + vpbp .* llvy;
642    
643     % B and Bm1
644     fseek(bid, offset, 'bof');
645     b = reshape(fread(bid, nps, 'real*4'),ne,ne,6);
646     offm1 = (iz - 2)*nps*4;
647     fseek(bm1id, offm1, 'bof');
648     bm1 =reshape(fread(bm1id, nps, 'real*4'),ne,ne,6);
649    
650     % ( v'B' )/( dB/dz )
651     dbdz = (b - bm1)/(R(iz) - R(izm1));
652     ind0 = find(dbdz==0.0);
653     dbdz(ind0) = 1.0;
654     rdbdz = 1.0 / (dbdz);
655     rdbdz(ind0) = 0.0;
656     vpbpdbdz = 0.5*(llvpbp + llvpbpm1) .* rdbdz;
657    
658     % Write the results
659     mid = fopen('vpbpdbdz-1992-2003', 'a', 'ieee-be');
660     fwrite(mid, vpbpdbdz, 'real*4');
661     fclose(mid);
662    
663     % Plot results
664     clow = [ -10 ]; % -20;
665     chigh = [ 10 ]; % 20;
666     ll = zeros(6*510,510);
667     for i = 1:6
668     xb = (i-1)*510 + 1; xe = xb + 510 - 1;
669     yb = 1; ye = 510;
670     ll(xb:xe,yb:ye) = vpbpdbdz(:,:,i);
671     end
672     shift=-1;
673     grph_CS(sq(ll),xcs,ycs,xgs,ygs,[clow],[chigh],shift);
674     title([ '(v''B'')/(dB/dz) at ' ...
675     sprintf('%g',Rmid(iz)) ...
676     'm depth on the 510x510x6 cubesphere for 1992--2003 ["cube5"]']);
677     % print('-painters', '-dpng', '-r650', ...
678     % ['vpTpdTdz_' sprintf('%02d_%07.1f',iz,Rmid(iz)) 'm_650.png'])
679     print('-painters', '-dpng', '-r150', ...
680     ['vpBpdBdz_' sprintf('%02d_%07.1f',iz,Rmid(iz)) 'm_150.png'])
681    
682    
683     % Stress: calc, write, and plot
684     stress = 1000 * (2*pi/(24*3600)*sin(pi*yc/180));
685     stress = stress .* vpbpdbdz;
686     sid = fopen('stress-b-1992-2003', 'a', 'ieee-be');
687     fwrite(sid, stress, 'real*4');
688     fclose(sid);
689     clow = []; % [ -1 ];
690     chigh = []; % [ 1 ];
691     ll = zeros(6*510,510);
692     for i = 1:6
693     xb = (i-1)*510 + 1; xe = xb + 510 - 1;
694     yb = 1; ye = 510;
695     ll(xb:xe,yb:ye) = stress(:,:,i);
696     end
697     shift=-1;
698     grph_CS(sq(ll),xcs,ycs,xgs,ygs,[clow],[chigh],shift);
699     title([ 'Stress at ' ...
700     sprintf('%g',Rmid(iz)) ...
701     'm depth on the 510x510x6 cubesphere for 1994--2003 ["cube5"]']);
702     % print('-painters', '-dpng', '-r650', ...
703     % ['stress_' sprintf('%02d_%07.1f',iz,Rmid(iz)) 'm_650.png'])
704     print('-painters', '-dpng', '-r150', ...
705     ['stress_' sprintf('%02d_%07.1f',iz,Rmid(iz)) 'm_150.png'])
706    
707    
708     % Next level
709     llvpbpm1 = llvpbp;
710    
711     end
712    
713    
714     %=======================================================
715     % Zonally average vpbpdbdz and stress
716    
717     clear all ; close all
718     tx = 85;
719     ty = 85;
720     nt = 216;
721     cx = 510;
722     cy = 510;
723     nz = 1;
724     ne = 510;
725     nps = ne * ne * 6;
726    
727     % XCS YCS XGS YGS
728     fnam = [ 'XC' ; 'YC'; 'XG'; 'YG' ];
729     for in = 1:4
730     uid = fopen([fnam(in,:) '.data'], 'r', 'ieee-be');
731     phi = unmangleJPL1( reshape(fread(uid, nps, 'real*4'), ...
732     tx*nt,ty), ne, tx );
733     fclose(uid);
734     eval([lower(fnam(in,:)) ' = phi;']);
735     a = zeros(6*510,510);
736     for i = 1:6
737     xb = (i-1)*510 + 1; xe = xb + 510 - 1;
738     yb = 1; ye = 510;
739     a(xb:xe,yb:ye) = phi(:,:,i);
740     end
741     eval([lower(fnam(in,:)) 's = a;'])
742     end
743     xcs = xcs + -360.0*(xcs > 180.0);
744     xgs = xgs + -360.0*(xgs > 180.0);
745     clear phi a
746    
747     nz = 1;
748     nr = 50;
749     nrm1 = nr - 1;
750     nlat = 181; nlatm1 = nlat - 1;
751    
752     hvals = linspace(-90,90,nlat);
753     % save indicies for zonal averages
754     i = 2;
755     for i = 2:nlat
756     inds = find(hvals(i-1)<yg & yg<hvals(i));
757     comm = sprintf('inds%04d = uint32(inds);',i-1);
758     eval(comm);
759     end
760    
761     % Zonally average vpbp
762     acc = zeros(nlatm1, nrm1);
763     num = zeros(size(acc));
764     ne = 510;
765     nps = ne * ne * 6;
766     zid = fopen('vpbpll-1992-2003', 'r', 'ieee-be');
767     iz = 1;
768     for iz = 1:50,
769     disp(sprintf('iz = %d',iz));
770     offset = (iz - 1)*nps*4;
771     fseek(zid, offset, 'bof');
772     vpbp = reshape(fread(zid, nps, 'real*4'),ne,ne,6);
773    
774     for jj = 1:nlatm1
775     eval( sprintf('clear inds; inds = inds%04d;',jj) );
776     tmp = vpbp(inds);
777     nzinds = find(tmp ~= 0.0);
778     num(jj,iz) = length(nzinds);
779     acc(jj,iz) = sum(tmp(nzinds));
780     end
781     end
782     fclose(zid);
783     zvpbp = acc ./ num;
784     % save zvpbp zvpbp
785    
786     % zonally average vpbpdbdz
787     acc = zeros(nlatm1, nrm1);
788     num = zeros(size(acc));
789     ne = 510;
790     nps = ne * ne * 6;
791     zid = fopen('vpbpdbdz-1992-2003', 'r', 'ieee-be');
792     iz = 1;
793     for iz = 1:49,
794     disp(sprintf('iz = %d',iz));
795     offset = (iz - 1)*nps*4;
796     fseek(zid, offset, 'bof');
797     vpbpdbdz = reshape(fread(zid, nps, 'real*4'),ne,ne,6);
798    
799     for jj = 1:nlatm1
800     eval( sprintf('clear inds; inds = inds%04d;',jj) );
801     tmp = vpbpdbdz(inds);
802     nzinds = find(tmp ~= 0.0);
803     num(jj,iz) = length(nzinds);
804     acc(jj,iz) = sum(tmp(nzinds));
805     end
806     end
807     fclose(zid);
808     zvpbpdbdz = acc ./ num;
809     % save zvpbpdbdz zvpbpdbdz
810    
811     % zonally average stress
812     acc = zeros(nlatm1, nrm1);
813     num = zeros(size(acc));
814     ne = 510;
815     nps = ne * ne * 6;
816     zid = fopen('stress-b-1992-2003', 'r', 'ieee-be');
817     iz = 1;
818     for iz = 1:49,
819     disp(sprintf('iz = %d',iz));
820     offset = (iz - 1)*nps*4;
821     fseek(zid, offset, 'bof');
822     stress = reshape(fread(zid, nps, 'real*4'),ne,ne,6);
823     jj = 22;
824     for jj = 1:nlatm1
825     eval( sprintf('clear inds; inds = inds%04d;',jj) );
826     tmp = stress(inds);
827     nzinds = find(tmp ~= 0.0);
828     num(jj,iz) = length(nzinds);
829     acc(jj,iz) = sum(tmp(nzinds));
830     end
831     end
832     fclose(zid);
833     stress = acc ./ num;
834     % save stress stress
835    
836     %------- UNUSED -----------------------
837     % zonally average u
838     acc = zeros(nlatm1, 50);
839     num = zeros(size(acc));
840     ne = 510;
841     nps = ne * ne * 6;
842     zid = fopen('Ull_ave_1994--2003', 'r', 'ieee-be');
843     iz = 1;
844     for iz = 1:50,
845     disp(sprintf('iz = %d',iz));
846     offset = (iz - 1)*nps*4;
847     fseek(zid, offset, 'bof');
848     U = reshape(fread(zid, nps, 'real*4'),ne,ne,6);
849     jj = 22;
850     for jj = 1:nlatm1
851     eval( sprintf('clear inds; inds = inds%04d;',jj) );
852     tmp = U(inds);
853     nzinds = find(tmp ~= 0.0);
854     num(jj,iz) = length(nzinds);
855     acc(jj,iz) = sum(tmp(nzinds));
856     end
857     end
858     fclose(zid);
859     zonalu = acc ./ num;
860     % save zonalu zonalu
861     %------- UNUSED -----------------------
862    
863     % zonally average B
864     acc = zeros(nlatm1, 50);
865     num = zeros(size(acc));
866     ne = 510;
867     nps = ne * ne * 6;
868     zid = fopen('b-ave-1992-2003', 'r', 'ieee-be');
869     iz = 1;
870     for iz = 1:50,
871     disp(sprintf('iz = %d',iz));
872     offset = (iz - 1)*nps*4;
873     fseek(zid, offset, 'bof');
874     B = reshape(fread(zid, nps, 'real*4'),ne,ne,6);
875     jj = 22;
876     for jj = 1:nlatm1
877     eval( sprintf('clear inds; inds = inds%04d;',jj) );
878     tmp = B(inds);
879     nzinds = find(tmp ~= 0.0);
880     num(jj,iz) = length(nzinds);
881     acc(jj,iz) = sum(tmp(nzinds));
882     end
883     end
884     fclose(zid);
885     zonalB = acc ./ num;
886     % save zonalB zonalB
887    
888     %------- UNUSED -----------------------
889     % Vertical gradient of zonally averaged B (dB/dz)
890     load zonalT
891     load allR
892     nz = size(zonalT,1);
893     dzaTdz = zeros(nz,size(zonalT,2)-1);
894     for iz = 2:50
895     dzaTdz(:,iz-1) = (zonalT(:,iz) - zonalT(:,iz-1)) ./ (R(iz) - R(iz-1));
896     end
897     % save dzaTdz dzaTdz
898     %------- UNUSED -----------------------
899    
900    
901     delR = [
902     10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
903     10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
904     31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
905     93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
906     139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
907     341.50,364.50,387.50,410.50,433.50,456.50 ];
908     R = cumsum(delR) - 0.5*delR;
909     Rmid = R(1:(length(R)-1)) + 0.5*diff(R);
910     hmid = [ -89.5:1:89.5 ];
911     % save allR delR R Rmid hmid
912    
913     %------- UNUSED -----------------------
914     surf(hmid,-Rmid,num'), view(2), shading interp, colorbar
915     caxis([ -1 1 ])
916     caxis('manual')
917     surf(hmid,-Rmid,mu'), view(2), shading interp, colorbar
918     title('Zonally Averaged Stress for 1994--2003 [cube5]')
919     xlabel('Latitude [deg]')
920     zlabel('Depth [m]')
921     axis([ -90 90 -5500 200 ])
922    
923     % print -dps -painters t_001.ps
924     print('-painters', '-dpng', '-r150', 'za_str_94--03_r150.png')
925     print('-painters', '-dpng', '-r650', 'za_str_94--03_r650.png')
926    
927     % plot and print bar(U)
928     load zonalu
929     surf(hmid,-R,zonalu'), view(2), shading interp, colorbar
930     contour(hmid,-R,mu'), colorbar
931     ac = 25;
932     ac = [-0.3:.005:.3];
933     [c,h] = contourf(hmid,-R,mu',ac); colorbar
934     hold on, contour(hmid,-R,mu',ac), hold off
935     title('Zonally Averaged U for 1994--2003 [cube5]')
936     xlabel('Latitude [deg]')
937     zlabel('Depth [m]')
938     axis([ -90 90 -6000 200 ])
939     print('-painters', '-dpng', '-r150', 'Ull_94--03_r150.png')
940     print('-painters', '-dpng', '-r650', 'Ull_94--03_r650.png')
941     %------- UNUSED -----------------------
942    
943    

  ViewVC Help
Powered by ViewVC 1.1.22