view m-toolbox/classes/@LTPDAworkbench/executeConstants.m @ 38:3aef676a1b20 database-connection-manager

Keep backtrace on error
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line source

function executeConstants(varargin)
  
  wb = varargin{1};
  
  if isa(wb, 'LTPDAworkbench')
    consts = awtinvoke(wb.mp, 'getAllConstants');
  elseif isa(wb, 'mpipeline.canvas.MCanvas')
    consts = wb.getAllConstants;
  else
    error('Unknown input object');
  end
  
  % Then execute all constants
  for kk=1:consts.size()
    
    c       = consts.get(kk-1);
    if ~c.isCommentedOut
      varname = char(c.getName());
      expr    = char(c.getExpression());
      
      if  exist(varname) > 1 || ~isvarname(varname)
        error('The constant block named "%s" is not a valid variable name. \nPlease rename it.', varname);
      end
      
      % can the expression be evaluated, or is it a string?
      try
        eval([expr ';']);
        cmd = [varname ' = ' expr ';'];
      catch
        cmd = [varname ' = ''' expr ''';'];
      end
      
      % evaluate
      disp(sprintf('++ preparing variable: %s', cmd));
      evalin('base', cmd);
    else
      varname = char(c.getName());
      cmd = ['clear ', varname];
      evalin('base', cmd);
    end
  end
  
end