% calculates the integral of chl and bb for each profile

close all
clear all

load float0005
% 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);
    I2=find(isfinite(bb)==1 & P <75 & 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';

%%%%%%%%%%%
h=figure('Units','inches','Resize','off'); % figure 10
set(gcf,'paperposition',[1.5 3.5 3.5 2.5]); % sets location and size on print out
set(gcf,'position',[0 0 3.5 2.5]); % sets window location and size on figure
figure(h);
axes1 = axes('Position',[0.187 0.167 0.65 0.74]);
[AX,H1,H2] = plotyy(tim,totalchl',tim,totalbb','Parent',axes1);
hold on
plot([732910 732910],[0 140],'k','LineWidth',2);
plot([732985 732985],[0 140],'k','LineWidth',2);
h=plot([732120,732200],[130.5 130.5],'k','Linewidth',2);
h=plot([732120,732200],[121 121],'k--','Linewidth',2);
hold off
set(gca,'FontName','Times New Roman','FontSize',10);
set(gca,'LineWidth',0.75);
set(H1,'Color','k','LineWidth',2);
set(H2,'Color','k','LineWidth',2);
set(H2,'LineStyle','--');
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),'xlim',[732090 733250]);
set(AX(2),'xlim',[732090 733250]);
set(AX(1),'ylim',[0 140]);
set(AX(2),'ylim',[0 1.4]);
set(AX(1),'XTick',[732115 732480 732850 733215]);
set(AX(2),'XTick',[]);
set(get(AX(2),'YLabel'),'Rotation',270.0);
set(get(AX(2),'YLabel'),'VerticalAlignment','bottom');
% xlim([732090 733250]);
tick = [732099 732464 732829 733194 733560];
set(AX(1),'XTick',tick);
set(AX(1), 'XTickLabels', datestr(tick,'dd mmm yy'));
% datetick(AX(1),'x', 'mmmyy','keeplimits','keepticks');
% datetick(AX(2),'x', 'mmmyy','keeplimits','keepticks');
set(AX(1),'YTick',[20 40 60 80 100 120 140]);
set(AX(2),'YTick',[0.2 0.4 0.6 0.8 1.0 1.2 1.4]);
xlabel('Day of the Year');
annotation('textbox',[0.25 0.82 0.1 0.1],'String','chl','EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');
annotation('textbox',[0.25 0.77 0.1 0.1],'String','b_{bp}','EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

%%%%%%%%%%%%%%%%%
h=figure('Units','inches','Resize','off'); % figure 9
set(gcf,'paperposition',[1.5 3.5 3.5 2.5]); % sets location and size on print out
set(gcf,'position',[0 0 3.5 2.5]); % sets window location and size on figure
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');
colormap(gray);
colorbar;
hold on
h=plot(pos_plot(I,1)-60,pos_plot(I,2),'-k','LineWidth',2);
% h=plot(pos_plot(I,1)-60,pos_plot(I,2),'-k','LineWidth',2,'Marker','o','MarkerSize',[round(totalbb(I)*20)],'MarkerFaceColor',[0 0 0]);
% h=plot(pos_plot(I,1)-60,pos_plot(I,2),'-k','LineWidth',2,'Marker','o','MarkerSize',[round(totalbb(I)*20)],'MarkerFaceColor',[0 0 0]);

pos1=[pos_plot(I,1)];
pos2=[pos_plot(I,2)];
b=[totalbb(I)];
bMarkerSize=(b*20);

num_alt_points=size(totalbb(I));
for k=1:num_alt_points
    h=plot(pos1(k,1)-60,pos2(k,1),'Marker','o','MarkerSize',[bMarkerSize(k,1)],'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','white');
end
% plot legend
max_b=max(b)
max_b_markersize=max(bMarkerSize)
min_b=min(b)
min_b_markersize=min(bMarkerSize)

% annotation('ellipse',[0.15 0.8 0.06 0.08],'EdgeColor','white')
annotation('textbox',[0.2565 0.77 0.2302 0.1602],'String','b_{bp}= 0.3','EdgeColor','none','Color','white','FontName','Times New Roman','FitHeightToText','on');
annotation('textbox',[0.2565 0.6814 0.2302 0.1602],'String','b_{bp}= 0.9','EdgeColor','none','Color','white','FontName','Times New Roman','FitHeightToText','on');
h=plot(-42.2,50.79,'Marker','o','MarkerSize',[min_b_markersize],'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','white');
h=plot(-42.2,50.45,'Marker','o','MarkerSize',[max_b_markersize],'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','white');
hold off
set(gca,'FontName','Times New Roman','FontSize',10,'LineWidth',0.75);
box on; % sets box around graph
xlabel('Longitude (^oW)');
ylabel('Latitude (^oN)');
% Create textbox for colorbar label
annotation('textbox',[0.93 0.55 0.08 0.07587],'String',{'cm'},'Rotation',[270],'EdgeColor','none','FontName','Times New Roman','FitHeightToText','on');

