2014-01-11 18:16:30 +05:30
|
|
|
#!/usr/bin/env python
|
2014-01-14 02:47:28 +05:30
|
|
|
import os,re,sys,string,subprocess
|
|
|
|
|
|
|
|
from optparse import OptionParser, Option
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
class extendableOption(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)
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
########################################################
|
|
|
|
# MAIN
|
|
|
|
########################################################
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
parser = OptionParser(option_class=extendableOption, usage='%prog options', description = """
|
|
|
|
Sets up the pre and post processing tools of DAMASK
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
""" + string.replace('$Id$','\n','\\n')
|
|
|
|
)
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
compilers = ['ifort','gfortran']
|
2014-01-14 19:42:35 +05:30
|
|
|
blastypes = ['LAPACK','ACML','IMKL']
|
2014-01-11 19:58:07 +05:30
|
|
|
|
2014-01-14 19:42:35 +05:30
|
|
|
parser.add_option('--with-fc', dest='compiler', type='string',
|
|
|
|
help='F90 compiler [%default]')
|
|
|
|
parser.add_option('--with-marc-dir', dest='marcdir', type='string',
|
|
|
|
help='root directory of MSC.Marc [%default]')
|
|
|
|
parser.add_option('--with-fftw-dir', dest='fftwdir', type='string',
|
|
|
|
help='root directory of FFTW [%default]')
|
|
|
|
parser.add_option('--with-blas-lapack-dir', dest='blasdir', type='string',
|
|
|
|
help='root directory of LAPACK [%default]')
|
|
|
|
parser.add_option('--with-blas-type', dest='blastype', type='string',
|
|
|
|
help='type of BLAS/LAPACK library [%default]')
|
2014-01-15 00:33:41 +05:30
|
|
|
parser.add_option('--with-spectral-options', dest='spectraloptions', type='string', action='extend',
|
|
|
|
help='options for spectral solver %default')
|
2014-01-11 19:58:07 +05:30
|
|
|
|
2014-01-14 02:47:28 +05:30
|
|
|
compiler = os.getenv('F90')
|
|
|
|
if compiler == None: compiler ={True:'ifort',False:'gfortran'}[\
|
|
|
|
subprocess.call(['which', 'ifort'],\
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0]
|
2014-01-14 19:42:35 +05:30
|
|
|
parser.set_defaults(compiler = compiler)
|
|
|
|
parser.set_defaults(blastype = 'LAPACK')
|
2014-01-15 00:33:41 +05:30
|
|
|
parser.set_defaults(fftwdir = '/usr/local')
|
|
|
|
parser.set_defaults(blasdir = '/usr')
|
|
|
|
parser.set_defaults(marcdir = '/msc')
|
|
|
|
parser.set_defaults(spectraloptions = [])
|
2014-01-14 19:42:35 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2014-01-14 19:42:35 +05:30
|
|
|
|
|
|
|
options.blastype = options.blastype.upper()
|
|
|
|
options.compiler = options.compiler.lower()
|
|
|
|
|
2014-01-14 02:47:28 +05:30
|
|
|
if options.blastype not in blastypes: print('Unknown BLAS type selected')
|
|
|
|
if options.compiler not in compilers: print('Unknown compiler type selected')
|
2014-01-11 19:58:07 +05:30
|
|
|
|
2014-01-14 19:42:35 +05:30
|
|
|
output = []
|
|
|
|
with open('installation/options','r') as f:
|
|
|
|
for line in f:
|
|
|
|
items = re.split('[= ]',line)
|
|
|
|
|
|
|
|
if items[0] == 'F90': line = '%s=%s\n'%(items[0],options.compiler)
|
2014-01-17 02:48:11 +05:30
|
|
|
if items[0] == 'FFTW_ROOT': line = '%s=%s\n'%(items[0],options.fftwdir.rstrip('/'))
|
|
|
|
if items[0] == 'MSC_ROOT': line = '%s=%s\n'%(items[0],options.marcdir.rstrip('/'))
|
2014-01-15 00:33:41 +05:30
|
|
|
for blastype in blastypes:
|
2014-01-15 01:02:55 +05:30
|
|
|
if options.blastype == blastype and items[0] == '%s_ROOT'%blastype:
|
2014-01-17 02:48:11 +05:30
|
|
|
line = '%s=%s\n'%(items[0],options.blasdir.rstrip('/'))
|
2014-01-15 00:33:41 +05:30
|
|
|
for spectralOption in options.spectraloptions:
|
|
|
|
[key,value] = re.split('[= ]',spectralOption)[0:2]
|
|
|
|
if key == items[0]:
|
|
|
|
line = '%s=%s\n'%(items[0],value)
|
|
|
|
options.spectraloptions.remove(spectralOption)
|
2014-01-14 19:42:35 +05:30
|
|
|
|
|
|
|
output.append(line)
|
2014-01-15 00:33:41 +05:30
|
|
|
for spectralOption in options.spectraloptions:
|
|
|
|
output.append(spectralOption+'\n')
|
2014-01-14 19:42:35 +05:30
|
|
|
|
|
|
|
with open('installation/options','w') as f:
|
|
|
|
for line in output:
|
|
|
|
f.write(line)
|