RE: Mathlink & Graphics....

*To*: mathgroup at smc.vnet.net*Subject*: [mg2217] RE: [mg2174] Mathlink & Graphics....*From*: "John R. Fultz" <jfultz>*Date*: Tue, 17 Oct 1995 02:33:00 -0400

>From: The GodFather[SMTP:gandalf at dogbert.ugcs.caltech.edu] To: mathgroup at smc.vnet.net >Sent: Thursday, October 12, 1995 12:58 AM >To: mathgroup at smc.vnet.net >Subject: [mg2174] Mathlink & Graphics.... > > > Unix Platform.... > > I've been trying to do this for a bit of time.... > > Basically, I would like from a C-code, to generate > a list of numbers {{1,2},{2,1}} and plot their positions > using mathematica's handy plotting routines.... > > If someone could post a way to simply execute a > Plot[x^2,{x,-2,2}], and either have mathematica display > it (in X), or return PostScript to the link stream or > to an output file I would be extremely grateful.... I've included code at the end which does exactly what you need. I also strongly suggest you download the MathLink Tutorial from MathSource, available as item 0206-693. Among other things, this discusses graphics. Note that, since the default init.m sets $DisplayFunction to "stdout" whenever MathLink has a parent connection (e.g. your MathLink program), you have to force it to set the $DisplayFunction elsewhere. I did so by forcing Mathematica to do a Get["Motif.m"] (of course, you could use OL.m or GL.m, if appropriate for your machine, as well). John Fultz Wolfram Research, Inc. -------------------------------- #include "mathlink.h" #include <stdlib.h> #include <stdio.h> char *foo[] = {"-linkname", "math -mathlink", "-linkmode", "launch", 0}; int main (argc, argv) int argc; char* argv[]; { MLINK lp; MLEnvironment ep; int i; char s; ep=MLInitialize(NULL); lp = MLOpen(4, foo); MLPutFunction(lp, "EvaluatePacket", 1); MLPutFunction(lp, "Get", 1); MLPutString(lp, "Motif.m"); MLEndPacket(lp); while (MLNextPacket(lp) != RETURNPKT) {MLNewPacket(lp); }; MLNewPacket(lp); MLPutFunction(lp, "EvaluatePacket", 1); MLPutFunction(lp, "ToExpression", 1); MLPutString(lp, "Plot[x^2, {x, -2, 2}]"); MLEndPacket(lp); while (MLNextPacket(lp) != RETURNPKT) {MLNewPacket(lp); }; MLNewPacket(lp); printf("Press Return to end."); scanf("%c",&s); MLClose(lp); MLDeinitialize(ep); }