MathGroup Archive 2000

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

Search the Archive

Re: MathLink MLGetRealArray

  • To: mathgroup at
  • Subject: [mg21971] Re: MathLink MLGetRealArray
  • From: Eckhard Hennig <hennig at>
  • Date: Mon, 7 Feb 2000 13:02:25 -0500 (EST)
  • Organization: ITWM
  • References: <87iph4$>
  • Sender: owner-wri-mathgroup at

Johannes Ludsteck schrieb in Nachricht <87iph4$3vb at>...
>Dear Group Members,
>I am trying to get a matrix from Mathematica into a c program via
>MathLink. When I compile the code below (with Borland C++ 5.0), I
>get an Warning message Suspicious pointer conversion in line...,
>which relates to depthx. However, the variable depthx works fine.
>The problem is with the array x. If I try to access the elements in x,
>for example
>temp = x[0][0]; temp = temp * temp;
>then the program crashes.
>void kerndens(void)
>   double **x, temp;
>   long *dimsx, depthx;
>   char **headsx;
>   MLGetRealArray(stdlink, &x, &dimsx, &headsx, &depthx);
>   MLPutReal(stdlink, x[0][0]);
>   MLDisownRealArray(stdlink, x, dimsx, headsx, depthx);


at a first glance, it seems that the array x is declared incorrectly: The
pointer should be declared as

  double *x;  // Not: **x

What you get from a MathLink connection is a *linear* array of numbers and
not a two-dimensional one. Therefore, the C code needed to access the array
element x[i, j] is given by

  xij = x[i*n + j]

where n = dimsx[1] is the column dimension. Please try if the following
modifications of your code help to solve your problem (I haven't tested
them, but the code should work).

void kerndens(void)
   double *x, temp;
   long *dimsx, depthx;
   char **headsx;
   int i, j, n;

   MLGetRealArray(stdlink, &x, &dimsx, &headsx, &depthx);
   n = dimsx[1];
   i = 0;
   j = 0;
   MLPutReal(stdlink, x[i*n + j]);
   MLDisownRealArray(stdlink, x, dimsx, headsx, depthx);

Best regards,


Dipl.-Ing. Eckhard Hennig      mailto:hennig at
Institut fuer Techno- und Wirtschaftsmathematik e.V. (ITWM)
Erwin-Schroedinger-Strasse,  67663 Kaiserslautern,  Germany
  Voice: +49-(0)631-205-3126    Fax: +49-(0)631-205-4139

     ITWM - Makers of Analog Insydes for Mathematica

  • Prev by Date: Re: Why doesn't Mathematica know this?
  • Next by Date: Re: Highly Oscillatory Integrand
  • Previous by thread: MathLink MLGetRealArray
  • Next by thread: Re: MathLink MLGetRealArray