close all

h2o1a=[];h2o2a=[];
path='C:\Data\LicorTest\';
control_data=[];Licor_data=[];ozone_data=[];
wresult=[]; O3result=[]; xcovresult=[];O3ppb=[];
lagtime=[]; control_licor1=[];control_licor2=[];
control_ozone=[];

for ddd=30;
    dd=num2str(ddd);
    if ddd<10;
       dd=['0' num2str(ddd)];	
    end;
    
    for hhh=18:20;
        hr=num2str(hhh);
        if hhh<10;
           hr=['0' num2str(hhh)];	
        end;
        
    for mmm=10;
        mm=num2str(mmm);
        if mmm<10;
           mm=['0' num2str(mmm)];	
        end;

    for yyy=7;
        yy=num2str(yyy);
        if yyy<10;
           yy=['0' num2str(yyy)];	
        end;
        
    for minu=0
        min=num2str(minu);
        if  minu<10;
            min=['0' num2str(minu)];	
        end;
        
   

%control data from computer in fast O3 instrument        
licor1_imp=importdata([path, 'Licor1\Licor1_' , yy, '-' , mm, '-',dd,'_',hr ,min, '.lvm']);
control_licor1=[control_licor1;licor1_imp]	;
disp(['licor1_',yy,'-', mm, '-', dd, '_' ,hr , min]);

licor2_imp=importdata([path, 'Licor2\LiIcor2_' , yy, '-' , mm, '-',dd,'_',hr ,min, '.lvm']);
control_licor2=[control_licor2;licor2_imp]	;
disp(['licor2_',yy,'-', mm, '-', dd, '_' ,hr , min]);

ozone_imp=importdata([path, 'ozone\ozone_' , yy, '-' , mm, '-',dd,'_',hr ,min, '.lvm']);
control_ozone=[control_ozone;ozone_imp]	;
disp(['ozone_',yy,'-', mm, '-', dd, '_' ,hr , min]);

h2o1=licor1_imp(:,3);
h2o2=licor2_imp(:,3);
h2o1=interpft(h2o1,36000);
h2o1=h2o1-21.0392;
h2o2=interpft(h2o2,36000);
h2o1a=[h2o1a;h2o1];
h2o2a=[h2o2a;h2o2];

           disp(['Calculating spectra for ',num2str(hhh)])
           [Sw,F]=psd2(detrend(h2o1),length(h2o1),10.);
           [Sws,Fsw]=specsmoo(Sw,10.);
           [Sw2,F2]=psd2(detrend(h2o2),length(h2o2),10.);
           [Sws2,Fsw2]=specsmoo(Sw2,10.);
           
           figure; loglog(Fsw(length(Fsw)-31:length(Fsw)),((Fsw(length(Fsw)-31:length(Fsw))).^(-2/3))./(Fsw(length(Fsw)-18).^(-2/3)).*Sws(length(Fsw)-18).*Fsw(length(Fsw)-18),'r');
           hold on;
           loglog(Fsw,Sws.*Fsw,'g');
           loglog(Fsw2(length(Fsw2)-31:length(Fsw2)),((Fsw2(length(Fsw2)-31:length(Fsw2))).^(-2/3))./(Fsw2(length(Fsw2)-18).^(-2/3)).*Sws2(length(Fsw2)-18).*Fsw2(length(Fsw2)-18),'y');
           loglog(Fsw2,Sws2.*Fsw2,'b');
           
           title(['H2O Spectra: green:Licor1, blue:Licor2  Day ',dd ,mm,yy,hr]);
           legend('5/3','H2O');       xlabel('Frequency in Hz');
           ylabel('Spectrum * Frequency');
           print([path,'\LicorTest\spectraH2O_' dd, hr,  '.jpg'],'-djpeg');

           
                    
                end;
            end;
        end;
    end;
end;

time=control_licor1(:,1);
co21=control_licor1(:,2);
h2o1=control_licor1(:,3);
T1=control_licor1(:,4);
p1=control_licor1(:,5);

time2=control_licor2(:,1);
co22=control_licor2(:,2);
h2o2=control_licor2(:,3);
T2=control_licor2(:,4);
p2=control_licor2(:,5);

time3=control_ozone(:,1);
ppb=control_ozone(:,2);
count=control_ozone(:,3);

%z=h2o1a-h2o2a(1:length(h2o1));


%figure; plot(z, '.'); grid;; ylabel('delta h2o'); title(['deltah20']);
figure; plot(time, co21, '.'); grid; xlabel('time / s'); ylabel('mmol/m3'); title(['co21']);
figure; plot(time2, co22, '.'); grid; xlabel('time / s'); ylabel('mmol/m3'); title(['co22']);
figure; plot(time3, ppb, '.'); grid; xlabel('time / s'); ylabel('ppb'); title(['O3 Monitor, ppb,Julianday:']);
figure; plot(time3, count, '.'); grid; xlabel('time / s'); ylabel('counts / S'); title(['fast O3, counts,Julianday:']);
figure; plot(time, h2o1, '.'); grid; xlabel('time / s'); ylabel('mmol/m3'); title(['h2o1']);
figure; plot(time2, h2o2, '.'); grid; xlabel('time / s'); ylabel('mmol/m3'); title(['h2o2']);
figure; plot(time, T1, '.'); grid; xlabel('time / s'); ylabel('degC'); title(['T1']);
figure; plot(time2, T2, '.'); grid; xlabel('time / s'); ylabel('degC'); title(['T2']);
figure; plot(time, p1, '.'); grid; xlabel('time / s'); ylabel('kPa'); title(['p1']);
figure; plot(time2, p2, '.'); grid; xlabel('time / s'); ylabel('kPa'); title(['p2']);
figure; plot(time, h2o1, '.'); hold on; plot(time2, h2o2, 'r.'); xlabel('time / s'); ylabel('mmol/m3'); title(['blue:h2o1, red:h2o2']);

