1 | # ---------------------------------------------------------------------- |
---|
2 | # EXAMPLE: Fermi-Dirac function in Tcl. |
---|
3 | # |
---|
4 | # This simple example shows how to use Rappture to wrap up a |
---|
5 | # simulator written in Matlab or some other language. |
---|
6 | # |
---|
7 | # ====================================================================== |
---|
8 | # AUTHOR: Michael McLennan, Purdue University |
---|
9 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and |
---|
12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # ====================================================================== |
---|
14 | package require Rappture |
---|
15 | |
---|
16 | # open the XML file containing the run parameters |
---|
17 | set driver [Rappture::library [lindex $argv 0]] |
---|
18 | |
---|
19 | set Ef [$driver get input.(Ef).current] |
---|
20 | set Ef [Rappture::Units::convert $Ef -to eV -units off] |
---|
21 | set T [$driver get input.(temperature).current] |
---|
22 | set T [Rappture::Units::convert $T -to K -units off] |
---|
23 | |
---|
24 | set fid [open "indeck" w] |
---|
25 | puts $fid $Ef |
---|
26 | puts $fid $T |
---|
27 | close $fid |
---|
28 | |
---|
29 | set status [catch {Rappture::exec octave --silent fermi.m < indeck} out] |
---|
30 | $driver put output.log $out |
---|
31 | |
---|
32 | if {$status == 0} { |
---|
33 | set fid [open out.dat r] |
---|
34 | set info [read $fid] |
---|
35 | close $fid |
---|
36 | |
---|
37 | # Label output graph with title, x-axis label, |
---|
38 | # y-axis lable, and y-axis units |
---|
39 | $driver put -append no output.curve(f12).about.label "Fermi-Dirac Factor" |
---|
40 | $driver put -append no output.curve(f12).xaxis.label "Fermi-Dirac Factor" |
---|
41 | $driver put -append no output.curve(f12).yaxis.label "Energy" |
---|
42 | $driver put -append no output.curve(f12).yaxis.units "eV" |
---|
43 | |
---|
44 | # skip over the first 4 header lines |
---|
45 | foreach line [lrange [split $info \n] 5 end] { |
---|
46 | if {[scan $line {%g %g} f E] == 2} { |
---|
47 | $driver put -append yes output.curve(f12).component.xy "$f $E\n" |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | file delete -force indeck out.dat |
---|
53 | |
---|
54 | # save the updated XML describing the run... |
---|
55 | Rappture::result $driver $status |
---|
56 | exit 0 |
---|