data=importdata('C:\Data\AMMA\AMMA_NOV08\AMMA_filter_NOV_final.txt');
data2=importdata('C:\Data\AMMA\AMMA_NOV08\AMMA_flux_10uf_NOV.txt');
% This file inclueds the GOMECC data filtered for reldir, rain, lagtime,
% std(O3>3), delta O3ppb>3, filterchange, calibration, count drop. There
% fore the column O3ppb is for each filter copied and filtered values set
% to NaN

jd=data(:,1);               %julianday
sp=data(:,2);               %ship speed
u=data(:,3);                %wind speed
reldir=data(:,4);           % relative wind direction
rain=data(:,5);             %NaN=rain>5    
lag=data(:,6);              % lagtime
O3ppb_o=data(:,7);          %O3ppb
deltaO3_o=data(:,8);
O3std_o=data(:,9);                
O3ppb=data(:,10);           %O3ppb
deltaO3=data(:,11);               
O3std=data(:,12);
sp2=data(:,13);
sig_u=data(:,14);
sig_h=data(:,15);
hand=data(:,16);
total_o=data(:,17);         %total filter crosscorr without lag
total=data(:,18);           %total filter constant lagtime without lag
slowO3=data2(:,52);
O3mean=data2(:,50);   
z=O3mean;

jj=find(isnan(lag));
lag(jj)=1;
total_o(jj)=NaN;

ii=find(isnan(reldir));
reldir(ii)=2;
z(ii)=NaN;

gg=find(isnan(deltaO3_o));
delta_o(gg)=3;
z(gg)=NaN;
gg2=find(isnan(deltaO3));
delta(gg2)=3;

hh=find(isnan(O3std_o));
std_o(hh)=4;
z(hh)=NaN;
hh2=find(isnan(O3std));
std(hh2)=4;

ff=find(O3ppb_o>100 | O3ppb_o<5);
total_o(ff)=NaN;
ff2=find(O3ppb>100 | O3ppb<5);
z(ff2)=NaN;
total(ff2)=NaN;


ij=find(isnan(u));
u(ij)=10;
z(ij)=NaN;

kk=find(isnan(rain));
rain(kk)=11;
z(kk)=NaN;

ok=find(isfinite(z));
z(ok)=0;

figure;plot(jd(kk),rain(kk),'y.') ;hold on; plot(jd(ij),u(ij),'c.');plot(jd(dd),cali(dd),'g.');plot(jd(ss),countdrop(ss),'r.');
plot(jd(tt),miss(tt),'k.');plot(jd(ff2),ppb5(ff2),'m.');plot(jd(ll),filter(ll),'y.');plot(jd(hh2),std(hh2),'c.');
plot(jd(gg2),delta(gg2),'g.');plot(jd(ii),reldir(ii),'r.');plot(jd(jj),lag(jj),'m.');plot(jd(ok),z(ok),'.');
xlabel('day of year');axis([190 220 0 12]);
legend('11:rain (19)','10:wind speed (23)','9:calibration (96)', '8:count drop (95)', '7:missing data (497)', '6:O3<5ppb,>80ppb (205)', '5:filter change (30)','4:std O3 (270)', '3:delta O3 (449)','2:relative wind direction (552)' , '1:lagtime (1480)','0:remainig data (2131)');
ylabel('filter No.');

l=find(isnan(total));
figure;plot(jd(l),O3mean(l),'.');hold on;plot(jd,total,'r.');
xlabel('Day of Year'); ylabel('[O3]/ppb');title('blue: eliminated, red: remainig; excluding lag time filter');
axis([190 220 -1 90])

k=find(isnan(total_o));
figure;plot(jd(k),O3mean(k),'.');hold on;plot(jd,total_o,'r.');
xlabel('Day of Year'); ylabel('[O3]/ppb');title('blue: eliminated, red: remainig; including lag time filter');
axis([190 220 -1 90])

%j=find(isfinite(total_o));
%i=find(isnan(total_o));
%figure;plot(jd(i),slowO3(i),'.');hold on;plot(jd(j),slowO3(j),'r.');
%xlabel('Day of Year'); ylabel('[O3]/ppb');title('slowO3;blue: eliminated, red: remainig; excluding lag time filter');
%axis([190 220 -1 90])

%figure;plot(jd,O3ppb,'.');hold on;plot(jd,slowO3,'.r')
%xlabel('Day of Year'); ylabel('[O3]/ppb');
%title('red:O3 ML8810, blue: O3 FRCI');
%axis([190 220 -1 90])

