calling a fortran dll from python with ctypes module

  • Permalink
  • submit to reddit
  • Email
  • Follow


I'm using ctypes to call a fortran dll from python. I have no problems
passing arguments of integer or double types, both scalars or arrays,
single or double precission, but I have errors with python strings.

For example:

(sorry, is python code)
.....
n = c_int(10)
Vector= c_double * m
f_x=Vector()
for i in range(m):
....f_x[i] = float(1.0)

ap = windll.LoadLibrary(locationDll)
ap.TEST_01(byref(n),byref(f_x),byref(y))
print y.value # ok

Char= c_char_p
mychar=Char('0123456789')
mychar2=Char(m*' ')
ap.TEST_02(mychar) #error

the error text is
ValueError: Procedure probably called with not enough arguments (4
bytes missing)

fortran code (CVF compiler)

subroutine TEST_01(n,x,out)
....!DEC$ ATTRIBUTES DLLEXPORT :: TEST_01
....INTEGER(4) n
....REAL(8), dimension(n):: x
....real(8):: out
....out=sum(x)
....return
END subroutine

subroutine TEST_02(a)
....!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
....CHARACTER(10):: a
....open(31,file='pru.txt')
....write(31,*) a
....close(31)
....return
END subroutine

Some suggestions are wellcome !

0
Reply solisgb (21) 6/6/2007 6:40:57 AM

See related articles to this posting


Fortran compilers sometimes pass a hidden integer length argument
along with a string. This is typically done for character(*)
arguments, for fixed-len characters it's not necessary, but CVF is
old, so who knows? I suggest you try defining TEST_02 with
CHARACTER(*):: a
and calling it from Python as
ap.TEST_02(mychar,byref(len(mychar)))
No warranty :)

0
Reply highegg (245) 6/6/2007 6:53:12 AM

On Jun 6, 7:53 am, highegg <high...@gmail.com> wrote:
> Fortran compilers sometimes pass a hidden integer length argument
> along with a string. This is typically done for character(*)
> arguments, for fixed-len characters it's not necessary, but CVF is
> old, so who knows? I suggest you try defining TEST_02 with
> CHARACTER(*):: a
> and calling it from Python as
> ap.TEST_02(mychar,byref(len(mychar)))
> No warranty :)

Some compilers add the length argument to the end of the arg list
whilst others (like CVF) add it immediately after the character(*)
argument - and some have options to enable you to choose (ifort I
think).

Simon Geard

0
Reply simon9085 (164) 6/6/2007 8:57:11 AM

On 6 jun, 08:53, highegg <high...@gmail.com> wrote:
> Fortran compilers sometimes pass a hidden integer length argument
> along with a string. This is typically done for character(*)
> arguments, for fixed-len characters it's not necessary, but CVF is
> old, so who knows? I suggest you try defining TEST_02 with
> CHARACTER(*):: a
> and calling it from Python as
> ap.TEST_02(mychar,byref(len(mychar)))
> No warranty :)

I try with your suggestions and the error persists, now with the text
WindowsError: exception: access violation reading 0x00C25000


0
Reply solisgb (21) 6/6/2007 12:04:47 PM

On 6 jun, 10:57, SimonG <s...@whiteowl.co.uk> wrote:
> On Jun 6, 7:53 am, highegg <high...@gmail.com> wrote:
>
> > Fortran compilers sometimes pass a hidden integer length argument
> > along with a string. This is typically done for character(*)
> > arguments, for fixed-len characters it's not necessary, but CVF is
> > old, so who knows? I suggest you try defining TEST_02 with
> > CHARACTER(*):: a
> > and calling it from Python as
> > ap.TEST_02(mychar,byref(len(mychar)))
> > No warranty :)
>
> Some compilers add the length argument to the end of the arg list
> whilst others (like CVF) add it immediately after the character(*)
> argument - and some have options to enable you to choose (ifort I
> think).
>
> Simon Geard

I have coded
ap.TEST_02(byref(len(mychar)),mychar)
and the message error is similar

0
Reply solisgb (21) 6/6/2007 12:08:13 PM

