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 11042 articles. 36 followers. Post

14 Replies
506 Views

Similar Articles

[PageSpeed] 41


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Calling a Fortran DLL from Fortran
In calling a FORTRAN DLL, from FORTRAN code, one needs to place the DLL in = a path that is searched by the Windows operating system. Placing the DLL in= a folder other than the ones in the PATH environment variable, will cause = the call to fail. Does anyone know how to call a DLL that is stored in a fo= lder not in the Windows path? In VB one uses the Declare statement to accom= plish that. I tried GETENVQQ to get the Path environment variable, then aug= ment the path of the DLL and then using the SETENVQQ to update the PATH en= vironment variable but I haven't been able to succ...

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...

DLL Call inside DLL Call
Hello, &nbsp; I'm trying to make a call to a DLL that was generated with LabView, inside a DLL that itself is called&nbsp;from a LabView Application. I know it sounds deviously, to do that. But it is necessary, because we try to run a big application on a cRio platform, and get into trouble with memory resources. So we decided save resources by using a C++ DLL. Now it would be a very nice feature to use the analyse functionality from LabView inside that C++ DLL, by loading LabView VIs dynamically in form of generated DLLs. This is necessary because we need a lot of Analyse VIs, th...

mex - matlab calls fortran which calls matlab which calls fortran
Dear All, I'm trying to link matlab and fortran with mex files and engine matlab, in linux OS. My general purpose is the following: 1) a matlab script A calls a mex function B based upon fortran source code 2) mex function B calls another function in matlab C within matlab engine 3) matlab routine C calls another mex file in fortran D While i'm able to do steps 2) and 3), I can't do step 1). Before to show the code, please reply to this simple question: Is it possible to build the overall process 1-3? On 8 Okt, 16:37, "Michele Catalano" <cata...@yahoo.it> wr...

c++ calling fortran and fortran calling C++
Hi, For my application in C++, I need to call a subtroutine in fortran. This subroutine must call a function of my program. I'm trying to use pointer of my function but I have segmentation fault. the fortran code is: subroutine dlltest [dllexport] (c_msg,e1,e2,e3,i,r,d,str) c implicit none integer i,l,m,length real*4 r double precision d character*128 e1,e2,e3,str,aux,aux2 external c_msg,length c first, write parameters to a file open(1,file='test.out',status='unknown') rewind(1) c write(1,*) 'function pointer: ',c_msg write(1,*) 'integer: ...

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...

How to link an Fortran f77 dll (Absoft Pro Fortran) with an existing f77 dll (Visual Fortran)
Hello, i have to connect an existing Fortran F77 DLL written in Visual Fortran to a new one. How can i link two DLLs together? I search an example, to understand how it works. Please help me! At the moment i have a dll called "example.dll". Within this dll are three functions: DOUBLE PRECISSION FUNCTION EXF1(A,B) !DEC$ ATTRIBUTES DLL_EXPORT :: EXF1 !DEC$ ATTRIBUTES ALIAS : "EXF1" :: EXF1 REAL*8 A,B EXF1=A*2*B RETURN End DOUBLE PRECISSION FUNCTION EXF2(A,B) !DEC$ ATTRIBUTES DLL_EXPORT :: EXF2 !DEC$ ATTRIBUTES ALIAS : "EXF2" :: EXF2 REAL*8 A,B EXF2...

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 ...

Calling FORTRAN functions rather than FORTRAN subroutines via call
Hi everybody, all examples I know show how to call a FORTRAN subroutine. I have a lot of FORTRAN code regarding thermophysical properties of water, steam, smoke gas etc. This code consists of many FORTRAN functions. I wish to call them inside scilab. Is it possible? If yes how can the function return value be obtained? Thank you very much, many greetings Eberhard On 2 jan, 14:41, i...@efranz.de wrote: > Hi everybody, > > all examples I know show how to call a FORTRAN subroutine. I have a > lot of FORTRAN code regarding thermophysical properties of water, > ...

calling perl modules from python
I have a hash function written by another organization that I need to use. It is implemented in perl. I've been attempting to decode what they are doing in their hash function and it is taking way too long. I've identified two functions in a perl module that I would like to 'call' from a python program. I found the following: http://www.annocpan.org/~GAAS/pyperl-1.0/perlmodule.pod and wondered if anyone had any comments. This thing implements a perl interpreter inside python. That seems like overkill to me. I wonder what wisdom this group can offer. -- David Bear -- let me...

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 ...