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