33 #define NONZERO_INITIALIZE YES
62 free ((
char *) m[0][0]);
73 free ((
char *) m[0][0][0]);
74 free ((
char *) m[0][0]);
92 v = (
char *) malloc (nx*dsize);
93 PlutoError (!v,
"Allocation failure in Array1D");
96 #if NONZERO_INITIALIZE == YES
97 if (dsize==
sizeof(
double)){
101 for (i = nx; i--; ) q[i] = i*1.e18 - 1.e16;
124 m = (
char **)malloc ((
size_t) nx*
sizeof(
char *));
125 PlutoError (!m,
"Allocation failure in Array2D (1)");
126 m[0] = (
char *) malloc ((
size_t) nx*ny*dsize);
127 PlutoError (!m[0],
"Allocation failure in Array2D (2)");
129 for (i = 1; i < nx; i++) m[i] = m[(i - 1)] + ny*dsize;
133 #if NONZERO_INITIALIZE == YES
134 if (dsize==
sizeof(
double)){
140 q[
i][
j] = i*j*1.e18 + 1.e16*
j;
149 char ***
Array3D (
int nx,
int ny,
int nz,
size_t dsize)
166 m = (
char ***) malloc ((
size_t) nx*
sizeof (
char **));
167 PlutoError (!m,
"Allocation failure in Array3D (1)");
169 m[0] = (
char **) malloc ((
size_t) nx*ny*
sizeof(
char *));
170 PlutoError (!m[0],
"Allocation failure in Array3D (2)");
172 m[0][0] = (
char *) malloc ((
size_t) nx*ny*nz*dsize);
173 PlutoError (!m[0][0],
"Allocation failure in Array3D (3)");
179 for (i = 1; i < nx; i++) m[i] = m[i - 1] + ny;
188 for (j = 1; j < ny; j++) m[0][j] = m[0][j - 1] + nz*dsize;
189 for (i = 1; i < nx; i++) m[i][0] = m[i - 1][0] + ny*nz*dsize;
191 for (i = 1; i < nx; i++) {
192 for (j = 1; j < ny; j++) {
193 m[
i][
j] = m[
i][j - 1] + nz*dsize;
196 for (j = 0; j < ny; j++){
197 for (i = 0; i < nx; i++){
198 if (m[i][j] == NULL){
199 print (
"! Allocation failure in Array3D\n");
206 #if NONZERO_INITIALIZE == YES
207 if (dsize==
sizeof(
double)){
214 q[
i][
j][
k] = 1.e18*i + 1.e17*j + 1.e16*k + 1.e15;
222 char ****
Array4D (
int nx,
int ny,
int nz,
int nv,
size_t dsize)
240 m = (
char ****) malloc ((
size_t) nx*
sizeof (
char ***));
241 PlutoError (!m,
"Allocation failure in Array4D (1)");
243 m[0] = (
char ***) malloc ((
size_t) nx*ny*
sizeof (
char **));
244 PlutoError (!m[0],
"Allocation failure in Array4D (2)");
246 m[0][0] = (
char **) malloc ((
size_t) nx*ny*nz*
sizeof (
char *));
247 PlutoError (!m[0][0],
"Allocation failure in Array4D (3)");
249 m[0][0][0] = (
char *) malloc ((
size_t) nx*ny*nz*nv*dsize);
250 PlutoError (!m[0][0][0],
"Allocation failure in Array4D (4)");
256 for (i = 1; i < nx; i++) m[i] = m[i - 1] + ny;
265 for (i = 1; i < nx; i++) {
266 m[
i][0] = m[i - 1][0] + ny*nz;
268 for (j = 1; j < ny; j++) {
269 m[0][
j] = m[0][j - 1] + nz;
272 for (i = 1; i < nx; i++) {
273 for (j = 1; j < ny; j++) {
274 m[
i][
j] = m[
i][j - 1] + nz;
285 for (i = 1; i < nx; i++) {
286 m[
i][0][0] = m[i - 1][0][0] + ny*nz*nv*dsize;
288 for (j = 1; j < ny; j++) {
289 m[0][
j][0] = m[0][j - 1][0] + nz*nv*dsize;
292 for (k = 1; k < nz; k++) {
293 m[0][0][
k] = m[0][0][k - 1] + nv*dsize;
297 for (i = 1; i < nx; i++) {
298 for (j = 1; j < ny; j++) {
299 m[
i][
j][0] = m[
i][j - 1][0] + nz*nv*dsize;
302 for (i = 1; i < nx; i++) {
303 for (k = 1; k < nz; k++) {
304 m[
i][0][
k] = m[
i][0][k - 1] + nv*dsize;
307 for (j = 1; j < ny; j++) {
308 for (k = 1; k < nz; k++) {
309 m[0][
j][
k] = m[0][
j][k - 1] + nv*dsize;
312 for (i = 1; i < nx; i++) {
313 for (j = 1; j < ny; j++) {
314 for (k = 1; k < nz; k++) {
315 m[
i][
j][
k] = m[
i][
j][k - 1] + nv*dsize;
322 #if NONZERO_INITIALIZE == YES
323 if (dsize==
sizeof(
double)){
331 q[
i][
j][
k][l] = l*1.e18*i + 1.e17*i*j - 1.e16*k*j + 1.e17;
338 #undef NONZERO_INITIALIZE
342 long int ncl,
long int nch,
343 long int ndl,
long int ndh)
361 long i,
j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
366 t=(
double ***) malloc((
unsigned int)(nrow*
sizeof(
double**)));
368 print (
"! ArrayBox: allocation failure (1)\n");
375 t[nrl]=(
double **) malloc((
unsigned int)(nrow*ncol*
sizeof(
double*)));
377 print (
"! ArrayBox: allocation failure (2)\n");
384 t[nrl][ncl]=(
double *) malloc((
unsigned int)(nrow*ncol*ndep*
sizeof(double)));
386 print (
"! ArrayBox: allocation failure (3)\n");
391 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
392 for(i=nrl+1;i<=nrh;i++) {
394 t[
i][ncl]=t[i-1][ncl]+ncol*ndep;
395 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
414 free((
char *) (t[nrl][ncl]+ndl));
415 free((
char *) (t[nrl]+ncl));
416 free((
char *) (t+nrl));
421 double ***
ArrayMap(
int nx,
int ny,
int nz,
double *uptr)
442 t = (
double ***) malloc((
size_t)((nx)*
sizeof(
double**)));
444 print (
"! ArrayMap: allocation failure (1) \n");
450 t[0] = (
double **) malloc((
size_t)((nx*ny)*
sizeof(
double*)));
452 print (
"! ArrayMap: allocation failure (2) \n");
460 print (
"! ArrayMap: allocation failure (3) \n");
464 for(j = 1; j < ny; j++) t[0][j]=t[0][j-1] + nz;
466 for(i = 1; i < nx; i++) {
468 t[
i][0] = t[i-1][0] + ny*nz;
469 for(j = 1; j < ny; j++) t[i][j] = t[i][j-1] + nz;
476 unsigned char ***
ArrayCharMap(
int nx,
int ny,
int nz,
unsigned char *uptr)
484 t = (
unsigned char ***) malloc((
size_t)((nx)*
sizeof(
unsigned char**)));
486 print (
"! ArrayCharMap: allocation failure (1) \n");
492 t[0] = (
unsigned char **) malloc((
size_t)((nx*ny)*
sizeof(
unsigned char*)));
494 print (
"! ArrayCharMap: allocation failure (2) \n");
502 print (
"! ArrayCharMap: allocation failure (3) \n");
506 for(j = 1; j < ny; j++) t[0][j]=t[0][j-1] + nz;
508 for(i = 1; i < nx; i++) {
510 t[
i][0] = t[i-1][0] + ny*nz;
511 for(j = 1; j < ny; j++) t[i][j] = t[i][j-1] + nz;
539 int ndl,
int ndh,
double *uptr)
547 int i,
j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
552 t = (
double ***) malloc((
size_t)((nrow)*
sizeof(
double**)));
554 print (
"! ArrayBoxMap: allocation failure (1) \n");
561 t[nrl] = (
double **) malloc((
size_t)((nrow*ncol)*
sizeof(
double*)));
563 print (
"! ArrayBoxMap: allocation failure (2) \n");
570 print (
"! ArrayBoxMap: allocation failure (3) \n");
575 for(j = ncl+1; j <= nch; j++) t[nrl][j] = t[nrl][j-1] + ndep;
576 for(i = nrl+1; i <= nrh; i++) {
577 t[
i] = t[i-1] + ncol;
578 t[
i][ncl] = t[i-1][ncl] + ncol*ndep;
579 for(j = ncl+1; j <= nch; j++) t[i][j] = t[i][j-1] + ndep;
594 free((
char*) (t[nrl]+ncl));
595 free((
char*) (t+nrl));
void FreeArray1D(void *v)
char **** Array4D(int nx, int ny, int nz, int nv, size_t dsize)
void FreeArrayBox(double ***t, long nrl, long ncl, long ndl)
double *** ArrayBox(long int nrl, long int nrh, long int ncl, long int nch, long int ndl, long int ndh)
void FreeArrayMap(double ***t)
char * Array1D(int nx, size_t dsize)
unsigned char *** ArrayCharMap(int nx, int ny, int nz, unsigned char *uptr)
void FreeArrayCharMap(unsigned char ***t)
void print(const char *fmt,...)
void PlutoError(int, char *)
char ** Array2D(int nx, int ny, size_t dsize)
double *** ArrayBoxMap(int nrl, int nrh, int ncl, int nch, int ndl, int ndh, double *uptr)
void FreeArray3D(void ***m)
void FreeArrayBoxMap(double ***t, int nrl, int nrh, int ncl, int nch, int ndl, int ndh)
void FreeArray4D(void ****m)
char *** Array3D(int nx, int ny, int nz, size_t dsize)
void FreeArray2D(void **m)
#define QUIT_PLUTO(e_code)
long int g_usedMemory
Amount of used memory in bytes.
double *** ArrayMap(int nx, int ny, int nz, double *uptr)