/**
 * \license This project is released under the BSD 2-clause license
 *
 * Copyright (C) 2014 Xevolver Project. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *    
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#define FFTW_ASL_INCLUDED

#define NOEFFECT (-1)

typedef  long long Int64 ;
typedef  int Int32 ;
typedef  unsigned long long UInt64 ;

enum plan_type
{
  DFFTW_PLAN_DFT_1D,  /* FORTRAN倍精度複素1次元離散フーリエ変換 */
  DFFTW_PLAN_DFT_2D,  /* FORTRAN倍精度複素2次元離散フーリエ変換 */
  DFFTW_PLAN_DFT_3D,  /* FORTRAN倍精度複素3次元離散フーリエ変換 */
  DFFTW_PLAN_DFT,     /* FORTRAN倍精度複素多次元離散フーリエ変換 */
  SFFTW_PLAN_DFT_1D,  /* FORTRAN単精度複素1次元離散フーリエ変換 */
  SFFTW_PLAN_DFT_2D,  /* FORTRAN単精度複素2次元離散フーリエ変換 */
  SFFTW_PLAN_DFT_3D,  /* FORTRAN単精度複素3次元離散フーリエ変換 */
  SFFTW_PLAN_DFT,     /* FORTRAN単精度複素多次元離散フーリエ変換 */
  FFTW_PLAN_DFT_1D,   /* C複素1次元離散フーリエ変換 */
  FFTW_PLAN_DFT_2D,   /* C複素2次元離散フーリエ変換 */
  FFTW_PLAN_DFT_3D,   /* C複素3次元離散フーリエ変換 */
#ifndef PHASE3D
  FFTW_PLAN_DFT       /* C複素多次元離散フーリエ変換 */
#else
  FFTW_PLAN_DFT,      /* C複素多次元離散フーリエ変換 */
  DFFTW_PLAN_DFT_R2C_1D,   /* FORTRAN倍精度実1次元離散フーリエ変換（順変換） */
  DFFTW_PLAN_DFT_C2R_1D,   /* FORTRAN倍精度実1次元離散フーリエ変換（逆変換） */
  DFFTW_PLAN_DFT_R2C_3D,   /* FORTRAN倍精度実3次元離散フーリエ変換（順変換） */
  DFFTW_PLAN_DFT_C2R_3D,   /* FORTRAN倍精度実3次元離散フーリエ変換（逆変換） */
  DFFTW_PLAN_MANY_DFT_R2C, /* FORTRAN倍精度実多重離散フーリエ変換（順変換） */
  DFFTW_PLAN_MANY_DFT_C2R, /* FORTRAN倍精度実多重離散フーリエ変換（逆変換） */
  DFFTW_PLAN_MANY_DFT      /* FORTRAN倍精度複素多重離散フーリエ変換 */
#endif
};

typedef struct double_complex
{
  double real;
  double img;
} Complex16;

typedef struct single_complex
{
  float real;
  float img;
} Complex8;

struct dfftw_plan           /* 倍精度FFTWラッパFORTRAN、プラン構造体 */
{
  Int32 asl_n1;            /* 1次元目の変換のサイズ */
  Int32 asl_n2;            /* 2次元目の変換のサイズ */
  Int32 asl_n3;            /* 3次元目の変換のサイズ */
  Complex16 *asl_indt;     /* 入力データ */
  Complex16 *asl_outdt;    /* 出力データ */
  Int32 asl_fbflag;        /* 変換の方向 1:逆、それ以外:正 */
  Int32 asl_flags;         /* 変換の方法。現状、意味を持たない。*/
  enum plan_type asl_plan_type; /* プランがどの変換に対応するか？*/
#ifdef PHASE3D
  double *asl_dindt;       /* 入力データ（倍精度実数型） */
  double *asl_doutdt;      /* 出力データ（倍精度実数型） */
  Int32 asl_howmany;       /* 多重FFTにおける変換数 */
  Int32 asl_istride;       /* 多重FFTにおける入力データのFFT適用方向ストライド要素数 */
  Int32 asl_idist;         /* 多重FFTにおける入力データの多重方向ストライド要素数 */
  Int32 asl_ostride;       /* 多重FFTにおける出力データのFFT適用方向ストライド要素数 */
  Int32 asl_odist;         /* 多重FFTにおける出力データの多重方向ストライド要素数 */
#endif
};

