% GETBUILTINMODELS returns a list of the built-in AO models found on the
% system.
% 
% CALL:   ca = ao.getBuiltInModels
% 
% OUTPUTS:
%          ca - a cell-array of models. The first column is the model name;
%               the second column is a description.
% 
% M Hewitson 23-11-08
% 
% $Id: getBuiltInModels.m,v 1.3 2011/04/06 14:06:10 mauro Exp $
% 
function txt = getBuiltInModels(objName)
  
  paths = utils.models.getBuiltinModelSearchPaths();
  
  for jj = 1:numel(paths)
    utils.helper.msg(utils.const.msg.PROC1, 'looking for models in %s', paths{jj});
  end
  
  % list files in here
  models = {};
  prefix = sprintf('%s_model_', objName);
  NN = 7+length(objName);
  for pp = 1:numel(paths)
    files = utils.prog.filescan(paths{pp}, '.m');
    for ff = 1:numel(files)
      parts = regexp(files{ff}, '(\.)*(\/)*', 'split');
      if strncmp(parts{end-1}, prefix, NN)
        models = [models parts(end-1)];
      end
    end
  end
  
  % Give a list and an error if bsys is empty
  txt = {};
  for k = 1:numel(models)
    if strcmp(objName, 'ssm')
      txt = [txt; models{k}(8+length(objName):end)];
    else
      try
        txt = [txt; {models{k}(8+length(objName):end), feval(models{k}, 'describe')}];
      catch
        warning('LTPDA:MODEL:DESCRIPTION', '!!! The model "%s" fails for the description.', models{k});
      end
    end
  end
end
