Computational Physics - Department of Physics

(Axel Boer) #1

198 6 Linear Algebra


#ifndefARRAY_H
#defineARRAY_H


#include
#include
#include
#include


using namespacestd;


template
classArray{
private:
static const intMAXDIM = 6;
T*data ; /> One-dimensional array of data.*/
intsize[MAXDIM]; /*> Size of each dimension./
intndim; /
> Number of dimensions occupied.*/
intlength; /*> Total number of entries./
intdx1, dx2, dx3, dx4, dx5;
voidallocate(intni=0,intnj=0,intnk=0,intnl=0,intnm=0,intnn=0){
ndim = MAXDIM;
// Set the number of entries in each dimension.
size[0]=ni;
size[1]=nj;
size[2]=nk;
size[3]=nl;
size[4]=nm;
size[5]=nn;


// Set the number of dimensions used.
if(size[5] == 0)
ndim--;
if(size[4] == 0)
ndim--;
if(size[3] == 0)
ndim--;
if(size[2] == 0)
ndim--;
if(size[1] == 0)
ndim--;
if(size[0] == 0){
ndim = 0;
length = 0;
data = NULL;
}else{
try{
inti;
// Set the length (total number of entries) of the one-dimensional array.
length = 1;
for(i=0; i<ndim; i++)
length*= size[i];
data =newT[length];
dx1 = size[0];
Free download pdf