MathGroup Archive 1997

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

Search the Archive

Re: the method of Graphics Display by MathLink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9649] Re: the method of Graphics Display by MathLink
  • From: kevinl at mallorn.com (Kevin Leuthold)
  • Date: Mon, 17 Nov 1997 19:50:06 -0500
  • Organization: Wolfram Research, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

>  Now, I'm trying to display graphics by MathLink in remote mode.
> 
>  The Mathlink Tutorial tell me that use Motif.m following

>      MLPutFunction(link,"Get",1)
>      MLPutFunction(link,"Motif.m")
>      ...

To evaluate Get["Motif.m"] in the kernel, you'll want to change call
MLString in place of the second MLFunction call:

>      MLPutFunction(link,"Get",1)
>      MLPutString(link,"Motif.m")
>      ...


>  But,ther is one problem.
>  In stating Mathematica, I have to execute next command.

>     Install[" ",linkMode->Listen]

>  I want to automatically execute this command in stating mathematica,
>  and want to execute mathematica from external by exec() system call.

Evaluating Install[" ", LinkMode -> Listen] (note that LinkMode is
capitalized) won't work - if you want MathLink to provide  a port for
you, you'll want to call Install["", LinkMode -> Listen] (no space in
between the quotes).

If you want to start the kernel and have it automatically evaluate a
command, you can use the -run flag.  So, at a command prompt, you can
do this:

math -run "Install[ToString[5000], LinkMode -> Listen]"

and the kernel will start up with Install[ToString[5000], LinkMode ->
Listen] being evaluated before you get a prompt.  So, you could make a
call to exec  that calls the kernel with the above arguments.  (This
has the disadvantage that the port 5000 may already be in use, and the
Install would then fail).

However, it may be preferable to use MathLink to launch the kernel.  You
can have your program launch a kernel, open a link, get the linkname
back,  and then Install the link.  This way you can have MathLink
choose a port that isn't in use, and you can do error checking to see
if the calls to LinkOpen and Install succeeded.

For example, following is a short program that does just that (with no
error  checking).

Kevin Leuthold
Wolfram Research



#include "mathlink.h"

int main( int argc, char* argv[]){
    MLENV ep;
    MLINK lp;
    long err;
    int pkt;
    const char *s;

    ep = MLInitialize( 0);
    lp = MLOpenString( ep, "-linkname 'math -mathlink' -linkmode
launch", &err);

    MLPutFunction( lp, "EvaluatePacket", 1L);
        MLPutFunction( lp, "ToExpression", 1L);
            MLPutString( lp,
            "link = LinkOpen[LinkMode -> Listen]; First[link]");
    MLEndPacket( lp);

    while( (pkt = MLNextPacket( lp), pkt) && pkt != RETURNPKT) {
        MLNewPacket( lp);
    }

    MLGetString( lp, &s);

    /* do something with the contents of s, which contains the linkname
	created by the call to LinkOpen */

    MLDisownString( lp, s);

    MLPutFunction( lp, "EvaluatePacket", 1L);
        MLPutFunction( lp, "ToExpression", 1L);
            MLPutString( lp, "Install[link]");
    MLEndPacket( lp);

    MLClose( lp);
    MLDeinitialize( ep);
}




  • Prev by Date: Which, If and "neither True nor False"
  • Next by Date: Re: Control System Professional Add-On for Mathematica
  • Previous by thread: the method of Graphics Display by MathLink
  • Next by thread: stop the frontend