ptolemy.data.expr
Class MatlabUtilities

java.lang.Object
  extended by ptolemy.data.expr.MatlabUtilities

public class MatlabUtilities
extends java.lang.Object

This class provides access to the Ptolemy Matlab interface in ptolemy.matlab by using reflection.

Since:
Ptolemy II 2.1
Version:
$Id: MatlabUtilities.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Christopher Hylands, Steve Neuendorffer, Zoltan Kemenczy, Research in Motion Ltd.
See Also:
ParseTreeEvaluator
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (neuendor)

Field Summary
private static long[] _engine
           
private static java.lang.Class _engineClass
           
private static java.lang.reflect.Method _engineClose
           
private static java.lang.reflect.Method _engineEvalString
           
private static java.lang.reflect.Method _engineGet
           
private static java.lang.reflect.Method _engineOpen
           
private static java.lang.reflect.Method _enginePut
           
 
Constructor Summary
MatlabUtilities()
           
 
Method Summary
private static void _initialize()
           
static Token evaluate(java.lang.String expression, java.util.Set variableNames, ParserScope scope)
          Evaluate a Matlab expression within a scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_engine

private static long[] _engine

_engineClass

private static java.lang.Class _engineClass

_engineClose

private static java.lang.reflect.Method _engineClose

_engineEvalString

private static java.lang.reflect.Method _engineEvalString

_engineGet

private static java.lang.reflect.Method _engineGet

_engineOpen

private static java.lang.reflect.Method _engineOpen

_enginePut

private static java.lang.reflect.Method _enginePut
Constructor Detail

MatlabUtilities

public MatlabUtilities()
Method Detail

evaluate

public static Token evaluate(java.lang.String expression,
                             java.util.Set variableNames,
                             ParserScope scope)
                      throws IllegalActionException
Evaluate a Matlab expression within a scope. The expression argument is of the form matlab("expression", arg1, arg2, ...), where arg1, arg2, ... is a list of Variables appearing in "expression". Note that this form of invoking matlab is limited to returning only the first return value of a matlab function. If you need multiple return values, use the matlab actor.

Note that having an instance of Expression in the model will keep the matlab engine open from model preinitialize() to wrapup() and hence opening/closing of additional Engine instances done by this matlab expression evaluator becomes fast. Most users should prefer to use Expression and resort to this mechanism of invoking matlab only where necessary, e.g. in FSM transition action expressions (which was the reason for introducing this form of matlab engine access).

If a "packageDirectories" Parameter is in the scope of this expression, its value is added to the matlab path while the expression is being executed (like Expression).

Parameters:
expression - The Matlab expression to be evaluated
variableNames - The Matlab variables required for evaluating the expression. Each elemement of the Set names a Token that is found in the scope.
scope - The scope to evaluate the expression within.
Returns:
The results of the evaluation
Throws:
IllegalActionException - If there is a problem initializing the Matlab interface, invoking the Matlab engine or accessing a a Token.

_initialize

private static void _initialize()
                         throws IllegalActionException
Throws:
IllegalActionException