
licor_prefix='li0';
disp(['read_co2_7200: ', licor_prefix]);

Licrate=10;%data rate in Hz
Lenlic=3600*Licrate;
Nlenlic=floor(Lenlic/6);
ncol=11;

z=[];zz=[];temp=[];
% z=NaN+zeros(ncol,36000); % flicor=10Hz -->864000 samples
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,'\', 'li00' yyyy(3:4) jd hr '_raw.txt'];
  

    flist=fopen(dfl,'r');
     zz=[];temp=[];
    if flist>0
          disp(dfl);
% (Data (DiagVal 8191)(DiagVal2 0)(CO2Raw 0.130853)(H2ORaw 0.0912389)(CO2D 25.0466
% )(H2OD 693.592)(Temp 32.5851)(Pres 100.943)(APres 101.015)(DPres
% -0.0717261)(Coo
% ler 2.19796)(CO2MF 630.709)(CO2MFd 641.921)(H2OMF 17.4657)(H2OMFd 17.7762)(DewPt
%  15.468)(AvgTemp 32.6053)(TempIn 32.5984)(TempOut 32.607)(AvgSS 101.976)(CO2SS 1
% 01.861)(H2OSS 102.09)(DeltaSS -0.228477)(H2OAW 36302.5)(H2OAWO 39748.5)(CO2AW 30
% 851)(CO2AWO 32694))
       while feof(flist)==0,  
           try    %VOCALS 2008 is lic, and has 2 data formats!...      
                temp=textscan(flist,'%2f%2f%3f %f %*f %*f:%*f:%*f:%*f %*f %*f %*f %*f %*f %*f %*f %f %*f %f %f %*f %*f %f %*f %f %f %*f %*f %*f %*f %*f %*f %*f %*f %*[^\n]','delimiter', ', ', 'headerlines', 1, 'emptyvalue', NaN,'treatAsEmpty','Overflow');%          temp =textscan(flist,'%2f%2f%3f %f %f %f %f %f %*[^\n]','delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN);
               temp{1,length(temp)+1}=hhh*ones(length(temp{end}),1);
%                zz=single(cell2mat(temp));  do not single time!
                zz=cell2mat(temp);  
               zy=[zz(:,1:4) single([zz(:,5:end-1)]) zz(:,end)]';
               z=[z zy];
           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)'];
                        % zz=single(cell2mat(temp));  do not single time!
                        zz=cell2mat(temp);  
                        zy=[zz(:,1:4) single([zz(:,5:end-1)]) zz(:,end)]';;%zy=[zz(:,1:4) single([zz(:,7:8) zz(:,10:12) zz(:,14:18) zz(:,20:21)]) zz(:,26)]';
                        z=[z zy];
                 end;
            end;     
   
       end;    

       fclose(flist);   
    end
%    z(:,any(isnan(z),1))=[];
% end
% Data Outputs: Ndx | Time | Date | CO2Raw | H2ORaw | DiagVal | CO2D | H2OD | Temp |
% AvgTemp | TempIn | TempOut | Pres | APres | DPres | FlowPressure | MeasFlowRate |
% VolFlowRate | FlowPower | FlowDrive | Aux | Aux2 | Aux3 | Aux4 | Cooler | CO2MF |
% CO2MFd | H2OMF | H2OMFd | DewPt | H2OAW | H2OAWO | CO2AW | CO2AWO

%CO2Raw --> CO2 absorptance
%CO2D --> CO2 density (mmol m-3)
%CO2MF --> CO2 mol fraction (?mol/mol)
%CO2MFd --> CO2 mol fraction dry (?mol/mol)
%H2OD --> H2O density (mmol m-3)
%H2OMF --> H2O mol fraction (mmol/mol)
% Temp --> Block temperature, °C
% AvgTemp --> Weighted average temperature of tin and tout, °C
% TempIn --> Inlet temperature, °C
% TempOut --> Outlet temperature, °C
% Pres --> Total pressure, kPa
% Apres --> Absolute pressure (LI-7550),kPa
% Dpres --> Differential pressure (sensor head), kPa
% H2OAW --> H2O source
% H2OAWO --> H2O reference
% CO2AW --> CO2 source
% CO2AWO --> CO2 reference
% Cooler --> Detector cooler (Volts)

% 4614811 (Data (DiagVal 8183)(CO2Raw 0.087695)(H2ORaw 0.0429437)(CO2D 15.5907)(H2OD 285.381)(Temp 22.3643)(Pres 82.4158)(APres 82.5536)(DPres -0.137818)(Cooler 2.059)(CO2MF 464.7)(CO2MFd 468.687)(H2OMF 8.50612)(H2OMFd 8.5791)(DewPt 1.85432)(AvgTemp 22.3796)(TempIn 22.3715)(TempOut 22.3816)(H2OAW 42432.5)(H2OAWO 44162)(CO2AW 35737)(CO2AWO 36105))
 
chk=size(z);
   if chk(1)==ncol,
      t7200= z(1,:)*60+z(2,:)+z(3,:)/1000; %time in s
      jd7200=ddd + (z(end,:) + t7200/3600)/24;
      LI7200_agc=single(z(4,:));  %diagnostic value
%       LI7200_CO2raw=z(5,:); %CO2 absorptance
%       LI7200_H2Oraw=z(6,:); %H2O absorptance
%       LI7200_CO2d=single(z(5,:)); %CO2 density (mmol m-3)
%       LI7200_H2Od=single(z(6,:)); %H2O density (mmol m-3)
%      LI7200_Tblock=z(9,:); %Temperature at IRGA block, °C
%       LI7200_Press=single(z(7,:)); %Total pressure, kPa
%       LI7200_APress=single(z(8,:)); % Absolute pressure (LI-7550),kPa
      LI7200_Headpress=single(z(5,:)); % Differential pressure (sensor head), kPa
 %     LI7200_cooler=z(13,:); %Detector cooler (Volts)
      LI7200_CO2mf=single(z(6,:)); %CO2 mol fraction (umol/mol)
      LI7200_CO2mfd=single(z(7,:));  %CO2 mol fraction dry (umol/mol)
%       LI7200_H2Omf=single(z(12,:));  %H2O mol fraction (mmol/mol)
%       LI7200_H2Omfd=single(z(13,:)); %H2O mol fraction dry (mmol/mol)?
      LI7200_Tdew=single(z(8,:)); %Dewpoint temperature (degC)
%      LI7200_Tmean=z(19,:); %Weighted average temperature of tin (20%) and tout(80%), °C
      LI7200_Tin=single(z(9,:)); %Inlet temperature, °C
      LI7200_Tout=single(z(10,:)); %Outlet temperature, °C
%       LI7200_H2OAW=z(22,:); %H2O source
%       LI7200_H2OAWO=z(23,:); % H2O reference
%       LI7200_CO2AW=z(24,:); % CO2 source
%       LI7200_CO2AWO=z(25,:); % CO2 reference


% AGC= LI7200agc(LI7200_agc,'AGConly');
% AGC=(LI7200_agc-(bin2dec('1111111110000')))*6.25+6.25; %Assumes all other flags are OK
AGC=dec2bin(LI7200_agc,16); %
AGC=bin2dec(AGC(end-3:end))*6.67;
% 100 is clean, 80 is
% relatively dirty, 50 is very dirty (the equivalent of an AGC value of 100 in
% earlier versions of the LI-7200 software), and 0 would mean no signal at all.
clear z temp
   end;
