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

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409