2009-03-23 21:38:17 +05:30
|
|
|
#!/usr/bin/env python
|
2013-01-24 20:15:23 +05:30
|
|
|
import os,string,re
|
|
|
|
import damask
|
2012-06-13 19:12:00 +05:30
|
|
|
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', \
|
2012-07-03 19:27:05 +05:30
|
|
|
help='compiles the spectral solver [%default]')
|
2012-11-13 22:56:25 +05:30
|
|
|
parser.add_option('-o', '--options', dest='makeOptions', action='extend', type='string', \
|
2012-07-03 19:27:05 +05:30
|
|
|
metavar="KEY=VALUE", \
|
|
|
|
help='comma-separated list of options passed to Makefile when compiling spectral code %default')
|
2012-06-13 19:12:00 +05:30
|
|
|
parser.set_defaults(spectralCompile = False)
|
2012-07-03 19:27:05 +05:30
|
|
|
parser.set_defaults(makeOptions = ['F90=ifort'])
|
2012-06-13 19:12:00 +05:30
|
|
|
|
|
|
|
(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-11-14 15:27:18 +05:30
|
|
|
'versions' : ['%%MARCVERSION%%','2010','2011','2012'],
|
2009-03-23 21:38:17 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2011-12-07 00:08:03 +05:30
|
|
|
bin_link = { \
|
2012-11-14 15:10:45 +05:30
|
|
|
'.' : [
|
|
|
|
'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:
|
2012-11-14 15:10:45 +05:30
|
|
|
me = architectures[arch]
|
|
|
|
try:
|
|
|
|
parentFile = open(baseDir+os.sep+me['parent'])
|
|
|
|
parentContent = parentFile.readlines()
|
|
|
|
parentFile.close()
|
|
|
|
except IOError:
|
|
|
|
print 'unable to open',me['parent']
|
|
|
|
continue
|
2009-03-23 21:38:17 +05:30
|
|
|
|
2012-11-14 15:10:45 +05:30
|
|
|
|
|
|
|
for version in me['versions'][1:]:
|
|
|
|
childFile = open(baseDir+os.sep+version.join(os.path.splitext(me['parent'])),'w')
|
|
|
|
for line in parentContent:
|
|
|
|
childFile.write(line.replace(me['versions'][0],version))
|
|
|
|
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:
|
2012-11-14 00:42:00 +05:30
|
|
|
m = re.match(r'(FFTW|IMKL|ACML|LAPACK)ROOT\s*\?=',line)
|
2011-12-20 16:28:51 +05:30
|
|
|
if m:
|
|
|
|
if m.group(1).lower() in damaskEnv.pathInfo:
|
|
|
|
substitution = damaskEnv.pathInfo[m.group(1).lower()]
|
|
|
|
else:
|
|
|
|
substitution = ''
|
2012-11-14 00:42:00 +05:30
|
|
|
line = '%sROOT ?= %s\n'%(m.group(1),substitution)
|
2011-12-20 16:28:51 +05:30
|
|
|
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-07-03 19:27:05 +05:30
|
|
|
os.system('make --directory %s %s'%(baseDir,' '.join(options.makeOptions)))
|
2011-12-07 00:08:03 +05:30
|
|
|
|
2012-11-14 15:10:45 +05:30
|
|
|
# processing symbolic linking list
|
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))
|
2012-11-14 15:10:45 +05:30
|
|
|
if os.path.exists(src):
|
|
|
|
sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),\
|
|
|
|
{True: dir,
|
|
|
|
False:os.path.splitext(file)[0]}[file == '']))
|
|
|
|
if os.path.lexists(sym_link): os.remove(sym_link)
|
|
|
|
os.symlink(src,sym_link)
|
|
|
|
print sym_link,'-->',src
|