Re: Re: MLPutRealList vs. sequence of MLPutDouble
- To: mathgroup at smc.vnet.net
- Subject: [mg61859] Re: Re: MLPutRealList vs. sequence of MLPutDouble
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Wed, 2 Nov 2005 04:09:27 -0500 (EST)
- Organization: Uni Leipzig
- References: <djq618$jb5$1@smc.vnet.net> <200510270954.FAA20752@smc.vnet.net> <djskkf$8mu$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
first of all, it is nearly impossible to find out what goes wrong
when you don't write down the Mathamtica code that
you are calling. If you have setup your Mathematica function as
test[x1_,x2_]:=somethingUsefullWith[x1,x2]
test[{x1_,x2_}]:=somethingUsefullWith[x1,x2]
it will work in both cases
If you have only the definition
test[x1_,x2_]:=somethingUsefullWith[x1,x2]
and the C-code
MLPutFunction(link,"test",2);
MLPutDouble(link,x1);
MLPutDouble(link,x2);
will work and
double x[2];
MLPutFunction(link,"test",1);
MLPutRealList(link,x,2L);
will not work because than you call test[{x1,x2}]
and not
test[x1,x2]
If you have only the definion
test[{x1_,x2_}]:=somethingUsefullWith[x1,x2]
in Mathematica, than
double x[2];
MLPutFunction(link,"test",1);
MLPutRealList(link,x,2L);
and
MLPutFunction(link,"test",2);
MLPutDouble(link,x1);
MLPutDouble(link,x2);
will not.
And clearly the Get[] command at the beginning of
your
code generate a return value Null or several
messages
and a $Failed and you must read it from the link.
Regards
Jens
"Reese Jones" <rjones at sandia.gov> schrieb im
Newsbeitrag news:djskkf$8mu$1 at smc.vnet.net...
| ...perhaps I don't understand but what you are
saying
| is exactly what I would expect:
|
| MLPutFunction(link, SCRIPT_NAME, 1);
| MLPutRealList(link,x,NUM_VARS);
|
| calls in Mathematica SCRIPT_NAME[{x0,x1}]
| (where NUM_VARS = 2, SCRIPT_NAME = "test" and
test is
| test[y_List] := y[[2]]; )
|
| except I get :
| Error detected by MathLink: MLGet out of
| sequence.
|
| are you saying the function in Mathematica needs
| to know the length of the list a priori? that
doesn't
| seem right
|
| Reese
|
|
|
|
| Jens-Peer Kuska wrote:
|
| >Hi,
| >
| >because
| >
| >MLPutFunction(link, SCRIPT_NAME, 1);
| >MLPutRealList(link,x,NUM_VARS);
| >
| >call in Mathematica SCRIPT_NAME[{x0,x1}]
| >
| >and
| >
| >MLPutFunction(link, SCRIPT_NAME, NUM_VARS);
| >for ( i=0; i<NUM_VARS; i++ ) {
MLPutDouble(link,
| >x[i]); }
| >
| >call in Mathematica
| >
| >SCRIPT_NAME[x0,x1]
| >
| >Regards
| > Jens
| >
| >"Reese Jones" <rjones at sandia.gov> schrieb im
| >Newsbeitrag news:djq618$jb5$1 at smc.vnet.net...
| >| Hi
| >| I am a new subscriber to the list and I
have a
| >seemingly
| >| simple (read: stupid) question: why does this
| >code work
| >| when I send a sequence of reals and not work
| >when I send
| >| a list?
| >|
| >| <SNIP>
| >| /* Now initialize and call Mathematica
*/
| >| env = MLInitialize(NULL);
| >| if (env == NULL) return 1;
| >|
| >| link = MLOpen(num_strings, Mparams);
| >| if (link == NULL) return 1;
| >|
| >| MLActivate(link);
| >|
| >| /* Load the compare function
definition
| >into Mathematica */
| >| MLPutFunction(link, "EnterTextPacket",
| >1);
| >| MLPutString(link, "<<" SCRIPT_NAME
".m");
| >| MLEndPacket(link);
| >|
| >| /* call the compare function with
x[1],
| >x[2]*/
| >| MLPutFunction(link, "EvaluatePacket",
1);
| >| #if REAL_LIST
| >| MLPutFunction(link, SCRIPT_NAME, 1);
| >| MLPutRealList(link,x,NUM_VARS);
| >| #else
| >| MLPutFunction(link, SCRIPT_NAME,
| >NUM_VARS);
| >| for ( i=0; i<NUM_VARS; i++ ) {
| >MLPutDouble(link, x[i]); }
| >| #endif
| >| MLEndPacket(link);
| >|
| >| /* skip any packets before the first
| >ReturnPacket
| >| and then get the result from the
| >calculation */
| >| int pkt;
| >| while( (pkt = MLNextPacket(link), pkt)
&&
| >pkt != RETURNPKT) {
| >| MLNewPacket(link);
| >| if (MLError(link)) {
| >| fprintf( stderr, "2
Error
| >detected by MathLink:
| >| %s.\n",
| >|
MLErrorMessage(link)); }
| >| }
| >|
| >| double fn_val=0.0;
| >| MLGetDouble(link, &fn_val);
| >| if (MLError(link)) {
| >| fprintf( stderr, "3 Error
| >detected by MathLink: %s.\n",
| >| MLErrorMessage(link)); }
| >| MLClose(link);
| >| MLDeinitialize(env);
| >| <SNIP>
| >|
| >| this is the Mathematica script that is called
| >(it takes a list and
| >| returns a single value) :
| >|
| >| (* test[x_Real,x2_Real] := x; *)
| >| test[y_List] := y[[2]];
| >|
| >|
| >| this is the output:
| >|
| >| Error detected by MathLink: MLGet out of
| >sequence.
| >| test : { 0.616000, 29.000000} -> f: 0.000000
| >|
| >|
| >| thanks
| >| Reese
| >|
| >| --
| >|
|
>:::::::::::::::::::::::::::::::::::::::::::::::::::::
| >| Reese Jones
| >| Sandia National Laboratories, MS 9042, P.O.
Box
| >0969
| >| Livermore, CA 94551
| >|
| >| phone: (925) 294-4744 or (800) 4SANDIA
x4-4744
| >| fax: (925) 294-1459
| >| e-mail: rjones at sandia.gov
| >|
|
>:::::::::::::::::::::::::::::::::::::::::::::::::::::
| >|
| >|
| >
| >
| >
| >
| >
| >
|
|
| --
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::
| Reese Jones
| Sandia National Laboratories, MS 9042, P.O. Box
0969
| Livermore, CA 94551
|
| phone: (925) 294-4744 or (800) 4SANDIA x4-4744
| fax: (925) 294-1459
| e-mail: rjones at sandia.gov
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|