Re: Reading arrays in mathlink
- To: mathgroup at smc.vnet.net
- Subject: [mg30156] Re: Reading arrays in mathlink
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 1 Aug 2001 02:19:11 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <9joa43$18o$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
from the Online-manual :
MLGetFunction() allocates memory for the character string corresponding
to the name of the head of the function. You must call MLDisownSymbol()
to disown this memory.
-----------------------------------------------------
General it would be better to transform the mixed type to
complex only numbers with
toSend=Flatten[
yourArgument /.
{Complex[a_,b_]:> {a,b},a_Real:> {a,0.},a_Integer:> {N[a],0.}}
]
send a list of the double length. This should be faster
than to transfer/check every entry.
Regards
Jens
Sseziwa Mukasa wrote:
>
> How does one read an array in Mathlink whose entries are either real or
> complex?
>
> I am trying the following seqeunce
>
> int r,c,i,j,args;
> char *sym;
> double val;
>
> MLCheckFunction( stdlink, "List", &r)
> for (i=0; i<r; i++) {
> MLCheckFunction( stdlink, "List", &c);
> for (j=0,j<c,j++) {
> MLGetFunction( stdlink, &sym, &args);
> switch (args) {
> case 1 :
> MLGetReal( stdlink, &val);
> break;
> case 2 :
> MLGetReal( stdlink, &val); /* Get real part*/
> MLGetReal( stdlink, &val); /* Get imaginary part*/
> break;
> }
> }
> }
>
> The connection dies for some reason. I have no idea why,