NFFT Logo 3.1.1 API Reference

construct_data_inh_3d.c

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

Generated on 17 Aug 2009 by Doxygen 1.5.3