11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.2 Using Compiled Code in Maple • 331example, if you create the number num = one-billion, then you computethe number val = 2*500-million. An address comparison of numand val does not indicate equality. After calling simplify as in num =MapleUnique(kv,num), both num and val point to the same memory.The following functions raise a Maple software-style er-Error Handlingror message.void MapleRaiseError( MKernelVector kv, char *msg );void MapleRaiseError1( MKernelVector kv, char *msg,ALGEB arg1 );void MapleRaiseError2( MKernelVector kv, char *msg,ALGEB arg1, ALGEB arg2 );The Fortran equivalent is:SUBROUTINE maple_raise_error( kv, msg, len )These functions display the message msg, stop execution, and returnto the Maple input loop. A call to MapleRaiseError does not return.The character string msg can contain wildcards of the form %N, where Nis a non-zero integer. These wildcards are replaced by the extra argument,arg1 or arg2, before displaying the message. If %-N is specified, then theoptional argument is displayed with st, nd, rd, or th appended to it. Forexample:MapleRaiseError2(kv, "the %-1 argument, ’%2’, is not valid",ToMapleInteger(i), args[i]);This, if invoked, raises the error, "the 4th argument, ’foo’, is notvalid", assuming i=4, and args[i] is set to the Maple name foo. 4The only option not allowed is %0 since the function cannot determinethe number of unparsed optional arguments.The C API also provides a mechanism for trapping errors raised byMaple.void* MapleTrapError( MKernelVector kv, void *(*proc)P(( void *data )), void *data, M_BOOL *errorflag );MapleTrapError executes the C function proc, passing it the data,data. If an error occurs, errorflag is set to TRUE and traperror returns4 For more information, see ?error.

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

Saved successfully!

Ooh no, something went wrong!