-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from tsipkens/developer
This merges numerous updates to the README, adjustments removing some less-often used code, support for YML configuration files, and refactoring (e.g., updating function headers to be closer to the standard Matlab format).
- Loading branch information
Showing
32 changed files
with
1,079 additions
and
1,328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
% LOAD_CONFIG Loads settings from configuration file (YML). | ||
% Files are loaded in order supplied, overwriting properties where | ||
% relevant. | ||
% | ||
% AUTHOR: Timothy Sipkens, 2021-03-25 | ||
|
||
function config = load_config(fnames) | ||
|
||
if ~iscell(fnames); fnames = {fnames}; end | ||
|
||
config = struct(); | ||
for ii=1:length(fnames) | ||
|
||
config0 = io.read_yml(fnames{ii}); % read new settings | ||
|
||
% Copy (or overwrite) existing settings. | ||
f = fieldnames(config0); | ||
for jj = 1:length(f) | ||
config.(f{jj}) = config0.(f{jj}); | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
% READ_YML Simple little function to read simple little YAML format parameter files. | ||
% | ||
% AUTHOR: Lloyd Russell, 2017 | ||
% REPO: https://github.com/llerussell/ReadYAML | ||
|
||
function results = read_yml(filePath) | ||
|
||
% read file line by line | ||
fid = fopen(filePath, 'r'); | ||
data = textscan(fid, '%s', 'delimiter', '\n', 'whitespace', ''); | ||
fclose(fid); | ||
|
||
% remove empty lines | ||
data = deblank(data{1}); | ||
data(cellfun('isempty', data)) = []; | ||
|
||
% prepare final results structure | ||
results = []; | ||
|
||
% parse the contents (line by line) | ||
for i = 1:numel(data) | ||
|
||
% extract this line | ||
thisLine = data{i}; | ||
|
||
% ignore if this line is a comment | ||
if strcmpi(thisLine(1), '#') | ||
continue | ||
end | ||
|
||
% find the seperator between key and value | ||
sepIndex = find(thisLine==':', 1, 'first'); | ||
|
||
% get the key name (remove whitespace) | ||
key = strtrim(thisLine(1:sepIndex-1)); | ||
|
||
% get the value, ignoring any comments (remove whitespace) | ||
value = strsplit(thisLine(sepIndex+1:end), '#'); | ||
value = strtrim(value{1}); | ||
|
||
% attempt to convert value to numeric type | ||
[convertedValue, success] = str2num(value); | ||
if success | ||
value = convertedValue; | ||
end | ||
|
||
% store the key and value in the results | ||
results.(key) = value; | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.