% plot_ctd.m 
% created by: John Leonard, August 8th, 1998 for 13.010, Fall 1998
% matlab script file for plotting salinity, density, and sound 
% speed as a function of depth from conductivity, temperature, 
% and pressure data.

% this file assumes that we have an array called data,

load('sample.dat');      % loads in the data and places it in the variable
                         % named "sample"
D = sample(:,1);  % depth is the first column of data
T = sample(:,2);  % temperature is the second column of data
S = sample(:,3);  % salinity is the third column of data

PR = 10;          % use 10 decibars for the reference pressure (1 atm)
LAT = 0;          % use latitude of zero in all calculations (error is minimal)
P = sw_pres(D,LAT); % calculate the pressure

THETA = sw_ptmp(S,T,P,PR);
SIGMA = sw_dens(S,T,P) - 1000.0;         % calculate sigma



subplot(131)
plot(T,D)
hold on
plot(THETA, D, 'r-.')
title('temperature vs. depth')
set(gca, 'Ydir', 'reverse')
grid on
zoom on
xlabel('temperature (deg C)')
ylabel('depth (m)')

subplot(132)
plot(S,D)
title('salinity vs. depth')
grid on
zoom on
xlabel('salinity (PSU)')
ylabel('depth (m)')
set(gca, 'Ydir', 'reverse')


subplot(133)
plot(SIGMA, D)
set(gca, 'Ydir', 'reverse')
grid on
zoom on
xlabel('\sigma (PSU)')
ylabel('depth (m)')
title('potential density vs. depth')

