From: hackbard Date: Sat, 18 Sep 2004 11:45:33 +0000 (+0000) Subject: init fourier.* (will be changed) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=15a0affd01053e899568c0ee1e7bd1315e11f925;p=my-code%2Fapi.git init fourier.* (will be changed) --- diff --git a/fourier/fourier.c b/fourier/fourier.c new file mode 100644 index 0000000..14878e2 --- /dev/null +++ b/fourier/fourier.c @@ -0,0 +1,57 @@ +/* fourier.c -- fourier transformation api + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include "fourier.h" + +int fourier_init(t_fourier *fourier,int outfd) { + + fprintf(outfd,"[fourier] initializing fourier api ...\n"); + + fourier->outfd=outfd; + fourier->type=0; + fourier->dim=0; + + return F_SUCCESS; +} + +int fourier_set_datalen(t_fourier *fourier,int dim,int len) { + + int i; + + if(dim>MAX_DIM) { + fprintf(fourier->outfd,"[fourier] dimension %d not supported\n",dim); + return F_SET_DLEN_ERROR; + } + + fourier->data_len[dim]=len; + + return F_SUCCESS; +} + +int fourier_malloc(t_fourier *fourier) { + + int i; + + if(fourier->dim==0) { + fprintf(fourier->outfd,"[fourier] dimension not specified\n"); + return F_DIM_ERROR; + } + for(i=0;idim;i++) { + if(fourier->data_len[i]==0) { + fprintf(fourier->outfd,"[fourier] invalid data len for dim %d\n",i); + return F_DLEN_ERROR; + } + } + + for(i=0;idim;i++) { + if((fourier->data[i]=(t_complex *)malloc(sizeof(t_complex)*fourier->data_len[i]))==NULL) { + fprintf(fourier->outfd,"[fourier] malloc for data dim %d failed\n",i); + return F_MALLOC_ERROR; + } + } + + return F_SUCCESS; +} diff --git a/fourier/fourier.h b/fourier/fourier.h new file mode 100644 index 0000000..5a8ddb3 --- /dev/null +++ b/fourier/fourier.h @@ -0,0 +1,33 @@ +/* fourier.h -- fourier headers */ + +#ifndef FOURIER_H +#define FOURIER_H + +/* includes */ +#include + +/* defines */ +#define F_SUCCESS 1 +#define F_ERROR -1 +#define F_DIM_ERROR -2 +#define F_DLEN_ERROR -3 +#define F_MALLOC_ERROR -4 +#define F_SET_DLEN_ERROR -5 + +#define MAX_DIM 3 + +/* fourier specific variables */ +typedef struct s_complex { + double r; + double i; +} t_complex; + +typedef struct s_fourier { + int outfd; + unsigned char type; + int dim; + t_complex *data[MAX_DIM]; + int data_len[MAX_DIM]; +} t_fourier; + +#endif