NFFT  3.4.1
construct_data_inh_3d.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_3d_plan my_plan;
49  FILE *fp,*fout,*fi,*finh,*ftime;
50  int my_N[3],my_n[3];
53  FFTW_MEASURE| FFTW_DESTROY_INPUT;
54 
55  double Ts;
56  double W;
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  N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
90 
91  W= MAX(fabs(min_inh),fabs(max_inh))/(0.5-((double)m)/N3);
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]=ceil(N3*sigma);
96 
97  /* initialise nfft */
98  mri_inh_3d_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[3*j+0],&my_plan.plan.x[3*j+1]);
107  fscanf(ftime,"%le ",&my_plan.plan.x[3*j+2]);
108  my_plan.plan.x[3*j+2] = (my_plan.plan.x[3*j+2]-Ts)*W/N3;
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_3d_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[3*j+0],my_plan.plan.x[3*j+1],creal(my_plan.f[j]),cimag(my_plan.f[j]));
139  }
140 
141  fclose(fout);
142 
143  mri_inh_3d_finalize(&my_plan);
144 }
145 
146 int main(int argc, char **argv)
147 {
148  if (argc <= 3) {
149  printf("usage: ./construct_data_inh_3d 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 /* \} */
#define MALLOC_X
Definition: nfft3.h:199
#define MALLOC_F_HAT
Definition: nfft3.h:200
void mri_inh_3d_trafo(mri_inh_3d_plan *ths)
Definition: mri.c:189
fftw_complex * f_hat
Fourier coefficients.
Definition: nfft3.h:525
fftw_complex * f
Samples.
Definition: nfft3.h:525
static void construct(char *file, int N, int M)
construct
void nfft_precompute_psi(nfft_plan *ths)
#define FFTW_INIT
Definition: nfft3.h:203
NFFT_INT M_total
Total number of samples.
Definition: nfft3.h:525
#define MALLOC_F
Definition: nfft3.h:201
#define FFT_OUT_OF_PLACE
Definition: nfft3.h:202
#define PRE_PSI
Definition: nfft3.h:197
Header file for the nfft3 library.
double * x
Nodes in time/spatial domain, size is doubles.
Definition: nfft3.h:192
#define PRE_PHI_HUT
Definition: nfft3.h:193
void mri_inh_3d_finalize(mri_inh_3d_plan *ths)
Definition: mri.c:266
unsigned flags
Flags for precomputation, (de)allocation, and FFTW usage, default setting is PRE_PHI_HUT | PRE_PSI | ...
Definition: nfft3.h:192