clear all
close('all')

load apex_data
for i=1:N
    file_i=int2str(i);
    n=length(file_i);
        if n==1
            name2=['dat00',file_i];
        elseif n==2
             name2=['dat0',file_i];
        else 
             name2=['dat',file_i];
        end           
    B=eval(name2);
    [mm nn]=size(B);
    if i==1
        dat=[B,zeros(mm,1)];
    else
        AA=[B,(i-1)*5*ones(mm,1)];
        dat=[dat;AA];
    end
end
tt=datenum(2005,8,25)+dat(:,17);
t=168+dat(:,17);
I=find(dat<-100);
dat(I)=NaN;
P=dat(:,1);
T=dat(:,2);
S=dat(:,3);
O=dat(:,4);
BlueRef=dat(:,5);
FSig=dat(:,6); % on F0005 this row is BlueSig=dat(:,6);
NtuReg=dat(:,7); % on F0005 this row is LSSRef=dat(:,7);
NtuSig=dat(:,8); % on F0005 this row is LSSSig=dat(:,8);
Tsig=dat(:,9); % on F0005 this row doesn't exist
theta=dat(:,10); % mistakenly (:,9)
sigma=dat(:,11); % mistakenly (:,10) etc...
O2sat=dat(:,12);
O2=dat(:,13);
Chl=dat(:,14);
B_LSS=dat(:,15);
% B_LSS_b=(LSSSig-51.8)*0.00004637;
% cp=B_LSS*63;
% cp_b=B_LSS_b*63;
% Chl_b=(BlueSig-29)*0.01079772; %should this be Chl_b=(BlueSig-51)*0.0149
% POC_b=10000*B_LSS_b;
%chl_corr=(FSig-50)*0.0149; % wetlabs calibration
chl_corr=Chl;
%%%%%%%%%%%%%%%%%%%%% parameter at surface vs. time plots
figure(1)
I=find(P>0 & P<10);
scatter(tt(I),chl_corr(I),'b.')
% axis([min(tt),max(tt)])
datetick('x','mmmyy')
title({'Chlorophyll','Float 0005, North Pacific'})
ylabel('Concentration [mg/m^3]')
% xlabel('time [month]')

%%%%%%%%%%%%%%%%%%%%% parameter vs. time and depth plots
figure(2); % sigma
%subplot(2,2,1)
scatter(tt,-P,5,sigma,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
set(gca,'LineWidth',0.75);
% set(gca,'XTick',[732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
title('Density-1000 [kg m^{-3}]');
ylabel('depth [db]');

figure(3); % theta
%subplot(2,2,2)
scatter(tt,-P,5,theta,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
% set(gca,'xtick',[732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
title('Potential temperature [^\oC]');
ylabel('depth [db]');

figure(4); % salinity
%subplot(2,2,2)
scatter(tt,-P,5,S,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
% set(gca,'xtick',[732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
title('Salinity [PSU]');
ylabel('depth [db]');

figure(5); % chlorophyll
%subplot(2,2,3)
scatter(tt,-P,5,chl_corr,'filled'),colorbar;
xlim([min(tt),max(tt)]);
ylim([-1050,max(-P)]);
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',10);
% set(gca,'xtick',[732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
title('Chlorophyll [mg m^{-3}]');
ylabel('depth [db]');

% figure(6); % bb, sensor no longer working
% %subplot(2,2,4)
% scatter(tt,-P,5,B_LSS,'filled'),colorbar;
% xlim([min(tt),max(tt)]);
% ylim([-1050,max(-P)]);
% set(gca,'FontName','Times New Roman');
% set(gca,'FontSize',16);
% set(gca,'xtick',[732464 732829 733194]);
% datetick(gca,'x','mmmyy','keepticks');
% % title('side scatter [m^{-1}]');
% ylabel('depth [db]');

% figure(7); % oxygen, sensor no longer working
% %subplot(2,2,4)
% scatter(tt,-P,5,O2./O2sat*100,'filled'),colorbar;
% xlim([min(tt),max(tt)]);
% ylim([-1050,max(-P)]);
% set(gca,'FontName','Times New Roman');
% set(gca,'FontSize',16);
% set(gca,'xtick',[732464 732829 733194]);
% datetick(gca,'x','mmmyy','keepticks');
% title('Oxygen saturation');
% ylabel('depth [db]');
% xlabel('time [month] starting in 2005');

% I=find(P>900);
% figure(8)
% subplot(2,3,1)
% plot(tt(I),sigma(I),'o');
% datetick('x','mmmyy')
% ylabel('density-1000 [kg]');
% subplot(2,3,2)
% plot(tt(I),theta(I),'o');
% datetick('x','mmmyy')
% ylabel('potential temperature [C]')
% subplot(2,3,3)
% plot(tt(I),S(I),'o');
% datetick('x','mmmyy')
% ylabel('salinity [psu]')
% %subplot(2,3,4)
% %plot(tt(I),O2(I)./O2sat(I)*100,'o');
% %datetick('x','mmmyy')
% %ylabel('O2 saturation')
% subplot(2,3,4)
% plot(tt(I),chl_corr(I)/3,'o');
% datetick('x','mmmyy')
% ylabel('chlorophyll [mg/m^3]')
% subplot(2,3,5)
% plot(tt(I),B_LSS_b(I),'o');
% datetick('x','mmmyy')
% ylabel('side scatter [m^{-1}]')
% I=find(P>2 & P<30 & isfinite(B_LSS_b));
% min(chl_corr(I));

