2016-08-30 98 views
0

當我嘗試編譯FORTRAN子程序時,f2py給出錯誤,我從中調用另一個FORTRAN函數將數組傳遞給它。 我簡化的代碼只留下問題。f2py Fortran函數接口編譯錯誤

SUBROUTINE MAS (matrix, a) 
    IMPLICIT NONE 
    INTERFACE 
     LOGICAL FUNCTION LTRY(input_array) 
      IMPLICIT NONE 
      INTEGER*4 :: input_array(:,:) 
     END FUNCTION LTRY 
    END INTERFACE 

    INTEGER*4 :: matrix (:,:) 
!f2py INTENT(INOUT) :: matrix(:,:) 
    INTEGER*4 a 
!f2py INTENT(INOUT) :: a 

    a = 1 
    IF (LTRY (matrix)) a = 2 
END SUBROUTINE 

LOGICAL FUNCTION LTRY(input_array) 
    IMPLICIT NONE 
    INTEGER*4 :: input_array (:,:) 

    IF (ANY(input_array == 0)) LTRY = .FALSE. 
END FUNCTION LTRY 

後,我嘗試編譯這個使用 f2py -c -m PTEST ptest.f90 我得到的錯誤的一個巨大數字。怎麼了? 使用Ubuntu和gfortran編譯器。

以下是編譯器的輸出(部分有錯誤報告):

gfortran:f77: /tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:16.35: 
       function ltry(input) ! in :ptest:ptest.f90:mas:unkno 
            1 
Error: Unexpected junk after function declaration at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:18.72: 
        integer, dimension(:,:) :: input 
                     1 
Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:19.72: 
        logical :: ltry 
                     1 
Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:20.17: 
       end function ltry 
       1 
Error: Expecting END INTERFACE statement at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:40.32: 
     ltryf2pywrap = .not.(.not.ltry(input_array)) 
           1 
Error: Operand of .not. operator at (1) is INTEGER(4) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:16.35: 
       function ltry(input) ! in :ptest:ptest.f90:mas:unkno 
            1 
Error: Unexpected junk after function declaration at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:18.72: 
        integer, dimension(:,:) :: input 
                     1 
Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:19.72: 
        logical :: ltry 
                     1 
Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:20.17: 
       end function ltry 
       1 
Error: Expecting END INTERFACE statement at (1) 
/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f:40.32: 
     ltryf2pywrap = .not.(.not.ltry(input_array)) 
           1 
Error: Operand of .not. operator at (1) is INTEGER(4) 
error: Command "/usr/bin/gfortran -Wall -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops -I/tmp/tmpSZHMCR/src.linux-i686-2.7 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c -c /tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.f -o /tmp/tmpSZHMCR/tmp/tmpSZHMCR/src.linux-i686-2.7/ptest-f2pywrappers.o" failed with exit status 1 
Compilation failed. 

有些錯誤看起來很奇怪。例如,編譯器將邏輯函數看作一個整數。

+3

你會得到什麼錯誤? –

+0

我編輯了我的問題 –

回答

0

不幸的是,您並未指明您獲得哪種類型的錯誤。 我試圖編譯我的系統上,而我得到的錯誤信息:

/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:16:35: 

       function ltry(input) ! in :ptest:ptest.f90:mas:unkno 
            1 
Error: Unexpected junk after function declaration at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:18:72: Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:19:72: Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:20:17: 

       end function ltry 
       1 
Error: Expecting END INTERFACE statement at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:16:35: 

       function ltry(input) ! in :ptest:ptest.f90:mas:unkno 
            1 
Error: Unexpected junk after function declaration at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:18:72: Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:19:72: Error: Unexpected data declaration statement in INTERFACE block at (1) 
/tmp/tmpLKy0jV/src.linux-x86_64-2.7/ptest-f2pywrappers.f:20:17: 

       end function ltry 
       1 
Error: Expecting END INTERFACE statement at (1) 

展望包裹文件中,我們可以看到,包裝提出了一個非常可疑的決定:它已經在末尾添加評論行的,但是緊接着,線包裹的評論未聲明的評論在第二行:

C  -*- fortran -*- 
C  This file is autogenerated with f2py (version:2) 
C  It contains Fortran 77 wrappers to fortran functions. 

     subroutine f2pywrapmas (matrix, a, f2py_matrix_d0, f2py_matr 
    &ix_d1) 
     integer*4 a 
     integer f2py_matrix_d0 
     integer f2py_matrix_d1 
     integer*4 matrix(f2py_matrix_d0,f2py_matrix_d1) 
     interface 
     subroutine mas(matrix,a) 
      integer*4, dimension(:,:) :: matrix 
      integer*4 :: a 
      interface ! in :ptest:ptest.f90:mas 
       function ltry(input) ! in :ptest:ptest.f90:mas:unkno 
    &wn_interface 
        integer, dimension(:,:) :: input 
        logical :: ltry 
       end function ltry 
      end interface 
     end subroutine mas 
     end interface 
     call mas(matrix, a) 
     end 

我不知道怎麼幫你,雖然。但我建議你在問題中發佈你的實際錯誤信息。

+0

謝謝。我已經通過f2py輸出更新了我的問題。 –