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