solisgb@gmail.com wrote:
| On 6 jun, 08:53, highegg <high...@gmail.com> wrote:
|| Fortran compilers sometimes pass a hidden integer length argument
|| along with a string. This is typically done for character(*)
|| arguments, for fixed-len characters it's not necessary, but CVF is
|| old, so who knows? I suggest you try defining TEST_02 with
|| CHARACTER(*):: a
|| and calling it from Python as
|| ap.TEST_02(mychar,byref(len(mychar)))
|| No warranty :)
| 
| I try with your suggestions and the error persists, now with the text
| WindowsError: exception: access violation reading 0x00C25000

Should be byval, actually.

Alternatively, on the CVF side, you can add 

!DEC$ATTRIBUTES REFERENCE:: stringarg

to suppress the hidden length argument; in that case, you also have to 
pass the character length by other means (normally, as a separate real
argument) and declare the argument as CHARACTER(length) (as opposed to
CHARACTER(*))


-- 
 Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.
0
Reply jdujic (694) 6/6/2007 3:16:04 PM

On 6 jun, 17:16, "Jugoslav Dujic" <jdu...@yahoo.com> wrote:
> soli...@gmail.com wrote:
>
> | On 6 jun, 08:53, highegg <high...@gmail.com> wrote:
> || Fortran compilers sometimes pass a hidden integer length argument
> || along with a string. This is typically done for character(*)
> || arguments, for fixed-len characters it's not necessary, but CVF is
> || old, so who knows? I suggest you try defining TEST_02 with
> || CHARACTER(*):: a
> || and calling it from Python as
> || ap.TEST_02(mychar,byref(len(mychar)))
> || No warranty :)
> |
> | I try with your suggestions and the error persists, now with the text
> | WindowsError: exception: access violation reading 0x00C25000
>
> Should be byval, actually.
>
> Alternatively, on the CVF side, you can add
>
> !DEC$ATTRIBUTES REFERENCE:: stringarg
>
> to suppress the hidden length argument; in that case, you also have to
> pass the character length by other means (normally, as a separate real
> argument) and declare the argument as CHARACTER(length) (as opposed to
> CHARACTER(*))
>
> --
>  Jugoslav
> ___________www.xeffort.com
>
> Please reply to the newsgroup.
> You can find my real e-mail on my home page above.

I change the fortran subroutine to

subroutine TEST_02(a,n)
!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
INTEGER(4):: n
CHARACTER(len=n):: a
....
passing a and n by value and by reference from python the error
message is ValueError: Procedure probably called with not enough
arguments (4 bytes missing).

I also have used the /iface:nomixed_str_len_arg compiler option with
the same result


0
Reply solisgb (21) 6/6/2007 4:45:50 PM

You should have cross-posted your message to comp.lang.python from the
beginning. Since you still have a problem, I suggest summarizing what
you have tried so far in a new message to comp.lang.python . Questions
about how to interface Python to other languages (most often C) arise
often there and are considered on-topic.

0
Reply beliavsky (2211) 6/6/2007 4:55:59 PM

On 6 jun, 18:55, Beliavsky <beliav...@aol.com> wrote:
> You should have cross-posted your message to comp.lang.python from the
> beginning. Since you still have a problem, I suggest summarizing what
> you have tried so far in a new message to comp.lang.python . Questions
> about how to interface Python to other languages (most often C) arise
> often there and are considered on-topic.

I did, without a solution. My feeling is:

1.- There are not a simple solution.
2.- Is a problem between C and fortran. In python, the module ctypes
exports python types to c, not to fortran (not is ftypes).

0
Reply solisgb (21) 6/6/2007 8:10:27 PM

On 6 Jun, 21:10, soli...@gmail.com wrote:
> On 6 jun, 18:55, Beliavsky <beliav...@aol.com> wrote:
>
> > You should have cross-posted your message to comp.lang.python from the
> > beginning. Since you still have a problem, I suggest summarizing what
> > you have tried so far in a new message to comp.lang.python . Questions
> > about how to interface Python to other languages (most often C) arise
> > often there and are considered on-topic.
>
> I did, without a solution. My feeling is:
>
> 1.- There are not a simple solution.
> 2.- Is a problem between C and fortran. In python, the module ctypes
> exports python types to c, not to fortran (not is ftypes).

