disp('AMMA_fixit_da1')

%tsg(1)=27.2;
ii=find(tsg<2 | tsg>32.5);
for i=1:length(ii)
   tsg(ii(i))=tsg(ii(i)-1);%tsg data limits
end;

jj=find(tsnk<2 | tsnk>32.5);tsnk(jj)=tsg(jj);%tsg data limits

jj=find(ta<02);ta(jj)=ta_im(jj);%tsg data limits
jj=find(jdy>192 & jdy<217 & ta<15);ta(jj)=ta(jj-1);
jj=find(jdy>192  & ta<14);ta(jj)=ta(jj-1);
qa=qa/1.018;%based on psychro calibrations
ta=ta+.00;%
jj=find( qa<7);qa(jj)=qa(jj-1);

ii=find(abs(U-U_scs)>10);U(ii)=U_scs(ii);dir(ii)=dir_scs(ii);

ii=find(abs(rl_im-rl)>1000);rl_im(ii)=rl(ii);

rs=1.05*rs;%cal of pyranometer
jj=find(rs<-50);rs(jj)=rs_im(jj);%tsg data limits
jj=find(rl<150 | rl>500);rl(jj)=NaN;%tsg data limits



%******************  correct org for offest *****
orgx=org;
org=max(0,orgx-.0);%(.42+(.6-.42)/(205-255)*(jdy-205)));
%ii=find(jdy>196.99);org(ii)=orgx(ii)-.44;

ii=find(abs(Lat)>500);Lat(ii)=Lat(ii-1);
ii=find(abs(Lon)>500 | Lon>-10);Lon(ii)=Lon(ii-1);

%check covariances for reasonable limits
ii=find(wuj<-.8 | wuj>.2);wuj(ii)=NaN;%wu1
ii=find(wu<-.8| wu>.2);wu(ii)=NaN;%wu2
ii=find(wv<-.8 | wv>.2);wv(ii)=NaN;%wv


%wt_son(ii)=wt_son(ii)/1000;
ii=find(wt_son<-.2 | wt_son>.5);wt_son(ii)=NaN;%wt

ii=find(qa<5);qa(ii)=qa_im(ii);
%fq=1.03*ones(length(jdy),ones)/.85;%moorings

rq=qa./wq_lic;
fq=1.05*max(1,1+.89*(rq-1.044));

%fq=qa./q_oph;
%ii=find(isnan(q_oph));fq(ii)=NaN;
%wq_oph=wq_oph.*fq*1.045;%correct 
%ii=find(wq<-.05 | wq>0.1);wq_oph(ii)=NaN;%wq
%wq=wq_oph;
%qq=qq.*fq.*fq;
%cq=cq.*fq.*fq;

%check variances for reasonable limits

ii=find(uu>20);uu(ii)=NaN;%uu
ii=find(vv>20);vv(ii)=NaN;%vv
ii=find(ww>10);ww(ii)=NaN;%ww
%tt(ii)=tt(ii)/1e5;
ii=find(tt>1);tt(ii)=NaN;%tt
%ii=find(qq>1);qq(ii)=NaN;%qq




%compute mean Cs from Cu and Cw
cup=cu;
cwp=cw;
ii=find(cup<0 |cup >1);cup(ii)=NaN;cu(ii)=NaN;
kk=find(cwp<0 |cwp >1);cwp(kk)=NaN;cw(kk)=NaN;



%edit ct and cq for bad data
%ii=find(cq<1e-4 | cq>.1);cq(ii)=NaN;
%ii=find(ct>1e2);
%ct(ii)=ct(ii)/1e5;
ii=find(ct<1e-6 | ct>1);ct(ii)=NaN;
ii=find(co<0 | co>1);co(ii)=NaN;
ii=find(cql<0 | cql>1);cql(ii)=NaN;
%xy=load('d:\cwf\data\epic_99\slope.txt');%read file with ophir ID slope data

%correct snake for solar contamination
%tsnk=tsnk-4.0e-4*rs;%not needed for Nauru


%nar_windnorm;%correct for wind distortion
AMMA_Xfixit_da2;
