NFFT 3.5.3alpha
reconstruct_data_2d.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 <math.h>
19#include <stdlib.h>
20#include <complex.h>
21
22#include "nfft3.h"
23
33static void reconstruct(char* filename,int N,int M,int iteration, int weight)
34{
35 int j,k,l; /* some variables */
36 double t0, t1;
37 double real,imag,t; /* to read the real and imag part of a complex number */
38 nfft_plan my_plan; /* plan for the two dimensional nfft */
39 solver_plan_complex my_iplan; /* plan for the two dimensional infft */
40 FILE* fin; /* input file */
41 FILE* fout_real; /* output file */
42 FILE* fout_imag; /* output file */
43 int my_N[2],my_n[2]; /* to init the nfft */
44 double epsilon=0.0000003; /* epsilon is a the break criterium for
45 the iteration */
46 unsigned infft_flags = CGNR | PRECOMPUTE_DAMP; /* flags for the infft*/
47 int m = 6;
48 double alpha = 2.0;
49 /* initialise my_plan */
50 my_N[0]=N; my_n[0]=ceil(N*alpha);
51 my_N[1]=N; my_n[1]=ceil(N*alpha);
52 nfft_init_guru(&my_plan, 2, my_N, M, my_n, m, PRE_PHI_HUT| PRE_PSI|
55 FFTW_MEASURE);
56
57 /* precompute lin psi if set */
58 if(my_plan.flags & PRE_LIN_PSI)
59 nfft_precompute_lin_psi(&my_plan);
60
61 /* set the flags for the infft*/
62 if (weight)
63 infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
64
65 /* initialise my_iplan, advanced */
66 solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)&my_plan, infft_flags );
67
68 /* get the weights */
69 if(my_iplan.flags & PRECOMPUTE_WEIGHT)
70 {
71 fin=fopen("weights.dat","r");
72 for(j=0;j<my_plan.M_total;j++)
73 {
74 fscanf(fin,"%le ",&my_iplan.w[j]);
75 }
76 fclose(fin);
77 }
78
79 /* get the damping factors */
80 if(my_iplan.flags & PRECOMPUTE_DAMP)
81 {
82 for(j=0;j<N;j++){
83 for(k=0;k<N;k++) {
84 int j2= j-N/2;
85 int k2= k-N/2;
86 double r=sqrt(j2*j2+k2*k2);
87 if(r>(double) N/2)
88 my_iplan.w_hat[j*N+k]=0.0;
89 else
90 my_iplan.w_hat[j*N+k]=1.0;
91 }
92 }
93 }
94
95 /* open the input file */
96 fin=fopen(filename,"r");
97
98 /* read x,y,freal and fimag from the knots */
99 for(j=0;j<my_plan.M_total;j++)
100 {
101 fscanf(fin,"%le %le %le %le ",&my_plan.x[2*j+0],&my_plan.x[2*j+1],
102 &real,&imag);
103 my_iplan.y[j] = real + _Complex_I*imag;
104 }
105
106 fclose(fin);
107
108 /* precompute psi */
109 if(my_plan.flags & PRE_PSI)
110 nfft_precompute_psi(&my_plan);
111
112 /* precompute full psi */
113 if(my_plan.flags & PRE_FULL_PSI)
114 nfft_precompute_full_psi(&my_plan);
115
116 /* init some guess */
117 for(k=0;k<my_plan.N_total;k++)
118 my_iplan.f_hat_iter[k]=0.0;
119
120 t0 = nfft_clock_gettime_seconds();
121
122 /* inverse trafo */
123 solver_before_loop_complex(&my_iplan);
124 for(l=0;l<iteration;l++)
125 {
126 /* break if dot_r_iter is smaller than epsilon*/
127 if(my_iplan.dot_r_iter<epsilon)
128 break;
129 fprintf(stderr,"%e, %i of %i\n",sqrt(my_iplan.dot_r_iter),
130 l+1,iteration);
131 solver_loop_one_step_complex(&my_iplan);
132 }
133
134
135 t1 = nfft_clock_gettime_seconds();
136 t=t1-t0;
137
138 fout_real=fopen("output_real.dat","w");
139 fout_imag=fopen("output_imag.dat","w");
140
141 for(k=0;k<my_plan.N_total;k++) {
142 fprintf(fout_real,"%le ", creal(my_iplan.f_hat_iter[k]));
143 fprintf(fout_imag,"%le ", cimag(my_iplan.f_hat_iter[k]));
144 }
145
146 fclose(fout_real);
147 fclose(fout_imag);
148
149 /* finalize the infft */
150 solver_finalize_complex(&my_iplan);
151
152 /* finalize the nfft */
153 nfft_finalize(&my_plan);
154}
155
156int main(int argc, char **argv)
157{
158 if (argc <= 5) {
159 printf("usage: ./reconstruct_data_2d FILENAME N M ITER WEIGHTS\n");
160 return 1;
161 }
162
163 reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]));
164
165 return 1;
166}
167/* \} */
static void reconstruct(char *filename, int N, int M, int iteration, int weight)
reconstruct makes an inverse 2d nfft
#define MALLOC_F_HAT
Definition nfft3.h:194
#define MALLOC_X
Definition nfft3.h:193
#define PRE_FULL_PSI
Definition nfft3.h:192
#define PRE_PSI
Definition nfft3.h:191
#define MALLOC_F
Definition nfft3.h:195
#define PRE_LIN_PSI
Definition nfft3.h:189
#define FFTW_INIT
Definition nfft3.h:197
#define PRE_PHI_HUT
Definition nfft3.h:187
#define CGNR
Definition nfft3.h:808
#define PRECOMPUTE_DAMP
Definition nfft3.h:812
#define PRECOMPUTE_WEIGHT
Definition nfft3.h:811
Header file for the nfft3 library.
data structure for an inverse NFFT plan with double precision
Definition nfft3.h:802
double * w
weighting factors
Definition nfft3.h:802
unsigned flags
iteration type
Definition nfft3.h:802
double * w_hat
damping factors
Definition nfft3.h:802
double dot_r_iter
weighted dotproduct of r_iter
Definition nfft3.h:802
fftw_complex * y
right hand side, samples
Definition nfft3.h:802
fftw_complex * f_hat_iter
iterative solution
Definition nfft3.h:802