Top Up Prev Next Bottom Contents Index Search

2.5 Particle types

The packets of data that pass from one star to another in Ptolemy are called particles. So far, all particles have simply been floating-point numbers representing samples of signals. However, several other data types are supported. Each star icon has a stem for each porthole. In pigi, if you are using a color monitor, the color of the stem indicates the type of data that the porthole consumes or produces, as summarized in table 2-5
. A blue stem on an input or output of a star icon indicates type "float", a purple stem indicates type "fix" for fix-point particles, a white stem indicates type "complex", an orange stem indicates type "int" for integer particles, a green stem indicates "message", a black stem indicated type "string", a yellow stem indicates type "file", and a red stem indicates "anytype". The "message" type is a user-defined data type (see the programmer's manual). A star that operates on "anytype" particles is said to be polymorphic. It processes all input data types exactly the same way. In addition, stars which input or output Matrix type particles have stems which are extra thick with colors corresponding to the four main types, float, int, complex, and fix.

Ptolemy usually makes conversions between these types automatically. The float to complex conversion does the obvious thing, putting the float value into the real part of the complex number and setting the imaginary part to zero. The complex to float conversion computes the magnitude of the complex number.

The Xscope star, and some other stars that generate output, accept "anytype" of input. If the input is complex, the magnitude will be plotted, because it will be cast to a float internally. If you want to plot both the real and imaginary parts you should use the ComplexReal conversion star first.

For technical reasons too involved to explain here, automatic type conversions cannot always be made. In particular, Ptolemy can only do one type conversion for any given output of a star. So if a single output is connected to multiple inputs of different types, Ptolemy may complain. For example, suppose you connect a "float" output to both a "complex" input and a "float" input. Ptolemy will complain. A simple solution is to insert an explicit type conversion. The type conversion stars can be found in the "conversion" palette of the appropriate domain. It will be explained below how to find this. Note that the matrix particle types do not support automatic type conversion at all. Conversion stars need to be explicitly inserted between two stars that work on different Matrix types.

Ptolemy's automatic type conversions have one potentially serious pitfall. Suppose you connect a "float" output to a "complex" and "anytype" input, as shown in figure 2-6

. This is legal because Ptolemy can satisfy the constraints with just one type conversion, float to complex. Suppose, however, that the "anytype" input belongs to an Xscope star. As explained above, the Xscope star plots the magnitude of a complex number unless you have an explicit ComplexReal conversion star. Hence, instead of plotting the "float" output, Xscope will plot the magnitude, converting all negative numbers to positive. A way to correct the problem is to explicitly convert the float to complex in the upper path only, as shown in figure 2-7.



Top Up Prev Next Bottom Contents Index Search

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