clear all
close all

fid = fopen('CPF003.001.msg');

rowIndex = 1;
acIndex = 1;
getHeaderLine = true;
while ~feof(fid)
    inLine = fgetl(fid)
    if(getHeaderLine)
        if strncmp(inLine, "Comment", 7)
          inLine = strrep(inLine,'/','per');
          dataLines{rowIndex} = strsplit(inLine, '\t');
          rowIndex = rowIndex + 1;
          getHeaderLine = false;
        end
    end
    
    if(strncmp(inLine, "AnchorPt", 8) || ... 
        strncmp(inLine, "AscendPt", 8) || ...
        strncmp(inLine, "AirCal", 6))
          dataLines{rowIndex} = strsplit(inLine, '\t','CollapseDelimiters',false)
          rowIndex = rowIndex + 1;
    end 
    
end
fclose(fid);

dataLines = dataLines';
dataLines = vertcat(dataLines{:});

tempDataTable = array2table(dataLines(2:end,:), 'VariableNames', dataLines(1,:));
writetable(tempDataTable, 'dataTable.txt')
dataTable = readtable('dataTable.txt', 'Format', '%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f')

dataTable.dt = datetime(dataTable.DateTime, 'InputFormat', 'yyyy-MMM-dd''T''HH:mm:ss''Z')

plot(dataTable.dt, dataTable.pres_dBar)
figure
plot(dataTable.dt, dataTable.FSig_counts, '-+');


    
    