Question: Using define_external for a fortran subroutine that take a subroutine as an argument

Dear all, 

We are trying to use a fortran subroutine in maple using external calling. I was able to get the 'multiply' example working. i.e. through the steps descibed here: 

My mult.f looks like this: 

    subroutine multiply(a,b)
    real a,b,mult

It simply takes two arguments (Real), and returns the product. I used the following commands to build the dll: 

1. gfortran -c mult.f        ## This creates the object file mult.o, which is used later. 

2. gfortran -shared -mrtd -o mult.dll mult.o ## This creates the dll and can be used in maple. 

The command in maple looks like this : 

mult := define_external("multiply",LIB="C:/shared/mult.dll",FORTRAN,'a'::(float[4]),'b'::(float[4]), RETURN::(float[4]));

And finally, 

mult(3., 3.) ## works, if it gives the correct output. 

Few things to note here are: 

1. The dll has to be generated from inside the Cygwin64 shell, with cygwin64/bin in the system path. 

2. This only worked for (some) 64-bit Maple version (Maple 2016 Standard). 

The reason, I repeated a working example, was because I tried following the same steps for the more complicated case, however without success so far.  This post explains an approach on how to pass a subroutine as an argument to a fortran subroutine in the dll. However the post is old and the steps did not work for me. 

My system is as follows: 

1. Fortran file to generate the dll, takefunc.f , takes a subroutine as an argument and calls it. 

    subroutine take(func)
    external func
    call func()

2. Fortran driver file to verify that the dll generated through this program works: 

    PROGRAM main
    external take, fun
    call take(fun)
    SUBROUTINE fun()
    PRINT *, "This is a nice one"

I want the step 2 to be performed in maple, i.e. fun() should be a maple procedure, and we should be able to use either WRAPPER or second dll to use take() in maple. 

I want the process to work with latest maple versions and compilers, Windows7 64-bit or 32-bit (and hopefully later). F77 is fine. 

Regret the long post, will keep this post updated if I make any progress. Any guidance in this matter is highly appreciated. Anyway to make define_external spew more debug information will also help. 

- Chintan Pathak 

Research Scientist,

ChemE, University of Washington. 

Please Wait...