/[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.12 - (hide annotations) (download)
Wed Apr 27 17:43:54 2005 UTC (20 years, 3 months ago) by edhill
Branch: MAIN
Changes since 1.11: +169 -8 lines
 o set the stream-wise average cut-off as "south of 30S"

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

  ViewVC Help
Powered by ViewVC 1.1.22