Note that there are some explanatory texts on larger screens.

plurals
  1. POwhen using f2py, function scope within fortran module different than when compiled for fortran program?
    primarykey
    data
    text
    <p>My problem is that when compiling with f2py, some module variables are not recognized by functions defined within the module. The errors are raised where variable types of arguments passed to the function are declared (such as a variable describing the type of <code>real</code>, or dimension elements). I do not get this error when compiling with gfortran. What is the difference and how can I remedy these errors when compiling with f2py?</p> <p>My example file, <code>moddata.f90</code>, contains the following code:</p> <pre><code>module mod implicit none integer, parameter :: dp = selected_real_kind(15) integer, parameter :: nelem = 3 real(kind=dp), dimension(nelem) :: b parameter (b=(/3,1,2/)) contains function foo(x,y) result(z) ! dp, nelem are defined in module above real(kind=dp), intent(in) :: x !scalar integer, dimension(nelem), intent(in) :: y ! local variable real(kind=dp) :: z z = sum(b*y*x) end function foo end module mod </code></pre> <p>and I compile with </p> <pre><code>f2py -c -m moddata moddata.f90 </code></pre> <p>and I get these errors:</p> <pre><code> y_Dims[0]=(nelem); ^ 1 warning and 1 error generated.reduce to a constant expression </code></pre> <p>if I redefine <code>integer, parameter :: nelem=3</code> before <code>integer, dimension(nelem), intent(in) :: y</code> and recompile, I get</p> <pre><code> real(kind=dp) foof2pywrap 1 Error: Parameter 'dp' at (1) has not been declared or is a variable, which does not reduce to a constant expression </code></pre> <p>with same errors for each of the <code>real(kind=dp)</code> declarations, and </p> <pre><code> foof2pywrap = foo(x, y) 1 Warning: Possible change of value in conversion from REAL(8) to REAL(4) at (1) </code></pre> <p>So I have to redefine <code>dp</code> by <code>integer, parameter :: dp = selected_real_kind(15)</code> in the function. And then it works.</p> <p>I don't get these errors when I compile this module with a fortran wrapper. I wonder why <code>nelem</code> and <code>dp</code> in the function is not properly scoped with f2py?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload