MathGroup Archive 2009

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

Search the Archive

problem about MLPutRealArray

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105322] problem about MLPutRealArray
  • From: 董理 <dongli2020 at gmail.com>
  • Date: Sat, 28 Nov 2009 01:05:14 -0500 (EST)

Hi all,

I want to send an array A to MathLink, the dimensions of A are 2, 3.
According to the document of MLPutRealArray, I wrote the following snippet:

"
double * A;
double * B;
long dims[2];
long * dims2;
char ** heads;
long d;

*(A+0) = 1.1;
*(A+1) = 1.2;
*(A+2) = 1.3;
*(A+3) = 1.4;
*(A+4) = 1.5;
*(A+5) = 1.6;

dims[0] = 2;
dims[1] = 3;

MLPutFunction(link, "EvaluatePacket", 1);
MLPutFunction(link, "CompoundExpression", 2);
MLPutFunction(link, "Set", 2);
MLPutSymbol(link, "A");
MLPutRealArray(link, A, dims, NULL, 2);
MLPutSymbol(link, "Null");
MLEndPacket(link);

while((packet = MLNextPacket(link)) && packet != RETURNPKT)
MLNewPacket(link);
MLNewPacket(link);

MLPutFunction(link, "EvaluatePacket", 1);
MLPutFunction(link, "ToExpression", 1);
MLPutString(link, "A");
MLEndPacket(link);

while((packet = MLNextPacket(link)) && packet != RETURNPKT) {
printf("packet %i\n", packet);
if(packet == TEXTPKT) {
MLGetString(link, &text);
printf("TEXTPKT:\n");
printf("%s\n", text);
}
MLNewPacket(link);
}

if(!packet) {
printf("packets receiving error: %s\n", MLErrorMessage(link));
} else {
if(!MLGetRealArray(link, &B, &dims2, &heads, &d)) {
printf("MLGetRealArray: internal errror: %s\n", MLErrorMessage(link));
return;
}
}
"
The B is:

1.100000 1.200000 1.300000 1.400000 1.500000

So why is that? Isn't "dims" the dimensions of A? The document of
MLPutRealArray and MLPutReal64Array are wrong!

DONG Li


  • Prev by Date: Re: How to make {f,g}[a,b,c] to become
  • Next by Date: Re: Re: Re: Replacing Values Close to One
  • Previous by thread: Re: Replacement rules that contain function arguments
  • Next by thread: Bug ??????