close all; clear all
load ab1209_db
% Program that plots sections for various parameters
%Abaco Section
pressure=1:5700';
%load ab0409_db.mat
data=input(['Which data would you like to plot?:\n'...
            '0 - raw\n'...
            '1 - calibrated\n'...
            'Select:']);
        if data == 0,
            cnv_plot = cnv_dlp;
        else
            cnv_plot = cnv_cal;
        end;


sts=27;
pot_temp_abaco=zeros(5700,sts)*NaN;
sal_abaco=zeros(5700,sts)*NaN;
sigma0_abaco=zeros(5700,sts)*NaN;
oxygen_abaco=zeros(5700,sts)*NaN;

% Abaco line stations 8 to 34
sensor=input('Do you want to use primary or secondary?(1 or 2)','s');
for i=1:sts
   sta=i+7;
   lon(i)=nanmean(cnv_plot(sta).longitude);
   lat(i)=nanmean(cnv_plot(sta).latitude);
   max_depth=find(cnv_plot(sta).pressure==max(cnv_plot(sta).pressure));
   prof(i)=max_depth;
   for j=1:max_depth
       if data == 0,        
        if sensor == '1',
            pot_temp_abaco(j,i)=cnv_plot(sta).thetapri(j);
            sal_abaco(j,i)=cnv_plot(sta).salpri(j);
            %oxygen_abaco(j,i)=cnv_plot(sta).oxmmpri(j);
            sigma0_abaco(j,i)=cnv_plot(sta).sigmapri(j);
            oxygen_abaco(j,i)=cnv_plot(sta).oxmmsec(j);
        else
            pot_temp_abaco(j,i)=cnv_plot(sta).thetasec(j);
            sal_abaco(j,i)=cnv_plot(sta).salsec(j);
            oxygen_abaco(j,i)=cnv_plot(sta).oxmmsec(j);
            sigma0_abaco(j,i)=cnv_plot(sta).sigmasec(j);
        end;
       else
        pot_temp_abaco(j,i)=cnv_plot(sta).pottemp(j);
        sal_abaco(j,i)=cnv_plot(sta).salt(j);
        oxygen_abaco(j,i)=cnv_plot(sta).oxyumol(j);
        sigma0_abaco(j,i)=cnv_plot(sta).sigma0(j); 
       end;
   end
   
end