I can reassure you at least that there is no problem cross-calling
between fortran and c if you're using simple data types (real,
character, integer or arrays thereof). CAD systems often have mixtures
of c and fortran and such cross-calling is bread an butter to them. c
interoperability is part of f2003 so you might make life easier for
yourself if you try a compiler that supports that functionality (I
think g95 is one). I suggest you look at the interface between python
and c. If python is passing structs then cross calling gets harder.

Simon Geard

0
Reply simon9085 (164) 6/6/2007 10:10:56 PM

solisgb@gmail.com wrote:
| On 6 jun, 17:16, "Jugoslav Dujic" <jdu...@yahoo.com> wrote:
|| soli...@gmail.com wrote:
|| 
||| On 6 jun, 08:53, highegg <high...@gmail.com> wrote:
|||| Fortran compilers sometimes pass a hidden integer length argument
|||| along with a string. This is typically done for character(*)
|||| arguments, for fixed-len characters it's not necessary, but CVF is
|||| old, so who knows? I suggest you try defining TEST_02 with
|||| CHARACTER(*):: a
|||| and calling it from Python as
|||| ap.TEST_02(mychar,byref(len(mychar)))
|||| No warranty :)
||| 
||| I try with your suggestions and the error persists, now with the text
||| WindowsError: exception: access violation reading 0x00C25000
|| 
|| Should be byval, actually.
|| 
|| Alternatively, on the CVF side, you can add
|| 
|| !DEC$ATTRIBUTES REFERENCE:: stringarg
|| 
|| to suppress the hidden length argument; in that case, you also have to
|| pass the character length by other means (normally, as a separate real
|| argument) and declare the argument as CHARACTER(length) (as opposed to
|| CHARACTER(*))
|| 
|| --
||  Jugoslav
|| ___________www.xeffort.com
|| 
|| Please reply to the newsgroup.
|| You can find my real e-mail on my home page above.
| 
| I change the fortran subroutine to
| 
| subroutine TEST_02(a,n)
| !DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
| INTEGER(4):: n
| CHARACTER(len=n):: a
| ...
| passing a and n by value and by reference from python the error
| message is ValueError: Procedure probably called with not enough
| arguments (4 bytes missing).

But you didn't specify !DEC$ATTRIBUTES REFERENCE:: a. 

CHARACTER(*) and CHARACTER(n) don't make difference from the
caller's perspective. !DEC$ATTRIBUTES REFERENCE specifies
"I don't want the hidden length passed; I'll declare it 
by other means".
 
| I also have used the /iface:nomixed_str_len_arg compiler option with
| the same result

....because you didn't specify REFERENCE, but just swapped the order
of the "real" arguments.

-- 
 Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.
0
Reply jdujic (694) 6/7/2007 9:36:20 AM

solisgb@gmail.com wrote:
| On 6 jun, 18:55, Beliavsky <beliav...@aol.com> wrote:
|| You should have cross-posted your message to comp.lang.python from the
|| beginning. Since you still have a problem, I suggest summarizing what
|| you have tried so far in a new message to comp.lang.python . Questions
|| about how to interface Python to other languages (most often C) arise
|| often there and are considered on-topic.
| 
| I did, without a solution. My feeling is:
| 
| 1.- There are not a simple solution.

There is. You just fail to pick up the correct combination.
To repeat, those are:

1)
ap.TEST_02(mychar,byval(len(mychar))) //or whatever is Python correct syntax
subroutine TEST_02(a)
....!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
....CHARACTER(*):: a
end subroutine

2)
ap.TEST_02(mychar,byref(len(mychar)))
subroutine TEST_02(a,n)
....!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
   !DEC$ATTRIBUTES REFERENCE:: a
   INTEGER:: n
....CHARACTER(n):: a
end subroutine

-- 
 Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.
0
Reply jdujic (694) 6/7/2007 9:39:05 AM

