Re: Simple MathLink question

*To*: mathgroup at smc.vnet.net*Subject*: [mg14738] Re: Simple MathLink question*From*: kevinl (Kevin Leuthold)*Date*: Wed, 11 Nov 1998 17:53:41 -0500*Organization*: Wolfram Research, Inc.*References*: <7257mf$89d@smc.vnet.net> <728l6j$eig@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

A follow up to my own post: What I stated below is only partly correct. In particular, the following paragraph is correct. >The first is that MathLink encodes its data in a private manner. This >wouldn't be a problem if you were calling MLPutString with >alphanumeric characters, since these characters are represented >literally. But it does mean that calling MLPutString on a string with >backslashes in it won't work. This is discussed in the MathLink >Developer Guide, in the "What's New" section, in a subsection entitled >"The Biggest Compatibility Issue". Instead of MLPutString in this >situation, consider using MLPutByteString. However, the rest of the post is inaccurate. If you are sending Get["D:\\new.txt"] to Mathematica, using MLPutFunction and MLPutByteString, then the string will only be parsed once - by your compiler. Mathematica's parser will not see this string since you are building it up yourself. So despite my original post, the following is correct: MLPutFunction( stdlink, "Get", 1); MLPutByteString( stdlink, "D:\\new.txt", 10); There are situations where a string would be parsed by both your C compiler and Mathematica, and so 4 backslashes would be needed for each pathname separator. Here is an example: MLPutFunction( stdlink, "ToExpression", 1); MLPutByteString( stdlink, "Get[\"D:\\\\new.txt\"]", 18); Sorry for any confusion. Kevin Leuthold MathLink Group Wolfram Research >Jim McGuire <jimm at opticalres.com> writes: >>I am trying to read in a set of Mathematica definitions which was saved >>using DumpSave["MathLink_USER.mx",{function1,function2,...}] from >>D:\jimm\svgcn018 directory on my NT PC. I have been unsuccessful >>reading it into the MathLink session. The definitions are very long >>and I do not relish the thought of importing them using MLPut commands. >>I tried the following test to see if the link is open. It shows the >>proper data is ready to be read by the link >>MLPutFunction(stdlink,"EvaluatePacket",1); >> MLPutFunction(stdlink,"Plus",2); >> MLPutReal(stdlink,2.1) >> MLPutInteger(stdlink,2); >>MLEndPacket(stdlink); >>printf("MLReady = %d\n",MLReady(stdlink)); >>However when I try the following, it shows that there is no data to be >>read on the stdlink and subsequent attempts to read data hang. >>MLPutFunction(stdlink,"EvaluatePacket",1); >> MLPutFunction(stdlink,"Get",1); >> MLPutString(stdlink,"\"D:\\jimm\\svgcn018\\MathLink_USERSUR.mx\""); >>MLEndPacket(stdlink); >>printf("MLReady = %d\n",MLReady(stdlink)); >>I have tried issuing Get["D:\jimm\svgcn018\MathLink_USERSUR.mx"] from >>within Mathematica and it works fine. The desired functions are >>loaded. >>Many thanks in advance for any assistance. >>Jim