# ---------------------------------------------------------------------- # LANGUAGE: Python API # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2015 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== language "Python" { extension ".py" command {python @tool/@@FILENAME@@ @driver} main {# ---------------------------------------------------------------------- # MAIN PROGRAM - generated by the Rappture Builder # ---------------------------------------------------------------------- import Rappture import sys import numpy as np # uncomment these to redirect stdout and stderr # to files for debugging. #sys.stderr = open('debug.err', 'w') #sys.stdout = open('debug.out', 'w') # open the XML file containing the run parameters io = Rappture.PyXml(sys.argv[1]) ######################################################### # Get input values from Rappture ######################################################### @@INPUTS@@ ######################################################### # Add your code here for the main body of your program ######################################################### # spit out progress messages as you go along... Rappture.Utils.progress(0, "Starting...") Rappture.Utils.progress(5, "Loading data...") Rappture.Utils.progress(50, "Half-way there") Rappture.Utils.progress(100, "Done") ######################################################### # Save output values back to Rappture ######################################################### @@OUTPUTS@@ io.close() sys.exit() } input boolean { code "\n# get input value for $path" code "# returns value as string \"yes\" or \"no\"" code "$id = io\['$path.current'\].value == 'yes'" } input image { code "\n# get input value for $path" code "# returns base64-encoded image data" code "$id = io\['$path.current'\].value" } input integer { code "\n# get input value for $path" code "$id = int(io\['$path.current'\].value)" } input number { set units [attr get units] if {$units ne ""} { code "\n# get input value for $path and convert to $units" code "str = io\['$path.current'\].value" code "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")" } else { code "\n# get input value for $path" code "$id = float(io\['$path.current'\].value)" } } input * { code "\n# get input value for $path" code "$id = io\['$path.current'\].value" } output curve { code "\n# save output value for $path" code "# x and y should be lists or arrays -- modify as needed" code "io\['$path.component.xy'\] = (x, y)" } output histogram { code "\n# save output value for $path" code "# x and y should be lists or arrays -- modify as needed" code "# (x,h,w) = x-coord, height of bar, and width of bar" code "io\['$path.component.xhw'\] = (x, h, w)" } output image { code "\n# save output value for $path" code "# data should be base64-encoded image data" code "io\['$path.current'\] = imdata" } output * { code "\n# save output value for $path" code "io\['$path.current'\] = $id" } }