Stefan,
DirectoryListing produces an Array an output.
If you know the number of files in the directory in advance, then you can use ArrayToSequence and have a SDF Director. The reason you need to know the number of files is because you need to know the size of the array so that SDF can calculate a schedule. An alternative is to set the allowRateChanges in SDFDirector to true, see DirectorySDFRateChange.xml
One issue with this model is that it does not terminate naturally.

Or, you can use the PN Director and terminate the model with a test that looks for a file name that has already been seen.

An alternative is to put the DirectoryListing inside a Composite that has a SDF Director. I ran in to issue with terminating the model though. Attached is DirectoryListing2.xml.

I'm probably missing an easier way to do this though.

See also
https://kepler-project.org/users/faq#how-do-i-branch

_Christopher

On 4/26/12 7:29 AM, Tomasz Żok wrote:
Dear Stefan,

please take a look at this tutorial session:
http://scilla.man.poznan.pl:8080/confluence/x/oAFU

You can jump straight to sections dedicated to looping in Kepler, there are
several possible solutions presented.

Best regards,
Tomek

Dear Kepler Community, I am rathre new to Kepler and I have a question regarding looping. I searched the documentation and the mailing list archive, but could not find a proper answer. For a specific workflow, I need to fetch several files from a Web server and process these. For this purpose, I use the DirectoryListing - Actor. Fetching the URLs of the files works fine, but how would I iterate over all the URLs for further processing? I would like to use the "URL to File" actor, but how would I iterate over the elements/URLs I receive? Is there an elegant way, or do I have to assemble (rather complicated) loops just for going through all the elements? So far I would use the Actor ArrayElement, but then I have to feed an index variable to it, which I would have to iterate after each token. This seems to be a bit of an overhead to me. Thanks in advance, Kind regards, Stefan



