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