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

Last change on this file since 2324 was 2324, checked in by gah, 13 years ago

added histogram example

File size: 3.7 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 0.01
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).xaxis.scale "log"
47    $driver put output.histogram(multi$factor).yaxis.label "Current"
48    $driver put output.histogram(multi$factor).yaxis.description \
49        "Current through the pull-down resistor."
50    $driver put output.histogram(multi$factor).yaxis.units "uA"
51    $driver put output.histogram(multi$factor).yaxis.log "log"
52
53    for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} {
54        set y [expr {pow(2.0,$factor*$x)/$x}]
55        $driver put -append yes \
56            output.histogram(multi$factor).component.xy "$x $y\n"
57    }
58}
59
60# generate a name value histogram
61set prefix output.histogram(namevalue)
62$driver put $prefix.about.label "Name value histogram"
63$driver put $prefix.about.description \
64    "This is an example of a name value histogram."
65$driver put $prefix.about.type "scatter"
66$driver put $prefix.xaxis.label "Time"
67$driver put $prefix.xaxis.description "Time during the experiment."
68$driver put output.histogram(namevalue).xaxis.units "s"
69$driver put output.histogram(namevalue).yaxis.label "Voltage v(11)"
70$driver put output.histogram(namevalue).yaxis.description "Output from the amplifier."
71$driver put output.histogram(namevalue).yaxis.units "V"
72
73set labels {
74  Apple Bread Cumcumber Date Eel Fish Grape Hotdog "Ice Cream"
75  Java Knife L M N O P
76}
77set count 0
78for {set x $min} {$x < $max} {set x [expr {$x+$dx}]} {
79    set y [expr {cos($x)/(1+$x)}]
80    set name [lindex $labels $count]
81    incr count
82    $driver put -append yes $prefix.component.namevalue "[list $name $y]\n"
83}
84
85# save the updated XML describing the run...
86Rappture::result $driver
87exit 0
Note: See TracBrowser for help on using the repository browser.