Tomer Cohen
11-16-2004, 05:59 PM
Did anyone had problems running the program using rlft3
from the NR example book (page 204)?
Although I have copy pasted the code to rlft3 and fourn from the site, after the forward and backward transform the values in data1 are much larger than the values in data2 but in a non uniform way.
In fact, for a 8*8*32 array they are too big to be represented as long numbers.
Anyway, here is the code
int main(void) {
TInt32 idm=(-3);
TUint32 err,i,j,k,l,nn1=NX,nn2=NY,nn3=NZ;
TReal32 ***data1,***data2,fnorm,**speq1;
// Allocate resources
fnorm=(float)nn1*(float)nn2*(float)nn3/2.0;
data1=f3tensor(1,nn1,1,nn2,1,nn3);
data2=f3tensor(1,nn1,1,nn2,1,nn3);
speq1=matrix(1,nn1,1,nn2<<1);
// Populate data1 and save a reference in data2
for(i=1;i<=nn1;i++)
{
for(j=1;j<=nn2;j++)
for(k=1;k<=nn3;k++)
data2[i][j][k]=fnorm*(data1[i][j][k]=2*ran1(&idm)-1);
}
// Perform forward and backward fourier transform
rFourier3D(data1,speq1,nn1,nn2,nn3,1);
rFourier3D(data1,speq1,nn1,nn2,nn3,-1);
// Compare results
err=compare("data",data1,data2,nn1,nn2,nn3,EPS);
if (err)
{
printf("Comparison error at tolerance %12.6f\n",EPS);
printf("Total number of errors is: %d\n",err);
}
else
printf(,"Data compares OK relative to tolerance %12.6f\n",EPS);
// Free resources
free_matrix(speq1,1,nn1,1,nn2<<1);
free_f3tensor(data2,1,nn1,1,nn2,1,nn3);
free_f3tensor(data1,1,nn1,1,nn2,1,nn3);
return 0;
}
from the NR example book (page 204)?
Although I have copy pasted the code to rlft3 and fourn from the site, after the forward and backward transform the values in data1 are much larger than the values in data2 but in a non uniform way.
In fact, for a 8*8*32 array they are too big to be represented as long numbers.
Anyway, here is the code
int main(void) {
TInt32 idm=(-3);
TUint32 err,i,j,k,l,nn1=NX,nn2=NY,nn3=NZ;
TReal32 ***data1,***data2,fnorm,**speq1;
// Allocate resources
fnorm=(float)nn1*(float)nn2*(float)nn3/2.0;
data1=f3tensor(1,nn1,1,nn2,1,nn3);
data2=f3tensor(1,nn1,1,nn2,1,nn3);
speq1=matrix(1,nn1,1,nn2<<1);
// Populate data1 and save a reference in data2
for(i=1;i<=nn1;i++)
{
for(j=1;j<=nn2;j++)
for(k=1;k<=nn3;k++)
data2[i][j][k]=fnorm*(data1[i][j][k]=2*ran1(&idm)-1);
}
// Perform forward and backward fourier transform
rFourier3D(data1,speq1,nn1,nn2,nn3,1);
rFourier3D(data1,speq1,nn1,nn2,nn3,-1);
// Compare results
err=compare("data",data1,data2,nn1,nn2,nn3,EPS);
if (err)
{
printf("Comparison error at tolerance %12.6f\n",EPS);
printf("Total number of errors is: %d\n",err);
}
else
printf(,"Data compares OK relative to tolerance %12.6f\n",EPS);
// Free resources
free_matrix(speq1,1,nn1,1,nn2<<1);
free_f3tensor(data2,1,nn1,1,nn2,1,nn3);
free_f3tensor(data1,1,nn1,1,nn2,1,nn3);
return 0;
}