Python Forum
Do I better to give up to use ctypes?!?!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I better to give up to use ctypes?!?!
#1
I've been trying to call Fortran.dll file with ctypes in Python 2.7. 

however I've struggled with how to send and get Array and Matrix. Strictly speaking, I'd like to know how to set argtypes and restypes for array and matrix.

I probably know how to do it with numpy but at this time I can't use numpy_modules but I can only use Python standard modules like ctypes. 
Actually I want to work with Rhino IronPython though, my Rhino IronPython is something wrong so I can't install numpy.

By the way, this is my Fortran and Python code to exchange array.
subroutine add_array(ii)
    implicit none
    real(8),dimension(0:1),intent(inout) :: ii(0:1)
    dimension b(0:1)
    integer i
    
    do i =1,2
         b(i)=1
         ii(i) = ii(i) + b(i)
    end do
    
end subroutine
stop
end
------------------------------------------------------------------------
from ctypes import*

addmodule = cdll.LoadLibrary("C:\\Users\\Owner\\add_arraytest.dll")
addmodule.test_.argtypes = [ POINTER(c_int),POINTER(c_int)]
addmodule.test_.restype = c_void_p

twoIntegers = c_int * 2
ii = twoIntegers(1,2)

ii(0) = c_int(ii[0])
ii(1) = c_int(ii[1])

addmodule.test_(byref(ii[0]),byref(ii[1]))

for i in ii: print i,
these program are collapsed... doesn't work at all...
I know C doesn't have executable statement to control whole array ,it should be controlled one by one
if there is no way to  to send and get Array and Matrix, please tell me!!!

Thanks a million in advance...
Reply
#2
why don't you just convert the FORTRAN to python?
Reply
#3
because there are so many Fortran programs in my laboratory in my university, and my professor and classmate in my laboratory still using it.

the reason why i cling fortran is because I try to connect Grasshopper Python in Rhinoceros to Fortran analysis program so it can analyze object while I making object.
I believe my attempt is gonna be benefit for my classmate to display their works clearly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  using ctypes to use a dll in a python module dauriac 3 377 Mar-06-2024, 04:38 PM
Last Post: dauriac
  Trying to debug segfault in ctypes binding to Fortran bthomas 1 594 Sep-01-2023, 11:26 AM
Last Post: bthomas
  ctypes juliolop 7 1,385 Apr-20-2023, 03:33 PM
Last Post: Larz60+
  Issue while using ctypes in python GiggsB 6 2,777 Mar-27-2022, 03:38 AM
Last Post: GiggsB
  Ctypes and libffi.so.7 luxedo 1 6,050 Oct-23-2021, 09:24 PM
Last Post: DeaD_EyE
  possible ctypes and numpy conflict? herbal_rage 0 3,145 Apr-16-2020, 11:35 AM
Last Post: herbal_rage
  python kernell crash with a ctypes program Jstechg 1 3,489 Nov-24-2018, 02:37 PM
Last Post: Jstechg
  generating ctypes wrapper for a c library? brighteningeyes 9 7,062 Nov-04-2018, 02:31 AM
Last Post: brighteningeyes
  DLL library with ctypes Max20 0 2,908 Aug-19-2018, 11:15 AM
Last Post: Max20
  dll not loading to Ctypes Philbot 1 6,849 Jul-01-2018, 09:55 AM
Last Post: Philbot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020