hi everyone:
I used 'ctypes' library to call Fortran code in python. Here, the Fortran code is packaged as a dynamic link library (dvode.so). This DLL can run by using Fortran code, and I meet some problem when I call this DLL in python.
1. As shown as Fig.listdevs.txt. I use '-nm' command to list the function name in DLL. I found that the moudle and subroutine in Fortran code are defined as some function which are typed T. And some parameters which are the variable that stores the data or strings are typed B or D. In python, I cant call the function which is B or D.
>>>import ctypes as cty
>>>zd = cty.CDLL('/mnt/e/02_python_exercise/dvode.so')
>>>zd.__zdplaskin_MOD_species_name
This command does not have any output
>>>print(zd.__zdplaskin_MOD_species_name)
ouput:<_FuncPtr object at 0x7f956c82dd80>
>>>print(dir(zd.__zdplaskin_MOD_species_name))
ouput:['__bool__', '__call__', '__class__', '__ctypes_from_outparam__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_b_base_', '_b_needsfree_', '_flags_', '_objects', '_restype_', 'argtypes', 'errcheck', 'restype']
>>>print(zd.__zdplaskin_MOD_species_name.__ctypes_from_outparam__)
ouput:<built-in method __ctypes_from_outparam__ of _FuncPtr object at 0x7fba9fe39d80>
>>>print(zd.__zdplaskin_MOD_species_name.__name_)
ouput:AttributeError: '_FuncPtr' object has no attribute '__name_'. Did you mean: '__name__'?
>>>print(zd.__zdplaskin_MOD_species_name.__str__)
ouput:<method-wrapper '__str__' of _FuncPtr object at 0x7fe956269d80>
Here, I am sure that the __zdplaskin_MOD_species_name only stores the strings in Fortran, and anyone know how to use 'ctypes' library to call this type B or D function.
Thank you very much.
I use Python 3.10.6 in ubuntu 18.04.