NFFT Logo 3.2.3
construct_data_inh_3d.c
1 /*
2  * Copyright (c) 2002, 2012 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 
19 /* $Id: construct_data_inh_3d.c 3896 2012-10-10 12:19:26Z tovo $ */
20 #include "config.h"
21 
22 #include <stdlib.h>
23 #include <math.h>
24 #include <limits.h>
25 #ifdef HAVE_COMPLEX_H
26 #include <complex.h>
27 #endif
28 
29 #include "nfft3.h"
30 #include "nfft3util.h"
31 
41 static void construct(char * file, int N, int M)
42 {
43  int j; /* some variables */
44  double real;
45  double w;
46  double time,min_time,max_time,min_inh,max_inh;
47  mri_inh_3d_plan my_plan;
48  FILE *fp,*fout,*fi,*finh,*ftime;
49  int my_N[3],my_n[3];
50  int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
51  MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE|
52  FFTW_MEASURE| FFTW_DESTROY_INPUT;
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((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
89 
90  W= NFFT_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*PI*Ts*my_plan.w[j]*W);
126  }
127 
128  if(my_plan.plan.nfft_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 /* \} */

Generated on Tue Apr 30 2013 by Doxygen 1.8.1