""" Lane Emden Routines f2py -m _laneemden -h _laneemden.pyf laneemden.f90 --overwrite-signature f2py --f90exec=/usr/bin/gfortran --f90flags='-fPIC -O3 -funroll-loops -fno-second-underscore' -L. -lgfortran -c -m _laneemden laneemden.f90 gfortran laneemden.f90 -o laneemden laneemden This may require to create a link to libgefortran.so ln -s /usr/lib64/libgfortran.so.3 libgfortran.so Or, for all users: [root]# cd /usr/lib64 [root]# ln -s libgfortran.so.3 libgfortran.so """ from __future__ import division from __future__ import print_function from __future__ import with_statement import os import subprocess path = os.path.dirname(__file__) so_file = os.path.join(path,'_laneemden.so') def _build_module(): """ Build the Lane Emden FOTRTAN module. We also do a test of the executable version """ cwd = os.getcwd() os.chdir(path) import numpy as np import glob # test executable try: subprocess.check_call("gfortran laneemden.f90 -o laneemden.exe",shell=True) except subprocess.CalledProcessError: print("executable compilation failed") raise try: result = subprocess.check_output("laneemden.exe") except subprocess.CalledProcessError: print("module executable failed") raise a = np.array([float(x) for x in result.split()]) b = np.array([6.8968486193938672,0.,-4.24297576045549740e-2]) print('Test result OK?: ',np.all(np.equal(a,b))) try: os.remove("laneemden.exe") except: pass # make module libs = glob.glob('/usr/lib64/libgfortran.so*') if len(libs) > 0: try: os.stat("libgfortran.so") except: try: os.remove("libgfortran.so") except: pass lib = libs[0] print('Trying to link '+lib) try: os.symlink(lib,"libgfortran.so") except: print("Could not create link") try: subprocess.check_call("f2py -m _laneemden -h _laneemden.pyf laneemden.f90 --overwrite-signature",shell=True) except subprocess.CalledProcessError: print("creating f2py signature failed") raise try: subprocess.check_call("f2py --f90exec=/usr/bin/gfortran --f90flags='-fPIC -O3 -funroll-loops -fno-second-underscore' -L. -lgfortran -c -m _laneemden laneemden.f90",shell=True) except subprocess.CalledProcessError: print("creating module failed") raise os.chdir(cwd) build = False if not os.path.exists(so_file): build = True else: f90_file = os.path.join(path,'laneemden.f90') if (os.path.getctime(so_file) < os.path.getctime(f90_file)): build = True if not build: try: import laneemden except ImportError: build = True # check for changed compiler version (works on Fedora 18) if not build: try: result = subprocess.check_output("gcc --version", shell=True) compiler_version = (result.splitlines()[0]).split(' ',2)[2] result = subprocess.check_output("strings - " + so_file + " | grep GCC", shell=True) library_version = result.splitlines()[0].split(' ',2)[2] if compiler_version != library_version: build = True except: pass if build: _build_module() from laneemden import *