source: branches/blt4_trunk/examples/zoo/curve/curve.tcl @ 6681

Last change on this file since 6681 was 6681, checked in by ldelgass, 8 years ago

merge rappture trunk to blt4_trunk branch

File size: 6.9 KB
Line 
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# ======================================================================
10package require Rappture
11
12# open the XML file containing the run parameters
13set driver [Rappture::library [lindex $argv 0]]
14
15set npts [$driver get input.(points).current]
16set min 0.01
17set max 10.0
18set 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
31for {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
37set xminl [expr $min+(($max-$min)/4.0)]
38set xmaxl [expr $max-(($max-$min)/4.0)]
39set yminl [expr {cos($xminl)/(1+$xminl)}]
40set 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
56for {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
63foreach 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
98for {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
115for {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
121set 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"
130for {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
144for {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"
156for {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...
162Rappture::result $driver
163exit 0
Note: See TracBrowser for help on using the repository browser.