source: branches/blt4/examples/app-fermi/wrapper/python/fermi.py @ 3957

Last change on this file since 3957 was 3957, checked in by gah, 11 years ago

sync with trunk

File size: 1.9 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Fermi-Dirac function in Python.
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# ======================================================================
14import Rappture
15import sys, os, commands, string
16
17# open the XML file containing the run parameters
18driver = Rappture.library(sys.argv[1])
19
20Tstr = driver.get('input.(temperature).current')
21T = Rappture.Units.convert(Tstr, to="k", units="off")
22
23Efstr = driver.get('input.(Ef).current')
24Ef = Rappture.Units.convert(Efstr, to="eV", units="off")
25
26fid = open('indeck','w')
27infile = "%(Ef)s\n%(T)s\n" % { 'Ef':Ef, 'T':T }
28fid.write(infile)
29fid.close()
30
31try:
32  out = commands.getoutput('octave --silent fermi.m < indeck')
33except:
34  sys.stderr.write('Error during execution of fermi.m')
35  exit(1);
36
37driver.put('output.log',out)
38
39fid = open('out.dat','r')
40info = fid.readlines()
41fid.close()
42
43# Label output graph with title, x-axis label,
44# y-axis lable, and y-axis units
45driver.put('output.curve(f12).about.label','Fermi-Dirac Factor')
46driver.put('output.curve(f12).xaxis.label','Fermi-Dirac Factor')
47driver.put('output.curve(f12).yaxis.label','Energy')
48driver.put('output.curve(f12).yaxis.units','eV')
49
50# skip over the first 4 header lines
51for line in info[6:]:
52    f,E = string.split(line[:-1])
53    f,E = float(f),float(E)
54    xy = "%g %g\n" % (f,E)
55    driver.put('output.curve(f12).component.xy',xy,append=1)
56
57os.remove('indeck'); os.remove('out.dat')
58
59Rappture.result(driver)
60sys.exit(0)
Note: See TracBrowser for help on using the repository browser.