00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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;
00043 double tmp;
00044 nfft_plan my_plan;
00045 FILE* fp;
00046
00047
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);
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