分配的數組太大,會引起以下錯誤:html
0x000007FE083F86C8 (DH0_fortran_DLL.dll) (GccCallfortranDLLexample.exe 中)處有未經處理的異常: 0xC00000FD: Stack overflow (參數: 0x0000000000000001, 0x0000000000033000)。數組
應該用動態數組:code
REAL,ALLOCATABLE :: W2(:),W3(:),W4(:),W5(:),DSP_A(:) ALLOCATE(W2(MAXFR)) ALLOCATE(W3(MAXFR)) ALLOCATE(W4(MAXFR)) ALLOCATE(W5(MAXFR)) ALLOCATE(DSP_A(MAXFR)) DO I=1,MAXFR DSP_A(I)=DSP1(I) END DO
在subroutine調用的時候,應該給方法寫上interfacehtm
SUBROUTINE ESCG1(NITR,EITR) C IMPLICIT NONE PARAMETER(MAXND=80000,MAXFR=MAXND*3) C interface subroutine AXMLT1(aaa,bbb) real, intent(inout) :: aaa(:), bbb(:) end subroutine AXMLT1 end interface C C COMMON/EQUA/DSP1(MAXFR) REAL,ALLOCATABLE :: W2(:),W3(:),W4(:),W5(:),DSP_A(:) ALLOCATE(W2(MAXFR)) ALLOCATE(W3(MAXFR)) ALLOCATE(W4(MAXFR)) ALLOCATE(W5(MAXFR)) ALLOCATE(DSP_A(MAXFR)) DO I=1,MAXFR DSP_A(I)=DSP1(I) END DO CALL AXMLT1(DSP_A,W2) RETURN END
本來的方法改成這樣:ip
SUBROUTINE AXMLT1(X,Z) C IMPLICIT REAL*8(A-Z) real,allocatable,dimension(:)::X,Z C RETURN END
http://pages.swcp.com/~walt/fortran_store/Html/Info/books/t90_2.htmlget