1 | # ---------------------------------------------------------------------- |
---|
2 | # LANGUAGE: Ruby API |
---|
3 | # ====================================================================== |
---|
4 | # AUTHOR: Michael McLennan, Purdue University |
---|
5 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
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 "Ruby" { |
---|
11 | extension ".rb" |
---|
12 | command {ruby @tool/@@FILENAME@@ @driver} |
---|
13 | |
---|
14 | main {# ---------------------------------------------------------------------- |
---|
15 | # MAIN PROGRAM - generated by the Rappture Builder |
---|
16 | # ---------------------------------------------------------------------- |
---|
17 | require "Rappture" |
---|
18 | |
---|
19 | # open the XML file containing the run parameters |
---|
20 | io = Rappture.new(ARGV[0]) |
---|
21 | |
---|
22 | ######################################################### |
---|
23 | # Get input values from Rappture |
---|
24 | ######################################################### |
---|
25 | @@INPUTS@@ |
---|
26 | |
---|
27 | ######################################################### |
---|
28 | # Add your code here for the main body of your program |
---|
29 | ######################################################### |
---|
30 | |
---|
31 | # spit out progress messages as you go along... |
---|
32 | io.progress(0, "Starting...") |
---|
33 | io.progress(5, "Loading data...") |
---|
34 | io.progress(50, "Half-way there") |
---|
35 | io.progress(100, "Done") |
---|
36 | |
---|
37 | ######################################################### |
---|
38 | # Save output values back to Rappture |
---|
39 | ######################################################### |
---|
40 | @@OUTPUTS@@ |
---|
41 | |
---|
42 | io.result(0) |
---|
43 | } |
---|
44 | |
---|
45 | input boolean { |
---|
46 | code "\n# get input value for $path" |
---|
47 | code "# returns value as string \"yes\" or \"no\"" |
---|
48 | code "str = io.get(\"$path.current\")" |
---|
49 | code "$id = (str == \"yes\")" |
---|
50 | } |
---|
51 | input image { |
---|
52 | code "\n# get input value for $path" |
---|
53 | code "# returns base64-encoded image data" |
---|
54 | code "$id = io.get(\"$path.current\")" |
---|
55 | } |
---|
56 | input number { |
---|
57 | set units [attr get units] |
---|
58 | if {$units ne ""} { |
---|
59 | code "\n# get input value for $path and convert to $units" |
---|
60 | code "str = io.get(\"$path.current\")" |
---|
61 | code "$id = io.convert(str, \"$units\", Rappture::UNITS_OFF)" |
---|
62 | } else { |
---|
63 | code "\n# get input value for $path" |
---|
64 | code "$id = io.get(\"$path.current\")" |
---|
65 | } |
---|
66 | } |
---|
67 | input * { |
---|
68 | code "\n# get input value for $path" |
---|
69 | code "$id = io.get(\"$path.current\")" |
---|
70 | } |
---|
71 | |
---|
72 | output curve { |
---|
73 | code "\n# save output value for $path" |
---|
74 | code "# this shows just one (x,y) point -- modify as needed" |
---|
75 | code "str = sprintf(\"%g %g\\n\", x, y)" |
---|
76 | code "io.put(\"$path.component.xy\", str, Rappture::APPEND)" |
---|
77 | } |
---|
78 | output histogram { |
---|
79 | code "\n# save output value for $path" |
---|
80 | code "# this shows just one point -- modify as needed" |
---|
81 | code "# (x,h,w) = x-coord, height of bar, and width of bar (optional)" |
---|
82 | code "str = sprintf(\"%g %g %g\\n\", x, h, w)" |
---|
83 | code "io.put(\"$path.component.xhw\", str, Rappture::APPEND)" |
---|
84 | } |
---|
85 | output image { |
---|
86 | code "\n# save output value for $path" |
---|
87 | code "# data should be base64-encoded image data" |
---|
88 | code "io.put(\"$path.current\", imdata, Rappture::OVERWRITE)" |
---|
89 | } |
---|
90 | output * { |
---|
91 | code "\n# save output value for $path" |
---|
92 | code "io.put(\"$path.current\",$id, Rappture::OVERWRITE)" |
---|
93 | } |
---|
94 | } |
---|