On 7 jun, 11:39, "Jugoslav Dujic" <jdu...@yahoo.com> wrote:
> soli...@gmail.com wrote:
>
> | On 6 jun, 18:55, Beliavsky <beliav...@aol.com> wrote:
> || You should have cross-posted your message to comp.lang.python from the
> || beginning. Since you still have a problem, I suggest summarizing what
> || you have tried so far in a new message to comp.lang.python . Questions
> || about how to interface Python to other languages (most often C) arise
> || often there and are considered on-topic.
> |
> | I did, without a solution. My feeling is:
> |
> | 1.- There are not a simple solution.
>
> There is. You just fail to pick up the correct combination.
> To repeat, those are:
>
> 1)
> ap.TEST_02(mychar,byval(len(mychar))) //or whatever is Python correct syntax
> subroutine TEST_02(a)
> ...!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
> ...CHARACTER(*):: a
> end subroutine
>
> 2)
> ap.TEST_02(mychar,byref(len(mychar)))
> subroutine TEST_02(a,n)
> ...!DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
>    !DEC$ATTRIBUTES REFERENCE:: a
>    INTEGER:: n
> ...CHARACTER(n):: a
> end subroutine
>
> --
>  Jugoslav
> ___________www.xeffort.com
>
> Please reply to the newsgroup.
> You can find my real e-mail on my home page above.


1) runs fine, 2) not

The final example must be:

#Python script calling fortran subroutine
from ctypes import *
ap = windll.LoadLibrary(self.locationDll)
ap.TEST_02.restype=None
myCadena='D:\BBDD\PythonScripts\pru.txt'
strLen=len(myCadena)
pf_myCadena = c_char_p(myCadena)
pf_srLen = c_int(strLen)
ap.TEST_02(pf_myCadena,pf_srLen)

!fortran dll
subroutine TEST_02(s)
  !DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
  !DEC$ATTRIBUTES REFERENCE:: s
  !INTEGER(4):: n
  CHARACTER(*):: s

  open (unit=31,file=trim(s))
  write(31,'(f0.1)') 1.0
  write(31,*) trim(s)
  write(31,'(i0)') len_trim(s)
  close(31)
  return
END subroutine


Thanks

0
Reply solisgb (21) 6/7/2007 3:19:12 PM

solisgb@gmail.com wrote:
| On 7 jun, 11:39, "Jugoslav Dujic" <jdu...@yahoo.com> wrote:
|| soli...@gmail.com wrote:

| 1) runs fine, 2) not
|
| The final example must be:
|
| !fortran dll
| subroutine TEST_02(s)
|  !DEC$ ATTRIBUTES DLLEXPORT :: TEST_02
|  !DEC$ATTRIBUTES REFERENCE:: s
|  !INTEGER(4):: n
|  CHARACTER(*):: s
|
| END subroutine

Uh, you're right; my bad. Sorry, I was so convinced that I didn't
bother looking at the manual. After I did, I discovered that they made
it so complicated that, after 10 years of mixed-language programming
experience with CVF, I got confused (again):

<quote>
1) If REFERENCE (only) is specified for a character argument, the following 
occurs:

 *On Windows systems, hidden lengths immediately follow the variable....
2) If REFERENCE is specified for a character argument, and C (or STDCALL) has 
been specified for the routine, the string is passed with no length. This is 
true even if REFERENCE is also specified for the routine.
3) If REFERENCE and C (or STDCALL) are specified for a routine, but REFERENCE 
has not been specified for the argument, the string is passed with the length.
</quote>

I have always used REFERENCE in combination with C or STDCALL (case 2),
so I naively expected that it also holds to case 1 (i.e. yours). In
other words, in your last version, REFERENCE is spurious :-D

Blame Can^H^H^H Microsoft, as always (AFAIK it's originally their semantics)

And morale: prefer RTFM to random usenet users :-).
-- 
 Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above. 

0
Reply jdujic (694) 6/7/2007 3:38:13 PM

On 6 jun, 18:55, Beliavsky <beliav...@aol.com> wrote:
> You should have cross-posted your message to comp.lang.python from the
> beginning. Since you still have a problem, I suggest summarizing what
> you have tried so far in a new message to comp.lang.python . Questions
> about how to interface Python to other languages (most often C) arise
> often there and are considered on-topic.

I did, without a solution. My feeling is:

1.- There are not a simple solution.
2.- Is a problem between C and fortran. In python, the module ctypes
exports python types to c, not to fortran (not is ftypes).

0
Reply solisgb (21) 6/8/2007 9:06:25 AM
comp.lang.fortran 10951 articles. 36 followers. Post

