NFFT Logo 3.2.3
nfsft/simple_test.c
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: simple_test.c 3902 2012-10-16 14:02:31Z tovo $ */
20 
21 #include "config.h"
22 
23 /* standard headers */
24 #include <stdio.h>
25 #include <math.h>
26 #include <string.h>
27 #include <stdlib.h>
28 /* It is important to include complex.h before nfft3.h. */
29 #ifdef HAVE_COMPLEX_H
30 #include <complex.h>
31 #endif
32 
33 #include "nfft3.h" /* NFFT3 header */
34 #include "nfft3util.h" /* NFFT3 utilities header*/
35 #include "infft.h" /* NFFT3 internal header */
36 
37 static void simple_test_nfsft(void)
38 {
39  const int N = 4; /* bandwidth/maximum degree */
40  const int M = 8; /* number of nodes */
41  nfsft_plan plan; /* transform plan */
42  int j, k, n; /* loop variables */
43 
44  /* precomputation (for fast polynomial transform) */
45  nfsft_precompute(N,1000.0,0U,0U);
46 
47  /* Initialize transform plan using the guru interface. All input and output
48  * arrays are allocated by nfsft_init_guru(). Computations are performed with
49  * respect to L^2-normalized spherical harmonics Y_k^n. The array of spherical
50  * Fourier coefficients is preserved during transformations. The NFFT uses a
51  * cut-off parameter m = 6. See the NFFT 3 manual for details.
52  */
53  nfsft_init_guru(&plan, N, M, NFSFT_MALLOC_X | NFSFT_MALLOC_F |
54  NFSFT_MALLOC_F_HAT | NFSFT_NORMALIZED | NFSFT_PRESERVE_F_HAT,
55  PRE_PHI_HUT | PRE_PSI | FFTW_INIT | FFT_OUT_OF_PLACE, 6);
56 
57  /* pseudo-random nodes */
58  for (j = 0; j < plan.M_total; j++)
59  {
60  plan.x[2*j]= nfft_drand48() - K(0.5);
61  plan.x[2*j+1]= K(0.5) * nfft_drand48();
62  }
63 
64  /* precomputation (for NFFT, node-dependent) */
65  nfsft_precompute_x(&plan);
66 
67  /* pseudo-random Fourier coefficients */
68  for (k = 0; k <= plan.N; k++)
69  for (n = -k; n <= k; n++)
70  plan.f_hat[NFSFT_INDEX(k,n,&plan)] =
71  nfft_drand48() - K(0.5) + _Complex_I*(nfft_drand48() - K(0.5));
72 
73  /* Direct transformation, display result. */
74  nfsft_trafo_direct(&plan);
75  printf("Vector f (NDSFT):\n");
76  for (j = 0; j < plan.M_total; j++)
77  printf("f[%+2d] = %+5.3" FE " %+5.3" FE "*I\n",j,
78  creal(plan.f[j]), cimag(plan.f[j]));
79 
80  printf("\n");
81 
82  /* Fast approximate transformation, display result. */
83  nfsft_trafo(&plan);
84  printf("Vector f (NFSFT):\n");
85  for (j = 0; j < plan.M_total; j++)
86  printf("f[%+2d] = %+5.3" FE " %+5.3" FE "*I\n",j,
87  creal(plan.f[j]), cimag(plan.f[j]));
88 
89  printf("\n");
90 
91  /* Direct adjoint transformation, display result. */
92  nfsft_adjoint_direct(&plan);
93  printf("Vector f_hat (NDSFT):\n");
94  for (k = 0; k <= plan.N; k++)
95  for (n = -k; n <= k; n++)
96  fprintf(stdout,"f_hat[%+2d,%+2d] = %+5.3" FE " %+5.3" FE "*I\n",k,n,
97  creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]),
98  cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)]));
99 
100  printf("\n");
101 
102  /* Fast approximate adjoint transformation, display result. */
103  nfsft_adjoint(&plan);
104  printf("Vector f_hat (NFSFT):\n");
105  for (k = 0; k <= plan.N; k++)
106  {
107  for (n = -k; n <= k; n++)
108  {
109  fprintf(stdout,"f_hat[%+2d,%+2d] = %+5.3" FE " %+5.3" FE "*I\n",k,n,
110  creal(plan.f_hat[NFSFT_INDEX(k,n,&plan)]),
111  cimag(plan.f_hat[NFSFT_INDEX(k,n,&plan)]));
112  }
113  }
114 
115  /* Finalize the plan. */
116  nfsft_finalize(&plan);
117 
118  /* Destroy data precomputed for fast polynomial transform. */
119  nfsft_forget();
120 }
121 
122 int main(void)
123 {
124  printf("Computing an NDSFT, an NFSFT, an adjoint NDSFT, and an adjoint NFSFT"
125  "...\n\n");
126  simple_test_nfsft();
127  return EXIT_SUCCESS;
128 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1