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
0027
0028
0029
0030
0031
0032
0033
0034 VERSION = '$Id: find.m,v 1.13 2008/02/19 18:01:59 ingo Exp $';
0035 ALGONAME = mfilename;
0036 CATEGORY = 'Helper';
0037 queries = [];
0038
0039
0040 if nargin == 2
0041 if isa(varargin{1}, 'ao') && ischar(varargin{2})
0042 in = char(varargin{2});
0043 if strcmp(in, 'Params')
0044 bo = getDefaultPL();
0045 return
0046 elseif strcmp(in, 'Version')
0047 bo = VERSION;
0048 return
0049 elseif strcmp(in, 'Category')
0050 bo = CATEGORY;
0051 return
0052 end
0053 end
0054 end
0055
0056
0057 in_names = {};
0058 for ii = 1:nargin
0059 in_names{end+1} = inputname(ii);
0060
0061 if ischar(varargin{ii})
0062 queries = [queries ' & ' varargin{ii}];
0063 end
0064 end
0065
0066 [as, ps, invars] = collect_inputs(varargin, in_names);
0067
0068
0069 if isempty(as)
0070 error('### Please input at least one AO.');
0071 end
0072 if isempty(ps) && isempty(queries)
0073 error('### Please specify queries to select directly or as a plist.');
0074 end
0075
0076 pl = combine(ps);
0077
0078
0079 queries = [queries ' & ' find(pl, 'query')];
0080
0081
0082 queries = strtrim(queries);
0083 if queries(1) == '&'
0084 queries = queries(2:end);
0085 end
0086 if queries(end) == '&'
0087 queries = queries(1:end-1);
0088 end
0089
0090
0091
0092
0093
0094 bo = [];
0095 for j=1:numel(as)
0096
0097 a = as(j);
0098 d = a.data;
0099
0100 [x,y] = get_xy_values(d);
0101
0102
0103
0104 vals = y;
0105
0106 cmd = sprintf('idx = find(%s);', queries);
0107 try
0108 eval(cmd);
0109 catch
0110 l_error = lasterror;
0111 error('%s\n\n### please use x or y for the queries.',l_error.message);
0112 end
0113
0114 if isa(d, 'cdata')
0115
0116 if length(x) == length(y)
0117 d = set_xy_axis(d, x(idx), y(idx));
0118 else
0119 d = set_xy_axis(d, x, y(idx));
0120 end
0121 else
0122 d = set_xy_axis(d, x(idx), y(idx));
0123 end
0124
0125
0126
0127
0128 queries = strtrim(queries);
0129 h = history(ALGONAME, VERSION, plist(param('query', queries)), a.hist);
0130 h = set(h, 'invars', invars(j));
0131
0132
0133 b = ao(d, h);
0134
0135
0136 b = setnh(b, 'name', sprintf('select(%s)', invars{j}));
0137
0138
0139 bo = [bo b];
0140
0141 end
0142
0143
0144 bo = reshape(bo, size(as));
0145
0146
0147
0148 function pl_default = getDefaultPL()
0149
0150 pl_default = plist(param('query', ''));
0151
0152
0153
0154