48 double GLOBAL_elapsed_time;
 
   67   int R2=2*ceil(sqrt(2.0)*R/2);
 
   71   for(t=-T/2; t<T/2; t++)
 
   73     for(r=-R2/2; r<R2/2; r++)
 
   75       xx = (double)r/R*cos(
PI*t/T);
 
   76       yy = (double)r/R*sin(
PI*t/T);
 
   78       if ( ((-0.5-1.0/(
double)R)<=xx) & (xx<=(0.5+1.0/(
double)R)) &
 
   79         ((-0.5-1.0/(
double)R)<=yy) & (yy<=(0.5+1.0/(
double)R)) )
 
   87           w[M] = fabs((
double)r);
 
  106 static int mpolar_dft(fftw_complex *f_hat, 
int NN, fftw_complex *f, 
int T, 
int R, 
int m)
 
  117   N[0]=NN; n[0]=2*N[0];                 
 
  118   N[1]=NN; n[1]=2*N[1];                 
 
  120   x = (
double *)
nfft_malloc(5*(T/2)*R*(
sizeof(double)));
 
  124   w = (
double *)
nfft_malloc(5*(T*R)/4*(
sizeof(double)));
 
  130   nfft_init_guru(&my_nfft_plan, 2, N, M, n, m,
 
  131                   PRE_PHI_HUT| PRE_PSI| MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
 
  132                   FFTW_MEASURE| FFTW_DESTROY_INPUT);
 
  135   for(j=0;j<my_nfft_plan.
M_total;j++)
 
  137     my_nfft_plan.
x[2*j+0] = x[2*j+0];
 
  138     my_nfft_plan.
x[2*j+1] = x[2*j+1];
 
  142   for(k=0;k<my_nfft_plan.
N_total;k++)
 
  143     my_nfft_plan.
f_hat[k] = f_hat[k];
 
  148   nfft_trafo_direct(&my_nfft_plan);
 
  151   GLOBAL_elapsed_time = nfft_elapsed_seconds(t1,t0);
 
  154   for(j=0;j<my_nfft_plan.
M_total;j++)
 
  155     f[j] = my_nfft_plan.
f[j];
 
  158   nfft_finalize(&my_nfft_plan);
 
  166 static int mpolar_fft(fftw_complex *f_hat, 
int NN, fftw_complex *f, 
int T, 
int R, 
int m)
 
  177   N[0]=NN; n[0]=2*N[0];                 
 
  178   N[1]=NN; n[1]=2*N[1];                 
 
  180   x = (
double *)
nfft_malloc(5*T*R/2*(
sizeof(
double)));
 
  184   w = (
double *)
nfft_malloc(5*T*R/4*(
sizeof(
double)));
 
  190   nfft_init_guru(&my_nfft_plan, 2, N, M, n, m,
 
  191                   PRE_PHI_HUT| PRE_PSI| MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
 
  192                   FFTW_MEASURE| FFTW_DESTROY_INPUT);
 
  196   for(j=0;j<my_nfft_plan.
M_total;j++)
 
  198     my_nfft_plan.
x[2*j+0] = x[2*j+0];
 
  199     my_nfft_plan.
x[2*j+1] = x[2*j+1];
 
  207     nfft_precompute_psi(&my_nfft_plan);
 
  210     nfft_precompute_full_psi(&my_nfft_plan);
 
  213   for(k=0;k<my_nfft_plan.
N_total;k++)
 
  214     my_nfft_plan.
f_hat[k] = f_hat[k];
 
  222   GLOBAL_elapsed_time = nfft_elapsed_seconds(t1,t0);
 
  225   for(j=0;j<my_nfft_plan.
M_total;j++)
 
  226     f[j] = my_nfft_plan.
f[j];
 
  229   nfft_finalize(&my_nfft_plan);
 
  250   N[0]=NN; n[0]=2*N[0];                 
 
  251   N[1]=NN; n[1]=2*N[1];                 
 
  253   x = (
double *)
nfft_malloc(5*T*R/2*(
sizeof(
double)));
 
  257   w = (
double *)
nfft_malloc(5*T*R/4*(
sizeof(
double)));
 
  263   nfft_init_guru(&my_nfft_plan, 2, N, M, n, m,
 
  264                   PRE_PHI_HUT| PRE_PSI| MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
 
  265                   FFTW_MEASURE| FFTW_DESTROY_INPUT);
 
  268     solver_init_advanced_complex(&my_infft_plan,(
nfft_mv_plan_complex*)(&my_nfft_plan), CGNR | PRECOMPUTE_WEIGHT );
 
  271   for(j=0;j<my_nfft_plan.
M_total;j++)
 
  273     my_nfft_plan.
x[2*j+0] = x[2*j+0];
 
  274     my_nfft_plan.
x[2*j+1] = x[2*j+1];
 
  275     my_infft_plan.
y[j]    = f[j];
 
  276     my_infft_plan.
w[j]    = w[j];
 
  284     nfft_precompute_psi(&my_nfft_plan);
 
  287     nfft_precompute_full_psi(&my_nfft_plan);
 
  291  if(my_infft_plan.
flags & PRECOMPUTE_DAMP)
 
  292    for(j=0;j<my_nfft_plan.
N[0];j++)
 
  293      for(k=0;k<my_nfft_plan.
N[1];k++)
 
  295         my_infft_plan.
w_hat[j*my_nfft_plan.
N[1]+k]=
 
  296           (sqrt(pow(j-my_nfft_plan.
N[0]/2,2)+pow(k-my_nfft_plan.
N[1]/2,2))>(my_nfft_plan.
N[0]/2)?0:1);
 
  300   for(k=0;k<my_nfft_plan.
N_total;k++)
 
  301       my_infft_plan.
f_hat_iter[k] = 0.0 + _Complex_I*0.0;
 
  306   solver_before_loop_complex(&my_infft_plan);
 
  311     for(k=0;k<my_nfft_plan.
N_total;k++)
 
  316     for(l=1;l<=
max_i;l++)
 
  323   GLOBAL_elapsed_time = nfft_elapsed_seconds(t1,t0);
 
  326   for(k=0;k<my_nfft_plan.
N_total;k++)
 
  331   nfft_finalize(&my_nfft_plan);
 
  342   fftw_plan my_fftw_plan;
 
  343   fftw_complex *f_hat,*f;
 
  345   double t_fft, t_dft_mpolar;
 
  347   f_hat = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*N*N);
 
  348   f     = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*(T*R/4)*5);
 
  350   my_fftw_plan = fftw_plan_dft_2d(N,N,f_hat,f,FFTW_BACKWARD,FFTW_MEASURE);
 
  353     f_hat[k] = (((
double)rand())/RAND_MAX) + _Complex_I* (((double)rand())/RAND_MAX);
 
  356   for(m=0;m<65536/N;m++)
 
  358       fftw_execute(my_fftw_plan);
 
  363   GLOBAL_elapsed_time = nfft_elapsed_seconds(t1,t0);
 
  364   t_fft=N*GLOBAL_elapsed_time/65536;
 
  369       t_dft_mpolar=GLOBAL_elapsed_time;
 
  372   for (m=3; m<=9; m+=3)
 
  375         fprintf(fp,
"%d\t&\t&\t%1.1e&\t%1.1e&\t%d\t",N,t_fft,t_dft_mpolar,m);
 
  378     fprintf(fp,
"%d\t&\t&\t%1.1e&\t       &\t%d\t",N,t_fft,m);
 
  380     fprintf(fp,
"  \t&\t&\t       &\t       &\t%d\t",m);
 
  382       printf(
"N=%d\tt_fft=%1.1e\tt_dft_mpolar=%1.1e\tm=%d\t",N,t_fft,t_dft_mpolar,m);
 
  385       fprintf(fp,
"%1.1e&\t",GLOBAL_elapsed_time);
 
  386       printf(
"t_mpolar=%1.1e\t",GLOBAL_elapsed_time);
 
  389   fprintf(fp,
"%1.1e\\\\\\hline\n",GLOBAL_elapsed_time);
 
  391   fprintf(fp,
"%1.1e\\\\\n",GLOBAL_elapsed_time);
 
  392       printf(
"t_impolar=%1.1e\n",GLOBAL_elapsed_time);
 
  404 int main(
int argc,
char **argv)
 
  410   fftw_complex *f_hat, *f, *f_direct, *f_tilde;
 
  414   double temp1, temp2, E_max=0.0;
 
  421     printf(
"mpolar_fft_test N T R \n");
 
  423     printf(
"N          mpolar FFT of size NxN    \n");
 
  424     printf(
"T          number of slopes          \n");
 
  425     printf(
"R          number of offsets         \n");
 
  428     printf(
"\nHence, comparison FFTW, mpolar FFT and inverse mpolar FFT\n");
 
  429     fp1=fopen(
"mpolar_comparison_fft.dat",
"w");
 
  432     for (logN=4; logN<=8; logN++)
 
  433   comparison_fft(fp1,(1U<< logN), 3*(1U<< logN), 3*(1U<< (logN-1)));
 
  442   printf(
"N=%d, modified polar grid with T=%d, R=%d => ",N,T,R);
 
  444   x = (
double *)
nfft_malloc(5*T*R/2*(
sizeof(
double)));
 
  445   w = (
double *)
nfft_malloc(5*T*R/4*(
sizeof(
double)));
 
  447   f_hat    = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*N*N);
 
  448   f        = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*1.25*T*R);  
 
  449   f_direct = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*1.25*T*R);
 
  450   f_tilde  = (fftw_complex *)
nfft_malloc(
sizeof(fftw_complex)*N*N);
 
  456   fp1=fopen(
"input_data_r.dat",
"r");
 
  457   fp2=fopen(
"input_data_i.dat",
"r");
 
  458   if ((fp1==NULL) || (fp2==NULL))
 
  462     fscanf(fp1,
"%le ",&temp1);
 
  463     fscanf(fp2,
"%le ",&temp2);
 
  464     f_hat[k]=temp1+ _Complex_I*temp2;
 
  474   printf(
"\nTest of the mpolar FFT: \n");
 
  475   fp1=fopen(
"mpolar_fft_error.dat",
"w+");
 
  476   for (m=1; m<=12; m++)
 
  482     E_max=X(error_l_infty_complex)(f_direct,f,M);
 
  483     printf(
"m=%2d: E_max = %e\n",m,E_max);
 
  484     fprintf(fp1,
"%e\n",E_max);
 
  489   for (m=3; m<=9; m+=3)
 
  491     printf(
"\nTest of the inverse mpolar FFT for m=%d: \n",m);
 
  492     sprintf(filename,
"mpolar_ifft_error%d.dat",m);
 
  493     fp1=fopen(filename,
"w+");
 
  494     for (max_i=0; max_i<=20; max_i+=2)
 
  500       E_max=X(error_l_infty_complex)(f_hat,f_tilde,N*N);
 
  501       printf(
"%3d iterations: E_max = %e\n",max_i,E_max);
 
  502       fprintf(fp1,
"%e\n",E_max);