clear all; close all;
load ab1209_db
pressure=1:800';
%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_nwpc = cnv_dlp;
        else
            cnv_nwpc = cnv_cal;
        end;

sts=9;
pot_temp_prov=zeros(800,sts)*NaN;
sal_prov=zeros(800,sts)*NaN;
sigma0_prov=zeros(800,sts)*NaN;
oxygen_prov=zeros(800,sts)*NaN;
prs=zeros(800,sts)*NaN;

% NW Providence stations 50 to 58
for i=1:9
   sta=i+36;
   lon(i)=nanmean(cnv_nwpc(sta).longitude);
   lat(i)=nanmean(cnv_nwpc(sta).latitude);
   max_depth=find(cnv_nwpc(sta).pressure==max(cnv_nwpc(sta).pressure));
   prof_prov(i)=max_depth-40;
   for j=1:max_depth
      if data == 0,
        pot_temp_prov(j,i)=cnv_nwpc(sta).thetapri(j);
        sal_prov(j,i)=cnv_nwpc(sta).salpri(j);
        oxygen_prov(j,i)=cnv_nwpc(sta).oxmmsec(j);
        sigma0_prov(j,i)=cnv_nwpc(sta).sigmapri(j);
        prs(j,i)=cnv_nwpc(sta).pressure(j);
       else
        pot_temp_prov(j,i)=cnv_nwpc(sta).pottemp(j);
        sal_prov(j,i)=cnv_nwpc(sta).salt(j);
        oxygen_prov(j,i)=cnv_nwpc(sta).oxyumol(j);
        sigma0_prov(j,i)=cnv_nwpc(sta).sigma0(j); 
       end;   
   end;
end;


%%%%%%%%%%%%%%%%%% Ploting the potential temperature %%%%%%%%%%%%%%%%%%%%%%
f1
%xi=[lon];
%zi=[1:1:800]';
%[XI,ZI]=meshgrid(xi,zi);
%TI=interp2(lon,pressure,pot_temp_prov,XI,ZI,'linear');
%[cs,hc]=contourf(xi,zi,nghbrfilt(TI),[9:1.5:27]);
%[cs,hc]=contourf(XI,ZI,nghbrfilt(pot_temp_prov),[0:1.5:30],'-k');%nghbrfilt

%contourf(lon,pressure,nghbrfilt(pot_temp_prov),[0:1.5:30],'-k');
[new_ptem]=make_edge_contour(pot_temp_prov,pressure,prof_prov,'27N');
contourf(lon,pressure,nghbrfilt(new_ptem),[0:1.5:30],'-k');

colormap(cejet)
colorbar
hold on
revyaxis

ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick', ...
    [-79.8 -79.6 -79.4 -79.2],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-79.84,-20,'79.8^oW');
text(-79.64,-20,'79.6^oW');
text(-79.44,-20,'79.4^oW');
text(-79.24,-20,'79.2^oW');
[C,h]=contour(lon,pressure,nghbrfilt(new_ptem),[10 15 20],'k');
clabel(C,h);
set(ax1,'FontSize',14,'ydir','reverse','Xtick',[-79.8 -79.6 -79.4 -79.2], ...
    'XtickLabel',[]);
set(h,'LineWidth',2);
ylabel('Pressure (dbar)');
for t=1:length(prof_prov)
    plot([lon(t) lon(t)],[0 prof_prov(t)],'k--')
end
xlabel('27N Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
set(0,'DefaultTextFontSize',14);
patch([lon -80.5 -80.5 -79.15 -79.15], ...
    [prof_prov 91 800 800 422],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-79.07,550,'Potential Temperature [^{o}C]','rotation',90)
noaalogo([0.13 0.13 0.15 0.15])

print('-depsc','figures/pot_temp_27N')

%%%%%%%%%%%%%%%%%%%%%%%%%% Ploting the salinity %%%%%%%%%%%%%%%%%%%%%%%%%%%

f2
%xi=[lon];
%zi=[1:1:800]';
%[XI,ZI]=meshgrid(xi,zi);
%TI=interp2(lon,pressure,sal_prov,XI,ZI,'linear');
%[cs,hc]=contourf(xi,zi,nghbrfilt(TI),[35:0.1:37]);
%[cs,hc]=contourf(XI,ZI,nghbrfilt(sal_prov),[35:0.1:37],'-k');

%contourf(lon,pressure,nghbrfilt(sal_prov),[34:0.1:37],'-k');
[new_sal]=make_edge_contour(sal_prov,pressure,prof_prov,'27N');
contourf(lon,pressure,nghbrfilt(new_sal),[34:0.1:37],'-k');

colormap(cejet)
colorbar
hold on
revyaxis

ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick', ...
    [-79.8 -79.6 -79.4 -79.2],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-79.84,-20,'79.8^oW');
text(-79.64,-20,'79.6^oW');
text(-79.44,-20,'79.4^oW');
text(-79.24,-20,'79.2^oW');
[C,h]=contour(lon,pressure,nghbrfilt(new_sal),[35 35.5 36 36.5],'k');
clabel(C,h);
set(ax1,'FontSize',14,'ydir','reverse','Xtick',[-79.8 -79.6 -79.4 -79.2], ...
    'XtickLabel',[]);
