% calculates the integral of chl and bb for each profile

close all
clear all

load float0005_dilate
% float0005 contains:
% tt
% float0005 containing profile, date, float position (lat, long), P, theta, S, sigma, B_LSS_b, Chl_b, O2sat, and O2
% chlorophyll and bb data are calibrated with moored data from P. Strutton, COASOSU 

profiles=unique(float0005(:,1));
num_profiles=length(profiles);

for k=1:num_profiles
    this_profile_range=find(float0005(:,1)==profiles(k));
    P=float0005(this_profile_range,5);
    bb=float0005(this_profile_range,9);
    chl=float0005(this_profile_range,10);
    time=tt(this_profile_range);
    I=find(isfinite(chl)==1 & P <300 & P>5);
    I1=find(isfinite(bb)==1 & P <1000 & P>5);
    totalchl(k)=integral(P(I),chl(I));
    totalbb(k)=integral(P(I1),bb(I1));
    tim(k)=median(time(I));
end

totalchl=totalchl';
totalbb=totalbb'; 

% plotyy(tim,totalchl',tim,totalbb');
% datetick('x','mmmyy')

h=figure('Units','inches','Resize','off');
figure(h);
[AX,H1,H2] = plotyy(tim,totalchl',tim,totalbb');
set(gca,'FontName','Times New Roman','FontSize',10,'LineWidth',0.75);
set(gcf,'paperposition',[1.5 3.5 5.2 4.2]); % sets location and size on print out
set(gcf,'position',[0 0 5.2 4]); % sets window location and size on figure
set(H1,'Color','k','LineWidth',2);
set(H2,'Color','k');
set(AX(1),'Color','none','XColor','k','YColor','k');
set(AX(2),'Color','none','XColor','k','YColor','k');
set(get(AX(1),'Ylabel'),'String','Depth integrated chlorophyll [mg m^{-2}]','FontName','Times New Roman','FontSize',10,'LineWidth',0.75);
set(get(AX(2),'Ylabel'),'String','Depth integrated b_{bp}(440)','FontName','Times New Roman','FontSize',10,'LineWidth',0.75);
set(AX(1),'xlim',[min(tim) max(tim)]);
set(AX(2),'xlim',[min(tim) max(tim)]);
set(AX(1),'ylim',[0 90]);
set(AX(2),'ylim',[0 0.6]);
set(AX(1),'XTick',[732115 732480 732850 733215]);
set(AX(1),'YTick',[0 30 60 90]);
set(AX(2),'YTick',[0 0.2 0.4 0.6]);
set(AX(2),'XTick',[]);
datetick(AX(1),'x', 'mmmyy','keeplimits','keepticks');
datetick(AX(2),'x', 'mmmyy','keeplimits','keepticks');

h=figure('Units','inches','Resize','off');
figure(h);
load float_position
tt_min=datenum(2006,9,1);
tt_max=datenum(2006,12,31);
I=find(tt<tt_max & tt> tt_min);
load altimeter_data
Z=griddata(lat(290-249,:),lon(290-249,:),ssh(290-249,:),[48:0.25:51],[317:0.25:325]');
[C,h] = contourf(-(360-[317:0.25:325]),[48:0.25:51],Z');
colorbar
hold on
plot(pos_plot(I,1)-60,pos_plot(I,2),'-*')
hold off
set(gca,'FontName','Times New Roman','FontSize',10,'LineWidth',0.75);
set(gcf,'paperposition',[1.5 3.5 5.2 4.2]); % sets location and size on print out
set(gcf,'position',[0 0 5.2 4]); % sets window location and size on figure
xlabel('Longitude');
ylabel('Latitude');

