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];
mm=length(Lwn(:,1));
Rrs=1.38*Lwn(:,1:5)./(ones(mm,1)*F0);
II=find(isfinite(Rrs(:,1).*Rrs(:,2).*Rrs(:,3).*Rrs(:,4).*Rrs(:,5)));
Rrs=Rrs(II,:);
time_SeaWIFS=date_seawifs(II);
wavelength=[412 443 490 510 555];

%APEX data
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,date_seawifs,'linear');
Salt=interp1(tt,S,date_seawifs,'linear');

for i=1:length(II)
    %compute IOPs of seawater
    [a_w,bb_w]=IOP_of_sw(wavelength(1:5),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];
    rrs=Rrs./(0.52+1.7*Rrs);
    A=GSM01_invert(rrs(i,1:5),a_w,bb_w);
    chl(i)=A(1);
    a_dg(i)=A(2);
    b_bp(i)=A(3);
end

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

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

% figure(3);
% plot(date_seawifs,b_bp(:,6),'g*')
% set(gca,'XTick',[732099 732464 732829 733194 733560]);
% datetick(gca,'x','mmmyy','keepticks');
% ylabel('b bp (667)');
% 
% figure(4);
% plot(date_seawifs,a_phi(:,6),'g*')
% set(gca,'XTick',[732099 732464 732829 733194 733560]);
% datetick(gca,'x','mmmyy','keepticks');
% ylabel('a phi (667)');


