-- GENERATED by C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs" #-}

module BioInf.ViennaRNA.Bindings.FFI.PartFunc
  ( ffi_pf_fold
  , ffi_pf_circ_fold
  , ffi_pf_fold_constrained
  , ffi_pf_circ_fold_constrained
  ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import           Foreign.C.String
import           Foreign.C.Types
import           Foreign.Marshal.Alloc
import           Foreign.Marshal.Array
import           Foreign.Ptr
import           GHC.Float
import qualified Data.Array.IArray as A
import           Unsafe.Coerce

import BioInf.ViennaRNA.Bindings.FFI.Utils





ffi_pf_fold :: String -> IO (Double,String,A.Array (Int,Int) Double)
ffi_pf_fold i =
  withCAString i $ \ci ->
  withCAString i $ \cs -> do
  let n = length i
  let z = n * (n+1) `div` 2 +1
  e  <- ffiwrap_pf_fold_constrained ci cs 0
  s  <- peekCAString cs
  bp <- export_bppm
{-# LINE 32 "./BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs" #-}

  xs <- peekArray z (bp :: Ptr CDouble)
  let ar = A.accumArray (const id) 0 ((1,1),(n,n)) $ zip [ (ii,jj) | ii <- [n,n-1..1], jj <- [n,n-1..ii]] (drop 1 $ map unsafeCoerce xs)
  return (cf2d e, s, ar)

ffi_pf_circ_fold :: String -> IO (Double,String,A.Array (Int,Int) Double)
ffi_pf_circ_fold i =
  withCAString i $ \ci -> do
  withCAString i $ \cs -> do
  let n = length i
  let z = n * (n+1) `div` 2 +1
  e  <- pf_circ_fold ci cs
  s  <- peekCAString cs
  bp <- export_bppm
{-# LINE 45 "./BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs" #-}

  xs <- peekArray z (bp :: Ptr CDouble)
  let ar = A.accumArray (const id) 0 ((1,1),(n,n)) $ zip [ (ii,jj) | ii <- [n,n-1..1], jj <- [n,n-1..ii]] (drop 1 $ map unsafeCoerce xs)
  return (cf2d e, s, ar)

ffi_pf_fold_constrained :: String -> String -> IO (Double,String,A.Array (Int,Int) Double)
ffi_pf_fold_constrained i s =
  withCAString i $ \ci ->
  withCAString s $ \cs -> do
  let n = length i
  let z = n * (n+1) `div` 2 +1
  e  <- ffiwrap_pf_fold_constrained ci cs 1
  s  <- peekCAString cs
  bp <- export_bppm
{-# LINE 58 "./BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs" #-}

  xs <- peekArray z (bp :: Ptr CDouble)
  let ar = A.accumArray (const id) 0 ((1,1),(n,n)) $ zip [ (ii,jj) | ii <- [n,n-1..1], jj <- [n,n-1..ii]] (drop 1 $ map unsafeCoerce xs)
  return (cf2d e, s, ar)

ffi_pf_circ_fold_constrained :: String -> String -> IO (Double,String,A.Array (Int,Int) Double)
ffi_pf_circ_fold_constrained i s =
  withCAString i $ \ci -> do
  withCAString i $ \cs -> do
  let n = length i
  let z = n * (n+1) `div` 2 +1
  e  <- ffiwrap_pf_circ_fold_constrained ci cs 1
  s  <- peekCAString cs
  bp <- export_bppm
{-# LINE 71 "./BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs" #-}

  xs <- peekArray z (bp :: Ptr CDouble)
  let ar = A.accumArray (const id) 0 ((1,1),(n,n)) $ zip [ (ii,jj) | ii <- [n,n-1..1], jj <- [n,n-1..ii]] (drop 1 $ map unsafeCoerce xs)
  return (cf2d e, s, ar)


foreign import ccall safe "BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs.h ffiwrap_pf_fold_constrained"
  ffiwrap_pf_fold_constrained :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (IO C2HSImp.CFloat))))

foreign import ccall safe "BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs.h export_bppm"
  export_bppm :: (IO (C2HSImp.Ptr C2HSImp.CDouble))

foreign import ccall safe "BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs.h pf_circ_fold"
  pf_circ_fold :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (IO C2HSImp.CFloat)))

foreign import ccall safe "BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs.h ffiwrap_pf_circ_fold_constrained"
  ffiwrap_pf_circ_fold_constrained :: ((C2HSImp.Ptr C2HSImp.CChar) -> ((C2HSImp.Ptr C2HSImp.CChar) -> (C2HSImp.CInt -> (IO C2HSImp.CFloat))))