NFFT  3.3.1
construct_data_inh_3d.c
00001 /*
00002  * Copyright (c) 2002, 2016 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include "config.h"
00019 
00020 #include <stdlib.h>
00021 #include <math.h>
00022 #include <limits.h>
00023 #ifdef HAVE_COMPLEX_H
00024 #include <complex.h>
00025 #endif
00026 
00027 #include "nfft3.h"
00028 
00029 #ifndef MAX
00030 #define MAX(a,b) (((a)>(b))?(a):(b))
00031 #endif
00032 
00042 static void construct(char * file, int N, int M)
00043 {
00044   int j;                  /* some variables */
00045   double real;
00046   double w;
00047   double time,min_time,max_time,min_inh,max_inh;
00048   mri_inh_3d_plan my_plan;
00049   FILE *fp,*fout,*fi,*finh,*ftime;
00050   int my_N[3],my_n[3];
00051   int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
00052                       MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE|
00053                       FFTW_MEASURE| FFTW_DESTROY_INPUT;
00054 
00055   double Ts;
00056   double W;
00057   int N3;
00058   int m=2;
00059   double sigma = 1.25;
00060 
00061   ftime=fopen("readout_time.dat","r");
00062   finh=fopen("inh.dat","r");
00063 
00064   min_time=INT_MAX; max_time=INT_MIN;
00065   for(j=0;j<M;j++)
00066   {
00067     fscanf(ftime,"%le ",&time);
00068     if(time<min_time)
00069       min_time = time;
00070     if(time>max_time)
00071       max_time = time;
00072   }
00073 
00074   fclose(ftime);
00075 
00076   Ts=(min_time+max_time)/2.0;
00077 
00078   min_inh=INT_MAX; max_inh=INT_MIN;
00079   for(j=0;j<N*N;j++)
00080   {
00081     fscanf(finh,"%le ",&w);
00082     if(w<min_inh)
00083       min_inh = w;
00084     if(w>max_inh)
00085       max_inh = w;
00086   }
00087   fclose(finh);
00088 
00089   N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
00090 
00091   W= MAX(fabs(min_inh),fabs(max_inh))/(0.5-((double)m)/N3);
00092 
00093   my_N[0]=N; my_n[0]=ceil(N*sigma);
00094   my_N[1]=N; my_n[1]=ceil(N*sigma);
00095   my_N[2]=N3; my_n[2]=ceil(N3*sigma);
00096 
00097   /* initialise nfft */
00098   mri_inh_3d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
00099                       FFTW_MEASURE| FFTW_DESTROY_INPUT);
00100 
00101   ftime=fopen("readout_time.dat","r");
00102   fp=fopen("knots.dat","r");
00103 
00104   for(j=0;j<my_plan.M_total;j++)
00105   {
00106     fscanf(fp,"%le %le",&my_plan.plan.x[3*j+0],&my_plan.plan.x[3*j+1]);
00107     fscanf(ftime,"%le ",&my_plan.plan.x[3*j+2]);
00108     my_plan.plan.x[3*j+2] = (my_plan.plan.x[3*j+2]-Ts)*W/N3;
00109   }
00110   fclose(fp);
00111   fclose(ftime);
00112 
00113   finh=fopen("inh.dat","r");
00114   for(j=0;j<N*N;j++)
00115   {
00116     fscanf(finh,"%le ",&my_plan.w[j]);
00117     my_plan.w[j]/=W;
00118   }
00119   fclose(finh);
00120 
00121 
00122   fi=fopen("input_f.dat","r");
00123   for(j=0;j<N*N;j++)
00124   {
00125     fscanf(fi,"%le ",&real);
00126     my_plan.f_hat[j] = real*cexp(2.0*_Complex_I*M_PI*Ts*my_plan.w[j]*W);
00127   }
00128 
00129   if(my_plan.plan.flags & PRE_PSI)
00130     nfft_precompute_psi(&my_plan.plan);
00131 
00132   mri_inh_3d_trafo(&my_plan);
00133 
00134   fout=fopen(file,"w");
00135 
00136   for(j=0;j<my_plan.M_total;j++)
00137   {
00138     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]));
00139   }
00140 
00141   fclose(fout);
00142 
00143   mri_inh_3d_finalize(&my_plan);
00144 }
00145 
00146 int main(int argc, char **argv)
00147 {
00148   if (argc <= 3) {
00149     printf("usage: ./construct_data_inh_3d FILENAME N M\n");
00150     return 1;
00151   }
00152 
00153   construct(argv[1],atoi(argv[2]),atoi(argv[3]));
00154 
00155   return 1;
00156 }
00157 /* \} */