NFFT Logo 3.0 API Reference
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

reconstruct_data_inh_2d1d.c

00001 #include <stdlib.h>
00002 #include <math.h>
00003 #include <limits.h>
00004 #include "nfft3.h"
00005 #include "util.h"
00006 
00013 void reconstruct(char* filename,int N,int M,int iteration , int weight)
00014 {
00015   int j,k,l;
00016   double time,min_time,max_time,min_inh,max_inh;
00017   double t,real,imag;
00018   double w,epsilon=0.0000003;     /* epsilon is a the break criterium for
00019                                    the iteration */;
00020   mri_inh_2d1d_plan my_plan;
00021   imri_inh_2d1d_plan my_iplan;
00022   FILE* fp,*fw,*fout_real,*fout_imag,*finh,*ftime;
00023   int my_N[3],my_n[3];
00024   int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
00025                       MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE;
00026   unsigned infft_flags = CGNR | PRECOMPUTE_DAMP;
00027 
00028   double Ts;
00029   double W,T;
00030   int N3;
00031   int m=2;
00032   double sigma = 1.25;
00033 
00034   ftime=fopen("readout_time.dat","r");
00035   finh=fopen("inh.dat","r");
00036 
00037   min_time=INT_MAX; max_time=INT_MIN;
00038   for(j=0;j<M;j++)
00039   {
00040     fscanf(ftime,"%le ",&time);
00041     if(time<min_time)
00042       min_time = time;
00043     if(time>max_time)
00044       max_time = time;
00045   }
00046   
00047   fclose(ftime);
00048   
00049   Ts=(min_time+max_time)/2.0;
00050 
00051 
00052   min_inh=INT_MAX; max_inh=INT_MIN;
00053   for(j=0;j<N*N;j++)
00054   {
00055     fscanf(finh,"%le ",&w);
00056     if(w<min_inh)
00057       min_inh = w;
00058     if(w>max_inh)
00059       max_inh = w;
00060   }
00061   fclose(finh);
00062 
00063   N3=ceil((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+(m)/(2*sigma))*4*sigma);
00064   /* N3 has to be even */
00065   if(N3%2!=0)
00066     N3++;
00067   
00068   T=((max_time-min_time)/2.0)/(0.5-((double) (m))/N3);
00069   W=N3/T;
00070 
00071   my_N[0]=N; my_n[0]=ceil(N*sigma);
00072   my_N[1]=N; my_n[1]=ceil(N*sigma);
00073   my_N[2]=N3; my_n[2]=N3;
00074   
00075   /* initialise nfft */ 
00076   mri_inh_2d1d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
00077                       FFTW_MEASURE| FFTW_DESTROY_INPUT);
00078 
00079 
00080   /* precompute lin psi if set */
00081   if(my_plan.plan.nfft_flags & PRE_LIN_PSI)
00082     nfft_precompute_lin_psi(&my_plan.plan);
00083                       
00084   if (weight)
00085     infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
00086 
00087   /* initialise my_iplan, advanced */
00088   imri_inh_2d1d_init_advanced(&my_iplan,&my_plan, infft_flags );
00089 
00090   /* get the weights */
00091   if(my_iplan.flags & PRECOMPUTE_WEIGHT)
00092   {
00093     fw=fopen("weights.dat","r");
00094     for(j=0;j<my_plan.M_total;j++)
00095     {
00096         fscanf(fw,"%le ",&my_iplan.w[j]);
00097     }
00098     fclose(fw);
00099   }
00100                       
00101   /* get the damping factors */
00102   if(my_iplan.flags & PRECOMPUTE_DAMP)
00103   {
00104     for(j=0;j<N;j++){
00105       for(k=0;k<N;k++) {
00106         int j2= j-N/2;
00107         int k2= k-N/2;
00108         double r=sqrt(j2*j2+k2*k2);
00109         if(r>(double) N/2) 
00110           my_iplan.w_hat[j*N+k]=0.0;
00111         else
00112           my_iplan.w_hat[j*N+k]=1.0;
00113       }   
00114     }
00115   }
00116 
00117   fp=fopen(filename,"r");
00118   ftime=fopen("readout_time.dat","r");
00119 
00120   for(j=0;j<my_plan.M_total;j++)
00121   {
00122     fscanf(fp,"%le %le %le %le",&my_plan.plan.x[2*j+0],&my_plan.plan.x[2*j+1],&real,&imag);
00123     my_iplan.y[j]=real+I*imag;
00124     fscanf(ftime,"%le ",&my_plan.t[j]);
00125 
00126     my_plan.t[j] = (my_plan.t[j]-Ts)/T;
00127   }
00128   fclose(fp);
00129   fclose(ftime);
00130 
00131 
00132   finh=fopen("inh.dat","r");
00133   for(j=0;j<N*N;j++)
00134   {
00135     fscanf(finh,"%le ",&my_plan.w[j]);
00136     my_plan.w[j]/=W;
00137   }
00138   fclose(finh);  
00139 
00140     
00141   if(my_plan.plan.nfft_flags & PRE_PSI) {
00142     nfft_precompute_psi(&my_plan.plan);
00143   }
00144   if(my_plan.plan.nfft_flags & PRE_FULL_PSI) {
00145       nfft_precompute_full_psi(&my_plan.plan);
00146   } 
00147 
00148   /* init some guess */
00149   for(j=0;j<my_plan.N_total;j++)
00150   {
00151     my_iplan.f_hat_iter[j]=0.0;
00152   }
00153  
00154   t=nfft_second();
00155   
00156   /* inverse trafo */
00157   imri_inh_2d1d_before_loop(&my_iplan);
00158   for(l=0;l<iteration;l++)
00159   {
00160     /* break if dot_r_iter is smaller than epsilon*/
00161     if(my_iplan.dot_r_iter<epsilon)
00162     break;
00163     fprintf(stderr,"%e,  %i of %i\n",sqrt(my_iplan.dot_r_iter),
00164     l+1,iteration);
00165     imri_inh_2d1d_loop_one_step(&my_iplan);
00166   }
00167 
00168   t=nfft_second()-t;
00169 #ifdef HAVE_MALLINFO
00170   fprintf(stderr,"time: %e seconds mem: %i \n",t,nfft_total_used_memory());
00171 #else
00172   fprintf(stderr,"time: %e seconds mem: mallinfo not available\n",t);
00173 #endif
00174   
00175   fout_real=fopen("output_real.dat","w");
00176   fout_imag=fopen("output_imag.dat","w");
00177   
00178   for (j=0;j<N*N;j++) {
00179     /* Verschiebung wieder herausrechnen */
00180     my_iplan.f_hat_iter[j]*=cexp(-2.0*I*PI*Ts*my_plan.w[j]*W);
00181     
00182     fprintf(fout_real,"%le ",creal(my_iplan.f_hat_iter[j]));
00183     fprintf(fout_imag,"%le ",cimag(my_iplan.f_hat_iter[j]));
00184   }
00185 
00186   fclose(fout_real);
00187   fclose(fout_imag);
00188   imri_inh_2d1d_finalize(&my_iplan);
00189   mri_inh_2d1d_finalize(&my_plan);
00190 }
00191 
00192 
00193 int main(int argc, char **argv)
00194 {
00195   if (argc <= 5) {
00196 
00197     printf("usage: ./reconstruct_data_inh_2d1d FILENAME N M ITER WEIGHTS\n");
00198     return 1;
00199   }
00200   
00201   reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]));
00202 
00203   return 1;
00204 }
00205 /* \} */

Generated on 1 Nov 2006 by Doxygen 1.4.4