[Swift-commit] r6416 - in trunk: libexec src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib/swiftscript

ketan at ci.uchicago.edu ketan at ci.uchicago.edu
Mon Apr 8 23:16:40 CDT 2013


Author: ketan
Date: 2013-04-08 23:16:40 -0500 (Mon, 08 Apr 2013)
New Revision: 6416

Added:
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ExtractFloat.java
Modified:
   trunk/libexec/vdl-lib.xml
   trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
Log:
adding extractFloat function to read floating point numbers from file a la extractInt

Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2013-04-09 00:04:05 UTC (rev 6415)
+++ trunk/libexec/vdl-lib.xml	2013-04-09 04:16:40 UTC (rev 6416)
@@ -3,6 +3,7 @@
   <namespace prefix="swiftscript">
 	<!-- string functions library -->
 	<export name="extract_int"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ExtractInt"/></export>
+	<export name="extract_float"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ExtractFloat"/></export>
 	<export name="read_data"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadData"/></export>
 	<export name="read_data2"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured"/></export>
 	<export name="read_structured"><elementDef classname="org.griphyn.vdl.karajan.lib.swiftscript.ReadStructured"/></export>

Modified: trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2013-04-09 00:04:05 UTC (rev 6415)
+++ trunk/src/org/griphyn/vdl/engine/ProcedureSignature.java	2013-04-09 04:16:40 UTC (rev 6416)
@@ -185,6 +185,7 @@
 		add(functionsMap, "arg", returns(STRING), args(STRING, optional(STRING)));
 
 		add(functionsMap, "extractInt", returns(INT), args(ANY));
+		add(functionsMap, "extractFloat", returns(FLOAT), args(ANY));
 		add(functionsMap, "filename", returns(STRING), args(ANY));
 		add(functionsMap, "filenames", returns(STRING_ARRAY), args(ANY));
 		add(functionsMap, "dirname", returns(STRING), args(ANY));

Added: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ExtractFloat.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ExtractFloat.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/ExtractFloat.java	2013-04-09 04:16:40 UTC (rev 6416)
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2012 University of Chicago
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.griphyn.vdl.karajan.lib.swiftscript;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.griphyn.vdl.karajan.lib.VDLFunction;
+import org.griphyn.vdl.mapping.AbstractDataNode;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.RootDataNode;
+import org.griphyn.vdl.type.Types;
+
+
+public class ExtractFloat extends VDLFunction {
+	static {
+		setArguments(ExtractFloat.class, new Arg[] { PA_VAR });
+	}
+
+	public Object function(VariableStack stack) throws ExecutionException {
+		AbstractDataNode handle = null;
+		try {
+			handle = (AbstractDataNode) PA_VAR.getValue(stack);
+			handle.waitFor();
+			
+			String fn = argList(filename(handle), true);
+			Reader freader = new FileReader(fn);
+			BufferedReader breader = new BufferedReader(freader);
+			String str = breader.readLine();
+			freader.close();
+			DSHandle result = new RootDataNode(Types.FLOAT, Float.parseFloat(str));
+			int provid = VDLFunction.nextProvenanceID();
+			VDLFunction.logProvenanceResult(provid, result, "extractfloat");
+			VDLFunction.logProvenanceParameter(provid, handle, "filename");
+			return result;
+		}
+		catch (IOException ioe) {
+			throw new ExecutionException("Reading floatingpoint content of file", ioe);
+		}
+	}
+}




More information about the Swift-commit mailing list