{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"C This file is a part of the GIFA program\n",
    "C     This software has been developped by the NMR Group in GIF/Yvette.\n",
    "C\n",
    "C     Authors :       M.A.Delsuc, V.Stoven, M.Robin\n",
    "C                     NMR Laboratory,\n",
    "C                     ICSN - CNRS\n",
    "C                     91190 GIF/YVETTE   FRANCE\n",
    "C\n",
    "C     This software cannot be used unless the user have been fully \n",
    "C licensed to do so form the above laboratory.\n",
    "C     This file cannot be copied, duplicated or used in any other program,\n",
    "C without written permission from the authors.\n",
    "C\n",
    "      subroutine fftcpx(fdata,size,sign)\n",
    "c IN\t: size,sign\n",
    "c INOUT\t: fdata\n",
    "C This subroutine performs an in-place complex fourier-transform\n",
    "C on the complexe array fdata of length SIZE.\n",
    "C SIGN = 1 for direct FT and -1 for inverse FT\n",
    "C from numerical recipes, Cambridge univ. press W.H.Press et al.\n",
    "\"\"\"\n",
    "import numpy as np\n",
    "def fftcpx(fdata, sign=1)\n",
    "\"\"\"\n",
    "      implicit none\n",
    "\n",
    "      integer size,sign\n",
    "      real fdata(2*size)\n",
    "\n",
    "#include \"constant.inc\"\n",
    "      real*8 wr,wi,costheta,sintheta,wtemp,theta,dtwopi\n",
    "      real tempr,tempi,swr,swi\n",
    "      integer i,j,n,m,mmax,step\n",
    "\"\"\"\n",
    "    size = len()\n",
    "    dtwopi = sign*2*np.pi\n",
    "#C first bit-reversal of the array (decimation in time)\n",
    "#      n = 2*size\n",
    "#      j = 1\n",
    "#      do 100 i=1,n,2\n",
    "    j = 1\n",
    "    for i in range()\n",
    "               if (j.gt.i) then\n",
    "                   tempr = fdata(j)\n",
    "                   tempi = fdata(j+1)\n",
    "                   fdata(j) = fdata(i)\n",
    "                   fdata(j+1) = fdata(i+1)\n",
    "                   fdata(i) = tempr\n",
    "                   fdata(i+1) = tempi\n",
    "                endif\n",
    "                m = n/2\n",
    "  200           if ((m.ge.2).and.(j.gt.m)) then   ! while...do\n",
    "                   j = j-m\n",
    "                   m = m/2\n",
    "                   goto 200\n",
    "                endif\n",
    "                j = j+m\n",
    "100   continue\n",
    "\n",
    "C here start the butterfly\n",
    "      mmax = 2                       ! runs on power of two\n",
    "300   if (n.gt.mmax) then                      ! while...do\n",
    "           step = 2*mmax\n",
    "           theta = dtwopi/mmax                 ! theta is the angle\n",
    "           costheta = -2.D0*dsin(0.5D0*theta)**2\n",
    "           sintheta = dsin(theta)\n",
    "           wr = 1.D0                        ! used for recursion\n",
    "           wi = 0D0\n",
    "           swr = sngl(wr)\n",
    "           swi = sngl(wi)\n",
    "           do 400 m=1,mmax,2\n",
    "              do 401 i=m,n,step\n",
    "                j = i+mmax\n",
    "                tempr = swr*fdata(j) - swi*fdata(j+1)\n",
    "                tempi = swr*fdata(j+1) + swi*fdata(j)\n",
    "                fdata(j) = fdata(i)-tempr\n",
    "                fdata(j+1) = fdata(i+1)-tempi\n",
    "                fdata(i) = fdata(i)+tempr\n",
    "                fdata(i+1) = fdata(i+1)+tempi\n",
    "  401         continue\n",
    "              wtemp = wr\n",
    "              wr = wr*costheta - wi*sintheta + wr\n",
    "              wi = wi*costheta + wtemp*sintheta + wi\n",
    "              swr = sngl(wr)\n",
    "              swi = sngl(wi)\n",
    " 400         continue\n",
    "           mmax = step\n",
    "      goto 300\n",
    "      endif\n",
    "      return\n",
    "      end\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
