clear
close all
load  data20160826
lat=54.255;
lon=17.970;
X=load('calib.dat');
CALIB=X(:,2);

dt=2;
data.doy=day2jd(data.year,data.month,data.day)+data.time/24;
[az,data.el]=sunpos(data.year,fix(data.doy),data.time-dt,lat,lon);
data.m=airmass(data.el);
wav=1020;
[v,ind]=min(abs(data.lambda-wav));
indt=find(data.m>1.9&data.m<6);
plot(data.m(indt),log(data.I(indt,ind)),'o')
set(gca,'xlim',[0 7])
A=polyfit(data.m(indt),log(data.I(indt,ind)),1)
M=[0:0.1:6];
Y=polyval(A,M);
hold on
plot(M,Y,'k')
AOD=-A(1)-rayleigh(data.lambda(ind),1013)


for k=1:1024
 A=polyfit(data.m(indt),log(data.I(indt,k)),1);
 O3(k)=opt_ozon(data.lambda(k),350);
 TAU(k)=-A(1);
 TAUray(k)=rayleigh(data.lambda(k),1013);
end

figure
plot(data.lambda,TAU)
hold on
plot(data.lambda,TAU-TAUray,'r')
plot(data.lambda,TAU-TAUray-O3,'k')
legend('TOTAT AOD','AOD-RAY','AOD-RAY-O3')