-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdescribeMethod.m
More file actions
174 lines (155 loc) · 5.79 KB
/
Copy pathdescribeMethod.m
File metadata and controls
174 lines (155 loc) · 5.79 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
function [descrip,functions]=describeMethod(rawMethod, ctx)
% DESCRIBEMETHOD Display detailed information about a raw processing method
%
% Shows the complete configuration of a raw processing method, including
% all processing functions in the pipeline, their arguments, and output
% assignments. Useful for understanding what a method does before applying
% it to data, or for debugging processing issues.
%
% Syntax:
% pf2.methods.raw.describeMethod()
% pf2.methods.raw.describeMethod(rawMethod)
% pf2.methods.raw.describeMethod(methodIndex)
% [descrip, functions] = pf2.methods.raw.describeMethod(...)
%
% Inputs:
% rawMethod - Method identifier (optional), one of:
% - String/char: Method name (e.g., 'x2_lpf_smar')
% - Numeric: Method index from the available methods list
% If omitted, prompts for interactive selection.
%
% Outputs:
% descrip - String containing the formatted method description
% If not requested, description prints to console.
% functions - Cell array of function configuration structs containing:
% .f - Function name
% .args - Argument names
% .argvals - Argument values
% .output - Output variable assignment
%
% Example:
% % Display current method details to console
% pf2.methods.raw.describeMethod();
%
% % Describe a specific method by name
% pf2.methods.raw.describeMethod('x2_lpf_smar');
%
% % Get method details as variables for programmatic use
% [desc, funcs] = pf2.methods.raw.describeMethod('OD_TDDR');
% fprintf('Method has %d processing functions\n', length(funcs));
%
% % Describe method by index
% pf2.methods.raw.describeMethod(3);
%
% See also: pf2.methods.raw.list, pf2.methods.raw.setMethod,
% pf2.methods.oxy.describeMethod, pf2.methods.describeCurrentMethods
if nargin < 2, ctx = []; end
methodsLib = pf2_base.resolveMethodsLib('raw', ctx);
if(nargin<1)
rawMethod=pf2.methods.raw(true);
getByIndex=false;
elseif(isnumeric(rawMethod))
getByIndex=true;
else
getByIndex=false;
end
% No current method selected (e.g. fresh install): report gracefully
% rather than failing the cfg lookup below.
if(~getByIndex && (isempty(rawMethod) || (ischar(rawMethod) && isempty(strtrim(rawMethod)))))
msg=sprintf(['No current Raw Method selected.\n' ...
'Use pf2.methods.raw.setMethod(...) to select one, ' ...
'or pf2.methods.raw.list() to see available methods.\n']);
if(nargout>0)
descrip=msg;
functions={};
else
fprintf(2,'%s',msg);
end
return;
end
% methodsLib.cfg may be a struct or a pf2_base.external.INI object; the
% latter exposes Sections as a property (isfield is false for objects), so
% probe with a struct-or-object safe check before reading it.
cfgHasSections = isfield(methodsLib,'cfg') && ...
((isstruct(methodsLib.cfg) && isfield(methodsLib.cfg,'Sections')) || ...
(isobject(methodsLib.cfg) && isprop(methodsLib.cfg,'Sections')));
if(cfgHasSections&&~isempty(methodsLib.cfg.Sections))
rawMethods=methodsLib.cfg.Sections;
if(getByIndex)
if(rawMethod>0&&rawMethod<=length(rawMethods))
rawMethod=rawMethods{rawMethod};
else
error('pf2:methods:raw:describeMethod:badIndex', 'Unable to find Raw Method at Index %i',rawMethod);
end
end
if(ismember(rawMethod,rawMethods)&&~isempty(methodsLib.cfg.(rawMethod)))
rawMethodCfg=methodsLib.cfg.(rawMethod);
else
error('pf2:methods:raw:describeMethod:methodNotFound', 'Unable to find current Raw Method name %s',rawMethod);
end
funcs=rawMethodCfg.F;
descripStr=sprintf('Raw Method: %s\n',rawMethod);
for f=1:length(funcs)
curFunc=funcs{f};
% Function entries may be plain structs or PipelineFunction objects;
% normalize to the struct shape (.f/.args/.argvals/.output) below.
if(isa(curFunc,'pf2_base.PipelineFunction'))
curFunc=curFunc.toStruct();
end
funcDescripStr=sprintf('%i. Function: %s\n',f,curFunc.f);
for a=1:length(curFunc.args)
if(iscell(curFunc.args))
arg=curFunc.args{a};
argVal=curFunc.argvals{a};
else
arg=curFunc.args;
argVal=curFunc.argvals;
end
funcDescripStr=sprintf('%s\targ%i: \t%s\t%s\n',funcDescripStr,a,arg,num2strOrNot(argVal));
end
if(isfield(curFunc,'output'))
if(iscell(curFunc.output(1)))
curFunc.output=curFunc.output{1};
end
funcDescripStr=sprintf('%s\toutput:\t%s\n',funcDescripStr,curFunc.output(1));
end
descripStr=sprintf('%s%s',descripStr,funcDescripStr);
end
if(nargout>0)
descrip=descripStr;
functions=funcs;
else
fprintf(descripStr);
end
else
% No methods library / Sections available: report gracefully rather than
% returning with unassigned outputs.
msg=sprintf('No Raw Methods available to describe.\n');
if(nargout>0)
descrip=msg;
functions={};
else
fprintf(2,'%s',msg);
end
end
end
function possibleStr=num2strOrNot(possibleStr)
if(iscell(possibleStr))
for i=1:length(possibleStr)
if(~ischar(possibleStr{i})&&isnumeric(possibleStr{i}))
possibleStr{i}=num2str(possibleStr{i});
end
end
elseif(~ischar(possibleStr)&&islogical(possibleStr))
if(possibleStr)
possibleStr='true';
else
possibleStr='false';
end
elseif(~ischar(possibleStr)&&isnumeric(possibleStr))
possibleStr=num2str(possibleStr);
end
if(iscell(possibleStr)&&length(possibleStr)==1)
possibleStr=possibleStr{1};
end
end