%%%%%%%%%%%%%%%% Ploting the potential temperature %%%%%%%%%%%%%%%%%%%%%%%%
f1
%c_color=[1:.2:8 11:14 16:19 21:30];
c_color=[1:3:8 9:25 26:30];
contourf(repmat(lon,5700,1),repmat(pressure',1,sts),nghbrfilt(pot_temp_abaco),c_color)
colormap(jet)
colorbar
hold on


%c1=[1:.25:8 11:14 16:19 21:40];
c1=[1:.25:8 9:25 26:30];
[C,h]=contour(lon,pressure',pot_temp_abaco,c1,'k');
%axis([-77 -69 0 5700])
ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick',[-76 -75 -74 -73 -72 -71 -70],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-77.30,-260,'77^oW')
text(-76.30,-260,'76^oW')
text(-75.30,-260,'75^oW')
text(-74.30,-260,'74^oW')
text(-73.30,-260,'73^oW')
text(-72.30,-260,'72^oW')
text(-71.30,-260,'71^oW')
text(-70.30,-260,'70^oW')
[C,h]=contour(lon,pressure',pot_temp_abaco,[10 15 20],'k');
clabel(C,h);
set(h,'LineWidth',2);
ylabel('Pressure (dbar)');
for t=1:length(prof)
    plot([lon(t) lon(t)],[0 prof(t)],'k--')
end
xlabel('Abaco Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
[C,h]=contour(lon,pressure',pot_temp_abaco,[2 3 4 5],'k');
clabel(C,h);
set(h,'LineWidth',2);
patch([ lon  -69.9 -69.9 -77 -77] ,[ prof 5578 5700 5700 450 ],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-68.49,4000,'Potential Temperature [^{o}C]','rotation',90)
noaalogo([0.28 0.13 0.12 0.12])

print -depsc figures/abaco_section_pottemp
%%%%%%%%%%%%%%%%%%%%%%% Ploting the salinity %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

f2
c_color=[34:0.1:38];
contourf(lon,pressure,nghbrfilt(sal_abaco),c_color)
colormap(cejet)
colorbar
hold on

csal1=34:0.01:35;
csal2=35:0.05:35.1;
csal3=35.1:0.1:38;
[C,h]=contour(lon,pressure',sal_abaco,csal1,'k');
%axis([-77 -71.9 0 5400])
ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick',[-76 -75 -74 -73 -72 -71 -70],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-77.30,-260,'77^oW')
text(-76.30,-260,'76^oW')
text(-75.30,-260,'75^oW')
text(-74.30,-260,'74^oW')
text(-73.30,-260,'73^oW')
text(-72.30,-260,'72^oW')
text(-71.30,-260,'71^oW')
text(-70.30,-260,'70^oW')
for t=1:length(prof)
    plot([lon(t) lon(t)],[0 prof(t)],'k--')
end
xlabel('Abaco Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
[C,h]=contour(lon,pressure',sal_abaco,csal2,'k');
[C,h]=contour(lon,pressure',sal_abaco,csal3,'k');
[C,h]=contour(lon,pressure',sal_abaco,[35 35.5 36 36.5],'k');
clabel(C,h,[35 35.5 36 36.5]);
set(h,'LineWidth',2)
patch([ lon  -69.9 -69.9 -77 -77] ,[ prof 5578 5700 5700 450 ],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-68.30,3250,'Salinity[psu]','rotation',90)
noaalogo([0.28 0.13 0.12 0.12])

print -depsc figures/abaco_section_salinity
%%%%%%%%%%%%%%%%%%%%% Ploting the potential density %%%%%%%%%%%%%%%%%%%%%%%

f3
c_color=[22:0.3:28];
contourf(lon,pressure,nghbrfilt(sigma0_abaco),c_color)
colormap(winter)
map=colormap;
colormap(flipud(map))
colorbar
hold on


cpd=[22:0.5:26 26:0.2:27.5 27.7:0.02:28];
[C,h]=contour(lon,pressure',sigma0_abaco,cpd,'k');
%axis([-77 -71.9 0 5400])
ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick',[-76 -75 -74 -73 -72 -71 -70],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-77.30,-260,'77^oW')
text(-76.30,-260,'76^oW')
text(-75.30,-260,'75^oW')
text(-74.30,-260,'74^oW')
text(-73.30,-260,'73^oW')
text(-72.30,-260,'72^oW')
text(-71.30,-260,'71^oW')
text(-70.30,-260,'70^oW')
for t=1:length(prof)
    plot([lon(t) lon(t)],[0 prof(t)],'k--')
end
xlabel('Abaco Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
%[C,h]=contour(lon,pressure',sigma0_abaco,...
%    [26.4 26.8 27.2 27.4],'k');
%clabel(C,h);
[C,h]=contour(lon,pressure',sigma0_abaco,[26 27 27.5],'k');
clabel(C,h);
set(h,'LineWidth',2)
patch([ lon  -69.9 -69.9 -77 -77] ,[ prof 5578 5700 5700 450 ],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-68.30,3100,'Sigma_{\theta}','rotation',90)
noaalogo([0.28 0.13 0.12 0.12])

print -depsc figures/abaco_section_sigma0
%%%%%%%%%%%%%%%%%%%%%%%%%% Ploting the oxygen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f4
%c_color=[2:0.2:8];
contourf(lon,pressure,nghbrfilt(oxygen_abaco))
colormap(cejet)
colorbar
hold on

% coxy1=2.1:0.1:2.9;
% coxy2=3.1:0.2:3.9;
% coxy3=4.1:0.2:8.0;
% 
% [C,h]=contour(lon,pressure',oxygen_abaco,coxy1,'k');
%axis([-77 -71.9 0 5400])
ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick',[-76 -75 -74 -73 -72 -71 -70],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-77.30,-260,'77^oW')
text(-76.30,-260,'76^oW')
text(-75.30,-260,'75^oW')
text(-74.30,-260,'74^oW')
text(-73.30,-260,'73^oW')
text(-72.30,-260,'72^oW')
text(-71.30,-260,'71^oW')
text(-70.30,-260,'70^oW')
for t=1:length(prof)
    plot([lon(t) lon(t)],[0 prof(t)],'k--')
end
xlabel('Abaco Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
% [C,h]=contour(lon,pressure',oxygen_abaco,coxy1,'k');
% [C,h]=contour(lon,pressure',oxygen_abaco,coxy2,'k');
% [C,h]=contour(lon,pressure',oxygen_abaco,coxy3,'k');
% [C,h]=contour(lon,pressure',oxygen_abaco,[2 3 4 5],'k');
% clabel(C,h);
% set(h,'LineWidth',3)
ylabel('Pressure (dbar)')
patch([ lon  -69.9 -69.9 -77 -77] ,[ prof 5578 5700 5700 450 ],'w','LineWidth',3);
text(-68.40,4200,'Dissolved Oxygen [{\mu}mol/kg]','rotation',90)
noaalogo([0.28 0.13 0.12 0.12])

print -depsc figures/abaco_section_oxygen