2009-03-23 21:38:17 +05:30
|
|
|
#!/usr/bin/env python
|
2012-06-13 19:12:00 +05:30
|
|
|
import os,string,re,damask
|
|
|
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
class extendedOption(Option):
|
|
|
|
# -----------------------------
|
|
|
|
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
|
|
|
# taken from online tutorial http://docs.python.org/library/optparse.html
|
|
|
|
|
|
|
|
ACTIONS = Option.ACTIONS + ("extend",)
|
|
|
|
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
|
|
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
|
|
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
|
|
|
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
|
|
if action == "extend":
|
|
|
|
lvalue = value.split(",")
|
|
|
|
values.ensure_value(dest, []).extend(lvalue)
|
|
|
|
else:
|
|
|
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
|
|
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """
|
|
|
|
Writes version specific files for different MARC releases, adjustes the make file for the spectral solver and optionally compiles the spectral solver
|
|
|
|
|
|
|
|
""" + string.replace('$Id$','\n','\\n')
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_option('-c', '--compile', dest='spectralCompile', action='store_true', \
|
|
|
|
help='compiles sthe spectral solver [%default]')
|
|
|
|
parser.add_option('-m', '--make', dest='makeOptions', type='string', \
|
|
|
|
help='options parsed to make file when compiling spectral code [%default]')
|
|
|
|
parser.set_defaults(spectralCompile = False)
|
|
|
|
parser.set_defaults(makeOptions = 'F90=ifort')
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
2009-03-23 21:38:17 +05:30
|
|
|
|
|
|
|
architectures = {
|
|
|
|
'marc': {
|
2011-05-11 22:10:51 +05:30
|
|
|
'parent': 'DAMASK_marc.f90',
|
2012-06-13 13:00:27 +05:30
|
|
|
'versions' : ['%%MARCVERSION%%','2007r1','2008r1','2010','2011','2012'],
|
2009-03-23 21:38:17 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2011-12-07 00:08:03 +05:30
|
|
|
bin_link = { \
|
|
|
|
'' : [
|
|
|
|
'DAMASK_spectral.exe',
|
|
|
|
],
|
|
|
|
}
|
2011-12-09 20:43:27 +05:30
|
|
|
|
2011-12-15 14:22:41 +05:30
|
|
|
damaskEnv = damask.Environment('../../') # script location relative to root
|
|
|
|
baseDir = damaskEnv.relPath('code/')
|
2011-03-11 14:50:37 +05:30
|
|
|
|
2009-03-23 21:38:17 +05:30
|
|
|
for arch in architectures:
|
2009-08-26 12:58:43 +05:30
|
|
|
me = architectures[arch]
|
2009-03-23 21:38:17 +05:30
|
|
|
try:
|
2011-12-09 20:43:27 +05:30
|
|
|
parentFile = open(baseDir+os.sep+me['parent'])
|
2009-03-23 21:38:17 +05:30
|
|
|
parentContent = parentFile.readlines()
|
|
|
|
parentFile.close()
|
|
|
|
except IOError:
|
2009-08-26 12:58:43 +05:30
|
|
|
print 'unable to open',me['parent']
|
2009-03-23 21:38:17 +05:30
|
|
|
continue
|
|
|
|
|
2009-08-26 12:58:43 +05:30
|
|
|
|
|
|
|
for version in me['versions'][1:]:
|
2011-12-09 20:43:27 +05:30
|
|
|
childFile = open(baseDir+os.sep+version.join(os.path.splitext(me['parent'])),'w')
|
2009-03-23 21:38:17 +05:30
|
|
|
for line in parentContent:
|
2009-08-26 12:58:43 +05:30
|
|
|
childFile.write(line.replace(me['versions'][0],version))
|
2009-03-23 21:38:17 +05:30
|
|
|
childFile.close()
|
2011-05-11 22:15:37 +05:30
|
|
|
|
2011-12-16 14:41:03 +05:30
|
|
|
# changing dirs in makefile
|
2012-03-14 17:28:05 +05:30
|
|
|
makefile = open(os.path.join(baseDir,'Makefile'))
|
2011-12-06 22:28:17 +05:30
|
|
|
content = makefile.readlines()
|
|
|
|
makefile.close()
|
2012-03-14 17:28:05 +05:30
|
|
|
makefile = open(os.path.join(baseDir,'Makefile'),'w')
|
2011-12-06 22:28:17 +05:30
|
|
|
for line in content:
|
2011-12-20 16:28:51 +05:30
|
|
|
m = re.match(r'(FFTW|IKML|ACML|LAPACK)ROOT\s*:?=',line)
|
|
|
|
if m:
|
|
|
|
if m.group(1).lower() in damaskEnv.pathInfo:
|
|
|
|
substitution = damaskEnv.pathInfo[m.group(1).lower()]
|
|
|
|
else:
|
|
|
|
substitution = ''
|
|
|
|
line = '%sROOT := %s\n'%(m.group(1),substitution)
|
|
|
|
makefile.write(line)
|
2011-12-06 22:28:17 +05:30
|
|
|
makefile.close()
|
|
|
|
|
|
|
|
# compiling spectral code
|
2012-06-13 19:12:00 +05:30
|
|
|
if (options.spectralCompile):
|
2011-12-09 20:43:27 +05:30
|
|
|
os.system('make --directory %s clean'%(baseDir))
|
2012-06-13 19:12:00 +05:30
|
|
|
os.system('make --directory %s %s'%(baseDir,options.makeOptions))
|
2011-12-07 00:08:03 +05:30
|
|
|
|
|
|
|
for dir in bin_link:
|
|
|
|
for file in bin_link[dir]:
|
|
|
|
src = os.path.abspath(os.path.join(baseDir,dir,file))
|
|
|
|
if (file == ''):
|
2011-12-15 14:22:41 +05:30
|
|
|
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),dir))
|
2011-12-07 00:08:03 +05:30
|
|
|
else:
|
2011-12-15 14:22:41 +05:30
|
|
|
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),os.path.splitext(file)[0]))
|
2011-12-07 00:08:03 +05:30
|
|
|
print sym_link,'-->',src
|
|
|
|
if os.path.lexists(sym_link):
|
|
|
|
os.remove(sym_link)
|
|
|
|
os.symlink(src,sym_link)
|