14 Replies
325 Views

Similar Articles

[PageSpeed] 6


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Calling CVF-Fortran-dll with ctypes and simple structure
Hi all, I deal with the old problem passing characters from python to a fortran dll build with CFV6.6c. I reduced our complex structure to a simple one. Here is the Fortran code: SUBROUTINE DEMO2L(s) C sample for calling CVF6.6c-DLLs from C vb/vba/python with simple structure !DEC$ ATTRIBUTES DLLEXPORT::DEMO2L TYPE rcDEMO INTEGER a REAL b CHARACTER c*9 END TYPE TYPE(rcDEMO) :: s C WRITE(*,*) s.a, s.b, s.c C sample calculation: s.a =3D s.a*10 s.b =3D s.b**2.3 s.c =3D 'Sample' RETURN END =46rom VB the calling is very simpl...

Problem calling python modules from python apache handler
Hi, I have the following setup... Apache 2.2.3, Python 2.5 and mod_python 3.3.1 I have configured apache to call a python script when fetching .py resources...so far so good... I did the hello world script in the mod_python docs and it works great. Now when I want to add some meat and potatoes and call some other python code from the script things get pear shaped.. I try to import the module I want, but it never can find it... I always get the error... ImportError: No module named ??? no matter what I do. I have moved my python modules around, to no avail. I've even put them in the s...

