[Swift-user] How to determine length of an array?

Thomas Uram turam at mcs.anl.gov
Thu Aug 2 11:23:30 CDT 2012


Some functionality of my script is conditional based on the contents of an array, so I need to determine the array length. The path described by the documentation leads to an exception. How should I determine array length? Or, a lesser requirement: how can I determine if an array is empty?

The user guide (http://www.ci.uchicago.edu/swift/guides/trunk/userguide/userguide.html) says:

@length(array) will return the length of an array in Swift. This function will wait for all elements in the array to be written before returning the length.

But the following Swift script:

type file;
file input_files[] <filesys_mapper; suffix=".log">;
trace( @length( input_files ) ) ;

Produces this output:

Swift 0.93 swift-r5483 cog-r3339

RunID: 20120802-1218-5dfj571d
 (input): found 255 files
Progress:  time: Thu, 02 Aug 2012 12:18:51 -0400
Execution failed:
	java.lang.ClassCastException: org.griphyn.vdl.mapping.RootArrayDataNode cannot be cast to java.util.Map
	at org.griphyn.vdl.karajan.lib.swiftscript.Misc.swiftscript_length(Misc.java:399)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.globus.cog.karajan.workflow.nodes.functions.FunctionsCollection.function(FunctionsCollection.java:82)
	at org.globus.cog.karajan.workflow.nodes.functions.AbstractFunction.post(AbstractFunction.java:27)
	at org.globus.cog.karajan.workflow.nodes.AbstractSequentialWithArguments.completed(AbstractSequentialWithArguments.java:194)
	at org.globus.cog.karajan.workflow.nodes.FlowNode.complete(FlowNode.java:214)
	at org.globus.cog.karajan.workflow.nodes.FlowContainer.post(FlowContainer.java:58)
	at org.globus.cog.karajan.workflow.nodes.functions.AbstractFunction.post(AbstractFunction.java:28)
	at org.globus.cog.karajan.workflow.nodes.Sequential.startNext(Sequential.java:29)
	at org.globus.cog.karajan.workflow.nodes.Sequential.executeChildren(Sequential.java:20)
	at org.globus.cog.karajan.workflow.nodes.FlowContainer.execute(FlowContainer.java:63)
	at org.globus.cog.karajan.workflow.nodes.FlowNode.restart(FlowNode.java:139)
	at org.globus.cog.karajan.workflow.nodes.FlowNode.start(FlowNode.java:197)
	at org.globus.cog.karajan.workflow.FlowElementWrapper.start(FlowElementWrapper.java:227)
	at org.globus.cog.karajan.workflow.events.EventBus.start(EventBus.java:104)
	at org.globus.cog.karajan.workflow.events.EventTargetPair.run(EventTargetPair.java:40)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-user/attachments/20120802/620b9c15/attachment.html>


More information about the Swift-user mailing list