0001 function bo = find(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 VERSION = '$Id: find.m,v 1.7 2007/10/24 17:35:28 ingo Exp $';
0027
0028
0029 if nargin == 2
0030 if isa(varargin{1}, 'ao') && ischar(varargin{2})
0031 in = char(varargin{2});
0032 if strcmp(in, 'Params')
0033 bo = getDefaultPL();
0034 return
0035 elseif strcmp(in, 'Version')
0036 bo = VERSION;
0037 return
0038 end
0039 end
0040 end
0041
0042
0043 invars = {};
0044 for j=1:nargin
0045 if isa(varargin{j}, 'ao')
0046 invars = [invars cellstr(inputname(j))];
0047 end
0048 end
0049
0050 ALGONAME = mfilename;
0051 VERSION = '$Id: find.m,v 1.7 2007/10/24 17:35:28 ingo Exp $';
0052
0053
0054 as = [];
0055 ps = [];
0056 queries = [];
0057 for j=1:nargin
0058 if isa(varargin{j}, 'ao')
0059 as = [as varargin{j}];
0060 end
0061 if isa(varargin{j}, 'plist')
0062 ps = [ps varargin{j}];
0063 end
0064 if ischar(varargin{j})
0065 queries = [queries ' & ' varargin{j}];
0066 end
0067 end
0068
0069 Na = length(as);
0070 if isempty(as)
0071 error('### Please input at least one AO.');
0072 end
0073 if isempty(ps) && isempty(queries)
0074 error('### Please specify queries to select directly or as a plist.');
0075 end
0076
0077
0078 if ~isempty(ps)
0079 pl = combine(ps);
0080 else
0081 pl = plist();
0082 end
0083
0084
0085 queries = [queries ' & ' find(pl, 'queries')];
0086
0087
0088 queries = strtrim(queries);
0089 if queries(1) == '&'
0090 queries = queries(2:end);
0091 end
0092 if queries(end) == '&'
0093 queries = queries(1:end-1);
0094 end
0095
0096
0097 disp(sprintf('*** processing %s', queries));
0098
0099
0100 bo = [];
0101 for j=1:numel(as)
0102
0103 a = as(j);
0104 d = a.data;
0105
0106 [x,y] = get_xy_values(d);
0107
0108
0109
0110 vals = y;
0111
0112 cmd = sprintf('idx = find(%s);', queries);
0113 try
0114 eval(cmd);
0115 catch
0116 l_error = lasterror;
0117 error('%s\n\n### please use x or y for the queries.',l_error.message);
0118 end
0119
0120 if isa(d, 'cdata')
0121
0122 if length(x) == length(y)
0123 d = set_xy_axis(d, x(idx), y(idx));
0124 else
0125 d = set_xy_axis(d, x, y(idx));
0126 end
0127 else
0128 d = set_xy_axis(d, x(idx), y(idx));
0129 end
0130
0131
0132
0133
0134 h = history(ALGONAME, VERSION, plist(param('queries', queries)), a.hist);
0135 h = set(h, 'invars', invars);
0136
0137
0138 b = ao(d, h);
0139
0140
0141
0142 if j > length(invars)
0143 n1 = a.name;
0144 else
0145 n1 = invars{j};
0146 end
0147 b = set(b, 'name', sprintf('select(%s)', n1));
0148
0149
0150 bo = [bo b];
0151
0152 end
0153
0154
0155 bo = reshape(bo, size(as));
0156
0157
0158
0159 function pl_default = getDefaultPL()
0160
0161 pl_default = plist(param('query', ''));
0162
0163
0164
0165