how to call this dll in python
I have a windows dll1.dll with a export function: int f1(char filename,char **buf,int *bufLen) { int len; //got the length of file anyway,such as 100 len = 100;//len = getLen(filename); *buf = (char*)calloc(100); *bufLen = len; return 0; } then how can I call the f1 function with python. thanks for your response. Shark schrieb: > I have a windows dll1.dll with a export function: > > int f1(char filename,char **buf,int *bufLen) > { > int len; > //got the length of file anyway,such as 100 > len = 100;//len = getLen(filename); > *buf = (char*)calloc(100); > *bufLen ...

Calling Fortran from Python
Howdy, I have been trying to call the following Fortran function from Python (using Windows XP, Compaq Fortran and Python 2.4). I tried F2Py, Pyfort and calldll with no success. I think I came very close with calldll. Here is a short summary Fortran code: SUBROUTINE SAMPLE(IERR1,IERR2,AIN,AOUT) C C SIMPLE SAMPLE OF A DLL C !DEC$ATTRIBUTES DLLEXPORT :: SAMPLE !DEC$ATTRIBUTES ALIAS:'SAMPLE' :: SAMPLE INTEGER,INTENT(OUT) :: IERR1,IERR2 REAL*8,INTENT(IN) :: AIN(*) REAL*8,INTENT(OUT) :: AOUT(*) C C *** SET MAXIMUM EXPECTED ELEMENTS OF ARRAY AI...

Calling python in fortran
Hi friends, I am learning python; and will like to call some python script from fortran(will call py2f) (those will mostly do some type of logging etc.). My main code is still in fortran. while the opposite scenario (calling fortran from python; using f2py) is fairly common, I have not found much about py2f. One suggestion is to use cython, so, essentially to make py2C and the call it from fortran. Other thing, I can think of is to call execute_command_line (not tried yet, tried system though.). I don't think py2f is rare, just want to know which is the standard and better practi...

Calling Python macro from ctypes
Is it possible to call a Python macro from ctypes? For example, Python 3.3 introduces some new macros for querying the internal representation of strings: http://www.python.org/dev/peps/pep-0393/#new-api So I try this in 3.3: py> import ctypes py> ctypes.pythonapi.PyUnicode_MAX_CHAR_VALUE Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.3/ctypes/__init__.py", line 366, in __getattr__ func = self.__getitem__(name) File "/usr/local/lib/python3.3/ctypes/__init__.py",...

calling a dll fortran with wxwindows
Hi, I use wxwindows for my application. I need to call a dll in fortran but I have problem with stings. My dll has a simple subroutine witch accept : i (long) r (real, 4 octets) d (double pr�cision) str (string, 128 octets) It returns a file 'dlltest.out' with the values of i,r,d and str. I use this code im my program to load the dll: wxDllType mydll=wxDllLoader::LoadLibrary("test.dll"); typedef void (*inti)(long*,float*,double*,char *,int); inti pint; pint = (inti) wxDllLoader::GetSymbol(mydll,"DLLTEST"); long a; a=12; ...

Cannot call a C module from Fortran
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything possible. When I replace the C module by a Fortran subroutine linking works. Here the Fortran subroutine that replaced the C module for testing: subroutine qqcprint return end But when I use this C module in the same library (replacing the Fortran testmodule) linking didn't work any longer. void qqcprint() { return; } I also tried it with this one: extern void qqcprint() { ...

Cannot call a C module from Fortran
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything possible. When I replace the C module by a Fortran subroutine linking works. Here the Fortran subroutine that replaced the C module for testing: subroutine qqcprint return end But when I use this C module in the same library (replacing the Fortran testmodule) linking didn't work any longer. void qqcprint() { return; } I also tried it with this one: extern void qqcprint() { ...

calling a matlab dll from fortran
Has anyone ever tried calling a matlab dll from compac visual fortran - a dll compiled with the command : mcc -W lib:sim_ex2 -L C -t -T link:lib -h simex2.m , where simex2.m is the name of the m-file. I seem to be able to be calling the routines but I cannot pass variables. I suppose that the fact that c and fortran pointers are not the same may be the source of the problem. But could the fact that the pointers point to mxArrays also be a problem? There are stuff to find as solutions but nothing seems to be working. Could anyone help? Here is one of the codes I have tried among ...

Calling subroutine in fortran module
I tried calling a subroutine in a fortran module from C ,but couldn't.I always get the error: undefined reference in the main.o file (main is in C calling the subroutine). for calling the subroutine I used the following name: modulename_MP_subroutinename_(...) and all possible variant (upper case,lower case).Can anybody help (for a unix system) "Amit" <kumar20@gmail.com> writes: > I tried calling a subroutine in a fortran module from C ,but couldn't.I > always get the error: undefined reference in the main.o file (main is > in C calling the subroutine). >...

Fortran DLL call from excel
I am calling a fortran DLL from excel which passes an array to fortran program. The array values are incrimented by 10. Its crishing the program. Why? and how do i resolve this. Full code presented below Subroutine FortranDLL( Array1, upbound ) !DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'FORTRANDLL' :: FortranDLL !DEC$ ATTRIBUTES REFERENCE :: Array1 !DEC$ ATTRIBUTES REFERENCE :: upbound Implicit None ! ...argument declarations Integer :: upbound Integer :: Array1(1:upbound) ! Local variables Integer :: i do i=1,upbound Array1(i)=Array1(i)+10 end do End Subro...

How to call a dll program from Fortran
Hello, I have created a dll program from Fortran (Compaq VF) to use it from a VB program. It works fine. (Thanks to help I've got from many of you). Now I want use the same dll from another Fortran program. Can somebody give me some examples in using dll programs from Fortran please? Thank you. Cem Athena wrote: > Hello, > I have created a dll program from Fortran (Compaq VF) to use it > from a VB program. It works fine. (Thanks to help I've got from many of > you). Now I want use the same dll from another Fortran program. Can somebody > g...

Calling C++ Modules in Python
Hi, I saw in the Beginner document that "=95Is easily extended by adding new modules implemented in a compiled language such as C or C++. ". While to my investigation, it seems not that easy or did I miss something? boost python (C++ libraries need to be re-compiled with written wrappers again?). SWIG (It works by taking the declarations found in C/C++ header and using them to generate the wrapper code that scripting languages need to access the underlying C/C++ code). Thanks -Patrick Hi Patrick, I'm using SWIG in my project. C++ code is wrapped and can be used in python ...

accessing fortran modules from python
hello all, i am currently in the process of planning a piece of software to model polymerisation kinetics, and intend to use python for all the high-level stuff. the number-crunching is something i would prefer to do in fortran (which i have never used, but will learn), but i have no experience of accessing non-python code from python. i am also fairly new to programming period, and am therefore tackling a fairly serious issue reletive to my experience. how easy is it to get fortran modules running from python? if c is easier to use in this respect, i could go in that direction instead. i r...

Calling a Perl Module from Python
I've recently made the switch. Wow, is Python great! One thing which I haven't been able to do is replace Perl's great lib collection (HTML::Parser, for instance, can do a lot that Soup just can't). Is there anyway to call Perl modules from Python? Thanks PS Please cc me on all responses __________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250 ...

