
clc;

matfiles = utils.prog.filescan('.', '.mat');
xmlfiles = utils.prog.filescan('.', '.xml');

currentVer = '';
currentCl  = '';

for j=1:numel(matfiles)
  fn = matfiles{j};
  [path, name, ext, ver] = fileparts(fn);
  [cl, rest] = strtok(name, '_');
  [v, rest] = strtok(rest, '_');
  if ~strcmp(v, currentVer) || ~strcmp(cl, currentCl)
    currentCl  = cl;
    currentVer = v;
    fprintf('%%%% Loading MAT files of class: %s and version: %s\n', cl, currentVer);
  end
  try
    warning('off', 'MATLAB:unknownElementsNowStruc');
    obj = feval(cl, fn);
    warning('on', 'MATLAB:unknownElementsNowStruc');
  catch err
    fprintf(2, '----- Loading %s failed. ', fn);
    fprintf(2, '%s\n', err.message);
  end
end

currentVer = '';
currentCl  = '';

for j=1:numel(xmlfiles)
  fn = xmlfiles{j};
  [path, name, ext, ver] = fileparts(fn);
  [cl, rest] = strtok(name, '_');
  [v, rest] = strtok(rest, '_');
  if ~strcmp(v, currentVer) || ~strcmp(cl, currentCl)
    currentCl  = cl;
    currentVer = v;
    fprintf('%%%% Loading XML files of class: %s and version: %s\n', cl, currentVer);
  end
  try
    obj = feval(cl, fn);
  catch err
    fprintf(2, '----- Loading %s failed. ', fn);
    fprintf(2, '%s\n', err.message)
  end
end

disp('%%%% Done.');


