1 |
% |
% |
2 |
% [Q] = C_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV]) |
% [Q] = C_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV]) |
3 |
|
% [Q1,Q2,Q3] = C_compute_potential_vorticity(SNAPSHOT,[WANTSPLPV]) |
4 |
% |
% |
5 |
% This file computes the potential vorticity Q from |
% This file computes the potential vorticity Q from |
6 |
% netcdf files of relative vorticity (OMEGAX, OMEGAY, ZETA) |
% netcdf files of relative vorticity (OMEGAX, OMEGAY, ZETA) |
50 |
FLpv3 = 2; |
FLpv3 = 2; |
51 |
end |
end |
52 |
end %if |
end %if |
53 |
|
%[FLpv1 FLpv2 FLpv3] |
54 |
|
|
55 |
|
|
56 |
%% Optionnal flags: |
%% Optionnal flags: |
57 |
global toshow % Turn to 1 to follow the computing process |
global toshow % Turn to 1 to follow the computing process |
61 |
|
|
62 |
% Path and extension to find them: |
% Path and extension to find them: |
63 |
pathname = strcat('netcdf-files',sla,snapshot,sla); |
pathname = strcat('netcdf-files',sla,snapshot,sla); |
64 |
|
%pathname = '.'; |
65 |
ext = strcat('.',netcdf_suff); |
ext = strcat('.',netcdf_suff); |
66 |
|
|
67 |
% Names: |
% Names: |
249 |
dz = zeros(1,nz).*NaN; |
dz = zeros(1,nz).*NaN; |
250 |
|
|
251 |
% Vertical grid differences: |
% Vertical grid differences: |
252 |
dz = diff(STdpt); |
% STdpt contains negative values with STdpt(1) at the surface |
253 |
|
% and STdpt(end) at the bottom of the ocean. |
254 |
|
% So dz is positive with respect to z axis upward: |
255 |
|
dz = -diff(STdpt); |
256 |
[a dz_3D c] = meshgrid(STlat,dz,STlon); clear a c |
[a dz_3D c] = meshgrid(STlat,dz,STlon); clear a c |
257 |
|
|
258 |
% Vertical gradient: |
% Vertical gradient: |
259 |
if toshow,disp('Vertical gradient of SIGMATHETA'), end |
if toshow,disp('Vertical gradient of SIGMATHETA'), end |
260 |
ST = ncST{4}(:,:,:); |
ST = ncST{4}(:,:,:); |
261 |
dSIGMATHETAdz = ( ST(2:nz+1,:,:) - ST(1:nz,:,:) ) ./ dz_3D; |
% Z axis upward, so vertical derivative is upper-part |
262 |
|
% minus lower-part: |
263 |
|
dSIGMATHETAdz = ( ST(1:nz,:,:) - ST(2:nz+1,:,:) ) ./ dz_3D; |
264 |
clear dz_3D ST |
clear dz_3D ST |
265 |
|
|
266 |
% Change vertical gridding: |
% Change vertical gridding: |
412 |
nc{ncid}(:,:,:) = PV; |
nc{ncid}(:,:,:) = PV; |
413 |
|
|
414 |
nc=close(nc); |
nc=close(nc); |
415 |
close(ncOx); |
if FLpv3 ~= 2 |
416 |
close(ncOy); |
close(ncOx); |
417 |
close(ncOz); |
close(ncOy); |
418 |
|
close(ncOz); |
419 |
|
end |
420 |
close(ncST); |
close(ncST); |
421 |
|
|
422 |
% Outputs: |
% Outputs: |
424 |
switch nargout |
switch nargout |
425 |
case 1 |
case 1 |
426 |
varargout(1) = {OUT}; |
varargout(1) = {OUT}; |
427 |
|
case 2 |
428 |
|
varargout(1) = {struct('PV1',PV1,'dpt',PV1_dpt,'lat',PV1_lat,'lon',PV1_lon)}; |
429 |
|
varargout(2) = {struct('PV2',PV2,'dpt',PV2_dpt,'lat',PV2_lat,'lon',PV2_lon)}; |
430 |
|
case 3 |
431 |
|
varargout(1) = {struct('PV1',PV1,'dpt',PV1_dpt,'lat',PV1_lat,'lon',PV1_lon)}; |
432 |
|
varargout(2) = {struct('PV2',PV2,'dpt',PV2_dpt,'lat',PV2_lat,'lon',PV2_lon)}; |
433 |
|
varargout(3) = {struct('PV3',PV3,'dpt',PV3_dpt,'lat',PV3_lat,'lon',PV3_lon)}; |
434 |
end |
end |