Matlab calling Fortran DLL (DVF) ?
I use Matlab 7 How to call a Fortran DLL? (I compile this DLL with Digital Visual Fortran 6.5) I look "loadlibray", but this function request an header file (.h file) - loadlibrary('myDLL','myFile.h') Possible without header file? Example? Thanks ...

Calling Access module functions from python
Hi, I have an Access Data Project (.adp) that I am trying to open and execute from Python. I am using the win32com.client, and I have successfully opened the application, but I'm getting an exception when I try to execute the function (actually a "Sub" that returns void, but that shouldn't matter). Here's what I have so far: conn=win32com.client.Dispatch('Access.Application') conn.OpenAccessProject("C:/path/to/file/filename.adp") conn.Visible = 1 # works so far conn.Run("test_interface") # Exception is thrown here. # com_error: (-2147352...

Calling FORTAN dll functions from Python
Does anyone know how to call functions from FORTRAN dlls in Python? Is it even possible? I browsed the documentation for Python 2.6.1 and the Python/C API comes close to what I would like to do but it is strictly limited to C. Unfortunately the passing of arguments in C and FORTRAN is very different, not to mention the differences with strings where FORTRAN expects a hidden length argument. It could call the FORTRAN dll from C and call the C functions from Python but is that my only option? For reference: I am using Python 2.6.1 FORTRAN powerstation 4.0. It is not an option t...

header for fortran dll to be called from matlab
Dear all, I am trying to call a DLL file from Matlab. I guess the DLL was created by FORTRAN and I don't have header file for this DLL file. Does anybody know how to write a header file for it? In the help document of the program, there are ways calling it from VB6 and Fortan90. The information is followed: VB Declaration Statement: Private Declare Sub ProcessWeather Lib "EPlusWth" (ByVal strInType As String, ByVal InTypeLen As Long, ByVal strOutType As String, ByVal OutTypeLen As Long, ByVal strInFileName As String, ByVal InFileNameLen As Long, ByVal strOutFileName As ...

Calling Intel Visual Fortran from Python
I have been exploring calling Fortran DLL subroutines from Python. I discovered that in order to call a DLL created with Intel Visual Fortran I had to set the calling convention for external procedures to CVF. I set this as a global compiler option (in Project Properties). I would prefer not to change the calling convention globally, in case there are undesirable side effects. The docs suggest that the same thing can be done on at the level of a subroutine, but this does not show up in the list of ATTRIBUTES directive options. Perhaps someone has already used Python with Fortran, and can e...

ctypes: How to call unexported functions in a dll
Hi, I am using ctypes in python 3 on a WXP machine Loading a dll and using its exported functions works fine. Now I want to use a function in the dll that is not exported. In C this can be done by just casting the address in the dll of that function to an apropriate function pointer and call it (you need to be sure about the address). Can a similar thing be done directly with ctypes? A work around I see is writing in wrapper dll in c that loads the main dll, exports a function that calls the unexported function in the main dll, but I don't find that an elegant solution....

Problems calling Fortran DLL from VBA
I am in trying to figure out how to use a DLL created in Fortran in VBA. I have a very simple Fortran procedure that I have compiled into a DLL. I can succesfully call this DLL from another Fortran procedure. I would like to access the DLL from VBA. I use the following protocol to define the function within the VBA (in Excel) Declare Function MyCalc Lib "test.DLL" Alias "_calc@12" _ (ByRef n1 As Long, ByRef n2 As Long, ByRef n3 As Long) I have used this exact protocol successfully for DLL's created in C++ and so I know the protocol is right. The error message that I...

python
Hello, I am interested in using python to script access to some hardware for which there are existing drivers in the form of DLLs. The DLLs each have four exported functions and a host of COM Properties and COM Methods. The four exported functions are as follows: DllCanUnloadNow DllGetClassObject DllRegisterServer DllUnregisterServer The COM methods and properties all begin with I, followed by a unique name. I am able to load the DLL using ctypes and it can access the exported functions, but I'm not sure how to access the COM methods and properties. I have read that ctypes once had s...