In comp.soft-sys.ptolemy, [EMAIL PROTECTED] (Hendrik Schoeneich) writes:
--------

    Hi!
    
    I would like to extend the expression language of Ptolemy II to
    calculate integer values based on double values. I need this feature
    for a controller that I have created using a modal model.
    
    The documentation says:
    >The expression language includes an extensible set of functions, such
    as >sin(), cos(), etc. The functions that are built in include all
    static methods >of the java.lang.Math class and the
    ptolemy.data.expr.UtilityFunctions class. >This can easily be extended
    by registering another class that includes static >methods.
    
    I am thankful for any help on interpreting "easily registering".
    
    Thanks,
    
    Hendrik Schoeneich
--------

ptII/ptolemy/data/expr/UtilityFunctions.java contains static
methods that return tokens.

ptII/ptolemy/data/expr/ASTPtFunctionNode.java says:

  <p> A function node is created when a function call is parsed. This
  node will search for the function, using reflection, in the classes
  registered for this purpose with the parser. Thus to add to the list
  of functions available to the expression, it is only necessary to
  create a new class with the functions defined in it and register it
  with the parser. By default only java.lang.Math and
  ptolemy.data.expr.UtilityFunctions are searched for a given
  function.

and it continues on with the details, see
http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII2.0/ptII2.0.1/doc/codeDoc/ptolemy/data/expr/ASTPtFunctionNode.html

PtParser.jjt contains a line that registers the UtilityFunctions
class.
PtParser.jjt gets converted by JavaCC to PtParser.jj and then to
PtParser.java.   To add a class to to be registered, you might
be able to directly edit PtParser.java.  

Or, you could add your method directly to UtilityFunctions.java

For example, UtilityFunctions.java contains a method:

    /** Return the approximate number of bytes available for future
     *  object allocation.  Note that requesting a garbage collection
     *  may change this value.
     *  @return The approximate number of bytes available.
     *  @see #totalMemory
     */
    public static LongToken freeMemory() {
        return new LongToken(Runtime.getRuntime().freeMemory());
    }

That method can be used to get the amount of free memory.
$PTII/util/testsuite/memory.xml is a model that plots the free
and total memory.  The expression actor takes an input
from a ramp that is always 0L so that the expression gets
reevaluated each time the actor gets fired.

I believe that the expression language works best with doubles.
Offhand, I'm not sure of the details of the issues we ran into
with non-double functions, but keep an eye out.

-Christopher

Christopher Hylands    [EMAIL PROTECTED]  University of California
Programmer/Analyst Chess/Ptolemy/GSRC         US Mail: 558 Cory Hall #1770
ph: (510)643-9841 fax:(510)642-2739           Berkeley, CA 94720-1770
home: (510)526-4010, (707)665-0131            (office: 400A Cory)



----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to