Example #1
0
def invoke_f2py(files, flags=[], wd=None):
    from numpy.f2py import main

    olddir = os.path.abspath(os.curdir)
    oldargv = list(sys.argv)
    try:
        if wd is not None:
            os.chdir(wd)
        sys.argv = ['f2py']
        sys.argv.extend(files)
        sys.argv.extend(flags)

        main()
    finally:
        sys.argv = oldargv
        os.chdir(olddir)
Example #2
0
def invoke_f2py(files, flags=[], wd=None):
    from numpy.f2py import main

    olddir = os.path.abspath(os.curdir)
    oldargv = list(sys.argv)
    try:
        if wd is not None:
            os.chdir(wd)
        sys.argv = ['f2py']
        sys.argv.extend(files)
        sys.argv.extend(flags)

        main()
    finally:
        sys.argv = oldargv
        os.chdir(olddir)
Example #3
0
    def import_selected_kind():
        """Tries to import the module which provides
        processor dependent kind values. If the module
        is not available it is compiled from a here-document
        and imported afterwards.

        Warning: creates both the source file and the
        compiled module in the current directory.

        """
        try:
            import f2py_selected_kind
        except:
            from numpy.f2py import compile
            # quick'n'dirty workaround for windoze
            if os.name == 'nt':
                f = open('f2py_selected_kind.f90', 'w')
                f.write(FCODE)
                f.close()
                from copy import deepcopy
                # save for later
                true_argv = deepcopy(sys.argv)
                sys.argv = (('%s -c --fcompiler=gnu95 --compiler=mingw32'
                             ' -m f2py_selected_kind'
                             ' f2py_selected_kind.f90') %
                            sys.executable).split()
                from numpy import f2py as f2py2e
                f2py2e.main()

                sys.argv = true_argv
            else:
                fcompiler = os.environ.get('F2PY_FCOMPILER', 'gfortran')
                compile(FCODE,
                        source_fn='f2py_selected_kind.f90',
                        modulename='f2py_selected_kind',
                        extra_args='--fcompiler=%s' % fcompiler)
            try:
                import f2py_selected_kind
            except Exception as e:
                raise Exception('Could not create selected_kind module\n' +
                                '%s\n' % os.path.abspath(os.curdir) +
                                '%s\n' % os.listdir('.') + '%s\n' % e)
        return f2py_selected_kind.kind
Example #4
0
    def import_selected_kind():
        """Tries to import the module which provides
        processor dependent kind values. If the module
        is not available it is compiled from a here-document
        and imported afterwards.

        Warning: creates both the source file and the
        compiled module in the current directory.

        """
        try:
            import f2py_selected_kind
        except:
            from numpy.f2py import compile
            # quick'n'dirty workaround for windoze
            if os.name == 'nt':
                f = open('f2py_selected_kind.f90', 'w')
                f.write(FCODE)
                f.close()
                from copy import deepcopy
                # save for later
                true_argv = deepcopy(sys.argv)
                sys.argv = (('%s -c --fcompiler=gnu95 --compiler=mingw32'
                             ' -m f2py_selected_kind'
                             ' f2py_selected_kind.f90')
                            % sys.executable).split()
                from numpy import f2py as f2py2e
                f2py2e.main()

                sys.argv = true_argv
            else:
                fcompiler = os.environ.get('F2PY_FCOMPILER', 'gfortran')
                compile(FCODE, source_fn='f2py_selected_kind.f90',
                        modulename='f2py_selected_kind',
                        extra_args='--fcompiler=%s' % fcompiler)
            try:
                import f2py_selected_kind
            except Exception as e:
                raise Exception('Could not create selected_kind module\n'
                                + '%s\n' % os.path.abspath(os.curdir)
                                + '%s\n' % os.listdir('.')
                                + '%s\n' % e)
        return f2py_selected_kind.kind
