source: trunk/examples/zoo/histogram/histogram.tcl @ 2388

Last change on this file since 2388 was 2388, checked in by gah, 13 years ago
File size: 3.6 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Rappture <histogram> elements
3# ======================================================================
4#  AUTHOR:  Michael McLennan, Purdue University
5#  Copyright (c) 2004-2005  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# ======================================================================
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 1
17set max 10.0
18set dx [expr {($max-$min)/double($npts)}]
19
20# generate a single histogram
21$driver put output.histogram(single).about.label "Single histogram"
22$driver put output.histogram(single).about.description \
23    "This is an example of a single histogram."
24$driver put output.histogram(single).xaxis.label "Time"
25$driver put output.histogram(single).xaxis.description "Time during the experiment."
26$driver put output.histogram(single).xaxis.units "s"
27$driver put output.histogram(single).yaxis.label "Voltage v(11)"
28$driver put output.histogram(single).yaxis.description "Output from the amplifier."
29$driver put output.histogram(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.histogram(single).component.xy "$x $y\n"
34}
35
36# generate multiple histograms on the same plot
37foreach factor {1 2} {
38    $driver put output.histogram(multi$factor).about.group "Multiple histogram"
39    $driver put output.histogram(multi$factor).about.label "Factor a=$factor"
40    $driver put output.histogram(multi$factor).about.description \
41        "This is an example of a multiple histograms on the same plot."
42    $driver put output.histogram(multi$factor).xaxis.label "Frequency"
43    $driver put output.histogram(multi$factor).xaxis.description \
44        "Frequency of the input source."
45    $driver put output.histogram(multi$factor).xaxis.units "Hz"
46    $driver put output.histogram(multi$factor).yaxis.label "Current"
47    $driver put output.histogram(multi$factor).yaxis.description \
48        "Current through the pull-down resistor."
49    $driver put output.histogram(multi$factor).yaxis.units "uA"
50    $driver put output.histogram(multi$factor).yaxis.log "log"
51
52    for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} {
53        set y [expr {pow(2.0,$factor*$x)/$x}]
54        $driver put -append yes \
55            output.histogram(multi$factor).component.xy "$x $y\n"
56    }
57}
58
59# generate a name value histogram
60set prefix output.histogram(namevalue)
61$driver put $prefix.about.label "Name value histogram"
62$driver put $prefix.about.description \
63    "This is an example of a name value histogram."
64$driver put $prefix.about.type "scatter"
65$driver put $prefix.xaxis.label "Time"
66$driver put $prefix.xaxis.description "Time during the experiment."
67$driver put output.histogram(namevalue).xaxis.units "s"
68$driver put output.histogram(namevalue).yaxis.label "Voltage v(11)"
69$driver put output.histogram(namevalue).yaxis.description "Output from the amplifier."
70$driver put output.histogram(namevalue).yaxis.units "V"
71
72set labels {
73  Apple Bread Cumcumber Date Eel Fish Grape Hotdog "Ice Cream"
74  Java Knife L M N O P
75}
76set count 0
77for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} {
78    set y [expr {cos($x)/(1+$x)}]
79    set name [lindex $labels $count]
80    incr count
81    $driver put -append yes $prefix.component.xy "[list $name $y]\n"
82}
83
84# save the updated XML describing the run...
85Rappture::result $driver
86exit 0
Note: See TracBrowser for help on using the repository browser.