NFFT Logo 3.2.3
mri2d/reconstruct_data_gridding.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_gridding.c 3896 2012-10-10 12:19:26Z tovo $ */
20 #include "config.h"
21 
22 #include <stdlib.h>
23 #include <math.h>
24 #ifdef HAVE_COMPLEX_H
25 #include <complex.h>
26 #endif
27 
28 #include "nfft3util.h"
29 #include "nfft3.h"
30 
40 static void reconstruct(char* filename, int N, int M, int weight)
41 {
42  int j; /* some variables */
43  double weights; /* store one weight temporary */
44  double real,imag; /* to read the real and imag part of a complex number */
45  nfft_plan my_plan; /* plan for the two dimensional nfft */
46  FILE* fin; /* input file */
47  FILE* fweight; /* input file for the weights */
48  FILE *fout_real; /* output file */
49  FILE *fout_imag; /* output file */
50  int my_N[2],my_n[2];
51  int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
52  MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE|
53  FFTW_MEASURE| FFTW_DESTROY_INPUT;
54 
55  /* initialise nfft */
56  my_N[0]=N; my_n[0]=ceil(N*1.2);
57  my_N[1]=N; my_n[1]=ceil(N*1.2);
58  nfft_init_guru(&my_plan, 2, my_N, M, my_n, 6,flags,
59  FFTW_MEASURE| FFTW_DESTROY_INPUT);
60 
61  fin=fopen(filename,"r");
62 
63  fweight=fopen("weights.dat","r");
64  for(j=0;j<my_plan.M_total;j++)
65  {
66  fscanf(fweight,"%le ",&weights);
67  fscanf(fin,"%le %le %le %le",&my_plan.x[2*j+0],&my_plan.x[2*j+1],&real,&imag);
68  my_plan.f[j] = real + _Complex_I*imag;
69  if (weight)
70  my_plan.f[j] = my_plan.f[j] * weights;
71  }
72  fclose(fweight);
73 
74  /* precompute psi */
75  if(my_plan.nfft_flags & PRE_PSI)
76  nfft_precompute_psi(&my_plan);
77 
78  /* precompute full psi */
79  if(my_plan.nfft_flags & PRE_FULL_PSI)
80  nfft_precompute_full_psi(&my_plan);
81 
82 
83  /* compute the adjoint nfft */
84  nfft_adjoint(&my_plan);
85 
86  fout_real=fopen("output_real.dat","w");
87  fout_imag=fopen("output_imag.dat","w");
88 
89  for (j=0;j<N*N;j++) {
90  fprintf(fout_real,"%le ",creal(my_plan.f_hat[j]));
91  fprintf(fout_imag,"%le ",cimag(my_plan.f_hat[j]));
92  }
93 
94  fclose(fin);
95  fclose(fout_real);
96  fclose(fout_imag);
97 
98  nfft_finalize(&my_plan);
99 }
100 
101 
102 int main(int argc, char **argv)
103 {
104  if (argc <= 5) {
105  printf("usage: ./reconstruct_data_gridding FILENAME N M ITER WEIGHTS\n");
106  return 1;
107  }
108  reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[5]));
109 
110  return 1;
111 }
112 /* \} */

Generated on Tue Apr 30 2013 by Doxygen 1.8.1