data=importdata('C:\Data\AMMA\flux_data\AMMA_filter_10.txt');

jd=data(:,1);               %julianday
sp=data(:,2);               %ship speed
u=data(:,3);
reldir=data(:,4);
rain=data(:,5);             %NaN=rain>5    
lag=data(:,6);
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=O3ppb_o;
total=O3ppb;
  

ii=find(u<0.5);
u(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,3)=u;

ii=find(reldir<270 & reldir>90);
reldir(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,4)=reldir;

ii=find(rain>5);
rain(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,5)=rain;

ii=find(lag>70 | lag<40);
lag(ii)=NaN;
data(:,6)=lag;

ii=find(O3ppb_o<5 | O3ppb_o>80);
O3ppb_o(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,7)=O3ppb_o;

ii=find(O3std_o>3 | O3std_o<-3);
O3std_o(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,9)=O3std_o;

ii=find(deltaO3_o>3 | deltaO3_o<-3);
deltaO3_o(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,8)=deltaO3_o;

ii=find(O3ppb<5 | O3ppb>80);
O3ppb(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,10)=O3ppb;

ii=find(O3std>3 | O3std<-3);
O3std(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,12)=O3std;

ii=find(deltaO3>3 | deltaO3<-3);
deltaO3(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,11)=deltaO3;

ii=find(sp2>2);
sp2(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,13)=sp2;

ii=find(sig_u> 0.5);
sig_u(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,14)=sig_u;

ii=find(sig_h> 8);
sig_h(ii)=NaN;
total_o(ii)=NaN;
total(ii)=NaN;
data(:,15)=sig_h;


ii=find(isnan(hand));
total_o(ii)=NaN;
total(ii)=NaN;

data(:,17)=total_o;
data(:,18)=total;

save(['C:\Data\AMMA\flux_data\AMMA_filter_10_final.txt'], 'data','-ascii');
