-1

I have some Python code, compiled with errors:

def rad2_cv(m, n, c, type, x):
    eps = 10e-8;
    if type == 1:
        result = f_radial.rad_fun(0, m, n, c, x, eps)
        return result[2], result[3]
    elif type == -1:
        result =  f_radial.rad_fun(1, m, n, c, x, eps)
        return result[2], result[3]

and some Fortran code in an .f file, compiled with no errors:

c****************************************************************************
c                    Radial spheroidal functions
c
c parameters:
c    kob  - switch between prolate (0) and oblate (1) functions
c    m    - index m
c    ne   - maximum index n
c    c2   - argument c (complex*16)
c    ksi0 - argument xi (real*8)
c    eps  - accuracy of getting eigenvalues
c
c results (all complex*16):
c    R1f(ne) - functions R^(1)_mn (c,xi),  n = 1, ne
c    R1d(ne) - derivatives dR^(1)_mn (c,xi)/dxi, n = 1, ne
c    R2f(ne) - functions R^(2)_mn (c,xi),  n = 1, ne
c    R2d(ne) - derivatives dR^(2)_mn (c,xi)/dxi, n = 1, ne
c
c 2005, Nov
c****************************************************************************

      SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
      parameter (nterms=330)
      IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
      REAL*8 C2, ksi0
      complex*16 R1f , R1d , R2f , R2d 
      COMPLEX*16 bdc2
      DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)
      COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
      COMMON /EPS1/ EPS1
      COMMON /EPS33/ EPS33
      COMMON /EPS3/ EPS3
      COMMON /FACT/ FACT(300)
      COMMON /PI/ PI
cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d
…
c final results
c    5 continue
    5 R1f = r1
      R1d = r2
      R2f = r3
      R2d = r4

    1 CONTINUE
      RETURN
      END

When I try to compile Python code got 2 errors:

first error :

f_radial.rad_fun() missing required argument 'r1f' (pos 7)

at

result = f_radial.rad_fun(0, m, n, c, x, eps)

and second error :

'NoneType' object is not subscriptable

at

return result[2], result[3]

What should I do?

  • It appears that `f_radial.rad_fun` expects at least one more parameter, at position 7 (you only provide 6), but it's impossible to tell, since you didn't share the source of (or a link to) the `f_radial` python library. Apparently, it does return a value (`None`) and you're trying to access that by index, which can't be done - `None[2]` for `result[2]` causes your error. – Grismar Sep 13 '19 at 02:02
  • The `f_radial` source is at https://github.com/ScattPy/scikits.scattpy/blob/master/src/radial.for – user432654 Sep 13 '19 at 02:22
  • And the corresponding python code is at https://github.com/ScattPy/scikits.scattpy/blob/master/scikits/scattpy/spheroidal_functions.py – user432654 Sep 13 '19 at 02:47
  • The code at https://github.com/ScattPy/scikits.scattpy/blob/master/scikits/scattpy/spheroidal_functions.py compiles just fine though? Your first error appears to be thrown by Fortran, but since you don't provide the connecting code or a working example, answering why this happens is impossible. The second error is a logical result of the first, as explained. As to what you should do: post an example that works in that it demonstrates the problem, so it can be reproduced and solved. – Grismar Sep 13 '19 at 02:57
  • As similar errors I had before I think there were errors with these lines at Fortran codes : `cf2py intent(in) kob, m, ne, C2, KSI0, EPS cf2py intent(out) R1f, R1d, R2f, R2d` – user432654 Sep 13 '19 at 03:29
  • Maybe if I use `cf2py intent(out,hide) R1f, R1d, R2f, R2d` my problem would be solved? – user432654 Sep 13 '19 at 03:47
  • That's for first error. I have no idea for second error. – user432654 Sep 13 '19 at 07:52

1 Answers1

0

Problem solved as replacing cf2py intent... statements before COMMON statements.

 SUBROUTINE rad_fun (kob, m, ne, C2, KSI0, EPS, R1f, R1d, R2f,R2d)
      parameter (nterms=330)
      IMPLICIT REAL*8 (A-H,O-Q,T-Z), COMPLEX*16 (R-S)
      REAL*8 C2, ksi0
      complex*16 R1f , R1d , R2f , R2d 
      COMPLEX*16 bdc2
      DIMENSION RLC2(nterms), rDC2(4*nterms), bDC2(4*nterms)

cf2py intent(in) kob, m, ne, C2, KSI0, EPS
cf2py intent(out) R1f, R1d, R2f, R2d

      COMMON /K1/ S, S1, AKSI, AK, K, NK, nal
      COMMON /EPS1/ EPS1
      COMMON /EPS33/ EPS33
      COMMON /EPS3/ EPS3
      COMMON /FACT/ FACT(300)
      COMMON /PI/ PI

…