how to call Fortran Procedures in Haskell Program?
Does anybody know how to call Fortran procedures in Haskell program? I tried Green Card, but seems it only works with C codes. Thanks.
Does anybody know how to call Fortran procedures in Haskell program? I tried Green Card, but seems it only works with C codes.
Most of our effort has gone into interfacing to C (and, to some extent, C++, Java, .net, etc.) - in fact, I'm not sure that we really know enough about Fortran calling conventions to do a decent job interfacing directly to Fortran. So, what I'd do is write little C wrappers for your fortran code or, if your compiler supports it, declare your fortran functions as using the C calling convention and then use one of the many tools for C: raw ffi, greencard, c2hs, etc. -- Alastair Reid
Hi there.
Does anybody know how to call Fortran procedures in Haskell program? I tried Green Card, but seems it only works with C codes.
Sigbjorn Finne posted a way of doing this a while back, possibly on this list, maybe the GHC one. He used the FFI and a simple squaring function. Below is an extension using an integer array. Note that I've had to double the array size. $ g77 -c atest.f $ ghc -fglasgow-exts main.hs -o main.exe $ ./main [1,3,0,0,2,4,0,0] If you go any further, please let me know as I want to interface to LAPACK. Cheers Mike Thomas. ................................................ module Main where import Ptr import Storable import MarshalArray import MarshalUtils import MarshalAlloc foreign import "atest_" unsafe atest_ :: Ptr Int -> Ptr Int -> IO Int atest :: Int -> IO [Int] atest x = withObject x $ \ ptr_x -> allocaArray x $ \ ptr_a -> do atest_ ptr_x ptr_a peekArray (x*2) ptr_a main = atest 4 >>= print --square :: Int -> IO Int --square x = -- withObject x $ \ ptr_x -> -- alloca $ \ ptr_res -> do -- square_ ptr_x ptr_res -- peek ptr_res ................................................ SUBROUTINE ATEST(N,M) DIMENSION M(N,N) M(1,1)=1 M(1,2)=2 M(2,1)=3 M(2,2)=4 RETURN END ................................................
participants (3)
-
Alastair Reid -
Mike Thomas -
Zhe Fu