*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit b7aca589 authored by Innerberger, Michael's avatar Innerberger, Michael
Browse files

Change type struct to dictionary to avoid frequent reflective calls

parent c3485b21
Branches
Tags
No related merge requests found
...@@ -19,21 +19,26 @@ classdef LevelData < handle ...@@ -19,21 +19,26 @@ classdef LevelData < handle
properties properties
% map for general metadata % map for general metadata
metaData metaData (1,1) dictionary
% Root folder for file storage % Root folder for file storage
root root
% Structure array storing string representations of variables % Structure array storing string representations of variables
dictionary dictionary
% Cell array of level data % Array of level data
level (1,:) struct level (1,:) struct
% Structure array of data types % Dictionary of data types
type (1,1) struct type (1,1) dictionary
% Cell array of names of absolute value variables % Cell array of names of absolute value variables
absoluteVariable (1,:) cell absoluteVariable (1,:) cell
% Cell array of names of timing variables % Cell array of names of timing variables
timeVariable (1,:) cell timeVariable (1,:) cell
end end
properties (Access=private)
% Dictionary of categories for cataloguing and plotting
category (1,1) dictionary
end
properties (Dependent) properties (Dependent)
% Path to folder for file storage % Path to folder for file storage
foldername (1,:) char foldername (1,:) char
...@@ -89,6 +94,8 @@ classdef LevelData < handle ...@@ -89,6 +94,8 @@ classdef LevelData < handle
obj.metaData("timestamp") = char(datetime('now', 'Format', 'yyyy-MM-dd_HH:mm:ss')); obj.metaData("timestamp") = char(datetime('now', 'Format', 'yyyy-MM-dd_HH:mm:ss'));
end end
obj.category = dictionary();
ensureFolderExists(obj.root); ensureFolderExists(obj.root);
% Initialise dictionary with some default values % Initialise dictionary with some default values
obj.dictionary = getDefaultDictionary(); obj.dictionary = getDefaultDictionary();
...@@ -140,7 +147,7 @@ classdef LevelData < handle ...@@ -140,7 +147,7 @@ classdef LevelData < handle
% contains a scalar value per level only % contains a scalar value per level only
bool = false(1, obj.nVariable); bool = false(1, obj.nVariable);
for j = 1:obj.nVariable for j = 1:obj.nVariable
t = obj.type.(obj.label{j}); t = obj.type(obj.label{j});
if strcmp(t.shape, 's') if strcmp(t.shape, 's')
bool(j) = true; bool(j) = true;
end end
...@@ -225,11 +232,11 @@ classdef LevelData < handle ...@@ -225,11 +232,11 @@ classdef LevelData < handle
end end
arguments (Repeating) arguments (Repeating)
variableName variableName {mustBeTextScalar}
end end
obj.level = rmfield(obj.level, variableName{:}); obj.level = rmfield(obj.level, variableName);
obj.type = rmfield(obj.type, variableName{:}); obj.type(variableName) = [];
end end
function removeLevel(obj, jLevel) function removeLevel(obj, jLevel)
...@@ -246,7 +253,7 @@ classdef LevelData < handle ...@@ -246,7 +253,7 @@ classdef LevelData < handle
%e.g., to reduce storage size %e.g., to reduce storage size
% REMOVENONSCALAR(obj) % REMOVENONSCALAR(obj)
variableNonScalar = setdiff(obj.label, obj.scalarVariable); variableNonScalar = setdiff(obj.label, obj.scalarVariable);
obj.remove(variableNonScalar); obj.remove(variableNonScalar{:});
end end
%% OUTPUT LEVEL DATA %% OUTPUT LEVEL DATA
...@@ -279,7 +286,7 @@ classdef LevelData < handle ...@@ -279,7 +286,7 @@ classdef LevelData < handle
% Creates formatting string for the header of the output to command line % Creates formatting string for the header of the output to command line
spec = cell(1, obj.nScalarVariable); spec = cell(1, obj.nScalarVariable);
for j = 1:obj.nScalarVariable for j = 1:obj.nScalarVariable
t = obj.type.(obj.scalarVariable{j}); t = obj.type(obj.scalarVariable{j});
spec{j} = assembleSpecifier(obj.getWidth(t), 's'); spec{j} = assembleSpecifier(obj.getWidth(t), 's');
end end
spec = strjoin(spec, separator) + "\n"; spec = strjoin(spec, separator) + "\n";
...@@ -289,7 +296,7 @@ classdef LevelData < handle ...@@ -289,7 +296,7 @@ classdef LevelData < handle
% Creates formatting string for printing to command line % Creates formatting string for printing to command line
spec = cell(1, obj.nScalarVariable); spec = cell(1, obj.nScalarVariable);
for j = 1:obj.nScalarVariable for j = 1:obj.nScalarVariable
t = obj.type.(obj.scalarVariable{j}); t = obj.type(obj.scalarVariable{j});
spec{j} = assembleSpecifier(obj.getWidth(t), t.formatSpec); spec{j} = assembleSpecifier(obj.getWidth(t), t.formatSpec);
end end
spec = strjoin(spec, separator) + "\n"; spec = strjoin(spec, separator) + "\n";
......
...@@ -71,7 +71,7 @@ function data = get(obj, jLevel, variableName) ...@@ -71,7 +71,7 @@ function data = get(obj, jLevel, variableName)
% Save extracted data to return variable % Save extracted data to return variable
data(:,jVariable) = value; data(:,jVariable) = value;
% Post-process character arrays % Post-process character arrays
if obj.type.(name).rawType == RawType.TEXT if obj.type(name).rawType == RawType.TEXT
data = mat2cell(char(data), ones(length(data), 1)); data = mat2cell(char(data), ones(length(data), 1));
end end
end end
......
...@@ -53,7 +53,7 @@ function set(obj, jLevel, variableName, value) ...@@ -53,7 +53,7 @@ function set(obj, jLevel, variableName, value)
end end
% Store type % Store type
if ~ismember(name, obj.label) if ~ismember(name, obj.label)
obj.type.(name) = currentType.adaptPrintWidthTo(name); obj.type(name) = currentType.adaptPrintWidthTo(name);
end end
% Store level-oriented data % Store level-oriented data
for k = 1:length(jLevel) for k = 1:length(jLevel)
......
...@@ -57,7 +57,7 @@ function setAbsolute(obj, jLevel, variableName, value) ...@@ -57,7 +57,7 @@ function setAbsolute(obj, jLevel, variableName, value)
if ~ismember(name, obj.absoluteVariable) if ~ismember(name, obj.absoluteVariable)
% Store type % Store type
obj.type.(name) = currentType.adaptPrintWidthTo(name); obj.type(name) = currentType.adaptPrintWidthTo(name);
% Store variable as absolute variable % Store variable as absolute variable
obj.absoluteVariable{end+1} = name; obj.absoluteVariable{end+1} = name;
end end
......
...@@ -56,7 +56,7 @@ function setTime(obj, jLevel, variableName, value) ...@@ -56,7 +56,7 @@ function setTime(obj, jLevel, variableName, value)
end end
% Store type % Store type
if ~ismember(name, obj.label) if ~ismember(name, obj.label)
obj.type.(name) = currentType.adaptPrintWidthTo(name); obj.type(name) = currentType.adaptPrintWidthTo(name);
end end
% Store variable as absolute variable % Store variable as absolute variable
if ~ismember(name, obj.timeVariable) if ~ismember(name, obj.timeVariable)
......
...@@ -126,7 +126,7 @@ classdef LevelDataCollection < handle ...@@ -126,7 +126,7 @@ classdef LevelDataCollection < handle
% to command line % to command line
spec = [' run', obj.separator]; spec = [' run', obj.separator];
for j = 1:obj.nTimeVariable for j = 1:obj.nTimeVariable
t = obj.item{1}.type.(obj.timeVariable{j}); t = obj.item{1}.type(obj.timeVariable{j});
if j < obj.nTimeVariable if j < obj.nTimeVariable
spec = [spec, '%', obj.getWidth(t), 's', obj.separator]; %#ok<*AGROW> spec = [spec, '%', obj.getWidth(t), 's', obj.separator]; %#ok<*AGROW>
else else
...@@ -142,7 +142,7 @@ classdef LevelDataCollection < handle ...@@ -142,7 +142,7 @@ classdef LevelDataCollection < handle
% Creates formatting string for printing to command line % Creates formatting string for printing to command line
spec = ['%4d', obj.separator]; spec = ['%4d', obj.separator];
for j = 1:obj.nTimeVariable for j = 1:obj.nTimeVariable
t = obj.item{1}.type.(obj.timeVariable{j}); t = obj.item{1}.type(obj.timeVariable{j});
if j < obj.nTimeVariable if j < obj.nTimeVariable
spec = [spec, '%', obj.getWidth(t), t.formatSpec, obj.separator]; spec = [spec, '%', obj.getWidth(t), t.formatSpec, obj.separator];
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment