![]() |
NFFT
3.3.1
|
00001 /* 00002 * Copyright (c) 2002, 2016 Jens Keiner, Stefan Kunis, Daniel Potts 00003 * 00004 * This program is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU General Public License as published by the Free Software 00006 * Foundation; either version 2 of the License, or (at your option) any later 00007 * version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU General Public License along with 00015 * this program; if not, write to the Free Software Foundation, Inc., 51 00016 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 #include <math.h> 00019 #include <stdlib.h> 00020 #include <complex.h> 00021 00022 #include "nfft3.h" 00023 00033 static void reconstruct(char* filename,int N,int M,int iteration, int weight) 00034 { 00035 int j,k,l; /* some variables */ 00036 double t0, t1; 00037 double real,imag,t; /* to read the real and imag part of a complex number */ 00038 nfft_plan my_plan; /* plan for the two dimensional nfft */ 00039 solver_plan_complex my_iplan; /* plan for the two dimensional infft */ 00040 FILE* fin; /* input file */ 00041 FILE* fout_real; /* output file */ 00042 FILE* fout_imag; /* output file */ 00043 int my_N[2],my_n[2]; /* to init the nfft */ 00044 double epsilon=0.0000003; /* epsilon is a the break criterium for 00045 the iteration */ 00046 unsigned infft_flags = CGNR | PRECOMPUTE_DAMP; /* flags for the infft*/ 00047 int m = 6; 00048 double alpha = 2.0; 00049 /* initialise my_plan */ 00050 my_N[0]=N; my_n[0]=ceil(N*alpha); 00051 my_N[1]=N; my_n[1]=ceil(N*alpha); 00052 nfft_init_guru(&my_plan, 2, my_N, M, my_n, m, PRE_PHI_HUT| PRE_PSI| 00053 MALLOC_X| MALLOC_F_HAT| MALLOC_F| 00054 FFTW_INIT| FFT_OUT_OF_PLACE, 00055 FFTW_MEASURE| FFTW_DESTROY_INPUT); 00056 00057 /* precompute lin psi if set */ 00058 if(my_plan.flags & PRE_LIN_PSI) 00059 nfft_precompute_lin_psi(&my_plan); 00060 00061 /* set the flags for the infft*/ 00062 if (weight) 00063 infft_flags = infft_flags | PRECOMPUTE_WEIGHT; 00064 00065 /* initialise my_iplan, advanced */ 00066 solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)&my_plan, infft_flags ); 00067 00068 /* get the weights */ 00069 if(my_iplan.flags & PRECOMPUTE_WEIGHT) 00070 { 00071 fin=fopen("weights.dat","r"); 00072 for(j=0;j<my_plan.M_total;j++) 00073 { 00074 fscanf(fin,"%le ",&my_iplan.w[j]); 00075 } 00076 fclose(fin); 00077 } 00078 00079 /* get the damping factors */ 00080 if(my_iplan.flags & PRECOMPUTE_DAMP) 00081 { 00082 for(j=0;j<N;j++){ 00083 for(k=0;k<N;k++) { 00084 int j2= j-N/2; 00085 int k2= k-N/2; 00086 double r=sqrt(j2*j2+k2*k2); 00087 if(r>(double) N/2) 00088 my_iplan.w_hat[j*N+k]=0.0; 00089 else 00090 my_iplan.w_hat[j*N+k]=1.0; 00091 } 00092 } 00093 } 00094 00095 /* open the input file */ 00096 fin=fopen(filename,"r"); 00097 00098 /* read x,y,freal and fimag from the knots */ 00099 for(j=0;j<my_plan.M_total;j++) 00100 { 00101 fscanf(fin,"%le %le %le %le ",&my_plan.x[2*j+0],&my_plan.x[2*j+1], 00102 &real,&imag); 00103 my_iplan.y[j] = real + _Complex_I*imag; 00104 } 00105 00106 fclose(fin); 00107 00108 /* precompute psi */ 00109 if(my_plan.flags & PRE_PSI) 00110 nfft_precompute_psi(&my_plan); 00111 00112 /* precompute full psi */ 00113 if(my_plan.flags & PRE_FULL_PSI) 00114 nfft_precompute_full_psi(&my_plan); 00115 00116 /* init some guess */ 00117 for(k=0;k<my_plan.N_total;k++) 00118 my_iplan.f_hat_iter[k]=0.0; 00119 00120 t0 = nfft_clock_gettime_seconds(); 00121 00122 /* inverse trafo */ 00123 solver_before_loop_complex(&my_iplan); 00124 for(l=0;l<iteration;l++) 00125 { 00126 /* break if dot_r_iter is smaller than epsilon*/ 00127 if(my_iplan.dot_r_iter<epsilon) 00128 break; 00129 fprintf(stderr,"%e, %i of %i\n",sqrt(my_iplan.dot_r_iter), 00130 l+1,iteration); 00131 solver_loop_one_step_complex(&my_iplan); 00132 } 00133 00134 00135 t1 = nfft_clock_gettime_seconds(); 00136 t=t1-t0; 00137 00138 fout_real=fopen("output_real.dat","w"); 00139 fout_imag=fopen("output_imag.dat","w"); 00140 00141 for(k=0;k<my_plan.N_total;k++) { 00142 fprintf(fout_real,"%le ", creal(my_iplan.f_hat_iter[k])); 00143 fprintf(fout_imag,"%le ", cimag(my_iplan.f_hat_iter[k])); 00144 } 00145 00146 fclose(fout_real); 00147 fclose(fout_imag); 00148 00149 /* finalize the infft */ 00150 solver_finalize_complex(&my_iplan); 00151 00152 /* finalize the nfft */ 00153 nfft_finalize(&my_plan); 00154 } 00155 00156 int main(int argc, char **argv) 00157 { 00158 if (argc <= 5) { 00159 printf("usage: ./reconstruct_data_2d FILENAME N M ITER WEIGHTS\n"); 00160 return 1; 00161 } 00162 00163 reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5])); 00164 00165 return 1; 00166 } 00167 /* \} */