Example #5
0
def build(options):
    """Build binary with f2py binding from complete
    set of source file in the current directory.

    """

    from os.path import isfile
    import os
    import sys
    from glob import glob

    src_files = ['kind_values_f2py.f90', 'base.f90']

    if isfile('base_acf.f90'):
        src_files.append('base_acf.f90')
    src_files.append('lattice.f90')
    if isfile('proclist_constants.f90'):
        src_files.append('proclist_constants.f90')
    if isfile('proclist_pars.f90'):
        src_files.append('proclist_pars.f90')

    src_files.extend(glob('nli_*.f90'))
    # src_files.extend(glob('get_rate_*.f90'))
    src_files.extend(glob('run_proc_*.f90'))
    src_files.append('proclist.f90')
    if isfile('proclist_acf.f90'):
        src_files.append('proclist_acf.f90')

    extra_flags = {}

    if options.no_optimize:
        extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                                   ' -xf95-cpp-input -Wall -fimplicit-none'
                                   ' -time  -fmax-identifier-length=63 ')
        extra_flags['gnu95'] = extra_flags['gfortran']
        extra_flags['intel'] = '-fpp -Wall -I/opt/intel/fc/10.1.018/lib'
        extra_flags['intelem'] = '-fpp -Wall'

    else:
        extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                                   ' -xf95-cpp-input -Wall -O3 -fimplicit-none'
                                   ' -time -fmax-identifier-length=63 ')
        extra_flags['gnu95'] = extra_flags['gfortran']
        extra_flags['intel'] = '-fast -fpp -Wall -I/opt/intel/fc/10.1.018/lib'
        extra_flags['intelem'] = '-fast -fpp -Wall'

    # FIXME
    extra_libs = ''
    ccompiler = ''
    if os.name == 'nt':
        ccompiler = '--compiler=mingw32'
        if sys.version_info < (2, 7):
            extra_libs = ' -lmsvcr71 '
        else:
            extra_libs = ' -lmsvcr90 '

    module_name = 'kmc_model'

    if not isfile('kind_values_f2py.f90'):
        evaluate_kind_values('kind_values.f90', 'kind_values_f2py.f90')

    for src_file in src_files:
        if not isfile(src_file):
            raise IOError('File %s not found' % src_file)

    call = []
    call.append('-c')
    call.append('-c')
    call.append('--fcompiler=%s' % options.fcompiler)
    if os.name == 'nt':
        call.append('%s' % ccompiler)
    extra_flags = extra_flags.get(options.fcompiler, '')

    if options.debug:
        extra_flags += ' -DDEBUG'
    call.append('--f90flags="%s"' % extra_flags)
    call.append('-m')
    call.append(module_name)
    call += src_files

    print(call)
    from copy import deepcopy
    true_argv = deepcopy(sys.argv)  # save for later
    from numpy import f2py
    sys.argv = call
    f2py.main()
    sys.argv = true_argv
Example #6
0
File: utils.py Project: lulzzz/kmos
def build(options):
    from os.path import isfile
    from os import system, name
    import sys

    src_files = 'kind_values_f2py.f90 base.f90 lattice.f90 proclist.f90'

    if name == 'nt':
        interpreter = 'python '
        options.fcompiler = 'gnu95'
    elif name == 'posix':
        interpreter = ''
    else:
        interpreter = ''

    extra_flags = {}
    extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                               ' -xf95-cpp-input -Wall -g')
    extra_flags['gnu95'] = extra_flags['gfortran']
    extra_flags['intel'] = '-fast -fpp -Wall -I/opt/intel/fc/10.1.018/lib'
    extra_flags['intelem'] = '-fast -fpp -Wall -g'

    # FIXME
    extra_libs = ''
    ccompiler = ''
    if name == 'nt':
        ccompiler = '--compiler=mingw32'
        if sys.version_info < (2, 7):
            extra_libs = ' -lmsvcr71 '
        else:
            extra_libs = ' -lmsvcr90 '

    module_name = 'kmc_model'


    if not isfile('kind_values_f2py.py'):
         evaluate_kind_values('kind_values.f90', 'kind_values_f2py.f90')

    for src_file in src_files.split():
        if not isfile(src_file):
            raise IOError('File %s not found' % src_file)

    call = []
    call.append('-c')
    call.append('-c')
    call.append('--fcompiler=%s' % options.fcompiler)
    if name == 'nt':
        call.append('%s' % ccompiler)
    #call += extra_libs.split()
    call.append('--f90flags="%s"' % extra_flags.get(
                                        options.fcompiler, ''))
    call.append('-m')
    call.append(module_name)
    call += src_files.split()

    print(call)
    #exit()
    from copy import deepcopy
    true_argv = deepcopy(sys.argv)  # save for later
    from numpy import f2py
    sys.argv = call
    f2py.main()
    sys.argv = true_argv
