Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fft / fft_fftpack.cpp
index f87426fa675b988878bb5cb374efd420111c88f4..49615f9ec0079175675b28d613f32c9f3f46a092 100644 (file)
@@ -68,16 +68,13 @@ struct gmx_fft
     int             ndim;     /**< Dimensions, including our subdimensions.  */
     int             n;        /**< Number of points in this dimension.       */
     int             ifac[15]; /**< 15 bytes needed for cfft and rfft         */
-    struct gmx_fft *next;     /**< Pointer to next dimension, or NULL.       */
-    real  *         work;     /**< 1st 4n reserved for cfft, 1st 2n for rfft */
+    struct gmx_fftnext;     /**< Pointer to next dimension, or NULL.       */
+    real*           work;     /**< 1st 4n reserved for cfft, 1st 2n for rfft */
 };
 
-int
-gmx_fft_init_1d(gmx_fft_t *        pfft,
-                int                nx,
-                int gmx_unused     flags)
+int gmx_fft_init_1d(gmx_fft_t* pfft, int nx, int gmx_unused flags)
 {
-    gmx_fft_t    fft;
+    gmx_fft_t fft;
 
     if (pfft == nullptr)
     {
@@ -86,7 +83,7 @@ gmx_fft_init_1d(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
+    if ((fft = static_cast<struct gmx_fft*>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -95,7 +92,7 @@ gmx_fft_init_1d(gmx_fft_t *        pfft,
     fft->n    = nx;
 
     /* Need 4*n storage for 1D complex FFT */
-    if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx)))) == nullptr)
+    if ((fft->work = static_cast<real*>(malloc(sizeof(real) * (4 * nx)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -111,13 +108,9 @@ gmx_fft_init_1d(gmx_fft_t *        pfft,
 };
 
 
-
-int
-gmx_fft_init_1d_real(gmx_fft_t *        pfft,
-                     int                nx,
-                     int gmx_unused     flags)
+int gmx_fft_init_1d_real(gmx_fft_t* pfft, int nx, int gmx_unused flags)
 {
-    gmx_fft_t    fft;
+    gmx_fft_t fft;
 
     if (pfft == nullptr)
     {
@@ -126,7 +119,7 @@ gmx_fft_init_1d_real(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
+    if ((fft = static_cast<struct gmx_fft*>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -135,7 +128,7 @@ gmx_fft_init_1d_real(gmx_fft_t *        pfft,
     fft->n    = nx;
 
     /* Need 2*n storage for 1D real FFT */
-    if ((fft->work = static_cast<real *>(malloc(sizeof(real)*(2*nx)))) == nullptr)
+    if ((fft->work = static_cast<real*>(malloc(sizeof(real) * (2 * nx)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -150,15 +143,11 @@ gmx_fft_init_1d_real(gmx_fft_t *        pfft,
     return 0;
 }
 
-int
-gmx_fft_init_2d_real(gmx_fft_t *        pfft,
-                     int                nx,
-                     int                ny,
-                     int                flags)
+int gmx_fft_init_2d_real(gmx_fft_t* pfft, int nx, int ny, int flags)
 {
-    gmx_fft_t     fft;
-    int           nyc = (ny/2 + 1);
-    int           rc;
+    gmx_fft_t fft;
+    int       nyc = (ny / 2 + 1);
+    int       rc;
 
     if (pfft == nullptr)
     {
@@ -168,17 +157,17 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
     *pfft = nullptr;
 
     /* Create the X transform */
-    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
+    if ((fft = static_cast<struct gmx_fft*>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
 
-    fft->n    = nx;
+    fft->n = nx;
 
     /* Need 4*nx storage for 1D complex FFT, and another
      * 2*nx*nyc elements for complex-to-real storage in our high-level routine.
      */
-    if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx+2*nx*nyc)))) == nullptr)
+    if ((fft->work = static_cast<real*>(malloc(sizeof(real) * (4 * nx + 2 * nx * nyc)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -186,7 +175,7 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
     fftpack_cffti1(nx, fft->work, fft->ifac);
 
     /* Create real Y transform as a link from X */
-    if ( (rc = gmx_fft_init_1d_real(&(fft->next), ny, flags)) != 0)
+    if ((rc = gmx_fft_init_1d_real(&(fft->next), ny, flags)) != 0)
     {
         free(fft);
         return rc;
@@ -197,22 +186,18 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
 }
 
 
-int
-gmx_fft_1d               (gmx_fft_t                  fft,
-                          enum gmx_fft_direction     dir,
-                          void *                     in_data,
-                          void *                     out_data)
+int gmx_fft_1d(gmx_fft_t fft, enum gmx_fft_direction dir, void* in_data, void* out_data)
 {
-    int             i, n;
-    real       *    p1;
-    real       *    p2;
+    int   i, n;
+    real* p1;
+    real* p2;
 
     n = fft->n;
 
     if (n == 1)
     {
-        p1    = static_cast<real *>(in_data);
-        p2    = static_cast<real *>(out_data);
+        p1    = static_cast<real*>(in_data);
+        p2    = static_cast<real*>(out_data);
         p2[0] = p1[0];
         p2[1] = p1[1];
     }
@@ -222,11 +207,11 @@ gmx_fft_1d               (gmx_fft_t                  fft,
      */
     if (in_data != out_data)
     {
-        p1 = static_cast<real *>(in_data);
-        p2 = static_cast<real *>(out_data);
+        p1 = static_cast<real*>(in_data);
+        p2 = static_cast<real*>(out_data);
 
         /* n complex = 2*n real elements */
-        for (i = 0; i < 2*n; i++)
+        for (i = 0; i < 2 * n; i++)
         {
             p2[i] = p1[i];
         }
@@ -238,11 +223,11 @@ gmx_fft_1d               (gmx_fft_t                  fft,
 
     if (dir == GMX_FFT_FORWARD)
     {
-        fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, -1);
+        fftpack_cfftf1(n, static_cast<real*>(out_data), fft->work + 2 * n, fft->work, fft->ifac, -1);
     }
     else if (dir == GMX_FFT_BACKWARD)
     {
-        fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, 1);
+        fftpack_cfftf1(n, static_cast<real*>(out_data), fft->work + 2 * n, fft->work, fft->ifac, 1);
     }
     else
     {
@@ -254,23 +239,18 @@ gmx_fft_1d               (gmx_fft_t                  fft,
 }
 
 
-
-int
-gmx_fft_1d_real          (gmx_fft_t                  fft,
-                          enum gmx_fft_direction     dir,
-                          void *                     in_data,
-                          void *                     out_data)
+int gmx_fft_1d_real(gmx_fft_t fft, enum gmx_fft_direction dir, void* in_data, void* out_data)
 {
-    int           i, n;
-    real       *  p1;
-    real       *  p2;
+    int   i, n;
+    real* p1;
+    real* p2;
 
     n = fft->n;
 
     if (n == 1)
     {
-        p1    = static_cast<real *>(in_data);
-        p2    = static_cast<real *>(out_data);
+        p1    = static_cast<real*>(in_data);
+        p2    = static_cast<real*>(out_data);
         p2[0] = p1[0];
         if (dir == GMX_FFT_REAL_TO_COMPLEX)
         {
@@ -286,10 +266,10 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
          */
         if (in_data != out_data)
         {
-            p1 = static_cast<real *>(in_data);
-            p2 = static_cast<real *>(out_data);
+            p1 = static_cast<real*>(in_data);
+            p2 = static_cast<real*>(out_data);
 
-            for (i = 0; i < 2*(n/2+1); i++)
+            for (i = 0; i < 2 * (n / 2 + 1); i++)
             {
                 p2[i] = p1[i];
             }
@@ -298,27 +278,26 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
         /* Elements 0 ..   n-1 in work are used for ffac values,
          * Elements n .. 2*n-1 are internal FFTPACK work space.
          */
-        fftpack_rfftf1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
+        fftpack_rfftf1(n, static_cast<real*>(out_data), fft->work + n, fft->work, fft->ifac);
 
         /*
          * FFTPACK has a slightly more compact storage than we, time to
          * convert it: ove most of the array one step up to make room for
          * zero imaginary parts.
          */
-        p2 = static_cast<real *>(out_data);
-        for (i = n-1; i > 0; i--)
+        p2 = static_cast<real*>(out_data);
+        for (i = n - 1; i > 0; i--)
         {
-            p2[i+1] = p2[i];
+            p2[i + 1] = p2[i];
         }
         /* imaginary zero freq. */
         p2[1] = 0;
 
         /* Is n even? */
-        if ( (n & 0x1) == 0)
+        if ((n & 0x1) == 0)
         {
-            p2[n+1] = 0;
+            p2[n + 1] = 0;
         }
-
     }
     else if (dir == GMX_FFT_COMPLEX_TO_REAL)
     {
@@ -328,15 +307,15 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
          * is more compact than ours (2 reals) it will fit, so compact it
          * and copy on-the-fly to the output array.
          */
-        p1 = static_cast<real *>(in_data);
-        p2 = static_cast<real *>(out_data);
+        p1 = static_cast<real*>(in_data);
+        p2 = static_cast<real*>(out_data);
 
         p2[0] = p1[0];
         for (i = 1; i < n; i++)
         {
-            p2[i] = p1[i+1];
+            p2[i] = p1[i + 1];
         }
-        fftpack_rfftb1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
+        fftpack_rfftb1(n, static_cast<real*>(out_data), fft->work + n, fft->work, fft->ifac);
     }
     else
     {
@@ -348,24 +327,20 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
 }
 
 
-int
-gmx_fft_2d_real          (gmx_fft_t                  fft,
-                          enum gmx_fft_direction     dir,
-                          void *                     in_data,
-                          void *                     out_data)
+int gmx_fft_2d_real(gmx_fft_t fft, enum gmx_fft_direction dir, void* in_data, void* out_data)
 {
-    int                i, j, nx, ny, nyc;
-    t_complex     *    data;
-    real       *       work;
-    real       *       p1;
-    real       *       p2;
+    int        i, j, nx, ny, nyc;
+    t_complex* data;
+    real*      work;
+    real*      p1;
+    real*      p2;
 
     nx = fft->n;
     ny = fft->next->n;
     /* Number of complex elements in y direction */
-    nyc = (ny/2+1);
+    nyc = (ny / 2 + 1);
 
-    work = fft->work+4*nx;
+    work = fft->work + 4 * nx;
 
     if (dir == GMX_FFT_REAL_TO_COMPLEX)
     {
@@ -378,23 +353,23 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
          */
         if (in_data != out_data)
         {
-            p1 = static_cast<real *>(in_data);
-            p2 = static_cast<real *>(out_data);
+            p1 = static_cast<real*>(in_data);
+            p2 = static_cast<real*>(out_data);
 
             for (i = 0; i < nx; i++)
             {
                 for (j = 0; j < ny; j++)
                 {
-                    p2[i*nyc*2+j] = p1[i*ny+j];
+                    p2[i * nyc * 2 + j] = p1[i * ny + j];
                 }
             }
         }
-        data = static_cast<t_complex *>(out_data);
+        data = static_cast<t_complex*>(out_data);
 
         /* y real-to-complex FFTs */
         for (i = 0; i < nx; i++)
         {
-            gmx_fft_1d_real(fft->next, GMX_FFT_REAL_TO_COMPLEX, data+i*nyc, data+i*nyc);
+            gmx_fft_1d_real(fft->next, GMX_FFT_REAL_TO_COMPLEX, data + i * nyc, data + i * nyc);
         }
 
         /* Transform to get X data in place */
@@ -403,12 +378,11 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
         /* Complex-to-complex X FFTs */
         for (i = 0; i < nyc; i++)
         {
-            gmx_fft_1d(fft, GMX_FFT_FORWARD, data+i*nx, data+i*nx);
+            gmx_fft_1d(fft, GMX_FFT_FORWARD, data + i * nx, data + i * nx);
         }
 
         /* Transpose back */
         gmx_fft_transpose_2d(data, data, nyc, nx);
-
     }
     else if (dir == GMX_FFT_COMPLEX_TO_REAL)
     {
@@ -422,13 +396,13 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
          */
         if (in_data != out_data)
         {
-            memcpy(work, in_data, sizeof(t_complex)*nx*nyc);
-            data = reinterpret_cast<t_complex *>(work);
+            memcpy(work, in_data, sizeof(t_complex) * nx * nyc);
+            data = reinterpret_cast<t_complex*>(work);
         }
         else
         {
             /* in-place */
-            data = reinterpret_cast<t_complex *>(out_data);
+            data = reinterpret_cast<t_complex*>(out_data);
         }
 
         /* Transpose to get X arrays */
@@ -437,7 +411,7 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
         /* Do X iFFTs */
         for (i = 0; i < nyc; i++)
         {
-            gmx_fft_1d(fft, GMX_FFT_BACKWARD, data+i*nx, data+i*nx);
+            gmx_fft_1d(fft, GMX_FFT_BACKWARD, data + i * nx, data + i * nx);
         }
 
         /* Transpose to get Y arrays */
@@ -446,7 +420,7 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
         /* Do Y iFFTs */
         for (i = 0; i < nx; i++)
         {
-            gmx_fft_1d_real(fft->next, GMX_FFT_COMPLEX_TO_REAL, data+i*nyc, data+i*nyc);
+            gmx_fft_1d_real(fft->next, GMX_FFT_COMPLEX_TO_REAL, data + i * nyc, data + i * nyc);
         }
 
         if (in_data != out_data)
@@ -454,14 +428,14 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
             /* Output (pointed to by data) is now in padded format.
              * Pack it into out_data if we were doing an out-of-place transform.
              */
-            p1 = reinterpret_cast<real *>(data);
-            p2 = static_cast<real *>(out_data);
+            p1 = reinterpret_cast<real*>(data);
+            p2 = static_cast<real*>(out_data);
 
             for (i = 0; i < nx; i++)
             {
                 for (j = 0; j < ny; j++)
                 {
-                    p2[i*ny+j] = p1[i*nyc*2+j];
+                    p2[i * ny + j] = p1[i * nyc * 2 + j];
                 }
             }
         }
@@ -475,8 +449,7 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
     return 0;
 }
 
-void
-gmx_fft_destroy(gmx_fft_t      fft)
+void gmx_fft_destroy(gmx_fft_t fft)
 {
     if (fft != nullptr)
     {
@@ -489,6 +462,4 @@ gmx_fft_destroy(gmx_fft_t      fft)
     }
 }
 
-void gmx_fft_cleanup()
-{
-}
+void gmx_fft_cleanup() {}