Exemplo n.º 1
0
def configuration(parent_package='', top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound

    compiler = get_default_fcompiler()
    # set some fortran compiler-dependent flags
    f90flags = []
    if compiler == 'gnu95':
        f90flags.append('-fdefault-real-8')
    elif compiler == 'intel' or compiler == 'intelem':
        f90flags.append('-132')
        f90flags.append('-r8')
    #  Set aggressive optimization level
    f90flags.append('-O3')
    #  Suppress all compiler warnings (avoid huge CI log files)
    f90flags.append('-w')
    config = Configuration('minimalf2py',
                           parent_name=parent_package,
                           top_path=top_path)
    config.add_subpackage('tests')
    config.add_extension(
        name='add',
        sources=['add.f', 'add.pyf'],
        extra_f90_compile_args=f90flags,
    )
    return config
Exemplo n.º 2
0
def configuration(parent_package='', top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound

    build = True
    try:
        # figure out which compiler we're going to use
        compiler = get_default_fcompiler()
        # set some fortran compiler-dependent flags
        f90flags = []
        if compiler == 'gnu95':
            f90flags.append('-fdefault-real-8')
        elif compiler == 'intel' or compiler == 'intelem':
            f90flags.append('-132')
            f90flags.append('-r8')
        #  Suppress all compiler warnings (avoid huge CI log files)
        f90flags.append('-w')
    except CompilerNotFound:
        print(
            'No Fortran compiler found, not building the CAM3 radiation module!'
        )
        build = False

    config = Configuration(package_name='cam3',
                           parent_name=parent_package,
                           top_path=top_path)
    config.add_data_files(join('data', 'abs_ems_factors_fastvx.c030508.nc'))
    if build:
        config.add_extension(name='_cam3',
                             sources=[cam3_gen_source],
                             extra_f90_compile_args=f90flags,
                             f2py_options=['--quiet'])
        config.add_include_dirs('src')
    return config
Exemplo n.º 3
0
def check_f2py_compiler():
    from numpy.distutils.fcompiler import get_default_fcompiler
    f2py_compiler = get_default_fcompiler()

    if 'gnu' not in f2py_compiler:
        print(' GNU compiler not installed. Checking f2py comompiler - this is UNTESTED' )
        print(' Speculatively setting flags - if compile fails, or OpenMP doesn\'t work install gfortran and retry')

    if 'gnu' in f2py_compiler:
        print('Found gnu compiler. Setting OpenMP flag to \'-fopenmp\'')
        compile_args = ['-fopenmp', '-lgomp', '-O3']
        link_args = ['-lgomp']
    elif 'intel' in f2py_compiler:
        print('Found intel compiler. Setting OpenMP flag to \'-openmp\'')
        compile_args = ['-openmp', '-O3']
        link_args = []
    elif 'pg' in f2py_comopiler:
        print('Found portland compiler. Setting OpenMP flag to \'-mp\'')
        compile_args = ['-mp', '-O3']
        link_args = []
    elif 'nag' in f2py_compiler:
        print('Found NAG compiler. Setting OpenMP flag to \'-openmp\'')
        compile_args = ['-openmp', '-O3']
        link_args = [] 
    else:   
        print('Not sure what compiler f2py uses. Speculatively setting OpenMP flag to \'-openmp\'')
        compile_args = ['-openmp', '-O3']
        link_args = [] 

    args = {'link_args':link_args,'compile_args':compile_args}

    return args
Exemplo n.º 4
0
def configuration(parent_package='', top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound

    build = True
    try:
        # figure out which compiler we're going to use
        compiler = get_default_fcompiler()
        # set some fortran compiler-dependent flags
        f90flags = []
        if compiler == 'gnu95':
            f90flags.append('-fno-range-check')
            f90flags.append('-ffree-form')
            f90flags.append('-fPIC')
        elif compiler == 'intel' or compiler == 'intelem':
            f90flags.append('-132')
        #  Need zero-level optimization to avoid build problems with rrtmg_lw_k_g.f90
        #f90flags.append('-O2')
        #  Suppress all compiler warnings (avoid huge CI log files)
        f90flags.append('-w')
    except CompilerNotFound:
        print('No Fortran compiler found, not building the RRTMG_LW radiation module!')
        build = False

    config = Configuration(package_name='_rrtmg_lw', parent_name=parent_package, top_path=top_path)
    if build:
        config.add_extension(
            name='_rrtmg_lw',
            sources=[rrtmg_lw_gen_source],
            extra_f90_compile_args=f90flags,
            f2py_options=['--quiet'],
        )

    return config
Exemplo n.º 5
0
def configuration(parent_package='', top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound

    build = True
    try:
        # figure out which compiler we're going to use
        compiler = get_default_fcompiler()
        # set some fortran compiler-dependent flags
        f90flags = []
        if compiler == 'gnu95':
            f90flags.append('-fno-range-check')
            f90flags.append('-ffree-form')
        elif compiler == 'intel' or compiler == 'intelem':
            f90flags.append('-132')
        #  Set aggressive optimization level
        f90flags.append('-O3')
        #  Suppress all compiler warnings (avoid huge CI log files)
        f90flags.append('-w')
    except CompilerNotFound:
        print('No Fortran compiler found, not building the RRTMG_LW radiation module!')
        build = False

    config = Configuration(package_name='_emanuel_convection', parent_name=parent_package, top_path=top_path)
    if build:
        config.add_extension(name='_emanuel_convection',
                             sources=[gen_source],
                             extra_f90_compile_args=f90flags,
                             f2py_options=['--quiet'],
                             )
    return config
Exemplo n.º 6
0
def get_fc():
    ''' get Fortran compiler '''
    fc = fcompiler.get_default_fcompiler()
    for i in range(len(sys.argv)):
        if '--fcompiler' in sys.argv[i]:
            fc = sys.argv.pop(i)
            fc = fc[fc.index('=') + 1:]
    return fc
Exemplo n.º 7
0
def configuration(parent_package='', top_path=None):
    """Configure all packages that need to be built."""
    config = Configuration('', parent_package, top_path)

    F95FLAGS = get_compiler_flags()

    kwargs = {}
    kwargs['extra_compile_args'] = F95FLAGS
    kwargs['f2py_options'] = ['--quiet']

    # numpy.distutils.fcompiler.FCompiler doesn't support .F95 extension
    compiler = FCompiler(get_default_fcompiler())
    compiler.src_extensions.append('.F95')
    compiler.language_map['.F95'] = 'f90'

    # collect all Fortran sources
    files = os.listdir('src')
    exclude_sources = ['PlanetsConstants.f95', 'PythonWrapper.f95']
    sources = [
        os.path.join('src', file) for file in files
        if file.lower().endswith('.f95') and file not in exclude_sources
    ]

    # (from http://stackoverflow.com/questions/14320220/
    #              testing-python-c-libraries-get-build-path)):
    build_lib_dir = "{dirname}.{platform}-{version[0]}.{version[1]}"
    dirparams = {
        'dirname': 'temp',
        'platform': sysconfig.get_platform(),
        'version': sys.version_info
    }
    libdir = os.path.join('build', build_lib_dir.format(**dirparams))
    print('searching SHTOOLS in:', libdir)

    # Fortran compilation
    config.add_library('SHTOOLS', sources=sources, **kwargs)

    # SHTOOLS
    config.add_extension(
        'pyshtools._SHTOOLS',
        include_dirs=[libdir],
        library_dirs=[libdir],
        libraries=['SHTOOLS', 'fftw3', 'm', 'lapack', 'blas'],
        sources=['src/pyshtools.pyf', 'src/PythonWrapper.f95'],
        **kwargs)

    # constants
    config.add_extension('pyshtools._constant',
                         sources=['src/PlanetsConstants.f95'],
                         **kwargs)

    return config
Exemplo n.º 8
0
def configuration(parent_package='', top_path=None):
    """Configure all packages that need to be built."""
    config = Configuration('', parent_package, top_path)

    F95FLAGS = get_compiler_flags()

    kwargs = {}
    kwargs['extra_compile_args'] = F95FLAGS
    kwargs['f2py_options'] = ['--quiet']

    # numpy.distutils.fcompiler.FCompiler doesn't support .F95 extension
    compiler = FCompiler(get_default_fcompiler())
    compiler.src_extensions.append('.F95')
    compiler.language_map['.F95'] = 'f90'

    # collect all Fortran sources
    files = os.listdir('src')
    exclude_sources = ['PlanetsConstants.f95', 'PythonWrapper.f95']
    sources = [os.path.join('src', file) for file in files if
               file.lower().endswith('.f95') and file not in exclude_sources]

    # (from http://stackoverflow.com/questions/14320220/
    #              testing-python-c-libraries-get-build-path)):
    build_lib_dir = "{dirname}.{platform}-{version[0]}.{version[1]}"
    dirparams = {'dirname': 'temp',
                 'platform': sysconfig.get_platform(),
                 'version': sys.version_info}
    libdir = os.path.join('build', build_lib_dir.format(**dirparams))
    print('searching SHTOOLS in:', libdir)

    # Fortran compilation
    config.add_library('SHTOOLS',
                       sources=sources,
                       **kwargs)

    # SHTOOLS
    config.add_extension('pyshtools._SHTOOLS',
                         include_dirs=[libdir],
                         library_dirs=[libdir],
                         libraries=['SHTOOLS', 'fftw3', 'm', 'lapack', 'blas'],
                         sources=['src/pyshtools.pyf',
                                  'src/PythonWrapper.f95'],
                         **kwargs)

    # constants
    config.add_extension('pyshtools._constant',
                         sources=['src/PlanetsConstants.f95'],
                         **kwargs)

    return config
Exemplo n.º 9
0
def check_f2py_compiler():
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound
    from numpy.distutils.fcompiler import CompilerNotFound
    f2py_compiler = get_default_fcompiler()

    if f2py_compiler == None:
        raise CompilerNotFound(
            'You don\'t have a Fortran compiler installed. Please install one and try again'
        )
        sys.exit()

    if 'gnu' not in f2py_compiler:
        print(
            ' GNU compiler not installed. Checking f2py compiler - this is UNTESTED'
        )
        print(
            ' Speculatively setting flags - if compile fails, or OpenMP doesn\'t work install gfortran and retry'
        )

    if 'gnu' in f2py_compiler:
        print('Found gnu compiler. Setting OpenMP flag to \'-fopenmp\'')
        compile_args = ['-fopenmp', '-lgomp', '-O3']
        link_args = ['-lgomp']
    elif f2py_compiler == 'intel':
        print('Found intel compiler. Setting OpenMP flag to \'-openmp\'')
        compile_args = ['-qopenmp', '-O3']
        link_args = []
    elif f2py_compiler == 'intelem':
        print('Found intel compiler. Setting OpenMP flag to \'-openmp\'')
        compile_args = ['-qopenmp', '-O3']
        link_args = []
    elif 'pg' in f2py_comopiler:
        print('Found portland compiler. Setting OpenMP flag to \'-mp\'')
        compile_args = ['-mp', '-O3']
        link_args = []
    elif 'nag' in f2py_compiler:
        print('Found NAG compiler. Setting OpenMP flag to \'-openmp\'')
        compile_args = ['-openmp', '-O3']
        link_args = []
    else:
        print(
            'Not sure what compiler f2py uses. Speculatively setting OpenMP flag to \'-openmp\''
        )
        compile_args = ['-openmp', '-O3']
        link_args = []

    args = {'link_args': link_args, 'compile_args': compile_args}

    return args
Exemplo n.º 10
0
def configuration(parent_package='', top_path=None):
    import os
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils import fcompiler

    # figure out which compiler we're going to use
    compiler = fcompiler.get_default_fcompiler()
    # set some fortran compiler-dependent flags
    f90flags = []
    if compiler == 'gnu95':
        f90flags.append('-fdefault-real-8')
    elif compiler == 'intel' or compiler == 'intelem':
        f90flags.append('-132')
        f90flags.append('-r8')
    #  Suppress all compiler warnings (avoid huge CI log files)
    f90flags.append('-w')

    sourcelist = ['_cam3.pyf',
                'src/pmgrid.F90',
                'src/prescribed_aerosols.F90',
                'src/quicksort.F90',
                'src/abortutils.F90',
                'src/shr_kind_mod.F90',
                'src/absems.F90',
                'src/wv_saturation.F90',
                'src/aer_optics.F90',
                'src/cmparray_mod.F90',
                'src/shr_const_mod.F90',
                'src/physconst.F90',
                'src/pkg_cldoptics.F90',
                'src/gffgch.F90',
                'src/chem_surfvals.F90',
                'src/volcrad.F90',
                'src/radae.F90',
                'src/radlw.F90',
                'src/radsw.F90',
                'src/crm.F90',
                'Driver.f90']

    config = Configuration(package_name='cam3', parent_name=parent_package, top_path=top_path)
    config.add_extension(name='_cam3',
                         sources=sourcelist,
                         extra_f90_compile_args=f90flags,
                         f2py_options=['--quiet'])
    config.add_include_dirs('src')
    config.add_data_files(os.path.join('data', 'abs_ems_factors_fastvx.c030508.nc'))
    return config
Exemplo n.º 11
0
def get_compiler_flags():
    """Set fortran flags depending on the compiler."""
    compiler = get_default_fcompiler()
    if compiler == 'absoft':
        flags = ['-m64', '-O3', '-YEXT_NAMES=LCS', '-YEXT_SFX=_',
                 '-fpic', '-speed_math=10']
    elif compiler == 'gnu95':
        flags = ['-m64', '-fPIC', '-O3', '-ffast-math']
    elif compiler == 'intel':
        flags = ['-m64', '-fpp', '-free', '-O3', '-Tf']
    elif compiler == 'g95':
        flags = ['-O3', '-fno-second-underscore']
    elif compiler == 'pg':
        flags = ['-fast']
    else:
        flags = ['-m64', '-O3']
    return flags
Exemplo n.º 12
0
def configuration(parent_package='', top_path=None):
    global config
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils.fcompiler import get_default_fcompiler, CompilerNotFound

    build = True
    try:
        # figure out which compiler we're going to use
        compiler = get_default_fcompiler()
        # set some fortran compiler-dependent flags
        f90flags = []
        if compiler == 'gnu95':
            f90flags.append('-fno-range-check')
            f90flags.append('-ffree-form')
        elif compiler == 'intel' or compiler == 'intelem':
            f90flags.append('-132')
        #  Need zero-level optimization to avoid build problems with rrtmg_sw_k_g.f90
        f90flags.append('-O0')
        #  Suppress all compiler warnings (avoid huge CI log files)
        f90flags.append('-w')
    except CompilerNotFound:
        print(
            'No Fortran compiler found, not building the RRTMG_SW radiation module!'
        )
        build = False

    config = Configuration(package_name='_rrtmg_sw',
                           parent_name=parent_package,
                           top_path=top_path)
    if build:
        config.add_extension(
            name='_rrtmg_sw',
            sources=[rrtmg_sw_gen_source],
            extra_f90_compile_args=f90flags,
            f2py_options=['--quiet'],
        )
    #  Not currently initializing from nc data file, so there's no reason to include it
    #config.add_data_files(join('rrtmg_sw_v4.0', 'gcm_model', 'data', 'rrtmg_sw.nc'))
    return config
Exemplo n.º 13
0
     'cppflags':'-DPLON=%i -DPLEV=%i' % (IM,KM)},
    {'name':'simple_turbulence',
     'dir':'src/turbulence/simple'},
    {'name':'rrtm_radiation_fortran',
     'dir':'src/radiation/rrtm'}
    ]

# define extensions that will be built when the --lite option is used
LiteExtensionsNames = ['grid','timestep','insolation','ozone','thermodyn','ccm3_radiation']
ExtensionsLite = []
for ext in Extensions:
    if ext['name'] in LiteExtensionsNames:
        ExtensionsLite.append(ext)

# figure out which compiler we're goint to use
compiler = fcompiler.get_default_fcompiler()
for i in range(len(sys.argv)):
    if '--fcompiler' in sys.argv[i]:
        compiler = sys.argv.pop(i)
        compiler = compiler[compiler.index('=')+1:]
print 'Using %s compiler' % compiler

# set some fortran compiler-dependent flags
if compiler == 'gnu95':
    f77flags='-ffixed-line-length-132 -fdefault-real-8'
    f90flags='-fdefault-real-8 -fno-range-check -ffree-form'
elif compiler == 'intel' or compiler == 'intelem':
    f77flags='-132 -r8'
    f90flags='-132 -r8'
elif compiler == 'ibm':
    f77flags='-qautodbl=dbl4 -qsuffix=f=f:cpp=F -qfixed=132'
Exemplo n.º 14
0
def get_options(args=None, get_parser=False):
    import optparse
    import os
    from glob import glob
    import kmos

    parser = optparse.OptionParser('Usage: %prog [help] (' +
                                   '|'.join(sorted(usage.keys())) +
                                   ') [options]',
                                   version=kmos.__version__)

    parser.add_option('-s',
                      '--source-only',
                      dest='source_only',
                      action='store_true',
                      default=False)

    parser.add_option('-p',
                      '--path-to-f2py',
                      dest='path_to_f2py',
                      default='f2py')

    parser.add_option('-b', '--backend', dest='backend', default='local_smart')
    parser.add_option(
        '-a',
        '--avoid-default-state',
        dest='avoid_default_state',
        action='store_true',
        default=False,
    )

    parser.add_option('-v',
                      '--steps-per-frame',
                      dest='steps_per_frame',
                      type='int',
                      default='50000')

    parser.add_option('-d',
                      '--debug',
                      default=False,
                      dest='debug',
                      action='store_true')

    parser.add_option('-n',
                      '--no-compiler-optimization',
                      default=False,
                      dest='no_optimize',
                      action='store_true')

    parser.add_option('-o', '--overwrite', default=False, action='store_true')

    parser.add_option('-l',
                      '--variable-length',
                      dest='variable_length',
                      default=95,
                      type='int')

    parser.add_option('-c', '--catmap', default=False, action='store_true')

    parser.add_option(
        '--acf',
        dest='acf',
        action='store_true',
        default=False,
    )

    try:
        from numpy.distutils.fcompiler import get_default_fcompiler
        from numpy.distutils import log
        log.set_verbosity(-1, True)
        fcompiler = get_default_fcompiler()
    except:
        fcompiler = 'gfortran'

    parser.add_option('-f',
                      '--fcompiler',
                      dest='fcompiler',
                      default=os.environ.get('F2PY_FCOMPILER', fcompiler))

    if args is not None:
        options, args = parser.parse_args(args.split())
    else:
        options, args = parser.parse_args()
    if len(args) < 1:
        parser.error('Command expected')
    if get_parser:
        return options, args, parser
    else:
        return options, args
Exemplo n.º 15
0
def get_options(args=None, get_parser=False):
    import optparse
    import os
    from glob import glob
    import kmos

    parser = optparse.OptionParser(
        'Usage: %prog [help] ('
        + '|'.join(sorted(usage.keys()))
        + ') [options]',
        version=kmos.__version__)

    parser.add_option('-s', '--source-only',
                      dest='source_only',
                      action='store_true',
                      default=False)

    parser.add_option('-p', '--path-to-f2py',
                      dest='path_to_f2py',
                      default='f2py')

    parser.add_option('-b', '--backend',
                      dest='backend',
                      default='local_smart')

    parser.add_option('-v', '--steps-per-frame',
                      dest='steps_per_frame',
                      type='int',
                      default='50000')

    parser.add_option('-d', '--debug',
                      default=False,
                      dest='debug',
                      action='store_true')
    parser.add_option('-n', '--no-compiler-optimization',
                      default=False,
                      dest='no_optimize',
                      action='store_true')

    try:
        from numpy.distutils.fcompiler import get_default_fcompiler
        from numpy.distutils import log
        log.set_verbosity(-1, True)
        fcompiler = get_default_fcompiler()
    except:
        fcompiler = 'gfortran'

    parser.add_option('-f', '--fcompiler',
                      dest='fcompiler',
                      default=os.environ.get('F2PY_FCOMPILER', fcompiler))

    if args is not None:
        options, args = parser.parse_args(args.split())
    else:
        options, args = parser.parse_args()
    if len(args) < 1:
        parser.error('Command expected')
    if get_parser:
        return options, args, parser
    else:
        return options, args
Exemplo n.º 16
0
def main(args=None):
    """The CLI main entry point function.

    The optional arguemnts args, can be used to
    directly supply command line argument like

    $ kmos <args>

    otherwise args will be taken from STDIN.

    """

    import optparse
    import os
    from glob import glob
    import kmos

    parser = optparse.OptionParser('Usage: %prog [help] (' +
                                   '|'.join(sorted(usage.keys())) +
                                   ') [options]',
                                   version=kmos.__version__)

    parser.add_option('-s',
                      '--source-only',
                      dest='source_only',
                      action='store_true',
                      default=False)

    parser.add_option('-p',
                      '--path-to-f2py',
                      dest='path_to_f2py',
                      default='f2py')

    try:
        from numpy.distutils.fcompiler import get_default_fcompiler
        from numpy.distutils import log
        log.set_verbosity(-1, True)
        fcompiler = get_default_fcompiler()
    except:
        fcompiler = 'gfortran'

    parser.add_option('-f',
                      '--fcompiler',
                      dest='fcompiler',
                      default=os.environ.get('F2PY_FCOMPILER', fcompiler))

    if args is not None:
        options, args = parser.parse_args(args.split())
    else:
        options, args = parser.parse_args()

    if len(args) < 1:
        parser.error('Command expected')

    if args[0] == 'benchmark':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        nsteps = 1000000
        from time import time
        from kmos.run import KMC_Model
        with KMC_Model(print_rates=False, banner=False) as model:
            time0 = time()
            model.do_steps(nsteps)
            needed_time = time() - time0
            print('%s steps took %.2f seconds' % (nsteps, needed_time))
            print('Or %.2e steps/s' % (1e6 / needed_time))
    elif args[0] == 'build':
        from kmos.utils import build
        build(options)
    elif args[0] == 'edit':
        from kmos import gui
        gui.main()
    elif args[0] == 'export-settings':
        import kmos.types
        import kmos.io
        from kmos.utils import build
        import shutil
        from kmos.io import ProcListWriter

        if len(args) < 2:
            parser.error('XML file and export path expected.')
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting to %s' % out_dir)
            args.append(out_dir)

        xml_file = args[1]
        export_dir = args[2]
        project = kmos.types.Project()
        project.import_xml_file(xml_file)

        writer = ProcListWriter(project, export_dir)
        writer.write_settings()

    elif args[0] == 'export':
        import kmos.types
        import kmos.io
        from kmos.utils import build
        import shutil
        if len(args) < 2:
            parser.error('XML file and export path expected.')
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting to %s' % out_dir)
            args.append(out_dir)

        xml_file = args[1]
        export_dir = os.path.join(args[2], 'src')

        project = kmos.types.Project()
        project.import_xml_file(xml_file)

        kmos.io.export_source(project, export_dir)

        if ((os.name == 'posix'
           and os.uname()[0] == 'Linux')
           or os.name == 'nt') \
           and not options.source_only:
            os.chdir(export_dir)
            build(options)
            for out in glob('kmc_*'):
                if os.path.exists('../%s' % out):
                    overwrite = raw_input(('Should I overwrite existing %s ?'
                                           '[y/N]  ') % out).lower()
                    if overwrite.startswith('y'):
                        os.remove('../%s' % out)
                        shutil.move(out, '..')
                else:
                    shutil.move(out, '..')

    elif args[0] == 'export-settings':
        import kmos.io
        pt = kmos.io.import_xml_file(args[1])
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting kmc_settings.py to %s' %
                  out_dir)
            args.append(out_dir)

        if not os.path.exists(args[2]):
            os.mkdir(args[2])
        elif not os.path.isdir(args[2]):
            raise UserWarning("Cannot overwrite %s; Exiting;" % args[2])
        writer = kmos.io.ProcListWriter(pt, args[2])
        writer.write_settings()

    elif args[0] == 'export-view':
        out_dir = os.path.splitext(args[1])[0]
        print('No export path provided. Exporting to %s' % out_dir)
        args.append(out_dir)
        os.system('kmos-export-program %s %s' % (args[1], args[2]))
        os.chdir(out_dir)
        main('view')

    elif args[0] == 'all':
        print('Interpreting: all -> help all\n\n')
        main('help all')
    elif args[0] == 'help':
        if len(args) < 2:
            parser.error('Which help do you  want?')
        if args[1] == 'all':
            for command in sorted(usage):
                print(usage[command])
        elif args[1] in usage:
            print('Usage: %s\n' % usage[args[1]])
        else:
            raise Exception('Command "%s" not known or not documented.' %
                            args[1])

    elif args[0] == 'import':
        import kmos.io
        if not len(args) >= 2:
            raise UserWarning('XML file name expected.')
        global pt
        pt = kmos.io.import_xml_file(args[1])
        sh(banner='Note: pt = kmos.io.import_xml(\'%s\')' % args[1])

    elif args[0] == 'rebuild':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from tempfile import mktemp
        if not os.path.exists('kmc_model.so') \
           and not os.path.exists('kmc_model.pyd'):
            raise Exception('No kmc_model.so found.')
        if not os.path.exists('kmc_settings.py'):
            raise Exception('No kmc_settings.py found.')

        from kmos.run import KMC_Model

        with KMC_Model(print_rates=False, banner=False) as model:
            tempfile = mktemp()
            f = file(tempfile, 'w')
            f.write(model.xml())
            f.close()

            for kmc_model in glob('kmc_model.*'):
                os.remove(kmc_model)
            os.remove('kmc_settings.py')
            main('export %s .' % tempfile)
            os.remove(tempfile)

    elif args[0] == 'run':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from kmos.run import KMC_Model

        with KMC_Model(print_rates=False) as model:
            global model
            sh(banner='Note: model = KMC_Model(print_rates=False)')

    elif args[0] == 'view':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from kmos import view
        view.main()

    else:
        parser.error('Command "%s" not understood.' % args[0])
Exemplo n.º 17
0
from numpy.distutils.fcompiler import get_default_fcompiler
import sys
import os

fcompile = get_default_fcompiler(os.name,sys.platform,True)

install_dir = sys.argv[1]

os.system("python setup.py config_fc --fcompiler="+str(fcompile)+" build_clib --fcompiler="+str(fcompile)+" build_ext --fcompiler="+str(fcompile)+" install --prefix='"+str(install_dir)+"'")
Exemplo n.º 18
0
    direct = os.path.dirname(direct)
    if base=='lib' or base=='lib64':
        root = direct
        if 'bin' in os.listdir(root):
            f2py_exec_path = os.path.join(root,'bin')
            if 'f2py' in os.listdir(f2py_exec_path):
                f2py_bin = os.path.join(f2py_exec_path,'f2py')
                break

Extensions = [
    {'name':'disort',
     'dir':'src/disort'},
    ]

# figure out which compiler we're goint to use
compiler = fcompiler.get_default_fcompiler(requiref90=True)
compiler = 'gnu95'  # ensure gfortran
for i in range(len(sys.argv)):
    if '--fcompiler' in sys.argv[i]:
        compiler = sys.argv.pop(i)
        compiler = compiler[compiler.index('=')+1:]
print 'Using %s compiler' % compiler

# set some fortran compiler-dependent flags
if compiler == 'gnu95' or compiler == 'gnu':
    # f77flags='-ffixed-line-length-132 -fdefault-real-8'
    # f90flags='-fdefault-real-8'
    f77flags='-O3'
    f90flags='-O3'
elif compiler == 'intel' or compiler == 'intelem':
    f77flags='-132 -r8 -w95 -w90 -mp'
Exemplo n.º 19
0
def configuration(parent_package='', top_path=None):
    import os
    from numpy.distutils.misc_util import Configuration
    from numpy.distutils import fcompiler

    # figure out which compiler we're going to use
    compiler = fcompiler.get_default_fcompiler()
    # set some fortran compiler-dependent flags
    f90flags = []
    if compiler == 'gnu95':
        f90flags.append('-fno-range-check')
        f90flags.append('-ffree-form')
    elif compiler == 'intel' or compiler == 'intelem':
        f90flags.append('-132')
    #  Need zero-level optimization to avoid build problems with rrtmg_sw_k_g.f90
    f90flags.append('-O0')
    #  Suppress all compiler warnings (avoid huge CI log files)
    f90flags.append('-w')

    sourcelist = ['_rrtmg_sw.pyf',
                  'rrtmg_sw_v4.0/gcm_model/modules/parkind.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/parrrsw.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_aer.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_cld.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_con.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg16.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg17.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg18.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg19.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg20.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg21.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg22.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg23.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg24.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg25.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg26.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg27.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg28.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_kg29.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_ncpar.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_k_g.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_ref.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_tbl.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_vsn.f90',
                  'rrtmg_sw_v4.0/gcm_model/modules/rrsw_wvn.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/mcica_random_numbers.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/mcica_subcol_gen_sw.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_vrtqdr.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_reftra.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_taumol.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_spcvmc.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_setcoef.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_init.f90',
                  'rrtmg_sw_v4.0/gcm_model/src/rrtmg_sw_cldprmc.f90',
                  'sourcemods/rrtmg_sw_rad.f90',
                  'Driver.f90']

    config = Configuration(package_name='_rrtmg_sw', parent_name=parent_package, top_path=top_path)
    config.add_extension(name='_rrtmg_sw',
                         sources=sourcelist,
                         extra_f90_compile_args=f90flags,
                        f2py_options=['--quiet'],
                        )
    #  Not currently initializing from nc data file, so there's no reason to include it
    #config.add_data_files(os.path.join('rrtmg_sw_v4.0', 'gcm_model', 'data', 'rrtmg_sw.nc'))

    return config
Exemplo n.º 20
0
Arquivo: cli.py Projeto: lulzzz/kmos
def main(args=None):
    """The CLI main entry point function.

    The optional arguemnts args, can be used to
    directly supply command line argument like

    $ kmos <args>

    otherwise args will be taken from STDIN.

    """

    import optparse
    import os
    from glob import glob
    import kmos

    parser = optparse.OptionParser(
        'Usage: %prog [help] ('
        + '|'.join(sorted(usage.keys()))
        + ') [options]',
        version=kmos.__version__)

    parser.add_option('-s', '--source-only',
                      dest='source_only',
                      action='store_true',
                      default=False)

    parser.add_option('-p', '--path-to-f2py',
                      dest='path_to_f2py',
                      default='f2py')

    try:
        from numpy.distutils.fcompiler import get_default_fcompiler
        from numpy.distutils import log
        log.set_verbosity(-1, True)
        fcompiler = get_default_fcompiler()
    except:
        fcompiler = 'gfortran'

    parser.add_option('-f', '--fcompiler',
                     dest='fcompiler',
                     default=os.environ.get('F2PY_FCOMPILER', fcompiler ))

    if args is not None:
        options, args = parser.parse_args(args.split())
    else:
        options, args = parser.parse_args()

    if len(args) < 1:
        parser.error('Command expected')

    if args[0] == 'benchmark':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        nsteps = 1000000
        from time import time
        from kmos.run import KMC_Model
        with KMC_Model(print_rates=False, banner=False) as model:
            time0 = time()
            model.do_steps(nsteps)
            needed_time = time() - time0
            print('%s steps took %.2f seconds' % (nsteps, needed_time))
            print('Or %.2e steps/s' % (1e6 / needed_time))
    elif args[0] == 'build':
        from kmos.utils import build
        build(options)
    elif args[0] == 'edit':
        from kmos import gui
        gui.main()
    elif args[0] == 'export-settings':
        import kmos.types
        import kmos.io
        from kmos.utils import build
        import shutil
        from kmos.io import ProcListWriter

        if len(args) < 2:
            parser.error('XML file and export path expected.')
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting to %s' % out_dir)
            args.append(out_dir)

        xml_file = args[1]
        export_dir = args[2]
        project = kmos.types.Project()
        project.import_xml_file(xml_file)

        writer = ProcListWriter(project, export_dir)
        writer.write_settings()

    elif args[0] == 'export':
        import kmos.types
        import kmos.io
        from kmos.utils import build
        import shutil
        if len(args) < 2:
            parser.error('XML file and export path expected.')
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting to %s' % out_dir)
            args.append(out_dir)

        xml_file = args[1]
        export_dir = os.path.join(args[2], 'src')

        project = kmos.types.Project()
        project.import_xml_file(xml_file)

        kmos.io.export_source(project, export_dir)

        if ((os.name == 'posix'
           and os.uname()[0] == 'Linux')
           or os.name == 'nt') \
           and not options.source_only:
            os.chdir(export_dir)
            build(options)
            for out in glob('kmc_*'):
                if os.path.exists('../%s' % out):
                    overwrite = raw_input(('Should I overwrite existing %s ?'
                                           '[y/N]  ') % out).lower()
                    if overwrite.startswith('y'):
                        os.remove('../%s' % out)
                        shutil.move(out, '..')
                else:
                    shutil.move(out, '..')

    elif args[0] == 'export-settings':
        import kmos.io
        pt = kmos.io.import_xml_file(args[1])
        if len(args) < 3:
            out_dir = os.path.splitext(args[1])[0]
            print('No export path provided. Exporting kmc_settings.py to %s'
                   % out_dir)
            args.append(out_dir)

        if not os.path.exists(args[2]):
            os.mkdir(args[2])
        elif not os.path.isdir(args[2]):
            raise UserWarning("Cannot overwrite %s; Exiting;" % args[2])
        writer = kmos.io.ProcListWriter(pt, args[2])
        writer.write_settings()

    elif args[0] == 'export-view':
        out_dir = os.path.splitext(args[1])[0]
        print('No export path provided. Exporting to %s' % out_dir)
        args.append(out_dir)
        os.system('kmos-export-program %s %s' % (args[1], args[2]))
        os.chdir(out_dir)
        main('view')

    elif args[0] == 'all':
        print('Interpreting: all -> help all\n\n')
        main('help all')
    elif args[0] == 'help':
        if len(args) < 2:
            parser.error('Which help do you  want?')
        if args[1] == 'all':
            for command in sorted(usage):
                print(usage[command])
        elif args[1] in usage:
            print('Usage: %s\n' % usage[args[1]])
        else:
            raise Exception('Command "%s" not known or not documented.'
                            % args[1])

    elif args[0] == 'import':
        import kmos.io
        if not len(args) >= 2:
            raise UserWarning('XML file name expected.')
        global pt
        pt = kmos.io.import_xml_file(args[1])
        sh(banner='Note: pt = kmos.io.import_xml(\'%s\')' % args[1])

    elif args[0] == 'rebuild':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from tempfile import mktemp
        if not os.path.exists('kmc_model.so') \
           and not os.path.exists('kmc_model.pyd'):
            raise Exception('No kmc_model.so found.')
        if not os.path.exists('kmc_settings.py'):
            raise Exception('No kmc_settings.py found.')

        from kmos.run import KMC_Model

        with KMC_Model(print_rates=False, banner=False) as model:
            tempfile = mktemp()
            f = file(tempfile, 'w')
            f.write(model.xml())
            f.close()

            for kmc_model in glob('kmc_model.*'):
                os.remove(kmc_model)
            os.remove('kmc_settings.py')
            main('export %s .' % tempfile)
            os.remove(tempfile)

    elif args[0] == 'run':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from kmos.run import KMC_Model

        with KMC_Model(print_rates=False) as model:
            global model
            sh(banner='Note: model = KMC_Model(print_rates=False)')

    elif args[0] == 'view':
        from sys import path
        path.append(os.path.abspath(os.curdir))
        from kmos import view
        view.main()

    else:
        parser.error('Command "%s" not understood.' % args[0])
Exemplo n.º 21
0
def configuration(parent_package='', top_path=None):
    """Configure all packages that need to be built."""
    config = Configuration('', parent_package, top_path)

    kwargs = {'libraries': [], 'include_dirs': [], 'library_dirs': []}

    # numpy.distutils.fcompiler.FCompiler doesn't support .F95 extension
    compiler = FCompiler(get_default_fcompiler())
    compiler.src_extensions.append('.F95')
    compiler.language_map['.F95'] = 'f90'

    # collect all Fortran sources
    files = os.listdir('src')
    exclude_sources = ['PlanetsConstants.f95', 'PythonWrapper.f95']
    sources = [
        os.path.join('src', file) for file in files
        if file.lower().endswith(('.f95',
                                  '.c')) and file not in exclude_sources
    ]

    # (from http://stackoverflow.com/questions/14320220/
    #              testing-python-c-libraries-get-build-path)):
    build_lib_dir = "{dirname}.{platform}-{version[0]}.{version[1]}"
    dirparams = {
        'dirname': 'temp',
        'platform': sysconfig.get_platform(),
        'version': sys.version_info
    }
    libdir = os.path.join('build', build_lib_dir.format(**dirparams))
    print('searching SHTOOLS in:', libdir)

    # Fortran compilation
    config.add_library('SHTOOLS', sources=sources)

    # SHTOOLS
    kwargs['libraries'].extend(['SHTOOLS'])
    kwargs['include_dirs'].extend([libdir])
    kwargs['library_dirs'].extend([libdir])
    kwargs['f2py_options'] = ['--quiet']

    # FFTW info
    fftw_info = get_info('fftw', notfound_action=2)
    dict_append(kwargs, **fftw_info)

    if sys.platform != 'win32':
        kwargs['libraries'].extend(['m'])

    # BLAS / Lapack info
    lapack_info = get_info('lapack_opt', notfound_action=2)
    blas_info = get_info('blas_opt', notfound_action=2)
    dict_append(kwargs, **blas_info)
    dict_append(kwargs, **lapack_info)

    if sys.platform == 'win32':
        kwargs['runtime_library_dirs'] = []

    config.add_extension(
        'pyshtools._SHTOOLS',
        sources=['src/pyshtools.pyf', 'src/PythonWrapper.f95'],
        **kwargs)

    return config
Exemplo n.º 22
0
def _build_extension(KM,JM,IM):
    name = 'cam3_radiation'
    #  Temporarily move to the source directory
    here = os.getcwd()
    pydir = os.path.dirname(os.path.abspath(__file__))
    srcdir = pydir + '/src/cam3'
    #  need to change to srcdir so f2py sees the .f2py_f2cmap file
    os.chdir(srcdir)
    srcdir = os.getcwd()
    # figure out which compiler we're goint to use
    compiler = fcompiler.get_default_fcompiler()
    # set some fortran compiler-dependent flags
    if compiler == 'gnu95':
        f77flags='-ffixed-line-length-132 -fdefault-real-8'
        f90flags='-fdefault-real-8 -fno-range-check -ffree-form'
    elif compiler == 'intel' or compiler == 'intelem':
        f77flags='-132 -r8'
        f90flags='-132 -r8'
    elif compiler == 'ibm':
        f77flags='-qautodbl=dbl4 -qsuffix=f=f:cpp=F -qfixed=132'
        f90flags='-qautodbl=dbl4 -qsuffix=f=f90:cpp=F90 -qfree=f90'
    else:
        print 'Sorry, compiler %s not supported' % compiler

    #cppflags = '-DPLEV=%i -DIM=%i -DJM=%i -DKM=%i' % (KM,IM,JM,KM)
    # only the vertical dimension needs to be set by pre-processor
    cppflags = '-DPLEV=%i' %KM

    src = getSources(srcdir)
    target = '_%s.so' % name
    #target = '_cam3_radiation.so'
    driver = glob.glob(os.path.join(srcdir,'Driver.f*'))[0]
    f77flags = '"%s %s"' % (cppflags,f77flags)
    f90flags = '"%s %s"' % (cppflags,f90flags)
    if buildNeeded(src, KM):
    #if True:
        print '\n Building %s ... \n' % os.path.basename(target)
        # generate signature file
        if os.path.exists(os.path.join(srcdir, 'sources_signature_file')):
            src_pyf = getSources(srcdir, source_file_name='sources_signature_file')
            src_pyf_str = string.join(src_pyf)
        else:
            src_pyf_str = driver
        subprocess.call('f2py --quiet --overwrite-signature %s -m _%s -h _%s.pyf'%(src_pyf_str,name,name), shell=True)

        # compile extension
        F2pyCommand = []
        F2pyCommand.append('f2py -c -m _%s' % name)
        F2pyCommand.append('--fcompiler=%s --noopt' % compiler)
        #F2pyCommand.append('-I%s' % dir)
        #F2pyCommand.append('-I%s' % os.path.join(dir,'include'))
        F2pyCommand.append('-I%s' % os.path.join(srcdir,'src'))
        #F2pyCommand.append('-I%s' % os.path.join(dir,'src','include'))
        F2pyCommand.append('--f77flags=%s' % f77flags)
        F2pyCommand.append('--f90flags=%s' % f90flags)
        F2pyCommand.append('_%s.pyf' % name)
        F2pyCommand.append('%s' % string.join(src))
        F2pyCommand.append('--quiet')
        F2pyCommand = string.join(F2pyCommand)
        print F2pyCommand
        if subprocess.call(F2pyCommand, shell=True) > 0:
            raise StandardError('+++ Compilation failed')
        # delete signature file
        subprocess.call('rm -f _%s.pyf' % name, shell=True)
        # Copy shared object file to pydir
        subprocess.call('cp %s %s'%(target, pydir), shell=True)
    #  Switch back to original working directory
    os.chdir(here)
Exemplo n.º 23
0
    dependency_graph = {
        filename: {
            module_sources[module]
            for module in scan_regexp(filename, r"use (\w+)")
        }
        for filename in f90_sources
    }

    return f77_sources + topological_sort(dependency_graph)


src_dir = "src"
source_files = get_sorted_source_files(src_dir)

compiler = fcompiler.get_default_fcompiler()
for arg in sys.argv:
    if "--fcompiler" in arg:
        compiler = arg[arg.index("=") + 1:]
print("Using %s compiler" % compiler, file=sys.stderr)

if compiler == "gnu95":
    f77flags = []
    f90flags = ["-ffree-line-length-none"]
    opt = ["-Ofast", "-march=native", "-funroll-loops", "-flto", "-fopenmp"]
elif compiler.startswith("intel"):
    f77flags = []
    f90flags = ["-assume realloc_lhs"]
    opt = ["-fast", "-openmp"]
else:
    print("Compiler %s not supported. Let's hope things just work." % compiler,
Exemplo n.º 24
0
f77_compiler_flags = {
    'gnu': '-Wall -ffixed-form -fno-second-underscore -fno-automatic',
    'gnu95': '-Wall -ffixed-form -fno-second-underscore -fno-automatic',
}

# Check if we need to configure a compile.
config_index = 0
for i, arg in enumerate(sys.argv):
    if arg == 'config_fc':
        break
    elif arg.startswith(('build', 'bdist', 'develop', 'install')):
        config_index = i
        break

if config_index > 0:
    f77 = get_default_fcompiler()
    f77flags = f77_compiler_flags.get(f77, None)
    if f77flags:
        # Configure compiler options using setup's 'config_fc' command.
        sys.argv[config_index:config_index] = \
            ['config_fc', '--f77flags=%s' % f77flags]

kwds = {
    'description': 'AXOD - axial turbine off-design analysis.',
    'version': version,
    'license': 'public domain',
    'install_requires': ['numpy'],
    'zip_safe': False,
}

kwds.update(config.todict())
Exemplo n.º 25
0
                          'language_level': 3,
                          'cdivision': False,
                          "boundscheck": True
                      }))

