| NFFT 3.5.0

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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
33 static 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|
53 MALLOC_X| MALLOC_F_HAT| MALLOC_F|
54 FFTW_INIT| FFT_OUT_OF_PLACE,
55 FFTW_MEASURE| FFTW_DESTROY_INPUT);
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
156 int 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 /* \} */
PRECOMPUTE_DAMP
#define PRECOMPUTE_DAMP
Definition: nfft3.h:790
MALLOC_X
#define MALLOC_X
Definition: nfft3.h:199
MALLOC_F_HAT
#define MALLOC_F_HAT
Definition: nfft3.h:200
PRECOMPUTE_WEIGHT
#define PRECOMPUTE_WEIGHT
Definition: nfft3.h:789
solver_plan_complex::w
double * w
weighting factors
Definition: nfft3.h:783
solver_plan_complex::flags
unsigned flags
iteration type
Definition: nfft3.h:783
nfft_precompute_lin_psi
void nfft_precompute_lin_psi(nfft_plan *ths)
solver_plan_complex::dot_r_iter
double dot_r_iter
weighted dotproduct of r_iter
Definition: nfft3.h:783
nfft_precompute_full_psi
void nfft_precompute_full_psi(nfft_plan *ths)
nfft_precompute_psi
void nfft_precompute_psi(nfft_plan *ths)
nfft_mv_plan_complex
Definition: nfft3.h:192
nfft_plan
data structure for an NFFT (nonequispaced fast Fourier transform) plan with double precision ...
Definition: nfft3.h:192
FFTW_INIT
#define FFTW_INIT
Definition: nfft3.h:203
nfft_plan::N_total
NFFT_INT N_total
Total number of Fourier coefficients.
Definition: nfft3.h:192
MALLOC_F
#define MALLOC_F
Definition: nfft3.h:201
nfft_plan::M_total
NFFT_INT M_total
Total number of samples.
Definition: nfft3.h:192
FFT_OUT_OF_PLACE
#define FFT_OUT_OF_PLACE
Definition: nfft3.h:202
PRE_LIN_PSI
#define PRE_LIN_PSI
Definition: nfft3.h:195
PRE_PSI
#define PRE_PSI
Definition: nfft3.h:197
CGNR
#define CGNR
Definition: nfft3.h:786
nfsft_wisdom::alpha
double * alpha
Precomputed recursion coefficients /f$^n/f$ for /f$k = 0,/ldots, N_{{max}}; n=-k,/ldots,k/f$ of associated Legendre-functions /f$P_k^n/f$.
Definition: kernel/nfsft/api.h:74
nfft_finalize
void nfft_finalize(nfft_plan *ths)
solver_plan_complex::y
fftw_complex * y
right hand side, samples
Definition: nfft3.h:783
PRE_FULL_PSI
#define PRE_FULL_PSI
Definition: nfft3.h:198
nfft3.h
Header file for the nfft3 library.
nfft_plan::x
double * x
Nodes in time/spatial domain, size is doubles.
Definition: nfft3.h:192
PRE_PHI_HUT
#define PRE_PHI_HUT
Definition: nfft3.h:193
nfft_plan::flags
unsigned flags
Flags for precomputation, (de)allocation, and FFTW usage, default setting is PRE_PHI_HUT | PRE_PSI | ...
Definition: nfft3.h:192
solver_plan_complex
data structure for an inverse NFFT plan with double precision
Definition: nfft3.h:783
solver_plan_complex::w_hat
double * w_hat
damping factors
Definition: nfft3.h:783
reconstruct
static void reconstruct(char *filename, int N, int M, int iteration, int weight)
reconstruct makes an inverse 2d nfft
Definition: reconstruct_data_2d.c:33
solver_plan_complex::f_hat_iter
fftw_complex * f_hat_iter
iterative solution
Definition: nfft3.h:783