chintanp

30 Reputation

3 Badges

9 years, 20 days

MaplePrimes Activity


These are replies submitted by chintanp

@acer : Thanks a lot for your post, and sorry for late reply. 

I was able to make the fortran dll work with REF keyword. I, however needed to remove the word 'FORTRAN' from the first call to define_external, as the FORTRAN option doesnt support REF. 

This doesnt change any part of the rest of the workflow though, as we are customizing the resulting wrapper anyway (which is unaffected with the FORTRAN option in define_external call). 

So finally, what works is: 

multiply(a1, a2, a3); // in mwrap_multiply.c, even when a3 is defined as FLOAT64 * as we need to pass the address to the fortran function

And in maple

mult(2., 3., 'mult1');

However, I found that this only works with 'double' and not 'float'. Although, this isn't a Maple issue, float wasn't working even with my C driver, so a question for stackoverflow. 

Thanks for your help. Will post results with more complicated DLLs. 

So, I started fresh and it worked. Below is the description of what worked. 

1. Success with simple subroutine: The fortran subroutine take(func) as described above which takes a subroutine as an argument and calls it. I am able to call the subroutine take(func) from maple, and func() can be a maple procedure. 

How : The problem was the incorrect INC_PATH in the define_external(`COMPILE_OPTIONS`), which had double quotes, so it was able to find the required header files for compiling the wrapper. Once, I corrected it, this simple example works like a charm. Attached working_simple1.zip with maple file, dll and fortran source file. Tested on Maple 2016 - standard worksheet (64-bit) with fortran source compiled on gfortran inside  64-bit cygwin and cygwin64/bin in the PATH. 

2. No success with another simple subroutine: While take(func) worked in its simplest form, this similar approach and toolchain, did not work for the multiply example, which worked previously with 'WRAPPERLESS' approach. The procedure gets generated in Maple, but it crashes when I execute it. Attached not_working_simple2.zip with maple file and fortran source etc. 

3. No success with slightly complex example : If I create a fortran subroutine with more than one argument along with a subrotine or if I pass an argument to the argument subroutine then Maple crashes on both instances. Attached code for not_working2.zip

Any guidance to debug this situation is appreciated. 

Thanks 

working_simple1.zip     not_working_simple2.zip       not_working2.zip    

@chintanp 

 

I was also exposed to another gem of a syntax, 

 

C([g[i] = rhs(subs(vars2, ode_eqs)[i])]);

 

This printed the output of the form: g[0] = ... and this way I was able to get the RHS of my equations in the variable g[] and then through some C manipulation of the code, I was able to assign g to the RHS of f << dot () == 

 

Maple could use some better documentation. 

 

Thanks 

 

@John Fredsted 

 

I think what you wanted to achieve is possible through the output=string option to CodeGEneration. It has to be passed as a second argument and it returned ex1 := "cg5 = (u(t) - 0.2e0 * pow(v(t), 0.2e1)) / m(t);\n" as a string and it can be manipulated now. 

 

Thanks for the direction. 

@John Fredsted 

 

Thanks for trying. 

I will also try to acheive this in C instead of through Maple. 

 

 

Page 1 of 1