Software Archive
Read-only legacy content
17061 Discussions

Incorrect use of DFFT2D function in DLL written on Compaq Visual Fortran 6.5

Intel_C_Intel
Employee
478 Views
Dear programmers!
We have confronted with some difficulties during writing of a DLL for 2-
Dimensional Fourie transformation.
There is our problem in a nutshell.
We pass a 1-Dimensional array DataIn [H*W] from C++ Builder to Compaq Visual
Fortran, where H and W . are upper limits of 2-Dimensional array A, got from
DataIn (see code below). DataOUT_R, DataOUT_I, DataOUT_ABS are 1-Dimensional
arrays passed from Compaq Visual Fortran to C++ Builder. DataOUT_R stores real
parts of Fourie image of A (2-D array F), DataOUT_I . imaginary parts and,
DataOUT_ABS . amplitudes. The arrays are got from .unfolding. F to 2 1-D arrays
(one for real and one for imaginary part). The last 1-D array was created from
the previous two. (A and F are complex arrays).

We.ve debugged the code line by line. First of all we make sure that passing of
an initial array from C++ Builder to Compaq Visual Fortran is correct. Then we
tested that initial 1-D array correctly folds to 2-D complex array. But then we
faced with a mistake. We call a DFFT2D function for 2-D Fourie transformation
and pass to it several parameters. The function generates 2-D complex array
with the same upper limits as A. The infill of the array is incorrect. There
are many zero values in it, what is impossible for values stored in A.

We listed the DLL code. .Write. commands are commented with .!. and we used by
us for debugging. The code is free from compiling and linker errors. We faced
with a logical substantial error. Please, help us to debug the DLL.

Thank you, Lev Liberant and Konstantin Kalinkin (Moscow, Russia)

SUBROUTINE FSUB (DataIN, H, W, DataOUT_R, DataOUT_I, DataOUT_ABS) 
USE DFIMSL 
IMPLICIT NONE 
 
! If we're building a DLL, specify that DLL_ROUT is  
! exported to a DLL. Key this off of the preprocessor 
! symbol _DLL which is automatically defined if we're 
! building a DLL. 
 
!DEC$ IF DEFINED (_DLL) 
!DEC$ ATTRIBUTES DLLEXPORT :: FSUB 
!DEC$ END IF 
INTEGER*4 nra,nca, Lda, Ldcoef 
INTEGER*4 I,COUNT_I,COUNT_J 
REAL*8 DataMax 
INTEGER,INTENT(IN) :: H,W 
REAL*8,INTENT(IN) :: DataIN (*) 
REAL*8,INTENT(OUT) :: DataOUT_R (*) 
REAL*8,INTENT(OUT) :: DataOUT_I (*) 
REAL*8,INTENT(OUT) :: DataOUT_ABS (*) 
COMPLEX*16 A(1500,1500), F(1500,1500) 
OPEN (1, FILE = 'C:fourie.txt') 
nra=H 
nca=W 
Lda=W 
Ldcoef=W 
DataMax=0. 
 
!WRITE (1,*) 'W=',W 
!WRITE (1,*) 'H=',H 
 
COUNT_I=1 
COUNT_J=1 
 
DO I=1,W*H 
A(COUNT_I,COUNT_J)=CMPLX(DataIN(I),0.0)  
!WRITE (1,*) 'A=',DREAL(A(COUNT_I,COUNT_J)), ' ', DIMAG(A(COUNT_I,COUNT_J)) 
 
COUNT_J=COUNT_J+1 
IF (COUNT_J>W) THEN 
COUNT_J=1 
COUNT_I=COUNT_I+1 
END IF 
END DO 
 
CALL DFFT2D(nra,nca,A,Lda,F,Ldcoef) 
 
COUNT_I=1 
COUNT_J=1 
DO I=1,W*H 
 
DataOUT_R(I)=DREAL(F(COUNT_I,COUNT_J)) 
DataOUT_I(I)=DIMAG(F(COUNT_I,COUNT_J)) 
!WRITE (1,*) 'DataOUT_R(I)', DataOUT_R(I), ' DataOUT_I(I)', DataOUT_I(I) 
DataOUT_ABS(I)=ABS(F(COUNT_I,COUNT_J)) 
IF (DataOUT_ABS(I)>DataMax) DataMax=DataOUT_ABS(I) 
 
COUNT_J=COUNT_J+1 
IF (COUNT_J>W) THEN 
COUNT_J=1 
COUNT_I=COUNT_I+1 
END IF 
 
END DO 
 
DO I=1,W*H 
DataOUT_ABS(I)=255*DataOUT_ABS(I)/DataMax 
END DO 
 
CLOSE (1) 
RETURN 
END
0 Kudos
1 Reply
hbell
Beginner
478 Views
Normally, FFT routines are dimensioned in powers of 2. I see neither your arrays nor their physical dimensions are a power of two. Try calling this routine with a dimension 16384 (=2**14). Just pad the extra vector elements with 0's.
The 255 in the last loop also doesn't look right.
0 Kudos
Reply