Skip to content
Snippets Groups Projects
Verified Commit 2a64b060 authored by Thomas Lambert's avatar Thomas Lambert :helicopter:
Browse files

fix(loader): automate header lines counting

parent 3aaf84a9
No related branches found
No related tags found
No related merge requests found
......@@ -34,15 +34,42 @@ function idTable = loadid(idFile)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Defaults and constants
COMMENT_LINES = 3; % Number of commented lines in the header
HEADER_STYLE = '#';
% Determine where the data starts
headerLines = calcheaderlines(idFile, HEADER_STYLE);
% Tweak options before import
opts = detectImportOptions(idFile);
opts.VariableNamesLine = COMMENT_LINES + 1;
opts.VariableUnitsLine = COMMENT_LINES + 2;
opts.DataLines = [COMMENT_LINES + 3 Inf];
opts.VariableNamesLine = headerLines + 1;
opts.VariableUnitsLine = headerLines + 2;
opts.DataLines = [headerLines + 3 Inf];
% Import
idTable = readtable(idFile, opts);
end
function headerLines = calcheaderlines(file, headerStyle)
% CALCHEADERLINES Calculate number of header lines in a file
fileID = fopen(file);
headerLines = 0;
inHeader = true;
while inHeader
line = textscan(fileID, '%s', 1, 'Delimiter', {'\n', '\r'});
line = char(line{:});
% The '' in the regex is not an empty space, it is the byte order mark that Matlab puts
% at the beginning of the stream...
if regexp(line, ['^\*\s*', headerStyle])
headerLines = headerLines + 1;
else
inHeader = false;
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment