NFFT Logo 3.2.2
construct_data_inh_2d1d.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_2d1d.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_2d1d_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,T;
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 
00089   N3=ceil((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
00090   T=((max_time-min_time)/2.0)/(0.5-((double) m)/N3);
00091   W=N3/T;
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]=N3;
00096 
00097   /* initialise nfft */
00098   mri_inh_2d1d_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[2*j+0],&my_plan.plan.x[2*j+1]);
00107     fscanf(ftime,"%le ",&my_plan.t[j]);
00108     my_plan.t[j] = (my_plan.t[j]-Ts)/T;
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*PI*Ts*my_plan.w[j]*W);
00127   }
00128 
00129   if(my_plan.plan.nfft_flags & PRE_PSI)
00130     nfft_precompute_psi(&my_plan.plan);
00131 
00132   mri_inh_2d1d_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[2*j+0],my_plan.plan.x[2*j+1],creal(my_plan.f[j]),cimag(my_plan.f[j]));
00139   }
00140 
00141   fclose(fout);
00142 
00143   mri_inh_2d1d_finalize(&my_plan);
00144 }
00145 
00146 int main(int argc, char **argv)
00147 {
00148   if (argc <= 3) {
00149     printf("usage: ./construct_data_inh_2d1d 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 /* \} */

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409