set(h,'LineWidth',2);
ylabel('Pressure (dbar)');
for t=1:length(prof_prov)
    plot([lon(t) lon(t)],[0 prof_prov(t)],'k--')
end
xlabel('27N Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
set(0,'DefaultTextFontSize',14);
patch([lon -80.5 -80.5 -79.15 -79.15], ...
    [prof_prov 91 800 800 422],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-79.06,475,'Salinity (psu)','rotation',90)
noaalogo([0.13 0.13 0.15 0.15])

print('-depsc','figures/sal_27N')

%%%%%%%%%%%%%%%%%%%%%%% plotting potential density %%%%%%%%%%%%%%%%%%%%%%%%

f3
%xi=[lon];
%zi=[1:1:800]';
%[XI,ZI]=meshgrid(xi,zi);
%TI=interp2(lon,pressure,sigma0_prov,XI,ZI,'linear');
%[cs,hc]=contourf(xi,zi,nghbrfilt(TI),[23.5:0.5:27]);
%[cs,hc]=contourf(XI,ZI,nghbrfilt(sigma0_prov),[23:0.5:27],'-k');

contourf(lon,pressure,nghbrfilt(sigma0_prov),[22:0.5:28],'-k');
%[new_sigma0]=make_edge_contour(sigma0_prov,pressure,prof_prov,'27N');
%contourf(lon,pressure,nghbrfilt(new_sigma0),[23:0.5:27],'-k');

colormap(cejet)
colorbar
hold on
revyaxis

ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick', ...
    [-79.8 -79.6 -79.4 -79.2],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-79.84,-20,'79.8^oW');
text(-79.64,-20,'79.6^oW');
text(-79.44,-20,'79.4^oW');
text(-79.24,-20,'79.2^oW');
[C,h]=contour(lon,pressure,nghbrfilt(sigma0_prov),[26 27],'k');
clabel(C,h);
set(ax1,'FontSize',14,'ydir','reverse','Xtick',[-79.8 -79.6 -79.4 -79.2], ...
    'XtickLabel',[]);
set(h,'LineWidth',2);
ylabel('Pressure (dbar)');
for t=1:length(prof_prov)
    plot([lon(t) lon(t)],[0 prof_prov(t)],'k--')
end
xlabel('27N Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
set(0,'DefaultTextFontSize',14);
patch([lon -80.5 -80.5 -79.15 -79.15], ...
    [prof_prov 91 800 800 422],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-79.06,450,'Sigma_{\theta}','rotation',90)
noaalogo([0.13 0.13 0.15 0.15])

print('-depsc','figures/sigma0_27N')

%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotting oxygen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

f4
%xi=[lon];
%zi=[1:1:800]';
%[XI,ZI]=meshgrid(xi,zi);
%TI=interp2(lon,pressure,oxygen_prov,XI,ZI,'linear');
%[cs,hc]=contourf(xi,zi,nghbrfilt(TI));
%[cs,hc]=contourf(XI,ZI,nghbrfilt(oxygen_prov));

%contourf(lon,pressure,nghbrfilt(oxygen_prov));
[new_oxy]=make_edge_contour(oxygen_prov,pressure,prof_prov,'27N');
contourf(lon,pressure,nghbrfilt(new_oxy),'-k');

colormap(cejet)
colorbar
hold on
revyaxis

ax1=gca;
set(ax1,'FontSize',14,'ydir','reverse','XAxisLocation','top','Xtick', ...
    [-79.8 -79.6 -79.4 -79.2],'XtickLabel',[]);
hold on
set(0,'DefaultTextFontSize',14);
text(-79.84,-20,'79.8^oW');
text(-79.64,-20,'79.6^oW');
text(-79.44,-20,'79.4^oW');
text(-79.24,-20,'79.2^oW');
%[C,h]=contour(xi,zi,nghbrfilt(TI),[10 15 20],'k');
%clabel(C,h);
set(ax1,'FontSize',14,'ydir','reverse','Xtick',[-79.8 -79.6 -79.4 -79.2], ...
    'XtickLabel',[]);
set(h,'LineWidth',2);
ylabel('Pressure (dbar)');
for t=1:length(prof_prov)
    plot([lon(t) lon(t)],[0 prof_prov(t)],'k--')
end
xlabel('27N Section')
ax2=gca;
set(ax2,'XAxisLocation','bottom');set(0,'DefaultTextFontSize',14);
set(0,'DefaultTextFontSize',14);
patch([lon -80.5 -80.5 -79.15 -79.15], ...
    [prof_prov 91 800 800 422],'w','LineWidth',3);
ylabel('Pressure (dbar)');
text(-79.07,600,'Dissolved Oxygen [{\mu}mol/kg]','rotation',90)
noaalogo([0.13 0.13 0.15 0.15])

print('-depsc','figures/oxygen_27N')