Example #7
0
File: utils.py Project: lulzzz/kmos
    def import_selected_kind():
        """Tries to import the module which provides
        processor dependent kind values. If the module
        is not available it is compiled from a here-document
        and imported afterwards.

        Warning: creates both the source file and the
        compiled module in the current directory.

        """
        try:
            import f2py_selected_kind
        except:
            from numpy.f2py import compile
            fcode = """module kind
    implicit none
    contains
    subroutine real_kind(p, r, kind_value)
      integer, intent(in), optional :: p, r
      integer, intent(out) :: kind_value

      if(present(p).and.present(r)) then
        kind_value = selected_real_kind(p=p, r=r)
      else
        if (present(r)) then
          kind_value = selected_real_kind(r=r)
        else
          if (present(p)) then
            kind_value = selected_real_kind(p)
          endif
        endif
      endif
    end subroutine real_kind

    subroutine int_kind(p, r, kind_value)
      integer, intent(in), optional :: p, r
      integer, intent(out) :: kind_value

      if(present(p).and.present(r)) then
        kind_value = selected_int_kind(p)
      else
        if (present(r)) then
          kind_value = selected_int_kind(r=r)
        else
          if (present(p)) then
            kind_value = selected_int_kind(p)
          endif
        endif
      endif
    end subroutine int_kind

    end module kind
            """
            # quick'n'dirty workaround for windoze
            if os.name == 'nt':
                with open('f2py_selected_kind.f90', 'w') as f:
                    f.write(fcode)
                from copy import deepcopy
                # save for later
                true_argv = deepcopy(sys.argv)
                sys.argv = ('%s -c --fcompiler=gnu95 --compiler=mingw32 -m f2py_selected_kind f2py_selected_kind.f90' % sys.executable).split()
                from numpy import f2py as f2py2e
                f2py2e.main()

                sys.argv = true_argv
            else:
                compile(fcode, source_fn='f2py_selected_kind.f90',
                        modulename='f2py_selected_kind')
            try:
                import f2py_selected_kind
            except:
                print(os.path.abspath(os.curdir))
                print(os.listdir('.'))
                raise
        return f2py_selected_kind.kind
Example #8
0
#!/usr/bin/env python

"""
this is a stripped down version of the f2py tool that is present on
my own machine, and is included here since it seems the f2py tool
itself is not available in the standard path on some machines,
even if numpy and numpy.f2py are available as python module.
"""

# Copyright J. de Kloe
# This software is licensed under the terms of the LGPLv3 Licence
# which can be obtained from https://www.gnu.org/licenses/lgpl.html

from numpy.f2py import main
main()
Example #9
0
def build(options):
    from os.path import isfile
    from os import system, name
    import sys

    src_files = 'kind_values_f2py.f90 base.f90 lattice.f90 proclist.f90'

    if name == 'nt':
        interpreter = 'python '
        options.fcompiler = 'gnu95'
    elif name == 'posix':
        interpreter = ''
    else:
        interpreter = ''

    extra_flags = {}
    extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                               ' -xf95-cpp-input -Wall -g')
    extra_flags['gnu95'] = extra_flags['gfortran']
    extra_flags['intel'] = '-fast -fpp -Wall -I/opt/intel/fc/10.1.018/lib'
    extra_flags['intelem'] = '-fast -fpp -Wall -g'

    # FIXME
    extra_libs = ''
    ccompiler = ''
    if name == 'nt':
        ccompiler = '--compiler=mingw32'
        if sys.version_info < (2, 7):
            extra_libs = ' -lmsvcr71 '
        else:
            extra_libs = ' -lmsvcr90 '

    module_name = 'kmc_model'

    if not isfile('kind_values_f2py.py'):
        evaluate_kind_values('kind_values.f90', 'kind_values_f2py.f90')

    for src_file in src_files.split():
        if not isfile(src_file):
            raise IOError('File %s not found' % src_file)

    call = []
    call.append('-c')
    call.append('-c')
    call.append('--fcompiler=%s' % options.fcompiler)
    if name == 'nt':
        call.append('%s' % ccompiler)
    #call += extra_libs.split()
    call.append('--f90flags="%s"' % extra_flags.get(options.fcompiler, ''))
    call.append('-m')
    call.append(module_name)
    call += src_files.split()

    print(call)
    #exit()
    from copy import deepcopy
    true_argv = deepcopy(sys.argv)  # save for later
    from numpy import f2py
    sys.argv = call
    f2py.main()
    sys.argv = true_argv
