NFFT Logo 3.2.3
reconstruct_data_inh_nnfft.c
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: reconstruct_data_inh_nnfft.c 3896 2012-10-10 12:19:26Z tovo $ */
20 #include "config.h"
21 
22 #include <stdlib.h>
23 #include <math.h>
24 #include <limits.h>
25 #ifdef HAVE_COMPLEX_H
26 #include <complex.h>
27 #endif
28 
29 #include "nfft3util.h"
30 #include "nfft3.h"
31 #include "infft.h"
32 
42 static void reconstruct(char* filename,int N,int M,int iteration, int weight)
43 {
44  int j,k,l; /* some variables */
45  nnfft_plan my_plan; /* plan for the two dimensional nfft */
46  solver_plan_complex my_iplan; /* plan for the two dimensional infft */
47  FILE* fin; /* input file */
48  FILE* finh;
49  FILE* ftime;
50  FILE* fout_real; /* output file */
51  FILE* fout_imag; /* output file */
52  int my_N[3],my_n[3]; /* to init the nfft */
53  ticks t0, t1;
54  double t,epsilon=0.0000003; /* epsilon is a the break criterium for
55  the iteration */
56  unsigned infft_flags = CGNR | PRECOMPUTE_DAMP; /* flags for the infft*/
57  double time,min_time,max_time,min_inh,max_inh;
58  double real,imag;
59  double *w;
60 
61  double Ts;
62  double W;
63  int N3;
64  int m=2;
65  double sigma = 1.25;
66 
67  w = (double*)nfft_malloc(N*N*sizeof(double));
68 
69  ftime=fopen("readout_time.dat","r");
70  finh=fopen("inh.dat","r");
71 
72  min_time=INT_MAX; max_time=INT_MIN;
73  for(j=0;j<M;j++)
74  {
75  fscanf(ftime,"%le ",&time);
76  if(time<min_time)
77  min_time = time;
78  if(time>max_time)
79  max_time = time;
80  }
81 
82  fclose(ftime);
83 
84  Ts=(min_time+max_time)/2.0;
85 
86  min_inh=INT_MAX; max_inh=INT_MIN;
87  for(j=0;j<N*N;j++)
88  {
89  fscanf(finh,"%le ",&w[j]);
90  if(w[j]<min_inh)
91  min_inh = w[j];
92  if(w[j]>max_inh)
93  max_inh = w[j];
94  }
95  fclose(finh);
96 
97  N3=ceil((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0)*4);
98 
99 
100  W=NFFT_MAX(fabs(min_inh),fabs(max_inh))*2.0;
101 
102  fprintf(stderr,"3: %i %e %e %e %e %e %e\n",N3,W,min_inh,max_inh,min_time,max_time,Ts);
103 
104  /* initialise my_plan */
105  my_N[0]=N;my_n[0]=ceil(N*sigma);
106  my_N[1]=N; my_n[1]=ceil(N*sigma);
107  my_N[2]=N3; my_n[2]=ceil(N3*sigma);
108  nnfft_init_guru(&my_plan, 3, N*N, M, my_N,my_n,m,
109  PRE_PSI| PRE_PHI_HUT| MALLOC_X| MALLOC_V| MALLOC_F_HAT| MALLOC_F );
110 
111  /* precompute lin psi if set */
112  if(my_plan.nnfft_flags & PRE_LIN_PSI)
113  nnfft_precompute_lin_psi(&my_plan);
114 
115  /* set the flags for the infft*/
116  if (weight)
117  infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
118 
119  /* initialise my_iplan, advanced */
120  solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)(&my_plan), infft_flags );
121 
122  /* get the weights */
123  if(my_iplan.flags & PRECOMPUTE_WEIGHT)
124  {
125  fin=fopen("weights.dat","r");
126  for(j=0;j<my_plan.M_total;j++)
127  {
128  fscanf(fin,"%le ",&my_iplan.w[j]);
129  }
130  fclose(fin);
131  }
132 
133  /* get the damping factors */
134  if(my_iplan.flags & PRECOMPUTE_DAMP)
135  {
136  for(j=0;j<N;j++){
137  for(k=0;k<N;k++) {
138  int j2= j-N/2;
139  int k2= k-N/2;
140  double r=sqrt(j2*j2+k2*k2);
141  if(r>(double) N/2)
142  my_iplan.w_hat[j*N+k]=0.0;
143  else
144  my_iplan.w_hat[j*N+k]=1.0;
145  }
146  }
147  }
148 
149  /* open the input file */
150  fin=fopen(filename,"r");
151  ftime=fopen("readout_time.dat","r");
152 
153  for(j=0;j<my_plan.M_total;j++)
154  {
155  fscanf(fin,"%le %le %le %le ",&my_plan.x[3*j+0],&my_plan.x[3*j+1],&real,&imag);
156  my_iplan.y[j]=real+ _Complex_I*imag;
157  fscanf(ftime,"%le ",&my_plan.x[3*j+2]);
158 
159  my_plan.x[3*j+2] = (my_plan.x[3*j+2]-Ts)*W/N3;
160  }
161 
162  for(j=0;j<N;j++)
163  {
164  for(l=0;l<N;l++)
165  {
166  my_plan.v[3*(N*j+l)+0]=(((double) j) -(((double) N)/2.0))/((double) N);
167  my_plan.v[3*(N*j+l)+1]=(((double) l) -(((double) N)/2.0))/((double) N);
168  my_plan.v[3*(N*j+l)+2] = w[N*j+l]/W ;
169  }
170  }
171 
172  /* precompute psi */
173  if(my_plan.nnfft_flags & PRE_PSI) {
174  nnfft_precompute_psi(&my_plan);
175  if(my_plan.nnfft_flags & PRE_FULL_PSI)
176  nnfft_precompute_full_psi(&my_plan);
177  }
178 
179  if(my_plan.nnfft_flags & PRE_PHI_HUT)
180  nnfft_precompute_phi_hut(&my_plan);
181 
182  /* init some guess */
183  for(k=0;k<my_plan.N_total;k++)
184  {
185  my_iplan.f_hat_iter[k]=0.0;
186  }
187 
188  t0 = getticks();
189 
190  /* inverse trafo */
191  solver_before_loop_complex(&my_iplan);
192  for(l=0;l<iteration;l++)
193  {
194  /* break if dot_r_iter is smaller than epsilon*/
195  if(my_iplan.dot_r_iter<epsilon)
196  break;
197  fprintf(stderr,"%e, %i of %i\n",sqrt(my_iplan.dot_r_iter),
198  l+1,iteration);
199  solver_loop_one_step_complex(&my_iplan);
200  }
201 
202  t1 = getticks();
203  t = nfft_elapsed_seconds(t1,t0);
204 
205  fout_real=fopen("output_real.dat","w");
206  fout_imag=fopen("output_imag.dat","w");
207 
208  for(k=0;k<my_plan.N_total;k++) {
209 
210  my_iplan.f_hat_iter[k]*=cexp(2.0*_Complex_I*PI*Ts*w[k]);
211 
212  fprintf(fout_real,"%le ", creal(my_iplan.f_hat_iter[k]));
213  fprintf(fout_imag,"%le ", cimag(my_iplan.f_hat_iter[k]));
214  }
215 
216 
217  fclose(fout_real);
218  fclose(fout_imag);
219 
220 
221  /* finalize the infft */
222  solver_finalize_complex(&my_iplan);
223 
224  /* finalize the nfft */
225  nnfft_finalize(&my_plan);
226 
227  nfft_free(w);
228 }
229 
230 int main(int argc, char **argv)
231 {
232  if (argc <= 5) {
233  printf("usage: ./reconstruct_data_inh_nnfft FILENAME N M ITER WEIGHTS\n");
234  return 1;
235  }
236 
237  reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]));
238 
239  return 1;
240 }
241 /* \} */

Generated on Tue Apr 30 2013 by Doxygen 1.8.1