%Fluxes and deposition velocity
jday=data2(:,1);
urel=data2(:,5);
lagtime=data2(:,43);            % lagtime between w and O3 calculated by crosscovriance, 10 min lagtime
O3w_o=data2(:,44);              % w'O3' calculated with crosscovariance, 10 min lagtime, no webb correction
O3mean_o=data2(:,45);           % mean O3 concentration cross (ppb)
O3dev_o=data2(:,46);            % stdev ozone cross (ppb)
O3w=data2(:,47);                % O3'w' with constant lagtime of 5.1 s, and function cov, no webb correction
O3mean=data2(:,48);             % mean O3 concentration constant lagtime (ppb)
O3dev=data2(:,49);              % stdev ozone constant lagtime (ppb)
Vd_o=data2(:,50);               % deposition velocity 10 min lagtime (cm/s)
[vdO3E,r_buz]=BuzoriusCorrection(Vd_o,urel,0.4);
Vd_o=vdO3E;
Vd=data2(:,51);                 % deposition velocity 5.1s lagtime (cm/s)
[vdO3E,r_buz]=BuzoriusCorrection(Vd,urel,0.4);
Vd=vdO3E;
slowO3=data2(:,54);
lat=data2(:,23);
lon=data2(:,24);

map;
%excluding lag time filter
%const
p=find(isfinite(total));
y=find(Vd(p)>2 | Vd(p)<-2);

Vdmean=mean(Vd(p(y)))
Vdmedian=median(Vd(p(y)))
ij=find(Vd(p(y))>0);
Vdmean2=mean(Vd(p(y(ij))))
Vdmedian2=median(Vd(p(y(ij))))

figure; plot(jday(p(y)),Vd(p(y)),'.');title('Vd constant lag time excluding lag time filter');
xlabel('Day of Year');ylabel('Vd (cm*s-1)');

%Histogram
x=-5:0.005:5;
figure;hist(Vd(p(y)),x);title('Vd constant lag time excluding lag time filter');
xlabel('Vd / cm*s-1'); ylabel('Number of Data Points');
hold on; plot([mean(Vd(p(y))) mean(Vd(p(y)))],[0 190], 'r')

%cross
p=find(isfinite(z));
Vdmean_o=mean(Vd_o(p))
Vdmedian_o=median(Vd_o(p))
ij=find(Vd_o(p)>0);
Vdmean_o2=mean(Vd_o(p(ij)))
Vdmedian_o2=median(Vd_o(p(ij)))

figure; plot(jday(p),Vd_o(p),'.');
xlabel('Day of Year');ylabel('Vd / cm*s-1');title('Vd cross correl including lag time filter');


%Histogram
x=-5:0.005:5;
figure;hist(Vd_o(p),x);
xlabel('Vd / cm*s-1'); ylabel('Number of Data Points');title('Vd cross correl including lag time filter');
hold on; plot([mean(Vd_o(p)) mean(Vd_o(p))],[0 190], 'r')

% With lagtime filter
lag=data(:,6);    
i=find(isnan(lag));
total(i)=NaN;
g=find(isfinite(total));

Vdmean3=mean(Vd(g))
Vdmedian3=median(Vd(g))
ij=find(Vd(g)>0);
Vdmean4=mean(Vd(g(ij)))
Vdmedian4=median(Vd(g(ij)))

figure; plot(jday(g),Vd(g),'.');
xlabel('Day of Year');ylabel('Vd / cm*s-1');title('Vd const lag time including lag time filter');

%Histogramm data filtered
x=-5:0.005:5;
figure;hist(Vd(g),x);
xlabel('Vd / cm*s-1'); ylabel('Number of Data Points');title('Vd constant lag time including lag time filter');
hold on; plot([mean(Vd(p)) mean(Vd(p))],[0 190], 'r')

%cross incl lag time filter
total(i)=NaN;
g=find(isfinite(total_o));
Vdmean_o3=mean(Vd_o(g))
Vdmedian_o3=median(Vd_o(g))
ij=find(Vd_o(g)>0);
Vdmean_o4=mean(Vd_o(g(ij)))
Vdmedian_o4=median(Vd_o(g(ij)))

figure; plot(jday(g),Vd_o(g),'.');
xlabel('Day of Year');ylabel('Vd / cm*s-1');title('Vd cross correl including lag time filter');

%Histogramm data filtered
x=-5:0.005:5;
figure;hist(Vd_o(g),x);
xlabel('Vd / cm*s-1'); ylabel('Number of Data Points');title('Vd cross correl including lag time filter');
hold on; plot([mean(Vd_o(p)) mean(Vd_o(p))],[0 190], 'r')