function handles = gltpda_aoImport(handles)

% GLTPDA_AOIMPORT import an analysis object from file
% 
% M Hewitson 15-02-07
% 
% $Id: gltpda_aoImport.m,v 1.2 2007/03/23 06:47:24 hewitson Exp $
% 

% init output
newaos = [];

% Load object(s)
% get filename 
[filename, pathname] = uigetfile({...
                         '*.txt', '2-column ascii';...
                         '*.mat', 'MAT-files';... 
                         '*.xml', 'LTPDA XML file'},...
                        'MAT-file input',...
                        'MultiSelect', 'on')
                      
% Loop over selected files
if iscellstr(filename)
  nfiles = length(filename);
  for f=1:nfiles
    infile = fullfile(pathname, char(filename(f)));
    a = readFromFile(infile);
    newaos  = [newaos a];
  end
else
  nfiles = 1;
  infile = fullfile(pathname, filename);
  a = readFromFile(infile);
  newaos  = [newaos a];
end


% Get current array of AOs
aos = getappdata(handles.main, 'aos');

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

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

% Update object list
gltpda_setAOlist(handles);

% Set focus to new object

%--------------------------------------------------------------------------
%
function a = readFromFile(infilename)

disp(['* reading ' infilename]);

  % Switch over different file types
  [path,name,ext,vers] = fileparts(infilename);

  switch ext
    case '.mat'

      in = load(infilename)

    case '.txt'

      a = ao(infilename);

    case '.xml'

      a = ao(infilename);

    otherwise
      error('### unknown file format.');
  end



% END