From 4806fda0ebdc9748e8e217ef2ed07811193e8dad Mon Sep 17 00:00:00 2001
From: Berk Silemek <berk.silemek@gmail.com>
Date: Mon, 14 Nov 2022 14:04:40 +0000
Subject: [PATCH] Fortran code to program ADC without any filter

---
 Software/ADC/rec_m4i_fifo_tdfilter.f | 104 +++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 Software/ADC/rec_m4i_fifo_tdfilter.f

diff --git a/Software/ADC/rec_m4i_fifo_tdfilter.f b/Software/ADC/rec_m4i_fifo_tdfilter.f
new file mode 100644
index 0000000..a737603
--- /dev/null
+++ b/Software/ADC/rec_m4i_fifo_tdfilter.f
@@ -0,0 +1,104 @@
+c     gfortran -O2 rec_m4i_fifo_tdfilter.f m4iset_extrig_rms.c -mcmodel=medium /usr/lib64/libspcm_linux.so -o rec_m4i_tdfltr
+
+      use iso_c_binding
+
+      implicit real*8 (a-h,o-z)
+      
+c      integer(kind=c_int) :: fzeig      
+      integer(kind=c_long_long) :: fzeig      
+c      integer(kind=c_intptr_t) :: fzeig      
+
+      integer*2 fid1(5000000000)
+      complex*16 fmix0(10001)
+      integer*8 ndp
+      complex*16 chelp0
+      character*64 argu
+
+      pi=4.d0*datan(1.d0)
+      dt=1.d0/500.d6
+
+      nfit2=1000
+      nfit=2*nfit2
+
+      call getarg(1,argu)
+      read(argu,*)fsig
+
+c      ndp=2000*1000000
+      ndp=2000*240*4096
+
+
+
+c -----------------------------------------------
+
+      windi0=0.d0
+      do i=1,2*nfit+1
+      x=dfloat(i-1)/dfloat(nfit)-1.d0
+      fmix0(i)=cdexp((0.d0,2.d0)*pi*fsig*dfloat(i-1)*dt)
+      windi0=windi0+wind(x)
+      fmix0(i)=fmix0(i)*wind(x)
+      enddo
+
+
+c -----------------------------------------------
+
+      adummy=m4iopen(fzeig)
+
+      adummy=m4iset(fzeig,fid1,ndp)
+
+      adummy=m4iclose(fzeig)
+
+c -----------------------------------------------
+
+
+c      iphi0=0
+      
+      do i=1,ndp-2*nfit-1,nfit
+
+      time=dfloat(i-1)*dt
+      chelp0=(0.d0,0.d0)
+      
+      do ii=2,2*nfit
+      chelp0=chelp0+dcmplx(dfloat(fid1(i-1+ii)),0.d0)*fmix0(ii)
+      enddo
+      
+      chelp0=2.d0*chelp0*cdexp((0.d0,2.d0)*pi*fsig*time)/windi0
+     
+c      help0=datan2(dimag(chelp0),dreal(chelp0))
+c      if(i.eq.1)dphi0=help0
+c      dphi0=help0-dphi0
+c      if(dphi0.gt.5.0d0)iphi0=iphi0+1
+c      if(dphi0.lt.-5.0d0)iphi0=iphi0-1
+c      dphi0=help0
+c      help0=help0-2.d0*pi*iphi0
+
+c      print *,time+2*nfit2*dt
+c     & ,dreal(chelp0),dimag(chelp0),cdabs(chelp0),help0*180.d0/pi
+      print *,time+2*nfit2*dt,cdabs(chelp0)
+
+      enddo
+
+c      print *,i,time+nfit*dt,cdabs(chelp0)
+
+
+      end
+
+
+c--------------------------------------------------------------------
+
+      real*8 function wind(x)
+      implicit real*8 (a-h,o-z)
+      pi=4.d0*datan(1.d0)
+      if(dabs(x).le.1.d0) then
+      if(dabs(x).ne.0.d0) then
+      wind=dexp(-1.d0/(1.d0-x*x))*dsin(2.073d0*pi*x)/x
+      else
+      wind=dexp(-1.d0/(1.d0-x*x))*2.073d0*pi
+      endif
+c      wind=dexp(-1.d0/(1.d0-x*x))
+c      wind=1.d0
+      else
+      wind=0.d0
+      endif
+      end
+
+
-- 
GitLab