function gltpda_analyse(handles)

% GLTPDA_ANALYSE perform the selected analysis on the selected analysis
% objects.
% 
% M Hewitson 15-02-07
% 
% $Id: gltpda_analyse.m,v 1.2 2007/03/23 06:47:24 hewitson Exp $
% 

%% Get selected AOs
% get AO array
aos = getappdata(handles.main, 'aos');

% Get selected objects
selected = get(handles.aoList, 'Value');
a = aos.objs(selected);

%% Analyse these

% get selected analysis name
aname = get(handles.analysisList, 'String');
aidx  = get(handles.analysisList, 'Value');
analysis = aname(aidx);

% get the function structure for this
settings = getappdata(handles.main, 'settings');
fcn = [];
for j=1:length(settings.functions)
  if strcmp(settings.functions(j).call, analysis)
    fcn = settings.functions(j);
  end
end
if isempty(fcn)
  error('### function not found in function list.');
end

% form parameter string
pl = plist();
% append non-default parameters
for j=1:length(fcn.params)
  p = fcn.params(j);
  if ~isempty(p.val)
    pstr = ['pl = append(pl, param(' char(p.name) ','];
    if isnumeric(p.val)
      pstr = [pstr num2str(p.val) ')'];
    elseif ischar(p.val)
      pstr = [pstr p.val ')'];
    elseif isa(p.val, 'specwin')
      pstr = [pstr 'p.val' ')'];      
    else
    end
    pstr = [pstr ');'];
  end
end

% Form an evaluation string
estr = ['b = ' fcn.call fcn.inputs ';']
eval(estr);

%% Add new ao to list 

% Add to object array
aos.objs  = [aos.objs b];
aos.nobjs = aos.nobjs + length(b);

% Set array
setappdata(handles.main, 'aos', aos);

% Update object list
gltpda_setAOlist(handles);




% END