shun_iwasawa a35b8f
#include <stdio.h></stdio.h>
shun_iwasawa a35b8f
#include <stdlib.h></stdlib.h>
shun_iwasawa a35b8f
#include <sys times.h=""></sys>
shun_iwasawa a35b8f
#include <unistd.h></unistd.h>
shun_iwasawa a35b8f
#include "kiss_fft.h"
shun_iwasawa a35b8f
#include "kiss_fftr.h"
shun_iwasawa a35b8f
#include "kiss_fftnd.h"
shun_iwasawa a35b8f
#include "kiss_fftndr.h"
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#include "pstats.h"
shun_iwasawa a35b8f
shun_iwasawa a35b8f
static
shun_iwasawa a35b8f
int getdims(int * dims, char * arg)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
    char *s;
shun_iwasawa a35b8f
    int ndims=0;
shun_iwasawa a35b8f
    while ( (s=strtok( arg , ",") ) ) {
shun_iwasawa a35b8f
        dims[ndims++] = atoi(s);
shun_iwasawa a35b8f
        //printf("%s=%d\n",s,dims[ndims-1]);
shun_iwasawa a35b8f
        arg=NULL;
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
    return ndims;
shun_iwasawa a35b8f
}
shun_iwasawa a35b8f
shun_iwasawa a35b8f
int main(int argc,char ** argv)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
    int k;
shun_iwasawa a35b8f
    int nfft[32];
shun_iwasawa a35b8f
    int ndims = 1;
shun_iwasawa a35b8f
    int isinverse=0;
shun_iwasawa a35b8f
    int numffts=1000,i;
shun_iwasawa a35b8f
    kiss_fft_cpx * buf;
shun_iwasawa a35b8f
    kiss_fft_cpx * bufout;
shun_iwasawa a35b8f
    int real = 0;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    nfft[0] = 1024;// default
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    while (1) {
shun_iwasawa a35b8f
        int c = getopt (argc, argv, "n:ix:r");
shun_iwasawa a35b8f
        if (c == -1)
shun_iwasawa a35b8f
            break;
shun_iwasawa a35b8f
        switch (c) {
shun_iwasawa a35b8f
            case 'r':
shun_iwasawa a35b8f
                real = 1;
shun_iwasawa a35b8f
                break;
shun_iwasawa a35b8f
            case 'n':
shun_iwasawa a35b8f
                ndims = getdims(nfft, optarg );
shun_iwasawa a35b8f
                if (nfft[0] != kiss_fft_next_fast_size(nfft[0]) ) {
shun_iwasawa a35b8f
                    int ng = kiss_fft_next_fast_size(nfft[0]);
shun_iwasawa a35b8f
                    fprintf(stderr,"warning: %d might be a better choice for speed than %d\n",ng,nfft[0]);
shun_iwasawa a35b8f
                }
shun_iwasawa a35b8f
                break;
shun_iwasawa a35b8f
            case 'x':
shun_iwasawa a35b8f
                numffts = atoi (optarg);
shun_iwasawa a35b8f
                break;
shun_iwasawa a35b8f
            case 'i':
shun_iwasawa a35b8f
                isinverse = 1;
shun_iwasawa a35b8f
                break;
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
    int nbytes = sizeof(kiss_fft_cpx);
shun_iwasawa a35b8f
    for (k=0;k
shun_iwasawa a35b8f
        nbytes *= nfft[k];
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#ifdef USE_SIMD        
shun_iwasawa a35b8f
    numffts /= 4;
shun_iwasawa a35b8f
    fprintf(stderr,"since SIMD implementation does 4 ffts at a time, numffts is being reduced to %d\n",numffts);
shun_iwasawa a35b8f
#endif
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    buf=(kiss_fft_cpx*)KISS_FFT_MALLOC(nbytes);
shun_iwasawa a35b8f
    bufout=(kiss_fft_cpx*)KISS_FFT_MALLOC(nbytes);
shun_iwasawa a35b8f
    memset(buf,0,nbytes);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    pstats_init();
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    if (ndims==1) {
shun_iwasawa a35b8f
        if (real) {
shun_iwasawa a35b8f
            kiss_fftr_cfg st = kiss_fftr_alloc( nfft[0] ,isinverse ,0,0);
shun_iwasawa a35b8f
            if (isinverse)
shun_iwasawa a35b8f
                for (i=0;i
shun_iwasawa a35b8f
                    kiss_fftri( st ,(kiss_fft_cpx*)buf,(kiss_fft_scalar*)bufout );
shun_iwasawa a35b8f
            else
shun_iwasawa a35b8f
                for (i=0;i
shun_iwasawa a35b8f
                    kiss_fftr( st ,(kiss_fft_scalar*)buf,(kiss_fft_cpx*)bufout );
shun_iwasawa a35b8f
            free(st);
shun_iwasawa a35b8f
        }else{
shun_iwasawa a35b8f
            kiss_fft_cfg st = kiss_fft_alloc( nfft[0] ,isinverse ,0,0);
shun_iwasawa a35b8f
            for (i=0;i
shun_iwasawa a35b8f
                kiss_fft( st ,buf,bufout );
shun_iwasawa a35b8f
            free(st);
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }else{
shun_iwasawa a35b8f
        if (real) {
shun_iwasawa a35b8f
            kiss_fftndr_cfg st = kiss_fftndr_alloc( nfft,ndims ,isinverse ,0,0);
shun_iwasawa a35b8f
            if (isinverse)
shun_iwasawa a35b8f
                for (i=0;i
shun_iwasawa a35b8f
                    kiss_fftndri( st ,(kiss_fft_cpx*)buf,(kiss_fft_scalar*)bufout );
shun_iwasawa a35b8f
            else
shun_iwasawa a35b8f
                for (i=0;i
shun_iwasawa a35b8f
                    kiss_fftndr( st ,(kiss_fft_scalar*)buf,(kiss_fft_cpx*)bufout );
shun_iwasawa a35b8f
            free(st);
shun_iwasawa a35b8f
        }else{
shun_iwasawa a35b8f
            kiss_fftnd_cfg st= kiss_fftnd_alloc(nfft,ndims,isinverse ,0,0);
shun_iwasawa a35b8f
            for (i=0;i
shun_iwasawa a35b8f
                kiss_fftnd( st ,buf,bufout );
shun_iwasawa a35b8f
            free(st);
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    free(buf); free(bufout);
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    fprintf(stderr,"KISS\tnfft=");
shun_iwasawa a35b8f
    for (k=0;k
shun_iwasawa a35b8f
        fprintf(stderr, "%d,",nfft[k]);
shun_iwasawa a35b8f
    fprintf(stderr,"\tnumffts=%d\n" ,numffts);
shun_iwasawa a35b8f
    pstats_report();
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    kiss_fft_cleanup();
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    return 0;
shun_iwasawa a35b8f
}
shun_iwasawa a35b8f