clear all
close all

%Read input data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\SeaWIFS\SeaWIFS_spectra_7_5km.mat';
Lwn=spectra_median;
F0=[173.004, 190.154, 196.473, 188.158, 183.010, 151.143];
mm=length(Lwn(:,1));
Rrs=1.38*Lwn(:,1:6)./(ones(mm,1)*F0);
II=find(isfinite(Rrs(:,1).*Rrs(:,2).*Rrs(:,3).*Rrs(:,4).*Rrs(:,5).*Rrs(:,6)));
Rrs=Rrs(II,:);
time_SeaWIFS=date_seawifs(II);
wavelength=[412 443 490 510 555 670];

%APEX data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\ARGOS\0005\float0005Surface.mat';
chl_surface(1)=float0005SurfaceChl(1,2);
time_surface(1)=float0005SurfaceChl(1,1);
I=find(diff(float0005SurfaceChl(:,1))>4);
for i=1:length(I)
    chl_surface(1+i)=float0005SurfaceChl(1+I(i),2);
    time_surface(1+i)=float0005SurfaceChl(1+I(i),1);
end
time_float=time_surface;
chl=chl_surface;

load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\APEX\0005\float0005.mat';
I2=find(float0005(:,5)>1 & float0005(:,5)<9);
S=float0005(I2,7);
T=float0005(I2,6);
bb=float0005(I2,9);
chl=chl_surface;
tt=tt(I2);
%user inputs:
%Temperature and salinity of water under consideration [degree C] (to compute water IOPs)
Temp=interp1(tt,T,time_SeaWIFS,'linear');
Salt=interp1(tt,S,time_SeaWIFS,'linear');

for i=1:length(II)
    %compute IOPs of seawater
    [a_w,bb_w]=IOP_of_sw(wavelength,Temp(i),Salt(i));
    %a_w=[0.02027,0.0111,0.01677,0.04496,0.05492,0.4920];
    %bb_w=[0.003242,0.002454,0.001622,0.001132,0.000989,0.0004262];
    [b_bp(i,:), a_phi(i,:), a_dg(i,:)]=QAA4_SeaWIFS(Rrs(i,:),a_w,bb_w);
end

figure(1);
plot(time_SeaWIFS,b_bp(:,2),'r*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('b bp (440)');

figure(2);
plot(time_SeaWIFS,a_phi(:,2),'r*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('a phi (440)');

figure(3);
plot(time_SeaWIFS,Rrs(:,6),'r*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('a phi');