# from https://github.com/pytest-dev/pytest-runner#conditional-requirement
needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
pytest_runner = ["pytest-runner"] if needs_pytest else []

try:
    with open("README.md", "r") as handle:
        long_description = handle.read()
except Exception:
    long_description = "\n".join(short_description[2:])

if get_default_fcompiler() != None:
    fortran_list = glob.glob(os.path.join(fpath, "*.f90"))
    for fext in fortran_list:
        name = os.path.split(fext)[-1].split(".")[-2]
        ext1 = Extension(name=name, sources=[fext], include_dirs=[fpath])
        extensions.append(ext1)
else:
    print("Fortran compiler is not found, default will use numba")

# try Extension and compile
# !!!! Note that we have Fortran modules that need to be compiled with "f2py3 -m solv_assoc -c solve_assoc.f90" and the same with solve_assoc_matrix.f90

setup(
    # Self-descriptive entries which should always be present
    name="despasito",
    author="Jennifer A Clark",
Exemplo n.º 26
0
f77_compiler_flags = {
    'gnu': '-Wall -ffixed-form -fno-second-underscore -fno-automatic',
    'gnu95': '-Wall -ffixed-form -fno-second-underscore -fno-automatic',
}

# Check if we need to configure a compile.
config_index = 0
for i, arg in enumerate(sys.argv):
    if arg == 'config_fc':
        break
    elif arg.startswith(('build', 'bdist', 'develop', 'install')):
        config_index = i
        break

if config_index > 0:
    f77 = get_default_fcompiler()
    f77flags = f77_compiler_flags.get(f77, None)
    if f77flags:
        # Configure compiler options using setup's 'config_fc' command.
        sys.argv[config_index:config_index] = \
            ['config_fc', '--f77flags=%s' % f77flags]

kwds = {'description':'AXOD - axial turbine off-design analysis.',
        'version':version,
        'license': 'public domain',
        'install_requires':['numpy'],
        'zip_safe':False,
       }

kwds.update(config.todict())
Exemplo n.º 27
0
from numpy.distutils.fcompiler import get_default_fcompiler
import sys
import os

fcompile = get_default_fcompiler(os.name, sys.platform, True)

install_dir = sys.argv[1]

os.system("python setup.py config_fc --fcompiler=" + str(fcompile) +
          " build_clib --fcompiler=" + str(fcompile) +
          " build_ext --fcompiler=" + str(fcompile) + " install --prefix='" +
          str(install_dir) + "'")