fftpack 的分段错误

Segmentation fault with fftpack

我正在尝试使用 fftpack(特别是 rffti.f、rffti1.f、rfftf.f、rfftf1.f、radf4.f、radf2.f , radf3.f, radf5.f, radfg.f) 使用此测试代码从 https://www.netlib.org/fftpack/index.html 下载:

program test
implicit none
integer,parameter:: n=100
real,dimension(n):: x,y
integer:: i 
real:: pi = 3.1415923535

x= [(i, i=1,n)]
y= sin((2*pi/100)*x)

call RFFTI(100,y)

end program test

,编译和运行:

gfortran -Wall -Wextra -o program.out \
rffti.f rffti1.f rfftf.f rfftf1.f radf4.f radf2.f radf3.f radf5.f radfg.f test.f90

./program.out

,我得到这个运行时错误:

程序收到信号 SIGSEGV:分段错误 - 内存引用无效。

此错误的回溯: do.sh:第 6 行:9069 分段错误(核心已转储)./program.out

除此错误外,我收到以下警告:

rffti1.f:8:72:

    8 |       IF (J-4) 102,102,103
      |                                                                        1
Warning: Fortran 2018 deleted feature: Arithmetic IF statement at (1)
rffti1.f:14:72:

   14 |       IF (NR) 101,105,101
      |                                                                        1
Warning: Fortran 2018 deleted feature: Arithmetic IF statement at (1)
rffti1.f:24:11:

   24 |       IFAC(3) = 2
      |           1
Warning: Array reference at (1) is out of bounds (3 > 1) in dimension 1
rffti1.f:27:11:

   27 |       IFAC(2) = NF
      |           1
Warning: Array reference at (1) is out of bounds (2 > 1) in dimension 1
rffti1.f:35:19:

   34 |       DO 110 K1=1,NFM1
      |                                                                        2
   35 |          IP = IFAC(K1+2)
      |                   1
Warning: Array reference at (1) out of bounds (3 > 1) in loop beginning at (2)
rfftf1.f:3:16:

    3 |       NF = IFAC(2)
      |                1
Warning: Array reference at (1) is out of bounds (2 > 1) in dimension 1
radf4.f:13:72:

   13 |       IF (IDO-2) 107,105,102
      |                                                                        1
Warning: Fortran 2018 deleted feature: Arithmetic IF statement at (1)
radf4.f:18:43:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
   17 |             IC = IDP2-I
   18 |             CR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf4.f:19:41:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   19 |             CI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf4.f:20:43:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   20 |             CR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf4.f:21:41:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   21 |             CI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf4.f:22:43:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   22 |             CR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf4.f:23:41:

   16 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   23 |             CI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf2.f:8:72:

    8 |       IF (IDO-2) 107,105,102
      |                                                                        1
Warning: Fortran 2018 deleted feature: Arithmetic IF statement at (1)
radf2.f:13:43:

   11 |          DO 103 I=3,IDO,2
      |                                                                        2
   12 |             IC = IDP2-I
   13 |             TR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf2.f:14:41:

   11 |          DO 103 I=3,IDO,2
      |                                                                        2
......
   14 |             TI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf3.f:16:43:

   14 |          DO 102 I=3,IDO,2
      |                                                                        2
   15 |             IC = IDP2-I
   16 |             DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf3.f:17:41:

   14 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   17 |             DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf3.f:18:43:

   14 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   18 |             DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf3.f:19:41:

   14 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   19 |             DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:22:43:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
   21 |             IC = IDP2-I
   22 |             DR2 = WA1(I-2)*CC(I-1,K,2)+WA1(I-1)*CC(I,K,2)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:23:41:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   23 |             DI2 = WA1(I-2)*CC(I,K,2)-WA1(I-1)*CC(I-1,K,2)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:24:43:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   24 |             DR3 = WA2(I-2)*CC(I-1,K,3)+WA2(I-1)*CC(I,K,3)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:25:41:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   25 |             DI3 = WA2(I-2)*CC(I,K,3)-WA2(I-1)*CC(I-1,K,3)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:26:43:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   26 |             DR4 = WA3(I-2)*CC(I-1,K,4)+WA3(I-1)*CC(I,K,4)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:27:41:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   27 |             DI4 = WA3(I-2)*CC(I,K,4)-WA3(I-1)*CC(I-1,K,4)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:28:43:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   28 |             DR5 = WA4(I-2)*CC(I-1,K,5)+WA4(I-1)*CC(I,K,5)
      |                                           1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)
radf5.f:29:41:

   20 |          DO 102 I=3,IDO,2
      |                                                                        2
......
   29 |             DI5 = WA4(I-2)*CC(I,K,5)-WA4(I-1)*CC(I-1,K,5)
      |                                         1
Warning: Array reference at (1) out of bounds (2 > 1) in loop beginning at (2)

RFFTI是一个初始化例程,将一些工作数据准备到一个特殊的工作数组中。

  SUBROUTINE RFFTI (N,WSAVE)
  DIMENSION       WSAVE(1)

(1) 只是一种过时且非常不幸的写法 (*)

您必须阅读 the manual 并了解 WSAVE 数组的大小。请注意,它是用于内部数据的特殊工作数组,不适用于您要转换的数据。

来自手册:

wsave
a work array which must be dimensioned at least 2*n+15. the same work array can be used for both rfftf and rfftb as long as n remains unchanged. different wsave arrays are required for different values of n. the contents of wsave must not be changed between calls of rfftf or rfftb.