NFFT Logo 3.2.2
construct_data_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_2d1d.c 3896 2012-10-10 12:19:26Z tovo $ */
00020 #include "config.h"
00021 
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #ifdef HAVE_COMPLEX_H
00025 #include <complex.h>
00026 #endif
00027 
00028 #include "nfft3util.h"
00029 #include "nfft3.h"
00030 
00040 static void construct(char * file, int N, int M, int Z, fftw_complex *mem)
00041 {
00042   int j,z;                /* some variables */
00043   double tmp;             /* a placeholder */
00044   nfft_plan my_plan;      /* plan for the two dimensional nfft  */
00045   FILE* fp;
00046 
00047   /* initialise my_plan */
00048   nfft_init_2d(&my_plan,N,N,M/Z);
00049 
00050   fp=fopen("knots.dat","r");
00051 
00052   for(j=0;j<my_plan.M_total;j++)
00053   {
00054     fscanf(fp,"%le %le %le",&my_plan.x[2*j+0],&my_plan.x[2*j+1],&tmp);
00055   }
00056   fclose(fp);
00057 
00058   fp=fopen(file,"w");
00059 
00060   for(z=0;z<Z;z++) {
00061     tmp = (double) z;
00062 
00063     for(j=0;j<N*N;j++)
00064       my_plan.f_hat[j] = mem[(z*N*N+N*N*Z/2+j)%(N*N*Z)];
00065 
00066     if(my_plan.nfft_flags & PRE_PSI)
00067       nfft_precompute_psi(&my_plan);
00068 
00069     nfft_trafo(&my_plan);
00070 
00071     for(j=0;j<my_plan.M_total;j++)
00072     {
00073       fprintf(fp,"%le %le %le %le %le\n",my_plan.x[2*j+0],my_plan.x[2*j+1],tmp/Z-0.5,
00074               creal(my_plan.f[j]),cimag(my_plan.f[j]));
00075     }
00076   }
00077   fclose(fp);
00078 
00079   nfft_finalize(&my_plan);
00080 }
00081 
00086 static void fft(int N,int M,int Z, fftw_complex *mem)
00087 {
00088   fftw_plan plan;
00089   plan = fftw_plan_many_dft(1, &Z, N*N,
00090                                   mem, NULL,
00091                                   N*N, 1,
00092                                   mem, NULL,
00093                                   N*N,1 ,
00094                                   FFTW_FORWARD, FFTW_ESTIMATE);
00095 
00096   fftw_execute(plan); /* execute the fft */
00097   fftw_destroy_plan(plan);
00098 }
00099 
00104 static void read_data(int N,int M,int Z, fftw_complex *mem)
00105 {
00106   int i,z;
00107   double real;
00108   FILE* fin;
00109   fin=fopen("input_f.dat","r");
00110 
00111   for(z=0;z<Z;z++)
00112   {
00113     for(i=0;i<N*N;i++)
00114     {
00115       fscanf(fin,"%le ",&real );
00116       mem[(z*N*N+N*N*Z/2+i)%(N*N*Z)]=real;
00117     }
00118   }
00119   fclose(fin);
00120 }
00121 
00122 int main(int argc, char **argv)
00123 {
00124   fftw_complex *mem;
00125 
00126   if (argc <= 4) {
00127     printf("usage: ./construct_data FILENAME N M Z\n");
00128     return 1;
00129   }
00130 
00131   mem = (fftw_complex*) nfft_malloc(sizeof(fftw_complex) * atoi(argv[2]) * atoi(argv[2]) * atoi(argv[4]));
00132 
00133   read_data(atoi(argv[2]),atoi(argv[3]),atoi(argv[4]), mem);
00134 
00135   fft(atoi(argv[2]),atoi(argv[3]),atoi(argv[4]), mem);
00136 
00137   construct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]), mem);
00138 
00139   nfft_free(mem);
00140 
00141   return 1;
00142 }
00143 /* \} */

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409