read_parameters_Stratus; %Reading parameter files flux conf from D:/data/lb/flux_eval_rhb_06
ddd=298;
hhh=10;
%read_son_day_test_07;
%[us,vs,ws,al,be]=rotcorr(u,v,w);
jd=num2str(ddd);
specsize=32768;
nover=36000-specsize;
nmx='li2';
read_licor_co2_stratus_07a;
tc2=t2a;licq2=Licor_H2O_a;licC2=Licor_CO2_a;Scs2=Scs;Fcs2=Fcs;Fhs2=Fhs;Shs2=Shs;Fc2=Fc;Sc2=Sc;


nmx='li1';
read_licor_co2_stratus_07a;
tc1=t2a;licq1=Licor_H2O_a;licC1=Licor_CO2_a;Scs1=Scs;Fcs1=Fcs;Fhs1=Fhs;Shs1=Shs;Fc1=Fc;Sc1=Sc;

nmx='lic';
read_licor_co2_stratus_07a;
ii=find(Fhs>.1);ik=ii(1);ff=Fhs(ik);ij=length(Fhs);fe=Fhs(ij);
figure;loglog(Fhs2,Fhs2.*Shs2,Fhs1,Fhs1.*Shs1,Fhs,Fhs.*Shs,Fhs(ii:ij),(Fhs(ii:ij).^(-2/3))./(Fhs(ik).^(-2/3)).*Fhs(ik).*Shs(ik));title('H2O');xlabel('f(Hz)');ylabel('f*Sx');legend('sample','null','open');
figure;loglog(Fcs2,Fcs2.*Scs2,Fcs1,Fcs1.*Scs1,Fcs,Fcs.*Scs,Fcs(ii:ij),(Fcs(ii:ij).^(-2/3))./(Fcs(ik).^(-2/3)).*Fcs(ik).*Scs(ik));title('CO2');xlabel('f(Hz)');ylabel('f*Sx');legend('sample','null','open');

figure;plot(tc2,licC2,tc1,licC1,t2a,Licor_CO2_a);title('Licor CO2 [umol/mol]');legend('sample','null','open');xlabel('Time(s)');ylabel('CO2 (\mumole/mole');
figure;plot(tc2,licq2,tc1,licq1,t2a,Licor_H2O_a);title(['Licor H2O [g/kg])']);legend('sample','null','open');xlabel('Time(s)');ylabel('q (g/kg)');

figure;semilogx(Fhs2,Shs2./Shs,Fhs1,Shs1./Shs);title('Spectral ratio: H2O');xlabel('f(Hz)');ylabel('Sy/Sx');legend('sample','null');axis([1e-4 10 0 2]);
figure;semilogx(Fcs2,Scs2./Scs,Fcs1,Scs1./Scs);title('Spectral ratio: CO2');xlabel('f(Hz)');ylabel('Sy/Sx');legend('sample','null');axis([1e-4 10 0 2]);


licC1i=interp1(tc1,licC1,t2a,'spline');
[Coc1,Fc]=csd2(detrend(licC1i),detrend(Licor_CO2_a),specsize,10,hamming(specsize),nover);
[Coc1s,Fcs]=specsmoo(Coc1,10);
licC2i=interp1(tc2,licC2,t2a,'spline');
[Coc2,Fc]=csd2(detrend(licC2i),detrend(Licor_CO2_a),specsize,10,hamming(specsize),nover);
[Coc2s,Fcs]=specsmoo(Coc2,10);
figure;semilogx(Fcs,abs(Coc1s)./sqrt(Scs1.*Scs),Fcs,abs(Coc2s)./sqrt(Scs2.*Scs),[.0001 10],[1 1],'--');title('Cxy/sqrt(Sx*Sy):CO2');xlabel('f(Hz)');ylabel('Coherence Spectrum');legend('null/open','sample/open');
figure;semilogx(Fcs,abs(Coc1s)./Scs,Fcs,abs(Coc2s)./Scs,[.0001 10],[1 1],'--');title('Cxy/Sx: CO2');xlabel('f(Hz)');ylabel('Response Spectrum');legend('null/open','sample/open');;axis([1e-4 10 0 2]);

licq1i=interp1(tc1,licq1,t2a,'spline');
[Coq1,Fq]=csd2(detrend(licq1i),detrend(Licor_H2O_a),specsize,10,hamming(specsize),nover);
[Coq1s,Fqs]=specsmoo(Coq1,10);
licq2i=interp1(tc2,licq2,t2a,'spline');
[Coq2,Fq]=csd2(detrend(licq2i),detrend(Licor_H2O_a),specsize,10,hamming(specsize),nover);
[Coq2s,Fqs]=specsmoo(Coq2,10);
figure;semilogx(Fqs,abs(Coq1s)./sqrt(Shs1.*Shs),Fqs,abs(Coq2s)./sqrt(Shs2.*Shs),[.0001 10],[1 1],'--');title('Cxy/sqrt(Sx*Sy): H2O)');xlabel('f(Hz)');ylabel('Coherence Spectrum');legend('null/open','sample/open');axis([1e-4 10 0 1.4]);
figure;semilogx(Fqs,abs(Coq1s)./Shs,Fqs,abs(Coq2s)./Shs,[.0001 10],[1 1],'--');title('Cxy/Sx: H2O');xlabel('f(Hz)');ylabel('Response Spectrum');legend('null/open','sample/open');axis([1e-4 10 0 2]);
