Skip to content
Snippets Groups Projects
Commit b8f222d3 authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Cleaned and optimized gtHSTParamReader

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@951 4c865b51-4357-4376-afb4-474e03ccb993
parent bca7ef51
No related branches found
No related tags found
No related merge requests found
......@@ -21,16 +21,16 @@ function par = gtHSTParamReader(filename)
par = [];
pattern = '(?<parameter>.*)=(?<value>.*)';
if ~exist(filename,'file')
error(['Could not find ' filename]);
gtError('gtHSTParamReader', ['Could not find ' filename]);
end
fid = fopen(filename,'rt');
if fid==-1
error(['Could not open ' filename]);
gtError('gtHSTParamReader', ['Could not open ' filename]);
end
% Initialize correct_rings_nb
par = setfield(par, 'correct_rings_nb', -1);
par.correct_rings_nb = -1;
while ~feof(fid)
txt = fgetl(fid);
......@@ -50,24 +50,15 @@ while ~feof(fid)
if regexp(field,'^ar2(\d+)')
value = regexprep(field,'ar2(\d+)','$1');
nb = str2num(value)/2 -1;
par = setfield(par, 'correct_rings_nb', nb);
par.correct_rings_nb = str2double(value)/2 -1;
continue;
end
test = [];
if ~isempty(regexp(tmp.value,'[0-9]'))
test = str2num(tmp.value);
end
try
if isempty(test)
par = setfield(par, field, tmp.value);
else
par = setfield(par, field, test);
end
catch
warning('Didn''t understand this header');
disp(field);
nb = str2num(tmp.value);
if ~isempty(regexp(tmp.value, '[0-9]', 'once')) && ~isempty(nb)
par.(field) = nb;
else
par.(field) = tmp.value;
end
else
disp(txt);
......@@ -78,11 +69,11 @@ end
ndx = find(par.options==':') + 2;
tmp.padding = par.options(ndx(1));
tmp.axis = par.options(ndx(2));
par = setfield(par, 'options_padding', tmp.padding);
par = setfield(par, 'options_axis', tmp.axis);
par.options_padding = tmp.padding;
par.options_axis = tmp.axis;
if length(ndx) > 2
tmp.avoid = par.options(ndx(3));
par = setfield(par, 'options_avoidhalftomo', tmp.avoid);
par.options_avoidhalftomo = tmp.avoid;
end
par.ccd_filter_para = sscanf(par.ccd_filter_para, '{"threshold":%f}');
......@@ -95,17 +86,15 @@ end % end of function
% SUB-FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function field=sfCleanField(str)
function field = sfCleanField(str)
% SFCLEANFIELD Removes weird characters (spaces, parentheses) from field.
str = lower(strtrim(str));
str(find(str==' ')) = '_';
str(find(str=='(')) = [];
str(find(str==')')) = [];
str(find(str=='-')) = '_';
str(find(str=='[')) = [];
str(find(str==']')) = [];
str(find(str==':')) = [];
str(str==' ') = '_';
str(str=='(') = [];
str(str==')') = [];
str(str=='-') = '_';
str(str=='[') = [];
str(str==']') = [];
str(str==':') = [];
field = str;
end % end of sfCleanField
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