Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Mathlink & Graphics....

  • Subject: [mg2217] RE: [mg2174] Mathlink & Graphics....
  • From: jfultz ("John R. Fultz")
  • Date: Tue, 17 Oct 1995 06:33:00 GMT
  • Approved: usenet@wri.com
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at wri.com ( )

>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);
}



  • Prev by Date: Re: Solid Geometry Problem
  • Next by Date: RE: C++
  • Previous by thread: Mathlink & Graphics....
  • Next by thread: Re: Mathlink & Graphics....