-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_params.m
45 lines (42 loc) · 1.3 KB
/
load_params.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function params = load_params(filename)
% LOAD_PARAMS read data from configuration file
%
% params = LOAD_PARAMS(filename) reads the data from a filename and
% returns the data in a struct. The params file contains information
% in the following format:
%
% % comments like this are ignored
% name1 = value1;
% name2 = value2;
%
% Input: filename * path to configuration file
% Output: params * struct containing parameter information.
% using the above example, the data is
% stored as:
%
% params.name1 = value
% params.name2 = value
%
% Written by Marshall Crumiller
% email: [email protected]
%--------------------------------------------------------------------------
if(~exist('filename','var')), filename='params.txt'; end
fid = fopen(filename);
params = [];
while(true)
C = textscan(fid, '%s = %s\n');
if(isempty(C{1}))
break;
elseif(isempty(C{2}))
continue;
else
key=C{1}{1}; val=C{2}{1};
if(isnan(str2double(val)))
if(val(end)==';'),val=val(1:end-1); end
eval(sprintf('params.%s = ''%s'';',key,val));
else
eval(sprintf('params.%s = %g;',key,val));
end
end
end
fclose(fid);