clear all
close all

%Read input data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\APEX\0015\Modis\MODIS_spectra_7_5km.mat'; % 0015
Lwn=spectra_median;
F0=[172.718,187.688,194.973,185.820,186.594];
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_MODIS=datenum_modis(II);
wavelength=[412 443 488 531 551];

%APEX data
load 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\APEX\0015\float0015.mat'; % 0015
I2=find(float0015(:,5)>1 & float0015(:,5)<9);
S=float0015(I2,7);
T=float0015(I2,6);
bb=float0015(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_MODIS,'linear');
Salt=interp1(tt,S,time_MODIS,'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_MODIS,b_bp,'g*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('b bp (443)');

figure(2); % chl
plot(time_MODIS,chl,'g*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('chl');

figure(3); % 
plot(time_MODIS,a_dg,'g*')
set(gca,'XTick',[732099 732464 732829 733194 733560]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('a_dg');

% figure;plot(Salt,a_dg,'*'); % salinity


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

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