Example #10
0
    def import_selected_kind():
        """Tries to import the module which provides
        processor dependent kind values. If the module
        is not available it is compiled from a here-document
        and imported afterwards.

        Warning: creates both the source file and the
        compiled module in the current directory.

        """
        try:
            import f2py_selected_kind
        except:
            from numpy.f2py import compile
            fcode = """module kind
    implicit none
    contains
    subroutine real_kind(p, r, kind_value)
      integer, intent(in), optional :: p, r
      integer, intent(out) :: kind_value

      if(present(p).and.present(r)) then
        kind_value = selected_real_kind(p=p, r=r)
      else
        if (present(r)) then
          kind_value = selected_real_kind(r=r)
        else
          if (present(p)) then
            kind_value = selected_real_kind(p)
          endif
        endif
      endif
    end subroutine real_kind

    subroutine int_kind(p, r, kind_value)
      integer, intent(in), optional :: p, r
      integer, intent(out) :: kind_value

      if(present(p).and.present(r)) then
        kind_value = selected_int_kind(p)
      else
        if (present(r)) then
          kind_value = selected_int_kind(r=r)
        else
          if (present(p)) then
            kind_value = selected_int_kind(p)
          endif
        endif
      endif
    end subroutine int_kind

    end module kind
            """
            # quick'n'dirty workaround for windoze
            if os.name == 'nt':
                with open('f2py_selected_kind.f90', 'w') as f:
                    f.write(fcode)
                from copy import deepcopy
                # save for later
                true_argv = deepcopy(sys.argv)
                sys.argv = (
                    '%s -c --fcompiler=gnu95 --compiler=mingw32 -m f2py_selected_kind f2py_selected_kind.f90'
                    % sys.executable).split()
                from numpy import f2py as f2py2e
                f2py2e.main()

                sys.argv = true_argv
            else:
                compile(fcode,
                        source_fn='f2py_selected_kind.f90',
                        modulename='f2py_selected_kind')
            try:
                import f2py_selected_kind
            except:
                print(os.path.abspath(os.curdir))
                print(os.listdir('.'))
                raise
        return f2py_selected_kind.kind
Example #11
0
def build(options):
    """Build binary with f2py binding from complete
    set of source file in the current directory.

    """

    from os.path import isfile
    import os
    import sys
    from glob import glob

    src_files = ['kind_values_f2py.f90', 'base.f90']
    
    if isfile('base_acf.f90'):
        src_files.append('base_acf.f90')
    src_files.append('lattice.f90')
    if isfile('proclist_constants.f90'):
        src_files.append('proclist_constants.f90')
    if isfile('proclist_pars.f90'):
        src_files.append('proclist_pars.f90')

    src_files.extend(glob('nli_*.f90'))
    # src_files.extend(glob('get_rate_*.f90'))
    src_files.extend(glob('run_proc_*.f90'))
    src_files.append('proclist.f90')
    if isfile('proclist_acf.f90'):
        src_files.append('proclist_acf.f90')

    extra_flags = {}

    if options.no_optimize:
        extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                                   ' -xf95-cpp-input -Wall -fimplicit-none'
                                   ' -time  -fmax-identifier-length=63 ')
        extra_flags['gnu95'] = extra_flags['gfortran']
        extra_flags['intel'] = '-fpp -Wall -I/opt/intel/fc/10.1.018/lib'
        extra_flags['intelem'] = '-fpp -Wall'

    else:
        extra_flags['gfortran'] = ('-ffree-line-length-none -ffree-form'
                                   ' -xf95-cpp-input -Wall -O3 -fimplicit-none'
                                   ' -time -fmax-identifier-length=63 ')
        extra_flags['gnu95'] = extra_flags['gfortran']
        extra_flags['intel'] = '-fast -fpp -Wall -I/opt/intel/fc/10.1.018/lib'
        extra_flags['intelem'] = '-fast -fpp -Wall'

    # FIXME
    extra_libs = ''
    ccompiler = ''
    if os.name == 'nt':
        ccompiler = '--compiler=mingw32'
        if sys.version_info < (2, 7):
            extra_libs = ' -lmsvcr71 '
        else:
            extra_libs = ' -lmsvcr90 '

    module_name = 'kmc_model'

    if not isfile('kind_values_f2py.f90'):
        evaluate_kind_values('kind_values.f90', 'kind_values_f2py.f90')

    for src_file in src_files:
        if not isfile(src_file):
            raise IOError('File %s not found' % src_file)

    call = []
    call.append('-c')
    call.append('-c')
    call.append('--fcompiler=%s' % options.fcompiler)
    if os.name == 'nt':
        call.append('%s' % ccompiler)
    extra_flags = extra_flags.get(options.fcompiler, '')

    if options.debug:
        extra_flags += ' -DDEBUG'
    call.append('--f90flags="%s"' % extra_flags)
    call.append('-m')
    call.append(module_name)
    call += src_files

    print(call)
    from copy import deepcopy
    true_argv = deepcopy(sys.argv)  # save for later
    from numpy import f2py
    sys.argv = call
    f2py.main()
    sys.argv = true_argv