/[MITgcm]/MITgcm_contrib/gmaze_pv/A_compute_potential_density.m
ViewVC logotype

Annotation of /MITgcm_contrib/gmaze_pv/A_compute_potential_density.m

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


Revision 1.8 - (hide annotations) (download)
Wed Sep 19 15:37:38 2007 UTC (17 years, 10 months ago) by gmaze
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +0 -0 lines
General Update

1 gmaze 1.6 gmaze_pv/B_compute_relative_vorticity.m0000644002352600001440000003066210560413602020023 0ustar gmazeusers%
2     % [OMEGA] = B_compute_relative_vorticity(SNAPSHOT)
3 gmaze 1.1 %
4 gmaze 1.6 % For a time snapshot, this program computes the
5     % 3D relative vorticity field from 3D
6     % horizontal speed fields U,V (x,y,z) as:
7     % OMEGA = ( -dVdz ; dUdz ; dVdx - dUdy )
8     % = ( Ox ; Oy ; ZETA )
9     % 3 outputs files are created.
10     %
11     % (U,V) must have same dimensions and by default are defined on
12     % a C-grid.
13     % If (U,V) are defined on an A-grid (coming from a cube-sphere
14     % to lat/lon grid interpolation for example), ie at the same points
15     % as THETA, SALTanom, ... the global variable 'griddef' must
16     % be set to 'A-grid'. Then (U,V) are moved to a C-grid for the computation.
17 gmaze 1.1 %
18 gmaze 1.6 % ZETA is computed at the upper-right corner of the C-grid.
19     % OMEGAX and OMEGAY are computed at V and U locations but shifted downward
20     % by 1/2 grid. In case of a A-grid for (U,V), OMEGAX and OMEGAY are moved
21     % to a C-grid according to the ZETA computation.
22 gmaze 1.4 %
23 gmaze 1.6 %
24 gmaze 1.3 % Files names are:
25     % INPUT:
26 gmaze 1.6 % ./netcdf-files/<SNAPSHOT>/<netcdf_UVEL>.<netcdf_domain>.<netcdf_suff>
27     % ./netcdf-files/<SNAPSHOT>/<netcdf_VVEL>.<netcdf_domain>.<netcdf_suff>
28 gmaze 1.3 % OUPUT:
29 gmaze 1.6 % ./netcdf-files/<SNAPSHOT>/OMEGAX.<netcdf_domain>.<netcdf_suff>
30     % ./netcdf-files/<SNAPSHOT>/OMEGAY.<netcdf_domain>.<netcdf_suff>
31     % ./netcdf-files/<SNAPSHOT>/ZETA.<netcdf_domain>.<netcdf_suff>
32 gmaze 1.3 %
33 gmaze 1.6 % 2006/06/07
34 gmaze 1.1 % gmaze@mit.edu
35     %
36 gmaze 1.6 % Last update:
37     % 2007/02/01 (gmaze) : Fix bug in ZETA grid and add compatibility with A-grid
38     %
39    
40     % On the C-grid, U and V are supposed to have the same dimensions and are
41     % defined like this:
42     %
43     % y
44     % ^ -------------------------
45     % | | | | | |
46     % | ny U * U * U * U * |
47     % | | | | | |
48     % | ny -- V --- V --- V --- V --
49     % | | | | | |
50     % | U * U * U * U * |
51     % | | | | | |
52     % | -- V --- V --- V --- V --
53     % | | | | | |
54     % | U * U * U * U * |
55     % | | | | | |
56     % | -- V --- V --- V --- V --
57     % | | | | | |
58     % | 1 U * U * U * U * |
59     % | | | | | |
60     % | 1 -- V --- V --- V --- V --
61     % |
62     % | 1 nx
63     % | 1 nx
64     %--|-------------------------------------> x
65     % |
66     %
67     % On the A-grid, U and V are defined on *, so we simply shift U westward by 1/2 grid
68     % and V southward by 1/2 grid. New (U,V) have the same dimensions as original fields
69     % but with first col for U, and first row for V set to NaN. Values are computed by
70     % averaging two contiguous values.
71     %
72 gmaze 1.1
73 gmaze 1.6 function varargout = B_compute_relative_vorticity(snapshot)
74 gmaze 1.1
75    
76 gmaze 1.6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
77     % Setup
78     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
79     global sla netcdf_UVEL netcdf_VVEL netcdf_domain netcdf_suff griddef
80 gmaze 1.1 pv_checkpath
81    
82    
83 gmaze 1.6 %% U,V files name:
84     filU = strcat(netcdf_UVEL,'.',netcdf_domain);
85     filV = strcat(netcdf_VVEL,'.',netcdf_domain);
86    
87 gmaze 1.1
88     %% Path and extension to find them:
89 gmaze 1.6 pathname = strcat('netcdf-files',sla,snapshot,sla);
90 gmaze 1.1 ext = strcat('.',netcdf_suff);
91    
92    
93 gmaze 1.6 %% Load files and axis:
94     ferfile = strcat(pathname,sla,filU,ext);
95     ncU = netcdf(ferfile,'nowrite');
96     [Ulon Ulat Udpt] = coordfromnc(ncU);
97 gmaze 1.1
98 gmaze 1.6 ferfile = strcat(pathname,sla,filV,ext);
99     ncV = netcdf(ferfile,'nowrite');
100     [Vlon Vlat Vdpt] = coordfromnc(ncV);
101 gmaze 1.4
102 gmaze 1.6 clear ext ferfile
103 gmaze 1.1
104 gmaze 1.6 %% Load grid definition:
105     global griddef
106     if length(griddef) == 0
107     griddef = 'C-grid'; % By default
108     end
109     switch lower(griddef)
110     case {'c-grid','cgrid','c'}
111     % Nothing to do here
112     case {'a-grid','agrid','a'}
113     disp('Found (U,V) defined on A-grid')
114     % Move Ulon westward by 1/2 grid point:
115     Ulon = [Ulon(1)-abs(diff(Ulon(1:2))/2) ; (Ulon(1:end-1)+Ulon(2:end))/2];
116     % Move V southward by 1/2 grid point:
117     Vlat = [Vlat(1)-abs(diff(Vlat(1:2))/2); (Vlat(1:end-1)+Vlat(2:end))/2];
118     % Now, (U,V) axis are defined as if they came from a C-grid
119     % (U,V) fields are moved to a C-grid during computation...
120     otherwise
121     error('The grid must be: C-grid or A-grid');
122     return
123     end %switch griddef
124    
125    
126     %% Optionnal flags
127     computeZETA = 1; % Compute ZETA or not ?
128 gmaze 1.1 global toshow % Turn to 1 to follow the computing process
129    
130    
131 gmaze 1.6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
132     % VERTICAL COMPONENT: ZETA %
133     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
134    
135     % U field is on the zonal side of the c-grid and
136     % V field on the meridional one.
137     % So computing meridional gradient for U and
138     % zonal gradient for V makes the relative vorticity
139     % zeta defined on the corner of the c-grid.
140 gmaze 1.1
141 gmaze 1.6 %%%%%%%%%%%%%%
142     %% Dimensions of ZETA field:
143     if toshow,disp('Dim'),end
144     ny = length(Ulat)-1;
145     nx = length(Vlon)-1;
146     nz = length(Udpt); % Note that Udpt=Vdpt
147    
148     %%%%%%%%%%%%%%
149     %% Pre-allocation:
150     if toshow,disp('Pre-allocate'),end
151     ZETA = zeros(nz,ny-1,nx-1).*NaN;
152     dx = zeros(ny-1,nx-1);
153     dy = zeros(ny-1,nx-1);
154 gmaze 1.1
155 gmaze 1.6 ZETA_lon = Ulon(2:nx+1);
156     ZETA_lat = Vlat(2:ny+1);
157 gmaze 1.1
158 gmaze 1.6 %%%%%%%%%%%%%%
159     %% Compute relative vorticity for each z-level:
160     if computeZETA
161 gmaze 1.1 for iz = 1 : nz
162 gmaze 1.6 if toshow
163     disp(strcat('Computing \zeta at depth : ',num2str(Udpt(iz)),...
164     'm (',num2str(iz),'/',num2str(nz),')' ));
165     end
166    
167     % Get velocities:
168     U = ncU{4}(iz,:,:);
169     V = ncV{4}(iz,:,:);
170     switch lower(griddef)
171     case {'a-grid','agrid','a'}
172     % Move U westward by 1/2 grid point:
173     % (1st col is set to nan, but axis defined)
174     U = [ones(ny+1,1).*NaN (U(:,1:end-1) + U(:,2:end))/2];
175     % Move V southward by 1/2 grid point:
176     % (1st row is set to nan but axis defined)
177     V = [ones(1,nx+1).*NaN; (V(1:end-1,:) + V(2:end,:))/2];
178     % Now, U and V are defined as if they came from a C-grid
179     end
180 gmaze 1.1
181 gmaze 1.6 % And now compute the vertical component of relative vorticity:
182     % (TO DO: m_lldist accepts tables as input, so this part may be
183     % done without x,y loop ...)
184     for iy = 1 : ny
185     for ix = 1 : nx
186     if iz==1 % It's more efficient to make this test each time than
187     % recomputing distance each time. m_lldist is a slow routine.
188     % ZETA axis and grid distance:
189     dx(iy,ix) = m_lldist([Vlon(ix+1) Vlon(ix)],[1 1]*Vlat(iy));
190     dy(iy,ix) = m_lldist([1 1]*Vlon(ix),[Ulat(iy+1) Ulat(iy)]);
191     end %if
192     % Horizontal gradients and ZETA:
193     dVdx = ( V(iy,ix+1)-V(iy,ix) ) / dx(iy,ix) ;
194     dUdy = ( U(iy+1,ix)-U(iy,ix) ) / dy(iy,ix) ;
195     ZETA(iz,iy,ix) = dVdx - dUdy;
196     end %for ix
197     end %for iy
198 gmaze 1.1 end %for iz
199    
200 gmaze 1.6 %%%%%%%%%%%%%%
201     %% Netcdf record:
202    
203     % General informations:
204     netfil = strcat('ZETA','.',netcdf_domain,'.',netcdf_suff);
205     units = '1/s';
206     ncid = 'ZETA';
207     longname = 'Vertical Component of the Relative Vorticity';
208     uniquename = 'vertical_relative_vorticity';
209    
210     % Open output file:
211     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
212    
213     % Define axis:
214     nc('X') = nx;
215     nc('Y') = ny;
216     nc('Z') = nz;
217    
218     nc{'X'} = 'X';
219     nc{'Y'} = 'Y';
220     nc{'Z'} = 'Z';
221    
222     nc{'X'} = ncfloat('X');
223     nc{'X'}.uniquename = ncchar('X');
224     nc{'X'}.long_name = ncchar('longitude');
225     nc{'X'}.gridtype = nclong(0);
226     nc{'X'}.units = ncchar('degrees_east');
227     nc{'X'}(:) = ZETA_lon;
228    
229     nc{'Y'} = ncfloat('Y');
230     nc{'Y'}.uniquename = ncchar('Y');
231     nc{'Y'}.long_name = ncchar('latitude');
232     nc{'Y'}.gridtype = nclong(0);
233     nc{'Y'}.units = ncchar('degrees_north');
234     nc{'Y'}(:) = ZETA_lat;
235    
236     nc{'Z'} = ncfloat('Z');
237     nc{'Z'}.uniquename = ncchar('Z');
238     nc{'Z'}.long_name = ncchar('depth');
239     nc{'Z'}.gridtype = nclong(0);
240     nc{'Z'}.units = ncchar('m');
241     nc{'Z'}(:) = Udpt;
242    
243     % And main field:
244     nc{ncid} = ncfloat('Z', 'Y', 'X');
245     nc{ncid}.units = ncchar(units);
246     nc{ncid}.missing_value = ncfloat(NaN);
247     nc{ncid}.FillValue_ = ncfloat(NaN);
248     nc{ncid}.longname = ncchar(longname);
249     nc{ncid}.uniquename = ncchar(uniquename);
250     nc{ncid}(:,:,:) = ZETA;
251    
252     nc=close(nc);
253    
254     clear x y z U V dx dy nx ny nz DVdx dUdy
255    
256     end %if compute ZETA
257    
258    
259     %%%%%%%%%%%%%%%%%%%%%%%%%
260     % HORIZONTAL COMPONENTS %
261     %%%%%%%%%%%%%%%%%%%%%%%%%
262     if toshow, disp('')
263     disp('Now compute horizontal components of relative vorticity ...'); end
264    
265     % U and V are defined on the same Z grid.
266    
267     %%%%%%%%%%%%%%
268     %% Dimensions of OMEGA x and y fields:
269     if toshow,disp('Dim'),end
270     O_nx = [length(Vlon) length(Ulon)];
271     O_ny = [length(Vlat) length(Ulat)];
272     O_nz = length(Udpt) - 1; % Idem Vdpt
273    
274     %%%%%%%%%%%%%%
275     %% Pre-allocations:
276     if toshow,disp('Pre-allocate'),end
277     Ox = zeros(O_nz,O_ny(1),O_nx(1)).*NaN;
278     Oy = zeros(O_nz,O_ny(2),O_nx(2)).*NaN;
279    
280     %%%%%%%%%%%%%%
281     %% Computation:
282    
283     %% Vertical grid differences:
284     dZ = diff(Udpt);
285     Odpt = Udpt(1:O_nz) + dZ/2;
286    
287     %% Zonal component of OMEGA:
288     if toshow,disp('Zonal direction ...'); end
289     [a dZ_3D c] = meshgrid(Vlat,dZ,Vlon); clear a c
290     V = ncV{4}(:,:,:);
291     switch lower(griddef)
292     case {'a-grid','agrid','a'}
293     % Move V southward by 1/2 grid point:
294     % (1st row is set to nan but axis defined)
295     V = cat(2,ones(O_nz+1,1,O_nx(1)).*NaN,(V(:,1:end-1,:) + V(:,2:end,:))/2);
296     % Now, V is defined as if it came from a C-grid
297     end
298     Ox = - ( V(2:O_nz+1,:,:) - V(1:O_nz,:,:) ) ./ dZ_3D;
299     clear V dZ_3D % For memory use
300    
301     %% Meridional component of OMEGA:
302     if toshow,disp('Meridional direction ...'); end
303     [a dZ_3D c] = meshgrid(Ulat,dZ,Ulon); clear a c
304     U = ncU{4}(:,:,:);
305     switch lower(griddef)
306     case {'a-grid','agrid','a'}
307     % Move U westward by 1/2 grid point:
308     % (1st col is set to nan, but axis defined)
309     U = cat(3,ones(O_nz+1,O_ny(2),1).*NaN,(U(:,:,1:end-1) + U(:,:,2:end))/2);
310     % Now, V is defined as if it came from a C-grid
311     end
312     Oy = ( U(2:O_nz+1,:,:) - U(1:O_nz,:,:) ) ./ dZ_3D;
313     clear U dZ_3D % For memory use
314    
315     clear dZ
316    
317    
318     %%%%%%%%%%%%%%
319     %% Record Zonal component:
320     if toshow,disp('Records ...'); end
321    
322     % General informations:
323     netfil = strcat('OMEGAX','.',netcdf_domain,'.',netcdf_suff);
324     units = '1/s';
325     ncid = 'OMEGAX';
326     longname = 'Zonal Component of the Relative Vorticity';
327     uniquename = 'zonal_relative_vorticity';
328    
329     % Open output file:
330     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
331    
332     % Define axis:
333     nc('X') = O_nx(1);
334     nc('Y') = O_ny(1);
335     nc('Z') = O_nz;
336    
337     nc{'X'} = 'X';
338     nc{'Y'} = 'Y';
339     nc{'Z'} = 'Z';
340    
341     nc{'X'} = ncfloat('X');
342     nc{'X'}.uniquename = ncchar('X');
343     nc{'X'}.long_name = ncchar('longitude');
344     nc{'X'}.gridtype = nclong(0);
345     nc{'X'}.units = ncchar('degrees_east');
346     nc{'X'}(:) = Vlon;
347 gmaze 1.1
348 gmaze 1.6 nc{'Y'} = ncfloat('Y');
349     nc{'Y'}.uniquename = ncchar('Y');
350     nc{'Y'}.long_name = ncchar('latitude');
351     nc{'Y'}.gridtype = nclong(0);
352     nc{'Y'}.units = ncchar('degrees_north');
353     nc{'Y'}(:) = Vlat;
354    
355     nc{'Z'} = ncfloat('Z');
356     nc{'Z'}.uniquename = ncchar('Z');
357     nc{'Z'}.long_name = ncchar('depth');
358     nc{'Z'}.gridtype = nclong(0);
359     nc{'Z'}.units = ncchar('m');
360     nc{'Z'}(:) = Odpt;
361 gmaze 1.1
362 gmaze 1.6 % And main field:
363     nc{ncid} = ncfloat('Z', 'Y', 'X');
364     nc{ncid}.units = ncchar(units);
365     nc{ncid}.missing_value = ncfloat(NaN);
366     nc{ncid}.FillValue_ = ncfloat(NaN);
367     nc{ncid}.longname = ncchar(longname);
368     nc{ncid}.uniquename = ncchar(uniquename);
369     nc{ncid}(:,:,:) = Ox;
370 gmaze 1.1
371 gmaze 1.6 nc=close(nc);
372 gmaze 1.1
373 gmaze 1.6 %%%%%%%%%%%%%%
374     %% Record Meridional component:
375 gmaze 1.1 % General informations:
376 gmaze 1.6 netfil = strcat('OMEGAY','.',netcdf_domain,'.',netcdf_suff);
377     units = '1/s';
378     ncid = 'OMEGAY';
379     longname = 'Meridional Component of the Relative Vorticity';
380     uniquename = 'meridional_relative_vorticity';
381 gmaze 1.1
382     % Open output file:
383     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
384    
385     % Define axis:
386 gmaze 1.6 nc('X') = O_nx(2);
387     nc('Y') = O_ny(2);
388     nc('Z') = O_nz;
389 gmaze 1.1
390     nc{'X'} = 'X';
391     nc{'Y'} = 'Y';
392     nc{'Z'} = 'Z';
393    
394     nc{'X'} = ncfloat('X');
395     nc{'X'}.uniquename = ncchar('X');
396     nc{'X'}.long_name = ncchar('longitude');
397     nc{'X'}.gridtype = nclong(0);
398     nc{'X'}.units = ncchar('degrees_east');
399 gmaze 1.6 nc{'X'}(:) = Ulon;
400 gmaze 1.1
401     nc{'Y'} = ncfloat('Y');
402     nc{'Y'}.uniquename = ncchar('Y');
403     nc{'Y'}.long_name = ncchar('latitude');
404     nc{'Y'}.gridtype = nclong(0);
405     nc{'Y'}.units = ncchar('degrees_north');
406 gmaze 1.6 nc{'Y'}(:) = Ulat;
407 gmaze 1.1
408     nc{'Z'} = ncfloat('Z');
409     nc{'Z'}.uniquename = ncchar('Z');
410     nc{'Z'}.long_name = ncchar('depth');
411     nc{'Z'}.gridtype = nclong(0);
412     nc{'Z'}.units = ncchar('m');
413 gmaze 1.6 nc{'Z'}(:) = Odpt;
414 gmaze 1.1
415     % And main field:
416     nc{ncid} = ncfloat('Z', 'Y', 'X');
417     nc{ncid}.units = ncchar(units);
418     nc{ncid}.missing_value = ncfloat(NaN);
419     nc{ncid}.FillValue_ = ncfloat(NaN);
420     nc{ncid}.longname = ncchar(longname);
421     nc{ncid}.uniquename = ncchar(uniquename);
422 gmaze 1.6 nc{ncid}(:,:,:) = Oy;
423 gmaze 1.1
424     nc=close(nc);
425 gmaze 1.6 close(ncU);
426     close(ncV);
427 gmaze 1.1
428 gmaze 1.5 % Outputs:
429 gmaze 1.6 OMEGA = struct(...
430     'Ox',struct('value',Ox,'dpt',Odpt,'lat',Vlat,'lon',Vlon),...
431     'Oy',struct('value',Oy,'dpt',Odpt,'lat',Ulat,'lon',Vlon),...
432     'Oz',struct('value',ZETA,'dpt',Udpt,'lat',ZETA_lat,'lon',ZETA_lon)...
433     );
434     switch nargout
435     case 1
436     varargout(1) = {OMEGA};
437     end
438     gmaze_pv/C_compute_potential_vorticity.m0000644002352600001440000003010210562377040020204 0ustar gmazeusers%
439     % [Q] = C_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV])
440     % [Q1,Q2,Q3] = C_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV])
441     %
442     % This file computes the potential vorticity Q from
443     % netcdf files of relative vorticity (OMEGAX, OMEGAY, ZETA)
444     % and potential density (SIGMATHETA) as
445     % Q = OMEGAX . dSIGMATHETA/dx + OMEGAY . dSIGMATHETA/dy + (f+ZETA).dSIGMATHETA/dz
446     %
447     % The optional flag WANTSPLPV is set to 0 by defaut. If turn to 1,
448     % then the program computes the simple PV defined by:
449     % splQ = f.dSIGMATHETA/dz
450     %
451     % Note that none of the fields are defined on the same grid points.
452     % So, I decided to compute Q on the same grid as SIGMATHETA, ie. the
453     % center of the c-grid.
454     %
455     % Files names are:
456     % INPUT:
457     % ./netcdf-files/<SNAPSHOT>/OMEGAX.<netcdf_domain>.<netcdf_suff>
458     % ./netcdf-files/<SNAPSHOT>/OMEGAY.<netcdf_domain>.<netcdf_suff>
459     % ./netcdf-files/<SNAPSHOT>/ZETA.<netcdf_domain>.<netcdf_suff>
460     % ./netcdf-files/<SNAPSHOT>/SIGMATHETA.<netcdf_domain>.<netcdf_suff>
461     % OUPUT:
462     % ./netcdf-files/<SNAPSHOT>/PV.<netcdf_domain>.<netcdf_suff>
463     % or
464     % ./netcdf-files/<SNAPSHOT>/splPV.<netcdf_domain>.<netcdf_suff>
465     %
466     % 06/07/2006
467     % gmaze@mit.edu
468     %
469    
470     function varargout = C_compute_potential_vorticity(snapshot,varargin)
471    
472    
473     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474     %% Setup
475     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476     global sla netcdf_domain netcdf_suff
477     pv_checkpath
478    
479     %% Flags to choose which term to compute (by default, all):
480     FLpv1 = 1;
481     FLpv2 = 1;
482     FLpv3 = 1;
483     if nargin==2 % case of optional flag presents:
484     if varargin{1}(1) == 1 % Case of the simple PV:
485     FLpv1 = 0;
486     FLpv2 = 0;
487     FLpv3 = 2;
488     end
489     end %if
490     %[FLpv1 FLpv2 FLpv3]
491    
492    
493     %% Optionnal flags:
494     global toshow % Turn to 1 to follow the computing process
495    
496    
497     %% NETCDF files:
498    
499     % Path and extension to find them:
500     pathname = strcat('netcdf-files',sla,snapshot,sla);
501     %pathname = '.';
502     ext = strcat('.',netcdf_suff);
503    
504     % Names:
505     if FLpv3 ~= 2 % We don't need them for splPV
506     filOx = strcat('OMEGAX' ,'.',netcdf_domain);
507     filOy = strcat('OMEGAY' ,'.',netcdf_domain);
508     filOz = strcat('ZETA' ,'.',netcdf_domain);
509     end %if
510     filST = strcat('SIGMATHETA','.',netcdf_domain);
511    
512     % Load files and coordinates:
513     if FLpv3 ~= 2 % We don't need them for splPV
514     ferfile = strcat(pathname,sla,filOx,ext);
515     ncOx = netcdf(ferfile,'nowrite');
516     [Oxlon Oxlat Oxdpt] = coordfromnc(ncOx);
517     ferfile = strcat(pathname,sla,filOy,ext);
518     ncOy = netcdf(ferfile,'nowrite');
519     [Oylon Oylat Oydpt] = coordfromnc(ncOy);
520     ferfile = strcat(pathname,sla,filOz,ext);
521     ncOz = netcdf(ferfile,'nowrite');
522     [Ozlon Ozlat Ozdpt] = coordfromnc(ncOz);
523     end %if
524     ferfile = strcat(pathname,sla,filST,ext);
525     ncST = netcdf(ferfile,'nowrite');
526     [STlon STlat STdpt] = coordfromnc(ncST);
527    
528    
529     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530     % Then, compute the first term: OMEGAX . dSIGMATHETA/dx %
531     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532     if FLpv1
533    
534     %%%%%
535     %% 1: Compute zonal gradient of SIGMATHETA:
536    
537     % Dim:
538     if toshow,disp('dim'),end
539     nx = length(STlon) - 1;
540     ny = length(STlat);
541     nz = length(STdpt);
542    
543     % Pre-allocate:
544     if toshow,disp('pre-allocate'),end
545     dSIGMATHETAdx = zeros(nz,ny,nx-1)*NaN;
546     dx = zeros(1,nx).*NaN;
547     STup = zeros(nz,nx);
548     STdw = zeros(nz,nx);
549    
550     % Zonal gradient of SIGMATHETA:
551     if toshow,disp('grad'), end
552     for iy = 1 : ny
553     if toshow
554     disp(strcat('Computing dSIGMATHETA/dx at latitude : ',num2str(STlat(iy)),...
555     '^o (',num2str(iy),'/',num2str(ny),')' ));
556     end
557     [dx b] = meshgrid( m_lldist(STlon(1:nx+1),[1 1]*STlat(iy)), STdpt ) ; clear b
558     STup = squeeze(ncST{4}(:,iy,2:nx+1));
559     STdw = squeeze(ncST{4}(:,iy,1:nx));
560     dSTdx = ( STup - STdw ) ./ dx;
561     % Change horizontal grid point definition to fit with SIGMATHETA:
562     dSTdx = ( dSTdx(:,1:nx-1) + dSTdx(:,2:nx) )./2;
563     dSIGMATHETAdx(:,iy,:) = dSTdx;
564     end %for iy
565    
566    
567     %%%%%
568     %% 2: Move OMEGAX on the same grid:
569     if toshow,disp('Move OMEGAX on the same grid as dSIGMATHETA/dx'), end
570    
571     % Change vertical gridding of OMEGAX:
572     Ox = ncOx{4}(:,:,:);
573     Ox = ( Ox(2:nz-1,:,:) + Ox(1:nz-2,:,:) )./2;
574     % And horizontal gridding:
575     Ox = ( Ox(:,2:ny-1,:) + Ox(:,1:ny-2,:) )./2;
576    
577     %%%%%
578     %% 3: Make both fields having same limits:
579     %% (Keep points where both fields are defined)
580     Ox = squeeze(Ox(:,:,2:nx));
581     dSIGMATHETAdx = squeeze( dSIGMATHETAdx (2:nz-1,2:ny-1,:) );
582    
583     %%%%%
584     %% 4: Last, compute first term of PV:
585     PV1 = Ox.*dSIGMATHETAdx ;
586    
587     % and define axis fron the ST grid:
588     PV1_lon = STlon(2:length(STlon)-1);
589     PV1_lat = STlat(2:length(STlat)-1);
590     PV1_dpt = STdpt(2:length(STdpt)-1);
591    
592     clear nx ny nz dx STup STdw iy dSTdx Ox dSIGMATHETAdx
593     end %if FLpv1
594    
595    
596    
597    
598     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599     % Compute the second term: OMEGAY . dSIGMATHETA/dy %
600     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601     if FLpv2
602    
603     %%%%%
604     %% 1: Compute meridional gradient of SIGMATHETA:
605    
606     % Dim:
607     if toshow,disp('dim'), end
608     nx = length(STlon) ;
609     ny = length(STlat) - 1 ;
610     nz = length(STdpt) ;
611    
612     % Pre-allocate:
613     if toshow,disp('pre-allocate'), end
614     dSIGMATHETAdy = zeros(nz,ny-1,nx).*NaN;
615     dy = zeros(1,ny).*NaN;
616     STup = zeros(nz,ny);
617     STdw = zeros(nz,ny);
618    
619     % Meridional gradient of SIGMATHETA:
620     % (Assuming the grid is regular, dy is independent of x)
621     [dy b] = meshgrid( m_lldist([1 1]*STlon(1),STlat(1:ny+1) ), STdpt ) ; clear b
622     for ix = 1 : nx
623     if toshow
624     disp(strcat('Computing dSIGMATHETA/dy at longitude : ',num2str(STlon(ix)),...
625     '^o (',num2str(ix),'/',num2str(nx),')' ));
626     end
627     STup = squeeze(ncST{4}(:,2:ny+1,ix));
628     STdw = squeeze(ncST{4}(:,1:ny,ix));
629     dSTdy = ( STup - STdw ) ./ dy;
630     % Change horizontal grid point definition to fit with SIGMATHETA:
631     dSTdy = ( dSTdy(:,1:ny-1) + dSTdy(:,2:ny) )./2;
632     dSIGMATHETAdy(:,:,ix) = dSTdy;
633     end %for iy
634    
635     %%%%%
636     %% 2: Move OMEGAY on the same grid:
637     if toshow,disp('Move OMEGAY on the same grid as dSIGMATHETA/dy'), end
638    
639     % Change vertical gridding of OMEGAY:
640     Oy = ncOy{4}(:,:,:);
641     Oy = ( Oy(2:nz-1,:,:) + Oy(1:nz-2,:,:) )./2;
642     % And horizontal gridding:
643     Oy = ( Oy(:,:,2:nx-1) + Oy(:,:,1:nx-2) )./2;
644    
645     %%%%%
646     %% 3: Make them having same limits:
647     %% (Keep points where both fields are defined)
648     Oy = squeeze(Oy(:,2:ny,:));
649     dSIGMATHETAdy = squeeze( dSIGMATHETAdy (2:nz-1,:,2:nx-1) );
650    
651     %%%%%
652     %% 4: Last, compute second term of PV:
653     PV2 = Oy.*dSIGMATHETAdy ;
654    
655     % and defined axis fron the ST grid:
656     PV2_lon = STlon(2:length(STlon)-1);
657     PV2_lat = STlat(2:length(STlat)-1);
658     PV2_dpt = STdpt(2:length(STdpt)-1);
659    
660    
661     clear nx ny nz dy STup STdw dy dSTdy Oy dSIGMATHETAdy
662     end %if FLpv2
663    
664    
665    
666    
667    
668     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669     % Compute the third term: ( f + ZETA ) . dSIGMATHETA/dz %
670     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671     if FLpv3
672    
673     %%%%%
674     %% 1: Compute vertical gradient of SIGMATHETA:
675    
676     % Dim:
677     if toshow,disp('dim'), end
678     nx = length(STlon) ;
679     ny = length(STlat) ;
680     nz = length(STdpt) - 1 ;
681    
682     % Pre-allocate:
683     if toshow,disp('pre-allocate'), end
684     dSIGMATHETAdz = zeros(nz-1,ny,nx).*NaN;
685     ST = zeros(nz+1,ny,nx);
686     dz = zeros(1,nz).*NaN;
687    
688     % Vertical grid differences:
689     % STdpt contains negative values with STdpt(1) at the surface
690     % and STdpt(end) at the bottom of the ocean.
691     % So dz is positive with respect to z axis upward:
692     dz = -diff(STdpt);
693     [a dz_3D c] = meshgrid(STlat,dz,STlon); clear a c
694    
695     % Vertical gradient:
696     if toshow,disp('Vertical gradient of SIGMATHETA'), end
697     ST = ncST{4}(:,:,:);
698     % Z axis upward, so vertical derivative is upper-part
699     % minus lower-part:
700     dSIGMATHETAdz = ( ST(1:nz,:,:) - ST(2:nz+1,:,:) ) ./ dz_3D;
701     clear dz_3D ST
702    
703     % Change vertical gridding:
704     dSIGMATHETAdz = ( dSIGMATHETAdz(1:nz-1,:,:) + dSIGMATHETAdz(2:nz,:,:) )./2;
705    
706     if FLpv3 == 1 % Just for full PV
707    
708     %%%%%
709     %% 2: Move ZETA on the same grid:
710     if toshow,disp('Move ZETA on the same grid as dSIGMATHETA/dz'), end
711     Oz = ncOz{4}(:,:,:);
712     % Change horizontal gridding:
713     Oz = ( Oz(:,:,2:nx-1) + Oz(:,:,1:nx-2) )./2;
714     Oz = ( Oz(:,2:ny-1,:) + Oz(:,1:ny-2,:) )./2;
715    
716     end %if FLpv3=1
717    
718     %%%%%
719     %% 3: Make them having same limits:
720     %% (Keep points where both fields are defined)
721     if FLpv3 == 1
722     Oz = squeeze(Oz(2:nz,:,:));
723     end %if
724     dSIGMATHETAdz = squeeze( dSIGMATHETAdz (:,2:ny-1,2:nx-1) );
725    
726    
727     %%%%%
728     %% 4: Last, compute third term of PV:
729     % and defined axis fron the ST grid:
730     PV3_lon = STlon(2:length(STlon)-1);
731     PV3_lat = STlat(2:length(STlat)-1);
732     PV3_dpt = STdpt(2:length(STdpt)-1);
733    
734     % Planetary vorticity:
735     f = 2*(2*pi/86400)*sin(PV3_lat*pi/180);
736     [a f c]=meshgrid(PV3_lon,f,PV3_dpt); clear a c
737     f = permute(f,[3 1 2]);
738    
739     % Third term of PV:
740     if FLpv3 == 2
741     % Compute simple PV, just with planetary vorticity:
742     PV3 = f.*dSIGMATHETAdz ;
743     else
744     % To compute full PV:
745     PV3 = (f+Oz).*dSIGMATHETAdz ;
746     end
747    
748    
749    
750     clear nx ny nz dz ST Oz dSIGMATHETAdz f
751     end %if FLpv3
752    
753    
754    
755     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
756     % Then, compute potential vorticity:
757     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758     if toshow,disp('Summing terms to get PV:'),end
759     % If we had computed the first term:
760     if FLpv1
761     if toshow,disp('First term alone'),end
762     PV = PV1;
763     PV_lon=PV1_lon;PV_lat=PV1_lat;PV_dpt=PV1_dpt;
764     end
765     % If we had computed the second term:
766     if FLpv2
767     if exist('PV') % and the first one:
768     if toshow,disp('Second term added to first one'),end
769     PV = PV + PV2;
770     else % or not:
771     if toshow,disp('Second term alone'),end
772     PV = PV2;
773     PV_lon=PV2_lon;PV_lat=PV2_lat;PV_dpt=PV2_dpt;
774     end
775     end
776     % If we had computed the third term:
777     if FLpv3
778     if exist('PV') % and one of the first or second one:
779     if toshow,disp('Third term added to first and/or second one(s)'),end
780     PV = PV + PV3;
781     else % or not:
782     if toshow,disp('Third term alone'),end
783     PV = PV3;
784     PV_lon=PV3_lon;PV_lat=PV3_lat;PV_dpt=PV3_dpt;
785     end
786     end
787    
788    
789     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790     % Record:
791     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
792     if toshow,disp('Now reccording PV file ...'),end
793    
794     % General informations:
795     if FLpv3 == 1
796     netfil = strcat('PV','.',netcdf_domain,'.',netcdf_suff);
797     units = 'kg/s/m^4';
798     ncid = 'PV';
799     longname = 'Potential vorticity';
800     uniquename = 'potential_vorticity';
801     else
802     netfil = strcat('splPV','.',netcdf_domain,'.',netcdf_suff);
803     units = 'kg/s/m^4';
804     ncid = 'splPV';
805     longname = 'Simple Potential vorticity';
806     uniquename = 'simple_potential_vorticity';
807     end %if
808    
809     % Open output file:
810     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
811    
812     % Define axis:
813     nc('X') = length(PV_lon);
814     nc('Y') = length(PV_lat);
815     nc('Z') = length(PV_dpt);
816    
817     nc{'X'} = 'X';
818     nc{'Y'} = 'Y';
819     nc{'Z'} = 'Z';
820    
821     nc{'X'} = ncfloat('X');
822     nc{'X'}.uniquename = ncchar('X');
823     nc{'X'}.long_name = ncchar('longitude');
824     nc{'X'}.gridtype = nclong(0);
825     nc{'X'}.units = ncchar('degrees_east');
826     nc{'X'}(:) = PV_lon;
827    
828     nc{'Y'} = ncfloat('Y');
829     nc{'Y'}.uniquename = ncchar('Y');
830     nc{'Y'}.long_name = ncchar('latitude');
831     nc{'Y'}.gridtype = nclong(0);
832     nc{'Y'}.units = ncchar('degrees_north');
833     nc{'Y'}(:) = PV_lat;
834    
835     nc{'Z'} = ncfloat('Z');
836     nc{'Z'}.uniquename = ncchar('Z');
837     nc{'Z'}.long_name = ncchar('depth');
838     nc{'Z'}.gridtype = nclong(0);
839     nc{'Z'}.units = ncchar('m');
840     nc{'Z'}(:) = PV_dpt;
841    
842     % And main field:
843     nc{ncid} = ncfloat('Z', 'Y', 'X');
844     nc{ncid}.units = ncchar(units);
845     nc{ncid}.missing_value = ncfloat(NaN);
846     nc{ncid}.FillValue_ = ncfloat(NaN);
847     nc{ncid}.longname = ncchar(longname);
848     nc{ncid}.uniquename = ncchar(uniquename);
849     nc{ncid}(:,:,:) = PV;
850    
851     nc=close(nc);
852     if FLpv3 ~= 2
853     close(ncOx);
854     close(ncOy);
855     close(ncOz);
856     end
857     close(ncST);
858    
859     % Outputs:
860     OUT = struct('PV',PV,'dpt',PV_dpt,'lat',PV_lat,'lon',PV_lon);
861     switch nargout
862     case 1
863     varargout(1) = {OUT};
864     case 2
865     varargout(1) = {struct('PV1',PV1,'dpt',PV1_dpt,'lat',PV1_lat,'lon',PV1_lon)};
866     varargout(2) = {struct('PV2',PV2,'dpt',PV2_dpt,'lat',PV2_lat,'lon',PV2_lon)};
867     case 3
868     varargout(1) = {struct('PV1',PV1,'dpt',PV1_dpt,'lat',PV1_lat,'lon',PV1_lon)};
869     varargout(2) = {struct('PV2',PV2,'dpt',PV2_dpt,'lat',PV2_lat,'lon',PV2_lon)};
870     varargout(3) = {struct('PV3',PV3,'dpt',PV3_dpt,'lat',PV3_lat,'lon',PV3_lon)};
871     end
872     gmaze_pv/compute_alpha.m0000644002352600001440000000676110560414351014725 0ustar gmazeusers%
873     % [ALPHA] = compute_alpha(SNAPSHOT)
874     %
875     % This function computes the thermal expansion coefficient from
876     % files of potential temperature THETA and salinity anomaly
877     % SALTanom.
878     % SALTanom is by default a salinity anomaly vs 35PSU.
879     % If not, (is absolute value) set the global variable is_SALTanom to 0
880     %
881     % Files name are:
882     % INPUT:
883     % ./netcdf-files/<SNAPSHOT>/<netcdf_THETA>.<netcdf_domain>.<netcdf_suff>
884     % ./netcdf-files/<SNAPSHOT>/<netcdf_SALTanom>.<netcdf_domain>.<netcdf_suff>
885     % OUTPUT:
886     % ./netcdf-files/<SNAPSHOT>/ALPHA.<netcdf_domain>.<netcdf_suff>
887     %
888     % with: netcdf_* as global variables
889     %
890     % Alpha is computed with the subroutine sw_alpha from package SEAWATER
891     %
892     % 06/27/06
893     % gmaze@mit.edu
894    
895     function varargout = compute_alpha(snapshot)
896    
897     global sla toshow
898     global netcdf_suff netcdf_domain
899     global netcdf_SALTanom netcdf_THETA
900     pv_checkpath
901    
902    
903     % Path and extension to find netcdf-files:
904     pathname = strcat('netcdf-files',sla);
905     ext = netcdf_suff;
906    
907     % Load files:
908     ferfile = strcat(pathname,sla,snapshot,sla,netcdf_THETA,'.',netcdf_domain,'.',ext);
909     ncT = netcdf(ferfile,'nowrite');
910     [Tlon Tlat Tdpt] = coordfromnc(ncT);
911    
912     ferfile = strcat(pathname,sla,snapshot,sla,netcdf_SALTanom,'.',netcdf_domain,'.',ext);
913     ncS = netcdf(ferfile,'nowrite');
914     [Slon Slat Sdpt] = coordfromnc(ncS); % but normaly is the same grid as T
915    
916     % Salinity field ref;
917     global is_SALTanom
918     if exist('is_SALTanom')
919     if is_SALTanom == 1
920     bS = 35;
921     else
922     bS = 0;
923     end
924     end
925    
926    
927     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
928     % surface PV flux
929     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
930    
931     % Define axis:
932     nx = length(Tlon) ;
933     ny = length(Tlat) ;
934     nz = length(Tdpt) ;
935    
936    
937     % Pre-allocation:
938     if toshow,disp('Pre-allocate');end
939     ALPHA = zeros(nz,ny,nx).*NaN;
940    
941     % Compute alpha:
942     for iz = 1 : nz
943     if toshow,disp(strcat('Compute alpha for level:',num2str(iz),'/',num2str(nz)));end
944     TEMP = ncT{4}(iz,:,:);
945     SALT = ncS{4}(iz,:,:) + bS;
946     PRES = (0.09998*9.81*Tdpt(iz))*ones(ny,nx);
947     ALPHA(iz,:,:) = sw_alpha(SALT,TEMP,PRES,'ptmp');
948     end %for iz
949    
950    
951     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
952     % Record
953     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
954     if toshow, disp('record'), end
955    
956     % General informations:
957     netfil = 'ALPHA';
958     units = '1/K';
959     ncid = 'ALPHA';
960     longname = 'Thermal expansion coefficient';
961     uniquename = 'ALPHA';
962    
963     % Open output file:
964     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
965    
966     % Define axis:
967     nx = length(Tlon) ;
968     ny = length(Tlat) ;
969     nz = length(Tdpt) ;
970    
971     nc('X') = nx;
972     nc('Y') = ny;
973     nc('Z') = nz;
974    
975     nc{'X'} = ncfloat('X');
976     nc{'X'}.uniquename = ncchar('X');
977     nc{'X'}.long_name = ncchar('longitude');
978     nc{'X'}.gridtype = nclong(0);
979     nc{'X'}.units = ncchar('degrees_east');
980     nc{'X'}(:) = Tlon;
981    
982     nc{'Y'} = ncfloat('Y');
983     nc{'Y'}.uniquename = ncchar('Y');
984     nc{'Y'}.long_name = ncchar('latitude');
985     nc{'Y'}.gridtype = nclong(0);
986     nc{'Y'}.units = ncchar('degrees_north');
987     nc{'Y'}(:) = Tlat;
988    
989     nc{'Z'} = ncfloat('Z');
990     nc{'Z'}.uniquename = ncchar('Z');
991     nc{'Z'}.long_name = ncchar('depth');
992     nc{'Z'}.gridtype = nclong(0);
993     nc{'Z'}.units = ncchar('m');
994     nc{'Z'}(:) = Tdpt;
995    
996     % And main field:
997     nc{ncid} = ncfloat('Z', 'Y', 'X');
998     nc{ncid}.units = ncchar(units);
999     nc{ncid}.missing_value = ncfloat(NaN);
1000     nc{ncid}.FillValue_ = ncfloat(NaN);
1001     nc{ncid}.longname = ncchar(longname);
1002     nc{ncid}.uniquename = ncchar(uniquename);
1003     nc{ncid}(:,:,:) = ALPHA;
1004    
1005     nc=close(nc);
1006     close(ncS);
1007     close(ncT);
1008    
1009     % Output:
1010     output = struct('ALPHA',ALPHA,'dpt',Tdpt,'lat',Tlat,'lon',Tlon);
1011 gmaze 1.4 switch nargout
1012     case 1
1013 gmaze 1.5 varargout(1) = {output};
1014 gmaze 1.4 end
1015 gmaze 1.6 gmaze_pv/compute_density.m0000644002352600001440000000767410560445025015325 0ustar gmazeusers%
1016     % [RHO] = compute_density(SNAPSHOT)
1017     %
1018     % For a time snapshot, this program computes the
1019     % 3D density from potential temperature and salinity fields.
1020     % THETA and SALTanom are supposed to be defined on the same
1021     % domain and grid.
1022     % SALTanom is by default a salinity anomaly vs 35PSU.
1023     % If not, (is absolute value) set the global variable is_SALTanom to 0
1024     %
1025     %
1026     % Files names are:
1027     % INPUT:
1028     % ./netcdf-files/<SNAPSHOT>/<netcdf_THETA>.<netcdf_domain>.<netcdf_suff>
1029     % ./netcdf-files/<SNAPSHOT>/<netcdf_SALTanom>.<netcdf_domain>.<netcdf_suff>
1030     % OUPUT:
1031     % ./netcdf-files/<SNAPSHOT>/RHO.<netcdf_domain>.<netcdf_suff>
1032     %
1033     % 06/21/2006
1034     % gmaze@mit.edu
1035     %
1036    
1037    
1038     function varargout = compute_density(snapshot)
1039    
1040    
1041     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1042     %% Setup
1043     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044     global sla netcdf_THETA netcdf_SALTanom netcdf_domain netcdf_suff
1045     global is_SALTanom
1046     pv_checkpath
1047    
1048    
1049     %% THETA and SALTanom files name:
1050     filTHETA = strcat(netcdf_THETA ,'.',netcdf_domain);
1051     filSALTa = strcat(netcdf_SALTanom,'.',netcdf_domain);
1052    
1053     %% Path and extension to find them:
1054     pathname = strcat('netcdf-files',sla,snapshot);
1055     %pathname = '.';
1056     ext = strcat('.',netcdf_suff);
1057    
1058     %% Load netcdf files:
1059     ferfile = strcat(pathname,sla,filTHETA,ext);
1060     ncTHETA = netcdf(ferfile,'nowrite');
1061     THETAvariables = var(ncTHETA);
1062    
1063     ferfile = strcat(pathname,sla,filSALTa,ext);
1064     ncSALTa = netcdf(ferfile,'nowrite');
1065     SALTavariables = var(ncSALTa);
1066    
1067     %% Gridding:
1068     % Don't care about the grid here !
1069     % SALTanom and THETA are normaly defined on the same grid
1070     % So we compute rho on it.
1071    
1072     %% Flags:
1073     global toshow % Turn to 1 to follow the computing process
1074    
1075    
1076     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1077     %% Now we compute the density
1078     %% The routine used is densjmd95.m
1079     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1080    
1081     % Axis (usual netcdf files):
1082     if toshow,disp('Dim');end
1083     [lon lat dpt] = coordfromnc(ncTHETA);
1084     nx = length(lon);
1085     ny = length(lat);
1086     nz = length(dpt);
1087    
1088     % Pre-allocate:
1089     if toshow,disp('Pre-allocate');end
1090     RHO = zeros(nz,ny,nx);
1091    
1092     global is_SALTanom
1093     if exist('is_SALTanom')
1094     if is_SALTanom == 1
1095     bS = 35;
1096     else
1097     bS = 0;
1098     end
1099     end
1100    
1101     % Then compute density RHO:
1102     for iz = 1 : nz
1103     if toshow,disp(strcat('Compute density at level:',num2str(iz),'/',num2str(nz)));end
1104    
1105     S = SALTavariables{4}(iz,:,:) + bS; % Move the anom to an absolute field
1106     T = THETAvariables{4}(iz,:,:);
1107     P = (0.09998*9.81*dpt(iz))*ones(ny,nx);
1108     RHO(iz,:,:) = densjmd95(S,T,P);
1109    
1110     end %for iz
1111    
1112    
1113    
1114    
1115     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1116     %% Record output:
1117     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1118    
1119     % General informations:
1120     netfil = strcat('RHO','.',netcdf_domain,'.',netcdf_suff);
1121     units = 'kg/m^3';
1122     ncid = 'RHO';
1123     longname = 'Density';
1124     uniquename = 'density';
1125    
1126     % Open output file:
1127     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
1128    
1129     % Define axis:
1130     nc('X') = nx;
1131     nc('Y') = ny;
1132     nc('Z') = nz;
1133    
1134     nc{'X'} = 'X';
1135     nc{'Y'} = 'Y';
1136     nc{'Z'} = 'Z';
1137    
1138     nc{'X'} = ncfloat('X');
1139     nc{'X'}.uniquename = ncchar('X');
1140     nc{'X'}.long_name = ncchar('longitude');
1141     nc{'X'}.gridtype = nclong(0);
1142     nc{'X'}.units = ncchar('degrees_east');
1143     nc{'X'}(:) = lon;
1144    
1145     nc{'Y'} = ncfloat('Y');
1146     nc{'Y'}.uniquename = ncchar('Y');
1147     nc{'Y'}.long_name = ncchar('latitude');
1148     nc{'Y'}.gridtype = nclong(0);
1149     nc{'Y'}.units = ncchar('degrees_north');
1150     nc{'Y'}(:) = lat;
1151    
1152     nc{'Z'} = ncfloat('Z');
1153     nc{'Z'}.uniquename = ncchar('Z');
1154     nc{'Z'}.long_name = ncchar('depth');
1155     nc{'Z'}.gridtype = nclong(0);
1156     nc{'Z'}.units = ncchar('m');
1157     nc{'Z'}(:) = dpt;
1158    
1159     % And main field:
1160     nc{ncid} = ncfloat('Z', 'Y', 'X');
1161     nc{ncid}.units = ncchar(units);
1162     nc{ncid}.missing_value = ncfloat(NaN);
1163     nc{ncid}.FillValue_ = ncfloat(NaN);
1164     nc{ncid}.longname = ncchar(longname);
1165     nc{ncid}.uniquename = ncchar(uniquename);
1166     nc{ncid}(:,:,:) = RHO;
1167    
1168    
1169    
1170     % Close files:
1171     close(ncTHETA);
1172     close(ncSALTa);
1173     close(nc);
1174    
1175    
1176     % Output:
1177     output = struct('RHO',RHO,'dpt',dpt,'lat',lat,'lon',lon);
1178     switch nargout
1179     case 1
1180     varargout(1) = {output};
1181     end
1182     gmaze_pv/compute_EKL.m0000644002352600001440000000727310560414451014253 0ustar gmazeusers%
1183     % [EKL] = compute_EKL(SNAPSHOT)
1184     %
1185     % Here we compute the Ekmal Layer Depth as:
1186     % EKL = 0.7 sqrt( |TAU|/RHO )/f
1187     %
1188     % where:
1189     % TAU is the amplitude of the surface wind-stress (N/m2)
1190     % RHO is the density of seawater (kg/m3)
1191     % f is the Coriolis parameter (kg/m3)
1192     % EKL is the Ekman layer depth (m)
1193     %
1194     % Files names are:
1195     % INPUT:
1196     % ./netcdf-files/<SNAPSHOT>/<netcdf_RHO>.<netcdf_domain>.<netcdf_suff>
1197     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUX>.<netcdf_domain>.<netcdf_suff>
1198     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUY>.<netcdf_domain>.<netcdf_suff>
1199     % OUTPUT
1200     % ./netcdf-files/<SNAPSHOT>/<netcdf_EKL>.<netcdf_domain>.<netcdf_suff>
1201     %
1202     % with netcdf_* as global variables
1203     % netcdf_EKL = 'EKL' by default
1204     %
1205     % 08/16/06
1206     % gmaze@mit.edu
1207    
1208     function varargout = compute_EKL(snapshot)
1209    
1210     global sla toshow
1211     global netcdf_suff netcdf_domain
1212     global netcdf_TAUX netcdf_TAUY netcdf_RHO netcdf_EKL
1213     pv_checkpath
1214     global EKL Tx Ty TAU RHO f
1215    
1216    
1217     % NETCDF file name:
1218     filTx = netcdf_TAUX;
1219     filTy = netcdf_TAUY;
1220     filRHO = netcdf_RHO;
1221    
1222     % Path and extension to find them:
1223     pathname = strcat('netcdf-files',sla);
1224     ext = netcdf_suff;
1225    
1226     % Load files:
1227     ferfile = strcat(pathname,sla,snapshot,sla,filTx,'.',netcdf_domain,'.',ext);
1228     ncTx = netcdf(ferfile,'nowrite');
1229     Tx = ncTx{4}(1,:,:);
1230     ferfile = strcat(pathname,sla,snapshot,sla,filTy,'.',netcdf_domain,'.',ext);
1231     ncTy = netcdf(ferfile,'nowrite');
1232     Ty = ncTy{4}(1,:,:);
1233     [Tylon Tylat Tydpt] = coordfromnc(ncTy);
1234    
1235     ferfile = strcat(pathname,sla,snapshot,sla,filRHO,'.',netcdf_domain,'.',ext);
1236     ncRHO = netcdf(ferfile,'nowrite');
1237     RHO = ncRHO{4}(1,:,:);
1238     [RHOlon RHOlat RHOdpt] = coordfromnc(ncRHO);
1239    
1240    
1241     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242     % Get EKL
1243     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244    
1245     % Dim:
1246     if toshow, disp('dim'), end
1247     nx = length(RHOlon);
1248     ny = length(RHOlat);
1249     nz = length(RHOdpt);
1250    
1251     % Pre-allocate:
1252     if toshow, disp('pre-allocate'), end
1253     EKL = zeros(ny,nx);
1254    
1255     % Planetary vorticity:
1256     f = 2*(2*pi/86400)*sin(RHOlat*pi/180);
1257     [a f c]=meshgrid(RHOlon,f,RHOdpt); clear a c
1258     f = permute(f,[3 1 2]);
1259     f = squeeze(f(1,:,:));
1260    
1261     % Windstress amplitude:
1262     TAU = sqrt( Tx.^2 + Ty.^2 );
1263    
1264     % Ekman Layer Depth:
1265     EKL = 0.7* sqrt(TAU ./ RHO) ./f;
1266     %EKL = 1.7975 * sqrt( TAU ./ RHO ./ f );
1267    
1268     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1269     % Record
1270     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271     if toshow, disp('record'), end
1272    
1273     % General informations:
1274     if ~isempty('netcdf_EKL')
1275     netfil = netcdf_EKL;
1276     else
1277     netfil = 'EKL';
1278     end
1279     units = 'm';
1280     ncid = 'EKL';
1281     longname = 'Ekman Layer Depth';
1282     uniquename = 'EKL';
1283    
1284     % Open output file:
1285     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
1286    
1287     % Define axis:
1288     nx = length(RHOlon) ;
1289     ny = length(RHOlat) ;
1290     nz = 1 ;
1291    
1292     nc('X') = nx;
1293     nc('Y') = ny;
1294     nc('Z') = nz;
1295    
1296     nc{'X'} = ncfloat('X');
1297     nc{'X'}.uniquename = ncchar('X');
1298     nc{'X'}.long_name = ncchar('longitude');
1299     nc{'X'}.gridtype = nclong(0);
1300     nc{'X'}.units = ncchar('degrees_east');
1301     nc{'X'}(:) = RHOlon;
1302    
1303     nc{'Y'} = ncfloat('Y');
1304     nc{'Y'}.uniquename = ncchar('Y');
1305     nc{'Y'}.long_name = ncchar('latitude');
1306     nc{'Y'}.gridtype = nclong(0);
1307     nc{'Y'}.units = ncchar('degrees_north');
1308     nc{'Y'}(:) = RHOlat;
1309    
1310     nc{'Z'} = ncfloat('Z');
1311     nc{'Z'}.uniquename = ncchar('Z');
1312     nc{'Z'}.long_name = ncchar('depth');
1313     nc{'Z'}.gridtype = nclong(0);
1314     nc{'Z'}.units = ncchar('m');
1315     nc{'Z'}(:) = RHOdpt(1);
1316    
1317     % And main field:
1318     nc{ncid} = ncfloat('Z', 'Y', 'X');
1319     nc{ncid}.units = ncchar(units);
1320     nc{ncid}.missing_value = ncfloat(NaN);
1321     nc{ncid}.FillValue_ = ncfloat(NaN);
1322     nc{ncid}.longname = ncchar(longname);
1323     nc{ncid}.uniquename = ncchar(uniquename);
1324     nc{ncid}(:,:,:) = EKL;
1325    
1326     nc=close(nc);
1327    
1328    
1329    
1330     % Output:
1331     output = struct('EKL',EKL,'lat',RHOlat,'lon',RHOlon);
1332     switch nargout
1333     case 1
1334     varargout(1) = {output};
1335     end
1336     gmaze_pv/compute_EKLx.m0000644002352600001440000000673110560414506014442 0ustar gmazeusers%
1337     % [EKL] = compute_EKLx(SNAPSHOT)
1338     %
1339     % Here we compute the Ekman Layer Depth as:
1340     % EKL = 0.7 sqrt( TAUx/RHO )/f
1341     %
1342     % where:
1343     % TAUx is the amplitude of the zonal surface wind-stress (N/m2)
1344     % RHO is the density of seawater (kg/m3)
1345     % f is the Coriolis parameter (kg/m3)
1346     % EKL is the Ekman layer depth (m)
1347     %
1348     % Files names are:
1349     % INPUT:
1350     % ./netcdf-files/<SNAPSHOT>/<netcdf_RHO>.<netcdf_domain>.<netcdf_suff>
1351     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUX>.<netcdf_domain>.<netcdf_suff>
1352     % OUTPUT
1353     % ./netcdf-files/<SNAPSHOT>/<netcdf_EKLx>.<netcdf_domain>.<netcdf_suff>
1354     %
1355     % with netcdf_* as global variables
1356     % netcdf_EKLx = 'EKLx' by default
1357     %
1358     % 12/04/06
1359     % gmaze@mit.edu
1360    
1361     function varargout = compute_EKLx(snapshot)
1362    
1363     global sla toshow
1364     global netcdf_suff netcdf_domain
1365     global netcdf_TAUX netcdf_RHO netcdf_EKLx
1366     pv_checkpath
1367     global EKL Tx Ty TAU RHO f
1368    
1369    
1370     % NETCDF file name:
1371     filTx = netcdf_TAUX;
1372     filRHO = netcdf_RHO;
1373    
1374     % Path and extension to find them:
1375     pathname = strcat('netcdf-files',sla);
1376     ext = netcdf_suff;
1377    
1378     % Load files:
1379     ferfile = strcat(pathname,sla,snapshot,sla,filTx,'.',netcdf_domain,'.',ext);
1380     ncTx = netcdf(ferfile,'nowrite');
1381     Tx = ncTx{4}(1,:,:);
1382    
1383     ferfile = strcat(pathname,sla,snapshot,sla,filRHO,'.',netcdf_domain,'.',ext);
1384     ncRHO = netcdf(ferfile,'nowrite');
1385     RHO = ncRHO{4}(1,:,:);
1386     [RHOlon RHOlat RHOdpt] = coordfromnc(ncRHO);
1387    
1388    
1389     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390     % Get EKL
1391     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1392    
1393     % Dim:
1394     if toshow, disp('dim'), end
1395     nx = length(RHOlon);
1396     ny = length(RHOlat);
1397     ynz = length(RHOdpt);
1398    
1399     % Pre-allocate:
1400     if toshow, disp('pre-allocate'), end
1401     EKL = zeros(ny,nx);
1402    
1403     % Planetary vorticity:
1404     f = 2*(2*pi/86400)*sin(RHOlat*pi/180);
1405     [a f c]=meshgrid(RHOlon,f,RHOdpt); clear a c
1406     f = permute(f,[3 1 2]);
1407     f = squeeze(f(1,:,:));
1408    
1409     % Windstress amplitude:
1410     TAU = sqrt( Tx.^2 );
1411    
1412     % Ekman Layer Depth:
1413     EKL = 0.7* sqrt(TAU ./ RHO) ./f;
1414     %EKL = 1.7975 * sqrt( TAU ./ RHO ./ f );
1415    
1416     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1417     % Record
1418     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1419     if toshow, disp('record'), end
1420    
1421     % General informations:
1422     if ~isempty('netcdf_EKLx')
1423     netfil = netcdf_EKLx;
1424     else
1425     netfil = 'EKLx';
1426     end
1427     units = 'm';
1428     ncid = 'EKLx';
1429     longname = 'Ekman Layer Depth from TAUx';
1430     uniquename = 'EKLx';
1431    
1432     % Open output file:
1433     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
1434    
1435     % Define axis:
1436     nx = length(RHOlon) ;
1437     ny = length(RHOlat) ;
1438     nz = 1 ;
1439    
1440     nc('X') = nx;
1441     nc('Y') = ny;
1442     nc('Z') = nz;
1443    
1444     nc{'X'} = ncfloat('X');
1445     nc{'X'}.uniquename = ncchar('X');
1446     nc{'X'}.long_name = ncchar('longitude');
1447     nc{'X'}.gridtype = nclong(0);
1448     nc{'X'}.units = ncchar('degrees_east');
1449     nc{'X'}(:) = RHOlon;
1450    
1451     nc{'Y'} = ncfloat('Y');
1452     nc{'Y'}.uniquename = ncchar('Y');
1453     nc{'Y'}.long_name = ncchar('latitude');
1454     nc{'Y'}.gridtype = nclong(0);
1455     nc{'Y'}.units = ncchar('degrees_north');
1456     nc{'Y'}(:) = RHOlat;
1457    
1458     nc{'Z'} = ncfloat('Z');
1459     nc{'Z'}.uniquename = ncchar('Z');
1460     nc{'Z'}.long_name = ncchar('depth');
1461     nc{'Z'}.gridtype = nclong(0);
1462     nc{'Z'}.units = ncchar('m');
1463     nc{'Z'}(:) = RHOdpt(1);
1464    
1465     % And main field:
1466     nc{ncid} = ncfloat('Z', 'Y', 'X');
1467     nc{ncid}.units = ncchar(units);
1468     nc{ncid}.missing_value = ncfloat(NaN);
1469     nc{ncid}.FillValue_ = ncfloat(NaN);
1470     nc{ncid}.longname = ncchar(longname);
1471     nc{ncid}.uniquename = ncchar(uniquename);
1472     nc{ncid}(:,:,:) = EKL;
1473    
1474    
1475    
1476     % Close files:
1477     close(ncTx);
1478     close(ncRHO);
1479     close(nc);
1480    
1481    
1482    
1483     % Output:
1484     output = struct('EKL',EKL,'lat',RHOlat,'lon',RHOlon);
1485     switch nargout
1486     case 1
1487     varargout(1) = {output};
1488     end
1489     gmaze_pv/compute_JBz.m0000644002352600001440000000654210560415013014316 0ustar gmazeusers%
1490     % [JBz] = compute_JBz(SNAPSHOT)
1491     %
1492     % Here we compute the PV flux due to diabatic processes as
1493     % JFz = - alpha * f * Qnet / MLD / Cw
1494     % where:
1495     % alpha = 2.5*E-4 1/K is the thermal expansion coefficient
1496     % f = 2*OMEGA*sin(LAT) is the Coriolis parameter
1497     % Qnet is the net surface heat flux (W/m^2), positive downward
1498     % MLD is the mixed layer depth (m, positive)
1499     % Cw = 4187 J/kg/K is the specific heat of seawater
1500     %
1501     % Files names are:
1502     % INPUT:
1503     % ./netcdf-files/<SNAPSHOT>/<netcdf_Qnet>.<netcdf_domain>.<netcdf_suff>
1504     % ./netcdf-files/<SNAPSHOT>/<netcdf_MLD>.<netcdf_domain>.<netcdf_suff>
1505     % OUTPUT:
1506     % ./netcdf-files/<SNAPSHOT>/JBz.<netcdf_domain>.<netcdf_suff>
1507     %
1508     % with: netcdf_* as global variables
1509     %
1510     % 06/27/06
1511     % gmaze@mit.edu
1512    
1513     function varargout = compute_JBz(snapshot)
1514    
1515     global sla toshow
1516     global netcdf_suff netcdf_domain
1517     global netcdf_Qnet netcdf_MLD
1518     pv_checkpath
1519    
1520    
1521     % Path and extension to find netcdf-files:
1522     pathname = strcat('netcdf-files',sla);
1523     ext = netcdf_suff;
1524    
1525     % Load files:
1526     ferfile = strcat(pathname,sla,snapshot,sla,netcdf_Qnet,'.',netcdf_domain,'.',ext);
1527     ncQ = netcdf(ferfile,'nowrite');
1528     [Qlon Qlat Qdpt] = coordfromnc(ncQ);
1529    
1530     ferfile = strcat(pathname,sla,snapshot,sla,netcdf_MLD,'.',netcdf_domain,'.',ext);
1531     ncMLD = netcdf(ferfile,'nowrite');
1532     [MLDlon MLDlat MLDdpt] = coordfromnc(ncMLD);
1533    
1534    
1535    
1536     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537     % surface PV flux
1538     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1539    
1540     % Define axis:
1541     nx = length(Qlon) ;
1542     ny = length(Qlat) ;
1543     nz = length(Qdpt) ;
1544    
1545    
1546     % Planetary vorticity:
1547     f = 2*(2*pi/86400)*sin(Qlat*pi/180);
1548     [a f] = meshgrid(Qlon,f); clear a c
1549    
1550    
1551     % Net surface heat flux:
1552     Qnet = ncQ{4}(:,:,:);
1553    
1554    
1555     % Mixed layer Depth:
1556     MLD = ncMLD{4}(:,:,:);
1557    
1558    
1559     % Coefficient:
1560     alpha = 2.5*10^(-4); % Surface average value
1561     Cw = 4187;
1562     coef = - alpha / Cw;
1563    
1564    
1565     % JBz:
1566     JBz = zeros(nz,ny,nx).*NaN;
1567     JBz(1,:,:) = coef*f.*Qnet./MLD;
1568    
1569    
1570    
1571     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1572     % Record
1573     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1574     if toshow, disp('record'), end
1575    
1576     % General informations:
1577     netfil = 'JBz';
1578     units = 'kg/m3/s2';
1579     ncid = 'JBz';
1580     longname = 'Vertical PV flux due to diabatic processes';
1581     uniquename = 'JBz';
1582    
1583     % Open output file:
1584     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
1585    
1586     % Define axis:
1587     nx = length(Qlon) ;
1588     ny = length(Qlat) ;
1589     nz = 1 ;
1590    
1591     nc('X') = nx;
1592     nc('Y') = ny;
1593     nc('Z') = nz;
1594    
1595     nc{'X'} = ncfloat('X');
1596     nc{'X'}.uniquename = ncchar('X');
1597     nc{'X'}.long_name = ncchar('longitude');
1598     nc{'X'}.gridtype = nclong(0);
1599     nc{'X'}.units = ncchar('degrees_east');
1600     nc{'X'}(:) = Qlon;
1601    
1602     nc{'Y'} = ncfloat('Y');
1603     nc{'Y'}.uniquename = ncchar('Y');
1604     nc{'Y'}.long_name = ncchar('latitude');
1605     nc{'Y'}.gridtype = nclong(0);
1606     nc{'Y'}.units = ncchar('degrees_north');
1607     nc{'Y'}(:) = Qlat;
1608    
1609     nc{'Z'} = ncfloat('Z');
1610     nc{'Z'}.uniquename = ncchar('Z');
1611     nc{'Z'}.long_name = ncchar('depth');
1612     nc{'Z'}.gridtype = nclong(0);
1613     nc{'Z'}.units = ncchar('m');
1614     nc{'Z'}(:) = Qdpt(1);
1615    
1616     % And main field:
1617     nc{ncid} = ncfloat('Z', 'Y', 'X');
1618     nc{ncid}.units = ncchar(units);
1619     nc{ncid}.missing_value = ncfloat(NaN);
1620     nc{ncid}.FillValue_ = ncfloat(NaN);
1621     nc{ncid}.longname = ncchar(longname);
1622     nc{ncid}.uniquename = ncchar(uniquename);
1623     nc{ncid}(:,:,:) = JBz;
1624    
1625     nc=close(nc);
1626     close(ncQ);
1627     close(ncMLD);
1628    
1629    
1630    
1631     % Output:
1632     output = struct('JBz',JBz,'lat',Qlat,'lon',Qlon);
1633     switch nargout
1634     case 1
1635     varargout(1) = {output};
1636     end
1637     gmaze_pv/compute_JFz.m0000644002352600001440000001363410560414727014335 0ustar gmazeusers%
1638     % [JFz] = compute_JFz(SNAPSHOT)
1639     %
1640     % Here we compute the PV flux due to frictionnal forces as
1641     % JFz = ( TAUx * dSIGMATHETA/dy - TAUy * dSIGMATHETA/dx ) / RHO / EKL
1642     %
1643     % where:
1644     % TAU is the surface wind-stress (N/m2)
1645     % SIGMATHETA is the potential density (kg/m3)
1646     % RHO is the density (kg/m3)
1647     % EKL is the Ekman layer depth (m, positive)
1648     %
1649     % Files names are:
1650     % INPUT:
1651     % ./netcdf-files/<SNAPSHOT>/<netcdf_SIGMATHETA>.<netcdf_domain>.<netcdf_suff>
1652     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUX>.<netcdf_domain>.<netcdf_suff>
1653     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUY>.<netcdf_domain>.<netcdf_suff>
1654     % ./netcdf-files/<SNAPSHOT>/<netcdf_RHO>.<netcdf_domain>.<netcdf_suff>
1655     % ./netcdf-files/<SNAPSHOT>/<netcdf_EKL>.<netcdf_domain>.<netcdf_suff>
1656     % OUTPUT:
1657     % ./netcdf-files/<SNAPSHOT>/JFz.<netcdf_domain>.<netcdf_suff>
1658     %
1659     % with netcdf_* as global variables
1660     %
1661     % 06/27/06
1662     % gmaze@mit.edu
1663    
1664     function varargout = compute_JFz(snapshot)
1665    
1666     global sla toshow
1667     global netcdf_suff netcdf_domain
1668     global netcdf_TAUX netcdf_TAUY netcdf_SIGMATHETA netcdf_EKL netcdf_RHO
1669     pv_checkpath
1670    
1671    
1672     % NETCDF file name:
1673     filST = netcdf_SIGMATHETA;
1674     filTx = netcdf_TAUX;
1675     filTy = netcdf_TAUY;
1676     filRHO = netcdf_RHO;
1677     filH = netcdf_EKL;
1678    
1679     % Path and extension to find them:
1680     pathname = strcat('netcdf-files',sla);
1681     ext = netcdf_suff;
1682    
1683     % Load files:
1684     ferfile = strcat(pathname,sla,snapshot,sla,filST,'.',netcdf_domain,'.',ext);
1685     ncST = netcdf(ferfile,'nowrite');
1686     [STlon STlat STdpt] = coordfromnc(ncST);
1687    
1688     ferfile = strcat(pathname,sla,snapshot,sla,filTx,'.',netcdf_domain,'.',ext);
1689     ncTx = netcdf(ferfile,'nowrite');
1690     ferfile = strcat(pathname,sla,snapshot,sla,filTy,'.',netcdf_domain,'.',ext);
1691     ncTy = netcdf(ferfile,'nowrite');
1692    
1693     ferfile = strcat(pathname,sla,snapshot,sla,filRHO,'.',netcdf_domain,'.',ext);
1694     ncRHO = netcdf(ferfile,'nowrite');
1695     RHO = ncRHO{4}(1,:,:);
1696    
1697     ferfile = strcat(pathname,sla,snapshot,sla,filH,'.',netcdf_domain,'.',ext);
1698     ncH = netcdf(ferfile,'nowrite');
1699     EKL = ncH{4}(1,:,:);
1700    
1701    
1702    
1703    
1704     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1705     % First term
1706     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1707    
1708     % Dim:
1709     if toshow, disp('dim'), end
1710     nx = length(STlon) ;
1711     ny = length(STlat) - 1 ;
1712     nz = length(STdpt);
1713    
1714     % Pre-allocate:
1715     if toshow, disp('pre-allocate'), end
1716     dSIGMATHETAdy = zeros(nz,ny-1,nx).*NaN;
1717     dy = zeros(1,ny).*NaN;
1718     STup = zeros(nz,ny);
1719     STdw = zeros(nz,ny);
1720    
1721     % Meridional gradient of SIGMATHETA:
1722     if toshow, disp('grad'), end
1723     % Assuming the grid is regular, dy is independent of x:
1724     [dy b] = meshgrid( m_lldist([1 1]*STlon(1),STlat(1:ny+1) ), STdpt ) ; clear b
1725     for ix = 1 : nx
1726     if toshow, disp(strcat(num2str(ix),'/',num2str(nx))), end
1727     STup = squeeze(ncST{4}(:,2:ny+1,ix));
1728     STdw = squeeze(ncST{4}(:,1:ny,ix));
1729     dSTdy = ( STup - STdw ) ./ dy;
1730     % Change horizontal grid point definition to fit with SIGMATHETA:
1731     dSTdy = ( dSTdy(:,1:ny-1) + dSTdy(:,2:ny) )./2;
1732     dSIGMATHETAdy(:,:,ix) = dSTdy;
1733     end %for iy
1734    
1735     % Make TAUx having same limits:
1736     TAUx = ncTx{4}(1,2:ny,:);
1737    
1738     % Compute first term: TAUx * dSIGMATHETA/dy
1739     iz = 1;
1740     JFz_a = TAUx .* squeeze(dSIGMATHETAdy(iz,:,:)) ;
1741    
1742    
1743     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1744     % Second term
1745     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1746    
1747     % Dim:
1748     if toshow, disp('dim'), end
1749     nx = length(STlon) - 1;
1750     ny = length(STlat) ;
1751     nz = length(STdpt) ;
1752    
1753     % Pre-allocate:
1754     if toshow, disp('pre-allocate'), end
1755     dSIGMATHETAdx = zeros(nz,ny,nx-1).*NaN;
1756     dx = zeros(1,nx).*NaN;
1757     STup = zeros(nz,nx);
1758     STdw = zeros(nz,nx);
1759    
1760     % Zonal gradient of SIGMATHETA
1761     if toshow, disp('grad'), end
1762     for iy = 1 : ny
1763     if toshow, disp(strcat(num2str(iy),'/',num2str(ny))), end
1764     [dx b] = meshgrid( m_lldist(STlon(1:nx+1),[1 1]*STlat(iy)), STdpt ) ; clear b
1765     STup = squeeze(ncST{4}(:,iy,2:nx+1));
1766     STdw = squeeze(ncST{4}(:,iy,1:nx));
1767     dSTdx = ( STup - STdw ) ./ dx;
1768     % Change horizontal grid point definition to fit with SIGMATHETA:
1769     dSTdx = ( dSTdx(:,1:nx-1) + dSTdx(:,2:nx) )./2;
1770     dSIGMATHETAdx(:,iy,:) = dSTdx;
1771     end %for iy
1772    
1773     % Make TAUy having same limits:
1774     TAUy = ncTy{4}(1,:,2:nx);
1775    
1776     % Compute second term: TAUy * dSIGMATHETA/dx
1777     iz = 1;
1778     JFz_b = TAUy .* squeeze(dSIGMATHETAdx(iz,:,:)) ;
1779    
1780    
1781    
1782     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1783     % Finish ...
1784     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1785     % Then make all terms having same limits:
1786     nx = length(STlon) ;
1787     ny = length(STlat) ;
1788     nz = length(STdpt) ;
1789     JFz_a = squeeze(JFz_a(:,2:nx-1));
1790     JFz_b = squeeze(JFz_b(2:ny-1,:));
1791     delta_e = squeeze(EKL(2:ny-1,2:nx-1));
1792     rho = squeeze(RHO(2:ny-1,2:nx-1));
1793    
1794     % and finish:
1795     JFz = (JFz_a - JFz_b)./delta_e./rho;
1796    
1797    
1798     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1799     % Record
1800     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1801     if toshow, disp('record'), end
1802    
1803     % General informations:
1804     netfil = 'JFz';
1805     units = 'kg/m3/s2';
1806     ncid = 'JFz';
1807     longname = 'Vertical PV flux due to frictional forces';
1808     uniquename = 'JFz';
1809    
1810     % Open output file:
1811     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
1812    
1813     % Define axis:
1814     nx = length(STlon) ;
1815     ny = length(STlat) ;
1816     nz = 1 ;
1817    
1818     nc('X') = nx-2;
1819     nc('Y') = ny-2;
1820     nc('Z') = nz;
1821    
1822     nc{'X'} = ncfloat('X');
1823     nc{'X'}.uniquename = ncchar('X');
1824     nc{'X'}.long_name = ncchar('longitude');
1825     nc{'X'}.gridtype = nclong(0);
1826     nc{'X'}.units = ncchar('degrees_east');
1827     nc{'X'}(:) = STlon(2:nx-1);
1828    
1829     nc{'Y'} = ncfloat('Y');
1830     nc{'Y'}.uniquename = ncchar('Y');
1831     nc{'Y'}.long_name = ncchar('latitude');
1832     nc{'Y'}.gridtype = nclong(0);
1833     nc{'Y'}.units = ncchar('degrees_north');
1834     nc{'Y'}(:) = STlat(2:ny-1);
1835    
1836     nc{'Z'} = ncfloat('Z');
1837     nc{'Z'}.uniquename = ncchar('Z');
1838     nc{'Z'}.long_name = ncchar('depth');
1839     nc{'Z'}.gridtype = nclong(0);
1840     nc{'Z'}.units = ncchar('m');
1841     nc{'Z'}(:) = STdpt(1);
1842    
1843     % And main field:
1844     nc{ncid} = ncfloat('Z', 'Y', 'X');
1845     nc{ncid}.units = ncchar(units);
1846     nc{ncid}.missing_value = ncfloat(NaN);
1847     nc{ncid}.FillValue_ = ncfloat(NaN);
1848     nc{ncid}.longname = ncchar(longname);
1849     nc{ncid}.uniquename = ncchar(uniquename);
1850     nc{ncid}(:,:,:) = JFz;
1851    
1852     nc=close(nc);
1853    
1854    
1855     % Output:
1856     output = struct('JFz',JFz,'lat',STlat(2:ny-1),'lon',STlon(2:nx-1));
1857     switch nargout
1858     case 1
1859     varargout(1) = {output};
1860     end
1861     gmaze_pv/compute_JFzx.m0000644002352600001440000001116410560414775014524 0ustar gmazeusers%
1862     % [JFzx] = compute_JFzx(SNAPSHOT)
1863     %
1864     % Here we compute the PV flux due to the zonal frictionnal force as
1865     % JFzx = ( TAUx * dSIGMATHETA/dy ) / RHO / EKL
1866     %
1867     % where:
1868     % TAUx is the surface zonal wind-stress (N/m2)
1869     % SIGMATHETA is the potential density (kg/m3)
1870     % RHO is the density (kg/m3)
1871     % EKL is the Ekman layer depth (m, positive)
1872     %
1873     % Files names are:
1874     % INPUT:
1875     % ./netcdf-files/<SNAPSHOT>/<netcdf_SIGMATHETA>.<netcdf_domain>.<netcdf_suff>
1876     % ./netcdf-files/<SNAPSHOT>/<netcdf_TAUX>.<netcdf_domain>.<netcdf_suff>
1877     % ./netcdf-files/<SNAPSHOT>/<netcdf_RHO>.<netcdf_domain>.<netcdf_suff>
1878     % ./netcdf-files/<SNAPSHOT>/<netcdf_EKL>.<netcdf_domain>.<netcdf_suff>
1879     % OUTPUT:
1880     % ./netcdf-files/<SNAPSHOT>/JFzx.<netcdf_domain>.<netcdf_suff>
1881     %
1882     % with netcdf_* as global variables
1883     %
1884     % 06/04/12
1885     % gmaze@mit.edu
1886    
1887     function varargout = compute_JFzx(snapshot)
1888    
1889     global sla toshow
1890     global netcdf_suff netcdf_domain
1891     global netcdf_TAUX netcdf_SIGMATHETA netcdf_EKL netcdf_RHO
1892     pv_checkpath
1893    
1894    
1895     % NETCDF file name:
1896     filST = netcdf_SIGMATHETA;
1897     filTx = netcdf_TAUX;
1898     filRHO = netcdf_RHO;
1899     filH = netcdf_EKL;
1900    
1901     % Path and extension to find them:
1902     pathname = strcat('netcdf-files',sla);
1903     ext = netcdf_suff;
1904    
1905     % Load files:
1906     ferfile = strcat(pathname,sla,snapshot,sla,filST,'.',netcdf_domain,'.',ext);
1907     ncST = netcdf(ferfile,'nowrite');
1908     [STlon STlat STdpt] = coordfromnc(ncST);
1909    
1910     ferfile = strcat(pathname,sla,snapshot,sla,filTx,'.',netcdf_domain,'.',ext);
1911     ncTx = netcdf(ferfile,'nowrite');
1912    
1913     ferfile = strcat(pathname,sla,snapshot,sla,filRHO,'.',netcdf_domain,'.',ext);
1914     ncRHO = netcdf(ferfile,'nowrite');
1915     RHO = ncRHO{4}(1,:,:);
1916    
1917     ferfile = strcat(pathname,sla,snapshot,sla,filH,'.',netcdf_domain,'.',ext);
1918     ncH = netcdf(ferfile,'nowrite');
1919     EKL = ncH{4}(1,:,:);
1920    
1921     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1922     % First term
1923     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1924    
1925     % Dim:
1926     if toshow, disp('dim'), end
1927     nx = length(STlon) ;
1928     ny = length(STlat) - 1 ;
1929    
1930     % Pre-allocate:
1931     if toshow, disp('pre-allocate'), end
1932     dSIGMATHETAdy = zeros(ny-1,nx).*NaN;
1933     dy = zeros(1,ny).*NaN;
1934     STup = zeros(1,ny);
1935     STdw = zeros(1,ny);
1936    
1937     % Meridional gradient of SIGMATHETA:
1938     if toshow, disp('grad'), end
1939     % Assuming the grid is regular, dy is independent of x:
1940     dy = m_lldist([1 1]*STlon(1),STlat(1:ny+1) ) ;
1941     for ix = 1 : nx
1942     if toshow, disp(strcat(num2str(ix),'/',num2str(nx))), end
1943     STup = squeeze(ncST{4}(1,2:ny+1,ix));
1944     STdw = squeeze(ncST{4}(1,1:ny,ix));
1945     dSTdy = ( STup - STdw ) ./ dy;
1946     % Change horizontal grid point definition to fit with SIGMATHETA:
1947     dSTdy = ( dSTdy(1:ny-1) + dSTdy(2:ny) )./2;
1948     dSIGMATHETAdy(:,ix) = dSTdy;
1949     end %for iy
1950    
1951     % Make TAUx having same limits:
1952     TAUx = ncTx{4}(1,2:ny,:);
1953    
1954     % Compute first term: TAUx * dSIGMATHETA/dy
1955     JFz_a = TAUx .* dSIGMATHETAdy ;
1956    
1957    
1958     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1959     % Finish ...
1960     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1961     % Then make all terms having same limits:
1962     nx = length(STlon) ;
1963     ny = length(STlat) ;
1964     JFz_a = squeeze(JFz_a(:,2:nx-1));
1965     delta_e = squeeze(EKL(2:ny-1,2:nx-1));
1966     rho = squeeze(RHO(2:ny-1,2:nx-1));
1967    
1968     % and finish:
1969     JFz = JFz_a./delta_e./rho;
1970    
1971    
1972     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1973     % Record
1974     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1975     if toshow, disp('record'), end
1976    
1977     % General informations:
1978     netfil = 'JFzx';
1979     units = 'kg/m3/s2';
1980     ncid = 'JFzx';
1981     longname = 'Vertical PV flux due to the zonal frictional force';
1982     uniquename = 'JFzx';
1983    
1984     % Open output file:
1985     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
1986    
1987     % Define axis:
1988     nx = length(STlon) ;
1989     ny = length(STlat) ;
1990     nz = 1 ;
1991    
1992     nc('X') = nx-2;
1993     nc('Y') = ny-2;
1994     nc('Z') = nz;
1995    
1996     nc{'X'} = ncfloat('X');
1997     nc{'X'}.uniquename = ncchar('X');
1998     nc{'X'}.long_name = ncchar('longitude');
1999     nc{'X'}.gridtype = nclong(0);
2000     nc{'X'}.units = ncchar('degrees_east');
2001     nc{'X'}(:) = STlon(2:nx-1);
2002    
2003     nc{'Y'} = ncfloat('Y');
2004     nc{'Y'}.uniquename = ncchar('Y');
2005     nc{'Y'}.long_name = ncchar('latitude');
2006     nc{'Y'}.gridtype = nclong(0);
2007     nc{'Y'}.units = ncchar('degrees_north');
2008     nc{'Y'}(:) = STlat(2:ny-1);
2009    
2010     nc{'Z'} = ncfloat('Z');
2011     nc{'Z'}.uniquename = ncchar('Z');
2012     nc{'Z'}.long_name = ncchar('depth');
2013     nc{'Z'}.gridtype = nclong(0);
2014     nc{'Z'}.units = ncchar('m');
2015     nc{'Z'}(:) = STdpt(1);
2016    
2017     % And main field:
2018     nc{ncid} = ncfloat('Z', 'Y', 'X');
2019     nc{ncid}.units = ncchar(units);
2020     nc{ncid}.missing_value = ncfloat(NaN);
2021     nc{ncid}.FillValue_ = ncfloat(NaN);
2022     nc{ncid}.longname = ncchar(longname);
2023     nc{ncid}.uniquename = ncchar(uniquename);
2024     nc{ncid}(:,:,:) = JFz;
2025    
2026    
2027    
2028     %%% Close files:
2029     close(ncST);
2030     close(ncTx);
2031     close(ncRHO);
2032     close(ncH);
2033     close(nc);
2034    
2035     % Output:
2036     output = struct('JFzx',JFz,'lat',STlat(2:ny-1),'lon',STlon(2:nx-1));
2037     switch nargout
2038     case 1
2039     varargout(1) = {output};
2040     end
2041     gmaze_pv/compute_MLD.m0000644002352600001440000001011010562175511014237 0ustar gmazeusers%
2042     % [MLD] = compute_MLD(SNAPSHOT)
2043     %
2044     % Here we compute the Mixed Layer Depth as:
2045     % MLD = min depth for which : ST > ST(SSS,SST-0.8,p0)
2046     %
2047     % where:
2048     % ST is potential density (kg/m3)
2049     % SST the Sea Surface Temperature (oC)
2050     % SSS the Sea Surface Salinity (PSU-35)
2051     % p0 the Sea Level Pressure (mb)
2052     % EKL is the Ekman layer depth (m, positive)
2053     %
2054     % Files names are:
2055     % INPUT:
2056     % ./netcdf-files/<SNAPSHOT>/<netcdf_SIGMATHETA>.<netcdf_domain>.<netcdf_suff>
2057     % ./netcdf-files/<SNAPSHOT>/<netcdf_THETA>.<netcdf_domain>.<netcdf_suff>
2058     % ./netcdf-files/<SNAPSHOT>/<netcdf_SALTanom>.<netcdf_domain>.<netcdf_suff>
2059     % OUTPUT
2060     % ./netcdf-files/<SNAPSHOT>/<netcdf_MLD>.<netcdf_domain>.<netcdf_suff>
2061     %
2062     % with netcdf_* as global variables
2063     % netcdf_MLD = 'MLD' by default
2064     %
2065     % Rq: This method leads to a MLD deeper than KPPmld in the middle of the
2066     % ocean, and shallower along the coast.
2067     %
2068     % 09/20/06
2069     % gmaze@mit.edu
2070    
2071     function varargout = compute_MLD(snapshot)
2072    
2073     global sla toshow
2074     global netcdf_suff netcdf_domain
2075     global netcdf_SIGMATHETA netcdf_THETA netcdf_SALTanom netcdf_MLD
2076     pv_checkpath
2077    
2078    
2079     % NETCDF file name:
2080     filST = netcdf_SIGMATHETA;
2081     filT = netcdf_THETA;
2082     filS = netcdf_SALTanom;
2083    
2084     % Path and extension to find them:
2085     pathname = strcat('netcdf-files',sla);
2086     ext = netcdf_suff;
2087    
2088     % Load files:
2089     ferfile = strcat(pathname,sla,snapshot,sla,filST,'.',netcdf_domain,'.',ext);
2090     ncST = netcdf(ferfile,'nowrite');
2091     ST = ncST{4}(:,:,:);
2092     [STlon STlat STdpt] = coordfromnc(ncST);
2093    
2094     ferfile = strcat(pathname,sla,snapshot,sla,filT,'.',netcdf_domain,'.',ext);
2095     ncT = netcdf(ferfile,'nowrite');
2096     SST = ncT{4}(1,:,:);
2097     [Tlon Tlat Tdpt] = coordfromnc(ncT);
2098    
2099     ferfile = strcat(pathname,sla,snapshot,sla,filS,'.',netcdf_domain,'.',ext);
2100     ncS = netcdf(ferfile,'nowrite');
2101     SSS = ncS{4}(1,:,:);
2102     [Slon Slat Sdpt] = coordfromnc(ncS);
2103    
2104    
2105     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2106     % COMPUTE The Mixed Layer Depth:
2107     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2108     if toshow, disp('pre-allocate'), end
2109     nx = length(STlon);
2110     ny = length(STlat);
2111     SST08 = SST - 0.8;
2112     SSS = SSS + 35;
2113     Surfadens08 = densjmd95(SSS,SST08,(0.09998*9.81*Tdpt(1))*ones(ny,nx))-1000;
2114     MLD = zeros(size(ST,2),size(ST,3));
2115    
2116     if toshow, disp('get MLD'), end
2117     for iy = 1 : size(ST,2)
2118     for ix = 1 : size(ST,3)
2119     mm = find( squeeze(ST(:,iy,ix)) > Surfadens08(iy,ix) );
2120     if ~isempty(mm)
2121     MLD(iy,ix) = STdpt(min(mm));
2122     end
2123     %end
2124     end
2125     end
2126    
2127     MLD(isnan(squeeze(ST(1,:,:)))) = NaN;
2128    
2129    
2130     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2131     % Ensure we have the right sign (positive)
2132     mm = nanmean(nanmean(MLD,1));
2133     if mm <= 0
2134     MLD = -MLD;
2135     end
2136    
2137    
2138    
2139     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2140     % Record
2141     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142     if toshow, disp('record'), end
2143    
2144     % General informations:
2145     if ~isempty('netcdf_MLD')
2146     netfil = netcdf_MLD;
2147     else
2148     netfil = 'MLD';
2149     end
2150     units = 'm';
2151     ncid = 'MLD';
2152     longname = 'Mixed Layer Depth';
2153     uniquename = 'MLD';
2154    
2155     % Open output file:
2156     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
2157    
2158     % Define axis:
2159     nx = length(STlon) ;
2160     ny = length(STlat) ;
2161     nz = 1 ;
2162    
2163     nc('X') = nx;
2164     nc('Y') = ny;
2165     nc('Z') = nz;
2166    
2167     nc{'X'} = ncfloat('X');
2168     nc{'X'}.uniquename = ncchar('X');
2169     nc{'X'}.long_name = ncchar('longitude');
2170     nc{'X'}.gridtype = nclong(0);
2171     nc{'X'}.units = ncchar('degrees_east');
2172     nc{'X'}(:) = STlon;
2173    
2174     nc{'Y'} = ncfloat('Y');
2175     nc{'Y'}.uniquename = ncchar('Y');
2176     nc{'Y'}.long_name = ncchar('latitude');
2177     nc{'Y'}.gridtype = nclong(0);
2178     nc{'Y'}.units = ncchar('degrees_north');
2179     nc{'Y'}(:) = STlat;
2180    
2181     nc{'Z'} = ncfloat('Z');
2182     nc{'Z'}.uniquename = ncchar('Z');
2183     nc{'Z'}.long_name = ncchar('depth');
2184     nc{'Z'}.gridtype = nclong(0);
2185     nc{'Z'}.units = ncchar('m');
2186     nc{'Z'}(:) = STdpt(1);
2187    
2188     % And main field:
2189     nc{ncid} = ncfloat('Z', 'Y', 'X');
2190     nc{ncid}.units = ncchar(units);
2191     nc{ncid}.missing_value = ncfloat(NaN);
2192     nc{ncid}.FillValue_ = ncfloat(NaN);
2193     nc{ncid}.longname = ncchar(longname);
2194     nc{ncid}.uniquename = ncchar(uniquename);
2195     nc{ncid}(:,:,:) = MLD;
2196    
2197     nc=close(nc);
2198     close(ncST);
2199     close(ncS);
2200     close(ncT);
2201    
2202    
2203     % Output:
2204     output = struct('MLD',MLD,'lat',STlat,'lon',STlon);
2205     switch nargout
2206     case 1
2207     varargout(1) = {output};
2208     end
2209     gmaze_pv/compute_QEk.m0000644002352600001440000000753110560415154014316 0ustar gmazeusers%
2210     % [QEk] = compute_QEk(SNAPSHOT)
2211     %
2212     % Here we compute the lateral heat flux induced by Ekman currents
2213     % from JFz, the PV flux induced by frictional forces:
2214     % QEk = - Cw * EKL * JFz / alpha / f
2215     % where:
2216     % Cw = 4187 J/kg/K is the specific heat of seawater
2217     % EKL is the Ekman layer depth (m)
2218     % JFz is the PV flux (kg/m3/s2)
2219     % alpha = 2.5*E-4 1/K is the thermal expansion coefficient
2220     % f = 2*OMEGA*sin(LAT) is the Coriolis parameter
2221     %
2222     % This allows a direct comparison with the net surface heat flux Qnet
2223     % which forces the surface Pv flux due to diabatic processes.
2224     %
2225     % Remind that:
2226     % JFz = ( TAUx * dSIGMATHETA/dy - TAUy * dSIGMATHETA/dx ) / RHO / EKL
2227     %
2228     % Files names are:
2229     % INPUT:
2230     % ./netcdf-files/<SNAPSHOT>/<netcdf_JFz>.<netcdf_domain>.<netcdf_suff>
2231     % ./netcdf-files/<SNAPSHOT>/<netcdf_EKL>.<netcdf_domain>.<netcdf_suff>
2232     % OUPUT:
2233     % ./netcdf-files/<SNAPSHOT>/QEk.<netcdf_domain>.<netcdf_suff>
2234     %
2235     % with netcdf_* as global variables
2236     %
2237     % 06/27/06
2238     % gmaze@mit.edu
2239    
2240     function varargout = compute_QEk(snapshot)
2241    
2242     global sla toshow
2243     global netcdf_suff netcdf_domain
2244     global netcdf_JFz netcdf_EKL
2245     pv_checkpath
2246    
2247    
2248     % NETCDF file name:
2249     filJFz = netcdf_JFz;
2250     filEKL = netcdf_EKL;
2251    
2252     % Path and extension to find them:
2253     pathname = strcat('netcdf-files',sla);
2254     ext = netcdf_suff;
2255    
2256     % Load files:
2257     ferfile = strcat(pathname,sla,snapshot,sla,filJFz,'.',netcdf_domain,'.',ext);
2258     ncJFz = netcdf(ferfile,'nowrite');
2259     JFz = ncJFz{4}(1,:,:);
2260     [JFzlon JFzlat JFzdpt] = coordfromnc(ncJFz);
2261    
2262     ferfile = strcat(pathname,sla,snapshot,sla,filEKL,'.',netcdf_domain,'.',ext);
2263     ncEKL = netcdf(ferfile,'nowrite');
2264     EKL = ncEKL{4}(1,:,:);
2265     [EKLlon EKLlat EKLdpt] = coordfromnc(ncEKL);
2266    
2267     % Make them having same limits:
2268     % (JFz is defined with first/last points removed from the EKL grid)
2269     nx = length(JFzlon) ;
2270     ny = length(JFzlat) ;
2271     nz = length(JFzdpt) ;
2272     EKL = squeeze(EKL(2:ny+1,2:nx+1));
2273    
2274    
2275     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2276     %
2277     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2278    
2279     % Dim:
2280     if toshow, disp('dim'), end
2281     nx = length(JFzlon) ;
2282     ny = length(JFzlat) ;
2283     nz = length(JFzdpt) ;
2284    
2285     % Pre-allocate:
2286     if toshow, disp('pre-allocate'), end
2287     QEk = zeros(nz,ny,nx).*NaN;
2288    
2289     % Planetary vorticity:
2290     f = 2*(2*pi/86400)*sin(JFzlat*pi/180);
2291     [a f]=meshgrid(JFzlon,f); clear a c
2292    
2293     % Coefficient:
2294     Cw = 4187;
2295     al = 2.5*10^(-4); % Average surface value of alpha
2296     coef = - Cw / al;
2297    
2298     % Compute flux:
2299     QEk = coef.* EKL .* JFz ./ f;
2300    
2301    
2302    
2303    
2304    
2305     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2306     % Record
2307     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
2308     if toshow, disp('record'), end
2309    
2310     % General informations:
2311     netfil = 'QEk';
2312     units = 'W/m2';
2313     ncid = 'QEk';
2314     longname = 'Lateral heat flux induced by Ekman currents';
2315     uniquename = 'QEk';
2316    
2317     % Open output file:
2318     nc = netcdf(strcat(pathname,sla,snapshot,sla,netfil,'.',netcdf_domain,'.',ext),'clobber');
2319    
2320     % Define axis:
2321     nx = length(JFzlon) ;
2322     ny = length(JFzlat) ;
2323     nz = 1 ;
2324    
2325     nc('X') = nx;
2326     nc('Y') = ny;
2327     nc('Z') = nz;
2328    
2329     nc{'X'} = ncfloat('X');
2330     nc{'X'}.uniquename = ncchar('X');
2331     nc{'X'}.long_name = ncchar('longitude');
2332     nc{'X'}.gridtype = nclong(0);
2333     nc{'X'}.units = ncchar('degrees_east');
2334     nc{'X'}(:) = JFzlon;
2335    
2336     nc{'Y'} = ncfloat('Y');
2337     nc{'Y'}.uniquename = ncchar('Y');
2338     nc{'Y'}.long_name = ncchar('latitude');
2339     nc{'Y'}.gridtype = nclong(0);
2340     nc{'Y'}.units = ncchar('degrees_north');
2341     nc{'Y'}(:) = JFzlat;
2342    
2343     nc{'Z'} = ncfloat('Z');
2344     nc{'Z'}.uniquename = ncchar('Z');
2345     nc{'Z'}.long_name = ncchar('depth');
2346     nc{'Z'}.gridtype = nclong(0);
2347     nc{'Z'}.units = ncchar('m');
2348     nc{'Z'}(:) = JFzdpt(1);
2349    
2350     % And main field:
2351     nc{ncid} = ncfloat('Z', 'Y', 'X');
2352     nc{ncid}.units = ncchar(units);
2353     nc{ncid}.missing_value = ncfloat(NaN);
2354     nc{ncid}.FillValue_ = ncfloat(NaN);
2355     nc{ncid}.longname = ncchar(longname);
2356     nc{ncid}.uniquename = ncchar(uniquename);
2357     nc{ncid}(:,:,:) = QEk;
2358    
2359     nc=close(nc);
2360    
2361    
2362    
2363     % Output:
2364     output = struct('QEk',QEk,'lat',JFzlat,'lon',JFzlon);
2365     switch nargout
2366     case 1
2367     varargout(1) = {output};
2368     end
2369     gmaze_pv/Contents.m0000644002352600001440000001344110560416053013673 0ustar gmazeusers% ECCO2: potential vorticity toolbox
2370     %
2371     % This package tries to provide some useful and simple routines to compute, visualize and
2372     % analyze Potential Vorticity from the global high resolution (1/8deg) simulation of the
2373     % MITgcm.
2374     % Routines are as general as possible for extended applications, but note that they were
2375     % developped to focus on the Western Atlantic region for the CLIMODE project.
2376     % Enjoy !
2377     %
2378     % gmaze@mit.edu
2379     % Last update: Feb1/2007
2380     %
2381     % ---------------------------------------------------------------------------------------------
2382     % PROGRAMS LIST (NOT A FUNCTIONS):
2383     %
2384     % eg_main_getPV
2385     % This program is an example of how to define global setup and
2386     % to launch the PV computing.
2387     % eg_write_bin2cdf_latlongrid_subdomain
2388     % This program is an example of how to extract a subdomain from
2389     % a lat/lon grid (1/8) binary file and write it into netcdf. A
2390     % directory is created for each time step.
2391     % eg_write_bin2cdf_csgrid_subdomain
2392     % This program is an example of how to extract a subdomain from
2393     % a cube sphere grid (CS510) binary file and write it into netcdf
2394     % and lat/lon grid (1/4). A directory is created for each time step.
2395     % eg_write_UVbin2cdf_csgrid_subdomain
2396     % Idem, except adapted to U and V fields.
2397     %
2398     % ---------------------------------------------------------------------------------------------
2399     % FUNCTIONS LIST 1: NETCDF FILES DIAGNOSTICS
2400     % From netcdf files contained into SNAPSHOT sub-directory of the
2401     % ./netcdf-files/ home folder, these functions ...
2402     %
2403     % A_compute_potential_density(SNAPSHOT)
2404     % Computes potential density SIGMATHETA from potential
2405     % temperature THETA and anomalous salinity SALTanom.
2406     % B_compute_relative_vorticity(SNAPSHOT)
2407     % Computes the 3 components of the relative vorticity from the
2408     % horizontal flow. Take care to the (U,V) grid !
2409     % C_compute_potential_vorticity(SNAPSHOT,[WANT_SPL_PV])
2410     % Computes the potential vorticity field from the relative
2411     % vorticity components and the potential density. Option
2412     % WANT_SPL_PV turned 1 (0 by default) makes the function only
2413     % computing the PV based on the planetary vorticity.
2414     % D_compute_potential_vorticity(SNAPSHOT,[WANT_SPL_PV])
2415     % Multiplies the potential vorticity computed with
2416     % C_COMPUTE_POTENTIAL_VORTICITY by the coefficient: -1/RHO
2417     % Optional flag WANTSPLPV is turned to 0 by default. Turn it to 1
2418     % if the PV computed was the simple one (f.dSIGMATHETA/dz). It's
2419     % needed for the output netcdf file informations.
2420     % compute_JBz(SNAPSHOT)
2421     % Computes the surface PV flux due to diabatic processes.
2422     % compute_JFz(SNAPSHOT)
2423     % Computes the surface PV flux due to frictionnal forces.
2424     % compute_density(SNAPSHOT)
2425     % Computes density RHO from potential temperature THETA
2426     % and anomalous salinity SALTanom.
2427     % compute_alpha(SNAPSHOT)
2428     % Computes the thermal expansion coefficient ALPHA from potential
2429     % temperature THETA and salinity anomaly SALTanom.
2430     % compute_QEk(SNAPSHOT)
2431     % Computes QEk, the lateral heat flux induced by Ekman currents
2432     % from JFz, the PV flux induced by frictional forces.
2433     % compute_EKL(SNAPSHOT)
2434     % Compute the Ekman Layer Depth from the wind stress and the density
2435     % fields.
2436     % compute_MLD(SNAPSHOT)
2437     % Compute the Mixed Layer Depth from the SST, SSS and potential
2438     % density fields.
2439     %
2440     % ---------------------------------------------------------------------------------------------
2441     % FUNCTIONS LIST 2: ANALYSIS FUNCTIONS
2442     %
2443     % volbet2iso(TRACER,LIMITS,DEPTH,LAT,LONG)
2444     % This function computes the volume embedded between two
2445     % iso-TRACER values and limited eastward, westward and southward
2446     % by fixed limits.
2447     % surfbet2outcrops(TRACER,LIMITS,LAT,LONG)
2448     % This function computes the horizontal surface limited
2449     % by two outcrops of a tracer.
2450     % intbet2outcrops(TRACER,LIMITS,LAT,LONG)
2451     % This function computes the horizontal surface integral
2452     % of the field TRACER on the area limited by two outcrops.
2453     % subfct_getisoS(TRACER,ISO)
2454     % This function determines the iso-surface ISO of the
2455     % 3D field TRACER(Z,Y,X).
2456     %
2457     % ---------------------------------------------------------------------------------------------
2458     % LOWER LEVEL AND SUB-FUNCTIONS LIST:
2459     %
2460     % pv_checkpath
2461     % This function, systematicaly called by the others, ensures that
2462     % all needed sub-directories of the package are in the path.
2463     %
2464     % ---------------------------------------------------------------------------------------------
2465     % PS:
2466     %
2467     % > Functions name are case sensitive.
2468     % > See sub-directory "subfct" for further functions.
2469     % > Following packages are required:
2470     % M_MAP: http://www.eos.ubc.ca/~rich/map.html
2471     % SEAWATER: http://www.marine.csiro.au/datacentre/processing.htm
2472     %
2473     % ---------------------------------------------------------------------------------------------
2474     %
2475     gmaze_pv/D_compute_potential_vorticity.m0000644002352600001440000001035310560414131020202 0ustar gmazeusers%
2476     % [Q] = D_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV])
2477     %
2478     % For a time snapshot, this program multiplies the potential
2479     % vorticity computed with C_COMPUTE_POTENTIAL_VORTICITY by the
2480     % coefficient: -1/RHO
2481     % Optional flag WANTSPLPV is turn to 0 by default. Turn it to 1
2482     % if the PV computed is the simple one (f.dSIGMATHETA/dz). It's
2483     % needed for the output netcdf file informations.
2484     %
2485     % CAUTION:
2486     %% If all the PV computing procedure has been performed with routines
2487     %% from the package, the PV field has less points than the RHO one, exactly
2488     %% first and last in all directions have to be removed from RHO.
2489     %
2490     % Files names are:
2491     % INPUT:
2492     % ./netcdf-files/<SNAPSHOT>/<netcdf_RHO>.<netcdf_domain>.<netcdf_suff>
2493     % ./netcdf-files/<SNAPSHOT>/<netcdf_PV>.<netcdf_domain>.<netcdf_suff>
2494     % OUPUT:
2495     % ./netcdf-files/<SNAPSHOT>/PV.<netcdf_domain>.<netcdf_suff>
2496     % or
2497     % ./netcdf-files/<SNAPSHOT>/splPV.<netcdf_domain>.<netcdf_suff>
2498     %
2499     % 06/21/2006
2500     % gmaze@mit.edu
2501     %
2502    
2503    
2504     function varargout = D_compute_potential_vorticity(snapshot,varargin)
2505    
2506    
2507     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2508     %% Setup
2509     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2510     global sla netcdf_RHO netcdf_PV netcdf_domain netcdf_suff
2511     pv_checkpath
2512    
2513     %% Flags to choose which term to compute (by default, all):
2514     FLpv3 = 1;
2515     if nargin==2 % case of optional flag presents:
2516     if varargin{1}(1) == 1 % Case of the simple PV:
2517     FLpv3 = 0;
2518     end
2519     end %if
2520    
2521     %% PV and RHO netcdf-files:
2522     filPV = strcat(netcdf_PV ,'.',netcdf_domain);
2523     filRHO = strcat(netcdf_RHO,'.',netcdf_domain);
2524    
2525     %% Path and extension to find them:
2526     pathname = strcat('netcdf-files',sla,snapshot);
2527     ext = strcat('.',netcdf_suff);
2528    
2529     %% Load netcdf files:
2530     ferfile = strcat(pathname,sla,filPV,ext);
2531     ncPV = netcdf(ferfile,'nowrite');
2532     [PV_lon PV_lat PV_dpt] = coordfromnc(ncPV);
2533    
2534     ferfile = strcat(pathname,sla,filRHO,ext);
2535     ncRHO = netcdf(ferfile,'nowrite');
2536     [RHO_lon RHO_lat RHO_dpt] = coordfromnc(ncRHO);
2537    
2538     %% Flags:
2539     global toshow % Turn to 1 to follow the computing process
2540    
2541    
2542    
2543     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2544     %% Apply the coefficient
2545     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2546    
2547     %% Pre-allocate:
2548     if toshow,disp('Pre-allocate');end
2549     nx = length(PV_lon);
2550     ny = length(PV_lat);
2551     nz = length(PV_dpt);
2552     PV = zeros(nz,ny,nx).*NaN;
2553    
2554     %% Apply:
2555     if toshow,disp('Multiplying PV field by -1/RHO'),end
2556     PV = - ncPV{4}(:,:,:) ./ ncRHO{4}(2:nz+1,2:ny+1,2:nx+1) ;
2557    
2558    
2559     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2560     % Record:
2561     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2562     if toshow,disp('Now reccording PV file ...'),end
2563    
2564     % General informations:
2565     %ncclose(ncPV);
2566    
2567     if FLpv3 == 1
2568     netfil = strcat('PV','.',netcdf_domain,'.',netcdf_suff);
2569     units = '1/s/m';
2570     ncid = 'PV';
2571     longname = 'Potential vorticity';
2572     uniquename = 'potential_vorticity';
2573     else
2574     netfil = strcat('splPV','.',netcdf_domain,'.',netcdf_suff);
2575     units = '1/s/m';
2576     ncid = 'splPV';
2577     longname = 'Simple Potential vorticity';
2578     uniquename = 'simple_potential_vorticity';
2579     end %if
2580    
2581     % Open output file:
2582     nc = netcdf(strcat(pathname,sla,netfil),'clobber');
2583    
2584     % Define axis:
2585     nc('X') = length(PV_lon);
2586     nc('Y') = length(PV_lat);
2587     nc('Z') = length(PV_dpt);
2588    
2589     nc{'X'} = 'X';
2590     nc{'Y'} = 'Y';
2591     nc{'Z'} = 'Z';
2592    
2593     nc{'X'} = ncfloat('X');
2594     nc{'X'}.uniquename = ncchar('X');
2595     nc{'X'}.long_name = ncchar('longitude');
2596     nc{'X'}.gridtype = nclong(0);
2597     nc{'X'}.units = ncchar('degrees_east');
2598     nc{'X'}(:) = PV_lon;
2599    
2600     nc{'Y'} = ncfloat('Y');
2601     nc{'Y'}.uniquename = ncchar('Y');
2602     nc{'Y'}.long_name = ncchar('latitude');
2603     nc{'Y'}.gridtype = nclong(0);
2604     nc{'Y'}.units = ncchar('degrees_north');
2605     nc{'Y'}(:) = PV_lat;
2606    
2607     nc{'Z'} = ncfloat('Z');
2608     nc{'Z'}.uniquename = ncchar('Z');
2609     nc{'Z'}.long_name = ncchar('depth');
2610     nc{'Z'}.gridtype = nclong(0);
2611     nc{'Z'}.units = ncchar('m');
2612     nc{'Z'}(:) = PV_dpt;
2613    
2614     % And main field:
2615     nc{ncid} = ncfloat('Z', 'Y', 'X');
2616     nc{ncid}.units = ncchar(units);
2617     nc{ncid}.missing_value = ncfloat(NaN);
2618     nc{ncid}.FillValue_ = ncfloat(NaN);
2619     nc{ncid}.longname = ncchar(longname);
2620     nc{ncid}.uniquename = ncchar(uniquename);
2621     nc{ncid}(:,:,:) = PV;
2622    
2623     nc=close(nc);
2624     close(ncPV);
2625     close(ncRHO);
2626    
2627     % Outputs:
2628     OUT = struct('PV',PV,'dpt',PV_dpt,'lat',PV_lat,'lon',PV_lon);
2629     switch nargout
2630     case 1
2631     varargout(1) = {OUT};
2632     end
2633     gmaze_pv/diagWALIN.m0000644002352600001440000001477210642604460013607 0ustar gmazeusers% [F,A,D,CROP] = diagWALIN(FLAG,C1,C2,Qnet,Snet,Classes,lon,lat,dA)
2634     %
2635     % DESCRIPTION:
2636     % Compute the transformation rate of a surface outcrop class (potential
2637     % density or SST) from surface net heat flux Qnet and salt flux Snet
2638     % according to the Walin theory.
2639     %
2640     % INPUTS:
2641     % FLAG : Can either be: 0, 1 or 2
2642     % 0: Outcrop field is surface potential density computed
2643     % from C1=SST and C2=SSS
2644     % 1: Outcrop field is surface potential density given by C1
2645     % 2: Outcrop field is SST and potential density is computed
2646     % from C1=SST and C2=SSS
2647     % C1,C2 : Depends on option FLAG:
2648     % - FLAG = 0 :
2649     % C1 : Sea surface temperature (degC)
2650     % C2 : Sea surface salinity (PSU)
2651     % - FLAG = 1 :
2652     % C1 : Surface potential density (kg/m3)
2653     % C2 : Not used
2654     % - FLAG = 2 :
2655     % C1 : Sea surface temperature (degC)
2656     % C2 : Sea surface salinity (PSU)
2657     % Qnet : Downward net surface heat flux (W/m2)
2658     % Snet : Downward net surface salt flux (kg/m2/s) ->
2659     % ie, Snet = rho*beta*SSS*(E-P)
2660     % Classes : Range of outcrops to explore (eg: [20:.1:30] for potential density)
2661     % lon,lat : axis
2662     % dA : Matrix of grid surface elements (m2) centered in (lon,lat)
2663     %
2664     %
2665     % OUTPUTS:
2666     % F(3,:) : Transformation rate (m3/s) (from 1:Qnet, 2:Snet and 3:Total)
2667     % A : Surface of each outcrops
2668     % D(3,:,:) : Maps of density flux (kg/m2/s) from 1:Qnet, 2:Snet and 3:Total
2669     % CROP(:,:) : Map of the surface field used to compute outcrop's contours
2670     %
2671     %
2672     % NOTES:
2673     % - Fields are of the format: C(LAT,LON)
2674     % - The potential density is computed with the equation of state routine from
2675     % the MITgcm called densjmd95.m
2676     % (see: http://mitgcm.org/cgi-bin/viewcvs.cgi/MITgcm_contrib/gmaze_pv/subfct/densjmd95.m)
2677     % - Snet may be filled of NaN if not available, its F component won't computed
2678     %
2679     %
2680     % AUTHOR:
2681     % Guillaume Maze / MIT 2006
2682     %
2683     % HISTORY:
2684     % - Revised: 06/28/2007
2685     % * Add option do directly give the pot. density as input
2686     % * Add options do take SST as outcrop
2687     % - Created: 06/22/2007
2688     %
2689     % REFERENCES:
2690     % Walin G. 1982: On the relation between sea-surface
2691     % heat flow and thermal circulation in the ocean. Tellus N24
2692     %
2693    
2694     % The routine is not optimized for speed but for clarity, that's why we
2695     % compute buoyancy fluxes, etc...
2696     %
2697     % TO DO:
2698     % - Fix signs in density fluxes to be correct albeit consistent with F right now
2699     % - Create options for non regular CLASS
2700     % - Create options to also compute the formation rate M
2701     % - Create options to compute an error bar
2702     % - Create check of inputs section
2703    
2704     function varargout = diagWALIN(FLAG,C1,C2,QNET,SNET,CLASS,lon,lat,dA);
2705    
2706    
2707    
2708     % 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PREPROC
2709     % Variables:
2710     nlat = size(C1,1);
2711     nlon = size(C1,2);
2712     CLASS = CLASS(:);
2713    
2714     % Determine surface fields from which we'll take outcrops contours:
2715     switch FLAG
2716    
2717     case {0,2} % Need to compute SIGMA THETA
2718     SST = C1;
2719     SSS = C2;
2720     ST = densjmd95(SSS,SST,zeros(nlat,nlon)) - 1000; % Real surface (depth = 0)
2721     %dpt = -5; ST = densjmd95(SSS,SST,(0.09998*9.81*dpt)*ones(nlat,nlon)) - 1000; % Model surface
2722     if FLAG == 0 % Outcrop is SIGMA THETA:
2723     OUTCROP = ST;
2724     elseif FLAG == 2 % Outcrop is SST:
2725     OUTCROP = SST;
2726     end
2727    
2728     case 1
2729     ST = C1; % Potential density
2730     OUTCROP = ST;
2731     end
2732    
2733     % Create a flag if we don't find salt flux:
2734     if length(find(isnan(SNET)==1)) == nlat*nlon
2735     do_ep = 0;
2736     else
2737     do_ep = 1;
2738     end
2739    
2740     % Physical constants:
2741     g = 9.81; % Gravity (m/s2)
2742     Cp = 3994; % Specific heat of sea water (J/K/kg)
2743     rho0 = 1035; % Density of reference (kg/m3)
2744     rho = ST+1000; % Density (kg/m3)
2745     % Thermal expansion coefficient (1/K)
2746     if exist('SST') & exist('SSS')
2747     alpha = sw_alpha(SSS,SST,zeros(nlat,nlon));
2748     else
2749     alpha = 2.*1e-4;
2750     end
2751    
2752    
2753     % 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BUOYANCY FLUX: b
2754     % The buoyancy flux (m/s2*m/s=m2/s3) is computed as:
2755     % b = g/rho*( alpha/Cp*QNET - SNET )
2756     % b = g/rho*alpha/Cp*QNET - g/rho*SNET
2757     % b = b_hf + b_ep
2758     % QNET the net heat flux (W/m2) and SNET the net salt flux (kg/m2/s)
2759     b_hf = g.*alpha./Cp.*QNET./rho;
2760     if do_ep==1, b_ep = -g*SNET./rho; else b_ep = zeros(nlat,nlon); end
2761     b = b_hf + do_ep*b_ep;
2762    
2763    
2764     % 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DENSITY FLUX: bd
2765     % Buoyancy flux is transformed into density flux (kg/m3*m/s = kg/m2/s):
2766     % bd = - rho/g * b
2767     % with b the buoyancy flux
2768     bd_hf = - rho/g.*b_hf;
2769     bd_ep = - rho/g.*b_ep;
2770     bd = - rho/g.*b;
2771    
2772    
2773     % 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NET MASS FLUX INTEGRATED OVER OUTCROPS: Bd
2774     % The amount of mass water flux over an outcrop is computed as:
2775     % Bd = SUM_ij bd(i,j)*dA(i,j)*MASK(i,j,OUTCROP)
2776     % with MASK(i,j,OUTCROP) = 1 where OUTCROP(i,j)-dC/2 <= OUTCROP(i,j) < OUTCROP(i,j)+dC/2
2777     % = 0 otherwise
2778     % Outcrops are defined with an increment of:
2779     dCROP = diff(CLASS(1:2));
2780    
2781     switch FLAG
2782     case {0,1}, coef = 1; % Potential density as outcrops
2783     case 2, coef = 1./(alpha.*rho0); % SST as outcrops
2784     end %switch
2785    
2786     % Surface integral:
2787     for iC = 1 : length(CLASS)
2788     CROPc = CLASS(iC);
2789     mask = zeros(nlat,nlon);
2790     mask(find( (CROPc-dCROP/2 <= OUTCROP) & (OUTCROP < CROPc+dCROP/2) )) = 1;
2791     Bd_hf(iC) = nansum(nansum(dA.*mask.*bd_hf.*coef,1),2);
2792     Bd_ep(iC) = nansum(nansum(dA.*mask.*bd_ep.*coef,1),2);
2793     Bd(iC) = nansum(nansum(dA.*mask.*bd.*coef,1),2);
2794     AA(iC) = nansum(nansum(dA.*mask,1),2);
2795     end %for iC
2796    
2797    
2798     % 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRANSFORMATION RATE: F
2799     % F is defined as the convergence/divergence of the integrated mass flux Bd.
2800     % F = Bd(CROP) / dCROP
2801     % where Bd is the mass flux over an outcrop.
2802     F_hf = Bd_hf./dCROP;
2803     F_ep = Bd_ep./dCROP;
2804     F = Bd./dCROP;
2805    
2806    
2807     % 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
2808     % Transformation rate:
2809     TRANSFORM_RATE(1,:) = F_hf;
2810     TRANSFORM_RATE(2,:) = F_ep;
2811     TRANSFORM_RATE(3,:) = F;
2812    
2813     % Density flux:
2814     DENSITY_FLUX(1,:,:) = bd_hf;
2815     DENSITY_FLUX(2,:,:) = bd_ep;
2816     DENSITY_FLUX(3,:,:) = bd;
2817    
2818     switch nargout
2819     case 1
2820     varargout(1) = {TRANSFORM_RATE};
2821     case 2
2822     varargout(1) = {TRANSFORM_RATE};
2823     varargout(2) = {AA};
2824     case 3
2825     varargout(1) = {TRANSFORM_RATE};
2826     varargout(2) = {AA};
2827     varargout(3) = {DENSITY_FLUX};
2828     case 4
2829     varargout(1) = {TRANSFORM_RATE};
2830     varargout(2) = {AA};
2831     varargout(3) = {DENSITY_FLUX};
2832     varargout(4) = {OUTCROP};
2833     end %switch
2834     gmaze_pv/eg_main_getPV.m0000644002352600001440000001111110557734746014614 0ustar gmazeusers%
2835     % THIS IS NOT A FUNCTION !
2836     %
2837     % Here is the main program to compute the potential vorticity Q
2838     % from the flow (UVEL,VVEL), potential temperature (THETA) and
2839     % salinity (SALTanom), given snapshot fields.
2840     % 3 steps to do it:
2841     % 1- compute the potential density SIGMATHETA (also called ST)
2842     % from THETA and SALTanom:
2843     % ST = SIGMA(S,THETA,p=0)
2844     % 2- compute the 3D relative vorticity field OMEGA (called O)
2845     % without vertical velocity terms:
2846     % O = ( -dVdz ; dUdz ; dVdx - dUdy )
2847     % 3- compute the potential vorticity Q:
2848     % Q = Ox.dSTdx + Oy.dSTdy + (f+Oz).dSTdz
2849     % (note that we only add the planetary vorticity at this last
2850     % step).
2851     % It's also possible to add a real last step 4 to compute PV as:
2852     % Q = -1/RHO * [Ox.dSTdx + Oy.dSTdy + (f+Oz).dSTdz]
2853     % Note that in this case, program loads the PV output from the
2854     % routine C_compute_potential_vorticity (step 3) and simply multiply
2855     % it by: -1/RHO.
2856     % RHO may be computed with the routine compute_density.m
2857     %
2858     %
2859     % Input files are supposed to be in a subdirectory called:
2860     % ./netcdf-files/<snapshot>/
2861     %
2862     % File names id are stored in global variables:
2863     % netcdf_UVEL, netcdf_VVEL, netcdf_THETA, netcdf_SALTanom
2864     % with the format:
2865     % netcdf_<ID>.<netcdf_domain>.<netcdf_suff>
2866     % where netcdf_domain and netcdf_suff are also in global
2867     % THE DOT IS ADDED IN SUB-PROG, SO AVOID IT IN DEFINITIONS
2868     %
2869     % Note that Q is not initialy defined with the ratio by -RHO.
2870     %
2871     % A simple potential vorticity (splQ) computing is also available.
2872     % It is defined as: splQ = f. dSIGMATHETA/dz
2873     %
2874     % 30Jan/2007
2875     % gmaze@mit.edu
2876     %
2877     clear
2878    
2879     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SETUP:
2880     pv_checkpath
2881    
2882    
2883     % File's name:
2884     global netcdf_UVEL netcdf_VVEL netcdf_THETA
2885     global netcdf_SALTanom is_SALTanom
2886     global netcdf_TAUX netcdf_TAUY netcdf_SIGMATHETA
2887     global netcdf_RHO netcdf_EKL netcdf_Qnet netcdf_MLD
2888     global netcdf_JFz netcdf_JBz
2889     global netcdf_suff netcdf_domain sla
2890     netcdf_UVEL = 'UVEL';
2891     netcdf_VVEL = 'VVEL';
2892     netcdf_THETA = 'THETA';
2893     netcdf_SALTanom = 'SALTanom'; is_SALTanom = 1;
2894     netcdf_TAUX = 'TAUX';
2895     netcdf_TAUY = 'TAUY';
2896     netcdf_SIGMATHETA = 'SIGMATHETA';
2897     netcdf_RHO = 'RHO';
2898     netcdf_EKL = 'EKL';
2899     netcdf_MLD = 'KPPmld'; %netcdf_MLD = 'MLD';
2900     netcdf_Qnet = 'TFLUX';
2901     netcdf_JFz = 'JFz';
2902     netcdf_JBz = 'JBz';
2903     netcdf_suff = 'nc';
2904     netcdf_domain = 'north_atlantic'; % Must not be empty !
2905    
2906    
2907    
2908     % FLAGS:
2909     % Turn 0/1 the following flag to determine which PV to compute:
2910     wantsplPV = 0; % (turn 1 for simple PV computing)
2911     % Turn 0/1 this flag to get online computing informations:
2912     global toshow
2913     toshow = 0;
2914    
2915     % Get date list:
2916     ll = dir(strcat('netcdf-files',sla));
2917     nt = 0;
2918     for il = 1 : size(ll,1)
2919     if ll(il).isdir & findstr(ll(il).name,'00')
2920     nt = nt + 1;
2921     list(nt).name = ll(il).name;
2922     end
2923     end
2924    
2925    
2926     %%%%%%%%%%%%%%%%%%%%%%%%%%%%% TIME LOOP
2927     for it = 1 : nt
2928     % Files are looked for in subdirectory defined by: ./netcdf-files/<snapshot>/
2929     snapshot = list(it).name;
2930     disp('********************************************************')
2931     disp('********************************************************')
2932     disp(snapshot)
2933     disp('********************************************************')
2934     disp('********************************************************')
2935    
2936    
2937     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMPUTING PV:
2938     % STEP 1:
2939     % Output netcdf file is:
2940     % ./netcdf-files/<snapshot>/SIGMATHETA.<netcdf_domain>.<netcdf_suff>
2941     A_compute_potential_density(snapshot)
2942     compute_density(snapshot)
2943    
2944    
2945     % STEP 2:
2946     % Output netcdf files are:
2947     % ./netcdf-files/<snapshot>/OMEGAX.<netcdf_domain>.<netcdf_suff>
2948     % ./netcdf-files/<snapshot>/OMEGAY.<netcdf_domain>.<netcdf_suff>
2949     % ./netcdf-files/<snapshot>/ZETA.<netcdf_domain>.<netcdf_suff>
2950     % No interest for the a splPV computing
2951     if ~wantsplPV
2952     B_compute_relative_vorticity(snapshot)
2953     end %if
2954    
2955     % STEP 3:
2956     % Output netcdf file is:
2957     % ./netcdf-files/<snapshot>/PV.<netcdf_domain>.<netcdf_suff>
2958     C_compute_potential_vorticity(snapshot,wantsplPV)
2959    
2960     % STEP 4:
2961     % Output netcdf file is (replace last one):
2962     % ./netcdf-files/<snapshot>/PV.<netcdf_domain>.<netcdf_suff>
2963     global netcdf_PV
2964     if wantsplPV == 1
2965     netcdf_PV = 'splPV';
2966     else
2967     netcdf_PV = 'PV';
2968     end %if
2969     D_compute_potential_vorticity(snapshot,wantsplPV)
2970    
2971    
2972     % OTHER computations:
2973     if 0
2974     compute_alpha(snapshot)
2975     compute_MLD(snapshot)
2976     compute_EKL(snapshot)
2977     compute_JFz(snapshot);
2978     compute_JBz(snapshot);
2979     compute_Qek(snapshot);
2980     end %if 1/0
2981    
2982    
2983     fclose('all');
2984     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% THAT'S IT !
2985     end %for it
2986    
2987    
2988     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% THAT'S IT !
2989    
2990     % Keep clean workspace:
2991     clear wantsplPV toshow netcdf_*
2992     clear global wantsplPV toshow netcdf_*
2993     gmaze_pv/eg_write_bin2cdf_csgrid_subdomain.m0000644002352600001440000001707310557736662020714 0ustar gmazeusers% Script to extract a subdomain from a CS510 simulation
2994     % and write in netCDF format on a regular lat/lon grid (1/4)
2995     %
2996     clear
2997     global sla
2998     pv_checkpath
2999    
3000    
3001     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Global setup:
3002     % Restrict global domain to:
3003     subdomain = 3; % North Atlantic
3004    
3005     % Path to find input binary Cube sphere files:
3006     pathi = './bin_cube49';
3007    
3008     % Path where the netcdf outputs will be stored:
3009     patho = './ecco2_cube49_netcdf';
3010     patho = strcat(patho,sla,'monthly');
3011     %patho = strcat(patho,sla,'six_hourly');
3012    
3013     % Time step (for date conversion):
3014     dt = 1200;
3015    
3016     % Variables to analyse (index into otab):
3017     otab = cs510grid_outputs_table; % from the 1/8 latlon definition
3018     wvar = [];
3019     dimen = 3;
3020     switch dimen
3021     case 3 % 3D fields:
3022     %wvar = [wvar 34]; % THETA
3023     %wvar = [wvar 31]; % RHOAnoma
3024     %wvar = [wvar 33]; % SALTanom
3025     case 2 % 2D fields:
3026     wvar = [wvar 23]; % TFLUX
3027     %wvar = [wvar 20]; % SST
3028     %wvar = [wvar 19]; % SSS
3029     end %switch number of dimensions
3030    
3031     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Pre-process
3032     % Get the grid:
3033     path_grid = './grid';
3034     XC = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'XC')),1,'float32');
3035     YC = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'YC')),1,'float32');
3036     XG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'XG')),1,'float32');
3037     YG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'YG')),1,'float32');
3038     GRID_125;
3039     ZC = - [0 cumsum(thk125(1:length(thk125)-1))];
3040     clear dpt125 lat125 lon125 thk125
3041    
3042     % How to move to a lat/lon grid:
3043     % CS510 is about 22km average resolution, ie: 1/4 degree
3044     XI = -180 : 1/4 : 180;
3045     YI = -90 : 1/4 : 90;
3046     ZI = ZC;
3047     if ~exist('CS510_to_LATLON025.mat','file')
3048     del = cube2latlon_preprocess(XC,YC,XI,YI);
3049     save('CS510_to_LATLON025.mat','XI','YI','XC','YC','del','-v6');
3050     else
3051     load('CS510_to_LATLON025.mat')
3052     end
3053    
3054     % Set subrange - Longitude given as degrees east
3055     % (exact values come from the 1/8 lat-lon grid)
3056     switch subdomain
3057     case 3
3058     sub_name = 'north_atlantic';
3059     lonmin = 276.0625;
3060     lonmax = 359.9375;
3061     latmin = 12.0975;
3062     latmax = 53.2011;
3063     depmin = 1; % !!! indices
3064     depmax = 29; % !!! indices
3065     if dimen == 3, depmax = 29,
3066     else, depmax = 1;end
3067     LIMITS = [lonmin lonmax latmin latmax depmin depmax]
3068     if 0
3069     m_proj('mercator','long',[270 365],'lat',[0 60]);
3070     clf;hold on;m_coast;m_grid;
3071     m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','k','linewidth',2);
3072     title(sub_name);
3073     end %if 1/0
3074     end
3075    
3076     % Get subdomain horizontal axis:
3077     xi = XI(max(find(XI<=LIMITS(1))):max(find(XI<=LIMITS(2))));
3078     yi = YI(max(find(YI<=LIMITS(3))):max(find(YI<=LIMITS(4))));
3079     zi = ZI(LIMITS(5):LIMITS(6));
3080    
3081     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3082     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop over variables to read
3083     for i = 1 : length(wvar)
3084     ifield = wvar(i);
3085     fil = otab{ifield,1};
3086    
3087     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%
3088     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Get info over the time loop
3089     % Get the file list:
3090     fild = fil; % Insert condition here for special files:
3091     if ifield == 23 & findstr(patho,'six')
3092     fild = 'surForcT';
3093     fil = 'surForcT';
3094     end
3095     l = dir(strcat(pathi,sla,fild));
3096     it = 0;
3097     clear ll
3098     for il = 1 : size(l,1)
3099     if ~l(il).isdir & findstr(l(il).name,strcat(fil,'.')) % is'it the file type we want ?
3100     it = it + 1;
3101     ll(it).name = l(il).name;
3102     end %if
3103     end %for il
3104     % Create the timetable:
3105     for il = 1 : size(ll,2)
3106     filin = ll(il).name;
3107     % Now extract the stepnum from : %s.%10.10d.data
3108     ic = findstr(filin,fil)+length(fil)+1; i = 1; clear stepnum
3109     while filin(ic) ~= '.'
3110     stepnum(i) = filin(ic); i = i + 1; ic = ic + 1;
3111     end
3112     ID = str2num(stepnum);
3113     TIME(il,:) = datestr(datenum(1992,1,1)+ID*dt/60/60/24,'yyyymmddHHMM');
3114     end
3115     nt = size(TIME,1);
3116    
3117     % %%%%%%%%%%%%%%%
3118     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop over time
3119     for it = 1 : nt
3120     snapshot = TIME(it,:);
3121     ID = 60*60*24/dt*( datenum(snapshot,'yyyymmddHHMM') - datenum(1992,1,1) );
3122     filin = ll(it).name;
3123     disp('')
3124     disp(strcat('Processing: ',fil,'//',snapshot))
3125     dirout = strcat(patho,sla,TIME(it,:),sla);
3126     filout = sprintf('%s.%s.nc',otab{ifield,1},sub_name);
3127    
3128     if ~exist(strcat(dirout,sla,filout),'file') % File already exists ?
3129    
3130     %%%% READ THE FILE
3131     switch otab{ifield,6}
3132     case 4, flt = 'float32';
3133     case 8, flt = 'float64';
3134     end
3135     t0 = clock;
3136     if findstr(filin,'.gz') % Gunzip file, special care !
3137     disp('|----> Find a file with gz extension, work on uncompressed file ...')
3138    
3139     % 1: copy the filename with it path into gunzip_1_file.txt
3140     fid1 = fopen('gunzip_1_file.txt','w');
3141     fprintf(fid1,'%s',strcat(pathi,sla,fild,sla,filin));fclose(fid1);
3142    
3143     % 2: uncompress the file into a temporary folder:
3144     disp('|------> uncompressing the file ...')
3145     ! ./gunzip_1_file.bat
3146     disp(strcat('|--------: ',num2str(etime(t0,clock))))
3147    
3148     % 3: Read the uncompress file:
3149     disp('|--> reading it ...')
3150     C = readrec_cs510(strcat('gunzip_1_file',sla,'tempo.data'),LIMITS(6),flt);
3151     disp(strcat('|----: ',num2str(etime(t0,clock))))
3152    
3153     % 4: Suppress it
3154     ! \rm ./gunzip_1_file/tempo.data
3155    
3156     else % Simply read the file:
3157     disp('|--> reading it ...')
3158     C = readrec_cs510(strcat(pathi,sla,fild,sla,filin),LIMITS(6),flt);
3159     disp(strcat('|----: ',num2str(etime(t0,clock))))
3160     end
3161    
3162     %%%% RESTRICT TO SUBDOMAIN
3163     disp('|--> get subdomain ...')
3164     % Restrict vertical to subdomain:
3165     if LIMITS(5) ~= 1
3166     disp('|----> vertical ...');
3167     C = C(:,:,LIMITS(5):end);
3168     end
3169     % Clean the field:
3170     C(find(C==0)) = NaN;
3171     % Move the field into lat/lon grid:
3172     disp('|----> Move to lat/lon grid ...');
3173     C = cube2latlon_fast(del,C);
3174     % And then restrict horizontal to subdomain:
3175     disp('|----> horizontal ...');
3176     C = C(max(find(XI<=LIMITS(1))):max(find(XI<=LIMITS(2))),...
3177     max(find(YI<=LIMITS(3))):max(find(YI<=LIMITS(4))),:);
3178    
3179    
3180     %%%% RECORD
3181     disp('|--> record netcdf file ...')
3182     fid1 = fopen('inprogress.txt','w');
3183     fprintf(fid1,'%s',strcat(dirout,sla,filout));fclose(fid1);
3184    
3185     if 1 % Realy want to record ?
3186    
3187     if ~exist(dirout,'dir')
3188     mkdir(dirout);
3189     end
3190    
3191    
3192     nc = netcdf('inprogress.nc','clobber');
3193    
3194     nc('X') = length(xi);
3195     nc('Y') = length(yi);
3196     nc('Z') = length(zi);
3197    
3198     nc{'X'}='X';
3199     nc{'Y'}='Y';
3200     nc{'Z'}='Z';
3201    
3202     nc{'X'}.uniquename='X';
3203     nc{'X'}.long_name='longitude';
3204     nc{'X'}.gridtype=ncint(0);
3205     nc{'X'}.units='degrees_east';
3206     nc{'X'}(:) = xi;
3207    
3208     nc{'Y'}.uniquename='Y';
3209     nc{'Y'}.long_name='latitude';
3210     nc{'Y'}.gridtype=ncint(0);
3211     nc{'Y'}.units='degrees_north';
3212     nc{'Y'}(:) = yi;
3213    
3214     nc{'Z'}.uniquename='Z';
3215     nc{'Z'}.long_name='depth';
3216     nc{'Z'}.gridtype=ncint(0);
3217     nc{'Z'}.units='m';
3218     nc{'Z'}(:) = zi;
3219    
3220     ncid = fil;
3221     nc{ncid}={'Z' 'Y' 'X'};
3222     nc{ncid}.missing_value = ncdouble(NaN);
3223     nc{ncid}.FillValue_ = ncdouble(0.0);
3224     nc{ncid}(:,:,:) = permute(C,[3 2 1]);
3225     nc{ncid}.units = otab{ifield,5};
3226    
3227     close(nc);
3228     ! ./inprogress.bat
3229    
3230     end %if 1/0 want to record ?
3231     disp(strcat('|--: ',num2str(etime(t0,clock))))
3232    
3233     else
3234     disp(strcat('|--> Skip file (already done):',dirout,sla,filout))
3235     end %if %file exist
3236    
3237     end %for it
3238     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END Loop over time
3239     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3240    
3241     end %if it
3242     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END Loop over variables to read
3243     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3244     gmaze_pv/eg_write_bin2cdf_latlongrid_subdomain.m0000644002352600001440000001147010557736437021573 0ustar gmazeusers% Script to extract and write in netCDF format a subdomain
3245     % from the 1.8 global run
3246     %
3247     clear
3248     global sla
3249     pv_checkpath
3250    
3251     % Load grid
3252     GRID_125
3253    
3254     % Load list of all outputs
3255     otab = latlon8grid_outputs_table;
3256    
3257     % Setup standard grid variables
3258     lon_c = lon125;
3259     lon_u = [lon125(1)-360+lon125(end) (lon125(2:end)+lon125(1:end-1))/2];
3260     lat_c = lat125;
3261     lat_v = [lat125(1)-(lat125(2)-lat125(1))/2 (lat125(1:end-1)+lat125(2:end))/2];
3262     z_c = (cumsum(thk125)-thk125/2);
3263     z_w = [0 cumsum(thk125(1:end-1))];
3264    
3265    
3266     % Set subrange - Longitude given as degrees east
3267     subdomain = 4;
3268    
3269     switch subdomain
3270     case 1
3271     sub_name = 'western_north_atlantic';
3272     lonmin = lon125(2209)-180;
3273     lonmax = lon125(2497-1)-180;
3274     latmin = lat125(1225);
3275     latmax = lat125(1497-1);
3276     depmin = min(z_w);
3277     depmax = z_c(29);
3278     m_proj('mercator','long',[270 365],'lat',[0 60]);
3279     %clf;hold on;m_coast;m_grid;
3280     LIMITS = [lonmin+180 lonmax+180 latmin latmax depmin depmax]
3281     %m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','r','linewidth',2);
3282     %title(sub_name);
3283    
3284     case 3
3285     sub_name = 'north_atlantic';
3286     lonmin = lon125(2209)-180;
3287     lonmax = lon125(2881-1)-180;
3288     latmin = lat125(1157);
3289     latmax = lat125(1565-1);
3290     depmin = min(z_w);
3291     depmax = z_c(29);
3292     m_proj('mercator','long',[270 365],'lat',[0 60]);
3293     clf;hold on;m_coast;m_grid;
3294     LIMITS = [lonmin+180 lonmax+180 latmin latmax depmin depmax]
3295     m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','k','linewidth',2);
3296     title(sub_name);
3297    
3298     case 4
3299     sub_name = 'global';
3300     lonmin = lon125(1)-180;
3301     lonmax = lon125(2881-1)-180;
3302     latmin = lat125(1);
3303     latmax = lat125(2177-1);
3304     depmin = min(z_w);
3305     depmax = z_c(29); depmax = z_w(2);
3306     m_proj('mercator','long',[0 360],'lat',[-90 90]);
3307     clf;hold on;m_coast;m_grid;
3308     LIMITS = [lonmin+180 lonmax+180 latmin latmax depmin depmax]
3309     m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','k','linewidth',2);
3310     title(sub_name);
3311    
3312    
3313     case 10
3314     sub_name = 'KE';
3315     lonmin = lon125(961)-180;
3316     lonmax = lon125(1601-1)-180;
3317     latmin = lat125(1140);
3318     latmax = lat125(1523-1);
3319     depmin = min(z_w);
3320     depmax = z_c(25);
3321     m_proj('mercator','long',[0 360],'lat',[-90 90]);
3322     %clf;hold on;m_coast;m_grid;
3323     LIMITS = [lonmin+180 lonmax+180 latmin latmax depmin depmax]
3324     %m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','k','linewidth',2);
3325     %title(sub_name);
3326    
3327    
3328     end
3329    
3330     %refresh
3331    
3332     % Path of the directory to find input binary files:
3333     pathi = 'ecco2_cycle1_bin/';
3334    
3335     % Path where the netcdf outputs will be stored:
3336     patho = './ecco2_cycle1_netcdf/monthly/';
3337     %patho = './ecco2_cycle1_netcdf/six_hourly/';
3338    
3339     % Variables to analyse (index into otab):
3340     wvar = [];
3341     % 3D fields:
3342     wvar = [wvar 34]; % THETA
3343     wvar = [wvar 35]; % THETASQ
3344     %wvar = [wvar 33]; % SALTanom
3345     %wvar = [wvar 47]; % VVEL
3346     %wvar = [wvar 31]; % RHOAnoma
3347    
3348    
3349    
3350     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3351     for i = 1 : length(wvar)
3352     ifield = wvar(i);
3353     fil = otab{ifield,1};
3354     l = dir(strcat(pathi,fil,sla));
3355     if ifield == 33,
3356     l = dir(strcat(pathi,'SALT',sla));
3357     end
3358     if ifield == 35,
3359     l = dir(strcat(pathi,'THETA',sla));
3360     end
3361     if ifield == 31,
3362     l = dir(strcat(pathi,'RHO',sla));
3363     end
3364     it = 0;
3365     clear ll
3366     for il = 1 : size(l,1)
3367     if ~l(il).isdir & findstr(l(il).name,strcat(fil,'.')) % is'it the file type we want ?
3368     it = it + 1;
3369     ll(it).name = l(il).name;
3370     end %if
3371     end %for il
3372    
3373     if it ~= 0 % if we found any files to compute:
3374    
3375     % Create the timetable:
3376     for il = 1 : size(ll,2)
3377     filinprog = ll(il).name;
3378     stepnum=str2num(filinprog(findstr(filinprog,fil)+length(fil)+1:length(filinprog)- ...
3379     length('.data')));
3380     TIME(il,:) = dtecco2(stepnum,0);
3381     end
3382    
3383     % Translate files:
3384     for il = 1 : size(ll,2)
3385    
3386     filinprog = ll(il).name;
3387     stepnum=str2num(filinprog(findstr(filinprog,fil)+length(fil)+1:length(filinprog)- ...
3388     length('.data')));
3389     ID = datenum(1992,1,1)+stepnum*300/60/60/24;
3390     dte = datestr(ID,'yyyymmddHHMM');
3391     disp(strcat(fil,'->',datestr(ID,'yyyy/mm/dd/HH:MM'),'== Recorded in ==>',TIME(il,:)));
3392     dirout = strcat(patho,sla,TIME(il,:));
3393    
3394     if 1 % Want to record ?
3395     if ~exist(dirout,'dir')
3396     mkdir(dirout);
3397     end
3398     pathname = strcat(pathi,fil,sla);
3399     if ifield == 33,
3400     pathname = strcat(pathi,'SALT',sla);
3401     end
3402     if ifield == 35,
3403     pathname = strcat(pathi,'THETA',sla);
3404     end
3405     if ifield == 31,
3406     pathname = strcat(pathi,'RHO',sla);
3407     end
3408     if ~exist(strcat(dirout,sla,sprintf('%s.%s.nc',otab{ifield,1},sub_name)),'file')
3409     %if 1
3410     latlon2ingrid_netcdf(pathname,strcat(dirout,sla),...
3411     stepnum,otab{ifield,1},otab, ...
3412     lon_c, lon_u, ...
3413     lat_c, lat_v, ...
3414     z_c, z_w, ...
3415     sub_name, ...
3416     lonmin,lonmax,latmin,latmax,depmin,depmax);
3417     else
3418     disp(strcat('##### Skip file (already done):',dirout,sla,...
3419     sprintf('%s.%s.nc',otab{ifield,1},sub_name)))
3420     end %if %file exist
3421    
3422     end %if 1/0 want to record ?
3423     % if il==1,break,end;
3424    
3425     fclose('all');
3426    
3427     end %for il
3428    
3429     end %if it
3430    
3431     end %for i
3432     gmaze_pv/eg_write_UVbin2cdf_csgrid_subdomain.m0000644002352600001440000002100210557737072021146 0ustar gmazeusers% Script to extract a subdomain from a CS510 simulation
3433     % and write in netCDF format on a regular lat/lon grid (1/4)
3434     % SPECIAL U V FIELDS !!
3435     %
3436     clear
3437     global sla
3438     pv_checkpath
3439    
3440    
3441     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Global setup:
3442     % Restrict global domain to:
3443     subdomain = 3; % North Atlantic
3444    
3445     % Path to find input binary Cube sphere files:
3446     pathi = './bin_cube49';
3447    
3448     % Path where the netcdf outputs will be stored:
3449     patho = './ecco2_cube49_netcdf';
3450     patho = strcat(patho,sla,'monthly');
3451     %patho = strcat(patho,sla,'six_hourly');
3452    
3453     % Time step (for date conversion):
3454     dt = 1200;
3455    
3456     % Variables to analyse (index into otab):
3457     otab = cs510grid_outputs_table; % from the 1/8 latlon definition
3458     wvar = [];
3459     dimen = 3;
3460     switch dimen
3461     case 3 % 3D fields:
3462     wvar = [wvar 39]; % UVEL
3463     wvar = [wvar 47]; % VVEL
3464     case 2 % 2D fields:
3465     end %switch number of dimensions
3466    
3467     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Pre-process
3468     % Get the grid:
3469     path_grid = './grid';
3470     XC = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'XC')),1,'float32');
3471     YC = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'YC')),1,'float32');
3472     XG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'XG')),1,'float32');
3473     YG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'YG')),1,'float32');
3474     dxG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'DXG')),1,'float32');
3475     dyG = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'DYG')),1,'float32');
3476     RAC = readrec_cs510(sprintf('%s.data',strcat(path_grid,sla,'RAC')),1,'float32');
3477     GRID_125;
3478     ZC = - [0 cumsum(thk125(1:length(thk125)-1))];
3479     clear dpt125 lat125 lon125 thk125
3480    
3481     % How to move to a lat/lon grid:
3482     % CS510 is about 22km average resolution, ie: 1/4 degree
3483     XI = -180 : 1/4 : 180;
3484     YI = -90 : 1/4 : 90;
3485     ZI = ZC;
3486     if ~exist('CS510_to_LATLON025.mat','file')
3487     del = cube2latlon_preprocess(XC,YC,XI,YI);
3488     save('CS510_to_LATLON025.mat','XI','YI','XC','YC','del','-v6');
3489     else
3490     load('CS510_to_LATLON025.mat')
3491     end
3492    
3493     % Set subrange - Longitude given as degrees east
3494     % (exact values come from the 1/8 lat-lon grid)
3495     switch subdomain
3496     case 3
3497     sub_name = 'north_atlantic';
3498     lonmin = 276.0625;
3499     lonmax = 359.9375;
3500     latmin = 12.0975;
3501     latmax = 53.2011;
3502     depmin = 1; % !!! indices
3503     depmax = 29; % !!! indices
3504     if dimen == 3, depmax = 29;
3505     else, depmax = 1;end
3506     LIMITS = [lonmin lonmax latmin latmax depmin depmax]
3507     if 0
3508     m_proj('mercator','long',[270 365],'lat',[0 60]);
3509     clf;hold on;m_coast;m_grid;
3510     m_line(LIMITS([1 2 2 1 1]),LIMITS([3 3 4 4 3]),'color','k','linewidth',2);
3511     title(sub_name);
3512     end %if 1/0
3513     end
3514    
3515     % Get subdomain horizontal axis:
3516     xi = XI(max(find(XI<=LIMITS(1))):max(find(XI<=LIMITS(2))));
3517     yi = YI(max(find(YI<=LIMITS(3))):max(find(YI<=LIMITS(4))));
3518     zi = ZI(LIMITS(5):LIMITS(6));
3519    
3520     filU = otab{39,1}; ifield = 39;
3521     filV = otab{47,1};
3522    
3523     % %%%%%%%%%%%%%%%%%%%%%%%%%%%%
3524     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Get info over the time loop
3525     % Get the file list:
3526     fildU = filU; % Insert condition here for special files:
3527     lU = dir(strcat(pathi,sla,fildU));
3528     fildV = filV; % Insert condition here for special files:
3529     lV = dir(strcat(pathi,sla,fildV));
3530    
3531     % Get the U files list:
3532     it = 0;
3533     clear ll
3534     for il = 1 : size(lU,1)
3535     if ~lU(il).isdir & ...
3536     findstr(lU(il).name,strcat(filU,'.')) % is'it the file type we want ?
3537     it = it + 1;
3538     ll(it).name = lU(il).name;
3539     end %if
3540     end %for il
3541     % Create the timetable of U:
3542     for il = 1 : size(ll,2)
3543     filin = ll(il).name;
3544     % Now extract the stepnum from : %s.%10.10d.data
3545     ic = findstr(filin,filU)+length(filU)+1; i = 1; clear stepnum
3546     while filin(ic) ~= '.'
3547     stepnum(i) = filin(ic); i = i + 1; ic = ic + 1;
3548     end
3549     ID = str2num(stepnum);
3550     TIME(il,:) = datestr(datenum(1992,1,1)+ID*dt/60/60/24,'yyyymmddHHMM');
3551     end
3552     nt = size(TIME,1);
3553    
3554     % Then we check if we have V when we have U:
3555     for it = 1 : nt
3556     snapshot = TIME(it,:);
3557     filUs = ll(it).name;
3558     filVs = strcat(filV,filUs(findstr(filUs,filU)+length(filU):end));
3559     if ~exist(strcat(pathi,sla,fildV,sla,filVs),'file')
3560     TIME(it,:) = NaN;
3561     end
3562     end
3563     itt = 0;
3564     for it = 1 : nt
3565     if find(isnan(TIME(it,:))==0)
3566     itt = itt + 1;
3567     TI(itt,:) = TIME(it,:);
3568     end
3569     end
3570     TIME = TI; clear TI
3571     nt = size(TIME,1);
3572    
3573    
3574     % %%%%%%%%%%%%%%%
3575     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop over time
3576     for it = 1 : nt
3577     snapshot = TIME(it,:);
3578     ID = 60*60*24/dt*( datenum(snapshot,'yyyymmddHHMM') - datenum(1992,1,1) );
3579     filin = ll(it).name;
3580     disp('')
3581     disp(strcat('Processing: ',num2str(ID),'//',snapshot))
3582     dirout = strcat(patho,sla,TIME(it,:),sla);
3583     filUout = sprintf('%s.%s.nc',filU,sub_name);
3584     filVout = sprintf('%s.%s.nc',filV,sub_name);
3585    
3586     if ~exist(strcat(dirout,sla,filUout),'file') % File already exists ?
3587    
3588     %%%% READ FILES U AND V
3589     switch otab{ifield,6}
3590     case 4, flt = 'float32';
3591     case 8, flt = 'float64';
3592     end
3593     t0 = clock;
3594     for iC = 1 : 2
3595     if iC == 1, fild = fildU; end
3596     if iC == 2, fild = fildV; filin = strcat(filV,filin(findstr(filin,filU)+length(filU):end)); end
3597     if findstr(filin,'.gz') % Gunzip file, special care !
3598     disp('|----> Find a file with gz extension, work on uncompressed file ...')
3599    
3600     % 1: copy the filename with it path into gunzip_1_file.txt
3601     fid1 = fopen('gunzip_1_file.txt','w');
3602     fprintf(fid1,'%s',strcat(pathi,sla,fild,sla,filin));fclose(fid1);
3603    
3604     % 2: uncompress the file into a temporary folder:
3605     disp('|------> uncompressing the file ...')
3606     ! ./gunzip_1_file.bat
3607     disp(strcat('|--------: ',num2str(etime(t0,clock))))
3608    
3609     % 3: Read the uncompress file:
3610     disp('|--> reading it ...')
3611     C = readrec_cs510(strcat('gunzip_1_file',sla,'tempo.data'),LIMITS(6),flt);
3612     disp(strcat('|----: ',num2str(etime(t0,clock))))
3613    
3614     % 4: Suppress it
3615     ! \rm ./gunzip_1_file/tempo.data
3616    
3617     else % Simply read the file:
3618     disp('|--> reading it ...')
3619     C = readrec_cs510(strcat(pathi,sla,fild,sla,filin),LIMITS(6),flt);
3620     disp(strcat('|----: ',num2str(etime(t0,clock))))
3621     end
3622     if iC == 1, CU = C; end
3623     if iC == 2, CV = C; end
3624     end %for iC
3625     clear C
3626    
3627     %%%% RESTRICT TO SUBDOMAIN
3628     disp('|--> get subdomain ...')
3629     % Restrict vertical to subdomain:
3630     if LIMITS(5) ~= 1
3631     disp('|----> vertical ...');
3632     CU = CU(:,:,LIMITS(5):end);
3633     CV = CV(:,:,LIMITS(5):end);
3634     end
3635     % Clean the field:
3636     CU(find(CU==0)) = NaN;
3637     CV(find(CV==0)) = NaN;
3638     % Move the field into lat/lon grid:
3639     disp('|----> Move to lat/lon grid ...');
3640     [CU CV] = uvcube2latlon_fast3(del,CU,CV,XG,YG,RAC,dxG,dyG);
3641    
3642     % And then restrict horizontal to subdomain:
3643     disp('|----> horizontal ...');
3644     CU = CU(max(find(XI<=LIMITS(1))):max(find(XI<=LIMITS(2))),...
3645     max(find(YI<=LIMITS(3))):max(find(YI<=LIMITS(4))),:);
3646     CV = CV(max(find(XI<=LIMITS(1))):max(find(XI<=LIMITS(2))),...
3647     max(find(YI<=LIMITS(3))):max(find(YI<=LIMITS(4))),:);
3648    
3649    
3650     %%%% RECORD
3651     disp('|--> record netcdf file ...')
3652    
3653     if 1 % Realy want to record ?
3654    
3655     if ~exist(dirout,'dir')
3656     mkdir(dirout);
3657     end
3658    
3659     for iC = 1 : 2
3660     if iC==1, ifield=39; C = CU; fil = filU; filout = filUout; end
3661     if iC==2, ifield=47; C = CV; fil = filV; filout = filVout; end
3662     fid1 = fopen('inprogress.txt','w');
3663     fprintf(fid1,'%s',strcat(dirout,sla,filout));fclose(fid1);
3664    
3665     nc = netcdf('inprogress.nc','clobber');
3666    
3667     nc('X') = length(xi);
3668     nc('Y') = length(yi);
3669     nc('Z') = length(zi);
3670    
3671     nc{'X'}='X';
3672     nc{'Y'}='Y';
3673     nc{'Z'}='Z';
3674    
3675     nc{'X'}.uniquename='X';
3676     nc{'X'}.long_name='longitude';
3677     nc{'X'}.gridtype=ncint(0);
3678     nc{'X'}.units='degrees_east';
3679     nc{'X'}(:) = xi;
3680    
3681     nc{'Y'}.uniquename='Y';
3682     nc{'Y'}.long_name='latitude';
3683     nc{'Y'}.gridtype=ncint(0);
3684     nc{'Y'}.units='degrees_north';
3685     nc{'Y'}(:) = yi;
3686    
3687     nc{'Z'}.uniquename='Z';
3688     nc{'Z'}.long_name='depth';
3689     nc{'Z'}.gridtype=ncint(0);
3690     nc{'Z'}.units='m';
3691     nc{'Z'}(:) = zi;
3692    
3693     ncid = fil;
3694     nc{ncid}={'Z' 'Y' 'X'};
3695     nc{ncid}.missing_value = ncdouble(NaN);
3696     nc{ncid}.FillValue_ = ncdouble(0.0);
3697     nc{ncid}(:,:,:) = permute(C,[3 2 1]);
3698     nc{ncid}.units = otab{ifield,5};
3699    
3700     close(nc);
3701     ! ./inprogress.bat
3702    
3703     end %if 1/0 want to record ?
3704     disp(strcat('|--: ',num2str(etime(t0,clock))))
3705    
3706     else
3707     disp(strcat('|--> Skip file (already done):',dirout,sla,filout))
3708     end %if %file exist
3709    
3710    
3711     end %for iC
3712    
3713     end %for it
3714     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END Loop over time
3715     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3716    
3717     gmaze_pv/pv_checkpath.m0000644002352600001440000000143010650154657014541 0ustar gmazeusers%
3718     % [] = pv_checkpath()
3719     %
3720     % This function detects where the package gmaze_pv is installed
3721     % (the upper level directory where the function volbet2iso
3722     % is found) and ensure that sub-directories are in the path
3723     %
3724    
3725     function [] = pv_checkpath()
3726    
3727     % Windows/Linux compatibility
3728     global sla
3729     sla = '/';
3730     if ispc , sla = '\'; end
3731    
3732    
3733     % Determine the directory name where the package is installed:
3734     fct_to_find = 'pv_checkpath';
3735     w = which(fct_to_find);
3736     packdir = w(1:length(w)-(length(fct_to_find)+2));
3737    
3738    
3739     % Try to found needed subdirectories:
3740    
3741     subdir = struct('name',{'subfct','test','visu','subduc'});
3742    
3743     for id = 1 : size(subdir(:),1)
3744     subdirname = subdir(id).name;
3745     fullsubdir = strcat(packdir,sla,subdirname);
3746     if isempty(findstr(path,fullsubdir))
3747     addpath(fullsubdir)
3748     end %if
3749     end %for
3750     gmaze_pv/outofdate/intbet2outcrops.m0000644002352600001440000000536610444547756017265 0ustar gmazeusers%
3751     % I = intbet2outcrops(TRACER,LIMITS,LAT,LONG)
3752     %
3753     % This function computes the horizontal surface integral between two
3754     % outcrops of the TRACER field, given fixed limits eastward, westward
3755     % and southward.
3756     %
3757     % TRACER = TRACER(LAT,LONG) : surface tracer variable in 2D
3758     % LIMITS = [OUTCROP1 OUTCROP2 MAX_LAT1 MAX_LAT2 MAX_LONG1 MAX_LONG2]
3759     % : limit's values (MAX_LAT2 is used only if
3760     % the outcrop's surfaces reach them).
3761     % LAT : latitude axis (1D), degrees northward
3762     % LONG : longitude axis (1D), degrees east
3763     % I : single surface integral value
3764     %
3765     % 06/15/2006
3766     % gmaze@mit.edu
3767     %
3768    
3769    
3770     function varargout = intbet2outcrops(TRACER,LIMITS,LAT,LONG)
3771    
3772    
3773     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3774     % PRE-PROCESS and ERROR CHECK %
3775     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3776     pv_checkpath
3777    
3778     % Check number of input:
3779     if nargin ~= 4
3780     help intbet2outcrops.m
3781     error('intbet2outcrops.m : Wrong number of parameters')
3782     return
3783     end %if
3784    
3785     % Check dimensions:
3786     n = size(TRACER);
3787     if length(n)==2
3788     [ny nx] = size(TRACER);
3789     if ny~=length(LAT) | nx~=length(LONG)
3790     help intbet2outcrops.m
3791     error('intbet2outcrops.m : Axis must have same dimensions than TRACER field');
3792     return
3793     end %if
3794     else
3795     help intbet2outcrops.m
3796     error('intbet2outcrops.m : TRACER must be a 2D field')
3797     return
3798     end %if
3799    
3800     % Ensure that axis are of dim: (1,N) and well sorted (increasing values):
3801     a=size(LAT);
3802     if a(1) ~= 1, LAT=LAT'; end
3803     S = sort(LAT);
3804     if S ~= LAT
3805     help intbet2outcrops.m
3806     error('intbet2outcrops.m : LAT must be increasing values')
3807     return
3808     end %if
3809     a=size(LONG);
3810     if a(1) ~= 1, LONG=LONG'; end
3811     S = sort(LONG);
3812     if S ~= LONG
3813     help intbet2outcrops.m
3814     error('intbet2outcrops.m : LONG must be increasing values')
3815     return
3816     end %if
3817    
3818     % LIMITS definition:
3819     if length(LIMITS) ~= 6
3820     help intbet2outcrops.m
3821     error('intbet2outcrops.m : LIMITS must contains 6 values')
3822     return
3823     end %if
3824     OUTCROPS = sort( LIMITS(1:2) );
3825     LAT_MAX = sort( LIMITS(3:4) );
3826     LONG_MAX = sort( LIMITS(5:6) );
3827    
3828    
3829    
3830     %%%%%%%%%%%%%%%%%%%%
3831     % COMPUTE INTEGRAL %
3832     %%%%%%%%%%%%%%%%%%%%
3833     % We first determine the element surface matrix and points to integrate:
3834     [I1 I1mat dI1] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(1) LAT_MAX LONG_MAX]);
3835     [I2 I2mat dI2] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(2) LAT_MAX LONG_MAX]);
3836    
3837     % Then we determine the outcrop surface limits:
3838     I1mat = abs(I1mat - 1);
3839     Imat = (I1mat + I2mat)./2;
3840     Imat(find(Imat<1)) = 0;
3841     Imat = logical(Imat);
3842    
3843     % And the integral of the TRACER on it:
3844     I = sum(TRACER(Imat).*dI1(Imat));
3845    
3846    
3847    
3848    
3849     %%%%%%%%%%%
3850     % OUTPUTS %
3851     %%%%%%%%%%%
3852     switch nargout
3853     case {0,1}
3854     varargout(1) = {I};
3855     case 2
3856     varargout(1) = {I};
3857     varargout(2) = {Imat};
3858     case 3
3859     varargout(1) = {I};
3860     varargout(2) = {Imat};
3861     varargout(3) = {dI1};
3862     end %switch nargout
3863    
3864    
3865    
3866     gmaze_pv/outofdate/surfbet2outcrops.m0000644002352600001440000000533010444550056017424 0ustar gmazeusers%
3867     % S = surfbet2outcrops(TRACER,LIMITS,LAT,LONG)
3868     %
3869     % This function computes the horizontal surface between two outcrops,
3870     % given fixed limits eastward, westward and southward.
3871     %
3872     % TRACER = TRACER(LAT,LONG) : surface tracer variable in 2D
3873     % LIMITS = [OUTCROP1 OUTCROP2 MAX_LAT1 MAX_LAT2 MAX_LONG1 MAX_LONG2]
3874     % : limit's values (MAX_LAT2 is used only if
3875     % the outcrop's surfaces reach them).
3876     % LAT : latitude axis (1D), degrees northward
3877     % LONG : longitude axis (1D), degrees east
3878     % S : single surface value (m^2)
3879     %
3880     % 06/14/2006
3881     % gmaze@mit.edu
3882     %
3883    
3884    
3885     function varargout = surfbet2outcrops(TRACER,LIMITS,LAT,LONG)
3886    
3887    
3888     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3889     % PRE-PROCESS and ERROR CHECK %
3890     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3891     pv_checkpath
3892    
3893     % Check number of input:
3894     if nargin ~= 4
3895     help surfbet2outcrops.m
3896     error('surfbet2outcrops.m : Wrong number of parameters')
3897     return
3898     end %if
3899    
3900     % Check dimensions:
3901     n = size(TRACER);
3902     if length(n)==2
3903     [ny nx] = size(TRACER);
3904     if ny~=length(LAT) | nx~=length(LONG)
3905     help surfbet2outcrops.m
3906     error('surfbet2outcrops.m : Axis must have same dimensions than TRACER field');
3907     return
3908     end %if
3909     else
3910     help surfbet2outcrops.m
3911     error('surfbet2outcrops.m : TRACER must be a 2D field')
3912     return
3913     end %if
3914    
3915     % Ensure that axis are of dim: (1,N) and well sorted (increasing values):
3916     a=size(LAT);
3917     if a(1) ~= 1, LAT=LAT'; end
3918     S = sort(LAT);
3919     if S ~= LAT
3920     help surfbet2outcrops.m
3921     error('surfbet2outcrops.m : LAT must be increasing values')
3922     return
3923     end %if
3924     a=size(LONG);
3925     if a(1) ~= 1, LONG=LONG'; end
3926     S = sort(LONG);
3927     if S ~= LONG
3928     help surfbet2outcrops.m
3929     error('surfbet2outcrops.m : LONG must be increasing values')
3930     return
3931     end %if
3932    
3933     % LIMITS definition:
3934     if length(LIMITS) ~= 6
3935     help surfbet2outcrops.m
3936     error('surfbet2outcrops.m : LIMITS must contains 6 values')
3937     return
3938     end %if
3939     OUTCROPS = sort( LIMITS(1:2) );
3940     LAT_MAX = sort( LIMITS(3:4) );
3941     LONG_MAX = sort( LIMITS(5:6) );
3942    
3943    
3944    
3945     %%%%%%%%%%%%%%%%%%%
3946     % COMPUTE SURFACE %
3947     %%%%%%%%%%%%%%%%%%%
3948     % It's computed as the difference between the northern outcrop surface
3949     % and the southern outcrop one.
3950     [S1 S1mat dS1] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(1) LAT_MAX LONG_MAX]);
3951     [S2 S2mat dS2] = subfct_getsurf(TRACER,LAT,LONG,[OUTCROPS(2) LAT_MAX LONG_MAX]);
3952    
3953    
3954     % Then:
3955     S = max(S1,S2)-min(S1,S2);
3956    
3957    
3958     % Last we determine the outcrop surface limits:
3959     S1mat = abs(S1mat - 1);
3960     Smat = (S1mat + S2mat)./2;
3961     Smat(find(Smat<1)) = 0;
3962     Smat = logical(Smat);
3963    
3964    
3965    
3966    
3967     %%%%%%%%%%%
3968     % OUTPUTS %
3969     %%%%%%%%%%%
3970     switch nargout
3971     case {0 , 1}
3972     varargout(1) = {S};
3973     case 2
3974     varargout(1) = {S};
3975     varargout(2) = {Smat};
3976     case 3
3977     varargout(1) = {S};
3978     varargout(2) = {Smat};
3979     varargout(3) = {dS1};
3980     end %switch nargout
3981    
3982    
3983    
3984     gmaze_pv/outofdate/volbet2iso.m0000644002352600001440000000575510560500653016171 0ustar gmazeusers%
3985     % [V,V3D,dV] = volbet2iso(TRACER,LIMITS,DEPTH,LAT,LONG)
3986     %
3987     % This function computes the ocean volume between two iso surfaces,
3988     % given fixed limits eastward, westward and southward.
3989     %
3990     % TRACER = TRACER(DEPTH,LAT,LONG) : surface tracer variable in 3D
3991     % LIMITS = [OUTCROP1 OUTCROP2 MAX_DEPTH MAX_LAT1 MAX_LAT2 MAX_LONG1 MAX_LONG2]
3992     % : limit's values (MAX_DEPTH and MAX_LAT2 are used only if
3993     % the iso-outcrop's surfaces reach them).
3994     % DEPTH : vertical axis (1D), m downward, positive
3995     % LAT : latitude axis (1D), degrees northward
3996     % LONG : longitude axis (1D), degrees east
3997     % V : single volume value (m^3)
3998     %
3999     % 06/12/2006
4000     % gmaze@mit.edu
4001     %
4002    
4003    
4004     function varargout = volbet2iso(TRACER,LIMITS,DEPTH,LAT,LONG)
4005    
4006    
4007     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4008     % PRE-PROCESS and ERROR CHECK %
4009     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4010     pv_checkpath
4011    
4012     % Check number of input:
4013     if nargin ~= 5
4014     help volbet2iso.m
4015     error('volbet2iso.m : Wrong number of parameters')
4016     return
4017     end %if
4018    
4019     % Check dimensions:
4020     n = size(TRACER);
4021     if length(n)==3
4022     [nz ny nx] = size(TRACER);
4023     if nz~=length(DEPTH) | ny~=length(LAT) | nx~=length(LONG)
4024     help volbet2iso.m
4025     error('volbet2iso.m : Axis must have same dimensions than TRACER field');
4026     return
4027     end %if
4028     else
4029     help volbet2iso.m
4030     error('volbet2iso.m : TRACER must be a 3D field')
4031     return
4032     end %if
4033    
4034     % Ensure that axis are of dim: (1,N) and well sorted (increasing values):
4035     a=size(DEPTH);
4036     if a(1) ~= 1, DEPTH=DEPTH'; end
4037     S = sort(DEPTH);
4038     if S ~= DEPTH
4039     help volbet2iso.m
4040     error('volbet2iso.m : DEPTH must be increasing values')
4041     return
4042     end %if
4043     a=size(LAT);
4044     if a(1) ~= 1, LAT=LAT'; end
4045     S = sort(LAT);
4046     if S ~= LAT
4047     help volbet2iso.m
4048     error('volbet2iso.m : LAT must be increasing values')
4049     returny
4050     end %if
4051     a=size(LONG);
4052     if a(1) ~= 1, LONG=LONG'; end
4053     S = sort(LONG);
4054     if S ~= LONG
4055     help volbet2iso.m
4056     error('volbet2iso.m : LONG must be increasing values')
4057     return
4058     end %if
4059    
4060     % LIMITS definition:
4061     if length(LIMITS) ~=7
4062     help volbet2iso.m
4063     error('volbet2iso.m : LIMITS must contains 7 values')
4064     return
4065     end %if
4066     OUTCROPS = sort( LIMITS(1:2) );
4067     H_MAX = LIMITS(3);
4068     LAT_MAX = sort( LIMITS(4:5) );
4069     LONG_MAX = sort( LIMITS(6:7) );
4070    
4071    
4072     %%%%%%%%%%%%%%%%%%
4073     % COMPUTE VOLUME %
4074     %%%%%%%%%%%%%%%%%%
4075     % It's computed as the difference between the northern outcrop volume
4076     % and the southern outcrop one.
4077     [V1 V1mat dV1] = subfct_getvol(TRACER,DEPTH,LAT,LONG,[OUTCROPS(1) H_MAX LAT_MAX LONG_MAX]);
4078     [V2 V2mat dV2] = subfct_getvol(TRACER,DEPTH,LAT,LONG,[OUTCROPS(2) H_MAX LAT_MAX LONG_MAX]);
4079    
4080    
4081     % Then:
4082     V = max(V1,V2)-min(V1,V2);
4083    
4084    
4085     % Last we determine the iso-0 volume limits:
4086     V1mat = abs(V1mat - 1);
4087     Vmat = (V1mat + V2mat)./2;
4088     Vmat(find(Vmat<1)) = 0;
4089     Vmat = logical(Vmat);
4090    
4091    
4092    
4093     %%%%%%%%%%%
4094     % OUTPUTS %
4095     %%%%%%%%%%%
4096     switch nargout
4097     case {0,1}
4098     varargout(1) = {V};
4099     case 2
4100     varargout(1) = {V};
4101     varargout(2) = {Vmat};
4102     case 3
4103     varargout(1) = {V};
4104     varargout(2) = {Vmat};
4105     varargout(3) = {dV1};
4106     end %switch nargout
4107    
4108    
4109    
4110     gmaze_pv/subduc/Contents.m0000644002352600001440000000146210636770564015176 0ustar gmazeusers% $$$ This directory contains scripts written by Jake Gebbie for diagnosing
4111     % $$$ subduction rates. All scripts are for offline diagnostics in MATLAB.
4112     % $$$
4113     % $$$
4114     % $$$ Eulerian maps of subduction:
4115     % $$$ diag_sann.m: Diagnose the annual subduction rate.
4116     % $$$ diag_induction.m: Diagnose lateral induction across a surface (usually the
4117     % $$$ mixed-layer base)
4118     % $$$ get_mldvel.m: Interpolate the velocity field to a surface (usually the
4119     % $$$ mixed-layer base)
4120     % $$$
4121     % $$$ Water-mass diagnostics:
4122     % $$$ To be included at a future date.
4123     % $$$
4124     % $$$ Utilities:
4125     % $$$ mldepth.m: Calculate mixed-layer depth from the density field.
4126     % $$$ cshift.m: A MATLAB replica of the popular Fortran function.
4127     % $$$ integrate_for_w.m: A MATLAB rendition of the MITgcm subroutine
4128     % $$$ of the same name.
4129     gmaze_pv/subduc/cshift.m0000644002352600001440000000103210636770656014654 0ustar gmazeusersfunction [out] = cshift(in,DIM,shift)
4130     %function [out] = cshift(in,DIM,shift)
4131     %
4132     % Replicate the CSHIFT function in F90 (?).
4133     %
4134     % G. Gebbie, MIT-WHOI, Dec 2003.
4135    
4136     totaldims = ndims(in);
4137     index = 1: totaldims;
4138     index(index==DIM) = [];
4139     index = [DIM index];
4140     sizin = size(in);
4141     in = permute(in,index);
4142     in = reshape(in,sizin(DIM),prod(sizin)./sizin(DIM));
4143    
4144     if shift>=0
4145     shift = shift - size(in,1);
4146     end
4147    
4148     out = [in(shift+1+size(in,1):size(in,1),:);in(1:size(in,1)+shift,:)];
4149     out = reshape(out,sizin(index));
4150     out = ipermute(out,index);
4151     gmaze_pv/subduc/diag_induction.m0000644002352600001440000000125710636770732016360 0ustar gmazeusersfunction [induction,gradx,grady] = diag_induction(ustar,vstar,h,dxc,dyc);
4152     %function [induction,gradx,grady] = diag_induction(ustar,vstar,h,dxc,dyc)
4153     %
4154     % Diagnose lateral induction u_h . grad h
4155     %
4156     % G. Gebbie, 2003.
4157    
4158     [nx,ny] = size(ustar);
4159    
4160     gradx(2:nx,:) = (h(2:nx,:) - h(1:nx-1,:));
4161     grady(:,2:ny) = h(:,2:ny) - h(:,1:ny-1);
4162    
4163     gradx = gradx ./ dxc;
4164     grady = grady ./ dyc;
4165    
4166     udelh = ustar .* gradx;
4167     vdelh = vstar .* grady;
4168    
4169     %% now move udelh from U points to H points, in order to match up with W*.
4170     %% involves an average.
4171     udelh2 = (udelh(2:nx,:)+udelh(1:nx-1,:))./2;
4172     vdelh2 = (vdelh(:,2:ny)+vdelh(:,1:ny-1))./2;
4173    
4174     udelh2(nx,:) = 0;
4175     vdelh2(:,ny)=0;
4176    
4177     induction = udelh2 + vdelh2;
4178     gmaze_pv/subduc/diag_sann.m0000644002352600001440000000216410637030046015305 0ustar gmazeusersfunction [sann,stot,latind,wmstar] = diag_sann(umean,vmean,wmean,maxmld,Z,delZ,dxc,dyc,raw,mask);
4179     %function [sann,stot,latind,wmstar] = diag_sann(umean,vmean,wmean,maxmld,Z,delZ,dxc,dyc,raw,mask)
4180     %
4181     % Diagnose annual subduction rate of Marshall et al 1993.
4182     % S_ann = -w_H - u_H . del H, [m/yr]
4183     %
4184     % Also, diagnose S_tot, total subduction estimated from
4185     % annual subduction rate.
4186     % S_tot = \int S_ann dt dA, [Sv]
4187     %
4188     % intermediate terms of calculation:
4189     % latind = u_H . del H = lateral induction
4190     % wmstar = w_H = vertical velocity at h = maxmld.
4191     %
4192     % mask = 2D mask for calculation of subrate.
4193     %
4194     % Z < 0
4195     % delZ < 0
4196     % h < 0
4197     %
4198     % Started: D. Jamous 1996, Fortran diagnostics.
4199     % Updated: G. Gebbie, 2003, MIT-WHOI for Matlab.
4200    
4201     %% map the mean velocity onto the maxmld surface.
4202     [umstar,vmstar,wmstar] = get_mldvel(umean,vmean,wmean,Z,delZ,maxmld);
4203    
4204     %% compute mean lateral induction.
4205     [latind] = diag_induction(umstar,vmstar,maxmld,dxc,dyc);
4206    
4207     sann = -wmstar - latind;
4208    
4209     sann = sann .*86400 .*365; %convert to meters/year.
4210    
4211     sanntmp = sann;
4212     sanntmp(isnan(sanntmp))=0;
4213     stot=nansum(nansum(sanntmp.*raw.*mask))./(86400)./365
4214    
4215     return
4216     gmaze_pv/subduc/get_mldvel.m0000644002352600001440000000166110637042472015513 0ustar gmazeusersfunction [ustar,vstar,wstar] = get_mldvel(u,v,w,depth,delZ,h)
4217     %function [ustar,vstar,wstar] = get_mldvel(u,v,w,Z,delZ,h)
4218     %
4219     % Get velocity at a surface h = h(x,y).
4220     % Velocity remains on the C-grid with depths "depth".
4221     %
4222     % depth < 0
4223     % delZ < 0
4224     % h < 0
4225     %
4226     % G. Maze: remove extra function dependance
4227     %
4228     % Started: D. Jamous, 1996, FORTRAN diags.
4229     %
4230     % Translated: G. Gebbie, MIT-WHOI, November 2003.
4231    
4232     [nx,ny,nz]=size(u);
4233    
4234     ustar = zeros(nx,ny);
4235     vstar = zeros(nx,ny);
4236     wstar = zeros(nx,ny);
4237    
4238     zbot = cumsum(delZ)';
4239     zbot = depth;
4240    
4241     for i=2:nx-1
4242     for j=2:ny-1
4243     ustar(i,j) = interp1( depth, squeeze(u(i,j,:)),(h(i,j)+h(i-1,j))./2,'linear');
4244     vstar(i,j) = interp1( depth, squeeze(v(i,j,:)),(h(i,j)+h(i,j-1))./2,'linear');
4245     end
4246     end
4247     for i=1:nx-1
4248     for j=1:ny-1
4249     wstar(i,j) = interp1( squeeze(zbot(1:nz)), squeeze(w(i,j,:)), h(i,j), 'linear');
4250     end
4251     end
4252    
4253     ustar(isnan(ustar))= 0;
4254     vstar(isnan(vstar))= 0;
4255     wstar(isnan(wstar))= 0;
4256     gmaze_pv/subduc/integrate_for_w.m0000644002352600001440000000172510636771041016550 0ustar gmazeusersfunction [w] = integrate_for_w(u,v,dxg,dyg,raw, delZ )
4257     %function [w] = integrate_for_w(u,v,dxg,dyg, raw, delZ )
4258     %
4259     % Get the vertical velocity from the horizontal velocity.
4260     % Use the conservation of volume for this computation.
4261     % U and V are 3-dimensional.
4262     % Following the MITgcm subroutine, integrate_for_w.F
4263     %
4264     % uncertain about the halo region.
4265     %
4266     % G. Gebbie, MIT-WHOI, 2003.
4267     %
4268    
4269     [nx ny nz] = size(u);
4270    
4271     k=1:nz;
4272     utrans(:,:,k) = u(:,:,k) .* dyg(:,:,ones(1,nz));
4273     vtrans(:,:,k) = v(:,:,k) .* dxg(:,:,ones(1,nz));
4274    
4275     %% is this the best way to overlap?
4276     utrans(nx+1,:,k) = utrans(1,:,k);
4277     vtrans(:,ny+1,k) = vtrans(:,1,k);
4278    
4279     %w(:,:,23) = zeros(nx,ny,nz);
4280    
4281     kbot = nz;
4282     i=1:nx;
4283     j=1:ny;
4284     w(:,:,kbot) = - (utrans(i+1,j,kbot) - utrans(i,j,kbot) + ...
4285     vtrans(i,j+1,kbot) - vtrans(i,j,kbot)) ...
4286     .*(delZ(kbot)) ./raw(i,j);
4287    
4288     for k=nz-1:-1:1
4289     w(:,:,k) = w(:,:,k+1)- ((utrans(i+1,j,k) - utrans(i,j,k) + ...
4290     vtrans(i,j+1,k) - vtrans(i,j,k)) .* (delZ(k) ./raw(i,j)));
4291     end
4292    
4293     return
4294     gmaze_pv/subduc/mlddepth.m0000644002352600001440000000456410636771064015204 0ustar gmazeusersfunction [mld,rho] = mldepth(T,S,depth,epsilon)
4295     %function [mld,rho] = mldepth(T,S,depth,epsilon)
4296     %
4297     % Solve for mixed layer depth on a 1-meter resolution grid.
4298     %
4299     % Handles input temperature and salinity of any dimension, i.e. 2-D, 3-D,
4300     % 4-D, with time and space in any order.
4301     %
4302     % Returns mixed layer depth in same dimension as T,S, except without
4303     % the vertical dimension.
4304     %
4305     % depth = depths on which theta and S are defined.
4306     % epsilon = threshold for density difference, surface to mixld.
4307     %
4308     % Method: Solve for potential density with the surface reference pressure.
4309     % Interpolate density onto a 1-meter resolution grid.
4310     % Search for the depth where surface density differs by some
4311     % threshold. This depth is the mixed layer depth.
4312     %
4313     % G. Gebbie, MIT-WHOI, August 22, 2001. on board the R/V Oceanus.
4314     %
4315     % Vectorized for Matlab, November 2003. GG. MIT-WHOI.
4316     %
4317     % required: seawater toolbox. WARNING: SEAWATER TOOLBOX SYNTAX
4318     % MAY HAVE CHANGED.
4319    
4320     mldlimit = 500 ;% a priori maximum limit of mixed layer depth
4321    
4322     S( S == 0) = NaN;
4323     T( T == 0) = NaN;
4324    
4325     % mldlimit is the limit of mixed layer depth here.
4326     grrid = (2*depth(1)):1:mldlimit;
4327    
4328     % Set reference pressure to zero. Should not make a difference if mixld < 500.
4329     pr =0;
4330    
4331     %% The vertical direction is special. Its dimension is specified by "depth".
4332     nz = length(depth);
4333    
4334     nn = size(T);
4335    
4336     %% Find vertical dimension.
4337     zindex = find(nn==nz);
4338    
4339     oindex = 1:ndims(T);
4340     oindex(oindex==zindex)=[];
4341     nx = prod(nn(oindex));
4342    
4343     %% Put the vertical direction at the end. Squeeze the rest.
4344     temp = permute(T,[oindex zindex]);
4345     temp = reshape(temp,nx,nz);
4346     % temp (temp==0) = nan;
4347    
4348     salt = permute(S,[1 2 4 3]);
4349     salt = reshape(salt,nx,nz);
4350     % salt (salt==0) = nan;
4351    
4352     pden = sw_pden(salt,temp,depth,pr);
4353    
4354     if nargout ==2
4355     rho = reshape(pden,[nn(oindex) nz]) ;
4356     rho = permute(rho,[1 2 4 3]);
4357     end
4358    
4359     temphi = interp1( depth', pden', grrid);
4360     differ = cumsum(diff(temphi));
4361    
4362     %% preallocate memory.
4363     mld = zeros(nx,1);
4364    
4365     % how would one vectorize this section?
4366     for i = 1:nx
4367     index =find(differ(:,i)> epsilon);
4368     if( isempty ( index) ==1)
4369     tmpmld = NaN;
4370     else
4371     tmpmld = grrid( index(1));
4372     end
4373     mld(i) = tmpmld;
4374     end
4375    
4376     % Make the user happy. Return mixed layer depth in the same form as the
4377     % input T,S, except vertical dimension is gone.
4378    
4379     mld = reshape(mld,[nn(oindex) 1]);
4380     mld = squeeze(mld);
4381    
4382     mld(isnan(mld)) = 0;
4383    
4384     return
4385     gmaze_pv/subfct/boxcar.m0000644002352600001440000000447610650145007014650 0ustar gmazeusers% PII = boxcar(C3D,H,X,Y,Z,isoC,dC)
4386     % The boxcar function:
4387     % { isoC-dC/2 <= C3D(iZ,iY,iX) < isoC + dC/2
4388     % PII(isoC,C3D(iZ,iY,iX) = 1 if:{ Z(iZ) > H(iY,iX)
4389     % = 0 otherwise
4390     %
4391     % Rq:
4392     % H may be a single value
4393     % Z and H should be negative
4394     % Z orientatd downward
4395     %
4396    
4397     %function [PII] = boxcar(C3D,H,X,Y,Z,isoC,dC)
4398    
4399     function [PII A B C] = boxcar(C3D,H,X,Y,Z,isoC,dC)
4400    
4401     nz = length(Z);
4402     ny = length(Y);
4403     nx = length(X);
4404    
4405     method = 2;
4406    
4407     if length(H) == 1, H = H.*ones(ny,nx); end
4408    
4409     switch method
4410     case 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4411     PII = zeros(nz,ny,nx);
4412     warning off
4413     for ix = 1 : nx
4414     for iy = 1 : ny
4415     Cprof = squeeze(C3D(:,iy,ix));
4416     li = find( isoC-dC/2 <= Cprof & ...
4417     Cprof < isoC+dC/2 & ...
4418     Z > H(iy,ix) );
4419     if ~isempty(li)
4420     PII(li,iy,ix) = 1;
4421     end %if
4422     end %for iy
4423     end %for ix
4424     warning on
4425    
4426     case 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4427     PII = ones(nz,ny,nx);
4428    
4429     [a b]=meshgrid(Z,H); b=reshape(b,[ny nx nz]);b=permute(b,[3 1 2]);H=b;clear a b
4430     [a b c]=meshgrid(Z,Y,X);a=permute(a,[2 1 3]);Z=a;clear a b c
4431    
4432     PII(find( -dC/2 < C3D-isoC & C3D-isoC <= +dC/2 & H<=Z )) = 0;
4433     PII = 1-PII;
4434    
4435    
4436     end %switch method
4437    
4438    
4439     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4440     %%% Also provide the 1/0 matrix of the layer boundaries:
4441     bounds_vert = zeros(nz,ny,nx);
4442     bounds_meri = zeros(nz,ny,nx);
4443    
4444     for ix = 1 : nx
4445     piisect = squeeze(PII(:,:,ix));
4446     boundsect = zeros(nz,ny);
4447     % Determine vertical boundaries of the layer:
4448     for iy = 1 : ny
4449     li = find(piisect(:,iy)==1);
4450     if length(li) ~= 0
4451     boundsect(li(1),iy) = 1;
4452     boundsect(li(end),iy) = 1;
4453     end
4454     end
4455     bounds_vert(:,:,ix) = boundsect;
4456    
4457     boundsect = zeros(nz,ny);
4458     % Determine horizontal meridional boundaries of the layer:
4459     for iz = 1 : nz
4460     li = find(piisect(iz,:)==1);
4461     if length(li) ~= 0
4462     boundsect(iz,li(1)) = 1;
4463     boundsect(iz,li(end)) = 1;
4464     end
4465     end
4466     bounds_meri(:,:,ix) = boundsect;
4467    
4468     end %for ix
4469    
4470     bounds_zona = zeros(nz,ny,nx);
4471     for iy = 1 : ny
4472     piisect = squeeze(PII(:,iy,:));
4473     boundsect = zeros(nz,nx);
4474     % Determine horizontal zonal boundaries of the layer:
4475     for iz = 1 : nz
4476     li = find(piisect(iz,:)==1);
4477     if length(li) ~= 0
4478     boundsect(iz,li(1)) = 1;
4479     boundsect(iz,li(end)) = 1;
4480     end
4481     end
4482     bounds_zona(:,iy,:) = boundsect;
4483     end %for iy
4484    
4485     A = bounds_vert;
4486     B = bounds_meri;
4487     C = bounds_zona;
4488    
4489     gmaze_pv/subfct/coordfromnc.m0000644002352600001440000000076410650144750015705 0ustar gmazeusers% [X,Y,Z] = COORDFROMNC(NC)
4490     %
4491     % Given a netcdf file, return 3D coordinates values
4492     % in X, Y and Z
4493     %
4494    
4495    
4496     function varargout = coordfromnc(nc)
4497    
4498     co = coord(nc);
4499    
4500    
4501     switch nargout
4502     case 1
4503     varargout(1) = {co{1}(:)};
4504     case 2
4505     varargout(1) = {co{1}(:)};
4506     varargout(2) = {co{2}(:)};
4507     case 3
4508     varargout(1) = {co{1}(:)};
4509     varargout(2) = {co{2}(:)};
4510     varargout(3) = {co{3}(:)};
4511     case 4
4512     varargout(1) = {co{1}(:)};
4513     varargout(2) = {co{2}(:)};
4514     varargout(3) = {co{3}(:)};
4515     varargout(4) = {co{4}(:)};
4516     end
4517     gmaze_pv/subfct/cs510grid_outputs_table.m0000644002352600001440000001107610650144733020044 0ustar gmazeusersfunction otab = cs510grid_outputs_table
4518    
4519     % otab = cs510grid_outputs_table()
4520     % ONLY FOR CUBE40
4521     % Fields
4522     % 1 - file prefix
4523     % 2 - dimensions
4524     % 3 - grid location
4525     % 4 - id string (defaults to file prefix if unknown)
4526     % 5 - units
4527     % 6 - bytes per value
4528    
4529    
4530     otab=[{'AREAtave'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
4531     {'ETAN'}, {'xy'}, {'c'}, {'ssh'}, {'m'}, {4},
4532     {'ETANSQ'}, {'xy'}, {'c'}, {'ssh_squared'}, {'m^2'}, {4},
4533     {'EXFhl'}, {'xy'}, {'c'}, {'latent_heat_flux'}, {'W/m^2'}, {4},
4534     {'EXFhs'}, {'xy'}, {'c'}, {'sensible_heat_flux'}, {'W/m^2'}, {4},
4535     {'EXFlw'}, {'xy'}, {'c'}, {'longwave_radiation'}, {'W/m^2'}, {4},
4536     {'EXFsw'}, {'xy'}, {'c'}, {'shortwave_radiation'}, {'W/m^2'}, {4},
4537     {'EmPmRtave'}, {'xy'}, {'c'}, {'net_evaporation'}, {'m/s'}, {4},
4538     {'FUtave'}, {'xy'}, {'c'}, {'averaged_zonal_stress'}, {'N/m^2'}, {4},
4539     {'FVtave'}, {'xy'}, {'c'}, {'averaged_meridional_stress'}, {'N/m^2'}, {4},
4540     {'HEFFtave'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
4541     {'KPPhbl'}, {'xy'}, {'c'}, {'thermocline_base'}, {'m'}, {4},
4542     {'KPPmld'}, {'xy'}, {'c'}, {'mixed_layer_depth'}, {'m'}, {4},
4543     {'PHIBOT'}, {'xy'}, {'c'}, {'bottom_pressure'}, {'Pa'}, {4},
4544     {'QNETtave'}, {'xy'}, {'c'}, {'averaged_net_heatflux'}, {'W/m^2'}, {4},
4545     {'QSWtave'}, {'xy'}, {'c'}, {'averaged_shortwave_heatflux'}, {'W/m^2'}, {4},
4546     {'SFLUX'}, {'xy'}, {'c'}, {'salinity_flux'}, {'psu/s'}, {4},
4547     {'SRELAX'}, {'xy'}, {'c'}, {'salinity_relaxation'}, {'psu/s'}, {4},
4548     {'SSS'}, {'xy'}, {'c'}, {'sea_surface_salinity'}, {'psu'}, {4},
4549     {'SST'}, {'xy'}, {'c'}, {'sea_surface_temperature'}, {'degrees_centigrade'}, {4},
4550     {'TAUX'}, {'xy'}, {'c'}, {'zonal_wind_stress'}, {'N/m^2'}, {4},
4551     {'TAUY'}, {'xy'}, {'c'}, {'meridional_wind_stress'}, {'N/m^2'}, {4},
4552     {'TFLUX'}, {'xy'}, {'c'}, {'temperature_flux'}, {'W/m^2'}, {4},
4553     {'TICE'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
4554     {'UICEtave'}, {'xy'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
4555     {'UVEL_k2'}, {'xy'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
4556     {'VICEtave'}, {'xy'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4557     {'VVEL_k2'}, {'xy'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4558     {'DRHODR'}, {'xyz'}, {'w'}, {'vertical_density_gradient'}, {'kg/m^4'}, {4},
4559     {'RHOANOSQ'}, {'xyz'}, {'c'}, {'density_anomaly_squared'}, {'(kg/m^3-1000)^2'}, {4},
4560     {'RHOAnoma'}, {'xyz'}, {'c'}, {'density_anomaly'}, {'kg/m^3-1000'}, {4},
4561     {'SALTSQan'}, {'xyz'}, {'c'}, {'salinity_anomaly_squared'}, {'(psu-35)^2'}, {4},
4562     {'SALTanom'}, {'xyz'}, {'c'}, {'salinity_anomaly'}, {'psu-35'}, {8},
4563     {'THETA'}, {'xyz'}, {'c'}, {'potential_temperature'}, {'degrees_centigrade'}, {8},
4564     {'THETASQ'}, {'xyz'}, {'c'}, {'potential_temperature_squared'}, {'degrees_centigrade^2'}, {8},
4565     {'URHOMASS'}, {'xyz'}, {'u'}, {'zonal_mass_transport'}, {'kg.m^3/s'}, {4},
4566     {'USLTMASS'}, {'xyz'}, {'u'}, {'zonal_salt_transport'}, {'psu.m^3/s'}, {4},
4567     {'UTHMASS'}, {'xyz'}, {'u'}, {'zonal_temperature_transport'}, {'degrees_centigrade.m^3/s'}, {4},
4568     {'UVEL'}, {'xyz'}, {'u'}, {'zonal_flow'}, {'m/s'}, {4},
4569     {'UVELMASS'}, {'xyz'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
4570     {'UVELSQ'}, {'xyz'}, {'u'}, {'zonal_flow_squared'}, {'(m/s)^2'}, {4},
4571     {'UV_VEL_Z'}, {'xyz'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
4572     {'VISCA4'}, {'xyz'}, {'c'}, {'biharmonic_viscosity'}, {'m^4/s'}, {4},
4573     {'VRHOMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4574     {'VSLTMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4575     {'VTHMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4576     {'VVEL'}, {'xyz'}, {'v'}, {'meridional_velocity'}, {'m/s'}, {4},
4577     {'VVELMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
4578     {'VVELSQ'}, {'xyz'}, {'v'}, {'meridional_velocity_squared'}, {'(m/s)^2'}, {4},
4579     {'WRHOMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4580     {'WSLTMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4581     {'WTHMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4582     {'WU_VEL'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4583     {'WVELMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4584     {'WVELSQ'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
4585     {'WV_VEL'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4}];
4586    
4587     gmaze_pv/subfct/densjmd95.m0000644002352600001440000001467710650144624015204 0ustar gmazeusers% DENSJMD95: Density of sea water
4588     %=========================================================================
4589     %
4590     % USAGE: dens = densjmd95(S,Theta,P)
4591     %
4592     % DESCRIPTION:
4593     % Density of Sea Water using Jackett and McDougall 1995 (JAOT 12)
4594     % polynomial (modified UNESCO polynomial).
4595     %
4596     % INPUT: (all must have same dimensions)
4597     % S = salinity [psu (PSS-78)]
4598     % Theta = potential temperature [degree C (IPTS-68)]
4599     % P = pressure [dbar]
4600     % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) )
4601     %
4602     % OUTPUT:
4603     % dens = density [kg/m^3]
4604     %
4605     % AUTHOR: Martin Losch 2002-08-09 (mlosch@mit.edu)
4606     %
4607     % check value
4608     % S = 35.5 PSU
4609     % Theta = 3 degC
4610     % P = 3000 dbar
4611     % rho = 1041.83267 kg/m^3
4612     %
4613    
4614     % Jackett and McDougall, 1995, JAOT 12(4), pp. 381-388
4615    
4616     % created by mlosch on 2002-08-09
4617    
4618     function rho = densjmd95(s,t,p)
4619    
4620    
4621     %----------------------
4622     % CHECK INPUT ARGUMENTS
4623     %----------------------
4624     if nargin ~=3
4625     error('densjmd95.m: Must pass 3 parameters')
4626     end
4627     if ndims(s) > 2
4628     dims = size(s);
4629     dimt = size(t);
4630     dimp = size(p);
4631     if length(dims) ~= length(dimt) | length(dims) ~= length(dimp) ...
4632     | length(dimt) ~= length(dimp)
4633     error(['for more than two dimensions, S, Theta, and P must have the' ...
4634     ' same number of dimensions'])
4635     else
4636     for k=length(dims)
4637     if dims(k)~=dimt(k) | dims(k)~=dimp(k) | dimt(k)~=dimp(k)
4638     error(['for more than two dimensions, S, Theta, and P must have' ...
4639     ' the same dimensions'])
4640     end
4641     end
4642     end
4643     else
4644     % CHECK S,T,P dimensions and verify consistent
4645     [ms,ns] = size(s);
4646     [mt,nt] = size(t);
4647     [mp,np] = size(p);
4648    
4649     % CHECK THAT S & T HAVE SAME SHAPE
4650     if (ms~=mt) | (ns~=nt)
4651     error('check_stp: S & T must have same dimensions')
4652     end %if
4653    
4654     % CHECK OPTIONAL SHAPES FOR P
4655     if mp==1 & np==1 % P is a scalar. Fill to size of S
4656     p = p(1)*ones(ms,ns);
4657     elseif np==ns & mp==1 % P is row vector with same cols as S
4658     p = p( ones(1,ms), : ); % Copy down each column.
4659     elseif mp==ms & np==1 % P is column vector
4660     p = p( :, ones(1,ns) ); % Copy across each row
4661     elseif mp==ms & np==ns % P is a matrix size(S)
4662     % shape ok
4663     else
4664     error('check_stp: P has wrong dimensions')
4665     end %if
4666     [mp,np] = size(p);
4667     % IF ALL ROW VECTORS ARE PASSED THEN LET US PRESERVE SHAPE ON RETURN.
4668     Transpose = 0;
4669     if mp == 1 % row vector
4670     p = p(:);
4671     t = t(:);
4672     s = s(:);
4673     Transpose = 1;
4674     end
4675     %***check_stp
4676     end
4677    
4678     % convert pressure to bar
4679     p = .1*p;
4680    
4681     % coefficients nonlinear equation of state in pressure coordinates for
4682     % 1. density of fresh water at p = 0
4683     eosJMDCFw(1) = 999.842594;
4684     eosJMDCFw(2) = 6.793952e-02;
4685     eosJMDCFw(3) = - 9.095290e-03;
4686     eosJMDCFw(4) = 1.001685e-04;
4687     eosJMDCFw(5) = - 1.120083e-06;
4688     eosJMDCFw(6) = 6.536332e-09;
4689     % 2. density of sea water at p = 0
4690     eosJMDCSw(1) = 8.244930e-01;
4691     eosJMDCSw(2) = - 4.089900e-03;
4692     eosJMDCSw(3) = 7.643800e-05 ;
4693     eosJMDCSw(4) = - 8.246700e-07;
4694     eosJMDCSw(5) = 5.387500e-09;
4695     eosJMDCSw(6) = - 5.724660e-03;
4696     eosJMDCSw(7) = 1.022700e-04;
4697     eosJMDCSw(8) = - 1.654600e-06;
4698     eosJMDCSw(9) = 4.831400e-04;
4699    
4700     t2 = t.*t;
4701     t3 = t2.*t;
4702     t4 = t3.*t;
4703    
4704     is = find(s(:) < 0 );
4705     if ~isempty(is)
4706     warning('found negative salinity values, reset them to NaN');
4707     s(is) = NaN;
4708     end
4709     s3o2 = s.*sqrt(s);
4710    
4711     % density of freshwater at the surface
4712     rho = eosJMDCFw(1) ...
4713     + eosJMDCFw(2)*t ...
4714     + eosJMDCFw(3)*t2 ...
4715     + eosJMDCFw(4)*t3 ...
4716     + eosJMDCFw(5)*t4 ...
4717     + eosJMDCFw(6)*t4.*t;
4718     % density of sea water at the surface
4719     rho = rho ...
4720     + s.*( ...
4721     eosJMDCSw(1) ...
4722     + eosJMDCSw(2)*t ...
4723     + eosJMDCSw(3)*t2 ...
4724     + eosJMDCSw(4)*t3 ...
4725     + eosJMDCSw(5)*t4 ...
4726     ) ...
4727     + s3o2.*( ...
4728     eosJMDCSw(6) ...
4729     + eosJMDCSw(7)*t ...
4730     + eosJMDCSw(8)*t2 ...
4731     ) ...
4732     + eosJMDCSw(9)*s.*s;
4733    
4734     rho = rho./(1 - p./bulkmodjmd95(s,t,p));
4735    
4736     if ndims(s) < 3 & Transpose
4737     rho = rho';
4738     end %if
4739    
4740     return
4741    
4742     function bulkmod = bulkmodjmd95(s,t,p)
4743     %function bulkmod = bulkmodjmd95(s,t,p)
4744    
4745     dummy = 0;
4746     % coefficients in pressure coordinates for
4747     % 3. secant bulk modulus K of fresh water at p = 0
4748     eosJMDCKFw(1) = 1.965933e+04;
4749     eosJMDCKFw(2) = 1.444304e+02;
4750     eosJMDCKFw(3) = - 1.706103e+00;
4751     eosJMDCKFw(4) = 9.648704e-03;
4752     eosJMDCKFw(5) = - 4.190253e-05;
4753     % 4. secant bulk modulus K of sea water at p = 0
4754     eosJMDCKSw(1) = 5.284855e+01;
4755     eosJMDCKSw(2) = - 3.101089e-01;
4756     eosJMDCKSw(3) = 6.283263e-03;
4757     eosJMDCKSw(4) = - 5.084188e-05;
4758     eosJMDCKSw(5) = 3.886640e-01;
4759     eosJMDCKSw(6) = 9.085835e-03;
4760     eosJMDCKSw(7) = - 4.619924e-04;
4761     % 5. secant bulk modulus K of sea water at p
4762     eosJMDCKP( 1) = 3.186519e+00;
4763     eosJMDCKP( 2) = 2.212276e-02;
4764     eosJMDCKP( 3) = - 2.984642e-04;
4765     eosJMDCKP( 4) = 1.956415e-06;
4766     eosJMDCKP( 5) = 6.704388e-03;
4767     eosJMDCKP( 6) = - 1.847318e-04;
4768     eosJMDCKP( 7) = 2.059331e-07;
4769     eosJMDCKP( 8) = 1.480266e-04;
4770     eosJMDCKP( 9) = 2.102898e-04;
4771     eosJMDCKP(10) = - 1.202016e-05;
4772     eosJMDCKP(11) = 1.394680e-07;
4773     eosJMDCKP(12) = - 2.040237e-06;
4774     eosJMDCKP(13) = 6.128773e-08;
4775     eosJMDCKP(14) = 6.207323e-10;
4776    
4777     t2 = t.*t;
4778     t3 = t2.*t;
4779     t4 = t3.*t;
4780    
4781     is = find(s(:) < 0 );
4782     if ~isempty(is)
4783     warning('found negative salinity values, reset them to NaN');
4784     s(is) = NaN;
4785     end
4786     s3o2 = s.*sqrt(s);
4787     %p = pressure(i,j,k,bi,bj)*SItoBar
4788     p2 = p.*p;
4789     % secant bulk modulus of fresh water at the surface
4790     bulkmod = eosJMDCKFw(1) ...
4791     + eosJMDCKFw(2)*t ...
4792     + eosJMDCKFw(3)*t2 ...
4793     + eosJMDCKFw(4)*t3 ...
4794     + eosJMDCKFw(5)*t4;
4795     % secant bulk modulus of sea water at the surface
4796     bulkmod = bulkmod ...
4797     + s.*( eosJMDCKSw(1) ...
4798     + eosJMDCKSw(2)*t ...
4799     + eosJMDCKSw(3)*t2 ...
4800     + eosJMDCKSw(4)*t3 ...
4801     ) ...
4802     + s3o2.*( eosJMDCKSw(5) ...
4803     + eosJMDCKSw(6)*t ...
4804     + eosJMDCKSw(7)*t2 ...
4805     );
4806     % secant bulk modulus of sea water at pressure p
4807     bulkmod = bulkmod ...
4808     + p.*( eosJMDCKP(1) ...
4809     + eosJMDCKP(2)*t ...
4810     + eosJMDCKP(3)*t2 ...
4811     + eosJMDCKP(4)*t3 ...
4812     ) ...
4813     + p.*s.*( eosJMDCKP(5) ...
4814     + eosJMDCKP(6)*t ...
4815     + eosJMDCKP(7)*t2 ...
4816     ) ...
4817     + p.*s3o2*eosJMDCKP(8) ...
4818     + p2.*( eosJMDCKP(9) ...
4819     + eosJMDCKP(10)*t ...
4820     + eosJMDCKP(11)*t2 ...
4821     ) ...
4822     + p2.*s.*( eosJMDCKP(12) ...
4823     + eosJMDCKP(13)*t ...
4824     + eosJMDCKP(14)*t2 ...
4825     );
4826    
4827     return
4828    
4829     gmaze_pv/subfct/diagCatH.m0000644002352600001440000000114710641300521015020 0ustar gmazeusers% Ch = diagCatH(C,depth,h)
4830     %
4831     % Get field C(depth,lat,lon) at depth h(lat,lon)
4832     %
4833     % depth < 0
4834     % h < 0
4835     %
4836     % G. Maze, MIT, June 2007
4837     %y
4838    
4839     function varargout = diagCatH(C,Z,h)
4840    
4841     % 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PREPROC
4842     [nz,ny,nx] = size(C);
4843     Ch = zeros(ny,nx);
4844    
4845     % 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMPUTING
4846     warning off
4847     for ix = 1 : nx
4848     for iy = 1 : ny
4849     Ch(iy,ix) = interp1( Z, squeeze(C(:,iy,ix)) , h(iy,ix) , 'linear');
4850     end
4851     end
4852     warning on
4853    
4854     % 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
4855     switch nargout
4856     case 1
4857     varargout(1) = {Ch};
4858     endgmaze_pv/subfct/diagHatisoC.m0000644002352600001440000000421010641267270015542 0ustar gmazeusers% [H,h,[dH,dh]] = diagHatisoC(C,Z,isoC,[dC])
4859     %
4860     % Get depth of C(depth,lat,lon) = isoC
4861     % Z < 0
4862     %
4863     % OUTPUTS:
4864     % H(lat,lon) is the depth determine with the input resolution
4865     % h(lat,lon) is a more accurate depth (determined with interpolation)
4866     % dH(lat,lon) is the thickness of the layer: isoC-dC < C < isoC+dC from H
4867     % dh(lat,lon) is the thickness of the layer: isoC-dC < C < isoC+dC from h
4868     %
4869     % G. Maze, MIT, June 2007
4870     %
4871    
4872     function varargout = diagHatisoC(C,Z,isoC,varargin)
4873    
4874    
4875     % 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PREPROC
4876     [nz,ny,nx] = size(C);
4877     H = zeros(ny,nx).*NaN;
4878     if nargout >= 2
4879     h = zeros(ny,nx).*NaN;
4880     z = [0:-1:Z(end)]; % Vertical axis of the interpolated depth
4881     if nargin == 4
4882     dh = zeros(ny,nx).*NaN;
4883     end
4884     end
4885     if nargin == 4
4886     dC = varargin{1};
4887     dH = zeros(ny,nx).*NaN;
4888     end
4889    
4890     % 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMPUTING
4891     warning off
4892     for ix = 1 : nx
4893     for iy = 1 : ny
4894     c = squeeze(C(:,iy,ix))';
4895     if isnan(c(1)) ~= 1
4896     if length(find(c>=isoC))>0 & length(find(c<=isoC))>0
4897    
4898     % Raw value:
4899     [cm icm] = min(abs(abs(c)-abs(isoC)));
4900     H(iy,ix) = Z(icm);
4901    
4902     if nargout >= 2
4903     % Interp guess:
4904     cc = feval(@interp1,Z,c,z,'linear');
4905     [cm icm] = min(abs(abs(cc)-abs(isoC)));
4906     h(iy,ix) = z(icm);
4907     end % if 2 outputs
4908    
4909     if nargin == 4
4910     [cm icm1] = min(abs(abs(c)-abs(isoC+dC)));
4911     [cm icm2] = min(abs(abs(c)-abs(isoC-dC)));
4912     dH(iy,ix) = max(Z([icm1 icm2])) - min(Z([icm1 icm2]));
4913    
4914     if nargout >= 2
4915     [cm icm1] = min(abs(abs(cc)-abs(isoC+dC)));
4916     [cm icm2] = min(abs(abs(cc)-abs(isoC-dC)));
4917     dh(iy,ix) = max(z([icm1 icm2])) - min(z([icm1 icm2]));
4918     end % if 2 outputs
4919     end % if thickness
4920    
4921     end % if found value in the profile
4922     end % if point n ocean
4923     end
4924     end
4925     warning on
4926    
4927     % 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
4928     switch nargout
4929     case 1
4930     varargout(1) = {H};
4931     case 2
4932     varargout(1) = {H};
4933     varargout(2) = {h};
4934     case 3
4935     varargout(1) = {H};
4936     varargout(2) = {h};
4937     varargout(3) = {dH};
4938     case 4
4939     varargout(1) = {H};
4940     varargout(2) = {h};
4941     varargout(3) = {dH};
4942     varargout(4) = {dh};
4943     end
4944     gmaze_pv/subfct/diagVOLU.m0000644002352600001440000001373310645460452015010 0ustar gmazeusers% [V,Cm,E,Vt,CC] = diagVOLU(FLAG,C1,C2,CLASS,LON,LAT,DPT,DV,[Ca(Z,Y,X),Cb(Z,Y,X),...])
4945     %
4946     % DESCRIPTION:
4947     % Compute the volume of water for a particular CLASS of potential
4948     % temperature or density.
4949     % Also compute mean values of additional 3D fields (such as Ca, Cb ...) along
4950     % the CLASS of the analysed field.
4951     %
4952     % The volume is accounted as:
4953     % CLASS(i) <= FIELD < CLASS(i+1)
4954     %
4955     % INPUTS:
4956     % FLAG : Can either be: 0, 1 or 2
4957     % 0: Compute volume of potential density classes
4958     % from C1=THETA and C2=SALT
4959     % 1: Compute volume of potential density classes
4960     % from C1=SIGMA_THETA
4961     % 2: Compute volume of temperature classes
4962     % from C1=THETA
4963     % C1,C2 : Depends on option FLAG:
4964     % - FLAG = 0 :
4965     % C1 : Temperature (^oC)
4966     % C2 : Salinity (PSU)
4967     % - FLAG = 1 :
4968     % C1 : Potential density (kg/m3)
4969     % C2 : Not used
4970     % - FLAG = 2 :
4971     % C1 : Temperature (^oC)
4972     % C2 : Not used
4973     % ClASS : Range to explore (eg: [20:.1:30] for potential density)
4974     % LON,LAT,DPT : axis (DPT < 0)
4975     % dV : Matrix of grid volume elements (m3) centered in (lon,lat,dpt)
4976     % Ca,Cb,...: Any additional 3D fields (unlimited)
4977     %
4978     %
4979     % OUTPUTS:
4980     % V : Volume of each CLASS (m3)
4981     % Cm : Mean value of the classified field (allow to check errors)
4982     % E : Each time a grid point is counted, a 1 is added to this 3D matrix
4983     % Allow to check double count of a point or unexplored areas
4984     % Vt : Is the total volume explored (Vt)
4985     % CC : Contains the mean value of additional fields Ca, Cb ....
4986     %
4987     % NOTES:
4988     % - Fields are on the format: C(DPT,LAT,LON)
4989     % - The potential density is computed with the equation of state routine from
4990     % the MITgcm called densjmd95.m
4991     % (see: http://mitgcm.org/cgi-bin/viewcvs.cgi/MITgcm_contrib/gmaze_pv/subfct/densjmd95.m)
4992     % - if dV is filled with NaN, dV is computed by the function
4993     %
4994     %
4995     % AUTHOR:
4996     % Guillaume Maze / MIT 2006
4997     %
4998     % HISTORY:
4999     % - Created: 06/29/2007
5000     %
5001    
5002     %
5003    
5004     function varargout = diagVOLU(FLAG,C1,C2,CLASS,LON,LAT,DPT,DV,varargin)
5005    
5006    
5007     % 0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PREPROC
5008     % Variables:
5009     ndpt = size(C1,1);
5010     nlat = size(C1,2);
5011     nlon = size(C1,3);
5012     CLASS = sort(CLASS(:));
5013     [Z b c] = meshgrid(DPT,LON,LAT);clear b c, Z = permute(Z,[2 3 1]);
5014    
5015     % Determine fields from which we'll take class contours:
5016     switch FLAG
5017    
5018     case {0,2} % Need to compute SIGMA THETA
5019     THETA = C1;
5020     SALT = C2;
5021     ST = densjmd95(SALT,THETA,0.09998*9.81*abs(Z)) - 1000;
5022     if FLAG == 0 % Field is SIGMA THETA:
5023     CROP = ST;
5024     elseif FLAG == 2 % Field is THETA:
5025     CROP = THETA;
5026     end
5027    
5028     case 1
5029     ST = C1; % Potential density
5030     CROP = ST;
5031     end
5032    
5033     % Volume elements:
5034     if length(find(isnan(DV)==1)) == ndpt*nlat*nlon
5035     if exist('subfct_getdV','file')
5036     DV = subfct_getdV(DPT,LAT,LON);
5037     else
5038     DV = local_getdV(DPT,LAT,LON);
5039     end
5040     end
5041    
5042     % Need to compute volume integral over these 3D fields
5043     nIN = nargin-8;
5044     if nIN >= 1
5045     doEXTRA = 1;
5046     else
5047     doEXTRA = 0;
5048     end
5049    
5050     % 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% VOLUME INTEGRATION
5051     explored = zeros(ndpt,nlat,nlon);
5052     % Volume integral:
5053     for iC = 1 : length(CLASS)-1
5054     mask = zeros(ndpt,nlat,nlon);
5055     mask(find( (CLASS(iC) <= CROP) & (CROP < CLASS(iC+1)) )) = 1;
5056     explored = explored + mask;
5057     VOL(iC) = nansum(nansum(nansum(DV.*mask,1),2),3);
5058    
5059     if VOL(iC) ~= 0
5060     CAR(iC) = nansum(nansum(nansum(CROP.*DV.*mask,1),2),3)./VOL(iC);
5061     if doEXTRA
5062     for ii = 1 : nIN
5063     C = varargin{ii};
5064     CAREXTRA(ii,iC) = nansum(nansum(nansum(C.*DV.*mask,1),2),3)./VOL(iC);
5065     end %for ii
5066     end %if doEXTRA
5067     else
5068     CAR(iC) = NaN;
5069     if doEXTRA
5070     for ii = 1 : nIN
5071     CAREXTRA(ii,iC) = NaN;
5072     end %for ii
5073     end %if doEXTRA
5074     end
5075     end %for iC
5076    
5077     % In order to compute the total volume of the domain:
5078     CROP(find(isnan(CROP)==0)) = 1;
5079     CROP(find(isnan(CROP)==1)) = 0;
5080     Vt = nansum(nansum(nansum(DV.*CROP,1),2),3);
5081    
5082     % 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
5083     switch nargout
5084     case 1
5085     varargout(1) = {VOL};
5086     case 2
5087     varargout(1) = {VOL};
5088     varargout(2) = {CAR};
5089     case 3
5090     varargout(1) = {VOL};
5091     varargout(2) = {CAR};
5092     varargout(3) = {explored};
5093     case 4
5094     varargout(1) = {VOL};
5095     varargout(2) = {CAR};
5096     varargout(3) = {explored};
5097     varargout(4) = {Vt};
5098     case 5
5099     varargout(1) = {VOL};
5100     varargout(2) = {CAR};
5101     varargout(3) = {explored};
5102     varargout(4) = {Vt};
5103     varargout(5) = {CAREXTRA};
5104     end %switch
5105    
5106    
5107    
5108    
5109    
5110    
5111    
5112     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5113     % This function computes the 3D dV volume elements.
5114     % Copy of the subfct_getDV function from gmaze_pv package
5115     function DV = local_getdV(Z,Y,X)
5116    
5117     nz = length(Z);
5118     ny = length(Y);
5119     nx = length(X);
5120    
5121     DV = zeros(nz,ny,nx);
5122    
5123     % Vertical elements:
5124     for iz = 1 : nz % Toward the deep ocean (because DPT<0)
5125     % Vertical grid length centered at Z(iy)
5126     if iz == 1
5127     dz = abs(Z(1)) + abs(sum(diff(Z(iz:iz+1))/2));
5128     elseif iz == nz % We don't know the real ocean depth
5129     dz = abs(sum(diff(Z(iz-1:iz))/2));
5130     else
5131     dz = abs(sum(diff(Z(iz-1:iz+1))/2));
5132     end
5133     DZ(iz) = dz;
5134     end
5135    
5136     % Surface and Volume elements:
5137     for ix = 1 : nx
5138     for iy = 1 : ny
5139     % Zonal grid length centered in X(ix),Y(iY)
5140     if ix == 1
5141     dx = abs(m_lldist([X(ix) X(ix+1)],[1 1]*Y(iy)))/2;
5142     elseif ix == nx
5143     dx = abs(m_lldist([X(ix-1) X(ix)],[1 1]*Y(iy)))/2;
5144     else
5145     dx = abs(m_lldist([X(ix-1) X(ix)],[1 1]*Y(iy)))/2+abs(m_lldist([X(ix) X(ix+1)],[1 1]*Y(iy)))/2;
5146     end
5147    
5148     % Meridional grid length centered in X(ix),Y(iY)
5149     if iy == 1
5150     dy = abs(m_lldist([1 1]*X(ix),[Y(iy) Y(iy+1)]))/2;
5151     elseif iy == ny
5152     dy = abs(m_lldist([1 1]*X(ix),[Y(iy-1) Y(iy)]))/2;
5153     else
5154     dy = abs(m_lldist([1 1]*X(ix),[Y(iy-1) Y(iy)]))/2+abs(m_lldist([1 1]*X(ix),[Y(iy) Y(iy+1)]))/2;
5155     end
5156    
5157     % Surface element:
5158     DA = dx*dy.*ones(1,nz);
5159    
5160     % Volume element:
5161     DV(:,iy,ix) = DZ.*DA;
5162     end %for iy
5163     end %for ix
5164    
5165     gmaze_pv/subfct/dtecco2.m0000644002352600001440000000202010650144563014702 0ustar gmazeusers% date = dtecco2(X,FORM)
5166     %
5167     % If:
5168     % FORM = 0, translate the stepnum X into a date string (yyyymmddHHMM)
5169     % FORM = 1, translate the date string X (yyyymmddHHMM) into a stepnum
5170     %
5171     % 06/08/29
5172     % gmaze@mit.edu
5173     %
5174    
5175     function varargout = dtecco2(varargin)
5176    
5177     % Test inputs:
5178     if nargin ~= 2
5179     help dtecco2.m
5180     error('dtecco2.m : Wrong number of parameters');
5181     return
5182     end %if
5183    
5184     % Recup inputs:
5185     X = varargin{1};
5186     FORM = varargin{2};
5187    
5188     % New tests:
5189     if FORM~=0 & FORM~=1
5190     help dtecco2.m
5191     error('dtecco2.m : Second argument must be 0 or 1');
5192     return
5193     elseif FORM == 0 & ~isnumeric(X)
5194     help dtecco2.m
5195     error('dtecco2.m : if 2nd arg is 0, 1st arg must be numeric');
5196     return
5197     elseif FORM == 1 & isnumeric(X)
5198     help dtecco2.m
5199     error('dtecco2.m : if 2nd arg is 1, 1st arg must be a string');
5200     return
5201     end
5202    
5203    
5204     % Let's go:
5205     switch FORM
5206    
5207     case 0
5208     ID = datestr(datenum(1992,1,1)+X*300/60/60/24,'yyyymmddHHMM');
5209     varargout(1) = {ID};
5210    
5211     case 1
5212     ID = 60*60*24/300*( datenum(X,'yyyymmddHHMM') - datenum(1992,1,1) );
5213     varargout(1) = {ID};
5214    
5215    
5216     end %switch
5217     gmaze_pv/subfct/getFLUXbudgetV.m0000644002352600001440000001354210650143163016164 0ustar gmazeusers% [D1,D2] = getFLUXbudgetV(z,y,x,Fx,Fy,Fz,box)
5218     %
5219     % Compute the two terms:
5220     % D1 as the volume integral of the flux divergence
5221     % D2 as the surface integral of the normal flux across the volume's boundary
5222     %
5223     % Given a 3D flux vector ie:
5224     % Fx(z,y,x)
5225     % Fy(z,y,x)
5226     % Fz(z,y,x)
5227     %
5228     % Defined on the C-grid at U,V,W locations (bounding the tracer point)
5229     % given by:
5230     % z ( = W detph )
5231     % y ( = V latitude)
5232     % x ( = U longitude)
5233     %
5234     % box is a 0/1 3D matrix defined on the tracer grid
5235     % ie, of dimension: z-1 , y-1 , x-1
5236     %
5237     % All fluxes are supposed to be scaled by the surface of the cell tile they
5238     % account for.
5239     %
5240     % Each D is decomposed as:
5241     % D(1) = Total integral (Vertical+Horizontal)
5242     % D(2) = Vertical contribution
5243     % D(3) = Horizontal contribution
5244     %
5245     % Rq:
5246     % The divergence theorem is thus a conservation law which states that
5247     % the volume total of all sinks and sources, the volume integral of
5248     % the divergence, is equal to the net flow across the volume's boundary.
5249     %
5250     % gmaze@mit.edu 2007/07/19
5251     %
5252     %
5253    
5254     function varargout = getFLUXbudgetV(varargin)
5255    
5256    
5257     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PRELIM
5258    
5259     dptw = varargin{1}; ndptw = length(dptw);
5260     latg = varargin{2}; nlatg = length(latg);
5261     long = varargin{3}; nlong = length(long);
5262    
5263     ndpt = ndptw - 1;
5264     nlon = nlong - 1;
5265     nlat = nlatg - 1;
5266    
5267     Fx = varargin{4};
5268     Fy = varargin{5};
5269     Fz = varargin{6};
5270    
5271     if size(Fx,1) ~= ndpt
5272     disp('Error, Fx(1) wrong dim');
5273     return
5274     end
5275     if size(Fx,2) ~= nlatg-1
5276     disp('Error, Fx(2) wrong dim');
5277     whos Fx
5278     return
5279     end
5280     if size(Fx,3) ~= nlong
5281     disp('Error, Fx(3) wrong dim');
5282     return
5283     end
5284    
5285     pii = varargin{7};
5286    
5287     % Ensure we're not gonna missed points cause is messy around:
5288     Fx(isnan(Fx)) = 0;
5289     Fy(isnan(Fy)) = 0;
5290     Fz(isnan(Fz)) = 0;
5291    
5292    
5293     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Compute the volume integral of flux divergence:
5294     % (gonna be on the tracer grid)
5295     dFdx = ( Fx(:,:,1:nlong-1) - Fx(:,:,2:nlong) );
5296     dFdy = ( Fy(:,1:nlatg-1,:) - Fy(:,2:nlatg,:) );
5297     dFdz = ( Fz(2:ndptw,:,:) - Fz(1:ndptw-1,:,:) );
5298     %whos dFdx dFdy dFdz
5299    
5300     % And sum it over the box:
5301     D1(1) = nansum(nansum(nansum( dFdx.*pii + dFdy.*pii + dFdz.*pii )));
5302     D1(2) = nansum(nansum(nansum( dFdz.*pii )));
5303     D1(3) = nansum(nansum(nansum( dFdy.*pii + dFdx.*pii )));
5304    
5305    
5306     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Compute the surface integral of the flux:
5307     if nargout > 1
5308     if exist('getVOLbounds')
5309     method = 3;
5310     else
5311     method = 2;
5312     end
5313    
5314     switch method
5315     %%%%%%%%%%%%%%%%%%%%
5316    
5317     %%%%%%%%%%%%%%%%%%%%
5318     case 2
5319     bounds_W = zeros(ndpt,nlat,nlon);
5320     bounds_E = zeros(ndpt,nlat,nlon);
5321     bounds_S = zeros(ndpt,nlat,nlon);
5322     bounds_N = zeros(ndpt,nlat,nlon);
5323     bounds_T = zeros(ndpt,nlat,nlon);
5324     bounds_B = zeros(ndpt,nlat,nlon);
5325     Zflux = 0;
5326     Mflux = 0;
5327     Vflux = 0;
5328    
5329     for iz = 1 : ndpt
5330     for iy = 1 : nlat
5331     for ix = 1 : nlon
5332     if pii(iz,iy,ix) == 1
5333    
5334     % Is it a western boundary ?
5335     if ix-1 <= 0 % Reach the domain limit
5336     bounds_W(iz,iy,ix) = 1;
5337     Zflux = Zflux + Fx(iz,iy,ix);
5338     elseif pii(iz,iy,ix-1) == 0
5339     bounds_W(iz,iy,ix) = 1;
5340     Zflux = Zflux + Fx(iz,iy,ix);
5341     end
5342     % Is it a eastern boundary ?
5343     if ix+1 >= nlon % Reach the domain limit
5344     bounds_E(iz,iy,ix) = 1;
5345     Zflux = Zflux - Fx(iz,iy,ix+1);
5346     elseif pii(iz,iy,ix+1) == 0
5347     bounds_E(iz,iy,ix) = 1;
5348     Zflux = Zflux - Fx(iz,iy,ix+1);
5349     end
5350    
5351     % Is it a southern boundary ?
5352     if iy-1 <= 0 % Reach the domain limit
5353     bounds_S(iz,iy,ix) = 1;
5354     Mflux = Mflux + Fy(iz,iy,ix);
5355     elseif pii(iz,iy-1,ix) == 0
5356     bounds_S(iz,iy,ix) = 1;
5357     Mflux = Mflux + Fy(iz,iy,ix);
5358     end
5359     % Is it a northern boundary ?
5360     if iy+1 >= nlat % Reach the domain limit
5361     bounds_N(iz,iy,ix) = 1;
5362     Mflux = Mflux - Fy(iz,iy+1,ix);
5363     elseif pii(iz,iy+1,ix) == 0
5364     bounds_N(iz,iy,ix) = 1;
5365     Mflux = Mflux - Fy(iz,iy+1,ix);
5366     end
5367    
5368     % Is it a top boundary ?
5369     if iz-1 <= 0 % Reach the domain limit
5370     bounds_T(iz,iy,ix) = 1;
5371     Vflux = Vflux - Fz(iz,iy,ix);
5372     elseif pii(iz-1,iy,ix) == 0
5373     bounds_T(iz,iy,ix) = 1;
5374     Vflux = Vflux - Fz(iz,iy,ix);
5375     end
5376     % Is it a bottom boundary ?
5377     if iz+1 >= ndpt % Reach the domain limit
5378     bounds_B(iz,iy,ix) = 1;
5379     Vflux = Vflux + Fz(iz+1,iy,ix);
5380     elseif pii(iz+1,iy,ix) == 0
5381     bounds_B(iz,iy,ix) = 1;
5382     Vflux = Vflux + Fz(iz+1,iy,ix);
5383     end
5384    
5385     end %for iy
5386     end %for ix
5387    
5388     end
5389     end
5390    
5391     D2(1) = Vflux+Mflux+Zflux;
5392     D2(2) = Vflux;
5393     D2(3) = Mflux+Zflux;
5394    
5395    
5396     %%%%%%%%%%%%%%%%%%%%
5397     case 3
5398     [bounds_N bounds_S bounds_W bounds_E bounds_T bounds_B] = getVOLbounds(pii);
5399     Mflux = nansum(nansum(nansum(...
5400     bounds_S.*squeeze(Fy(:,1:nlat,:)) - bounds_N.*squeeze(Fy(:,2:nlat+1,:)) )));
5401     Zflux = nansum(nansum(nansum(...
5402     bounds_W.*squeeze(Fx(:,:,1:nlon)) - bounds_E.*squeeze(Fx(:,:,2:nlon+1)) )));
5403     Vflux = nansum(nansum(nansum(...
5404     bounds_B.*squeeze(Fz(2:ndpt+1,:,:))-bounds_T.*squeeze(Fz(1:ndpt,:,:)) )));
5405    
5406     D2(1) = Vflux+Mflux+Zflux;
5407     D2(2) = Vflux;
5408     D2(3) = Mflux+Zflux;
5409    
5410     end %switch method surface flux
5411     end %if we realy need to compute this ?
5412    
5413    
5414    
5415    
5416     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
5417    
5418    
5419     switch nargout
5420     case 1
5421     varargout(1) = {D1};
5422     case 2
5423     varargout(1) = {D1};
5424     varargout(2) = {D2};
5425     case 3
5426     varargout(1) = {D1};
5427     varargout(2) = {D2};
5428     varargout(3) = {bounds_N};
5429     case 4
5430     varargout(1) = {D1};
5431     varargout(2) = {D2};
5432     varargout(3) = {bounds_N};
5433     varargout(4) = {bounds_S};
5434     case 5
5435     varargout(1) = {D1};
5436     varargout(2) = {D2};
5437     varargout(3) = {bounds_N};
5438     varargout(4) = {bounds_S};
5439     varargout(5) = {bounds_W};
5440     case 6
5441     varargout(1) = {D1};
5442     varargout(2) = {D2};
5443     varargout(3) = {bounds_N};
5444     varargout(4) = {bounds_S};
5445     varargout(5) = {bounds_W};
5446     varargout(6) = {bounds_E};
5447     case 7
5448     varargout(1) = {D1};
5449     varargout(2) = {D2};
5450     varargout(3) = {bounds_N};
5451     varargout(4) = {bounds_S};
5452     varargout(5) = {bounds_W};
5453     varargout(6) = {bounds_E};
5454     varargout(7) = {bounds_T};
5455     case 8
5456     varargout(1) = {D1};
5457     varargout(2) = {D2};
5458     varargout(3) = {bounds_N};
5459     varargout(4) = {bounds_S};
5460     varargout(5) = {bounds_W};
5461     varargout(6) = {bounds_E};
5462     varargout(7) = {bounds_T};
5463     varargout(8) = {bounds_B};
5464    
5465     end %switchgmaze_pv/subfct/getVOLbounds.m0000644002352600001440000000535510650140675015750 0ustar gmazeusers% [BN BS BW BE BT BB] = getVOLbounds(PII)
5466     %
5467     % Given a 1/0 3D matrix PII, determine faces bounding the volume
5468     %
5469     % INPUT:
5470     % PII is of dimensions: PII(NDPT,NLAT,NLON)
5471     % with:
5472     % DPT downward
5473     % LAT northward
5474     % LON eastward
5475     %
5476     % OUTPUT:
5477     % BN,BS, BW,BE, BT,BB are 3D matrices like PII, filled with 0 or 1.
5478     % 1 indicates a surface bounding the volume
5479     %
5480     % BN stands for northern bound
5481     % BS stands for southern bound
5482     % BW stands for western bound
5483     % BE stands for eastern bound
5484     % BT stands for top bound
5485     % BB stands for bottom bound
5486     %
5487     % gmaze@mit.edu 2007/07/19
5488     %
5489    
5490     function varargout = getVOLbounds(varargin)
5491    
5492    
5493     pii = varargin{1};
5494     ndpt = size(pii,1);
5495     nlat = size(pii,2);
5496     nlon = size(pii,3);
5497    
5498    
5499     bounds_W = zeros(ndpt,nlat,nlon);
5500     bounds_E = zeros(ndpt,nlat,nlon);
5501     bounds_S = zeros(ndpt,nlat,nlon);
5502     bounds_N = zeros(ndpt,nlat,nlon);
5503     bounds_T = zeros(ndpt,nlat,nlon);
5504     bounds_B = zeros(ndpt,nlat,nlon);
5505    
5506     for iz = 1 : ndpt
5507     for iy = 1 : nlat
5508     for ix = 1 : nlon
5509     if pii(iz,iy,ix) == 1
5510    
5511     % Is it a western boundary ?
5512     if ix-1 <= 0 % Reach the domain limit
5513     bounds_W(iz,iy,ix) = 1;
5514     elseif pii(iz,iy,ix-1) == 0
5515     bounds_W(iz,iy,ix) = 1;
5516     end
5517     % Is it a eastern boundary ?
5518     if ix+1 >= nlon % Reach the domain limit
5519     bounds_E(iz,iy,ix) = 1;
5520     elseif pii(iz,iy,ix+1) == 0
5521     bounds_E(iz,iy,ix) = 1;
5522     end
5523    
5524     % Is it a southern boundary ?
5525     if iy-1 <= 0 % Reach the domain limit
5526     bounds_S(iz,iy,ix) = 1;
5527     elseif pii(iz,iy-1,ix) == 0
5528     bounds_S(iz,iy,ix) = 1;
5529     end
5530     % Is it a northern boundary ?
5531     if iy+1 >= nlat % Reach the domain limit
5532     bounds_N(iz,iy,ix) = 1;
5533     elseif pii(iz,iy+1,ix) == 0
5534     bounds_N(iz,iy,ix) = 1;
5535     end
5536    
5537     % Is it a top boundary ?
5538     if iz-1 <= 0 % Reach the domain limit
5539     bounds_T(iz,iy,ix) = 1;
5540     elseif pii(iz-1,iy,ix) == 0
5541     bounds_T(iz,iy,ix) = 1;
5542     end
5543     % Is it a bottom boundary ?
5544     if iz+1 >= ndpt % Reach the domain limit
5545     bounds_B(iz,iy,ix) = 1;
5546     elseif pii(iz+1,iy,ix) == 0
5547     bounds_B(iz,iy,ix) = 1;
5548     end
5549    
5550     end % if
5551     end %for ix
5552     end % for iy
5553     end % for iz
5554    
5555     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS
5556     switch nargout
5557    
5558     case 1
5559     varargout(1) = {bounds_N};
5560     case 2
5561     varargout(1) = {bounds_N};
5562     varargout(2) = {bounds_S};
5563     case 3
5564     varargout(1) = {bounds_N};
5565     varargout(2) = {bounds_S};
5566     varargout(3) = {bounds_W};
5567     case 4
5568     varargout(1) = {bounds_N};
5569     varargout(2) = {bounds_S};
5570     varargout(3) = {bounds_W};
5571     varargout(4) = {bounds_E};
5572     case 5
5573     varargout(1) = {bounds_N};
5574     varargout(2) = {bounds_S};
5575     varargout(3) = {bounds_W};
5576     varargout(4) = {bounds_E};
5577     varargout(5) = {bounds_T};
5578     case 6
5579     varargout(1) = {bounds_N};
5580     varargout(2) = {bounds_S};
5581     varargout(3) = {bounds_W};
5582     varargout(4) = {bounds_E};
5583     varargout(5) = {bounds_T};
5584     varargout(6) = {bounds_B};
5585    
5586     end %switchgmaze_pv/subfct/GRID_125.m0000644002352600001440000004612710650144530014505 0ustar gmazeusers% THE 1/8 ORIGINAL GLOBAL GRID
5587    
5588     delR = [ 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.01, ...
5589     10.03, 10.11, 10.32, 10.80, 11.76, 13.42, 16.04 , 19.82, 24.85, ...
5590     31.10, 38.42, 46.50, 55.00, 63.50, 71.58, 78.90, 85.15, 90.18, ...
5591     93.96, 96.58, 98.25, 99.25,100.01,101.33,104.56,111.33,122.83, ...
5592     139.09,158.94,180.83,203.55,226.50,249.50,272.50,295.50,318.50, ...
5593     341.50,364.50,387.50,410.50,433.50,456.50 ];
5594     phiMin=-78.6672;
5595     delY=[0.0247, 0.0247, 0.0247, 0.0248, 0.0248, 0.0248, 0.0249, 0.0250, ...
5596     0.0251, 0.0251, 0.0251, 0.0252, 0.0252, 0.0253, 0.0253, 0.0254, ...
5597     0.0255, 0.0255, 0.0255, 0.0256, 0.0257, 0.0257, 0.0258, 0.0258, ...
5598     0.0259, 0.0259, 0.0260, 0.0260, 0.0261, 0.0262, 0.0262, 0.0263, ...
5599     0.0264, 0.0264, 0.0264, 0.0265, 0.0266, 0.0266, 0.0267, 0.0267, ...
5600     0.0268, 0.0268, 0.0269, 0.0270, 0.0270, 0.0271, 0.0271, 0.0272, ...
5601     0.0272, 0.0273, 0.0274, 0.0274, 0.0275, 0.0275, 0.0276, 0.0276, ...
5602     0.0277, 0.0278, 0.0278, 0.0279, 0.0280, 0.0280, 0.0281, 0.0281, ...
5603     0.0282, 0.0282, 0.0283, 0.0284, 0.0285, 0.0285, 0.0285, 0.0286, ...
5604     0.0287, 0.0287, 0.0288, 0.0288, 0.0289, 0.0290, 0.0291, 0.0291, ...
5605     0.0291, 0.0292, 0.0293, 0.0294, 0.0294, 0.0294, 0.0295, 0.0296, ...
5606     0.0297, 0.0297, 0.0298, 0.0298, 0.0299, 0.0300, 0.0300, 0.0301, ...
5607     0.0302, 0.0302, 0.0303, 0.0304, 0.0304, 0.0305, 0.0306, 0.0306, ...
5608     0.0307, 0.0307, 0.0308, 0.0309, 0.0309, 0.0310, 0.0311, 0.0311, ...
5609     0.0312, 0.0313, 0.0314, 0.0314, 0.0314, 0.0315, 0.0316, 0.0317, ...
5610     0.0317, 0.0318, 0.0319, 0.0319, 0.0320, 0.0321, 0.0321, 0.0322, ...
5611     0.0323, 0.0323, 0.0324, 0.0325, 0.0326, 0.0326, 0.0327, 0.0327, ...
5612     0.0328, 0.0329, 0.0330, 0.0331, 0.0331, 0.0332, 0.0332, 0.0333, ...
5613     0.0334, 0.0334, 0.0335, 0.0336, 0.0337, 0.0337, 0.0338, 0.0339, ...
5614     0.0340, 0.0340, 0.0341, 0.0342, 0.0342, 0.0343, 0.0344, 0.0344, ...
5615     0.0345, 0.0346, 0.0347, 0.0347, 0.0348, 0.0349, 0.0350, 0.0350, ...
5616     0.0351, 0.0352, 0.0353, 0.0353, 0.0354, 0.0355, 0.0356, 0.0356, ...
5617     0.0357, 0.0358, 0.0359, 0.0359, 0.0360, 0.0361, 0.0362, 0.0362, ...
5618     0.0363, 0.0364, 0.0365, 0.0366, 0.0366, 0.0367, 0.0367, 0.0368, ...
5619     0.0369, 0.0370, 0.0371, 0.0371, 0.0372, 0.0373, 0.0374, 0.0375, ...
5620     0.0375, 0.0376, 0.0377, 0.0378, 0.0379, 0.0380, 0.0380, 0.0381, ...
5621     0.0381, 0.0382, 0.0383, 0.0384, 0.0385, 0.0386, 0.0387, 0.0388, ...
5622     0.0388, 0.0389, 0.0389, 0.0391, 0.0391, 0.0392, 0.0393, 0.0394, ...
5623     0.0395, 0.0395, 0.0396, 0.0397, 0.0398, 0.0399, 0.0400, 0.0400, ...
5624     0.0401, 0.0402, 0.0403, 0.0403, 0.0404, 0.0405, 0.0406, 0.0407, ...
5625     0.0408, 0.0409, 0.0409, 0.0410, 0.0411, 0.0412, 0.0413, 0.0414, ...
5626     0.0414, 0.0415, 0.0416, 0.0417, 0.0418, 0.0419, 0.0420, 0.0421, ...
5627     0.0421, 0.0422, 0.0423, 0.0424, 0.0425, 0.0426, 0.0427, 0.0428, ...
5628     0.0428, 0.0429, 0.0430, 0.0431, 0.0432, 0.0433, 0.0434, 0.0435, ...
5629     0.0435, 0.0436, 0.0437, 0.0438, 0.0439, 0.0440, 0.0441, 0.0442, ...
5630     0.0443, 0.0444, 0.0444, 0.0445, 0.0446, 0.0447, 0.0448, 0.0449, ...
5631     0.0450, 0.0451, 0.0452, 0.0453, 0.0453, 0.0454, 0.0455, 0.0456, ...
5632     0.0457, 0.0458, 0.0459, 0.0460, 0.0461, 0.0462, 0.0463, 0.0464, ...
5633     0.0465, 0.0466, 0.0466, 0.0468, 0.0468, 0.0470, 0.0471, 0.0471, ...
5634     0.0472, 0.0473, 0.0474, 0.0475, 0.0476, 0.0477, 0.0478, 0.0479, ...
5635     0.0480, 0.0481, 0.0482, 0.0483, 0.0484, 0.0485, 0.0486, 0.0487, ...
5636     0.0488, 0.0489, 0.0490, 0.0491, 0.0491, 0.0493, 0.0494, 0.0494, ...
5637     0.0495, 0.0496, 0.0498, 0.0498, 0.0499, 0.0501, 0.0502, 0.0502, ...
5638     0.0504, 0.0505, 0.0505, 0.0506, 0.0508, 0.0508, 0.0510, 0.0511, ...
5639     0.0512, 0.0513, 0.0514, 0.0515, 0.0516, 0.0517, 0.0518, 0.0519, ...
5640     0.0520, 0.0521, 0.0522, 0.0523, 0.0524, 0.0525, 0.0526, 0.0527, ...
5641     0.0528, 0.0529, 0.0530, 0.0532, 0.0533, 0.0533, 0.0534, 0.0536, ...
5642     0.0536, 0.0538, 0.0539, 0.0540, 0.0541, 0.0542, 0.0543, 0.0544, ...
5643     0.0545, 0.0546, 0.0548, 0.0548, 0.0549, 0.0551, 0.0552, 0.0552, ...
5644     0.0554, 0.0555, 0.0556, 0.0557, 0.0558, 0.0559, 0.0561, 0.0561, ...
5645     0.0562, 0.0564, 0.0565, 0.0566, 0.0567, 0.0568, 0.0569, 0.0570, ...
5646     0.0571, 0.0573, 0.0574, 0.0574, 0.0576, 0.0577, 0.0578, 0.0579, ...
5647     0.0581, 0.0581, 0.0583, 0.0583, 0.0585, 0.0586, 0.0587, 0.0588, ...
5648     0.0590, 0.0590, 0.0592, 0.0592, 0.0594, 0.0595, 0.0596, 0.0597, ...
5649     0.0599, 0.0600, 0.0601, 0.0602, 0.0603, 0.0604, 0.0606, 0.0606, ...
5650     0.0607, 0.0609, 0.0610, 0.0611, 0.0612, 0.0614, 0.0615, 0.0616, ...
5651     0.0617, 0.0618, 0.0619, 0.0621, 0.0622, 0.0623, 0.0624, 0.0625, ...
5652     0.0626, 0.0627, 0.0629, 0.0630, 0.0631, 0.0632, 0.0634, 0.0634, ...
5653     0.0636, 0.0637, 0.0639, 0.0639, 0.0640, 0.0641, 0.0643, 0.0644, ...
5654     0.0646, 0.0647, 0.0648, 0.0649, 0.0650, 0.0651, 0.0653, 0.0654, ...
5655     0.0656, 0.0656, 0.0657, 0.0659, 0.0660, 0.0661, 0.0663, 0.0663, ...
5656     0.0665, 0.0666, 0.0668, 0.0668, 0.0670, 0.0671, 0.0672, 0.0674, ...
5657     0.0675, 0.0676, 0.0678, 0.0678, 0.0680, 0.0681, 0.0682, 0.0683, ...
5658     0.0685, 0.0686, 0.0687, 0.0689, 0.0690, 0.0691, 0.0692, 0.0694, ...
5659     0.0695, 0.0696, 0.0698, 0.0698, 0.0700, 0.0701, 0.0703, 0.0703, ...
5660     0.0705, 0.0706, 0.0708, 0.0709, 0.0710, 0.0711, 0.0713, 0.0714, ...
5661     0.0715, 0.0716, 0.0718, 0.0719, 0.0721, 0.0721, 0.0723, 0.0724, ...
5662     0.0726, 0.0726, 0.0728, 0.0729, 0.0731, 0.0732, 0.0733, 0.0734, ...
5663     0.0736, 0.0737, 0.0738, 0.0740, 0.0741, 0.0742, 0.0744, 0.0745, ...
5664     0.0746, 0.0747, 0.0749, 0.0750, 0.0751, 0.0753, 0.0754, 0.0755, ...
5665     0.0757, 0.0758, 0.0759, 0.0761, 0.0762, 0.0763, 0.0765, 0.0766, ...
5666     0.0767, 0.0768, 0.0770, 0.0771, 0.0773, 0.0774, 0.0775, 0.0776, ...
5667     0.0778, 0.0779, 0.0781, 0.0782, 0.0783, 0.0784, 0.0786, 0.0787, ...
5668     0.0789, 0.0790, 0.0791, 0.0792, 0.0794, 0.0795, 0.0797, 0.0798, ...
5669     0.0799, 0.0800, 0.0802, 0.0803, 0.0805, 0.0806, 0.0807, 0.0808, ...
5670     0.0810, 0.0811, 0.0813, 0.0814, 0.0816, 0.0817, 0.0818, 0.0819, ...
5671     0.0821, 0.0822, 0.0824, 0.0825, 0.0826, 0.0827, 0.0829, 0.0830, ...
5672     0.0832, 0.0833, 0.0834, 0.0835, 0.0837, 0.0838, 0.0840, 0.0841, ...
5673     0.0842, 0.0844, 0.0845, 0.0846, 0.0848, 0.0849, 0.0851, 0.0852, ...
5674     0.0853, 0.0854, 0.0856, 0.0858, 0.0859, 0.0860, 0.0861, 0.0863, ...
5675     0.0864, 0.0865, 0.0867, 0.0868, 0.0870, 0.0871, 0.0872, 0.0873, ...
5676     0.0875, 0.0876, 0.0878, 0.0879, 0.0881, 0.0882, 0.0883, 0.0884, ...
5677     0.0886, 0.0887, 0.0889, 0.0890, 0.0892, 0.0893, 0.0894, 0.0895, ...
5678     0.0897, 0.0898, 0.0900, 0.0901, 0.0902, 0.0903, 0.0905, 0.0906, ...
5679     0.0908, 0.0909, 0.0911, 0.0912, 0.0913, 0.0914, 0.0916, 0.0917, ...
5680     0.0919, 0.0920, 0.0921, 0.0923, 0.0924, 0.0925, 0.0927, 0.0928, ...
5681     0.0930, 0.0931, 0.0932, 0.0933, 0.0935, 0.0936, 0.0938, 0.0939, ...
5682     0.0940, 0.0942, 0.0943, 0.0944, 0.0946, 0.0947, 0.0949, 0.0950, ...
5683     0.0951, 0.0952, 0.0954, 0.0955, 0.0957, 0.0958, 0.0959, 0.0960, ...
5684     0.0962, 0.0963, 0.0965, 0.0966, 0.0967, 0.0968, 0.0970, 0.0971, ...
5685     0.0973, 0.0974, 0.0975, 0.0976, 0.0978, 0.0979, 0.0981, 0.0982, ...
5686     0.0983, 0.0984, 0.0986, 0.0987, 0.0988, 0.0989, 0.0991, 0.0992, ...
5687     0.0994, 0.0995, 0.0997, 0.0998, 0.0999, 0.1000, 0.1002, 0.1003, ...
5688     0.1004, 0.1005, 0.1007, 0.1008, 0.1009, 0.1011, 0.1012, 0.1013, ...
5689     0.1015, 0.1016, 0.1017, 0.1018, 0.1020, 0.1021, 0.1023, 0.1024, ...
5690     0.1025, 0.1026, 0.1028, 0.1028, 0.1030, 0.1031, 0.1032, 0.1034, ...
5691     0.1035, 0.1036, 0.1037, 0.1039, 0.1040, 0.1041, 0.1043, 0.1044, ...
5692     0.1045, 0.1047, 0.1048, 0.1049, 0.1050, 0.1051, 0.1053, 0.1053, ...
5693     0.1055, 0.1056, 0.1058, 0.1058, 0.1060, 0.1061, 0.1063, 0.1063, ...
5694     0.1065, 0.1066, 0.1067, 0.1069, 0.1070, 0.1071, 0.1072, 0.1073, ...
5695     0.1075, 0.1075, 0.1077, 0.1078, 0.1079, 0.1081, 0.1082, 0.1083, ...
5696     0.1084, 0.1085, 0.1087, 0.1088, 0.1089, 0.1090, 0.1091, 0.1092, ...
5697     0.1093, 0.1095, 0.1096, 0.1097, 0.1098, 0.1099, 0.1100, 0.1102, ...
5698     0.1103, 0.1104, 0.1105, 0.1106, 0.1107, 0.1108, 0.1109, 0.1111, ...
5699     0.1112, 0.1113, 0.1114, 0.1115, 0.1116, 0.1117, 0.1118, 0.1119, ...
5700     0.1120, 0.1121, 0.1122, 0.1123, 0.1125, 0.1125, 0.1127, 0.1128, ...
5701     0.1129, 0.1130, 0.1131, 0.1132, 0.1133, 0.1134, 0.1135, 0.1136, ...
5702     0.1137, 0.1138, 0.1139, 0.1140, 0.1142, 0.1143, 0.1143, 0.1144, ...
5703     0.1146, 0.1147, 0.1147, 0.1149, 0.1150, 0.1151, 0.1151, 0.1152, ...
5704     0.1153, 0.1154, 0.1155, 0.1156, 0.1157, 0.1158, 0.1159, 0.1160, ...
5705     0.1161, 0.1162, 0.1163, 0.1164, 0.1164, 0.1166, 0.1166, 0.1167, ...
5706     0.1168, 0.1169, 0.1170, 0.1171, 0.1172, 0.1173, 0.1174, 0.1175, ...
5707     0.1175, 0.1176, 0.1177, 0.1178, 0.1179, 0.1180, 0.1180, 0.1181, ...
5708     0.1182, 0.1183, 0.1184, 0.1185, 0.1186, 0.1186, 0.1187, 0.1188, ...
5709     0.1189, 0.1190, 0.1190, 0.1191, 0.1192, 0.1193, 0.1194, 0.1194, ...
5710     0.1195, 0.1196, 0.1197, 0.1197, 0.1198, 0.1199, 0.1200, 0.1200, ...
5711     0.1201, 0.1202, 0.1203, 0.1203, 0.1204, 0.1204, 0.1205, 0.1206, ...
5712     0.1207, 0.1207, 0.1208, 0.1209, 0.1209, 0.1210, 0.1211, 0.1211, ...
5713     0.1212, 0.1213, 0.1214, 0.1214, 0.1214, 0.1215, 0.1216, 0.1216, ...
5714     0.1217, 0.1218, 0.1218, 0.1219, 0.1219, 0.1220, 0.1221, 0.1221, ...
5715     0.1222, 0.1222, 0.1223, 0.1223, 0.1224, 0.1224, 0.1225, 0.1225, ...
5716     0.1226, 0.1227, 0.1227, 0.1228, 0.1228, 0.1228, 0.1229, 0.1230, ...
5717     0.1230, 0.1231, 0.1231, 0.1231, 0.1232, 0.1232, 0.1233, 0.1233, ...
5718     0.1234, 0.1234, 0.1234, 0.1235, 0.1235, 0.1236, 0.1236, 0.1237, ...
5719     0.1237, 0.1237, 0.1238, 0.1238, 0.1238, 0.1239, 0.1239, 0.1240, ...
5720     0.1240, 0.1240, 0.1240, 0.1241, 0.1241, 0.1242, 0.1242, 0.1242, ...
5721     0.1242, 0.1243, 0.1243, 0.1243, 0.1243, 0.1244, 0.1244, 0.1245, ...
5722     0.1245, 0.1245, 0.1245, 0.1245, 0.1246, 0.1246, 0.1246, 0.1246, ...
5723     0.1246, 0.1247, 0.1247, 0.1247, 0.1247, 0.1247, 0.1248, 0.1248, ...
5724     0.1248, 0.1248, 0.1248, 0.1248, 0.1249, 0.1249, 0.1249, 0.1249, ...
5725     0.1249, 0.1249, 0.1249, 0.1249, 0.1249, 0.1249, 0.1250, 0.1249, ...
5726     0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, ...
5727     0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, 0.1250, ...
5728     0.1250, 0.1250, 0.1250, 0.1250, 0.1249, 0.1250, 0.1250, 0.1250, ...
5729     0.1250, 0.1249, 0.1249, 0.1249, 0.1249, 0.1249, 0.1249, 0.1249, ...
5730     0.1248, 0.1249, 0.1249, 0.1248, 0.1248, 0.1248, 0.1248, 0.1248, ...
5731     0.1248, 0.1247, 0.1247, 0.1247, 0.1246, 0.1247, 0.1246, 0.1246, ...
5732     0.1246, 0.1245, 0.1245, 0.1246, 0.1245, 0.1245, 0.1244, 0.1244, ...
5733     0.1244, 0.1244, 0.1243, 0.1243, 0.1242, 0.1243, 0.1242, 0.1242, ...
5734     0.1241, 0.1241, 0.1241, 0.1241, 0.1240, 0.1240, 0.1239, 0.1239, ...
5735     0.1239, 0.1239, 0.1238, 0.1238, 0.1237, 0.1237, 0.1236, 0.1236, ...
5736     0.1236, 0.1235, 0.1235, 0.1235, 0.1234, 0.1234, 0.1233, 0.1233, ...
5737     0.1232, 0.1232, 0.1231, 0.1231, 0.1230, 0.1230, 0.1230, 0.1229, ...
5738     0.1229, 0.1228, 0.1228, 0.1227, 0.1227, 0.1226, 0.1226, 0.1225, ...
5739     0.1224, 0.1224, 0.1223, 0.1223, 0.1222, 0.1222, 0.1221, 0.1220, ...
5740     0.1220, 0.1219, 0.1219, 0.1218, 0.1218, 0.1217, 0.1217, 0.1216, ...
5741     0.1215, 0.1214, 0.1214, 0.1213, 0.1213, 0.1212, 0.1211, 0.1211, ...
5742     0.1210, 0.1209, 0.1209, 0.1208, 0.1208, 0.1206, 0.1206, 0.1205, ...
5743     0.1205, 0.1204, 0.1203, 0.1202, 0.1202, 0.1201, 0.1200, 0.1200, ...
5744     0.1199, 0.1198, 0.1197, 0.1197, 0.1196, 0.1195, 0.1195, 0.1194, ...
5745     0.1193, 0.1192, 0.1191, 0.1190, 0.1189, 0.1189, 0.1188, 0.1187, ...
5746     0.1186, 0.1186, 0.1185, 0.1184, 0.1183, 0.1182, 0.1181, 0.1180, ...
5747     0.1180, 0.1178, 0.1178, 0.1177, 0.1177, 0.1176, 0.1174, 0.1174, ...
5748     0.1173, 0.1172, 0.1171, 0.1170, 0.1169, 0.1168, 0.1167, 0.1166, ...
5749     0.1166, 0.1164, 0.1164, 0.1163, 0.1162, 0.1161, 0.1160, 0.1159, ...
5750     0.1158, 0.1157, 0.1156, 0.1155, 0.1154, 0.1153, 0.1152, 0.1151, ...
5751     0.1151, 0.1150, 0.1149, 0.1147, 0.1147, 0.1146, 0.1144, 0.1143, ...
5752     0.1143, 0.1142, 0.1140, 0.1139, 0.1138, 0.1137, 0.1136, 0.1135, ...
5753     0.1134, 0.1133, 0.1132, 0.1131, 0.1130, 0.1129, 0.1128, 0.1127, ...
5754     0.1126, 0.1125, 0.1123, 0.1122, 0.1121, 0.1120, 0.1119, 0.1118, ...
5755     0.1117, 0.1116, 0.1115, 0.1114, 0.1113, 0.1112, 0.1110, 0.1109, ...
5756     0.1108, 0.1107, 0.1106, 0.1105, 0.1104, 0.1103, 0.1101, 0.1100, ...
5757     0.1099, 0.1098, 0.1097, 0.1096, 0.1095, 0.1093, 0.1092, 0.1091, ...
5758     0.1090, 0.1089, 0.1088, 0.1086, 0.1085, 0.1084, 0.1083, 0.1082, ...
5759     0.1081, 0.1079, 0.1078, 0.1077, 0.1076, 0.1075, 0.1073, 0.1072, ...
5760     0.1071, 0.1070, 0.1069, 0.1067, 0.1066, 0.1065, 0.1064, 0.1062, ...
5761     0.1061, 0.1060, 0.1059, 0.1057, 0.1056, 0.1055, 0.1054, 0.1052, ...
5762     0.1051, 0.1050, 0.1049, 0.1048, 0.1047, 0.1045, 0.1044, 0.1043, ...
5763     0.1041, 0.1040, 0.1039, 0.1037, 0.1036, 0.1035, 0.1034, 0.1032, ...
5764     0.1031, 0.1030, 0.1029, 0.1027, 0.1026, 0.1025, 0.1024, 0.1022, ...
5765     0.1021, 0.1020, 0.1019, 0.1017, 0.1016, 0.1014, 0.1013, 0.1012, ...
5766     0.1011, 0.1010, 0.1008, 0.1007, 0.1005, 0.1004, 0.1003, 0.1001, ...
5767     0.1000, 0.0999, 0.0998, 0.0996, 0.0995, 0.0994, 0.0993, 0.0991, ...
5768     0.0989, 0.0988, 0.0987, 0.0986, 0.0985, 0.0983, 0.0982, 0.0980, ...
5769     0.0979, 0.0978, 0.0977, 0.0975, 0.0974, 0.0972, 0.0971, 0.0970, ...
5770     0.0969, 0.0967, 0.0966, 0.0964, 0.0963, 0.0962, 0.0961, 0.0959, ...
5771     0.0958, 0.0956, 0.0955, 0.0954, 0.0953, 0.0951, 0.0950, 0.0948, ...
5772     0.0947, 0.0946, 0.0944, 0.0943, 0.0942, 0.0940, 0.0939, 0.0938, ...
5773     0.0936, 0.0935, 0.0934, 0.0932, 0.0931, 0.0929, 0.0928, 0.0927, ...
5774     0.0925, 0.0924, 0.0923, 0.0921, 0.0920, 0.0919, 0.0918, 0.0916, ...
5775     0.0914, 0.0913, 0.0912, 0.0910, 0.0909, 0.0908, 0.0906, 0.0905, ...
5776     0.0904, 0.0902, 0.0901, 0.0899, 0.0898, 0.0897, 0.0896, 0.0894, ...
5777     0.0893, 0.0891, 0.0890, 0.0889, 0.0887, 0.0886, 0.0885, 0.0883, ...
5778     0.0882, 0.0880, 0.0879, 0.0878, 0.0876, 0.0875, 0.0874, 0.0872, ...
5779     0.0871, 0.0869, 0.0868, 0.0867, 0.0866, 0.0864, 0.0863, 0.0861, ...
5780     0.0860, 0.0859, 0.0857, 0.0856, 0.0855, 0.0853, 0.0852, 0.0850, ...
5781     0.0849, 0.0848, 0.0846, 0.0845, 0.0844, 0.0842, 0.0841, 0.0840, ...
5782     0.0838, 0.0837, 0.0836, 0.0834, 0.0833, 0.0831, 0.0830, 0.0829, ...
5783     0.0828, 0.0826, 0.0825, 0.0823, 0.0822, 0.0821, 0.0819, 0.0818, ...
5784     0.0817, 0.0815, 0.0814, 0.0813, 0.0811, 0.0810, 0.0809, 0.0807, ...
5785     0.0806, 0.0804, 0.0803, 0.0802, 0.0801, 0.0799, 0.0798, 0.0796, ...
5786     0.0795, 0.0794, 0.0793, 0.0791, 0.0790, 0.0788, 0.0787, 0.0786, ...
5787     0.0785, 0.0783, 0.0782, 0.0781, 0.0779, 0.0778, 0.0776, 0.0775, ...
5788     0.0774, 0.0773, 0.0771, 0.0770, 0.0768, 0.0767, 0.0766, 0.0765, ...
5789     0.0763, 0.0762, 0.0760, 0.0759, 0.0758, 0.0757, 0.0755, 0.0754, ...
5790     0.0753, 0.0751, 0.0750, 0.0749, 0.0748, 0.0746, 0.0745, 0.0744, ...
5791     0.0742, 0.0741, 0.0739, 0.0738, 0.0737, 0.0736, 0.0735, 0.0733, ...
5792     0.0732, 0.0730, 0.0729, 0.0728, 0.0727, 0.0725, 0.0724, 0.0723, ...
5793     0.0722, 0.0720, 0.0719, 0.0718, 0.0717, 0.0715, 0.0714, 0.0713, ...
5794     0.0711, 0.0710, 0.0708, 0.0707, 0.0706, 0.0705, 0.0704, 0.0702, ...
5795     0.0701, 0.0700, 0.0699, 0.0697, 0.0696, 0.0695, 0.0694, 0.0692, ...
5796     0.0691, 0.0690, 0.0689, 0.0687, 0.0686, 0.0685, 0.0684, 0.0683, ...
5797     0.0681, 0.0680, 0.0678, 0.0677, 0.0676, 0.0675, 0.0674, 0.0672, ...
5798     0.0671, 0.0670, 0.0669, 0.0667, 0.0666, 0.0665, 0.0664, 0.0662, ...
5799     0.0661, 0.0660, 0.0659, 0.0658, 0.0656, 0.0655, 0.0654, 0.0653, ...
5800     0.0652, 0.0650, 0.0649, 0.0648, 0.0647, 0.0646, 0.0644, 0.0643, ...
5801     0.0641, 0.0640, 0.0639, 0.0639, 0.0637, 0.0636, 0.0634, 0.0633, ...
5802     0.0632, 0.0631, 0.0630, 0.0629, 0.0628, 0.0626, 0.0625, 0.0624, ...
5803     0.0623, 0.0622, 0.0621, 0.0619, 0.0618, 0.0617, 0.0616, 0.0615, ...
5804     0.0613, 0.0612, 0.0611, 0.0610, 0.0609, 0.0608, 0.0606, 0.0605, ...
5805     0.0604, 0.0603, 0.0602, 0.0601, 0.0600, 0.0598, 0.0597, 0.0596, ...
5806     0.0595, 0.0594, 0.0592, 0.0592, 0.0590, 0.0589, 0.0588, 0.0587, ...
5807     0.0586, 0.0585, 0.0584, 0.0583, 0.0581, 0.0581, 0.0579, 0.0578, ...
5808     0.0577, 0.0576, 0.0574, 0.0574, 0.0572, 0.0571, 0.0570, 0.0569, ...
5809     0.0568, 0.0567, 0.0566, 0.0565, 0.0564, 0.0562, 0.0561, 0.0561, ...
5810     0.0559, 0.0558, 0.0557, 0.0556, 0.0555, 0.0554, 0.0552, 0.0552, ...
5811     0.0551, 0.0549, 0.0548, 0.0547, 0.0546, 0.0545, 0.0544, 0.0543, ...
5812     0.0542, 0.0541, 0.0540, 0.0539, 0.0538, 0.0536, 0.0536, 0.0534, ...
5813     0.0533, 0.0533, 0.0532, 0.0530, 0.0529, 0.0528, 0.0527, 0.0526, ...
5814     0.0525, 0.0524, 0.0523, 0.0522, 0.0521, 0.0520, 0.0519, 0.0518, ...
5815     0.0517, 0.0516, 0.0515, 0.0514, 0.0513, 0.0512, 0.0511, 0.0510, ...
5816     0.0508, 0.0508, 0.0506, 0.0505, 0.0505, 0.0504, 0.0502, 0.0502, ...
5817     0.0501, 0.0499, 0.0498, 0.0498, 0.0496, 0.0495, 0.0494, 0.0494, ...
5818     0.0493, 0.0491, 0.0491, 0.0490, 0.0489, 0.0488, 0.0487, 0.0486, ...
5819     0.0485, 0.0484, 0.0483, 0.0482, 0.0481, 0.0480, 0.0479, 0.0478, ...
5820     0.0477, 0.0476, 0.0475, 0.0474, 0.0474, 0.0472, 0.0471, 0.0471, ...
5821     0.0470, 0.0468, 0.0468, 0.0466, 0.0465, 0.0465, 0.0464, 0.0463, ...
5822     0.0462, 0.0461, 0.0460, 0.0459, 0.0458, 0.0457, 0.0457, 0.0455, ...
5823     0.0454, 0.0453, 0.0452, 0.0452, 0.0451, 0.0450, 0.0449, 0.0448, ...
5824     0.0447, 0.0446, 0.0446, 0.0444, 0.0444, 0.0443, 0.0442, 0.0441, ...
5825     0.0440, 0.0439, 0.0438, 0.0437, 0.0436, 0.0435, 0.0434, 0.0434, ...
5826     0.0433, 0.0432, 0.0431, 0.0430, 0.0430, 0.0429, 0.0427, 0.0427, ...
5827     0.0426, 0.0425, 0.0424, 0.0423, 0.0422, 0.0421, 0.0421, 0.0419, ...
5828     0.0419, 0.0418, 0.0417, 0.0416, 0.0415, 0.0414, 0.0414, 0.0412, ...
5829     0.0412, 0.0411, 0.0410, 0.0410, 0.0409, 0.0407, 0.0407, 0.0406, ...
5830     0.0406, 0.0404, 0.0403, 0.0403, 0.0402, 0.0401, 0.0400, 0.0400, ...
5831     0.0399, 0.0398, 0.0397, 0.0396, 0.0395, 0.0394, 0.0394, 0.0393, ...
5832     0.0392, 0.0391, 0.0391, 0.0389, 0.0389, 0.0388, 0.0388, 0.0387, ...
5833     0.0386, 0.0384, 0.0384, 0.0383, 0.0382, 0.0382, 0.0381, 0.0380, ...
5834     0.0380, 0.0378, 0.0378, 0.0377, 0.0376, 0.0375, 0.0375, 0.0373, ...
5835     0.0373, 0.0372, 0.0372, 0.0370, 0.0370, 0.0369, 0.0369, 0.0367, ...
5836     0.0367, 0.0366, 0.0366, 0.0364, 0.0364, 0.0363, 0.0363, 0.0362, ...
5837     0.0361, 0.0360, 0.0359, 0.0358, 0.0358, 0.0357, 0.0357, 0.0356, ...
5838     0.0355, 0.0354, 0.0354, 0.0353, 0.0352, 0.0351, 0.0350, 0.0350, ...
5839     0.0349, 0.0348, 0.0347, 0.0346, 0.0346, 0.0345, 0.0344, 0.0343, ...
5840     0.0343, 0.0342, 0.0342, 0.0341, 0.0341, 0.0339, 0.0339, 0.0338, ...
5841     0.0338, 0.0336, 0.0336, 0.0335, 0.0335, 0.0334, 0.0333, 0.0332, ...
5842     0.0332, 0.0331, 0.0331, 0.0330, 0.0329, 0.0328, 0.0327, 0.0327, ...
5843     0.0326, 0.0325, 0.0325, 0.0324, 0.0323, 0.0323, 0.0322, 0.0321, ...
5844     0.0321, 0.0320, 0.0320, 0.0319, 0.0318, 0.0317, 0.0317, 0.0316, ...
5845     0.0315, 0.0314, 0.0314, 0.0314, 0.0313, 0.0312, 0.0311, 0.0310, ...
5846     0.0310, 0.0310, 0.0309, 0.0308, 0.0307, 0.0307, 0.0306, 0.0305, ...
5847     0.0305, 0.0304, 0.0304, 0.0303, 0.0303, 0.0301, 0.0301, 0.0301, ...
5848     0.0300, 0.0299, 0.0298, 0.0298, 0.0297, 0.0297, 0.0296, 0.0295, ...
5849     0.0294, 0.0294, 0.0294, 0.0293, 0.0292, 0.0291, 0.0291, 0.0290, ...
5850     0.0290, 0.0289, 0.0289, 0.0288, 0.0287, 0.0287, 0.0286, 0.0285, ...
5851     0.0285, 0.0284, 0.0284, 0.0283, 0.0283, 0.0282, 0.0281, 0.0281, ...
5852     0.0280, 0.0279, 0.0279, 0.0278, 0.0278, 0.0277, 0.0277, 0.0276, ...
5853     0.0275, 0.0275, 0.0274, 0.0274, 0.0273, 0.0272, 0.0271, 0.0271, ...
5854     0.0271, 0.0270, 0.0270, 0.0269, 0.0269, 0.0268, 0.0267, 0.0267, ...
5855     0.0266, 0.0265, 0.0265, 0.0264, 0.0264, 0.0264, 0.0263, 0.0262, ...
5856     0.0261, 0.0261, 0.0261, 0.0260, 0.0259, 0.0259, 0.0258, 0.0258, ...
5857     0.0257, 0.0257, 0.0256, 0.0255, 0.0255, 0.0254, 0.0254, 0.0253, ...
5858     0.0253, 0.0252, 0.0252, 0.0251, 0.0251, 0.0250, 0.0250, 0.0249, ...
5859     0.0249, 0.0248, 0.0248, 0.0247, 0.0246, 0.0246, 0.0245, 0.0245, ...
5860     0.0244, 0.0244, 0.0243, 0.0243, 0.0242, 0.0242, 0.0241, 0.0241, ...
5861     0.0240, 0.0240, 0.0239, 0.0239, 0.0238, 0.0238, 0.0237, 0.0237, ...
5862     0.0236, 0.0236, 0.0235, 0.0235, 0.0234, 0.0234, 0.0233, 0.0233, ...
5863     0.0232, 0.0232, 0.0231, 0.0231, 0.0230, 0.0230, 0.0229, 0.0229, ...
5864     0.0228, 0.0228, 0.0227, 0.0227, 0.0226, 0.0226, 0.0225, 0.0225, ...
5865     0.0224, 0.0224, 0.0223, 0.0223, 0.0222, 0.0222, 0.0221, 0.0221, ...
5866     0.0220, 0.0220, 0.0219, 0.0219, 0.0219, 0.0218, 0.0218, 0.0218];
5867     delX=ones(2880,1)*.125;
5868    
5869     top=[0 cumsum(delR(1:(length(delR)-1)))];
5870     bot=cumsum(delR);
5871     thk125=bot-top;
5872     dpt125=(top+bot)/2;
5873    
5874     top=[0 cumsum(delX(1:(length(delX)-1)))'];
5875     bot=cumsum(delX)';
5876     lon125=(top+bot)/2;
5877    
5878     top=[phiMin phiMin+cumsum(delY(1:(length(delY)-1)))];
5879     bot=phiMin+cumsum(delY);
5880     lat125=(top+bot)/2;
5881    
5882     clear top bot del* phi*
5883     gmaze_pv/subfct/latlon2ingrid_netcdf.m0000644002352600001440000001111310650144456017456 0ustar gmazeusers% latlon2ingrid_netcdf: Read a bin snapshot from 1/8 simu and record it as netcdf
5884     % latlon2ingrid_netcdf(pathname,pathout, ...
5885     % stepnum,fpref,otab, ...
5886     % lon_c, lon_u, ...
5887     % lat_c, lat_v, ...
5888     % z_c, z_w, ...
5889     % subname, ...
5890     % lonmin,lonmax,latmin,latmax,depmin,depmax);
5891    
5892     function latlon2ingrid_netcdf(pathname,pathout, ...
5893     stepnum,fpref,otab, ...
5894     lon_c, lon_u, ...
5895     lat_c, lat_v, ...
5896     z_c, z_w, ...
5897     subname, ...
5898     lonmin,lonmax,latmin,latmax,depmin,depmax);
5899    
5900     irow=strmatch({fpref},otab(:,1),'exact');
5901     if length(irow) ~= 1
5902     fprintf('Bad irow value in latlon2ingrid_netcdf2\n');
5903     return
5904     end
5905     loc=otab{irow,3};
5906     id=otab{irow,4};
5907     units=otab{irow,5};
5908     dimspec=otab{irow,2};
5909     if strmatch(id,'unknown_id','exact')
5910     id = fpref;
5911     end
5912     fprintf('Field %s, loc=%s, id=%s, units=%s, dimspec=%s\n',fpref,loc,id,units,dimspec);
5913     wordlen=otab{irow,6};
5914     if wordlen == 4
5915     numfmt='float32';
5916     end
5917     if wordlen == 8
5918     numfmt='float64';
5919     end
5920     %numfmt='float64';
5921     %wordlen =8;
5922    
5923     %ilo_c=min(find(lon_c >= lonmin & lon_c <= lonmax));
5924     %ilo_u=min(find(lon_u >= lonmin & lon_u <= lonmax));
5925     %ihi_c=max(find(lon_c >= lonmin & lon_c <= lonmax));
5926     %ihi_u=max(find(lon_u >= lonmin & lon_u <= lonmax));
5927     ilo_c=min(find(lon_c-180 >= lonmin & lon_c-180 <= lonmax));
5928     ilo_u=min(find(lon_u-180 >= lonmin & lon_u-180 <= lonmax));
5929     ihi_c=max(find(lon_c-180 >= lonmin & lon_c-180 <= lonmax));
5930     ihi_u=max(find(lon_u-180 >= lonmin & lon_u-180 <= lonmax));
5931     jlo_c=min(find(lat_c >= latmin & lat_c <= latmax));
5932     jlo_v=min(find(lat_v >= latmin & lat_v <= latmax));
5933     jhi_c=max(find(lat_c >= latmin & lat_c <= latmax));
5934     jhi_v=max(find(lat_v >= latmin & lat_v <= latmax));
5935     klo_w=min(find(z_w >= depmin & z_w <= depmax));
5936     khi_w=max(find(z_w >= depmin & z_w <= depmax));
5937     klo_c=min(find(z_c >= depmin & z_c <= depmax));
5938     khi_c=max(find(z_c >= depmin & z_c <= depmax));
5939    
5940     fnam=sprintf('%s.%10.10d.data',fpref,stepnum);
5941     if loc == 'c'
5942     ilo=ilo_c;
5943     ihi=ihi_c;
5944     jlo=jlo_c;
5945     jhi=jhi_c;
5946     klo=klo_c;
5947     khi=khi_c;
5948     lon=lon_c;
5949     lat=lat_c;
5950     dep=-z_c;
5951     end
5952     if loc == 'u'
5953     ilo=ilo_u;
5954     ihi=ihi_u;
5955     jlo=jlo_c;
5956     jhi=jhi_c;
5957     klo=klo_c;
5958     khi=khi_c;
5959     lon=lon_u;
5960     lat=lat_c;
5961     dep=-z_c;
5962     end
5963     if loc == 'v'
5964     ilo=ilo_c;
5965     ihi=ihi_c;
5966     jlo=jlo_v;
5967     jhi=jhi_v;
5968     klo=klo_c;
5969     khi=khi_c;
5970     lon=lon_c;
5971     lat=lat_v;
5972     dep=-z_c;
5973     end
5974     if loc == 'w'
5975     ilo=ilo_c;
5976     ihi=ihi_c;
5977     jlo=jlo_c;
5978     jhi=jhi_c;
5979     klo=klo_w;
5980     khi=khi_w;
5981     lon=lon_c;
5982     lat=lat_v;
5983     dep=-z_w;
5984     end
5985    
5986     nx=1;ny=1;nz=1;
5987     if strmatch(dimspec,'xyz','exact');
5988     nx=length(lon);
5989     ny=length(lat);
5990     nz=length(dep);
5991     end
5992     if strmatch(dimspec,'xy','exact');
5993     nx=length(lon);
5994     ny=length(lat);
5995     end
5996    
5997     if klo > nz
5998     klo = nz;
5999     end
6000     if khi > nz
6001     khi = nz;
6002     end
6003    
6004     phiXYZ=zeros(ihi-ilo+1,jhi-jlo+1,khi-klo+1,'single');
6005     disp(strcat('in:',pathname,fnam))
6006     %[klo khi khi-klo+1]
6007    
6008     % Read a single level (selected by k)
6009     for k = klo : khi
6010     fid = fopen(strcat(pathname,fnam),'r','ieee-be');
6011     fseek(fid,(k-1)*nx*ny*wordlen,'bof');
6012     phi = fread(fid,nx*ny,numfmt);
6013     %whos phi, [k nx ny]
6014     phiXY = reshape(phi,[nx ny]);
6015     phiXY = phiXY(ilo:ihi,jlo:jhi);
6016     phiXYZ(:,:,k) = phiXY;
6017     %phiXYZ(100,100,k)
6018     fclose(fid);
6019     end
6020    
6021     %%%clear phi;
6022     %%%clear phiXY;
6023     phiXYZ(find(phiXYZ==0))=NaN;
6024    
6025     if subname == ' '
6026     %outname=sprintf('%s.nc',id);
6027     outname = sprintf('%s.nc',otab{irow,1});
6028     else
6029     %outname=sprintf('%s_%s.nc',subname,id);
6030     outname = sprintf('%s.%s.nc',otab{irow,1},subname);
6031     %outname = sprintf('%s.%s.nc',strcat(otab{irow,1},'s'),subname);
6032    
6033     end
6034     nc = netcdf(strcat(pathout,outname),'clobber');
6035     %disp(strcat(pathout,outname))
6036    
6037     nc('X')=ihi-ilo+1;
6038     nc('Y')=jhi-jlo+1;
6039     nc('Z')=khi-klo+1;
6040    
6041     nc{'X'}='X';
6042     nc{'Y'}='Y';
6043     nc{'Z'}='Z';
6044    
6045     nc{'X'}.uniquename='X';
6046     nc{'X'}.long_name='longitude';
6047     nc{'X'}.gridtype=ncint(0);
6048     nc{'X'}.units='degrees_east';
6049     nc{'X'}(:) = lon(ilo:ihi);
6050    
6051     nc{'Y'}.uniquename='Y';
6052     nc{'Y'}.long_name='latitude';
6053     nc{'Y'}.gridtype=ncint(0);
6054     nc{'Y'}.units='degrees_north';
6055     nc{'Y'}(:) = lat(jlo:jhi);
6056    
6057     nc{'Z'}.uniquename='Z';
6058     nc{'Z'}.long_name='depth';
6059     nc{'Z'}.gridtype=ncint(0);
6060     nc{'Z'}.units='m';
6061     nc{'Z'}(:) = dep(klo:khi);
6062    
6063     ncid=id;
6064     nc{ncid}={'Z' 'Y' 'X'};
6065     nc{ncid}.missing_value = ncdouble(NaN);
6066     nc{ncid}.FillValue_ = ncdouble(0.0);
6067     nc{ncid}(:,:,:) = permute(phiXYZ,[3 2 1]);
6068     nc{ncid}.units=units;
6069    
6070     close(nc);
6071     gmaze_pv/subfct/latlon8grid_outputs_table.m0000644002352600001440000001111310650144325020557 0ustar gmazeusersfunction otab = latlon8grid_outputs_table
6072    
6073     % otab = latlon8grid_outputs_table()
6074     % Output Fields from 1/8 simulations
6075     % 1 - file prefix
6076     % 2 - dimensions
6077     % 3 - grid location
6078     % 4 - id string (defaults to file prefix if unknown)
6079     % 5 - units
6080     % 6 - bytes per value
6081    
6082    
6083     otab=[{'AREAtave'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
6084     {'ETAN'}, {'xy'}, {'c'}, {'ssh'}, {'m'}, {4},
6085     {'ETANSQ'}, {'xy'}, {'c'}, {'ssh_squared'}, {'m^2'}, {4},
6086     {'EXFhl'}, {'xy'}, {'c'}, {'latent_heat_flux'}, {'W/m^2'}, {4},
6087     {'EXFhs'}, {'xy'}, {'c'}, {'sensible_heat_flux'}, {'W/m^2'}, {4},
6088     {'EXFlw'}, {'xy'}, {'c'}, {'longwave_radiation'}, {'W/m^2'}, {4},
6089     {'EXFsw'}, {'xy'}, {'c'}, {'shortwave_radiation'}, {'W/m^2'}, {4},
6090     {'EmPmRtave'}, {'xy'}, {'c'}, {'net_evaporation'}, {'m/s'}, {4},
6091     {'FUtave'}, {'xy'}, {'c'}, {'averaged_zonal_stress'}, {'N/m^2'}, {4},
6092     {'FVtave'}, {'xy'}, {'c'}, {'averaged_meridional_stress'}, {'N/m^2'}, {4},
6093     {'HEFFtave'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
6094     {'KPPhbl'}, {'xy'}, {'c'}, {'thermocline_base'}, {'m'}, {4},
6095     {'KPPmld'}, {'xy'}, {'c'}, {'mixed_layer_depth'}, {'m'}, {4},
6096     {'PHIBOT'}, {'xy'}, {'c'}, {'bottom_pressure'}, {'Pa'}, {4},
6097     {'QNETtave'}, {'xy'}, {'c'}, {'averaged_net_heatflux'}, {'W/m^2'}, {4},
6098     {'QSWtave'}, {'xy'}, {'c'}, {'averaged_shortwave_heatflux'}, {'W/m^2'}, {4},
6099     {'SFLUX'}, {'xy'}, {'c'}, {'salinity_flux'}, {'psu/s'}, {4},
6100     {'SRELAX'}, {'xy'}, {'c'}, {'salinity_relaxation'}, {'psu/s'}, {4},
6101     {'SSS'}, {'xy'}, {'c'}, {'sea_surface_salinity'}, {'psu'}, {4},
6102     {'SST'}, {'xy'}, {'c'}, {'sea_surface_temperature'}, {'degrees_centigrade'}, {4},
6103     {'TAUX'}, {'xy'}, {'c'}, {'zonal_wind_stress'}, {'N/m^2'}, {4},
6104     {'TAUY'}, {'xy'}, {'c'}, {'meridional_wind_stress'}, {'N/m^2'}, {4},
6105     {'TFLUX'}, {'xy'}, {'c'}, {'temperature_flux'}, {'W/m^2'}, {4},
6106     {'TICE'}, {'xy'}, {'c'}, {'unknown_id'}, {'unknown_units'}, {4},
6107     {'UICEtave'}, {'xy'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
6108     {'UVEL_k2'}, {'xy'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
6109     {'VICEtave'}, {'xy'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6110     {'VVEL_k2'}, {'xy'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6111     {'DRHODR'}, {'xyz'}, {'w'}, {'vertical_density_gradient'}, {'kg/m^4'}, {4},
6112     {'RHOANOSQ'}, {'xyz'}, {'c'}, {'density_anomaly_squared'}, {'(kg/m^3-1000)^2'}, {4},
6113     {'RHOAnoma'}, {'xyz'}, {'c'}, {'density_anomaly'}, {'kg/m^3-1000'}, {8},
6114     {'SALTSQan'}, {'xyz'}, {'c'}, {'salinity_anomaly_squared'}, {'(psu-35)^2'}, {4},
6115     {'SALTanom'}, {'xyz'}, {'c'}, {'salinity_anomaly'}, {'psu-35'}, {8},
6116     {'THETA'}, {'xyz'}, {'c'}, {'potential_temperature'}, {'degrees_centigrade'}, {8},
6117     {'THETASQ'}, {'xyz'}, {'c'}, {'potential_temperature_squared'}, {'degrees_centigrade^2'}, {8},
6118     {'URHOMASS'}, {'xyz'}, {'u'}, {'zonal_mass_transport'}, {'kg.m^3/s'}, {4},
6119     {'USLTMASS'}, {'xyz'}, {'u'}, {'zonal_salt_transport'}, {'psu.m^3/s'}, {4},
6120     {'UTHMASS'}, {'xyz'}, {'u'}, {'zonal_temperature_transport'}, {'degrees_centigrade.m^3/s'}, {4},
6121     {'UVEL'}, {'xyz'}, {'u'}, {'zonal_flow'}, {'m/s'}, {4},
6122     {'UVELMASS'}, {'xyz'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
6123     {'UVELSQ'}, {'xyz'}, {'u'}, {'zonal_flow_squared'}, {'(m/s)^2'}, {4},
6124     {'UV_VEL_Z'}, {'xyz'}, {'u'}, {'unknown_id'}, {'unknown_units'}, {4},
6125     {'VISCA4'}, {'xyz'}, {'c'}, {'biharmonic_viscosity'}, {'m^4/s'}, {4},
6126     {'VRHOMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6127     {'VSLTMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6128     {'VTHMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6129     {'VVEL'}, {'xyz'}, {'v'}, {'meridional_velocity'}, {'m/s'}, {4},
6130     {'VVELMASS'}, {'xyz'}, {'v'}, {'unknown_id'}, {'unknown_units'}, {4},
6131     {'VVELSQ'}, {'xyz'}, {'v'}, {'meridional_velocity_squared'}, {'(m/s)^2'}, {4},
6132     {'WRHOMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6133     {'WSLTMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6134     {'WTHMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6135     {'WU_VEL'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6136     {'WVELMASS'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6137     {'WVELSQ'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4},
6138     {'WV_VEL'}, {'xyz'}, {'w'}, {'unknown_id'}, {'unknown_units'}, {4}];
6139    
6140     gmaze_pv/subfct/readrec_cs510.m0000644002352600001440000000064110557736031015711 0ustar gmazeusers% C = READREC_CS510(fnam,NZ,fldprec)
6141     %
6142     % Get one record from the CS510 run
6143     %
6144     % fnam : string to the file (include path)
6145     % NZ : number of levels to read
6146     % fldprec : float32 or float64
6147     % ouput is: C(510,510,NZ,6)
6148     %
6149     %
6150    
6151     function C = readrec_cs510(fnam,NZ,fldprec)
6152    
6153     fmt = 'ieee-be';
6154     nx = 510;
6155     ny = 510;
6156    
6157    
6158     fid = fopen(fnam,'r',fmt);
6159     C = fread(fid,6*nx*ny*NZ,fldprec);
6160     fclose(fid);
6161     C = reshape(C,[6*nx ny NZ]);
6162    
6163    
6164     gmaze_pv/subfct/subfct_getdS.m0000644002352600001440000000121610650144121015767 0ustar gmazeusers% DS = subfct_getdS(LAT,LON)
6165     % This function computes the 2D dS surface elements centered
6166     % on LON,LAT
6167     %
6168    
6169     function ds = subfct_getdS(Y,X);
6170    
6171     ny = length(Y);
6172     nx = length(X);
6173    
6174     if nx == size(X,1)
6175     X = X';
6176     end
6177     if ny == size(Y,1)
6178     Y = Y';
6179     end
6180    
6181     %%% Compute the DY:
6182     % Assuming Y is independant of ix:
6183     d = m_lldist([1 1]*X(1),Y);
6184     dy = [d(1)/2 (d(2:length(d))+d(1:length(d)-1))/2 d(length(d))/2];
6185     dy = meshgrid(dy,X)';
6186    
6187     %%% Compute the DX:
6188     clear d
6189     for iy = 1 : ny
6190     d(:,iy) = m_lldist(X,Y([iy iy]));
6191     end
6192     dx = [d(1,:)/2 ; ( d(2:size(d,1),:) + d(1:size(d,1)-1,:) )./2 ; d(size(d,1),:)/2];
6193     dx = dx';
6194    
6195     %% Compute the horizontal DS surface element:
6196     ds = dx.*dy;
6197    
6198     gmaze_pv/subfct/subfct_getdV.m0000644002352600001440000000270710650144103016000 0ustar gmazeusers% DV = subfct_getdV(DEPTH,LATITUDE,LONGITUDE)
6199     % Compute 3D volume elements matrix from geographical
6200     % axis Z(<0,downward), Y and X
6201    
6202     function DV = subfct_getdV(Z,Y,X)
6203    
6204     nz = length(Z);
6205     ny = length(Y);
6206     nx = length(X);
6207    
6208     DV = zeros(nz,ny,nx);
6209    
6210     % Vertical elements:
6211     for iz = 1 : nz % Toward the deep ocean (because DPT<0)
6212     % Vertical grid length centered at Z(iy)
6213     if iz == 1
6214     dz = abs(Z(1)) + abs(sum(diff(Z(iz:iz+1))/2));
6215     elseif iz == nz % We don't know the real ocean depth
6216     dz = abs(sum(diff(Z(iz-1:iz))/2));
6217     else
6218     dz = abs(sum(diff(Z(iz-1:iz+1))/2));
6219     end
6220     DZ(iz) = dz;
6221     end
6222    
6223     % Surface and Volume elements:
6224     for ix = 1 : nx
6225     for iy = 1 : ny
6226     % Zonal grid length centered in X(ix),Y(iY)
6227     if ix == 1
6228     dx = abs(m_lldist([X(ix) X(ix+1)],[1 1]*Y(iy)))/2;
6229     elseif ix == nx
6230     dx = abs(m_lldist([X(ix-1) X(ix)],[1 1]*Y(iy)))/2;
6231     else
6232     dx = abs(m_lldist([X(ix-1) X(ix)],[1 1]*Y(iy)))/2+abs(m_lldist([X(ix) X(ix+1)],[1 1]*Y(iy)))/2;
6233     end
6234    
6235     % Meridional grid length centered in X(ix),Y(iY)
6236     if iy == 1
6237     dy = abs(m_lldist([1 1]*X(ix),[Y(iy) Y(iy+1)]))/2;
6238     elseif iy == ny
6239     dy = abs(m_lldist([1 1]*X(ix),[Y(iy-1) Y(iy)]))/2;
6240     else
6241     dy = abs(m_lldist([1 1]*X(ix),[Y(iy-1) Y(iy)]))/2+abs(m_lldist([1 1]*X(ix),[Y(iy) Y(iy+1)]))/2;
6242     end
6243    
6244     % Surface element:
6245     DA = dx*dy.*ones(1,nz);
6246    
6247     % Volume element:
6248     DV(:,iy,ix) = DZ.*DA;
6249     end %for iy
6250     end %for ix
6251    
6252     gmaze_pv/test/test_intbet2outcrops.m0000644002352600001440000000275210506046003017257 0ustar gmazeusers% Test of the function intbet2outcrops
6253     clear
6254    
6255     % Theoritical fields:
6256     eg = 2;
6257    
6258     switch eg
6259     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6260     case 1 % The more simple:
6261     % Axis:
6262     lon = [200:1/8:300]; nlon = length(lon);
6263     lat = [0:1/8:20]; nlat = length(lat);
6264    
6265     % chp goes linearly from 20 at 0N to 0 at 20N
6266     [a chp] = meshgrid(lon,-lat+lat(nlat)); clear a c
6267     [a chp] = meshgrid(lon,-lat+2); clear a c
6268     chp(14:16,:) = -1; % Make the integral proportional to the surface
6269    
6270     % Define limits:
6271     LIMITS(1) = -1 ;
6272     LIMITS(2) = -1 ;
6273     LIMITS(3:4) = lat([14 16]) ;
6274     LIMITS(5:6) = lon([1 nlon]) ;
6275    
6276     % Expected integral:
6277     dx = m_lldist([200 300],[1 1]*1.75)./1000;
6278     dy = m_lldist([1 1],[1.625 1.875])./1000;
6279     Iexp = dx*dy/2; % Unit is km^2
6280    
6281    
6282     case 2
6283     % Axis:
6284     lon = [200:1/8:300]; nlon = length(lon);
6285     lat = [0:1:40]; nlat = length(lat);
6286    
6287     %
6288     [a chp]=meshgrid(lon,40-lat);
6289    
6290     % Define limits:
6291     LIMITS(1) = 9.5 ;
6292     LIMITS(2) = 10.5 ;
6293     LIMITS(3:4) = lat([1 nlat]) ;
6294     LIMITS(5:6) = lon([1 nlon]) ;
6295    
6296     Iexp=4;
6297    
6298     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6299    
6300     end %switch
6301    
6302    
6303     % Get integral:
6304     [I Imat dI] = intbet2outcrops(chp,LIMITS,lat,lon);
6305    
6306     disp('Computed:')
6307     disp(num2str(I/1000^2))
6308     disp('Approximatly expected:')
6309     disp(num2str(Iexp))
6310    
6311     %break
6312     figure;iw=1;jw=2;
6313     subplot(iw,jw,1);hold on
6314     pcolor(chp);shading flat;canom;colorbar;axis tight
6315     title('Tracer to integrate');
6316    
6317     subplot(iw,jw,2);hold on
6318     pcolor(double(Imat));shading flat;canom;colorbar;axis tight
6319     title('Points selected for the integration');
6320     gmaze_pv/test/test_surfbet2outcrops.m0000664002352600001440000000161010444073147017450 0ustar gmazeusers% Test of the function surfbet2outcrops
6321     %
6322    
6323     clear
6324    
6325     % Theoritical fields:
6326     eg = 1;
6327    
6328     switch eg
6329     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6330     case 1 % The more simple:
6331     % Axis:
6332     lon = [200:1/8:300]; nlon = length(lon);
6333     lat = [0:1/8:20]; nlat = length(lat);
6334    
6335     % chp goes linearly from 20 at 0N to 0 at 20N
6336     [a chp] = meshgrid(lon,-lat+lat(nlat)); clear a c
6337     % chp(:,1:400) = chp(:,1:400).*NaN;
6338    
6339     % Define limits:
6340     LIMITS(1) = 18 ; % Between 1.75N and 2N
6341     LIMITS(2) = 18.2 ;
6342     LIMITS(3:4) = lat([1 nlat]) ;
6343     LIMITS(5:6) = lon([1 nlon]) ;
6344    
6345     % Expected surface:
6346     dx = m_lldist([200 300],[1 1]*1.875)./1000;
6347     dy = m_lldist([1 1],[1.75 2])./1000;
6348     Sexp = dx*dy; % Unit is km^2
6349    
6350     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6351    
6352     end %switch
6353    
6354    
6355    
6356     % Get surface:
6357     [S Smat dS] = surfbet2outcrops(chp,LIMITS,lat,lon);
6358    
6359     disp('Computed:')
6360     disp(num2str(S/1000^2))
6361     disp('Approximatly expected:')
6362     disp(num2str(Sexp))
6363     gmaze_pv/test/test_volbet2iso.m0000664002352600001440000000207310444073303016203 0ustar gmazeusers% Test of the function volbet2iso
6364     %
6365    
6366     clear
6367    
6368     % Theoritical fields:
6369     eg = 1;
6370    
6371     switch eg
6372     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6373     case 1 % The more simple:
6374     % Axis:
6375     lon = [200:1/8:300]; nlon = length(lon);
6376     lat = [0:1/8:20]; nlat = length(lat);
6377     dpt = [5:5:1000]; ndpt = length(dpt);
6378    
6379     % chp goes linearly from 10 at 30N to 0 at 40N
6380     % uniformely between the surface and the bottom:
6381     [a chp c] = meshgrid(lon,-lat+lat(nlat),dpt); clear a c
6382     chp = permute(chp,[3 1 2]);
6383     %chp(:,:,1:400) = chp(:,:,1:400).*NaN;
6384    
6385     % Define limits:
6386     LIMITS(1) = 18 ; % Between 1.75N and 2N
6387     LIMITS(2) = 18.2 ;
6388     LIMITS(3) = dpt(ndpt) ;
6389     LIMITS(4:5) = lat([1 nlat]) ;
6390     LIMITS(6:7) = lon([1 nlon]) ;
6391    
6392     % Expected volume:
6393     dx = m_lldist([200 300],[1 1]*1.875)./1000;
6394     dy = m_lldist([1 1],[1.75 2])./1000;
6395     dz = dpt(ndpt)./1000;
6396     Vexp = dx*dy*dz; % Unit is km^3
6397    
6398     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6399    
6400     end %switch
6401    
6402    
6403    
6404     % Get volume:
6405     [V Vmat dV] = volbet2iso(chp,LIMITS,dpt,lat,lon);
6406    
6407     disp('Computed:')
6408     disp(num2str(V/1000^3))
6409     disp('Approximatly expected:')
6410     disp(num2str(Vexp))
6411     gmaze_pv/visu/eg_view_Timeserie.m0000644002352600001440000002322110511523746016520 0ustar gmazeusers%
6412     % THIS IS NOT A FUNCTION !
6413     %
6414     % Plot time series of all variables in different ways
6415     % Outputs recording possible
6416     %
6417    
6418     clear
6419     global sla netcdf_domain
6420     pv_checkpath
6421    
6422     % Path and extension to find files:
6423     pathname = strcat('netcdf-files',sla);
6424     %pathname = strcat('netcdf-files-twice-daily',sla);
6425     %pathname = strcat('netcdf-files-daily',sla);
6426     ext = 'nc';
6427     netcdf_domain = 'western_north_atlantic';
6428    
6429     % Date series:
6430     ID = datenum(2000,12,31,12,0,0); % Start date
6431     ID = datenum(2000,12,31,0,0,0); % Start date
6432     ID = datenum(2001,1,1,12,0,0); % Start date
6433     ID = datenum(2001,4,1,0,0,0); % Start date
6434     %IDend = datenum(2001,2,26,12,0,0); % End date
6435     IDend = datenum(2001,7,4,0,0,0); % End date
6436    
6437     dt = datenum(0,0,1,0,0,0); % Time step between input: 1 day
6438     %dt = datenum(0,0,2,0,0,0); % Time step between input: 2 days
6439     %dt = datenum(0,0,7,0,0,0); % Time step between input: 1 week
6440     %dt = datenum(0,0,0,12,0,0); % Time step between input: 12 hours
6441     IDend = ID + 1*dt; %
6442     nt = (IDend-ID)/dt;
6443    
6444     % Create TIME table:
6445     for it = 1 : nt
6446     ID = ID + dt;
6447     snapshot = datestr(ID,'yyyymmddHHMM'); % For twice-daily data
6448     % snapshot = datestr(ID,'yyyymmdd'); % For daily data
6449     TIME(it,:) = snapshot;
6450     end %for it
6451    
6452    
6453     % Some settings
6454     iso = 25.25; % Which sigma-theta surface ?
6455     getiso = 0; % We do not compute the isoST by default
6456     outimg = 'img_tmp'; % Output directory
6457     %outimg = 'img_tmp2'; % Output directory
6458     %outimg = 'img_tmp3'; % Output directory
6459     prtimg = 0; % Do we record figures as jpg files ?
6460    
6461     % Plot modules available:
6462     sub = get_plotlist('eg_view_Timeserie','.');
6463     disp('Available plots:')
6464     sub = get_plotlistdef('eg_view_Timeserie','.');
6465     disp('Set the variable <pl> in view_Timeserie.m with wanted plots')
6466    
6467     % Selected plots list:
6468     pl = [7]; %getiso=1;
6469    
6470     % Verif plots:
6471     disp(char(2));disp('You have choosed to plot:')
6472     for i = 1 : length(pl)
6473     disp(strcat(num2str(pl(i)),' -> ', sub(pl(i)).description ) )
6474     end
6475     s = input(' Are you sure ([y]/n) ?','s');
6476     if ~isempty(s) & s == 'n'
6477     return
6478     end
6479    
6480     % To find a specific date
6481     %find(str2num(TIME)==200103300000),break
6482    
6483     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6484     % Video loop:
6485     for it = 1 : nt
6486     snapshot = TIME(it,:);
6487     %titf='.section_32N';if ~exist(strcat(outimg,sla,'PV.',snapshot,titf,'.jpg'),'file')
6488    
6489     %%%%%%%%%%%%%%%%
6490     % NETCDF files name:
6491     filPV = 'PV';
6492     filST = 'SIGMATHETA';
6493     filT = 'THETA';
6494     filTx = 'TAUX';
6495     filTy = 'TAUY';
6496     filJFz = 'JFz';
6497     filJBz = 'JBz';
6498     filQnet = 'TFLUX';
6499     filQEk = 'QEk';
6500     %filMLD = 'KPPmld';
6501     filMLD = 'MLD';
6502     filOx = 'OMEGAX';
6503     filOy = 'OMEGAY';
6504     filZET = 'ZETA';
6505     filEKL = 'EKL';
6506    
6507    
6508     % Load fields:
6509     disp('load fields...')
6510     % (I keep proper axis for each variables in case of one day they would be different)
6511     ferfile = strcat(pathname,sla,snapshot,sla,filPV,'.',netcdf_domain,'.',ext);
6512     ncQ = netcdf(ferfile,'nowrite');
6513     [Qlon Qlat Qdpt] = coordfromnc(ncQ);
6514     Q = ncQ{4}(:,:,:); clear ncQ ferfile
6515     [nz ny nx] = size(Q);
6516     %Qdpt = -Qdpt;
6517    
6518     ferfile = strcat(pathname,sla,snapshot,sla,filZET,'.',netcdf_domain,'.',ext);
6519     ncZET = netcdf(ferfile,'nowrite');
6520     [ZETAlon ZETAlat ZETAdpt] = coordfromnc(ncZET);
6521     ZETA = ncZET{4}(:,:,:); clear ncZET ferfile
6522     % Move ZETA on the same grid as Q:
6523     ZETA = ( ZETA(:,:,2:nx-1) + ZETA(:,:,1:nx-2) )./2;
6524     ZETA = ( ZETA(:,2:ny-1,:) + ZETA(:,1:ny-2,:) )./2;
6525     ZETAlon = ( ZETAlon(2:nx-1) + ZETAlon(1:nx-2) )./2;
6526     ZETAlat = ( ZETAlat(2:ny-1) + ZETAlat(1:ny-2) )./2;
6527    
6528     ferfile = strcat(pathname,sla,snapshot,sla,filOx,'.',netcdf_domain,'.',ext);
6529     ncOX = netcdf(ferfile,'nowrite');
6530     [OXlon OXlat OXdpt] = coordfromnc(ncOX);
6531     OX = ncOX{4}(:,:,:); clear ncOX ferfile
6532     % Move OMEGAx on the same grid as Q:
6533     OX = ( OX(:,2:ny-1,:) + OX(:,1:ny-2,:) )./2;
6534     OX = ( OX(2:nz-1,:,:) + OX(1:nz-2,:,:) )./2;
6535     OXlat = ( OXlat(2:ny-1) + OXlat(1:ny-2) )./2;
6536     OXdpt = ( OXdpt(2:nz-1) + OXdpt(1:nz-2) )./2;
6537    
6538     ferfile = strcat(pathname,sla,snapshot,sla,filOy,'.',netcdf_domain,'.',ext);
6539     ncOY = netcdf(ferfile,'nowrite');
6540     [OYlon OYlat OYdpt] = coordfromnc(ncOY);
6541     OY = ncOY{4}(:,:,:); clear ncOY ferfile
6542     % Move OMEGAy on the same grid as Q:
6543     OY = ( OY(2:nz-1,:,:) + OY(1:nz-2,:,:) )./2;
6544     OY = ( OY(:,:,2:nx-1) + OY(:,:,1:nx-2) )./2;
6545     OYdpt = ( OYdpt(2:nz-1) + OYdpt(1:nz-2) )./2;
6546     OYlon = ( OYlon(2:nx-1) + OYlon(1:nx-2) )./2;
6547    
6548    
6549     ferfile = strcat(pathname,sla,snapshot,sla,filST,'.',netcdf_domain,'.',ext);
6550     ncST = netcdf(ferfile,'nowrite');
6551     [STlon STlat STdpt] = coordfromnc(ncST);
6552     ST = ncST{4}(:,:,:); clear ncST ferfile
6553    
6554     ferfile = strcat(pathname,sla,snapshot,sla,filT,'.',netcdf_domain,'.',ext);
6555     ncT = netcdf(ferfile,'nowrite');
6556     [Tlon Tlat Tdpt] = coordfromnc(ncT);
6557     T = ncT{4}(:,:,:); clear ncT ferfile
6558    
6559     ferfile = strcat(pathname,sla,snapshot,sla,filTx,'.',netcdf_domain,'.',ext);
6560     ncTx = netcdf(ferfile,'nowrite');
6561     [Txlon Txlat Txdpt] = coordfromnc(ncTx);
6562     Tx = ncTx{4}(1,:,:); clear ncTx ferfile
6563     ferfile = strcat(pathname,sla,snapshot,sla,filTy,'.',netcdf_domain,'.',ext);
6564     ncTy = netcdf(ferfile,'nowrite');
6565     [Tylon Tylat Tydpt] = coordfromnc(ncTy);
6566     Ty = ncTy{4}(1,:,:); clear ncTy ferfile
6567    
6568     ferfile = strcat(pathname,sla,snapshot,sla,filJFz,'.',netcdf_domain,'.',ext);
6569     ncJFz = netcdf(ferfile,'nowrite');
6570     [JFzlon JFzlat JFzdpt] = coordfromnc(ncJFz);
6571     JFz = ncJFz{4}(1,:,:);
6572    
6573     ferfile = strcat(pathname,sla,snapshot,sla,filJBz,'.',netcdf_domain,'.',ext);
6574     ncJBz = netcdf(ferfile,'nowrite');
6575     [JBzlon JBzlat JBzdpt] = coordfromnc(ncJBz);
6576     JBz = ncJBz{4}(1,:,:);
6577    
6578     ferfile = strcat(pathname,sla,snapshot,sla,filQnet,'.',netcdf_domain,'.',ext);
6579     ncQnet = netcdf(ferfile,'nowrite');
6580     [Qnetlon Qnetlat Qnetdpt] = coordfromnc(ncQnet);
6581     Qnet = ncQnet{4}(1,:,:);
6582     % $$$
6583     % $$$ ferfile = strcat(pathname,sla,snapshot,sla,filQEk,'.',netcdf_domain,'.',ext);
6584     % $$$ ncQEk = netcdf(ferfile,'nowrite');
6585     % $$$ [QEklon QEklat QEkdpt] = coordfromnc(ncQEk);
6586     % $$$ QEk = ncQEk{4}(1,:,:);
6587     % $$$
6588     ferfile = strcat(pathname,sla,snapshot,sla,filMLD,'.',netcdf_domain,'.',ext);
6589     ncMLD = netcdf(ferfile,'nowrite');
6590     [MLDlon MLDlat MLDdpt] = coordfromnc(ncMLD);
6591     MLD = ncMLD{4}(1,:,:);
6592    
6593     ferfile = strcat(pathname,sla,snapshot,sla,filEKL,'.',netcdf_domain,'.',ext);
6594     ncEKL = netcdf(ferfile,'nowrite');
6595     [EKLlon EKLlat EKLdpt] = coordfromnc(ncEKL);
6596     EKL = ncEKL{4}(1,:,:);
6597    
6598    
6599     %%%%%%%%%%%%%%%%
6600     % Q is defined on the same grid of ST but troncated by extrem 2 points, then here
6601     % make all fields defined with same limits...
6602     % In case of missing points, we add NaN.
6603     disp('Reshape them')
6604     ST = squeeze(ST(2:nz+1,2:ny+1,2:nx+1));
6605     STdpt = STdpt(2:nz+1);
6606     STlon = STlon(2:nx+1);
6607     STlat = STlat(2:ny+1);
6608     T = squeeze(T(2:nz+1,2:ny+1,2:nx+1));
6609     Tdpt = Tdpt(2:nz+1);
6610     Tlon = Tlon(2:nx+1);
6611     Tlat = Tlat(2:ny+1);
6612     JBz = squeeze(JBz(2:ny+1,2:nx+1));
6613     JBzlon = JBzlon(2:nx+1);
6614     JBzlat = JBzlat(2:ny+1);
6615     Qnet = squeeze(Qnet(2:ny+1,2:nx+1));
6616     Qnetlon = Qnetlon(2:nx+1);
6617     Qnetlat = Qnetlat(2:ny+1);
6618     MLD = squeeze(MLD(2:ny+1,2:nx+1));
6619     MLDlon = MLDlon(2:nx+1);
6620     MLDlat = MLDlat(2:ny+1);
6621     EKL = squeeze(EKL(2:ny+1,2:nx+1));
6622     EKLlon = EKLlon(2:nx+1);
6623     EKLlat = EKLlat(2:ny+1);
6624     ZETA = squeeze(ZETA(2:nz+1,:,:));
6625     ZETA = cat(2,ZETA,ones(size(ZETA,1),1,size(ZETA,3)).*NaN);
6626     ZETA = cat(2,ones(size(ZETA,1),1,size(ZETA,3)).*NaN,ZETA);
6627     ZETA = cat(3,ZETA,ones(size(ZETA,1),size(ZETA,2),1).*NaN);
6628     ZETA = cat(3,ones(size(ZETA,1),size(ZETA,2),1).*NaN,ZETA);
6629     ZETAdpt = ZETAdpt(2:nz+1);
6630     ZETAlon = STlon;
6631     ZETAlat = STlat;
6632     OX = squeeze(OX(:,:,2:nx+1));
6633     OX = cat(1,OX,ones(1,size(OX,2),size(OX,3)).*NaN);
6634     OX = cat(1,ones(1,size(OX,2),size(OX,3)).*NaN,OX);
6635     OX = cat(2,OX,ones(size(OX,1),1,size(OX,3)).*NaN);
6636     OX = cat(2,ones(size(OX,1),1,size(OX,3)).*NaN,OX);
6637     OXlon = STlon;
6638     OXlat = STlat;
6639     OXdpt = STdpt;
6640     OY = squeeze(OY(:,2:ny+1,:));
6641     OY = cat(1,OY,ones(1,size(OY,2),size(OY,3)).*NaN);
6642     OY = cat(1,ones(1,size(OY,2),size(OY,3)).*NaN,OY);
6643     OY = cat(3,OY,ones(size(OY,1),size(OY,2),1).*NaN);
6644     OY = cat(3,ones(size(OY,1),size(OY,2),1).*NaN,OY);
6645     OYlon = STlon;
6646     OYlat = STlat;
6647     OYdpt = STdpt;
6648    
6649    
6650     % Planetary vorticity:
6651     f = 2*(2*pi/86400)*sin(ZETAlat*pi/180);
6652     [a f c]=meshgrid(ZETAlon,f,ZETAdpt); clear a c
6653     f = permute(f,[3 1 2]);
6654    
6655     % Apply mask:
6656     MASK = ones(size(ST,1),size(ST,2),size(ST,3));
6657     MASK(find(isnan(ST))) = NaN;
6658     T = T.*MASK;
6659     Qnet = Qnet.*squeeze(MASK(1,:,:));
6660    
6661    
6662     % Grid:
6663     global domain subdomain1 subdomain2 subdomain3
6664     grid_setup
6665     subdomain = subdomain1;
6666    
6667    
6668     %%%%%%%%%%%%%%%%
6669     % Here we determine the isosurface and its depth:
6670     if getiso
6671     disp('Get iso-ST')
6672     [Iiso mask] = subfct_getisoS(ST,iso);
6673     Diso = ones(size(Iiso)).*NaN;
6674     Qiso = ones(size(Iiso)).*NaN;
6675     for ix = 1 : size(ST,3)
6676     for iy = 1 : size(ST,2)
6677     if ~isnan(Iiso(iy,ix)) & ~isnan( Q(Iiso(iy,ix),iy,ix) )
6678     Diso(iy,ix) = STdpt(Iiso(iy,ix));
6679     Qiso(iy,ix) = Q(Iiso(iy,ix),iy,ix);
6680     end %if
6681     end, end %for iy, ix
6682     end %if
6683    
6684    
6685    
6686     %%%%%%%%%%%%%%%%
6687     % "Normalise" the PV:
6688     fO = 2*(2*pi/86400)*sin(32*pi/180);
6689     dST = 27.6-25.4;
6690     H = -1000;
6691     RHOo = 1000;
6692     Qref = -fO/RHOo*dST/H;
6693     if getiso, QisoN = Qiso./Qref; end
6694    
6695    
6696     %%%%%%%%%%%%%%%%
6697     %%%%%%%%%%%%%%%%
6698     % Plots:
6699     disp('Plots ...')
6700    
6701    
6702     for i = 1 : length(pl)
6703     disp(strcat('Plotting module:',sub(pl(i)).name))
6704     eval(sub(pl(i)).name(1:end-2),'disp(''Oups scratch...'');return');
6705     end
6706    
6707    
6708     %%%%%%%%%%%%%%%%
6709     %%%%%%%%%%%%%%%%
6710    
6711     %else,disp(strcat('Skip:',snapshot));end
6712    
6713     fclose('all');
6714    
6715    
6716     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6717     end %for it
6718     gmaze_pv/visu/eg_view_Timeserie_pl1.m0000644002352600001440000003402010511523556017272 0ustar gmazeusers%DEF 1 var per figure
6719    
6720     % Map projection:
6721     m_proj('mercator','long',subdomain.limlon,'lat',subdomain.limlat);
6722     %m_proj('mercator','long',subdomain2.limlon,'lat',subdomain2.limlat);
6723     %m_proj('mercator','long',subdomain.limlon,'lat',[25 40]);
6724     %m_proj('mercator','long',[subdomain.limlon(1) 360-24],'lat',[25 50]);
6725    
6726     % Which variables to plot:
6727     wvar = [21 10 7 22];
6728     wvar = [12];
6729    
6730     for ip = 1 : length(wvar)
6731    
6732     figur(10+ip);clf;drawnow;hold on;iw=1;jw=1;
6733    
6734     % Variables loop:
6735     % Default:
6736     CBAR = 'v'; % Colorbar orientation
6737     Tcontour = [17 19]; Tcolor = [0 0 0]; % Theta contours
6738     Hcontour = -[0:200:600]; Hcolor = [0 0 0]; % MLD contours
6739     unit = ''; % Default unit
6740     load mapanom2 ; N = 256; c = [0 0]; cmap = jet; % Colormaping
6741     uselogmap = 1; % Use the log colormap
6742     showT = 1; % Iso-Theta contours
6743     showW = 0; % Windstress arrows
6744     showH = 0; colorW = 'w'; % Mixed Layer Depth
6745     showE = 0; colorE = 'w'; % Ekman Layer Depth
6746     showCLIM = 1; % Show CLIMODE region box
6747     showQnet = 0 ; Qnetcontour = [-1000:100:1000]; % Show the Net heat flux
6748     CONT = 0; % Contours instead of pcolor
6749     CONTshlab = 0; % Show label for contours plot
6750     CONTc = 0; % Highlighted contours instead of pcolor
6751     CONTcshlab = 0; % Show label for contours plot
6752     colorCOAST = [0 0 0]; % Land color
6753     SHADE = 'flat'; % shading option
6754    
6755     %if it==1, mini; end
6756     switch wvar(ip)
6757     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1
6758     case 1
6759     C = Diso;
6760     Clon = Qlon; Clat = Qlat;
6761     tit = strcat('Depth of \sigma_\theta=',num2str(iso),'kg.m^{-3}');
6762     showW = 0; % Windstress
6763     cx = [-600 0];
6764     unit = 'm';
6765     titf = 'Diso';
6766     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11
6767     case 11
6768     C = Qiso;
6769     %C(isnan(C)) = 10;
6770     Clon = Qlon; Clat = Qlat;
6771     tit = strcat('Full potential vorticity field on iso-\sigma=',num2str(iso));
6772     colorCOAST = [1 1 1]*.5; % Land color
6773     showW = 0; % Windstress
6774     showH = 0;
6775     showCLIM = 1;
6776     showT = 1;
6777     Tcontour = [22 22];
6778     N = 256;
6779     c = [1 5];
6780     cx = [-(1+2*c(1)) 1+2*c(2)]*5e-10; cmap = mapanom; %cmap = jet;
6781     unit = '1/m/s';
6782     titf = strcat('PViso_',num2str(iso));
6783     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12
6784     case 12
6785     % First iso-ST have been computed in view_Timeserie
6786     % Here is the 2nd one (supposed to be deeper than the 1st one)
6787     iso2 = 25.35;
6788     disp('Get 2nd iso-ST')
6789     [Iiso mask] = subfct_getisoS(ST,iso2);
6790     Diso1 = Diso;
6791     Diso2 = ones(size(Iiso)).*NaN;
6792     Qiso2 = ones(size(Iiso)).*NaN;
6793     for ix = 1 : size(ST,3)
6794     for iy = 1 : size(ST,2)
6795     if ~isnan(Iiso(iy,ix)) & ~isnan( Q(Iiso(iy,ix),iy,ix) )
6796     Diso2(iy,ix) = STdpt(Iiso(iy,ix));
6797     Qiso2(iy,ix) = Q(Iiso(iy,ix),iy,ix);
6798     end %if
6799     end, end %for iy, ix
6800     Diso1(isnan(squeeze(MASK(1,:,:)))) = NaN;
6801     Diso2(isnan(squeeze(MASK(1,:,:)))) = NaN;
6802     for ix = 1 : size(ST,3)
6803     for iy = 1 : size(ST,2)
6804     if isnan(Diso1(iy,ix)) & isnan(Diso2(iy,ix))
6805     Hbiso(iy,ix) = -Inf;
6806     elseif isnan(Diso1(iy,ix)) & ~isnan(Diso2(iy,ix))
6807     Hbiso(iy,ix) = Inf;
6808     elseif ~isnan(Diso1(iy,ix)) & ~isnan(Diso2(iy,ix))
6809     Hbiso(iy,ix) = Diso1(iy,ix) - Diso2(iy,ix);
6810     end
6811     end, end %for iy, ix
6812     Hbiso = Hbiso.*squeeze(MASK(1,:,:));
6813     %figur(1);pcolor(Diso1);shading flat;colorbar
6814     %figur(2);pcolor(Diso2);shading flat;colorbar
6815     %figur(3);pcolor(Hbiso);shading flat;colorbar
6816    
6817     C = Hbiso;
6818     %C(isnan(C)) = NaN;
6819     Clon = STlon; Clat = STlat;
6820     tit = strvcat(strcat('Height between iso-\sigma=',num2str(iso),...
6821     ' and: iso-\sigma=',num2str(iso2)),...
6822     strcat('(White areas are outcrops for both iso-\sigma and red areas only for: ',...
6823     num2str(iso),')'));
6824     colorCOAST = [1 1 0]*.8; % Land color
6825     showW = 1; colorW = 'k'; % Windstress
6826     showH = 0; % Mixed layer depth
6827     showCLIM = 1; % CLIMODE
6828     showT = 0; Tcontour = [21 23]; % THETA
6829     CONTc = 0; CONTcv = [0:0]; CONTcshlab = 1;
6830     showQnet = 1; Qnetcontour=[[-1000:200:-400] [400:200:1000]];
6831     cx = [0 300]; uselogmap = 0;
6832     cmap = [[1 1 1]; jet ; [1 0 0]];
6833     unit = 'm';
6834     titf = strcat('Hbiso_',num2str(iso),'_',num2str(iso2));
6835     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2
6836     case 2
6837     C = QisoN; % C = Qiso;
6838     Clon = Qlon; Clat = Qlat;
6839     tit = strcat(snapshot,'/ Potential vorticity field: q = (-f/\rho . d\sigma_\theta/dz) / q_{ref}');
6840     %tit = strcat(snapshot,'/ Potential vorticity field: q = - f . d\sigma_\theta/dz / \rho');
6841     showW = 0; % Windstress
6842     cx = [0 1]*10;
6843     unit = char(1);
6844     titf = 'PVisoN';
6845    
6846     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 21
6847     case 21
6848     C = squeeze(Q(1,:,:));
6849     Clon = Qlon; Clat = Qlat;
6850     tit = strcat('Surface potential vorticity field');
6851     showW = 0; % Windstress
6852     showH = 0;
6853     showCLIM = 1;
6854     N = 256;
6855     c = [1 12]; cx = [-(1+2*c(1)) 1+2*c(2)]*1e-14; cmap = mapanom; % ecco2_bin1
6856     c = [1 12]; cx = [-(1+2*c(1)) 1+2*c(2)]*1e-11; cmap = mapanom; % ecco2_bin2
6857     unit = '1/m/s';
6858     titf = 'PV.Lsurface';
6859     %SHADE = 'interp';
6860    
6861     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22
6862     case 22
6863     C = squeeze(Q(11,:,:));
6864     Clon = Qlon; Clat = Qlat;
6865     tit = strcat('Full potential vorticity field (-115m)');
6866     showW = 0; % Windstress
6867     N = 32;
6868     c = [1 12];
6869     c = [1 12]; cx = [-(1+2*c(1)) 1+2*c(2)]*1e-14; cmap = mapanom; % ecco2_bin1
6870     c = [1 12]; cx = [-(1+2*c(1)) 1+2*c(2)]*1e-11; cmap = mapanom; % ecco2_bin2
6871     unit = '1/m/s';
6872     titf = 'PV.L115';
6873     colorCOAST = [1 1 1]*.5;
6874    
6875     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3
6876     case 3
6877     C = JFz;
6878     Clon = JFzlon; Clat = JFzlat;
6879     %tit = strcat(snapshot,'/ Mechanical PV flux J^F_z and windstress');
6880     tit = strvcat(['Mechanical PV flux J^F_z (positive upward), Ekman layer depth (green contours' ...
6881     ' m)'],'and windstress (black arrows)');
6882     %Tcolor = [0 0 0];
6883     showW = 1; % Windstress
6884     colorW = 'k';
6885     showE = 1;
6886     Econtour = [10 20:20:200];
6887     N = 256;
6888     c = [1 1];
6889     cx = [-(1+2*c(1)) 1+2*c(2)]*1e-11; cmap = mapanom; %cmap = jet;
6890     %cx = [-1 1]*10^(-11);
6891     unit = 'kg/m^3/s^2';
6892     titf = 'JFz';
6893     showCLIM = 1;
6894    
6895     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4
6896    
6897     case 4
6898     C = JBz;
6899     Clon = JBzlon; Clat = JBzlat;
6900     tit = strcat(snapshot,'/ Diabatic PV flux J^B_z and windstress');
6901     showW = 1; % Windstress
6902     cx = [-1 1]*10^(-11);
6903     unit = 'kg/m^3/s^2';
6904     titf = 'JBz';
6905    
6906     case 5
6907     C = Qnet;
6908     Clon = Qnetlon; Clat = Qnetlat;
6909     tit = ['Net surface heat flux Q_{net} (positive downward), mixed layer depth (green contours,' ...
6910     ' m) and windstress (black arrows)'];
6911     tit = ['Net surface heat flux Q_{net} (positive downward), and windstress (black arrows)'];
6912     showH = 0;
6913     Hcontour = -[100 200:200:600];
6914     showT = 0;
6915     showW = 1; colorW = 'k';
6916     N = 256;
6917     c = [1 1]; cx = [-(1+2*c(1)) 1+2*c(2)]*200; cmap = mapanom;
6918     %cx = [-1 1]*500;
6919     cmap = mapanom;
6920     unit = 'W/m^2';
6921     titf = 'Qnet';
6922     showCLIM = 1;
6923     colorCOAST = [0 0 0];
6924    
6925     case 6
6926     C = JFz./JBz;
6927     Clon = JFzlon; Clat = JFzlat;
6928     tit = strcat(snapshot,'/ Ratio: J^F_z/J^B_z');
6929     cx = [-1 1]*5;
6930     unit = char(1);
6931     titf = 'JFz_vs_JBz';
6932    
6933     case 7
6934     C = squeeze(ST(1,:,:));
6935     C(isnan(C)) = 0;
6936     Clon = STlon; Clat = STlat;
6937     tit = strcat('Surface Potential density \sigma_\theta ');
6938     showT = 0; %
6939     cmap = flipud(hot);
6940     CONT = 1; CONTv = [20:.2:30]; CONTshlab = 0;
6941     CONTc = 1; CONTcv = [20:1:30]; CONTcshlab = 1;
6942     cx = [23 28];
6943     unit = 'kg/m^3';
6944     titf = 'SIGMATHETA';
6945     colorCOAST = [1 1 1]*.5;
6946    
6947     case 8
6948     C = squeeze(ZETA(1,:,:));
6949     Clon = ZETAlon; Clat = ZETAlat;
6950     tit = strcat('Surface relative vorticity');
6951     showW = 0; % Windstress
6952     showH = 0;
6953     showCLIM = 1;
6954     N = 256;
6955     c = [0 0];
6956     cx = [-(1+2*c(1)) 1+2*c(2)]*6e-5; cmap = mapanom;
6957     unit = '1/s';
6958     titf = 'ZETA';
6959    
6960     case 9
6961     C = abs(squeeze(ZETA(1,:,:))./squeeze(f(1,:,:)));
6962     Clon = ZETAlon; Clat = ZETAlat;
6963     tit = strcat('Absolute ratio between relative and planetary vorticity');
6964     showW = 0; % Windstress
6965     showH = 0;
6966     showCLIM = 1;
6967     N = 256;
6968     c = [0 1];
6969     cx = [0 1+3*c(2)];
6970     cmap = flipud(hot); cmap = mapanom;
6971     unit = '';
6972     titf = 'ZETA_vs_f';
6973    
6974     case 10
6975     C = squeeze(T(1,:,:));
6976     Clon = Tlon; Clat = Tlat;
6977     tit = strcat('Surface Potential temperature \theta ');
6978     showT = 0; %
6979     N = 256; c = [0 0];
6980     cmap = flipud(hot); cmap = jet;
6981     CONT = 0; CONTv = [0:1:40]; CONTshlab = 0;
6982     CONTc = 1; CONTcv = [0:1:40]; CONTcshlab = 1;
6983     cx = [0 30];
6984     unit = '^oK';
6985     titf = 'THETA';
6986     colorCOAST = [1 1 1]*.5;
6987    
6988    
6989     end %switch what to plot
6990    
6991     % Draw variable:
6992     sp=subplot(iw,jw,1);hold on
6993     if CONT ~= 1
6994     m_pcolor(Clon,Clat,C);
6995     shading(SHADE);
6996     if uselogmap
6997     colormap(logcolormap(N,c(1),c(2),cmap));
6998     else
6999     colormap(cmap);
7000     end
7001    
7002     if wvar(ip) == 10
7003     if CONTc
7004     clear cs h csh
7005     EDW = [21:23];
7006     [cs,h] = m_contour(Clon,Clat,C,CONTcv,'k');
7007     csh = clabel(cs,h,'fontsize',8,'labelspacing',800);
7008     set(csh,'visible','on');
7009     for ih = 1 : length(h)
7010     if find(EDW == get(h(ih),'Userdata'))
7011     set(h(ih),'linewidth',1.5)
7012     end %if
7013     if find(EDW(2) == get(h(ih),'Userdata'))
7014     set(h(ih),'linestyle','--')
7015     end %if
7016     end %for
7017     for icsh = 1 : length(csh)
7018     if find(EDW == get(csh(icsh),'userdata') )
7019     set(csh(icsh),'visible','on');
7020     end %if
7021     end %for
7022     end %if CONTc
7023     end % if ST
7024    
7025     else
7026     clear cs h csh
7027     [cs,h] = m_contourf(Clon,Clat,C,CONTv);
7028     if uselogmap
7029     colormap(mycolormap(logcolormap(N,c(1),c(2),cmap),length(CONTv)));
7030     else
7031     colormap(mycolormap(cmap,length(CONTv)));
7032     end
7033     csh = clabel(cs,h,'fontsize',8,'labelspacing',800);
7034     set(csh,'visible','off');
7035     if CONTshlab
7036     set(csh,'visible','on');
7037     end
7038     if CONTc
7039     for ih = 1 : length(h)
7040     if find(CONTcv == get(h(ih),'CData'))
7041     set(h(ih),'linewidth',1.5)
7042     end
7043     end
7044     if CONTcshlab
7045     for ih = 1 : length(csh)
7046     if find(CONTcv == str2num( get(csh(ih),'string') ) )
7047     set(csh(ih),'visible','on','color','k','fontsize',8);
7048     set(csh(ih),'fontweight','bold','margin',1e-3);
7049     end
7050     end
7051     end
7052     end
7053     end
7054     caxis(cx);
7055     ccol(ip) = colorbar(CBAR,'fontsize',10);
7056     ctitle(ccol(ip),unit);
7057     title(tit);
7058     m_coast('patch',colorCOAST);
7059     m_grid('xtick',360-[20:5:80],'ytick',[20:2:50]);
7060     set(gcf,'name',titf);
7061    
7062     if wvar == 5 % Qnet (Positions depend on map limits !)
7063     yy=get(ccol,'ylabel');
7064     set(yy,'string','Cooling Warming');
7065     set(yy,'fontweight','bold');
7066     end %if
7067    
7068     if showT
7069     clear cs h
7070     [cs,h] = m_contour(Tlon,Tlat,squeeze(T(1,:,:)),Tcontour);
7071     clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',200);
7072     for ih=1:length(h)
7073     set(h(ih),'edgecolor',Tcolor,'linewidth',1.2);
7074     end
7075     end %if show THETA contours
7076    
7077     if showQnet
7078     clear cs h
7079     CQnet = Qnet;
7080     if wvar(ip) == 12
7081     %CQnet(isnan(C)) = NaN;
7082     end
7083     [cs,h] = m_contour(Qnetlon,Qnetlat,CQnet,Qnetcontour);
7084     Qnetmap = mycolormap(mapanom,length(Qnetcontour));
7085     if ~isempty(cs)
7086     clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',200);
7087     for ih=1:length(h)
7088     val = get(h(ih),'userdata');
7089     set(h(ih),'edgecolor',Qnetmap( find(Qnetcontour == val) ,:),'linewidth',1);
7090     end
7091     end
7092     end %if show Qnet contours
7093    
7094     if showW
7095     dx = 10*diff(Txlon(1:2)); dy = 8*diff(Txlat(1:2));
7096     dx = 20*diff(Txlon(1:2)); dy = 10*diff(Txlat(1:2));
7097     lo = [Txlon(1):dx:Txlon(length(Txlon))];
7098     la = [Txlat(1):dy:Txlat(length(Txlat))];
7099     [lo la] = meshgrid(lo,la);
7100     Txn = interp2(Txlat,Txlon,Tx',la,lo);
7101     Tyn = interp2(Txlat,Txlon,Ty',la,lo);
7102     s = 2;
7103     m_quiver(lo,la,Txn,Tyn,s,colorW,'linewidth',1.25);
7104     % m_quiver(lo,la,-(1+sin(la*pi/180)).*Txn,(1+sin(la*pi/180)).*Tyn,s,'w');
7105     m_quiver(360-82,37,1,0,s,'w','linewidth',1.25);
7106     m_text(360-82,38,'1 N/m^2','color','w');
7107     end %if show windstress
7108    
7109     if showH
7110     clear cs h
7111     %[cs,h] = m_contour(MLDlon,MLDlat,MLD,Hcontour);
7112     cm = flipud(mycolormap(jet,length(Hcontour)));
7113     cm = mycolormap([linspace(0,0,20); linspace(1,.5,20) ;linspace(0,0,20)]',length(Hcontour));
7114     cm = [0 1 0 ; 0 .6 0 ; 0 .2 0 ; 0 0 0];
7115     for ii = 1 : length(Hcontour)
7116     [cs,h] = m_contour(MLDlon,MLDlat,MLD,[1 1]*Hcontour(ii));
7117     if ~isempty(cs)
7118     % clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',300);
7119     clabel(cs,h,'fontsize',8,'color',cm(ii,:),'labelspacing',600,'fontweight','bold');
7120     for ih=1:length(h)
7121     % set(h(ih),'edgecolor',Hcolor,'linewidth',1);
7122     set(h(ih),'edgecolor',cm(ii,:),'linewidth',1.2);
7123     end
7124     end
7125     end
7126     end %if show Mixed Layer depth
7127    
7128     if showE
7129     clear cs h
7130     %[cs,h] = m_contour(EKLlon,EKLlat,EKL,Econtour);
7131     %cm = flipud(mycolormap(jet,length(Econtour)));
7132     n = length(Econtour);
7133     cm = flipud([linspace(0,0,n); linspace(1,0,n) ;linspace(0,0,n)]');
7134     %cm = [0 1 0 ; 0 .6 0 ; 0 .2 0 ; 0 0 0];
7135     for ii = 1 : length(Econtour)
7136     [cs,h] = m_contour(EKLlon,EKLlat,EKL,[1 1]*Econtour(ii));
7137     if ~isempty(cs)
7138     % clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',300);
7139     cl=clabel(cs,h,'fontsize',8,'color',cm(ii,:),'labelspacing',600,'fontweight','bold');
7140     for ih = 1 : length(h)
7141     % set(h(ih),'edgecolor',Ecolor,'linewidth',1);
7142     set(h(ih),'edgecolor',cm(ii,:),'linewidth',1.2);
7143     end
7144     end
7145     end
7146     end %if show Ekman Layer depth
7147    
7148     if showCLIM
7149     m_line(360-[71 62 62 71 71],[36 36 40.5 40.5 36],'color','r','linewidth',1.5)
7150     end
7151    
7152    
7153     if 1 % Show the date in big in the upper left corner
7154     spp=subplot('position',[0 .95 .25 .05]);
7155     p=patch([0 1 1 0],[0 0 1 1],'w');
7156     set(spp,'ytick',[],'xtick',[]);
7157     set(spp,'box','off');
7158     dat = num2str(TIME(it,:));
7159     dat = strcat(dat(1:4),'/',dat(5:6),'/',dat(7:8),':',dat(9:10),'H',dat(11:12));
7160     text(0.1,.5,dat,'fontsize',16,...
7161     'fontweight','bold','color','r','verticalalign','middle');
7162     end
7163    
7164     %%%%%%%%%%%%%%%%
7165     drawnow
7166     set(gcf,'position',[4 48 888 430]);
7167     %videotimeline(num2str(zeros(size(TIME,1),1)),it,'b')
7168     set(gcf,'color','white')
7169     set(findobj('tag','m_grid_color'),'facecolor','none')
7170     if prtimg
7171     set(gcf,'paperposition',[0.6 6.5 25 14]);
7172     %print(gcf,'-djpeg100',strcat(outimg,sla,titf,'.',snapshot,'.jpg'));
7173     exportj(gcf,0,strcat(outimg,sla,titf,'.',snapshot));
7174     end %if
7175    
7176    
7177     end %for ip
7178    
7179     gmaze_pv/visu/eg_view_Timeserie_pl2.m0000644002352600001440000001207410511523556017300 0ustar gmazeusers%DEF All components of the relative vorticity
7180    
7181     % Map projection:
7182     m_proj('mercator','long',subdomain.limlon,'lat',subdomain.limlat);
7183     %m_proj('mercator','long',subdomain2.limlon,'lat',subdomain2.limlat);
7184     %m_proj('mercator','long',subdomain.limlon,'lat',[25 40]);
7185     %m_proj('mercator','long',[subdomain.limlon(1) 360-24],'lat',[25 50]);
7186    
7187     % Which variables to plot:
7188     wvar = [1:3];
7189     iz = 2; % Surface
7190     %iz = 6; % Core of the Gulf Stream
7191     %iz = 22; % Under the Gulf Stream
7192    
7193     figure(12);clf;hold on;iw=1;jw=length(wvar);
7194    
7195     for ip = 1 : length(wvar)
7196    
7197     % Variables loop:
7198     % Default:
7199     CBAR = 'h'; % Colorbar orientation
7200     Tcontour = [17 19]; Tcolor = [0 0 0]; % Theta contours
7201     Hcontour = -[0:200:600]; Hcolor = [0 0 0]; % MLD contours
7202     unit = ''; % Default unit
7203     load mapanom2 ; N = 256; c = [0 0]; cmap = jet; % Colormaping
7204     showT = 1; % Iso-Theta contours
7205     showW = 0; % Windstress arrows
7206     showH = 0; colorW = 'w'; % Mixed Layer Depth
7207     showCLIM = 0; % Show CLIMODE region box
7208     CONT = 0; % Contours instead of pcolor
7209     CONTshlab = 0; % Show label for contours plot
7210     colorCOAST = [0 0 0]; % Land color
7211     SHADE = 'flat'; % shading option
7212    
7213     N = 32;
7214     c = [12 30];
7215     cx = [-(1+2*c(1)) 1+2*c(2)]*6e-5; cmap = mapanom;
7216     titf = 'OMEGA';
7217    
7218     switch wvar(ip)
7219     case 1
7220     C = -squeeze(OX(iz,:,:));
7221     Clon = OXlon; Clat = OXlat;
7222     tit = strcat('\omega_x = - \partial v / \partial z');
7223     showW = 0; % Windstress
7224     showH = 0;
7225     showCLIM = 1;
7226     unit = '1/s';
7227     case 2
7228     C = -squeeze(OY(iz,:,:));
7229     Clon = OYlon; Clat = OYlat;
7230     tit = strcat('\omega_y = \partial u / \partial z');
7231     showW = 0; % Windstress
7232     showH = 0;
7233     showCLIM = 1;
7234     %N = 256;
7235     %c = [10 10];
7236     %cx = [-(1+2*c(1)) 1+2*c(2)]*6e-5; cmap = mapanom;
7237     unit = '1/s';
7238     case 3
7239     C = squeeze(ZETA(iz,:,:));
7240     Clon = ZETAlon; Clat = ZETAlat;
7241     tit = strcat('\zeta = \partial v / \partial x - \partial u / \partial y');
7242     showW = 0; % Windstress
7243     showH = 0;
7244     showCLIM = 1;
7245     %N = 256;
7246     %c = [10 10];
7247     %cx = [-(1+2*c(1)) 1+2*c(2)]*6e-5; cmap = mapanom;
7248     unit = '1/s';
7249     end %switch what to plot
7250    
7251    
7252     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7253     % Draw variable:
7254     sp=subplot(iw,jw,ip);hold on
7255     if CONT ~= 1
7256     m_pcolor(Clon,Clat,C);
7257     shading(SHADE);
7258     colormap(logcolormap(N,c(1),c(2),cmap));
7259     else
7260     [cs,h] = m_contourf(Clon,Clat,C,CONTv);
7261     colormap(mycolormap(logcolormap(N,c(1),c(2),cmap),length(CONTv)));
7262     if CONTshlab
7263     clabel(cs,h,'labelspacing',200,'fontsize',8)
7264     end
7265     end
7266     caxis(cx);
7267     if ip == 2
7268     ccol = colorbar(CBAR,'fontsize',10);
7269     ctitle(ccol,unit);
7270     posiC = get(ccol,'position');
7271     set(ccol,'position',[.2 posiC(2) 1-2*.2 .02]);
7272     end
7273     title(tit);
7274     m_coast('patch',colorCOAST);
7275     m_grid('xtick',360-[20:5:80],'ytick',[20:2:50]);
7276     set(gcf,'name',titf);
7277    
7278    
7279     if showT
7280     [cs,h] = m_contour(Tlon,Tlat,squeeze(T(1,:,:)),Tcontour);
7281     clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',200);
7282     for ih=1:length(h)
7283     set(h(ih),'edgecolor',Tcolor,'linewidth',1);
7284     end
7285     end %if show THETA contours
7286    
7287     if showW
7288     dx = 10*diff(Txlon(1:2)); dy = 8*diff(Txlat(1:2));
7289     dx = 20*diff(Txlon(1:2)); dy = 10*diff(Txlat(1:2));
7290     lo = [Txlon(1):dx:Txlon(length(Txlon))];
7291     la = [Txlat(1):dy:Txlat(length(Txlat))];
7292     [lo la] = meshgrid(lo,la);
7293     Txn = interp2(Txlat,Txlon,Tx',la,lo);
7294     Tyn = interp2(Txlat,Txlon,Ty',la,lo);
7295     s = 2;
7296     m_quiver(lo,la,Txn,Tyn,s,colorW,'linewidth',1.25);
7297     % m_quiver(lo,la,-(1+sin(la*pi/180)).*Txn,(1+sin(la*pi/180)).*Tyn,s,'w');
7298     m_quiver(360-84,47,1,0,s,'w','linewidth',1.25);
7299     m_text(360-84,48,'1 N/m^2','color','w');
7300     end %if show windstress
7301    
7302     if showH
7303     %[cs,h] = m_contour(MLDlon,MLDlat,MLD,Hcontour);
7304     cm = flipud(mycolormap(jet,length(Hcontour)));
7305     cm = mycolormap([linspace(0,0,20); linspace(1,.5,20) ;linspace(0,0,20)]',length(Hcontour));
7306     cm = [0 1 0 ; 0 .6 0 ; 0 .2 0 ; 0 0 0];
7307     for ii = 1 : length(Hcontour)
7308     [cs,h] = m_contour(MLDlon,MLDlat,MLD,[1 1]*Hcontour(ii));
7309     if ~isempty(cs)
7310     % clabel(cs,h,'fontsize',8,'color',[0 0 0],'labelspacing',300);
7311     clabel(cs,h,'fontsize',8,'color',cm(ii,:),'labelspacing',600,'fontweight','bold');
7312     for ih=1:length(h)
7313     % set(h(ih),'edgecolor',Hcolor,'linewidth',1);
7314     set(h(ih),'edgecolor',cm(ii,:),'linewidth',1.2);
7315     end
7316     end
7317     end
7318     end %if show Mixed Layer depth
7319    
7320     if showCLIM
7321     m_line(360-[71 62 62 71 71],[36 36 40.5 40.5 36],'color','r','linewidth',1.5)
7322     end
7323    
7324     %suptitle(strcat('Relative vorticity component at depth:',num2str(OYdpt(iz)),'m'));
7325    
7326    
7327     end %for ip
7328     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7329    
7330     if 1 % Show the date in big in the upper left corner
7331     spp=subplot('position',[0 .95 .25 .05]);
7332     p=patch([0 1 1 0],[0 0 1 1],'w');
7333     set(spp,'ytick',[],'xtick',[]);
7334     set(spp,'box','off');
7335     text(0.1,.5,num2str(TIME(it,:)),'fontsize',16,...
7336     'fontweight','bold','color','r','verticalalign','middle');
7337     end
7338    
7339    
7340     %%%%%%%%%%%%%%%%
7341     drawnow
7342     set(gcf,'position',[4 48 888 430]);
7343     videotimeline(num2str(zeros(size(TIME,1),1)),it,'b')
7344     %videotimeline(TIME,it,'b')
7345     if prtimg
7346     set(gcf,'color','white')
7347     set(findobj('tag','m_grid_color'),'facecolor','none')
7348     set(gcf,'paperposition',[0.6 6.5 25 14]);
7349     exportj(gcf,1,strcat(outimg,sla,titf,'.',snapshot));
7350     end %if
7351    
7352     gmaze_pv/visu/eg_view_Timeserie_pl3.m0000644002352600001440000001207010511523556017275 0ustar gmazeusers%DEF Field projection on 3D surface
7353    
7354    
7355     % Which variables to plot:
7356     %wvar = [1 2 3 4 6];
7357     wvar = [1];
7358    
7359     for ip = 1 : length(wvar)
7360    
7361     figure(30+ip);clf;hold on;iw=1;jw=1;
7362    
7363     % Variables loop:
7364     % Default:
7365     CBAR = 'v'; % Colorbar orientation
7366     Tcontour = [17 19]; Tcolor = [0 0 0]; % Theta contours
7367     Hcontour = -[0:200:600]; Hcolor = [0 0 0]; % MLD contours
7368     unit = ''; % Default unit
7369     load mapanom2 ; N = 256; c = [0 0]; cmap = jet; % Colormaping
7370     showT = 1; % Iso-Theta contours
7371     showW = 0; % Windstress arrows
7372     showH = 0; colorW = 'w'; % Mixed Layer Depth
7373     showCLIM = 0; % Show CLIMODE region box
7374     CONT = 0; % Contours instead of pcolor
7375     CONTshlab = 0; % Show label for contours plot
7376     colorCOAST = [0 0 0]; % Land color
7377    
7378     %if it==1, mini; end
7379     switch wvar(ip)
7380    
7381     end %switch what to plot
7382    
7383     C = Diso;
7384     Clon = STlon;
7385     Clat = STlat;
7386     % Replace land by zero:
7387     STs = squeeze(ST(1,:,:));
7388     %C(isnan(STs)) = 0;
7389    
7390     C2 = Qiso;
7391     % Replace land by zero:
7392     Qs = squeeze(Q(1,:,:));
7393     C2(isnan(Qs)) = 0;
7394     % Replace ocean surface area of Diso by surface value of Q:
7395     %C2(isnan(C)) = -10;
7396     C2(isnan(C)) = Qs(isnan(C));
7397    
7398     % Then replace NaN surface value of Diso by 0
7399     C(isnan(C)) = 0;
7400     C2(isnan(C2)) = 10;
7401    
7402     LON = [min(Clon) max(Clon)];
7403     LAT = [min(Clat) max(Clat)];
7404     %LON = [277 299];
7405     LAT = [26 40];
7406     C = squeeze(C( max(find(Clat<=LAT(1))):max(find(Clat<=LAT(2))) , : ));
7407     C = squeeze(C( : , max(find(Clon<=LON(1))):max(find(Clon<=LON(2))) ));
7408     C2=squeeze(C2( max(find(Clat<=LAT(1))):max(find(Clat<=LAT(2))) , : ));
7409     C2=squeeze(C2( : , max(find(Clon<=LON(1))):max(find(Clon<=LON(2)))));
7410     Clon = squeeze(Clon( max(find(Clon<=LON(1))):max(find(Clon<=LON(2))) ));
7411     Clat = squeeze(Clat( max(find(Clat<=LAT(1))):max(find(Clat<=LAT(2))) ));
7412    
7413    
7414    
7415     if 0
7416     nlon = length(Clon);
7417     nlat = length(Clat);
7418     [lati longi] = meshgrid(Clat,Clon);
7419     %longi = longi'; lati = lati';
7420    
7421     new_dimension = fix([1*nlon .5*nlat]);
7422     n_nlon = new_dimension(1);
7423     n_nlat = new_dimension(2);
7424     n_Clon = interp1(Clon,[1:fix(nlon/n_nlon):nlon],'cubic')';
7425     n_Clat = interp1(Clat,[1:fix(nlat/n_nlat):nlat],'cubic')';
7426     [n_lati n_longi] = meshgrid(n_Clat,n_Clon);
7427     n_lati = n_lati'; n_longi = n_longi';
7428    
7429     n_C = interp2(lati,longi,C',n_lati,n_longi,'spline');
7430    
7431     n_C(find(n_C==0)) = NaN;
7432     n_C = lisse(n_C,5,5);
7433    
7434     end %if
7435    
7436    
7437     %C(find(C==0)) = NaN;
7438     %C = lisse(C,2,2);
7439     %C2 = lisse(C2,2,2);
7440    
7441     % Map projection:
7442     %m_proj('mercator','long',subdomain.limlon,'lat',subdomain.limlat);
7443     %m_proj('mercator','long',subdomain.limlon,'lat',[25 40]);
7444     %m_proj('mercator','long',[subdomain.limlon(1) 360-24],'lat',[25 50]);
7445     %m_proj('mercator','long',Clon([1 length(Clon)])','lat',Clat([1 length(Clat)])');
7446     %m_proj('mercator','long',Clon([1 length(Clon)])','lat',[15 40]);
7447     %m_proj('mercator','long',[275 330],'lat',[15 40]);
7448    
7449     camx = [-200:20:200];
7450     az = [-30:10:30];
7451     az = 5;
7452     el = linspace(5,50,length(az));
7453     el = 20*ones(1,length(az));
7454    
7455     for ii = 1 : length(az)
7456    
7457     clf
7458     %surf(n_Clon,n_Clat,n_C);
7459     s=surf(Clon,Clat,C);
7460     %[X,Y] = m_ll2xy(Clon,Clat);
7461     %s=surf(X,Y,C);
7462    
7463     set(s,'cdata',C2);
7464     N = 32;
7465     %c = [1 30];
7466     %cx = [-(1+2*c(1)) 1+2*c(2)]*1.5e-12; cmap = mapanom; cmap = jet;
7467     c = [0 12];
7468     cx = [-(1+2*c(1)) 1+2*c(2)]*.95*1e-9; cmap = mapanom; %cmap = jet;
7469     cmap = [logcolormap(N,c(1),c(2),cmap); .3 .3 .3]; % Last value is for NaN
7470     %cmap = 1 - cmap;
7471     colormap(cmap);
7472     caxis(cx); %colorbar
7473    
7474    
7475     shading interp
7476     view(az(ii),el(ii))
7477     %set(gca,'ylim',[15 40]);
7478     %set(gca,'xlim',[275 330]);
7479     grid on
7480     xlabel('Longitude');
7481     ylabel('Latitude');
7482     zlabel('Depth');
7483    
7484     %h = camlight('left'); %set(h,'color',[0 0 0]);
7485     %camlight
7486     l=light('position',[0 0 1]);
7487     light('position',[0 0 -1]);
7488     %set(h,'position',[150 -200 2000]);
7489     %set(h,'style','infinite')
7490     lighting flat
7491     material dull
7492    
7493     %set(gca,'plotBoxAspectRatio',[2 2 .5])
7494     %m_coast('color',[0 0 0])
7495     camzoom(2)
7496     camzoom(1.25)
7497    
7498     set(gca,'plotBoxAspectRatio',[2 2 .25])
7499     set(gca,'visible','off');
7500     %camzoom(1.1)
7501     %for ix=1:length(camx)
7502     % set(h,'position',[camx(ix) -200 2000]);
7503     % refresh;drawnow
7504     %M(ii) = getframe;
7505     %end
7506    
7507    
7508     if 0
7509     xlim = get(gca,'xlim');
7510     ylim = get(gca,'ylim');
7511     lC=[0 0 1];
7512     for x = 280:10:340
7513     if x >= xlim(1) & x <= xlim(2)
7514     line([1 1]*x,ylim,'color',lC);
7515     end
7516     end %for x
7517     for y = 0 : 10 : 90
7518     if y >= ylim(1) & y <= ylim(2)
7519     line(xlim,[1 1]*y,'color',lC)
7520     end
7521     end %for y
7522     end
7523    
7524    
7525     if 1 % Show the date in big in the upper left corner
7526     spp=subplot('position',[0 .95 .25 .05]);
7527     p=patch([0 1 1 0],[0 0 1 1],'w');
7528     set(spp,'ytick',[],'xtick',[]);
7529     set(spp,'box','off');
7530     dat = num2str(TIME(it,:));
7531     dat = strcat(dat(1:4),'/',dat(5:6),'/',dat(7:8),':',dat(9:10),'H',dat(11:12));
7532     text(0.1,.5,dat,'fontsize',16,...
7533     'fontweight','bold','color','r','verticalalign','middle');
7534     end
7535    
7536     end
7537     %return
7538    
7539     %%%%%%%%%%%%%%%%
7540     drawnow
7541     set(gcf,'position',[4 48 888 430]);
7542     %videotimeline(TIME,it,'b')
7543     %videotimeline(num2str(zeros(size(TIME,1),1)),it,'b')
7544     set(gcf,'color','white')
7545     if prtimg
7546     %set(findobj('tag','m_grid_color'),'facecolor','none')
7547     set(gcf,'paperposition',[0.6 6.5 25 14]);
7548     titf='3Dview';
7549     exportj(gcf,1,strcat(outimg,sla,titf,'.',snapshot));
7550     end %if
7551    
7552     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
7553    
7554    
7555    
7556    
7557     end %for ip
7558     gmaze_pv/visu/get_plotlistdef.m0000644002352600001440000000264610513537642016267 0ustar gmazeusers%
7559     % get_plotlistdef(MASTER,SUBDIR)
7560     %
7561     % This function display description of pre-defined plots
7562     % available with the MASTER.m in the folder SUBDIR
7563     %
7564     % 07/12/06
7565     % gmaze@mit.edu
7566    
7567     function LIST = get_plotlistdef(MASTER,SUBDIR)
7568    
7569     global sla
7570    
7571     % Define suffixe of plot module:
7572     suff = '_pl';
7573    
7574    
7575     d = dir(SUBDIR);
7576     ii = 0;
7577     % Select Matlab files:
7578     for id = 1 : length(d)
7579     en = length( d(id).name );
7580     if en~=1 & (d(id).name(en-1:en) == '.m') & ~d(id).isdir
7581     ii = ii + 1;
7582     l(ii).name = d(id).name;
7583     end
7584     end
7585    
7586     % Select Matlab files with MASTER as prefix
7587     ii = 0;
7588     for il = 1 : length(l)
7589     fil = l(il).name;
7590     pref = strcat(MASTER,suff);
7591     iM = findstr( strcat(SUBDIR,sla,fil) , pref ) ;
7592    
7593     if ~isempty(iM)
7594     ii = ii + 1;
7595     LIST(ii).name = l(il).name;
7596     LIST(ii).index = ii;
7597    
7598     % Recup description of plot module:
7599     fid = fopen(strcat(SUBDIR,sla,fil));
7600     thatsit = 0;
7601     while thatsit ~= 1
7602     tline = fgetl(fid);
7603     if tline ~= -1
7604     if length(tline)>4 & tline(1:4) == '%DEF'
7605     LIST(ii).description = tline(5:end);
7606     thatsit = 1;
7607     end %if
7608     else
7609     LIST(ii).description = 'Not found';
7610     thatsit = 1;
7611     end %if
7612     end %while
7613     disp(strcat( num2str(LIST(ii).index),': Module extension :',fil(length(MASTER)+2:end-2)));
7614     disp(strcat('|-----> description :' , LIST(ii).description ));
7615     disp(char(2))
7616    
7617     end %if
7618    
7619     end %for il
7620    
7621     if ~exist('LIST')
7622     LIST= NaN;
7623     end
7624    
7625     gmaze_pv/visu/get_plotlistfields.m0000644002352600001440000000331610631370426016766 0ustar gmazeusers%
7626     % get_plotlistfields(MASTER,SUBDIR)
7627     %
7628     % This function returns the list of fields required by
7629     % the modules of MASTER file in SUBDIR
7630     %
7631     % 06/05/2007
7632     % gmaze@mit.edu
7633    
7634     function LIST = get_plotlistfields(MASTER,SUBDIR)
7635    
7636     global sla
7637    
7638     % Define suffixe of module:
7639     suff = '_pl';
7640    
7641    
7642     d = dir(SUBDIR);
7643     ii = 0;
7644     % Select Matlab files:
7645     for id = 1 : length(d)
7646     en = length( d(id).name );
7647     if en~=1 & (d(id).name(en-1:en) == '.m') & ~d(id).isdir
7648     ii = ii + 1;
7649     l(ii).name = d(id).name;
7650     end
7651     end
7652    
7653     % Select Matlab files with MASTER as prefix
7654     ii = 0;
7655     for il = 1 : length(l)
7656     fil = l(il).name;
7657     pref = strcat(MASTER,suff);
7658     iM = findstr( strcat(SUBDIR,sla,fil) , pref );
7659    
7660     if ~isempty(iM)
7661     ii = ii + 1;
7662     LIST(ii).name = l(il).name;
7663     LIST(ii).index = ii;
7664    
7665     % Recup list of fields required by the module:
7666     fid = fopen(strcat(SUBDIR,sla,fil));
7667     thatsit = 0;
7668     clear fiel
7669     while thatsit ~= 1
7670     tline = fgetl(fid);
7671     if tline ~= -1
7672     if length(tline)>4 & tline(1:4) == '%REQ'
7673     tl = strtrim(tline(5:end));
7674     if strmatch(';',tl(end)), tl = tl(1:end-1);end
7675     tl = [';' tl ';'];
7676     pv = strmatch(';',tl');
7677     for ifield = 1 : length(pv)-1
7678     fiel(ifield).name = tl(pv(ifield)+1:pv(ifield+1)-1);
7679     end
7680     LIST(ii).nbfields = size(fiel,2);
7681     LIST(ii).required = fiel;
7682     thatsit = 1;
7683     end %if
7684     else
7685     fiel.name = 'Not found';
7686     LIST(ii).required = fiel;
7687     thatsit = 1;
7688     end %if
7689     end %while
7690     %disp(strcat( num2str(LIST(ii).index),': Module extension :',fil(length(MASTER)+2:end-2)));
7691     %disp(strcat('|-----> description :' , LIST(ii).description ));
7692     %disp(char(2))
7693    
7694     end %if
7695    
7696     end %for il
7697    
7698     if ~exist('LIST')
7699     LIST= NaN;
7700     end
7701    
7702     gmaze_pv/visu/get_plotlist.m0000644002352600001440000000260610641013406015571 0ustar gmazeusers%
7703     % LIST = get_plotlist(MASTER,SUBDIR)
7704     %
7705     % This function determines the list of pre-defined plots
7706     % available with the MASTER.m in the folder SUBDIR
7707     % LIST is a structure with name and description of each modules.
7708     %
7709    
7710     function LIST = get_plotlist(MASTER,SUBDIR)
7711    
7712     global sla
7713    
7714     % Define suffixe of plot module:
7715     suff = '_pl';
7716    
7717     d = dir(strcat(SUBDIR,sla));
7718    
7719     ii = 0;
7720     % Select Matlab files:
7721     for id = 1 : length(d)
7722     en = length( d(id).name );
7723     if en~=1 & (d(id).name(en-1:en) == '.m') & ~d(id).isdir
7724     ii = ii + 1;
7725     l(ii).name = d(id).name;
7726     end
7727     end
7728    
7729    
7730     % Select Matlab files with MASTER as prefix
7731     ii = 0;
7732    
7733     for il = 1 : size(l,2)
7734     fil = l(il).name;
7735     pref = strcat(MASTER,suff);
7736     iM = findstr( strcat(SUBDIR,sla,fil) , pref ) ;
7737    
7738     if ~isempty(iM)
7739     ii = ii + 1;
7740     LIST(ii).name = l(il).name;
7741     LIST(ii).index = ii;
7742    
7743     % Recup description of plot module:
7744     fid = fopen(strcat(SUBDIR,sla,fil));
7745     if fid < 0
7746     sprintf('Problem with file: %s',strcat(SUBDIR,sla,fil))
7747     return
7748     end
7749     thatsit = 0;
7750     while thatsit ~= 1
7751     tline = fgetl(fid);
7752     if tline ~= -1
7753     if length(tline)>4 & tline(1:4) == '%DEF'
7754     LIST(ii).description = tline(5:end);
7755     thatsit = 1;
7756     end %if
7757     else
7758     LIST(ii).description = 'Not found';
7759     thatsit = 1;
7760     end %if
7761     end %while
7762    
7763     end %if
7764    
7765     end %for il
7766    
7767     if ~exist('LIST')
7768     LIST= NaN;
7769     end
7770     gmaze_pv/visu/grid_setup.m0000644002352600001440000000471110506557107015237 0ustar gmazeusers% Here we define as global variables grids for u, v, theta and salt
7771     % and also sub domain for the CLIMODE North Atlantic study
7772    
7773    
7774     function grid_setup
7775    
7776     global domain subdomain1 subdomain2 subdomain3 subdomain4
7777    
7778    
7779     % Load grid
7780    
7781     GRID_125
7782    
7783     % Setup standard grid variables:
7784    
7785     lon_salt=lon125;
7786     lon_thet=lon125;
7787     lon_u=[lon125(1)-360+lon125(end) (lon125(2:end)+lon125(1:end-1))/2];
7788     lon_v=lon125;
7789    
7790     lat_salt=lat125';
7791     lat_thet=lat125';
7792     lat_u=lat125';
7793     lat_v=[lat125(1)-(lat125(2)-lat125(1))/2 (lat125(1:end-1)+lat125(2:end))/2]';
7794    
7795     dpt_salt=dpt125;
7796     dpt_thet=dpt125;
7797     dpt_u=dpt125;
7798     dpt_v=dpt125;
7799     dpt_w=[0 cumsum(thk125(1:end-1))];
7800    
7801    
7802     % Define the domain with structure:
7803     domain = struct(...
7804     'SALTanom',struct('lon',lon_salt,'lat',lat_salt','dpt',dpt_salt),...
7805     'THETA', struct('lon',lon_thet,'lat',lat_thet','dpt',dpt_thet),...
7806     'UVEL', struct('lon',lon_u,'lat',lat_u','dpt',dpt_u),...
7807     'VVEL', struct('lon',lon_v,'lat',lat_v','dpt',dpt_v),...
7808     'WVEL', struct('lon',lon_salt,'lat',lat_salt','dpt',dpt_w)...
7809     );
7810    
7811    
7812    
7813     % And here we define the subdomain global structure containing 3D limits
7814     % of the studied region, defined on the central grid.
7815    
7816     sub_name='western_north_atlantic';
7817     lonmin=lon125(2209);
7818     lonmax=lon125(2401);
7819     latmin=lat125(1225);
7820     latmax=lat125(1497);
7821     dptmin=dpt125(1);
7822     dptmax=dpt125(29);
7823    
7824     subdomain1=struct('name',sub_name,...
7825     'limlon',[lonmin lonmax],...
7826     'limlat',[latmin latmax],...
7827     'limdpt',[dptmin dptmax]);
7828    
7829    
7830     sub_name='climode';
7831     lonmin=lon125(2312); % = 332E
7832     lonmax=lon125(2384); % = 306E
7833     latmin=lat125(1368); % = 27N
7834     latmax=lat125(1414); % = 50N
7835     dptmin=dpt125(1); % = 5m
7836     dptmax=dpt125(29); % = 1105.9m
7837    
7838     subdomain2=struct('name',sub_name,...
7839     'limlon',[lonmin lonmax],...
7840     'limlat',[latmin latmax],...
7841     'limdpt',[dptmin dptmax]);
7842    
7843    
7844     sub_name='north_atlantic';
7845     lonmin=lon125(2209);
7846     lonmax=lon125(2880);
7847     latmin=lat125(1157);
7848     latmax=lat125(1564);
7849     dptmin=dpt125(1);
7850     dptmax=dpt125(29);
7851    
7852     subdomain3=struct('name',sub_name,...
7853     'limlon',[lonmin lonmax],...
7854     'limlat',[latmin latmax],...
7855     'limdpt',[dptmin dptmax]);
7856    
7857    
7858     sub_name='global';
7859     lonmin=lon125(1);
7860     lonmax=lon125(2880);
7861     latmin=lat125(1);
7862     latmax=lat125(2176);
7863     dptmin=dpt125(1);
7864     dptmax=dpt125(29);
7865    
7866     subdomain4=struct('name',sub_name,...
7867     'limlon',[lonmin lonmax],...
7868     'limlat',[latmin latmax],...
7869     'limdpt',[dptmin dptmax]);
7870     gmaze_pv/visu/logcolormap.m0000644002352600001440000000267610454542255015420 0ustar gmazeusers%
7871     % cmap = logcolormap(Ncol,c1,c2,cmapO)
7872     %
7873     %
7874     % 07/10/06
7875     % gmaze@mit.edu
7876    
7877     function cmap = logcolormap(Ncol,c1,c2,cmapO);
7878    
7879     cmapO = mycolormap(cmapO,Ncol);
7880    
7881     colD = [1 1 1];
7882     colU = [0 0 0];
7883    
7884    
7885     cmapD = [linspace(colD(1),cmapO(1,1),c1*Ncol) ; ...
7886     linspace(colD(2),cmapO(1,2),c1*Ncol) ; ...
7887     linspace(colD(3),cmapO(1,3),c1*Ncol)]';
7888     %cmapD = ones(c1*Ncol,3)*0;
7889    
7890    
7891    
7892     cmapU = [linspace(cmapO(Ncol,1),colU(1),c2*Ncol) ; ...
7893     linspace(cmapO(Ncol,2),colU(2),c2*Ncol) ; ...
7894     linspace(cmapO(Ncol,3),colU(3),c2*Ncol)]';
7895     %cmapU = ones(c2*Ncol,3)*0;
7896    
7897    
7898     if c1 == 0 & c2 ~= 0
7899     cmap = [...
7900     cmapO ; ...
7901     cmapU ; ...
7902     ];
7903     end
7904    
7905     if c1 ~= 0 & c2 ==0
7906     cmap = [...
7907     cmapD ; ...
7908     cmapO ; ...
7909     ];
7910     end
7911    
7912     if c1 ~= 0 & c2 ~= 0
7913     cmap = [...
7914     cmapD ; ...
7915     cmapO ; ...
7916     cmapU ; ...
7917     ];
7918     end
7919    
7920     if c1 == 0 & c2 == 0
7921     cmap = [cmapO];
7922     end
7923    
7924     cmap = [cmapD;cmapO;cmapU];
7925    
7926     if 0
7927     n = ceil(Ncol/4);
7928     u1 = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]';
7929    
7930     x = log( linspace(1,exp(1),n) ).^2;
7931     %u = [x ones(1,n-1) (n:-1+dx:1)/n]';
7932     u = [x ones(1,n-n/2) fliplr(x)]';
7933    
7934    
7935    
7936     g = ceil(n/2) - (mod(Ncol,4)==1) + (1:length(u1))';
7937    
7938     %b = - (1:length(u))' ;
7939    
7940     b = g - n ;
7941     r = g + n ;
7942    
7943     r(r>Ncol) = [];
7944     g(g>Ncol) = [];
7945     b(b<1) = [];
7946    
7947     cmap = zeros(Ncol,3);
7948     cmap(r,1) = u1(1:length(r));
7949     cmap(g,2) = u1(1:length(g));
7950     cmap(b,3) = u1(end-length(b)+1:end);
7951     end
7952    
7953    
7954    
7955    
7956     if 0
7957     % Set the colormap:
7958     clf;colormap(cmap);
7959     hold on
7960     plot(cmap(:,1),'r*-');
7961     plot(cmap(:,2),'g*-');
7962     plot(cmap(:,3),'b*-');
7963     colorbar
7964     grid on
7965     end
7966     gmaze_pv/visu/mapclean.m0000644002352600001440000000205410453230731014640 0ustar gmazeusers%
7967     % SUBFCT_MAPCLEAN(CPLOT,CBAR)
7968     %
7969     % This function makes uniformed subplots (handles CPLOT)
7970     % and their vertical colorbars (handles CBAR)
7971     %
7972     % 07/06/06
7973     % gmaze@mit.edu
7974    
7975     function subfct_mapclean(CPLOT,CBAR)
7976    
7977    
7978     np = length(CPLOT);
7979     proper1 = 'position';
7980     proper2 = 'position';
7981    
7982     % Get positions of subplots and colorbars:
7983     for ip = 1 : np
7984     Pot(ip,:) = get(CPLOT(ip),proper1);
7985     Bot(ip,:) = get(CBAR(ip),proper2);
7986     end
7987    
7988    
7989     % Set coord of subplots: [left bottom width height]
7990     W = max(Pot(:,3));
7991     H = max(Pot(:,4));
7992     Pot;
7993     for ip = 1 : np
7994     set(CPLOT(ip),proper1,[Pot(ip,1:2) W H]);
7995     end
7996    
7997    
7998     % Get new positions of subplots:
7999     for ip = 1 : np
8000     Pot(ip,:) = get(CPLOT(ip),proper1);
8001     end
8002    
8003    
8004     % Fixe colorbars coord: [left bottom width height]
8005     Wmin = 0.0435*min(Pot(:,3));
8006     Hmin = 0.6*min(Pot(:,4));
8007    
8008     % Set them:
8009     for ip = 1 : np
8010     %set(CBAR(ip),proper2,[Bot(ip,1) Bot(ip,2) Wmin Hmin]);
8011     % set(CBAR(ip),proper2,[Pot(ip,1)+Pot(ip,3)*1.1 Pot(ip,2)+Pot(ip,2)*0.1 Wmin Hmin]);
8012     set(CBAR(ip),proper2,[Pot(ip,1)+Pot(ip,3)*1.05 Pot(ip,2)+Pot(ip,4)*0.2 ...
8013     0.0435*Pot(ip,3) 0.6*Pot(ip,4)])
8014     end
8015     gmaze_pv/visu/videotimeline.m0000644002352600001440000000170410453551212015716 0ustar gmazeusers%
8016     % [] = videotimeline(TIMERANGE,IT,POSITION)
8017     %
8018     % TIMERANGE contains all the time line serie
8019     % TIME contains the current time
8020     %
8021    
8022     function varargout = videotimeline(TIME,it,POSIT)
8023    
8024    
8025     [nt nc] = size(TIME);
8026    
8027     DY = .02;
8028     DX = 1/nt;
8029    
8030     bgcolor=['w' 'r'];
8031     bdcolor=['k' 'r'];
8032     txtcolor=['k' 'w'];
8033     fts = 8;
8034    
8035     figure(gcf);hold on
8036    
8037     for ii = 1 : nt
8038     %p=patch([ii-1 ii ii ii-1]*DX,[1 1 0 0]*DY,'w');
8039     if POSIT == 't'
8040     s=subplot('position',[(ii-1)*DX 1-DY DX DY]);
8041     else
8042     s=subplot('position',[(ii-1)*DX 0 DX DY]);
8043     end
8044     p=patch([0 1 1 0],[0 0 1 1],'w');
8045     set(s,'ytick',[],'xtick',[]);
8046     set(s,'box','on');
8047     tt=text(.35,0.5,TIME(ii,:));
8048    
8049     if ii == it
8050     set(p,'facecolor',bgcolor(2));
8051     set(p,'edgecolor',bdcolor(2));
8052     %set(s,'color',bgcolor(2));
8053     set(tt,'fontsize',fts,'color',txtcolor(2));
8054     else
8055     set(p,'facecolor',bgcolor(1));
8056     set(p,'edgecolor',bdcolor(1));
8057     %set(s,'color',bgcolor(1));
8058     set(tt,'fontsize',fts,'color',txtcolor(1));
8059     end
8060     end
8061    

  ViewVC Help
Powered by ViewVC 1.1.22