1 |
#!/usr/bin/python |
2 |
# $Id$ |
3 |
|
4 |
""" |
5 |
commandline utility to take an xml file, parse it, and run a simulation. |
6 |
invoke this by doing ./runmodel.py <filename.xml> |
7 |
|
8 |
@var __author__: name of author |
9 |
@var __copyright__: copyrights |
10 |
@var __license__: licence agreement |
11 |
@var __url__: url entry point on documentation |
12 |
@var __version__: version |
13 |
@var __date__: date of the version |
14 |
""" |
15 |
|
16 |
__author__="Elspeth Thorne, e.thorne@uq.edu.au" |
17 |
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
18 |
http://www.access.edu.au |
19 |
Primary Business: Queensland, Australia""" |
20 |
__license__="""Licensed under the Open Software License version 3.0 |
21 |
http://www.opensource.org/licenses/osl-3.0.php""" |
22 |
__url__="http://www.iservo.edu.au/esys" |
23 |
__version__="$Revision$" |
24 |
__date__="$Date$" |
25 |
|
26 |
|
27 |
from esys.escript import modelframe |
28 |
import optparse |
29 |
|
30 |
parser = optparse.OptionParser(usage="%prog [options] <ESySXML files>") |
31 |
parser.add_option('-f', '--file', dest='filename', |
32 |
help='the input ESySXML file', metavar='FILE') |
33 |
parser.add_option('-d', '--debug', dest='dbg', action="store_true", |
34 |
help='switch debug on', default=False) |
35 |
parser.add_option('-n', '--new', action="store", |
36 |
help='output ESySXML file', |
37 |
dest='new_file_name', default='') |
38 |
def main(): |
39 |
(options, args) = parser.parse_args() |
40 |
if options.filename: |
41 |
filenames=list(options.filename) + args |
42 |
else: |
43 |
filenames=args |
44 |
if len(filenames)<1: |
45 |
parser.error("no input file.") |
46 |
|
47 |
files = [(file(arg), arg) for arg in filenames] |
48 |
for f, filename in files: |
49 |
xml = modelframe.ESySXMLParser(f.read(), debug=options.dbg) |
50 |
sims = xml.parse() |
51 |
for s in sims: |
52 |
if isinstance(s, modelframe.Simulation): |
53 |
if options.new_file_name: s.writeXML(file(options.new_file_name,'w')) |
54 |
s.run() |
55 |
|
56 |
if __name__=='__main__': |
57 |
main() |
58 |
|