Question: Problems with call to external Fortran routine

Dear Maple experts,

I'm trying to make use of Maple's external calling facility to speed up some bottlenecks in my calculations (and simply to learn how it works...).

As I frequently need complex numbers, Fortran looked like the more appropriate choice. This is mainly because Maple can help with generating small code snippets for complex-valued functions whereas the code generation for C/C++ requires more manual work...

Apart from that, however, I have problems to use 'define_external' with a Fortran DLL library (I'm using Maple 12 under Windows XP). Consider the following trivial Fortran function which takes two complex numbers and returns the absolute value of their sum

      complex function myadder (a, b)
      !DEC ATTRIBUTES STDCALL DLLEXPORT :: myadder
        complex a
        complex b
        myadder = cabs(a + b)
        return
      end

I compile this with Intel's Fortran Compiler and I get a library file.

Then, in Maple, I want to acces this function as follows:

ext_adder := define_external('myadder', 'FORTRAN', 'a'::complex[8], 'b'::complex[8], 'RETURN'::float[8], 'LIB' = "C:\\shared/myadder.dll");

Then an error message from Microsoft's Visual C++ Runtime Library pops up saying that Maple's mserver.exe has made an attempt to load the C runtime library incorrectly. Is this a bug in Maple or maybe 'only' an incompatibility with the C++ Runtime Library?

Moreover, if change the example above so that a complex number is returned (e.g. the complex sum instead of the absolute value) and change the external definition according to

ext_adder := define_external('myadder', 'FORTRAN', 'a'::complex[8], 'b'::complex[8], 'RETURN'::complex[8], 'LIB' = "C:\\shared/myadder.dll");

then I get an error: "Error, complex datatypes cannot be returned using AUTO"

I assume that both problems are related to the automatic wrapper generation, right? I checked using a similarly trivial (real-valued) example in C/C++ and it worked. But then again I cannot easily work with complex numbers...

So, does anyone know how to work with (complex-valued) Fortran functions? Or, alternatively, how would it work with C++? Thanks in advance.

Thomas

Please Wait...