% pHctd_02.m                                        by:  Edward T Peltzer, MBARI
%                                                   revised:  2008 Feb 24.
%
% M-file to plot temperature and salinity data from the pH_CTD
% deployment during 2007: Aug 15th (227) thru Nov 2nd (306).
%
% Data file = S4AD_2007Nov_02.xls  /  Worksheet = Select
%
%   Column   Parameter        Units
%
%     A      Time             Yearday  
%     B      Temp             deg C
%     C      Cond             S/m
%     D      Pres             dbar


% Clear environment space and set orientation

clear all
close all


% Load data and assign data vectors

yrd = xlsread('pH_CTD','Select','A2:A11365');
tmp = xlsread('pH_CTD','Select','B2:B11365');
con = xlsread('pH_CTD','Select','C2:C11365');
prs = xlsread('pH_CTD','Select','D2:D11365');


% Calculate salinity from conductivity

sal = salinity(con,tmp,prs);
THETA = Potentmp(sal,tmp,prs,0);
sigth = (density(sal,THETA)-1)*1000;


% Define plotting region and make figure 1

figure(1)
orient tall

left = 1.25/8.5;
bottom = 2.5/11;
width = 6/8.5;
height = 6/11;

subplot('position',[left bottom width height])


% Make plot

plot(tmp,sal,'r+')

hold on


% Define axis and set tick-label-size

axis('xy');
axis([3.9 4.9 34.25 34.50]);

h=gca;
set(h,'FontSize',16);
set(h,'FontWeight','normal');
set(h,'LineWidth',1);


% Manually define and control X-ticks and X-tick labels

xtl = [3.9:0.1:4.8];

N = length(xtl);

for I = 1:N
    if rem(I,2) == 0
        if rem(xtl(I)*10,10) == 0
            XTL(I,:) = [num2str(xtl(I)) '.0'];
        else
            XTL(I,:) = [num2str(xtl(I))];
        end
    else
        XTL(I,:) = ['   '];
    end
end

set(h,'XTick',xtl);
set(h,'XTickLabel',XTL);


% Manually define and control Y-ticks and Y-tick labels

ytl = [34.25:0.01:34.50];

N = length(ytl);

for I = 1:N
    if rem(I-1,5) == 0
        if rem(ytl(I)*10,1) == 0
            YTL(I,:) = [' ' num2str(ytl(I)) '0'];
        else
            YTL(I,:) = [' ' num2str(ytl(I))];
        end
    else
        YTL(I,:) = ['      '];
    end    
end

set(h,'YTick',ytl);
set(h,'YTickLabel',YTL);


% Label plot -- X-Axis

xlabel(['Temperature (\circC)']);
h=get(gca,'xlabel');
set(h,'Color',[0,0,0]);
set(h,'FontSize',20);
set(h,'FontWeight','normal');


% Label plot -- Y-Axis

ylabel('Salinity (pss-78)');
h=get(gca,'ylabel');
set(h,'Color',[0,0,0]);
set(h,'FontSize',20);
set(h,'FontWeight','normal');


% Label plot -- Title

title(['MARS Test Station 2007']);
h=get(gca,'title');
set(h,'FontSize',20);
set(h,'FontWeight','normal');


% Label plot -- Legends

leg1 = sprintf(['Mean temp = %4.2f ' setstr(177) ' %4.2f ' setstr(176) 'C'],mean(tmp),std(tmp));
h = text(4.3,34.47,leg1);
set(h,'Color',[0,0,0]);
set(h,'FontSize',16);
set(h,'FontWeight','normal');

leg2 = sprintf(['Mean sal = %6.3f ' setstr(177) ' %5.3f'],mean(sal),std(sal));
h = text(4.3,34.45,leg2);
set(h,'Color',[0,0,0]);
set(h,'FontSize',16);
set(h,'FontWeight','normal');

means = sprintf(['%6.3f ' setstr(177) ' %5.3f'],mean(sigth),std(sigth));

leg3 = ['Mean \sigma_{\theta} = ' means];
h = text(4.1,34.30,leg3);
set(h,'Color',[0,0,0]);
set(h,'FontSize',16);
set(h,'FontWeight','normal');

ranges = sprintf(['%6.3f - %6.3f'],max(sigth),min(sigth));

leg4 = ['Range \sigma_{\theta} = ' ranges];
h = text(4.1,34.28,leg4);
set(h,'Color',[0,0,0]);
set(h,'FontSize',16);
set(h,'FontWeight','normal');

hold off
