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