% This program is here to check and compare the different Licors present on
% the ship.
% LB on 03/25/2008

clear all;
close('all');
fclose('all');


%%%% READ FLUX TEAM PSD/Uconn Licors 7500 measurements %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
read_parameters_GASEXIII; %Reading parameter files flux conf from D:/data/lb/flux_eval_rhb_06
plotit=0;
prtit=0;
ddd=76;
hhh=00;
% ddd=87;
% hhh=23;
% ddd=90;
% hhh=2;

read_pc_day_GASEXIII_08; 

[Licor_H2O_li1,Licor_CO2_li1,Licor_Temp_li1,Licor_Press_li1,agc_li1,jd_lic_li1,Fcs_li1,Scs_li1,Fhs_li1,Shs_li1]=CO2_GASEXIII_read('li1','Uconn',ddd,way_raw_data_flux,year,hhh);
[Licor_H2O_li2,Licor_CO2_li2,Licor_Temp_li2,Licor_Press_li2,agc_li2,jd_lic_li2,Fcs_li2,Scs_li2,Fhs_li2,Shs_li2]=CO2_GASEXIII_read('li2','Uconn',ddd,way_raw_data_flux,year,hhh);
[Licor_H2O_li3,Licor_CO2_li3,Licor_Temp_li3,Licor_Press_li3,agc_li3,jd_lic_li3,Fcs_li3,Scs_li3,Fhs_li3,Shs_li3]=CO2_GASEXIII_read('li3','Uconn',ddd,way_raw_data_flux,year,hhh);

[Licor_H2O_lin,Licor_CO2_lin,Licor_Temp_lin,Licor_Press_lin,agc_lin,jd_lic_lin,Fcs_lin,Scs_lin,Fhs_lin,Shs_lin]=CO2_GASEXIII_read('lin','PSD',ddd,way_raw_data_flux,year,hhh);
[Licor_H2O_lis,Licor_CO2_lis,Licor_Temp_lis,Licor_Press_lis,agc_lis,jd_lic_lis,Fcs_lis,Scs_lis,Fhs_lis,Shs_lis]=CO2_GASEXIII_read('lis','PSD',ddd,way_raw_data_flux,year,hhh);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% READ Underway system measurement AOML %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
UWCO2_read;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% READ Licors 6262 Wade %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wade_6262_read;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure;plot(jd_lic_li1,Licor_H2O_li1,'.',jd_lic_li2,Licor_H2O_li2,'.',jd_lic_li3,Licor_H2O_li3,'.',jd_lic_lin,Licor_H2O_lin,'.',jd_lic_lis,Licor_H2O_lis,'.',jd_pc,qvais,'ko-');
legend('open 1','open 2','open 3','null','sample','PSD Vaisala');xlabel(['JD', year]);ylabel('q (g/kg)');title(['Licor specific humidity. ', cruise, year]);
ylim([-5 30]);
 print('-djpeg90 ',['E:\Data\CRUISES\GasExIII\Hawaii_meeting\042808\H2O_' num2str(ddd) num2str(hhh) '.jpg']);

figure;plot(jd_lic_li1,Licor_CO2_li1,'.',jd_lic_li2,Licor_CO2_li2,'.',jd_lic_li3,Licor_CO2_li3,'.',jd_lic_lin,Licor_CO2_lin,'.',jd_lic_lis,Licor_CO2_lis,'.',jd_UW_CO2_air,UW_CO2_air,'ko-');
legend('7500 open paired 1','7500 open paired 2','7500 open 3','7500 null','7500 sample','UWCO2 system');xlabel(['JD', year]);ylabel('CO2 (umol/mol)');title(['Licor CO2 concentration [umol/mol]. ', cruise, year]);
axis([ddd+hhh/24 ddd+(hhh+1)/24 0 800]);
 print('-djpeg90 ',['E:\Data\CRUISES\GasExIII\Hawaii_meeting\042808\CO2_' num2str(ddd) num2str(hhh) '.jpg']);


