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