git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5835 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
146
src/memory.cpp
146
src/memory.cpp
@ -84,149 +84,3 @@ void Memory::fail(const char *name)
|
||||
sprintf(str,"Cannot create/grow a vector/array of pointers for %s",name);
|
||||
error->one(str);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
older routines, will be deprecated at some point
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a 2d double array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double **Memory::create_2d_double_array(int n1, int n2, const char *name)
|
||||
|
||||
{
|
||||
double *data = (double *) smalloc(n1*n2*sizeof(double),name);
|
||||
double **array = (double **) smalloc(n1*sizeof(double *),name);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < n1; i++) {
|
||||
array[i] = &data[n];
|
||||
n += n2;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 2d double array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Memory::destroy_2d_double_array(double **array)
|
||||
|
||||
{
|
||||
if (array == NULL) return;
|
||||
sfree(array[0]);
|
||||
sfree(array);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1st dim of a 2d double array
|
||||
last dim must stay the same
|
||||
if either dim is 0, return NULL
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double **Memory::grow_2d_double_array(double **array,
|
||||
int n1, int n2, const char *name)
|
||||
|
||||
{
|
||||
if (array == NULL) return create_2d_double_array(n1,n2,name);
|
||||
|
||||
double *data = (double *) srealloc(array[0],n1*n2*sizeof(double),name);
|
||||
array = (double **) srealloc(array,n1*sizeof(double *),name);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < n1; i++) {
|
||||
array[i] = &data[n];
|
||||
n += n2;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a 2d int array
|
||||
if either dim is 0, return NULL
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int **Memory::create_2d_int_array(int n1, int n2, const char *name)
|
||||
|
||||
{
|
||||
if (n1 == 0 || n2 == 0) return NULL;
|
||||
|
||||
int *data = (int *) smalloc(n1*n2*sizeof(int),name);
|
||||
int **array = (int **) smalloc(n1*sizeof(int *),name);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < n1; i++) {
|
||||
array[i] = &data[n];
|
||||
n += n2;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 2d int array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Memory::destroy_2d_int_array(int **array)
|
||||
|
||||
{
|
||||
if (array == NULL) return;
|
||||
sfree(array[0]);
|
||||
sfree(array);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1st dim of a 2d int array
|
||||
last dim must stay the same
|
||||
if either dim is 0, return NULL
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int **Memory::grow_2d_int_array(int **array, int n1, int n2, const char *name)
|
||||
|
||||
{
|
||||
if (n1 == 0 || n2 == 0) {
|
||||
destroy_2d_int_array(array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (array == NULL) return create_2d_int_array(n1,n2,name);
|
||||
|
||||
int *data = (int *) srealloc(array[0],n1*n2*sizeof(int),name);
|
||||
array = (int **) srealloc(array,n1*sizeof(int *),name);
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < n1; i++) {
|
||||
array[i] = &data[n];
|
||||
n += n2;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
create a 2d double array with 2nd index from n2lo to n2hi inclusive
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double **Memory::create_2d_double_array(int n1, int n2lo, int n2hi,
|
||||
const char *name)
|
||||
{
|
||||
int n2 = n2hi - n2lo + 1;
|
||||
double **array = create_2d_double_array(n1,n2,name);
|
||||
|
||||
for (int i = 0; i < n1; i++) array[i] -= n2lo;
|
||||
return array;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
free a 2d double array with 2nd index offset
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Memory::destroy_2d_double_array(double **array, int offset)
|
||||
{
|
||||
if (array == NULL) return;
|
||||
sfree(&array[0][offset]);
|
||||
sfree(array);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user