| NFFT 3.5.0

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

construct_data_inh_2d1d.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 #include <limits.h>
23 #ifdef HAVE_COMPLEX_H
24 #include <complex.h>
25 #endif
26
27 #include "nfft3.h"
28
29 #ifndef MAX
30 #define MAX(a,b) (((a)>(b))?(a):(b))
31 #endif
32
42 static void construct(char * file, int N, int M)
43 {
44 int j; /* some variables */
45 double real;
46 double w;
47 double time,min_time,max_time,min_inh,max_inh;
48 mri_inh_2d1d_plan my_plan;
49 FILE *fp,*fout,*fi,*finh,*ftime;
50 int my_N[3],my_n[3];
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 double Ts;
56 double W,T;
57 int N3;
58 int m=2;
59 double sigma = 1.25;
60
61 ftime=fopen("readout_time.dat","r");
62 finh=fopen("inh.dat","r");
63
64 min_time=INT_MAX; max_time=INT_MIN;
65 for(j=0;j<M;j++)
66 {
67 fscanf(ftime,"%le ",&time);
68 if(time<min_time)
69 min_time = time;
70 if(time>max_time)
71 max_time = time;
72 }
73
74 fclose(ftime);
75
76 Ts=(min_time+max_time)/2.0;
77
78 min_inh=INT_MAX; max_inh=INT_MIN;
79 for(j=0;j<N*N;j++)
80 {
81 fscanf(finh,"%le ",&w);
82 if(w<min_inh)
83 min_inh = w;
84 if(w>max_inh)
85 max_inh = w;
86 }
87 fclose(finh);
88
89
90 N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
91 T=((max_time-min_time)/2.0)/(0.5-((double) m)/N3);
92 W=N3/T;
93
94 my_N[0]=N; my_n[0]=ceil(N*sigma);
95 my_N[1]=N; my_n[1]=ceil(N*sigma);
96 my_N[2]=N3; my_n[2]=N3;
97
98 /* initialise nfft */
99 mri_inh_2d1d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
100 FFTW_MEASURE| FFTW_DESTROY_INPUT);
101
102 ftime=fopen("readout_time.dat","r");
103 fp=fopen("knots.dat","r");
104
105 for(j=0;j<my_plan.M_total;j++)
106 {
107 fscanf(fp,"%le %le ",&my_plan.plan.x[2*j+0],&my_plan.plan.x[2*j+1]);
108 fscanf(ftime,"%le ",&my_plan.t[j]);
109 my_plan.t[j] = (my_plan.t[j]-Ts)/T;
110 }
111 fclose(fp);
112 fclose(ftime);
113
114 finh=fopen("inh.dat","r");
115 for(j=0;j<N*N;j++)
116 {
117 fscanf(finh,"%le ",&my_plan.w[j]);
118 my_plan.w[j]/=W;
119 }
120 fclose(finh);
121
122
123 fi=fopen("input_f.dat","r");
124 for(j=0;j<N*N;j++)
125 {
126 fscanf(fi,"%le ",&real);
127 my_plan.f_hat[j] = real*cexp(2.0*_Complex_I*M_PI*Ts*my_plan.w[j]*W);
128 }
129
130 if(my_plan.plan.flags & PRE_PSI)
131 nfft_precompute_psi(&my_plan.plan);
132
133 mri_inh_2d1d_trafo(&my_plan);
134
135 fout=fopen(file,"w");
136
137 for(j=0;j<my_plan.M_total;j++)
138 {
139 fprintf(fout,"%le %le %le %le\n",my_plan.plan.x[2*j+0],my_plan.plan.x[2*j+1],creal(my_plan.f[j]),cimag(my_plan.f[j]));
140 }
141
142 fclose(fout);
143
144 mri_inh_2d1d_finalize(&my_plan);
145 }
146
147 int main(int argc, char **argv)
148 {
149 if (argc <= 3) {
150 printf("usage: ./construct_data_inh_2d1d FILENAME N M\n");
151 return 1;
152 }
153
154 construct(argv[1],atoi(argv[2]),atoi(argv[3]));
155
156 return 1;
157 }
158 /* \} */
mri_inh_2d1d_plan::f_hat
fftw_complex * f_hat
Fourier coefficients.
Definition: nfft3.h:525
MALLOC_X
#define MALLOC_X
Definition: nfft3.h:199
MALLOC_F_HAT
#define MALLOC_F_HAT
Definition: nfft3.h:200
mri_inh_2d1d_finalize
void mri_inh_2d1d_finalize(mri_inh_2d1d_plan *ths)
Definition: mri.c:174
mri_inh_2d1d_plan::f
fftw_complex * f
Samples.
Definition: nfft3.h:525
mri_inh_2d1d_plan
Definition: nfft3.h:525
nfft_precompute_psi
void nfft_precompute_psi(nfft_plan *ths)
FFTW_INIT
#define FFTW_INIT
Definition: nfft3.h:203
mri_inh_2d1d_plan::M_total
NFFT_INT M_total
Total number of samples.
Definition: nfft3.h:525
MALLOC_F
#define MALLOC_F
Definition: nfft3.h:201
mri_inh_2d1d_init_guru
void mri_inh_2d1d_init_guru(mri_inh_2d1d_plan *ths, int *N, int M, int *n, int m, double sigma, unsigned nfft_flags, unsigned fftw_flags)
Definition: mri.c:156
FFT_OUT_OF_PLACE
#define FFT_OUT_OF_PLACE
Definition: nfft3.h:202
PRE_PSI
#define PRE_PSI
Definition: nfft3.h:197
mri_inh_2d1d_trafo
void mri_inh_2d1d_trafo(mri_inh_2d1d_plan *ths)
Definition: mri.c:57
construct
static void construct(char *file, int N, int M)
construct
Definition: construct_data_inh_2d1d.c:42
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