NFFT 3.5.3alpha
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
42static 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];
52 MALLOC_F| FFTW_INIT| FFTW_MEASURE;
53
54 double Ts;
55 double W,T;
56 int N3;
57 int m=2;
58 double sigma = 1.25;
59
60 ftime=fopen("readout_time.dat","r");
61 finh=fopen("inh.dat","r");
62
63 min_time=INT_MAX; max_time=INT_MIN;
64 for(j=0;j<M;j++)
65 {
66 fscanf(ftime,"%le ",&time);
67 if(time<min_time)
68 min_time = time;
69 if(time>max_time)
70 max_time = time;
71 }
72
73 fclose(ftime);
74
75 Ts=(min_time+max_time)/2.0;
76
77 min_inh=INT_MAX; max_inh=INT_MIN;
78 for(j=0;j<N*N;j++)
79 {
80 fscanf(finh,"%le ",&w);
81 if(w<min_inh)
82 min_inh = w;
83 if(w>max_inh)
84 max_inh = w;
85 }
86 fclose(finh);
87
88
89 N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
90 T=((max_time-min_time)/2.0)/(0.5-((double) m)/N3);
91 W=N3/T;
92
93 my_N[0]=N; my_n[0]=ceil(N*sigma);
94 my_N[1]=N; my_n[1]=ceil(N*sigma);
95 my_N[2]=N3; my_n[2]=N3;
96
97 /* initialise nfft */
98 mri_inh_2d1d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
99 FFTW_MEASURE| FFTW_DESTROY_INPUT);
100
101 ftime=fopen("readout_time.dat","r");
102 fp=fopen("knots.dat","r");
103
104 for(j=0;j<my_plan.M_total;j++)
105 {
106 fscanf(fp,"%le %le ",&my_plan.plan.x[2*j+0],&my_plan.plan.x[2*j+1]);
107 fscanf(ftime,"%le ",&my_plan.t[j]);
108 my_plan.t[j] = (my_plan.t[j]-Ts)/T;
109 }
110 fclose(fp);
111 fclose(ftime);
112
113 finh=fopen("inh.dat","r");
114 for(j=0;j<N*N;j++)
115 {
116 fscanf(finh,"%le ",&my_plan.w[j]);
117 my_plan.w[j]/=W;
118 }
119 fclose(finh);
120
121
122 fi=fopen("input_f.dat","r");
123 for(j=0;j<N*N;j++)
124 {
125 fscanf(fi,"%le ",&real);
126 my_plan.f_hat[j] = real*cexp(2.0*_Complex_I*M_PI*Ts*my_plan.w[j]*W);
127 }
128
129 if(my_plan.plan.flags & PRE_PSI)
130 nfft_precompute_psi(&my_plan.plan);
131
132 mri_inh_2d1d_trafo(&my_plan);
133
134 fout=fopen(file,"w");
135
136 for(j=0;j<my_plan.M_total;j++)
137 {
138 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]));
139 }
140
141 fclose(fout);
142
143 mri_inh_2d1d_finalize(&my_plan);
144}
145
146int main(int argc, char **argv)
147{
148 if (argc <= 3) {
149 printf("usage: ./construct_data_inh_2d1d FILENAME N M\n");
150 return 1;
151 }
152
153 construct(argv[1],atoi(argv[2]),atoi(argv[3]));
154
155 return 1;
156}
157/* \} */
static void construct(char *file, int N, int M)
construct
#define MALLOC_F_HAT
Definition nfft3.h:194
#define MALLOC_X
Definition nfft3.h:193
#define PRE_PSI
Definition nfft3.h:191
#define MALLOC_F
Definition nfft3.h:195
#define FFTW_INIT
Definition nfft3.h:197
#define PRE_PHI_HUT
Definition nfft3.h:187
Header file for the nfft3 library.
NFFT_INT M_total
Total number of samples.
Definition nfft3.h:532
fftw_complex * f
Samples.
Definition nfft3.h:532
fftw_complex * f_hat
Fourier coefficients.
Definition nfft3.h:532