| 1 |
% |
% |
| 2 |
% [] = COMPUTE_DENSITY(SNAPSHOT) |
% [RHO] = compute_density(SNAPSHOT) |
| 3 |
% |
% |
| 4 |
% For a time snapshot, this program computes the |
% For a time snapshot, this program computes the |
| 5 |
% 3D density from potential temperature and salinity. |
% 3D density from potential temperature and salinity fields. |
| 6 |
% THETA and SALTanom are supposed to be defined on the same |
% THETA and SALTanom are supposed to be defined on the same |
| 7 |
% domain and grid. |
% domain and grid. |
| 8 |
|
% SALTanom is by default a salinity anomaly vs 35PSU. |
| 9 |
|
% If not, (is absolute value) set the global variable is_SALTanom to 0 |
| 10 |
|
% |
| 11 |
% |
% |
| 12 |
|
% Files names are: |
| 13 |
|
% INPUT: |
| 14 |
|
% ./netcdf-files/<SNAPSHOT>/<netcdf_THETA>.<netcdf_domain>.<netcdf_suff> |
| 15 |
|
% ./netcdf-files/<SNAPSHOT>/<netcdf_SALTanom>.<netcdf_domain>.<netcdf_suff> |
| 16 |
|
% OUPUT: |
| 17 |
|
% ./netcdf-files/<SNAPSHOT>/RHO.<netcdf_domain>.<netcdf_suff> |
| 18 |
|
% |
| 19 |
% 06/21/2006 |
% 06/21/2006 |
| 20 |
% gmaze@mit.edu |
% gmaze@mit.edu |
| 21 |
% |
% |
| 22 |
|
|
| 23 |
|
|
| 24 |
function compute_density(snapshot) |
function varargout = compute_density(snapshot) |
| 25 |
|
|
| 26 |
|
|
| 27 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 28 |
%% Setup |
%% Setup |
| 29 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 30 |
global sla netcdf_THETA netcdf_SALTanom netcdf_domain netcdf_suff |
global sla netcdf_THETA netcdf_SALTanom netcdf_domain netcdf_suff |
| 31 |
|
global is_SALTanom |
| 32 |
pv_checkpath |
pv_checkpath |
| 33 |
|
|
| 34 |
|
|
| 74 |
if toshow,disp('Pre-allocate');end |
if toshow,disp('Pre-allocate');end |
| 75 |
RHO = zeros(nz,ny,nx); |
RHO = zeros(nz,ny,nx); |
| 76 |
|
|
| 77 |
|
global is_SALTanom |
| 78 |
|
if exist('is_SALTanom') |
| 79 |
|
if is_SALTanom == 1 |
| 80 |
|
bS = 35; |
| 81 |
|
else |
| 82 |
|
bS = 0; |
| 83 |
|
end |
| 84 |
|
end |
| 85 |
|
|
| 86 |
% Then compute density RHO: |
% Then compute density RHO: |
| 87 |
for iz = 1 : nz |
for iz = 1 : nz |
| 88 |
if toshow,disp(strcat('Compute density at level:',num2str(iz),'/',num2str(nz)));end |
if toshow,disp(strcat('Compute density at level:',num2str(iz),'/',num2str(nz)));end |
| 89 |
|
|
| 90 |
S = SALTavariables{4}(iz,:,:) + 35; % Move the anom to an absolute field |
S = SALTavariables{4}(iz,:,:) + bS; % Move the anom to an absolute field |
| 91 |
T = THETAvariables{4}(iz,:,:); |
T = THETAvariables{4}(iz,:,:); |
| 92 |
P = (0.09998*9.81*dpt(iz))*ones(ny,nx); |
P = (0.09998*9.81*dpt(iz))*ones(ny,nx); |
| 93 |
RHO(iz,:,:) = densjmd95(S,T,P); |
RHO(iz,:,:) = densjmd95(S,T,P); |
| 150 |
nc{ncid}.uniquename = ncchar(uniquename); |
nc{ncid}.uniquename = ncchar(uniquename); |
| 151 |
nc{ncid}(:,:,:) = RHO; |
nc{ncid}(:,:,:) = RHO; |
| 152 |
|
|
|
nc=close(nc); |
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
% Close files: |
| 156 |
|
close(ncTHETA); |
| 157 |
|
close(ncSALTa); |
| 158 |
|
close(nc); |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
% Output: |
| 162 |
|
output = struct('RHO',RHO,'dpt',dpt,'lat',lat,'lon',lon); |
| 163 |
|
switch nargout |
| 164 |
|
case 1 |
| 165 |
|
varargout(1) = {output}; |
| 166 |
|
end |