The work array passed to the FFT routine needs to be increased in size from 3*MAXDIM elements (for NAG) to 6*MAXDIM+15 (for FFTPACK). Here, MAXDIM is the size of the largest array dimension.
Replace the call
DOUBLE PRECISION X(N), Y(N), WORK( 3*MAXDIM )
INTEGER ND( NDIM )
CALL C06FJF( NDIM, ND, N, X, Y, WORK, LWORK, IFAIL )
with
DOUBLE PRECISION X(N), Y(N), WORK( 6*MAXDIM + 15 )
INTEGER ND( NDIM )
CALL PDA_DNFFTF( NDIM, ND, X ,Y, WORK, ISTAT )
IF( ISTAT .NE. 0 ) THEN
This means that NDIM was either less than 1 or greater than 20.
Report a programming error!
END IF
PDA [1ex