Re: Programming with .NET / hand over of variables
- To: mathgroup at smc.vnet.net
- Subject: [mg68419] Re: [mg68376] Programming with .NET / hand over of variables
- From: Todd Gayley <tgayley at wolfram.com>
- Date: Fri, 4 Aug 2006 03:59:38 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 05:06 AM 8/3/2006, Andreas Baumbach wrote:
>Dear Sir or Madam,
>
>i don't know how simple or difficult this question is, but i do not know
>how to work this problem out.
>i have an problem with the implementation of Mathematica in my
>.NET-Program.
>
>Here is the code:
>
>mathKernel.Compute("puffer1 =
>ReadList[\"v3504b.txt\",{Number,Number}]"); //Read an array of numbers
>from a file
>mathErgebnis = new
>Wolfram.NETLink.Expr(mathKernel.Result); //The
>Result, which is send back by mathKernel is saved as an Expression
>double[][] ar = ?
> //Transform the Result in an
>array which i can handle with C#
>
>I want to have the 2*N array, which is saved in puffer1, transformed in
>an C# equivalent.
>What have i to do, so that it works?
>Thanks for your advice.
Andreas,
Since you want the result as an Expr, set the ResultFormat property to
ensure that:
mathKernel.ResultFormat = MathKernel.ResultFormatType.Expr;
mathKernel.Compute("puffer1 = ReadList[\"v3504b.txt\",{Number,Number}]");
mathErgebnis = (Expr) mathKernel.Result;
To get the Expr's value as a native C# array, use the AsArray() method:
double[,] ar = mathErgebnis.AsArray(ExpressionType.Real, 2);
You say you want a double[][] instead of a double[,]. If you really want
the "array of arrays" format you will have to manually allocate a
double[][] of the correct size and fill it from the elements in ar. It is
generally more convenient to work with multidimensional arrays (double[,])
than arrays-of-arrays (double[][]) in C#.
Todd Gayley
Wolfram Research