Using Mathlink to export arrays

*To*: mathgroup at smc.vnet.net*Subject*: [mg67090] Using Mathlink to export arrays*From*: "Amy" <amy.squillacote at kitware.com>*Date*: Fri, 9 Jun 2006 01:07:32 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Hi, I am using Mathlink to move arrays with depth=3 from Mathematica (version 5.2) into a C++ program I am developing. I want to represent the data in my program as fully as possible (i.e., avoid casting to another data type), but I also don't want to use more memory than is necessary to store the data. My program handles arrays of any type of integer data (short integer, integer, and long integer) as well floating-point data (stored as float, not double, in C++). I am trying to figure out how to determine from Mathematica what type (and which MLGet***Array method) I should use based on the data array coming from Mathematica. I first tried the following. if (MLGetShortIntegerArray(...)) { // do something } else if (MLGetIntegerArray(...)) { // do something else } else if (MLGetLongIntegerArray(...)) { // do something else } else if (MLGetFloatArray(...)) { // do something else } else { // fail } I thought if I passed in floating-point data that the MLGet***IntegerArray methods would return 0 (for failure), but they did not. Instead the MLGetShortIntegerArray method was used, and the floating-point data in the array was cast to a short integer type. I then tried to change my .tm file so the Pattern only accepted integer arrays (intending to create a separate function for handling floating-point arrays), but I could not get that to work either; neither my integer or floating point arrays were accepted. The relevant excerpt from my .tm file follows. :Begin: :Function: MyFunction :Pattern: MyFunction[x_?ArrayQ[#, IntegerQ]] :Arguments: {x} :ArgumentTypes: {Manual} :ReturnType: Integer :End: Any insights? - Amy