NFFT  3.5.3
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];
52  MALLOC_F| FFTW_INIT| FFTW_MEASURE;
53 
54  double Ts;
55  double W;
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  N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
89 
90  W= MAX(fabs(min_inh),fabs(max_inh))/(0.5-((double)m)/N3);
91 
92  my_N[0]=N; my_n[0]=ceil(N*sigma);
93  my_N[1]=N; my_n[1]=ceil(N*sigma);
94  my_N[2]=N3; my_n[2]=ceil(N3*sigma);
95 
96  /* initialise nfft */
97  mri_inh_3d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
98  FFTW_MEASURE| FFTW_DESTROY_INPUT);
99 
100  ftime=fopen("readout_time.dat","r");
101  fp=fopen("knots.dat","r");
102 
103  for(j=0;j<my_plan.M_total;j++)
104  {
105  fscanf(fp,"%le %le",&my_plan.plan.x[3*j+0],&my_plan.plan.x[3*j+1]);
106  fscanf(ftime,"%le ",&my_plan.plan.x[3*j+2]);
107  my_plan.plan.x[3*j+2] = (my_plan.plan.x[3*j+2]-Ts)*W/N3;
108  }
109  fclose(fp);
110  fclose(ftime);
111 
112  finh=fopen("inh.dat","r");
113  for(j=0;j<N*N;j++)
114  {
115  fscanf(finh,"%le ",&my_plan.w[j]);
116  my_plan.w[j]/=W;
117  }
118  fclose(finh);
119 
120 
121  fi=fopen("input_f.dat","r");
122  for(j=0;j<N*N;j++)
123  {
124  fscanf(fi,"%le ",&real);
125  my_plan.f_hat[j] = real*cexp(2.0*_Complex_I*M_PI*Ts*my_plan.w[j]*W);
126  }
127 
128  if(my_plan.plan.flags & PRE_PSI)
129  nfft_precompute_psi(&my_plan.plan);
130 
131  mri_inh_3d_trafo(&my_plan);
132 
133  fout=fopen(file,"w");
134 
135  for(j=0;j<my_plan.M_total;j++)
136  {
137  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]));
138  }
139 
140  fclose(fout);
141 
142  mri_inh_3d_finalize(&my_plan);
143 }
144 
145 int main(int argc, char **argv)
146 {
147  if (argc <= 3) {
148  printf("usage: ./construct_data_inh_3d FILENAME N M\n");
149  return 1;
150  }
151 
152  construct(argv[1],atoi(argv[2]),atoi(argv[3]));
153 
154  return 1;
155 }
156 /* \} */
static void construct(char *file, int N, int M)
construct
void mri_inh_3d_finalize(mri_inh_3d_plan *ths)
Definition: mri.c:266
void mri_inh_3d_trafo(mri_inh_3d_plan *that)
Definition: mri.c:189
#define MALLOC_F_HAT
Definition: nfft3.h:188
#define MALLOC_X
Definition: nfft3.h:187
#define PRE_PSI
Definition: nfft3.h:185
#define MALLOC_F
Definition: nfft3.h:189
#define FFTW_INIT
Definition: nfft3.h:191
#define PRE_PHI_HUT
Definition: nfft3.h:181
Header file for the nfft3 library.