11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

334 • Chapter 7: <strong>Advanced</strong> ConnectivityALGEB test( MKernelVector k, ALGEB args ){/* skip arg checking for the sake of brevity */kv = k; /* save kernel vector *//* get the hfarray handle */hfparams[3] = MapleEvalhf(DAG(args[1]));fn = DAG(args[2]); /* save the function handle */do_stuff(callback); /* start the routine that *//* calls callback() */return( k->toMapleNULL() );}In Maple, the external routine is accessed like any other, except anerror is raised if the given procedure is not able to use evalhf.> f := proc(n,x,y) y[1] := n*sin(x); end:> y := Vector([1,2],datatype=float[8]):> p := define_external(’test’,MAPLE,LIB="libtest.so"):> p(y,f):General Evaluation The following procedures evaluate a Maple proceduresor statements. These routines are not available in the Fortran API.ALGEB MapleEval( MKernelVector kv, ALGEB s );ALGEB EvalMapleProc( MKernelVector kv, ALGEB fn, int nargs,/* ALGEB arg1, ALGEB arg2, */ ... );ALGEB EvalMapleStatement( MKernelVector kv, char *statement );EvalMapleProc is a callback to Maple. The first argument fn is aMaple PROC or FUNCTION dag, which is evaluated with the arguments,arg1 .. argN. For example, consider the following Maple function.> f := proc(x) x^2; end:If this function is passed to the external function as args[1], thefollowing code executes the given function at x := 3.14.ALGEB a1, MapleResult;double CResult;a1 = ToMapleFloat(kv,3.14);MapleResult = EvalMapleProc(kv,args[1],1,a1);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!