hi ,
I want to read a file with a fortran dll using ctype.
the structure of my file is:
-
AX
-
BX
-
… .
-
4.0 5.0 6.9
-
1.2 8.0 7.0
-
… … …
for read the file , i have PATH to pass to dll fortran and get a character array from Ax,BX,… and float array from the number.
In my Fortran code:
DLL_READ.f90 (2.2 KB)
I have error : error #8532: A character dummy argument with length other than 1 is not interoperable.
in my python code :
Summary
import ctypes
import numpy as np
from numpy.ctypeslib import ndpointer
import os
def Import_DLL():
PATH = os.path.dirname(os.path.realpath(__file__))
print('path=',PATH)
Lib = ctypes.CDLL(os.path.join(PATH,"./DLL_read.dll"))
return Lib
def Decla_Arg():
Lib.open_file.argtypes = [ctypes.c_int, ctypes.c_char_p]
Lib.open_file.restype = None
Lib.get_char_col.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.c_char_p]
Lib.get_char_col.restype = None
Lib.get_float.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int), ndpointer(dtype=ctypes.c_float)]
Lib.get_float.restype = None
def open_file(FicWxx,PATH):
Lib.open_file(FicWxx,PATH)
return
def get_char_col(FicWxx,nliais):
elem=list()
nliais = ctypes.c_int(nliais)
Lib.get_char_col(FicWxx, nliais, elem)
return elem
def get_res_type(FicWxx, nliais, istep):
param=np.zeros(shape=(3 , nliais),dtype=ctypes.c_float)
Lib.get_float(FicWxx, nliais,param)
return param
-------------- main --------------------------------
if name == “main”:
Lib=Import_DLL()
Decla_Arg()
FicWxx = 15
PATH ="C\\user\\file.txt"
open_file(FicWxx,PATH)
elem = get_char_col(FicWxx, nliais)
print("elem =", elem)
param = get_res_type(FicWxx, nliais)
print("param =", param)
I have problem with PATH : Lib.open_file(FicWxx,PATH)
ctypes.ArgumentError: argument 2: TypeError: wrong type
and I have errors with python strings array ELEM.
Thank you for your help