FW: RE: Mathlink & Graphics....
- Subject: [mg2254] FW: [mg2217] RE: [mg2174] Mathlink & Graphics....
- From: jfultz ("John R. Fultz")
- Date: Thu, 19 Oct 1995 05:31:44 GMT
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: Wolfram Research, Inc.
- Sender: daemon at wri.com ( )
I forgot to mention some things about my previous message. Note in the code I sent out, I ended it with the following: > 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); Some may wonder why I chose to end my code as I did. There are two specific things I'd like to point out. First, note that I did get the ReturnPacket from the Plot command. It's a common mistake to not get the ReturnPacket from a Plot command or some other command which returns output you're not interested in, but the output must be retrieved, even if it's Null (earlier in a part of the program I didn't quote, I also retrieved the ReturnPacket from a Get command, which was null). If you're not interested in the ReturnPacket, you must get it, although it's perfectly in your right to throw it away once you have it. It's not just a good idea to do this; you will screw your program up if you don't. The other thing some may wonder about is why I bothered to put the scanf at the end instead of immediately terminating the program. I discovered a while back that, if Mathematica is piping graphics to an external stream, it requires a little time to do so even after it's sent the ReturnPacket back to you. If I were to execute an MLClose immediately after getting the ReturnPacket, the kernel would close abruptly and never finish shelling out to the motifps command. So, the scanf is simply a delaying tactic to keep the MathLink connection open long enough to finish the plot. Of course, if this Plot were to show up in the middle of your MathLink program instead of the end, this would not be an issue. John Fultz Wolfram Research, Inc.