LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

2D functions in Advanced Analysis Library

I am trying to use some of the 2D functions (e.g. Sum2D etc.) in the
Adv. Analysis Library.

The following piece of code is supposed to allocate memory for a 2D
array, fill that array with random numbers and determine the sum of the
elements. I can get an error: "Array argument too small..."
If you use pointers the problem persists no matter how many points the
2D array has.
HOWEVER, if you do not use pointers and declare an array, i.e.
dArray[][], then it works if the number of points is small, e.g. 10.

Any help would be appreciated.

#include
#include
#define NPTS 240

void main ()
{
int i, j;
double sum;
double **dArray;

// Allocate memory for the 2D array
dArray
= malloc(NPTS*sizeof(double));
for (i=0; i dArray[i] = malloc(NPTS*sizeof(double));

// Put some random numbers in the array
for (i=0; i {
for (j=0; j dArray[i][j] = rand();
}

// Use Advanced Analysis to sum the array elements. You get an error:
// Error: Array argument too small (1920) bytes. Argument must contain
at least 460800 bytes

Sum2D (dArray, NPTS, NPTS, ∑);

// Other Advanced Analysis 2D functions have the same the problem.
// If you use pointers the problem persists no matter what NPTS is
// HOWEVER, if you use arrays, i.e. dArray[][], then it works if NPTS
is small, e.g. 10
free(dArray);
}

Thanks

Haris Riris
hriris@pop900.gsfc.nasa.gov
NASA/GSFC, mail code 924
0 Kudos
Message 1 of 4
(4,181 Views)
In article <38B2FB92.F50F4ADB@pop900.gsfc.nasa.gov>,
Haris Riris wrote:
> I am trying to use some of the 2D functions (e.g. Sum2D etc.) in the
> Adv. Analysis Library.
>
> The following piece of code is supposed to allocate memory for a 2D
> array, fill that array with random numbers and determine the sum of
the
> elements. I can get an error: "Array argument too small..."
> If you use pointers the problem persists no matter how many points
the
> 2D array has.
> HOWEVER, if you do not use pointers and declare an array, i.e.
> dArray[][], then it works if the number of points is small, e.g. 10.
>
> Hi
I had similar problems, I'm sure the problem is not the 2D functions.
With your definition the memory is big enough for one row only
.
I never found out how to create a 2d array with pointers. In c a 2D
array is an array of arrays. But how can I tell the compiler my
NxMxsizeOfDouble array shall be organized as NxM array??
Can any of the 'C'cracks help the two of us?

Best Regards
Urs


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 2 of 4
(4,181 Views)
Actually it does create a 2d array. (You can check it with the debugger).
But pointers aside, the 2D functions seem to have a maximum number of NxM
(about 10 x 10) if you use arrays.
I couldn't find any limit in their manual
Haris



ursb@my-deja.com wrote:

> In article <38B2FB92.F50F4ADB@pop900.gsfc.nasa.gov>,
> Haris Riris wrote:
> > I am trying to use some of the 2D functions (e.g. Sum2D etc.) in the
> > Adv. Analysis Library.
> >
> > The following piece of code is supposed to allocate memory for a 2D
> > array, fill that array with random numbers and determine the sum of
> the
> > elements. I can get an error: "Array argument too small..."
> > If you use pointers the problem persists no matter how many points
> the
> > 2D
array has.
> > HOWEVER, if you do not use pointers and declare an array, i.e.
> > dArray[][], then it works if the number of points is small, e.g. 10.
> >
> > Hi
> I had similar problems, I'm sure the problem is not the 2D functions.
> With your definition the memory is big enough for one row only.
> I never found out how to create a 2d array with pointers. In c a 2D
> array is an array of arrays. But how can I tell the compiler my
> NxMxsizeOfDouble array shall be organized as NxM array??
> Can any of the 'C'cracks help the two of us?
>
> Best Regards
> Urs
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
0 Kudos
Message 3 of 4
(4,181 Views)
Hi Haris,
You have run into the CVI pointer arithmetic user protection. Look up
Pointer Protection and Array Indexing Errors in the online help.
You can disable pointer checking for a particular pointer by casting it
to an arithmetic type, then back to a pointer type.
This code comes from the help file. Define the folowing macro.

#define DISABLE_RUNTIME_CHECKING(ptr) ((ptr) = (void *)((unsigned) (ptr)))

Call it after the call to malloc().

// Allocate memory for the 2D array
dArray = malloc(NPTS*sizeof(double));

for (i=0; i dArray[i] = malloc(NPTS*sizeof(double));
DISABLE_RUNTIME_CHECKING(dArray);

Hope this helps,
Reed.
//----------------------------------------------------------
Reed Blake
Beta Technology
Industrial and Scientific Computing

Haris Riris wrote in message <38B2FB92.F50F4ADB@pop900.gsfc.nasa.gov>...
>I am trying to use some of the 2D functions (e.g. Sum2D etc.) in the
>Adv. Analysis Library.
>
>The following piece of code is supposed to allocate memory for a 2D
>array, fill that array with random numbers and determine the sum of the
>elements. I can get an error: "Array argument too small..."
> If you use pointers the problem persists no matter how many points the
>2D array has.
> HOWEVER, if you do not use pointers and declare an array, i.e.
>dArray[][], then it works if the number of points is small, e.g. 10.
>
>Any help would be appreciated.
>
>#include
>#include
>#define NPTS 240
>
>void main ()
>{
> int i, j;
> double sum;
> double **dArray;
>
> // Allocate memory for the 2D array
> dArray = malloc(NPTS*sizeof(double));
> for (i=0; i> dArray[i] = malloc(NPTS*sizeof(double));
>
> // Put some random numbers in the array
> for (i=0; i> {
> for (j=0; j> dArray[i][j] = rand();
> }
>
> // Use Advanced Analysis to sum the array elements. You get an error:
> // Error: Array argument too small (1920) bytes. Argument must contain
>at least 460800 bytes
>
> Sum2D (dArray, NPTS, NPTS, ∑);
>
> // Other Advanced Analysis 2D functions have the same the problem.
> // If you use pointers the problem persists no matter what NPTS is
> // HOWEVER, if you use arrays, i.e. dArray[][], then it works if NPTS
>is small, e.g. 10
> free(dArray);
>}
>
>Thanks
>
>Haris Riris
>hriris@pop900.gsfc.nasa.gov
>NASA/GSFC, mail code 924
>
0 Kudos
Message 4 of 4
(4,181 Views)