source: trunk/examples/app-fermi/wrapper/tcl/fermi.tcl @ 557

Last change on this file since 557 was 557, checked in by dkearney, 17 years ago

added c example of wrapping a legacy application, moved the tcl example to its own folder. this is related to rappture ticket #40

File size: 1.9 KB
Line 
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-2005  Purdue Research Foundation
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# ======================================================================
14package require Rappture
15
16# open the XML file containing the run parameters
17set driver [Rappture::library [lindex $argv 0]]
18
19set Ef [$driver get input.(Ef).current]
20set Ef [Rappture::Units::convert $Ef -to eV -units off]
21set T [$driver get input.(temperature).current]
22set T [Rappture::Units::convert $T -to K -units off]
23
24set fid [open "indeck" w]
25puts $fid $Ef
26puts $fid $T
27close $fid
28
29set status [catch {Rappture::exec octave --silent fermi.m < indeck} out]
30$driver put output.log $out
31
32if {$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
52file delete -force indeck out.dat
53
54# save the updated XML describing the run...
55Rappture::result $driver $status
56exit 0
Note: See TracBrowser for help on using the repository browser.