MathGroup Archive 2008

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

Search the Archive

Re: problem with MLGetReal64Array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84857] Re: problem with MLGetReal64Array
  • From: GS <vokaputs at gmail.com>
  • Date: Wed, 16 Jan 2008 23:05:47 -0500 (EST)
  • References: <fm9an9$ipe$1@smc.vnet.net> <fmf7q3$dm1$1@smc.vnet.net>

On Jan 16, 12:37 am, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
wrote:
> Hi,
>
> I would Flatten[] the array and read the dimensions
> separate, i.e., send a variable that contain the dimensions
> and a flat array with the values in the array. In the C-code
> the dimensions are read first and put into the data structure
> you have for the n-dimensional array. My image processing package
> has definitions like
>
> template <>
> Image<int>::Image(int nX, int nY,int ch, MLINK link): nx(nX), ny(nY),
> channelNo(ch) {
>    int *data;
>    long len;
>
>    pixelSize=nx*ny*channelNo;
>    byteSize=nx*ny*channelNo*sizeof(int);
>    MLGetIntegerList(link,&data,&len);
>    if(len==0 || len!=nx*ny*channelNo) {
>      fprintf(stderr,
>        "Error creating Image<int> form MathLink. Need %d pixels got %ld.",
>        pixelSize,len);
>      bm=NULL;
>     }
>    else {
>      bm=new int[pixelSize];
>      memcpy(bm,data,byteSize);
>     }
>    MLDisownIntegerList(link,data,len);
>
> };
>
> and I call my C-functions always with
>
> myFunction[Sequence @@ Dimensions[imageData],Flatten[imageData]]
>
> ...
>
> But you can walk into the structure of your n-dimensional array
> with reading heads and list length ..
>
> Regards
>    Jens
>
> GS wrote:
> > On Jan 14, 12:51 am, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de>
> > wrote:
> >> Hi,
>
> >> and you think that the Mathematica Kernel know that
> >> you wish to get a Real64Array[] and not a
> >> List[List[___Real]..]
> >> ??
>
> >> Regards
> >>    Jens
>
> >> GS 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_]
> >>> :Arguments:        {x}
> >>> :ArgumentTypes:    {Manual}
> >>> :ReturnType:       Null
> >>> :End:
> >>> :Evaluate: getRealArray::usage = "gets a matrix of reals."
> >>> **************************************************************
>
> > Hi Jens,
> > I am not sure that I understand your question, but it looks like you
> > see what my problem is.
> > I would appreciate it very much if you could point out how I should
> > fix the code.
> > Thank you.
> > GS

Hi Jens,

Thanks for the advice. That is exactly what I do now (I found one of
your earlier posts with this idea). However, the point of my posting
is that the Mathlink command MLPutReal64Array does not work as it is
described in the Mathematica tutorials (MLPutReal64List does work, and can be
used as a kludge replacement of the former). If I do not have mistakes
in my sample code, I have to declare that MLPutReal64Array has a bug.
I am wondering if anybody from Wolfram wants to comment on the issue.

GS


  • Prev by Date: On placement of controls around Manipulate display area and positioning of control varibles relative to the control itself.
  • Next by Date: Re: Re: Re: bug -- advice sought
  • Previous by thread: Re: problem with MLGetReal64Array
  • Next by thread: Re: problem with MLGetReal64Array