MathGroup Archive 1998

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

Search the Archive

Re: Simple MathLink question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14715] Re: Simple MathLink question
  • From: kevinl (Kevin Leuthold)
  • Date: Tue, 10 Nov 1998 01:21:05 -0500
  • Organization: Wolfram Research, Inc.
  • References: <7257mf$89d@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jim,

There are two problems here that you need to be aware of.

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.

The second is that when you send a string from your C program to
Mathematica,  remember that the string will be parsed twice - once by
your compiler and  once by Mathematica.  So, if you do this for
example:

MLPutFunction( stdlink, "Get", 1);
MLPutByteString( stdlink, "D:\\new.txt", 10);

then Mathematica will evaluate the command:

Get["D:\new.txt"]

(with only one backslash).  Mathematica will parse this to mean that the
string  you are passing to Get has 9 characters, the third of which is
a newline  character ('\n').  So, instead, you want to have 4
backslashes in your  C string for every pathname separator:

MLPutFunction( stdlink, "Get", 1);
MLPutByteString( stdlink, "D:\\\\new.txt", 11);

I hope this helps.

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



  • Prev by Date: Generating C++BLAS wrapers with Mathematica
  • Next by Date: Re: Multiplying large polynomials
  • Previous by thread: Simple MathLink question
  • Next by thread: Re: Simple MathLink question