NFFT Logo 3.2.2
construct_data_inh_3d.c
00001 /*
00002  * Copyright (c) 2002, 2012 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 
00019 /* $Id: construct_data_inh_3d.c 3896 2012-10-10 12:19:26Z tovo $ */
00020 #include "config.h"
00021 
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include <limits.h>
00025 #ifdef HAVE_COMPLEX_H
00026 #include <complex.h>
00027 #endif
00028 
00029 #include "nfft3.h"
00030 #include "nfft3util.h"
00031 
00041 static void construct(char * file, int N, int M)
00042 {
00043   int j;                  /* some variables */
00044   double real;
00045   double w;
00046   double time,min_time,max_time,min_inh,max_inh;
00047   mri_inh_3d_plan my_plan;
00048   FILE *fp,*fout,*fi,*finh,*ftime;
00049   int my_N[3],my_n[3];
00050   int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
00051                       MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE|
00052                       FFTW_MEASURE| FFTW_DESTROY_INPUT;
00053 
00054   double Ts;
00055   double W;
00056   int N3;
00057   int m=2;
00058   double sigma = 1.25;
00059 
00060   ftime=fopen("readout_time.dat","r");
00061   finh=fopen("inh.dat","r");
00062 
00063   min_time=INT_MAX; max_time=INT_MIN;
00064   for(j=0;j<M;j++)
00065   {
00066     fscanf(ftime,"%le ",&time);
00067     if(time<min_time)
00068       min_time = time;
00069     if(time>max_time)
00070       max_time = time;
00071   }
00072 
00073   fclose(ftime);
00074 
00075   Ts=(min_time+max_time)/2.0;
00076 
00077   min_inh=INT_MAX; max_inh=INT_MIN;
00078   for(j=0;j<N*N;j++)
00079   {
00080     fscanf(finh,"%le ",&w);
00081     if(w<min_inh)
00082       min_inh = w;
00083     if(w>max_inh)
00084       max_inh = w;
00085   }
00086   fclose(finh);
00087 
00088   N3=ceil((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
00089 
00090   W= NFFT_MAX(fabs(min_inh),fabs(max_inh))/(0.5-((double)m)/N3);
00091 
00092   my_N[0]=N; my_n[0]=ceil(N*sigma);
00093   my_N[1]=N; my_n[1]=ceil(N*sigma);
00094   my_N[2]=N3; my_n[2]=ceil(N3*sigma);
00095 
00096   /* initialise nfft */
00097   mri_inh_3d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
00098                       FFTW_MEASURE| FFTW_DESTROY_INPUT);
00099 
00100   ftime=fopen("readout_time.dat","r");
00101   fp=fopen("knots.dat","r");
00102 
00103   for(j=0;j<my_plan.M_total;j++)
00104   {
00105     fscanf(fp,"%le %le",&my_plan.plan.x[3*j+0],&my_plan.plan.x[3*j+1]);
00106     fscanf(ftime,"%le ",&my_plan.plan.x[3*j+2]);
00107     my_plan.plan.x[3*j+2] = (my_plan.plan.x[3*j+2]-Ts)*W/N3;
00108   }
00109   fclose(fp);
00110   fclose(ftime);
00111 
00112   finh=fopen("inh.dat","r");
00113   for(j=0;j<N*N;j++)
00114   {
00115     fscanf(finh,"%le ",&my_plan.w[j]);
00116     my_plan.w[j]/=W;
00117   }
00118   fclose(finh);
00119 
00120 
00121   fi=fopen("input_f.dat","r");
00122   for(j=0;j<N*N;j++)
00123   {
00124     fscanf(fi,"%le ",&real);
00125     my_plan.f_hat[j] = real*cexp(2.0*_Complex_I*PI*Ts*my_plan.w[j]*W);
00126   }
00127 
00128   if(my_plan.plan.nfft_flags & PRE_PSI)
00129     nfft_precompute_psi(&my_plan.plan);
00130 
00131   mri_inh_3d_trafo(&my_plan);
00132 
00133   fout=fopen(file,"w");
00134 
00135   for(j=0;j<my_plan.M_total;j++)
00136   {
00137     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]));
00138   }
00139 
00140   fclose(fout);
00141 
00142   mri_inh_3d_finalize(&my_plan);
00143 }
00144 
00145 int main(int argc, char **argv)
00146 {
00147   if (argc <= 3) {
00148     printf("usage: ./construct_data_inh_3d FILENAME N M\n");
00149     return 1;
00150   }
00151 
00152   construct(argv[1],atoi(argv[2]),atoi(argv[3]));
00153 
00154   return 1;
00155 }
00156 /* \} */

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409