struct sfftw_plan           /* 単精度FFTWラッパFORTRAN、プラン構造体 */
{
  Int32 asl_n1;            /* 1次元目の変換のサイズ */
  Int32 asl_n2;            /* 2次元目の変換のサイズ */
  Int32 asl_n3;            /* 3次元目の変換のサイズ */
  Complex8 *asl_indt;      /* 入力データ */
  Complex8 *asl_outdt;     /* 出力データ */
  Int32 asl_fbflag;        /* 変換の方向 1:逆、それ以外:正 */
  Int32 asl_flags;         /* 変換の方法。現状、意味を持たない。*/
  enum plan_type asl_plan_type; /* プランがどの変換に対応するか？*/
};

struct fftw_plan            /* FFTWラッパC、プラン構造体 */
{
  Int32 asl_n1;            /* 1次元目の変換のサイズ */
  Int32 asl_n2;            /* 2次元目の変換のサイズ */
  Int32 asl_n3;            /* 3次元目の変換のサイズ */
#ifdef ENABLE_FLOAT
  Complex8 *asl_indt;      /* 入力データ */
  Complex8 *asl_outdt;     /* 出力データ */
#else
  Complex16 *asl_indt;     /* 入力データ */
  Complex16 *asl_outdt;    /* 出力データ */
#endif
  Int32 asl_fbflag;        /* 変換の方向 1:逆、それ以外:正 */
  Int32 asl_flags;         /* 変換の方法。現状、意味を持たない。*/
  enum plan_type asl_plan_type; /* プランがどの変換に対応するか？*/
};

/* ASL関数のEXTERN宣言ここから */
/* 複素1次元離散フーリエ変換 */
extern void cfc1fb_(Int32 *, Complex8 *, Int32 *, Int32 *, Int32 *,
                     float *, Complex8 *, Int32 * ); 
extern void zfc1fb_(Int32 *, Complex16 *, Int32 *, Int32 *, Int32 *,
                     double *, Complex16 *, Int32 * ); 
extern Int32 ASL_cfc1fb(Int32, Complex8 *, Int32, Int32, Int32 *,
                         double *, Complex8 *);
extern Int32 ASL_zfc1fb(Int32, Complex16 *, Int32, Int32, Int32 *,
                         double *, Complex16 *);
/* 複素2次元離散フーリエ変換 */
extern void cfc2fb_(Int32 *, Int32 *, Complex8 *, Int32 *, Int32 *,
                     Int32 *, Int32 *, float *, Complex8 *, Int32 * );
extern void zfc2fb_(Int32 *, Int32 *, Complex16 *, Int32 *, Int32 *,
                     Int32 *, Int32 *, double *, Complex16 *, Int32 * );
extern Int32 ASL_cfc2fb(Int32, Int32, Complex8 *, Int32, Int32, Int32,
                         Int32 *, double *, Complex8 *);
extern Int32 ASL_zfc2fb(Int32, Int32, Complex16 *, Int32, Int32, Int32,
                         Int32 *, double *, Complex16 *);
/* 複素3次元離散フーリエ変換 */
extern void cfc3fb_(Int32 *, Int32 *, Int32 *, Complex8 *, Int32 *,
                     Int32 *, Int32 *, Int32 *, Int32 *, float *,
                     Complex8 *, Int32 * );
extern void zfc3fb_(Int32 *, Int32 *, Int32 *, Complex16 *, Int32 *,
                     Int32 *, Int32 *, Int32 *, Int32 *, double *,
                     Complex16 *, Int32 * );
extern Int32 ASL_cfc3fb(Int32, Int32, Int32, Complex8 *, Int32, Int32,
                         Int32, Int32, Int32 *, double *, Complex8 *);
extern Int32 ASL_zfc3fb(Int32, Int32, Int32, Complex16 *, Int32, Int32,
                         Int32, Int32, Int32 *, double *, Complex16 *);
#ifdef PHASE3D
/* 倍精度実1次元離散フーリエ変換 */
extern void dfr1fb_(Int32 *, double *, Int32 *, Int32 *, Int32 *, double *, double *, Int32 *);
/* 倍精度実3次元離散フーリエ変換 */
extern void dfr3fb_(Int32 *, Int32 *, Int32 *, double *, Int32 *, Int32 *, Int32 *, Int32 *, Int32 *, double *, double *, Int32 *);
/* 倍精度実多重離散フーリエ変換 */
extern void dfrmfb_(Int32 *, Int32 *, double *, Int32 *, Int32 *, Int32 *, Int32 *, double *, double *, Int32 *);
/* 倍精度複素多重離散フーリエ変換 */
/* 入出力配列は実数型として扱っている */
extern void zfcmfb_(Int32 *, Int32 *, double *, Int32 *, Int32 *, Int32 *, Int32 *, double *, double *, Int32 *);
#endif
/* ASL関数のEXTERN宣言ここまで */
