PLUTO  4.0
 All Data Structures Files Functions Variables Enumerations Macros Pages
Functions
arrays.c File Reference

Memory allocation functions. More...

#include "pluto.h"

Functions

void FreeArray1D (void *v)
 
void FreeArray2D (void **m)
 
void FreeArray3D (void ***m)
 
void FreeArray4D (void ****m)
 
char * Array1D (int nx, size_t dsize)
 
char ** Array2D (int nx, int ny, size_t dsize)
 
char *** Array3D (int nx, int ny, int nz, size_t dsize)
 
char **** Array4D (int nx, int ny, int nz, int nv, size_t dsize)
 
double *** ArrayBox (long int nrl, long int nrh, long int ncl, long int nch, long int ndl, long int ndh)
 
void FreeArrayBox (double ***t, long nrl, long ncl, long ndl)
 
double *** ArrayMap (int nx, int ny, int nz, double *uptr)
 
void FreeArrayMap (double ***t)
 
double *** ArrayBoxMap (int nrl, int nrh, int ncl, int nch, int ndl, int ndh, double *uptr)
 
void FreeArrayBoxMap (double ***t, int nrl, int nrh, int ncl, int nch, int ndl, int ndh)
 

Detailed Description

Provides essential functions for allocating and deallocating multi-dimensional arrays. The functions Array1D(), Array2D(), Array3D(), Array4D() can be used to allocate storage for 1-D, 2-D, 3-D and 4-D arrays of any data type with indices starting at 0.

The function ArrayBox() can be used to allocate memory for a double precision array with specified index range.

The functions ArrayMap() can be used to convert a one-dimensional array into a 3D array.

Author
A. Mignone (migno.nosp@m.ne@p.nosp@m.h.uni.nosp@m.to.i.nosp@m.t)
Date
Sep 18, 2012

Function Documentation

char* Array1D ( int  nx,
size_t  dsize 
)

Allocate memory for a 1-D array of any basic data type starting at 0.

Parameters
[in]nxnumber of elements to be allocated
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char *) to the allocated memory area.
char** Array2D ( int  nx,
int  ny,
size_t  dsize 
)

Allocate memory for a 2-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 2nd dimension
[in]nynumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char **) to the allocated memory area with index range [0...nx-1][0...ny-1]
char*** Array3D ( int  nx,
int  ny,
int  nz,
size_t  dsize 
)

Allocate memory for a 3-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimension
[in]nznumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ***) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1]
char**** Array4D ( int  nx,
int  ny,
int  nz,
int  nv,
size_t  dsize 
)

Allocate memory for a 4-D array of any basic data type.

Parameters
[in]nxnumber of elements in the 4th dimension
[in]nynumber of elements in the 3rd dimension
[in]nznumber of elements in the 2nd dimension
[in]nvnumber of elements in the 1st dimension
[in]dsizedata-type of the array to be allocated
Returns
A pointer of type (char ****) to the allocated memory area with index range [0...nx-1][0...ny-1][0...nz-1][0...nv-1]
double*** ArrayBox ( long int  nrl,
long int  nrh,
long int  ncl,
long int  nch,
long int  ndl,
long int  ndh 
)

Allocate memory for a 3-D array in double precision with given subscript range [low...high] for each direction. Useful for staggered arrays which do not start at [0].

Parameters
[in]nrllower bound index for the 3rd dimension
[in]nrhupper bound index for the 3rd dimension
[in]ncllower bound index for the 2nd dimension
[in]nchupper bound index for the 2nd dimension
[in]ndllower bound index for the 1st dimension
[in]ndhupper bound index for the 1st dimension
Returns
A pointer of type (double ***) to the allocated memory area with index range [nrl...nhl][ncl...nch][ndl...ndh].
double*** ArrayBoxMap ( int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh,
double *  uptr 
)

Convert a one-dimensional array into a 3D array with given subscript range [low...high] for each direction.

double*** ArrayMap ( int  nx,
int  ny,
int  nz,
double *  uptr 
)

Convert a one dimensional array with (nx*ny*nz) elements into a 3D array with index range [0..nx-1][0..ny-1][0..nz-1]. This function is similar, conceptually, to Array3D() except that the memory area is already allocated.

Parameters
[in]uptrpointer to 1D array
[in]nxnumber of elements in the 3rd dimension
[in]nynumber of elements in the 2nd dimensions
[in]nznumber of elements in the 1st dimensions
Returns
A pointer to the 3D array.
void FreeArray1D ( void *  v)

Free memory allocated by the pointer *v.

void FreeArray2D ( void **  m)

Free memory allocated by the double pointer **v.

void FreeArray3D ( void ***  m)

Free memory allocated by the pointer ***v.

void FreeArray4D ( void ****  m)

Free memory allocated by the pointer ****v.

void FreeArrayBox ( double ***  t,
long  nrl,
long  ncl,
long  ndl 
)

Free memory allocated by the ArrayBox function.

Parameters
[in]tpointer to an allocated memory area
[in]nrlstarting index of the array for the 3rd dimension
[in]nclstarting index of the array for the 2nd dimension
[in]ndlstarting index of the array for the 1st dimension
void FreeArrayBoxMap ( double ***  t,
int  nrl,
int  nrh,
int  ncl,
int  nch,
int  ndl,
int  ndh 
)

Free memory allocated with the ArrayBoxMap () function

void FreeArrayMap ( double ***  t)

Free memory allocate with ArrayMap()