/[escript]/temp/escript/py_src/runmodel.py
ViewVC logotype

Diff of /temp/escript/py_src/runmodel.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.269  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26