Top Up Prev Next Bottom Contents Index Search

2.2 Adding stars dynamically to Ptolemy

To get a quick sense of what it means to create a new star, you can use one of the existing stars as a template. Create a new directory in which you have write permission. Copy the source code for an existing Ptolemy star. For example,

cd my_directory
cp $PTOLEMY/src/domains/sdf/stars/SDFSin.pl SDFMyStar.pl
chmod +w SDFMyStar.pl
The " .pl" extensions on the file names stand for "Ptolemy language" or "preprocessor language." The file name must be of the form DomainStarname.pl for dynamic linking and the look-inside command to work. The last command just ensures that you can modify the file. Edit the file to change the name of the star from Sin to MyStar. This is necessary so that the name does not conflict with the existing Sin star in the SDF domain.

You can now dynamically link your new star. Start pigi, the graphical editor. If you start pigi in your new directory, you will get a blank init.pal facet. Place your mouse cursor in this facet, and issue the " make-star" command (the shortcut is "*"). A dialog box like the following will appear:

Enter the name of the star, MyStar, its domain, SDF, the location of the directory that defines it, such as ~user_name/my_directory, and the name of palette in which you would like its icon to appear, user.pal. The star will be compiled and dynamically linked with the Ptolemy executable. An icon for it will appear in the facet user.pal. Try using this in a simple system.

Three details about dynamic linking may prove useful:

go {
output%0 << sin (double(input%0));
}
The one line of code is ordinary C++ code, although the "<<" and "%" operators have been overloaded. This line means that the current value (%0) of the output named "output" should be assigned the value returned by the sin function applied to the current value of the input named "input". The cast to double indicates that we are not really interested in the Particle object supplied by the input, but rather its value, interpreted as a double-precision floating point number. Try changing this code to

go {
output%0 << sin (double(input%0)) + 1.0;
}
To recompile and reload the star, place your mouse cursor on any instance of the icon for the star, and type "L" (or invoke the "Extend: load-star" command through the menus).

Sometimes, you will wish to dynamically link stars that are derived from other stars that you have dynamically linked. To do this, the base class stars must be permanently linked. This can be done with the "Extend:load-star-perm" command ("K"). To do this, place the mouse over an icon representing the parent star, and type "K". Once the parent star is permanently linked, it cannot be replaced or redefined: you must restart pigi.

The go and all other entries in the .pl file defining the star are explained in the following sections.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.