kml_fft(f)_plan_r2r
Create a plan for the n-dimensional real-to-real (R2R) transform of a single contiguous data sequence.
Interface Definition
C interface:
kml_fft_plan kml_fft_plan_r2r(int rank, const int *n, double *in, double *out, const kml_fft_r2r_kind *kind, unsigned flags);
kml_fftf_plan kml_fftf_plan_r2r(int rank, const int *n, float *in, float *out, const kml_fftf_r2r_kind *kind, unsigned flags);
Fortran interface:
RES = KML_FFT_PLAN_R2R(RANK, N, IN, OUT, KIND, FLAGS);
RES = KML_FFTF_PLAN_R2R(RANK, N, IN, OUT, KIND, FLAGS);
KML_FFT_REDFT11 and KML_FFT_ROODFT11 support only sequences whose length is an integer multiple of 4. Other transforms support only sequences whose length is an integer multiple of 2.
Return Value
The function returns a structure pointer of the kml_fft(f)_plan type. This object is used as a parameter in the kml_fft(f)_execute function to perform FFT on the current input and output. In addition, the object may also be added into the kml_fft(f)_execute_r2r function as a parameter to perform FFT on the new input and output.
If this function returns a non-null pointer, the plan has been successfully executed. Otherwise, the plan failed to be executed.
Parameters
Parameter |
Data Type |
Description |
Input/Output |
|---|---|---|---|
rank |
int |
Dimension of FFT. The constraint is 1 <= rank <= 3. |
Input |
n |
const int* |
Indicates an array whose dimension is rank, including the size of each dimension in the FFT sequence. The constraint is n[i] >= 1, for i in 0 to rank - 1. |
Input |
in |
|
Inputs the data to be transformed. |
Input |
out |
|
Outputs the data generated using FFT. |
Output |
kind |
|
kind is an array whose size is rank, including the R2R transform type in each dimension of an FFT sequence. kind[i] (for i in 0 to rank - 1) has the following options:
|
Input |
flags |
unsigned int |
A planning option, not in use. |
Input |
Dependencies
C: "kfft.h"
Fortran: "kfft.f03"
Examples
C interface:
int rank = 2;
int *n;
n = (int*)kml_fft_malloc(sizeof(int) * rank);
n[0] = 2;
n[1] = 4;
double init[8] = {1, 2, 3, 4, 5, 6, 7, 8};
double *in;
in = (double*)kml_fft_malloc(sizeof(double) * n[0] * n[1]);
for (int i = 0; i < n[0] * n[1]; i++) {
in[i] = init[i];
}
double *out;
out = (double*)kml_fft_malloc(sizeof(double) * n[0] * n[1]);
kml_fft_r2r_kind *kind;
kind = (kml_fft_r2r_kind*)kml_fft_malloc(sizeof(kml_fft_r2r_kind) * rank);
kind[0] = KML_FFT_DHT;
kind[1] = KML_FFT_DHT;
kml_fft_plan plan;
plan = kml_fft_plan_r2r(rank, n, in, out, kind, KML_FFT_ESTIMATE);
kml_fft_execute_r2r(plan, in, out);
kml_fft_destroy_plan(plan);
kml_fft_free(n);
kml_fft_free(kind);
kml_fft_free(in);
kml_fft_free(out);
/*
* out = {3.600000e+01, -8.000000e+00, -4.000000e+00, 0.000000e+00,
* -1.600000e+01, 0.000000e+00, 0.000000e+00, 0.000000e+00}
*/
Fortran interface:
INTEGER(C_INT) :: RANK = 2
INTEGER(C_INT) :: N(2)
INTEGER(C_INT) :: KIND(2)
REAL(C_DOUBLE) :: INIT(8)
REAL(C_DOUBLE), POINTER :: IN(:), OUT(:)
TYPE(C_PTR) :: PIN, POUT
INTEGER(C_SIZE_T) :: SIZE
SIZE = N(1) * N(2)
DATA N/2, 4/
DATA KIND/KML_FFT_DHT, KML_FFT_DHT/
PIN = KML_FFT_MALLOC(8 * SIZE)
POUT = KML_FFT_MALLOC(8 * SIZE)
CALL C_F_POINTER(PIN, IN, SHAPE=[SIZE])
CALL C_F_POINTER(POUT, OUT, SHAPE=[SIZE])
DATA INIT/1, 2, 3, 4, 5, 6, 7, 8/
INTEGER :: I
DO WHILE(I <= SIZE)
IN(I) = INIT(I)
END DO
TYPE(C_PTR) :: PLAN
PLAN = KML_FFT_PLAN_R2R(RANK, N, IN, OUT, KIND, KML_FFT_ESTIMATE)
CALL KML_FFT_EXECUTE_R2R(PLAN, IN, OUT)
CALL KML_FFT_DESTROY_PLAN(PLAN)
CALL KML_FFT_FREE(PIN)
CALL KML_FFT_FREE(POUT)
!
! OUT = /3.600000E+01, -8.000000E+00, -4.000000E+00, 0.000000E+00,
! -1.600000E+01, 0.000000E+00, 0.000000E+00, 0.000000E+00/
!