1 | # ---------------------------------------------------------------------- |
---|
2 | # LANGUAGE: Python API |
---|
3 | # ====================================================================== |
---|
4 | # AUTHOR: Michael McLennan, Purdue University |
---|
5 | # Copyright (c) 2004-2011 Purdue Research Foundation |
---|
6 | # |
---|
7 | # See the file "license.terms" for information on usage and |
---|
8 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
9 | # ====================================================================== |
---|
10 | language "Python" { |
---|
11 | extension ".py" |
---|
12 | command {python @tool/@@FILENAME@@ @driver} |
---|
13 | |
---|
14 | main {# ---------------------------------------------------------------------- |
---|
15 | # MAIN PROGRAM - generated by the Rappture Builder |
---|
16 | # ---------------------------------------------------------------------- |
---|
17 | import Rappture |
---|
18 | import sys |
---|
19 | from math import * |
---|
20 | |
---|
21 | # open the XML file containing the run parameters |
---|
22 | io = Rappture.library(sys.argv[1]) |
---|
23 | |
---|
24 | ######################################################### |
---|
25 | # Get input values from Rappture |
---|
26 | ######################################################### |
---|
27 | @@INPUTS@@ |
---|
28 | |
---|
29 | ######################################################### |
---|
30 | # Add your code here for the main body of your program |
---|
31 | ######################################################### |
---|
32 | |
---|
33 | # spit out progress messages as you go along... |
---|
34 | Rappture.Utils.progress(0, "Starting...") |
---|
35 | Rappture.Utils.progress(5, "Loading data...") |
---|
36 | Rappture.Utils.progress(50, "Half-way there") |
---|
37 | Rappture.Utils.progress(100, "Done") |
---|
38 | |
---|
39 | ######################################################### |
---|
40 | # Save output values back to Rappture |
---|
41 | ######################################################### |
---|
42 | @@OUTPUTS@@ |
---|
43 | |
---|
44 | Rappture.result(io) |
---|
45 | sys.exit() |
---|
46 | } |
---|
47 | |
---|
48 | input boolean { |
---|
49 | code "\n# get input value for $path" |
---|
50 | code "# returns value as string \"yes\" or \"no\"" |
---|
51 | code "$id = io.get('$path.current') == 'yes'" |
---|
52 | } |
---|
53 | input image { |
---|
54 | code "\n# get input value for $path" |
---|
55 | code "# returns base64-encoded image data" |
---|
56 | code "$id = io.get('$path.current')" |
---|
57 | } |
---|
58 | input integer { |
---|
59 | code "\n# get input value for $path" |
---|
60 | code "$id = int(io.get('$path.current'))" |
---|
61 | } |
---|
62 | input number { |
---|
63 | set units [attr get units] |
---|
64 | if {$units ne ""} { |
---|
65 | code "\n# get input value for $path and convert to $units" |
---|
66 | code "str = io.get('$path.current')" |
---|
67 | code "$id = Rappture.Units.convert(str, to=\"$units\", units=\"off\")" |
---|
68 | } else { |
---|
69 | code "\n# get input value for $path" |
---|
70 | code "$id = float(io.get('$path.current'))" |
---|
71 | } |
---|
72 | } |
---|
73 | input * { |
---|
74 | code "\n# get input value for $path" |
---|
75 | code "$id = io.get('$path.current')" |
---|
76 | } |
---|
77 | |
---|
78 | output curve { |
---|
79 | code "\n# save output value for $path" |
---|
80 | code "# this shows just one (x,y) point -- modify as needed" |
---|
81 | code "line = "%g %g\n" % (x, y)" |
---|
82 | code "io.put('$path.component.xy', line, append=1)" |
---|
83 | } |
---|
84 | output histogram { |
---|
85 | code "\n# save output value for $path" |
---|
86 | code "# this shows just one point -- modify as needed" |
---|
87 | code "# (x,h,w) = x-coord, height of bar, and width of bar (optional)" |
---|
88 | code "line = "%g %g %g\n" % (x, h, w)" |
---|
89 | code "io.put('$path.component.xhw', line, append=1)" |
---|
90 | } |
---|
91 | output image { |
---|
92 | code "\n# save output value for $path" |
---|
93 | code "# data should be base64-encoded image data" |
---|
94 | code "io.put('$path.current', imdata)" |
---|
95 | } |
---|
96 | output * { |
---|
97 | code "\n# save output value for $path" |
---|
98 | code "io.put('$path.current',$id)" |
---|
99 | } |
---|
100 | } |
---|