int fourier_init(t_fourier *fourier,int outfd) {
- fprintf(outfd,"[fourier] initializing fourier api ...\n");
+ dprintf(outfd,"[fourier] initializing fourier api ...\n");
fourier->outfd=outfd;
fourier->type=0;
fourier->data[i]=(t_complex *)malloc(fourier->data_len[i]*sizeof(t_complex));
fourier->ftdata[i]=(t_complex *)malloc(fourier->data_len[i]*sizeof(t_complex));
if((fourier->data[i]==NULL)||(fourier->ftdata[i]==NULL)) {
- fprintf(fourier->outfd,"[fourier] malloc failed\n");
+ dprintf(fourier->outfd,"[fourier] malloc failed\n");
return F_ALLOC_FAIL;
}
}
int i;
- fprintf(fourier->outfd,"[fourier] shutdown\n");
+ dprintf(fourier->outfd,"[fourier] shutdown\n");
for(i=0;i<fourier->dim;i++) {
- free(fourier->data[dim]);
- free(fourier->ftdata[dim]);
+ free(fourier->data[i]);
+ free(fourier->ftdata[i]);
}
return F_SUCCESS;
double arg;
if(fourier->type&FWD) {
- for(dim=1;dim<=fourier->dim;dim++) {
+ for(dim=0;dim<fourier->dim;dim++) {
for(k=0;k<fourier->data_len[dim];k++) {
fourier->ftdata[dim][k].r=0;
fourier->ftdata[dim][k].i=0;
for(i=0;i<fourier->data_len[dim];i++) {
/* f(k) = 1/N sum(n=0-N) f(n) exp(-i*k*2*PI*n/N) */
arg=-1.0*k*M_PI*i/fourier->data_len[dim];
- fourier->ftdata[dim][k].r+=(cos(arg)*fourier->data[dim][i]-sin(arg)*fourier->data[dim][i].i);
- fourier->ftdata[dim][k].i+=(sin(arg)*fourier->data[dim][i]+cos(arg)*fourier->data[dim][i].i);
+ fourier->ftdata[dim][k].r+=(cos(arg)*fourier->data[dim][i].r-sin(arg)*fourier->data[dim][i].i);
+ fourier->ftdata[dim][k].i+=(sin(arg)*fourier->data[dim][i].r+cos(arg)*fourier->data[dim][i].i);
}
fourier->ftdata[dim][k].r/=fourier->data_len[dim];
fourier->ftdata[dim][k].i/=fourier->data_len[dim];
fourier->data[dim][k].i=0;
for(i=0;i<fourier->data_len[dim];i++) {
arg=1.0*k*M_PI*i/fourier->data_len[dim];
- fourier->data[dim][k].r+=(cos(arg)*fourier->ftdata[dim][i]-sin(arg)*fourier->ftdata[dim][i].i);
- fourier->data[dim][k].i+=(sin(arg)*fourier->ftdata[dim][i]+cos(arg)*fourier->ftdata[dim][i].i);
+ fourier->data[dim][k].r+=(cos(arg)*fourier->ftdata[dim][i].r-sin(arg)*fourier->ftdata[dim][i].i);
+ fourier->data[dim][k].i+=(sin(arg)*fourier->ftdata[dim][i].r+cos(arg)*fourier->ftdata[dim][i].i);
}
}
}
return F_SUCCESS;
}
+int fourier_dft_2d(t_fourier *fourier) {
+ return 0;
+}
+
+int fourier_dft_3d(t_fourier *fourier) {
+ return 0;
+}
+
int fourier_calc(t_fourier *fourier) {
- fprintf(fourier->outfd,"[fourier] %d dimensional %c-%cft calculation ...\n",
+ dprintf(fourier->outfd,"[fourier] %d dimensional %c-%cft calculation ...\n",
fourier->dim,
((fourier->type&FWD)?'f':'b'),
((fourier->type&DFT)?'d':'f'));
fourier_dft_3d(fourier);
break;
default:
- fprintf(fourier->outfd,"[fourier] dimension failure\n");
+ dprintf(fourier->outfd,"[fourier] dimension failure\n");
return F_DIM_FAILURE;
}
return F_SUCCESS;
}
else {
- fprintf(fourier->outfd,"[fourier] fft not supported by now\n");
+ dprintf(fourier->outfd,"[fourier] fft not supported by now\n");
return F_NOT_SUPPORTED;
}
}