Image

Imagejhubert wrote in Imagecpp

Hello, everyone! I'm a phyicist, and during my studies I learned enough C/C++ for my scientific needs, but I never really had much in the way of formal training or in-depth knowledge of the language.

Nethertheless, this knowledge was sufficient to get me hired as a research assistant and Ph.D. student in the field of Computational Materials Science. But now I'm doing little else than programming, and this means I have to catch up on some things fast...

Here is a problem I am currently wrestling with: I know how to create and destroy vectors and matrices of varying sizes depending on what sizes are currently needed within the program. The code I use is the following:

For vectors:

//---------------------------------------------------------------------------
double *dvector(long nl)
{
double *v;
long i;

v = new double[nl+1];
for (i=1;i<=nl;i++) {
v[i] = 0.0;
}
return v;
}
//---------------------------------------------------------------------------
void free_dvector(double *v)
{
delete [] v;
}
//---------------------------------------------------------------------------


For matrices:

//---------------------------------------------------------------------------
double **dmatrix(long nr, long nc)
{
double **m;
long i;
long j;

m = new double*[nr+1];
for (j=1;j<=nr;j++) {
m[j]= new double[nc+1];
for (i=1;i<=nc;i++) {
m[j][i] = 0.0;
}
}
return m;
}
//---------------------------------------------------------------------------
void free_dmatrix(double **m, long nr)
{
long j;

for (j=1;j<=nr;j++) {
delete m[j];
}
delete [] m;
}
//---------------------------------------------------------------------------


The vectors and matrices are created by:

v = dvector(xsize);
m = dmatrix(xsize,ysize);

and deleted by:

free_dvector(v);
free_dmatrix(m, xsize);


Now, what I want to know is if it is possible to extend the same principle to extend the same principle to three dimensions as well?