/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* file: fftpackC.c * contents: C languange interface to fftpack routines * author: M. Borland, 1995. $Log: fftpackC.c,v $ Revision 1.7 2003/07/22 20:50:39 soliday atexit is always used. Revision 1.6 2002/08/14 16:41:20 soliday Added Open License Revision 1.5 1999/05/28 14:55:01 soliday Removed compiler warnings under Linux. Revision 1.4 1999/04/22 03:34:10 borland Change to avoid WIN32 compiler warning. Revision 1.3 1999/04/22 03:32:43 borland Eliminated references to mdb.h to solve WIN32 build problem. * Revision 1.2 1995/09/05 21:13:16 saunders * First test release of the SDDS1.5 package. * */ #include "stdio.h" #include "stdlib.h" #include "fftpack.h" #include "fftpackC.h" #include "string.h" #define SWAP_DOUBLE(x, y) {double tmp_swap_double; tmp_swap_double=(x); (x)=(y); (y)=tmp_swap_double; } typedef struct { double *array; long length; } FFTPACK_WORKSPACE; static FFTPACK_WORKSPACE *realWorkspace = NULL; static long realWorkspaces = 0; static FFTPACK_WORKSPACE *complexWorkspace = NULL; static long complexWorkspaces = 0; static short atexitFFTpackRegistered = 0; void atexitFFTpack(void) { long i; if (realWorkspace) { for (i=0; i=0; i--) output[i+1] = output[i]; if (!realFFT(output+1, n, flags)) return 0; output[0] = output[1]; /* DC real term */ output[1] = 0; /* DC imag term */ if (n%2==0) output[n+1] = 0; /* Nyquist real term */ return 1; } /* inverse FFT: input is floor[n/2] complex points */ output[0] = input[0]; for (i=1; i<=n; i++) output[i] = input[i+1]; if (!realFFT(output, n, flags)) return 0; return 1; } long complexFFT(double *data, long n, unsigned long flags) { long i, iWorkspace; if (flags&(~(INVERSE_FFT|MINUS_I_THETA))) { fputs("invalid flag bits set for realFFT()\n", stderr); exit(1); } if (n<1) return 0; if (n==1) return 1; if (!atexitFFTpackRegistered) { #if defined(ATEXIT_AVAIL) atexit(atexitFFTpack); #endif atexitFFTpackRegistered = 1; } for (iWorkspace=0; iWorkspace