1 | # ---------------------------------------------------------------------- |
---|
2 | # EXAMPLE: Rappture <curve> elements |
---|
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 | package require Rappture |
---|
11 | |
---|
12 | # open the XML file containing the run parameters |
---|
13 | set driver [Rappture::library [lindex $argv 0]] |
---|
14 | |
---|
15 | set npts [$driver get input.(points).current] |
---|
16 | set min 0.01 |
---|
17 | set max 10.0 |
---|
18 | set dx [expr {($max-$min)/double($npts)}] |
---|
19 | |
---|
20 | # generate a single curve |
---|
21 | $driver put output.curve(single).about.label "Single curve" |
---|
22 | $driver put output.curve(single).about.description \ |
---|
23 | "This is an example of a single curve." |
---|
24 | $driver put output.curve(single).xaxis.label "Time" |
---|
25 | $driver put output.curve(single).xaxis.description "Time during the experiment." |
---|
26 | $driver put output.curve(single).xaxis.units "s" |
---|
27 | $driver put output.curve(single).yaxis.label "Voltage v(11)" |
---|
28 | $driver put output.curve(single).yaxis.description "Output from the amplifier." |
---|
29 | $driver put output.curve(single).yaxis.units "V" |
---|
30 | |
---|
31 | for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} { |
---|
32 | set y [expr {cos($x)/(1+$x)}] |
---|
33 | $driver put -append yes output.curve(single).component.xy "$x $y\n" |
---|
34 | } |
---|
35 | |
---|
36 | # generate a single curve with x and y axis upper and lower limits |
---|
37 | set xminl [expr $min+(($max-$min)/4.0)] |
---|
38 | set xmaxl [expr $max-(($max-$min)/4.0)] |
---|
39 | set yminl [expr {cos($xminl)/(1+$xminl)}] |
---|
40 | set ymaxl [expr {cos($xmaxl)/(1+$xmaxl)}] |
---|
41 | |
---|
42 | $driver put output.curve(limited).about.label "Axis limits curve" |
---|
43 | $driver put output.curve(limited).about.description \ |
---|
44 | "This is an example of a single curve with x and y axis limits applied." |
---|
45 | $driver put output.curve(limited).xaxis.label "Time" |
---|
46 | $driver put output.curve(limited).xaxis.description "Time during the experiment." |
---|
47 | $driver put output.curve(limited).xaxis.units "s" |
---|
48 | $driver put output.curve(limited).xaxis.min $xminl |
---|
49 | $driver put output.curve(limited).xaxis.max $xmaxl |
---|
50 | $driver put output.curve(limited).yaxis.label "Voltage v(11)" |
---|
51 | $driver put output.curve(limited).yaxis.description "Output from the amplifier." |
---|
52 | $driver put output.curve(limited).yaxis.units "V" |
---|
53 | $driver put output.curve(limited).yaxis.min $yminl |
---|
54 | $driver put output.curve(limited).yaxis.max $ymaxl |
---|
55 | |
---|
56 | for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} { |
---|
57 | set y [expr {cos($x)/(1+$x)}] |
---|
58 | $driver put -append yes output.curve(limited).component.xy "$x $y\n" |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | # generate multiple curves on the same plot |
---|
63 | foreach factor {1 2} { |
---|
64 | $driver put output.curve(multi$factor).about.group "Multiple curve" |
---|
65 | $driver put output.curve(multi$factor).about.label "Factor a=$factor" |
---|
66 | $driver put output.curve(multi$factor).about.description \ |
---|
67 | "This is an example of a multiple curves on the same plot." |
---|
68 | $driver put output.curve(multi$factor).xaxis.label "Frequency" |
---|
69 | $driver put output.curve(multi$factor).xaxis.description \ |
---|
70 | "Frequency of the input source." |
---|
71 | $driver put output.curve(multi$factor).xaxis.units "Hz" |
---|
72 | #$driver put output.curve(multi$factor).xaxis.scale "log" |
---|
73 | $driver put output.curve(multi$factor).yaxis.label "Current" |
---|
74 | $driver put output.curve(multi$factor).yaxis.description \ |
---|
75 | "Current through the pull-down resistor." |
---|
76 | $driver put output.curve(multi$factor).yaxis.units "uA" |
---|
77 | $driver put output.curve(multi$factor).yaxis.log "log" |
---|
78 | |
---|
79 | for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} { |
---|
80 | set y [expr {pow(2.0,$factor*$x)/$x}] |
---|
81 | $driver put -append yes \ |
---|
82 | output.curve(multi$factor).component.xy "$x $y\n" |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | # generate a scatter curve |
---|
87 | $driver put output.curve(scatter).about.label "Scatter curve" |
---|
88 | $driver put output.curve(scatter).about.description \ |
---|
89 | "This is an example of a scatter curve." |
---|
90 | $driver put output.curve(scatter).about.type "scatter" |
---|
91 | $driver put output.curve(scatter).xaxis.label "Time" |
---|
92 | $driver put output.curve(scatter).xaxis.description "Time during the experiment." |
---|
93 | $driver put output.curve(scatter).xaxis.units "s" |
---|
94 | $driver put output.curve(scatter).yaxis.label "Voltage v(11)" |
---|
95 | $driver put output.curve(scatter).yaxis.description "Output from the amplifier." |
---|
96 | $driver put output.curve(scatter).yaxis.units "V" |
---|
97 | |
---|
98 | for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} { |
---|
99 | set y [expr {cos($x)/(1+$x)}] |
---|
100 | $driver put -append yes output.curve(scatter).component.xy "$x $y\n" |
---|
101 | } |
---|
102 | |
---|
103 | # generate a bar curve |
---|
104 | $driver put output.curve(bars).about.label "Bar chart" |
---|
105 | $driver put output.curve(bars).about.description \ |
---|
106 | "This is an example of a scatter curve." |
---|
107 | $driver put output.curve(bars).about.type "bar" |
---|
108 | $driver put output.curve(bars).xaxis.label "Time" |
---|
109 | $driver put output.curve(bars).xaxis.description "Time during the experiment." |
---|
110 | $driver put output.curve(bars).xaxis.units "s" |
---|
111 | $driver put output.curve(bars).yaxis.label "Voltage v(11)" |
---|
112 | $driver put output.curve(bars).yaxis.description "Output from the amplifier." |
---|
113 | $driver put output.curve(bars).yaxis.units "V" |
---|
114 | |
---|
115 | for {set x 0} {$x < $npts} {incr x} { |
---|
116 | set y [expr {sin($x)/(1+$x)}] |
---|
117 | $driver put -append yes output.curve(bars).component.xy "$x $y\n" |
---|
118 | } |
---|
119 | |
---|
120 | # generate mixed curves on the same plot |
---|
121 | set deg2rad 0.017453292519943295 |
---|
122 | |
---|
123 | $driver put output.curve(line).about.group "Mixed element types" |
---|
124 | $driver put output.curve(line).about.label "Sine" |
---|
125 | $driver put output.curve(line).about.description \ |
---|
126 | "This is an example of a mixed curves on the same plot." |
---|
127 | $driver put output.curve(line).xaxis.label "Degrees" |
---|
128 | #$driver put output.curve(line).yaxis.label "Sine" |
---|
129 | $driver put output.curve(line).about.type "line" |
---|
130 | for {set x 0} {$x <= 360} {incr x 30} { |
---|
131 | set y [expr {sin($x*$deg2rad)}] |
---|
132 | $driver put -append yes output.curve(line).component.xy "$x $y\n" |
---|
133 | } |
---|
134 | |
---|
135 | $driver put output.curve(bar).about.group "Mixed element types" |
---|
136 | $driver put output.curve(bar).about.label "Cosine" |
---|
137 | $driver put output.curve(bar).about.description \ |
---|
138 | "This is an example of a mixed curves on the same plot." |
---|
139 | $driver put output.curve(bar).xaxis.label "Degrees" |
---|
140 | #$driver put output.curve(bar).yaxis.label "Cosine" |
---|
141 | $driver put output.curve(bar).about.type "bar" |
---|
142 | $driver put output.curve(bar).about.style "-barwidth 24.0" |
---|
143 | |
---|
144 | for {set x 0} {$x <= 360} {incr x 30} { |
---|
145 | set y [expr {cos($x*$deg2rad)}] |
---|
146 | $driver put -append yes output.curve(bar).component.xy "$x $y\n" |
---|
147 | } |
---|
148 | |
---|
149 | $driver put output.curve(point).about.group "Mixed element types" |
---|
150 | $driver put output.curve(point).about.label "Random" |
---|
151 | $driver put output.curve(point).about.description \ |
---|
152 | "This is an example of a mixed curves on the same plot." |
---|
153 | $driver put output.curve(point).xaxis.label "Degrees" |
---|
154 | #$driver put output.curve(point).yaxis.label "Random" |
---|
155 | $driver put output.curve(point).about.type "scatter" |
---|
156 | for {set x 0} {$x <= 360} {incr x 10} { |
---|
157 | set y [expr {(rand() * 2.0) - 1}] |
---|
158 | $driver put -append yes output.curve(point).component.xy "$x $y\n" |
---|
159 | } |
---|
160 | |
---|
161 | # save the updated XML describing the run... |
---|
162 | Rappture::result $driver |
---|
163 | exit 0 |
---|