% % 
% % figure;plot(jd_lic_li1,Licor_H2O_li1,'.',jd_lic_li2,Licor_H2O_li2,'.',jd_lic_li3,Licor_H2O_li3,'.',jd_lic_lin,Licor_H2O_lin,'.',jd_lic_lis,Licor_H2O_lis,'.',jd_pc,qvais,'ko-',jd_6262-0.0003,qcell_834,'+',jd_6262-0.0003,qcell_918,'+',jd_6262-0.0003,qcell_598,'+');
% % legend('open 1','open 2','open 3','null','sample','PSD Vaisala','6262 unit 834','6262 unit 918','6262 null unit 598');xlabel(['JD', year]);ylabel('q (g/kg)');title(['Licor specific humidity. ', cruise, year]);
% % ylim([-5 30]);
% % 
% % figure;plot(jd_lic_li1,Licor_CO2_li1,'.',jd_lic_li2,Licor_CO2_li2,'.',jd_lic_li3,Licor_CO2_li3,'.',jd_lic_lin,Licor_CO2_lin,'.',jd_lic_lis,Licor_CO2_lis,'.',jd_UW_CO2_air,UW_CO2_air,'ko-',jd_6262-0.0003,co2air_834,'+',jd_6262-0.0003,co2air_918,'+',jd_6262-0.0003,co2air_598,'+');
% % legend('7500 open paired 1','7500 open paired 2','7500 open 3','7500 null','7500 sample','UWCO2 system','6262 unit 834','6262 unit 918','6262 null unit 598');xlabel(['JD', year]);ylabel('CO2 (umol/mol)');title(['Licor CO2 concentration [umol/mol]. ', cruise, year]);
% % % axis([ddd+hhh(1)/24 ddd+(hhh(length(hhh)))/24 0 800]);
% % axis([ddd+hhh/24 ddd+(hhh+1)/24 0 800]);
% % 
% % % % figure;plot(jd_lic_li1,Licor_H2O_li1,'.',jd_lic_li2,Licor_H2O_li2,'.',jd_lic_li3,Licor_H2O_li3,'.',jd_lic_lin,Licor_H2O_lin,'.',jd_lic_lis,Licor_H2O_lis,'.',jd_pc,qvais,'ko-');
% % % % legend('open 1','open 2','open 3','null','sample','PSD Vaisala');xlabel(['JD', year]);ylabel('q (g/kg)');title(['Licor specific humidity. ', cruise, year]);
% % % % ylim([-5 30]);
% % % % 
% % % % figure;plot(jd_lic_li1,Licor_CO2_li1,'.',jd_lic_li2,Licor_CO2_li2,'.',jd_lic_li3,Licor_CO2_li3,'.',jd_lic_lin,Licor_CO2_lin,'.',jd_lic_lis,Licor_CO2_lis,'.');
% % % % legend('7500 open paired 1','7500 open paired 2','7500 open 3','7500 null','7500 sample');xlabel(['JD', year]);ylabel('CO2 (umol/mol)');title(['Licor CO2 concentration [umol/mol]. ', cruise, year]);
% % % % axis([ddd+hhh/24 ddd+(hhh+1)/24 0 800]);
% % % 
% % % 
% % 
% % if 0
% % ii=find(Fhs_li1>.1);ik=ii(1);ff=Fhs_li1(ik);ij=length(Fhs_li1);fe=Fhs_li1(ij);
% % figure;loglog(Fhs_li1,Fhs_li1.*Shs_li1,Fhs_li2,Fhs_li2.*Shs_li2,Fhs_li3,Fhs_li3.*Shs_li3,Fhs_lin,Fhs_lin.*Shs_lin,Fhs_lis,Fhs_lis.*Shs_lis);
% % hold on;loglog(Fhs_834,Fhs_834.*Shs_834,'--',Fhs_918,Fhs_918.*Shs_918,'--',Fhs_598,Fhs_598.*Shs_598,'--',Fhs_li1(ii:ij),(Fhs_li1(ii:ij).^(-2/3))./(Fhs_li1(ik).^(-2/3)).*Fhs_li1(ik).*Shs_li1(ik))
% % title('H2O');xlabel('f(Hz)');ylabel('f*Sx');
% % legend('7500 open paired 1','7500 open paired 2','7500 open 3','7500 null','7500 sample','6262 unit 834','6262 unit 918','6262 null unit 598')
% % 
% % figure;loglog(Fcs_li1,Fcs_li1.*Scs_li1,Fcs_li2,Fcs_li2.*Scs_li2,Fcs_li3,Fcs_li3.*Scs_li3,Fcs_lin,Fcs_lin.*Scs_lin,Fcs_lis,Fcs_lis.*Scs_lis,Fcs_li1(ii:ij),(Fcs_li1(ii:ij).^(-2/3))./(Fcs_li1(ik).^(-2/3)).*Fcs_li1(ik).*Scs_li1(ik));
% % hold on;loglog(Fcs_834,Fcs_834.*Scs_834,'--',Fcs_918,Fcs_918.*Scs_918,'--',Fcs_598,Fcs_598.*Scs_598,'--')
% % title('CO2');xlabel('f(Hz)');ylabel('f*Sx');
% % legend('7500 open paired 1','7500 open paired 2','7500 open 3','7500 null','7500 sample','6262 unit 834','6262 unit 918','6262 null unit 598')
% % 
% % % 
% % % figure;plot(jd_lic_li1,Licor_Temp_li1,'.',jd_lic_li2,Licor_Temp_li2,'.',jd_lic_li3,Licor_Temp_li3,'.',jd_lic_lin,Licor_Temp_lin,'.',jd_lic_lis,Licor_Temp_lis,'.');
% % % legend('open 1','open 2','open 3','null','sample');xlabel(['JD', year]);ylabel('Temp (degC)');title(['Licor temperature. ', cruise, year]);
% % % 
% % % figure;plot(jd_lic_li1,Licor_Press_li1,'.',jd_lic_li2,Licor_Press_li2,'.',jd_lic_li3,Licor_Press_li3,'.',jd_lic_lin,Licor_Press_lin,'.',jd_lic_lis,Licor_Press_lis,'.');
% % % legend('open 1','open 2','open 3','null','sample');xlabel(['JD', year]);ylabel('Press (kPa)');title(['Licor pressure. ', cruise, year]);
% % % 
% % % figure;plot(jd_lic_li1,agc_li1,'.',jd_lic_li2,agc_li2,'.',jd_lic_li3,agc_li3,'.',jd_lic_lin,agc_lin,'.',jd_lic_lis,agc_lis,'.');
% % % legend('open 1','open 2','open 3','null','sample');xlabel(['JD', year]);ylabel('AGC (%)');title(['Licor AGC value. ', cruise, year]);
% % 
% % 
% % Licor_H2O_li1=interpft(Licor_H2O_li1(~isnan(Licor_H2O_li1)),36000);
% % Licor_H2O_li2=interpft(Licor_H2O_li2(~isnan(Licor_H2O_li2)),36000);
% % Licor_H2O_li3=interpft(Licor_H2O_li3(~isnan(Licor_H2O_li3)),36000);
% % Licor_H2O_lis=interpft(Licor_H2O_lis(~isnan(Licor_H2O_lis)),36000);
% % Licor_H2O_lin=interpft(Licor_H2O_lin(~isnan(Licor_H2O_lin)),36000);
% % 
% % ii=find(~isnan(Licor_H2O_li1));
% % specsize=length(Licor_H2O_li1(ii));
% % nover=36000-specsize;
% % 
% % [Coq1,Fq]=csd2(detrend(Licor_H2O_lin),detrend(Licor_H2O_li1),specsize,10,hamming(specsize),nover);[Coq1s,Fqs]=specsmoo(Coq1,10);
% % [Coq2,Fq]=csd2(detrend(Licor_H2O_lis),detrend(Licor_H2O_li1),specsize,10,hamming(specsize),nover);[Coq2s,Fqs]=specsmoo(Coq2,10);
% % figure;semilogx(Fqs,abs(Coq1s)./sqrt(Shs_li1.*Shs_lin),Fqs,abs(Coq2s)./sqrt(Shs_li1.*Shs_lis),[.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_li1,Fqs,abs(Coq2s)./Shs_li1,[.0001 10],[1 1],'--');title('Cxy/Sx: H2O');xlabel('f(Hz)');ylabel('Response Spectrum');legend('null/open','sample/open');axis([1e-4 10 0 1.4]);
% % 
% % [Coq1,Fq]=csd2(detrend(Licor_H2O_lin),detrend(Licor_H2O_li2),specsize,10,hamming(specsize),nover);[Coq1s,Fqs]=specsmoo(Coq1,10);
% % [Coq2,Fq]=csd2(detrend(Licor_H2O_lis),detrend(Licor_H2O_li2),specsize,10,hamming(specsize),nover);[Coq2s,Fqs]=specsmoo(Coq2,10);
% % figure;semilogx(Fqs,abs(Coq1s)./sqrt(Shs_li2.*Shs_lin),Fqs,abs(Coq2s)./sqrt(Shs_li2.*Shs_lis),[.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_li2,Fqs,abs(Coq2s)./Shs_li2,[.0001 10],[1 1],'--');title('Cxy/Sx: H2O');xlabel('f(Hz)');ylabel('Response Spectrum');legend('null/open','sample/open');axis([1e-4 10 0 1.4]);
% % 
% % [Coq1,Fq]=csd2(detrend(Licor_H2O_lin),detrend(Licor_H2O_li3),specsize,10,hamming(specsize),nover);[Coq1s,Fqs]=specsmoo(Coq1,10);
% % [Coq2,Fq]=csd2(detrend(Licor_H2O_lis),detrend(Licor_H2O_li3),specsize,10,hamming(specsize),nover);[Coq2s,Fqs]=specsmoo(Coq2,10);
% % figure;semilogx(Fqs,abs(Coq1s)./sqrt(Shs_li3.*Shs_lin),Fqs,abs(Coq2s)./sqrt(Shs_li3.*Shs_lis),[.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_li3,Fqs,abs(Coq2s)./Shs_li3,[.0001 10],[1 1],'--');title('Cxy/Sx: H2O');xlabel('f(Hz)');ylabel('Response Spectrum');legend('null/open','sample/open');axis([1e-4 10 0 1.4]);
% % 
% % Licq1=interpft(Licor_H2O_li2(~isnan(Licor_H2O_li2)),18000);Licq1=Licq1';
% % [SLicq1,FLicq1]=psd2(detrend(Licq1),18000,5,hamming(18000));[SLicq1s,FLicq1s]=specsmoo(SLicq1,5);
% % [Coq1,Fq]=csd2(detrend(qcell_834),detrend(Licq1),18000,5,hamming(18000),nover);[Coq1s,Fqs]=specsmoo(Coq1,5);
% % [Coq2,Fq]=csd2(detrend(qcell_918),detrend(Licq1),18000,5,hamming(18000),nover);[Coq2s,Fqs]=specsmoo(Coq2,5);
% % [Coq3,Fq]=csd2(detrend(qcell_598),detrend(Licq1),18000,5,hamming(18000),nover);[Coq3s,Fqs]=specsmoo(Coq3,5);
% % figure;semilogx(Fqs,abs(Coq1s)./sqrt(SLicq1s.*Shs_834),Fqs,abs(Coq2s)./sqrt(SLicq1s.*Shs_918),Fqs,abs(Coq3s)./sqrt(SLicq1s.*Shs_598),[.0001 10],[1 1],'--');title('Cxy/sqrt(Sx*Sy): H2O)');xlabel('f(Hz)');ylabel('Coherence Spectrum');legend('6262 unit 834/open paired 1','6262 unit 918/open paired 1','6262 null unit 598/open paired 1');axis([1e-4 10 0 1.4]);
% % figure;semilogx(Fqs,abs(Coq1s)./SLicq1s,Fqs,abs(Coq2s)./SLicq1s,Fqs,abs(Coq3s)./SLicq1s,[.0001 10],[1 1],'--');title('Cxy/Sx: H2O');xlabel('f(Hz)');ylabel('Response Spectrum');legend('6262 unit 834/open paired 1','6262 unit 918/open paired 1','6262 null unit 598/open paired 1');axis([1e-4 10 0 1.4]);
% % 
% % 
% % [Coq1,Fq]=csd2(detrend(Licor_H2O_lin),detrend(uvwplat(1,:)),36000,10,hamming(36000));[Coq1s,Fqs]=specsmoo(Coq1,10);
% % [Coq2,Fq]=csd2(detrend(Licor_H2O_lin),detrend(uvwplat(2,:)),36000,10,hamming(36000));[Coq2s,Fqs]=specsmoo(Coq2,10);
% % [Coq3,Fq]=csd2(detrend(Licor_H2O_lin),detrend(uvwplat(3,:)),36000,10,hamming(36000));[Coq3s,Fqs]=specsmoo(Coq3,10);
% % figure;semilogx(Fqs,abs(Coq1s)./sqrt(Shs_lin.*Sx),Fqs,abs(Coq2s)./sqrt(Shs_lin.*Sy),Fqs,abs(Coq3s)./sqrt(Shs_lin.*Sz),[.0001 10],[1 1],'--')
% % title('H2O Coherence Spectrum with platform velocity)');xlabel('f(Hz)');ylabel('Cxy/sqrt(Sx*Sy)');legend('null/U platform','null/V platform','null/W platform');axis([1e-4 10 0 1.4]);

% % end;