MathGroup Archive 2008

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

Search the Archive

Re: problem with MLGetReal64Array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85162] Re: problem with MLGetReal64Array
  • From: GS <vokaputs at gmail.com>
  • Date: Wed, 30 Jan 2008 06:15:04 -0500 (EST)
  • References: <fm9an9$ipe$1@smc.vnet.net>

Here is a solution to the original post, kindly communicated to me by
Steve Wilson from Wolfram.
Two things were wrong in my code:

1. The argument of the function get_real_array should be void rather
than MLINK lp.
The mathlink functions (MLGetReal64Array, etc) in the body of this
function should use
stdlink instead of the link pointer lp.
2. The function should return something to the kernel. In the original
version of the code,
where it returned nothing, the kernel hung during execution of the
external code (waiting
forever to get a return value).

None of this issues are properly documented (at least I could not find
anything).
The information on the Wolfram web site
http://reference.wolfram.com/mathematica/ref/c/MLGetReal64Array.html
is misleading on both accounts.

Here  is the fixed code. The function returns Null to the code:
void get_real_array(void)
 {
         double *data;
         int *dims;
         char **heads;
         int d;

         if(! MLGetReal64Array(stdlink, &data, &dims, &heads, &d))
         {
                 MLPutSymbol(stdlink, "$Aborted");
                 return;
         }

         MLReleaseReal64Array(stdlink, data, dims, heads, d);
         MLPutSymbol(stdlink,"Null");
 }

GS.


On Jan 11, 7:04 pm, GS <vokap... at gmail.com> wrote:
> I am trying to compile a c program that uses MathLink, to be able to
> execute an external c-code from Mathematica. I use Mathematica 6.0.1
> on Windows XP and a gcc compiler from cygwin with -mno-cygwin option.
> There were no problems with compiling and running the addtwo example
> rom the Mathematica tutorial. Since I will need to transfer arrays
> from and to Mathematica, I also want to learn how to use MLPutReal64Array
> and MLGetReal64Array functions.
>
> I did not have a problem with compiling an example with
> MLPutReal64Array from Mathematica online tutorial. However, the following
> example with MLGetReal64Array does not work for me (see the code
> below). The code compiles without errors, however, when I Install[]
> it, and run the command
>       getRealArray[{{1., 2.}, {4., 5.}}]
> it crashes the link with the message "LinkObject::linkd: Unable to
> communicate with closed link ...".
>
> Did anybody succeed in compiling this example?
> Thanks.
>
> PS. My attempt to compile with Microsoft Visual C gives the same
> result (link crash).
>
> ******************** array.c ***************************
> #include "mathlink.h"
>
> /* read an array of double-precision floating-point numbers from a
> link */
>
> void get_real_array(MLINK lp)
> {
>         double *data;
>         int *dims;
>         char **heads;
>         int d; /* stores the rank of the array */
>
>         if(! MLGetReal64Array(lp, &data, &dims, &heads, &d))
>                 {
>                         /* unable to read the array from lp */
>                         return;
>                 }
>
>         MLReleaseReal64Array(lp, data, dims, heads, d);
>
> }
>
> int main(int argc, char* argv[])
> {
>         return MLMain(argc, argv);}
>
> ********************* end of array.c****************************
>
> ********************* array.tm********************************
> :Begin:
> :Function:         get_real_array
> :Pattern:          getRealArray[x_]
> :Aguments:        {x}
> :ArgumentTypes:    {Manual}
> :ReturnType:       Null
> :End:
> :Evaluate: getRealArray::usage = "gets a matrix of reals."
> **************************************************************


  • Prev by Date: Re: LATEX to Mathematica
  • Next by Date: Re: Polylog equations
  • Previous by thread: Re: problem with MLGetReal64Array
  • Next by thread: Use Style for symbol with a value?