-
Thomas Lambert authoredThomas Lambert authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
loadid.m 2.35 KiB
function idTable = loadid(idFile)
% LOADID Load the identification file into a table.
%
% Note
% The identification table must obey to the following scheme
% # Header line 1
% # ... (any number of header lines)
% # Header last line
% DataName1, DataName2, ..., DataNameN
% DataUnit1, DataUnit2, ..., DataUnitN
% Data1, Data2, ..., Data3
%
% The number of header lines is NOT detected automatically and must be specified as a constant
% -----
%
% Syntax:
% idTable = loadid(idFile) load the identification file into a Matlab table.
%
% Inputs:
% idFile: Identification file.
%
% Outputs:
% idTable: Table with the identification data.
%
% See also: readdata.
% ----------------------------------------------------------------------------------------------
% TODO: Check for inconsistencies in the table (in terms of speed, temperature, etc)
% ----------------------------------------------------------------------------------------------
% (c) Copyright 2022 University of Liege
% Author: Thomas Lambert <t.lambert@uliege.be>
% ULiege - Aeroelasticity and Experimental Aerodynamics
% MIT License
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Defaults and constants
HEADER_STYLE = '#';
% Determine where the data starts
headerLines = calcheaderlines(idFile, HEADER_STYLE);
% Tweak options before import
opts = detectImportOptions(idFile);
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