/[ascend]/trunk/models/test/reverse_ad/modelgen.py
ViewVC logotype

Contents of /trunk/models/test/reverse_ad/modelgen.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2130 - (show annotations) (download) (as text)
Fri Dec 18 01:32:28 2009 UTC (10 years, 6 months ago) by mahesh
File MIME type: text/x-python
File size: 1942 byte(s)
Merging all changes from Mahesh's GSOC project.
svn merge -r2273:2671 svn://ascend.cheme.cmu.edu/ascend/code/branches/mahesh .
See http://ascendwiki.cheme.cmu.edu/User:Mnm87 for details.
1 #!/usr/bin/env python
2 # ASCEND modelling environment
3 # Copyright (C) 2006, 2007 Carnegie Mellon University
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19
20 # This script generates a model file that includes all the models under
21 # models/test/ipopt which is later used for second derivative calculations
22
23 import os, sys, glob
24
25 dirname = '../ipopt/'
26 files = glob.glob(dirname+'*.a4c')
27
28 try:
29
30 #Clearing already existing file
31 fout = open('allmodels.a4c','w')
32 fout.close()
33 #Creating new model file
34 fout = open('allmodels.a4c','a')
35 for modelfile in sorted(files):
36 fin = open(modelfile,'r')
37 contents = fin.read()
38 fout.write(contents+'\r\n')
39 fin.close()
40 fout.write('MODEL allmodels;\r\n')
41 i=1
42 for modelfile in sorted(files):
43 (filepath,filewithext) = os.path.split(modelfile)
44 (filename,ext) = os.path.splitext(filewithext)
45 fout.write('\tm'+str(i)+' IS_A '+ filename + ';\r\n')
46 i=i+1
47 fout.write('METHODS\r\n')
48 fout.write('METHOD on_load;\r\n')
49 i=1
50 for modelfile in sorted(files):
51 fout.write('\tRUN m'+str(i)+'.on_load;\r\n')
52 i=i+1
53 fout.write('END on_load;\r\nEND allmodels;\r\n')
54 fout.close()
55 except IOError:
56 print "Error Creating Super-Model file"
57
58
59

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22