Brigham Young University Homepage

Physics & Astronomy

Materials Simulation Group

Libraries

32-bit

Switch the compiler environment variables so that we can make a 32-bit library to be called from python using the ctypes module.

. /opt/intel/composerxe-2011/bin/compilervars.sh ia32

Python

Here is an example of making a library out of a fortran90/95 module:

ifort -dynamiclib -o libtest.so num_types.f90 combinatorics.f90

Now, call a routine from python

#!/usr/bin/python

from ctypes import *
libtest = cdll.LoadLibrary("./libtest.so")

# If you don't know what the method is called in the library, use "nm"
method = libtest.combinatorics_mp_binomial_
x = c_int(32)
y = c_int(15)
print "x = %d, y = %d" % (x.value, y.value)
#
# The byref() is necessary since
# FORTRAN does references,
#
bnml = method( byref(x), byref(y) )
print "x = %d, y = %d" % (x.value, y.value)
print bnml

 

The Church of Jesus Christ of Latter-day Saints | BYU-Hawaii | BYU-Idaho | BYU Jerusalem Center | BYU Salt Lake Center | LDS Business College