[kepler-dev] How do I create nested loops in Kepler

Christopher Brooks cxh at eecs.berkeley.edu
Tue Jul 5 18:41:00 PDT 2005

Hi Dan,
I don't think that Ramp will reset to 0 during a run for you.
Try using Pulse instead.

I hacked up http://ptolemy.eecs.berkeley.edu/~cxh/models/parameterizedLoops.xml
which uses the Pulse actor.  One tricky part is that 
Pulse uses two arrays to determine what values are produced.

The Pulse docs say:

   The <i>values</i> parameter contains an ArrayToken, which specifies
   the sequence of values to produce at the output.  The <i>indexes</i>
   parameter contains an array of integers, which specifies when those values
   should be produced.  The array in the <i>indexes</i> parameter
   must have the same length as that in the
   <i>values</i> parameter or an exception will be thrown by the fire() method.
   Also, the <i>indexes</i> array must be increasing and non-negative,
   or an exception will be thrown when it is set.

The tricky part is to use an expression to create the array from 
0 to maximum-1
That expression is:
This similar to the Matlab syntax for creating an array.

Of course, if you know beforehand how far you want to count, then you can
hardwire it in; for example, use: {0,1,2}

The other trick is that I set the vectorizationFactor parameter of
the inner SDF Scheduler to fire the inner pulse actor the appropriate
number of times.

One slightly odd thing is that I'm using the Ramp in the outer model
to trigger the Pulse in the inner model.  This is more of a DE sort
of style, but seems to work here.

See the DDF Loop demo at ddf/demo/Loop/Loop.xml for a model that
dynamically changes the loop counts on the fly.

Someone like Steve or Edward might have some further refinements.

Hope this helps!



    Hi All,
        I am having great difficulty in figuring out how to handle various 
    looping constructs in Kepler/Ptolemy. So I ask if someone can explain 
    how to handle nested loops (using SDF and/or PN directors)?
        For example, assume I want to count from 0 to 3 twice in a row so 
    that the output on a final text display is
    I've tried various ways using Ramp actors and Composite actors but 
    cannot seem to get this simple case to work.
    Dan Higgins                                  higgins at nceas.ucsb.edu
    http://www.nceas.ucsb.edu/    Ph: 805-893-5127
    National Center for Ecological Analysis and Synthesis (NCEAS) 
    Marine Science Building - Room 3405
    Santa Barbara, CA 93195

More information about the Kepler-dev mailing list