Package ptolemy.moml

Class MoMLCommandLineApplication

  • All Implemented Interfaces:
    ExecutionListener, ChangeListener

    public class MoMLCommandLineApplication
    extends MoMLSimpleApplication
    A application that reads command line arguments that set parameters and a .xml file naming a model, sets the parameters and runs the model.

    MoMLApplication sets the look and feel, which starts up Swing, so we can't use MoMLApplication for non-graphical simulations.

    The parent class, @{link ptolemy.moml.MoMLSimpleApplication} does not handle command line parameters that set parameters For example to use this class, try:

     java -classpath $PTII ptolemy.moml.MoMLCommandLineApplication -myParameter '"Hello, World."' test/MoMLCommandLineApplicationTest.xml
     
    or
     $PTII/bin/ptinvoke ptolemy.moml.MoMLCommandLineApplication -myParameter '""Hellow, World.""' test/MoMLCommandLineApplicationTest.xml
     

    If a Ptolemy model is instantiated on the command line, either by giving a MoML file or a -class argument, then parameters of that model can be set on the command line. The syntax is:

     $PTII/bin/ptinvoke ptolemy.moml.MoMLCommandLineApplication -parameterName value modelFile.xml
     
    where parameterName is the name of a parameter relative to the top level of a model or the director of a model. For instance, if foo.xml defines a toplevel entity named x and x contains an entity named y and a parameter named a, and y contains a parameter named b, then:
     $PTII/bin/ptinvoke ptolemy.moml.MoMLCommandLineApplication  -a 5 -y.b 10 foo.xml
     
    would set the values of the two parameters.

    Note that strings need to be carefully backslashed, so to set a parameter named c to the string "bar" it might be necessary to do something like:

     $PTII/bin/ptinvoke ptolemy.moml.MoMLCommandLineApplication -a 5 -y.b 10 -c '""bar"" foo.xml
     
    The reason the single quotes and double quotes are necessary is because ptinvoke is a shell script which tends to strip off the double quotes.
    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Christopher Brooks
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Red (cxh)
    • Constructor Detail

      • MoMLCommandLineApplication

        public MoMLCommandLineApplication​(java.lang.String[] args)
                                   throws java.lang.Throwable
        Parse a MoML file that contains a model, update the parameters and run the model.
        Parameters:
        args - An array of strings, where the last element names a MoML file that contains a Ptolemy II model. The string should be a relative pathname. Other elements may name model parameters and values for the parameters. Parameter names should begin with a "-" and be followed by the value for the parameter.
        Throws:
        java.lang.Throwable - If there was a problem parsing or running the model.
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        Create an instance of a single model and run it.
        Parameters:
        args - The command-line arguments naming the .xml file to run