ImportError: DLL load failed while importing polint: The specified module could not be found

I am trying to create a module from Fortran which can be used in Python using f2py for the polint process.

MODULE PolintModule
  IMPLICIT NONE
  INTEGER, PARAMETER :: NMAX = 10
  CONTAINS

  SUBROUTINE polint(xa, ya, n, x, y, dy)
    INTEGER, INTENT(IN) :: n
    REAL(8), INTENT(IN) :: x
    REAL(8), INTENT(IN) :: xa(n), ya(n)
    REAL(8), INTENT(OUT) :: y, dy
    INTEGER :: i, m, ns
    REAL(8) :: den, dif, dift, ho, hp, w
    REAL(8) :: c(NMAX), d(NMAX)

    ! Initialization
    ns = 1
    dif = ABS(x - xa(1))
    DO i = 1, n
      dift = ABS(x - xa(i))
      IF (dift < dif) THEN
        ns = i
        dif = dift
      ENDIF
      c(i) = ya(i)
      d(i) = ya(i)
    END DO

    y = ya(ns)
    ns = ns - 1

    ! Interpolation loop
    DO m = 1, n - 1
      DO i = 1, n - m
        ho = xa(i) - x
        hp = xa(i + m) - x
        w = c(i + 1) - d(i)
        den = ho - hp
        IF (den == 0.0) THEN
          PRINT *, 'Error: Failure in polint'
          STOP
        END IF
        den = w / den
        d(i) = hp * den
        c(i) = ho * den
      END DO
      IF (2 * ns < n - m) THEN
        dy = c(ns + 1)
      ELSE
        dy = d(ns)
        ns = ns - 1
      ENDIF
      y = y + dy
    END DO

  END SUBROUTINE polint

END MODULE PolintModule

Here is my polint code

The following command I am entering in the terminal f2py -c -m polint polint.f90

To create a .pyd file (I am using wwindows)

The following is the python code:

from numpy import sin, linspace, array, pi
import matplotlib.pyplot as plt
import polint as p

# Define table of sin(x)
xx = linspace(0, 2 * pi, 10)
yy = sin(xx)

# Define points at which to interpolate
x = linspace(-pi, 3 * pi, 501)

# Interpolate and get dy
y = [p.polint(xx, yy, len(xx), w)[0] for w in x]
dy = [p.polint(xx, yy, len(xx), w)[1] for w in x]

# Plot the outputs
plt.figure(1)
plt.plot(xx, yy, 'ro', label='Table values')
plt.plot(x, y, 'r', label='Interpolated values')
plt.plot(x, sin(x), 'g', label='True function')
plt.title("Interpolating sin(x)")
plt.legend()

plt.figure(2)
plt.semilogy(x, abs(array(dy)), 'r', label='Estimated Error')
plt.semilogy(x, abs(array(sin(x) - y)), 'g', label='True Error')
plt.title("Estimated vs True Error")
plt.legend()

plt.show()

The following is the error I am getting import polint as p ImportError: DLL load failed while importing polint: The specified module could not be found.

I am tying to solve the error for quite some time but am not able to. Please guide me on the steps which i can take.

Upvotes: 0

Views: 31

Answers (0)

Related Questions