kml_fft(f)_plan_dft_c2r
建立单个连续数据序列n维C2R变换的plan。
接口定义
C interface:
kml_fft_plan kml_fft_plan_dft_c2r(int rank, const int *n, kml_fft_complex *in, double *out, unsigned flags);
kml_fftf_plan kml_fftf_plan_dft_c2r(int rank, const int *n, kml_fftf_complex *in, float *out, unsigned flags);
Fortran interface:
RES = KML_FFT_PLAN_DFT_C2R(RANK, N, IN, OUT, FLAGS);
RES = KML_FFTF_PLAN_DFT_C2R(RANK, N, IN, OUT, FLAGS);
返回值
函数返回一个kml_fft(f)_plan类型的结构体指针。将该对象作为参数传入kml_fft(f)_execute函数中使用,将对当前提供的输入in和输出out执行FFT变换;另外,也可以通过将该对象作为参数传入kml_fft(f)_execute_dft_c2r函数中以对新的输入in和输出out执行FFT变换。
如果函数返回非空指针,则表示plan执行成功,否则表示执行失败。
参数
参数名 |
数据类型 |
描述 |
输入/输出 |
---|---|---|---|
rank |
int |
FFT变换的维度是rank,约束:1 ≤ rank ≤ 3。 |
输入 |
n |
const int* |
n是维度为rank的数组,包含FFT序列每一维度的大小,约束:n[i] ≥ 1, for i in 0 to rank - 1。 |
输入 |
in |
|
输入待变换的数据。 |
输入 |
out |
|
输出快速傅里叶变换后的数据。 |
输出 |
flags |
unsigned int |
planning选项,未使用。 |
输入 |
依赖
C: "kfft.h"
示例
C interface:
int rank = 2; int *n; n = (int*)kml_fft_malloc(sizeof(int) * rank); n[0] = 2; n[1] = 4; double init[6][2] = {{120, 0}, {8, 8}, {0, 0}, {0, 16}, {0, 16}, {-8, 8}}; kml_fft_complex *in; in = (kml_fft_complex*)kml_fft_malloc(sizeof(kml_fft_complex) * n[0] * (n[1] / 2 + 1)); for (int i = 0; i < n[0] * (n[1] / 2 + 1); i++) { in[i][0] = init[i][0]; in[i][1] = init[i][1]; } double *out; out = (double*)kml_fft_malloc(sizeof(double) * n[0] * n[1]); kml_fft_plan plan; plan = kml_fft_plan_dft_c2r(rank, n, in, out, KML_FFT_ESTIMATE); kml_fft_execute_dft_c2r(plan, in, out); kml_fft_destroy_plan(plan); kml_fft_free(n); kml_fft_free(in); kml_fft_free(out); /* * out = {1.280000e+02, 8.000000e+01, 9.600000e+01, 1.760000e+02, * 1.440000e+02, 1.280000e+02, 1.120000e+02, 9.600000e+01} */
Fortran interface:
INTEGER(C_INT) :: RANK = 2 INTEGER(C_INT) :: N(2) REAL(C_DOUBLE), DIMENSION(6, 2) :: INIT DATA N/2, 3/ TYPE(KML_FFT_COMPLEX), POINTER :: IN REAL(C_DOUBLE), POINTER :: OUT TYPE(C_PTR) :: PIN, POUT INTEGER(C_SIZE_T) :: CSIZE, RSIZE CSIZE = N(1) * (N(2) / 2 + 1) RSIZE = N(1) * N(2) PIN = KML_FFT_MALLOC(SIZEOF(16 * CSIZE)) POUT = KML_FFT_MALLOC(8 * RSIZE) CALL C_F_POINTER(PIN, IN, SHAPE=[CSIZE]) CALL C_F_POINTER(POUT, OUT, SHAPE=[RSIZE]) DATA INIT/120, 8, 0, 0, 0, -8, 0, 8, 0, 16, 16, 8/ INTEGER :: I DO WHILE(I <= CSIZE) IN(I)%R = INIT(I, 0) IN(I)%I = INIT(I, 1) END DO TYPE(C_PTR) :: PLAN PLAN = KML_FFT_PLAN_DFT_C2R(RANK, N, IN, OUT, KML_FFT_ESTIMATE) CALL KML_FFT_EXECUTE_DFT_C2R(PLAN, IN, OUT) CALL KML_FFT_DESTROY_PLAN(PLAN) CALL KML_FFT_FREE(PIN) CALL KML_FFT_FREE(POUT) ! ! OUT = /1.280000E+02, 8.000000E+01, 9.600000E+01, 1.760000E+02, ! 1.440000E+02, 1.280000E+02, 1.120000E+02, 9.600000E+01/ !