--
Christopher Brooks, PMP                       University of California
CHESS Executive Director                      US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
ph: 510.643.9841                                (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670

<?xml version="1.0" standalone="no"?>
<!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN"
    "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd";>
<entity name="DirectoryListing2" class="ptolemy.actor.TypedCompositeActor">
    <property name="_createdBy" class="ptolemy.kernel.attributes.VersionAttribute" value="9.0.devel">
    </property>
    <property name="_windowProperties" class="ptolemy.actor.gui.WindowPropertiesAttribute" value="{bounds={313, 195, 813, 588}, maximized=false}">
    </property>
    <property name="_vergilSize" class="ptolemy.actor.gui.SizeAttribute" value="[600, 478]">
    </property>
    <property name="_vergilZoomFactor" class="ptolemy.data.expr.ExpertParameter" value="1.0">
    </property>
    <property name="_vergilCenter" class="ptolemy.data.expr.ExpertParameter" value="{300.0, 239.0}">
    </property>
    <property name="Annotation" class="ptolemy.vergil.kernel.attributes.TextAttribute">
        <property name="text" class="ptolemy.kernel.util.StringAttribute" value="List a directory and make sure that this file is present in that directory.">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="[30.0, 200.0]">
        </property>
    </property>
    <property name="SDF Director" class="ptolemy.domains.sdf.kernel.SDFDirector">
        <property name="iterations" class="ptolemy.data.expr.Parameter" value="0">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="{160, 40}">
        </property>
    </property>
    <entity name="Display" class="ptolemy.actor.lib.gui.Display">
        <property name="_windowProperties" class="ptolemy.actor.gui.WindowPropertiesAttribute" value="{bounds={598, 421, 484, 208}, maximized=false}">
        </property>
        <property name="_paneSize" class="ptolemy.actor.gui.SizeAttribute" value="[484, 164]">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="{400, 130}">
        </property>
    </entity>
    <entity name="CompositeActor" class="ptolemy.actor.TypedCompositeActor">
        <property name="_location" class="ptolemy.kernel.util.Location" value="[110.0, 150.0]">
        </property>
        <property name="SDF Director" class="ptolemy.domains.sdf.kernel.SDFDirector">
            <property name="iterations" class="ptolemy.data.expr.Parameter" value="10">
            </property>
            <property name="_location" class="ptolemy.kernel.util.Location" value="[170.0, 50.0]">
            </property>
        </property>
        <port name="port_0" class="ptolemy.actor.TypedIOPort">
            <property name="output"/>
            <property name="_location" class="ptolemy.kernel.util.Location" value="{580.0, 200.0}">
            </property>
        </port>
        <entity name="DirectoryListing" class="ptolemy.actor.lib.io.DirectoryListing">
            <property name="directoryOrURL" class="ptolemy.actor.parameters.FilePortParameter" value="$CLASSPATH/ptolemy/actor/lib/io/test/auto">
            </property>
            <property name="pattern" class="ptolemy.data.expr.StringParameter" value="">
            </property>
            <property name="listOnlyFiles" class="ptolemy.data.expr.Parameter" value="true">
            </property>
            <property name="_location" class="ptolemy.kernel.util.Location" value="[80.0, 135.0]">
            </property>
        </entity>
        <entity name="ArrayToSequence" class="ptolemy.domains.sdf.lib.ArrayToSequence">
            <property name="enforceArrayLength" class="ptolemy.data.expr.Parameter" value="false">
            </property>
            <property name="_location" class="ptolemy.kernel.util.Location" value="[205.0, 135.0]">
            </property>
        </entity>
        <relation name="relation3" class="ptolemy.actor.TypedIORelation">
        </relation>
        <relation name="relation_0" class="ptolemy.actor.TypedIORelation">
        </relation>
        <link port="port_0" relation="relation_0"/>
        <link port="DirectoryListing.output" relation="relation3"/>
        <link port="ArrayToSequence.input" relation="relation3"/>
        <link port="ArrayToSequence.output" relation="relation_0"/>
    </entity>
    <relation name="relation" class="ptolemy.actor.TypedIORelation">
    </relation>
    <link port="Display.input" relation="relation"/>
    <link port="CompositeActor.port_0" relation="relation"/>
</entity>
<?xml version="1.0" standalone="no"?>
<!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN"
    "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd";>
<entity name="DirectoryListingSDFRateChange" class="ptolemy.actor.TypedCompositeActor">
    <property name="_createdBy" class="ptolemy.kernel.attributes.VersionAttribute" value="9.0.devel">
    </property>
    <property name="_windowProperties" class="ptolemy.actor.gui.WindowPropertiesAttribute" value="{bounds={313, 195, 813, 588}, maximized=false}">
    </property>
    <property name="_vergilSize" class="ptolemy.actor.gui.SizeAttribute" value="[600, 478]">
    </property>
    <property name="_vergilZoomFactor" class="ptolemy.data.expr.ExpertParameter" value="1.0">
    </property>
    <property name="_vergilCenter" class="ptolemy.data.expr.ExpertParameter" value="{300.0, 239.0}">
    </property>
    <property name="Annotation" class="ptolemy.vergil.kernel.attributes.TextAttribute">
        <property name="text" class="ptolemy.kernel.util.StringAttribute" value="List a directory and make sure that this file is present in that directory.">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="[30.0, 200.0]">
        </property>
    </property>
    <property name="SDF Director" class="ptolemy.domains.sdf.kernel.SDFDirector">
        <property name="iterations" class="ptolemy.data.expr.Parameter" value="1000">
        </property>
        <property name="allowRateChanges" class="ptolemy.data.expr.Parameter" value="true">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="[155.0, 60.0]">
        </property>
    </property>
    <entity name="Display" class="ptolemy.actor.lib.gui.Display">
        <property name="_windowProperties" class="ptolemy.actor.gui.WindowPropertiesAttribute" value="{bounds={596, 401, 484, 208}, maximized=false}">
        </property>
        <property name="_paneSize" class="ptolemy.actor.gui.SizeAttribute" value="[484, 164]">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="{400, 130}">
        </property>
    </entity>
    <entity name="DirectoryListing" class="ptolemy.actor.lib.io.DirectoryListing">
        <property name="directoryOrURL" class="ptolemy.actor.parameters.FilePortParameter" value="$CLASSPATH/ptolemy/actor/lib/io/test/auto">
        </property>
        <property name="pattern" class="ptolemy.data.expr.StringParameter" value="">
        </property>
        <property name="listOnlyFiles" class="ptolemy.data.expr.Parameter" value="true">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="{90.0, 145.0}">
        </property>
    </entity>
    <entity name="ArrayToSequence" class="ptolemy.domains.sdf.lib.ArrayToSequence">
        <property name="enforceArrayLength" class="ptolemy.data.expr.Parameter" value="false">
        </property>
        <property name="_location" class="ptolemy.kernel.util.Location" value="[215.0, 145.0]">
        </property>
    </entity>
    <relation name="relation2" class="ptolemy.actor.TypedIORelation">
    </relation>
    <relation name="relation" class="ptolemy.actor.TypedIORelation">
    </relation>
    <link port="Display.input" relation="relation"/>
    <link port="DirectoryListing.output" relation="relation2"/>
    <link port="ArrayToSequence.input" relation="relation2"/>
    <link port="ArrayToSequence.output" relation="relation"/>
</entity>
_______________________________________________
Kepler-users mailing list
Kepler-users@kepler-project.org
http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users

Reply via email to