Fortran Compilation#

The pygeostat.fortran module includes functions for compiling Fortran code and building custom GSLIB executables.

Compilation Functions#

build_pygeostat_fortran#

pygeostat.fortran.build_pygeostat_fortran(pygeostatmodules='all', compiler='gnu', mode='release', exflags='', opt='O2', clean=True, verbose=False)[source]#

This function builds the f2py extensions with minimal interaction from the user. The goal is to make this function callable with gs.build_pygeostat_fortran(), and have all requirements sorted out automatically resulting in a set of compiled pygeostat fortran extensions.

Modules are compiled to pygeostat/fortran/, regardless of where the function is called from. If no gnu compiling tools are found on the path (gfortran -v, gcc -v returns nothing), then conda install mingw -y is run to install MinGW, and this compiler is used.

Parameters:
  • pygeostatmodules (str) – either "all" or one of the dictionary keys found in pygeostat/fortran/sourcedefs.py

  • compiler (str) – either "intel", "gnu" or a path to a local folder containing gfortran compilers, e.g., C:/mingw/bin/

  • mode (str) – “release” or “debug”

  • exflags (str) – compiler-specific permissable fortran compiler flags

  • opt (str) – optimization level, defaults to O2

  • clean (bool) – if True then the build directory is cleaned before compiling (recommended)

  • verbose (bool) – write all output to the terminal

Code author: Ryan Martin - 07-04-2018

build_custom_fortran#

pygeostat.fortran.build_custom_fortran(sources, includes={}, wraponly={}, name=None, srcdir='./', outdir='./', tmpdir='./tmp/', compiler='gnu', mode='release', exflags='', opt='O2', clean=True, verbose=True)[source]#

This function is intended to allow arbitrary f2py extensions to be constructed using the tooling provided in this module. This function replaces FortranBuild as a more succinct methodology to compile the requred sources.

Parameters:
  • sources (list or dict) – either a list of fortran files where the last depends on the first and the last file in the list contains the f2py wrapping code, or a dictionary where keys in the dictionary indicate the name of the module to be built and the values are the lists of associated sources to generate that module. See pygeostat/fortran/sourcedefs.py for inspiration on the structure of these dictionaries

  • includes (list or dict) – a matching item to sources that contains a list or dict of extra items to include on the link step of compilation. See pygeostat/fortran/sourcedefs.py.

  • wraponly (list or dict) – matching item to sources and includes that contains a list or dictionary of functions that get wrapped for python, other functions in the f2py fortran code are ignored. See pygeostat/fortran/sourcedefs.py.

  • name (str) – if sources is a list, a name must be provided for the resulting <name>.pyd

  • srcdir (str) – various locations to consider

  • tmpdir (str) – various locations to consider

  • outdir (str) – various locations to consider

  • compiler (str) – either "intel", "gnu" or a path to a compiler bin directory

  • mode (str) – "release" or "debug"

  • exflags (str) – compiler-specific permissable fortran compiler flags

  • opt (str) – optimization level, defaults to O2

  • clean (bool) – if True then the build directory is cleaned before compiling (recommended)

  • verbose (bool) – write all output to the terminal

Code author: Ryan Martin - 07-04-2018

build_lapack#

pygeostat.fortran.build_lapack(compiler, force_compile=False, verbose=True)[source]#

A small utility to build the lapack library that is required in some of the .pyd builds.

Parameters:
  • compiler (str) – ‘intel’ or ‘gnu’

  • force_compile (bool) – If True will force compile even if lapack library is already built

  • verbose (bool) – ‘all’ prints all output, ‘min’ only prints a message if it starts compiling lapack, none prints only if error is found

Code author: Tyler Acorn March 08, 2017