Try GP in your browser Main Download Packages Funding SEARCH Help / Community FAQ Documentation Tutorials Mailing Lists Bugs Timeline Ateliers PARI/GP Library Publications Contributed GP scripts Links Fun! Development Latest Changes Version Control Coding Guidelines PariDroid Logo Tests & benchmarks Buildlogs Coverage Report Doc Coverage Refcards test Benchmarks WWW Stats |
How to use extern: the example of mwrank
The
Unfortunately, using
We assume henceforth that you have a working version of
Wrapper shellscriptCreate a file calledgpmwrank . This file must be executable
and in your shell path, e.g. $HOME/bin . Put the following lines
in this file:
#!/bin/sh res=`echo "$1 0 0 0 0 0" | mwrank -q -v 0 -o | grep '^\['` if test -z "$res"; then echo 'error("An error occured in mwrank")' else echo "$res" fi
This passes on its arguments to Otherwise an error occured, and we act accordingly: remember that the output of this file will be read by gp's interpreter, so we do not trigger an error here, we print a command that will trigger it when read by gp. Make sure this script is executable (chmod 755 gpmwrank), then put it somewhere in your PATH. (This is a list of directories where your shell looks for executable files.) Note: The time ellapsed in commands called via extern is not taken into account by gp's timer. You may want to use extern("time cmd") instead of extern("cmd").Wrapper gpscriptIn order to define the functionellrank , create a file
ellrank.gp containing the following lines:
ellrank(e) = { my(l = length(e)); if (type(e) != "t_VEC" || (l != 5 && l != 13 && l != 19), error("incorrect type in ellrank") ); extern( Str("gpmwrank ["e[1]","e[2]","e[3]","e[4]","e[5]"]") ) }
This does some rudimentary error checking then calls Put this file somewhere in your GP path. (See the path default in the manual.) Loading ellrank on startupAdd the following line at the end of your.gprc file:
read "ellrank.gp"
This causes the
Of course, the names of the file and function do not have to coincide. They
were chosen as above for consistency and self-documentation:
path = "$HOME/pari/gpscripts"in your .gprc, if for instance ellrank.gp went there. TestingYou are ready to test the installation. Start gp and try some examples:? ellrank([0,-1,1,-10,-20]) %1 = [[0], []] ? ellrank([0,0,1,-1,0]) %2 = [[1], [[0, 0]]] ? ellrank([1,0,0,0,1]) %3 = [[2], [[1, 1], [3/4, 7/8]]] |
PARI/GP Development
Last Modified: 2016-03-22 20:34:27
Copyleft © 2003-2022
the PARI group.