/[MITgcm]/MITgcm_contrib/high_res_cube/eddy_flux/c22/plot_c22.m
ViewVC logotype

Annotation of /MITgcm_contrib/high_res_cube/eddy_flux/c22/plot_c22.m

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


Revision 1.3 - (hide annotations) (download)
Tue Mar 29 21:47:29 2005 UTC (20 years, 4 months ago) by edhill
Branch: MAIN
Changes since 1.2: +38 -5 lines
 o SSH streamwise averaging

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

  ViewVC Help
Powered by ViewVC 1.1.22