disp(['read_dpco2']);

z=[];ncol=16;
%fclose('all');

for jam=00:23
    hr=sprintf('%02i',jam);
    jd=sprintf('%03i',ddd);

    dfx=[jd hr];

    dfl=[way_raw_data_flux, yyyy(3:4),jd,'\', 'pc00' yyyy(3:4) jd hr '_raw.txt'];
    disp(dfl);

    flist=fopen(dfl,'r');

    if flist>0
       while feof(flist)==0,  
           try        
% 0000339 <li840><data><celltemp>5.1517286e1</celltemp><cellpres>1.0154567e2</cellpres><co2>4.2964444e2</co2><co2abs>7.6984672e-2</co2abs><h2o>2.3213593e1</h2o><h2oabs>1.2517902e-1</h2oabs><h2odewpoint>2.0072984e1</h2odewpoint><ivolt>1.1124877e1</ivolt><raw><co2>1641395</co2><co2ref>2181723</co2ref><h2o>1268637</h2o><h2oref>1381192</h2oref></raw></data></li840>
             
               temp=textscan(flist,'%2f%2f%3f <li840><data><celltemp>%f</celltemp><cellpres>%f</cellpres><co2>%f</co2><co2abs>%f</co2abs><h2o>%f</h2o><h2oabs>%f</h2oabs><h2odewpoint>%f</h2odewpoint><ivolt>%f</ivolt><raw><co2>%f</co2><co2ref>%f</co2ref><h2o>%f</h2o><h2oref>%f</h2oref></raw></data></li840> %*[^\n]', 'headerlines', 1, 'emptyvalue', NaN);
               temp{1,length(temp)+1}=jam*ones(length(temp{end}),1);
               z=[z cell2mat(temp)'];
           catch
                 for ll=1:ncol
                     [l8,c8]=size(temp{1,ncol});
                     if length(temp{1,ll})~=l8
                         temp{1,ll}(l8+1)=[];
                     end;
                 end;
                 if ~isempty(temp{1,1})
                     z=[z cell2mat(temp)'];
                 end;
            end;     
   
       end;    

       fclose(flist);   
    end
%    z(:,any(isnan(z),1))=[];
end

chk=size(z);
   if chk(1)==ncol,
    tpCO2= z(1,:)*60+z(2,:)+z(3,:)/1000; %time in s
    jd_pCO2=ddd + (z(end,:) + tpCO2/3600)/24;
    pCO2_celltemp=single(z(4,:));
    pCO2_cellpres=single(z(5,:));
    pCO2_co2=single(z(6,:));
    pCO2_co2abs=single(z(7,:));
    pCO2_h2o=single(z(8,:));
    pCO2_h2oabs=single(z(9,:));
    pCO2_h2odewpoint=single(z(10,:));
    pCO2_ivolt=single( z(11,:));
    pCO2_rawco2=single( z(12,:));
    pCO2_co2ref=single(z(13,:));
    pCO2_rawh2o=single(z(14,:));
    pCO2_h2oref=single(z(15,:));

   end;


clear z temp
if  exist('pCO2_co2','var') && ~isempty(pCO2_co2)

figure;plot(jd_pCO2,pCO2_co2,'b');
title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  pCO2 system',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')
xlabel('Hour (UTC)');ylabel('CO2 (\mumol/mol)');
% axis([ddd ddd+1 median(pCO2_co2(~isnan(pCO2_co2)))-20 median(pCO2_co2(~isnan(pCO2_co2)))+20])
axis([ddd ddd+1 350 500])
set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
grid
annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
if prtit; print(graphdevice,[way_images_flux, cruise '_pCO2_system_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end

figure;
annotation(gcf,'textbox',[0.072 0.85 0.8498 0.12462],'String',sprintf('%s (%04i-%02i-%02i, DOY%03i).  dpCO2 parameters ',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontSize',12,'FitBoxToText','off','LineStyle','none','FontWeight','Bold','Interpreter','none'); 

subplot(2,2,1)
plot(jd_pCO2,pCO2_celltemp,'b')
xlabel('Hour (UTC)');ylabel('Cell Temperature (degC)');
axis([ddd ddd+1 51 52]); 
set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))
grid

subplot(2,2,2)
plot(jd_pCO2,pCO2_cellpres,'b');
xlabel('Hour (UTC)');ylabel('Cell Pressure (kPa)'); axis([ddd ddd+1 95 110]); 
set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
grid

subplot(2,2,3)
plot(jd_pCO2,pCO2_ivolt,'b');
xlabel('Hour (UTC)');ylabel('ivolt (V)'); axis([ddd ddd+1 10.5 11.5]); 
set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
grid

subplot(2,2,4)
plot(jd_pCO2,pCO2_h2odewpoint,'b')
xlabel('Hour (UTC)');ylabel('Dew point (degC)'); axis([ddd ddd+1 -100 0]); 
set(gca(gcf),'XTick',ddd:2/24:ddd+1);datetick('x','HH:MM','keepticks');
xax=get(gca(gcf),'XTickLabel');xax(end,:)='24:00';set(gca(gcf),'XTickLabel',xax(:,1:2))    
grid

annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
if prtit; print('-djpeg90 ',[way_images_flux cruise '_dpCO2_control_parameters_' sprintf('%04i_%02i_%02i_%03i',Vdate(1),Vdate(2),Vdate(3),ddd) graphformat]); end

    
    
    jd_ref=ddd+(0:1439)/60/24;
    pCO2_co2i=intavg(jd_pCO2,pCO2_co2,jd_ref); %g/kg   
end;    
