// Calculate weighting matrix
this.calcWeights();
// order data
ArrayMaths am = new ArrayMaths(x1);
am = am.sort();
this.x1indices = am.originalIndices();
x1 = am.array();
double[][][] hold = new double[lPoints][mPoints][nPoints];
double[][][] hold1 = null;
double[][][] hold2 = null;
double[][][] hold12 = null;
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
hold[i][j][k] = y[this.x1indices[i]][j][k];
}
}
}
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
y[i][j][k] = hold[i][j][k];
}
}
}
if(flag){
hold1 = new double[lPoints][mPoints][nPoints];
hold2 = new double[lPoints][mPoints][nPoints];
hold12 = new double[lPoints][mPoints][nPoints];
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
hold1[i][j][k] = dydx1[this.x1indices[i]][j][k];
hold2[i][j][k] = dydx2[this.x1indices[i]][j][k];
hold12[i][j][k] = d2ydx1dx2[this.x1indices[i]][j][k];
}
}
}
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
dydx1[i][j][k] = hold1[i][j][k];
dydx2[i][j][k] = hold2[i][j][k];
d2ydx1dx2[i][j][k] = hold12[i][j][k];
}
}
}
}
am = new ArrayMaths(x2);
am = am.sort();
this.x2indices = am.originalIndices();
x2 = am.array();
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
hold[i][j][k] = y[i][this.x2indices[j]][k];
}
}
}
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
y[i][j][k] = hold[i][j][k];
}
}
}
if(flag){
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
hold1[i][j][k] = dydx1[i][this.x2indices[j]][k];
hold2[i][j][k] = dydx2[i][this.x2indices[j]][k];
hold12[i][j][k] = d2ydx1dx2[i][this.x2indices[j]][k];
}
}
}
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
dydx1[i][j][k] = hold1[i][j][k];
dydx2[i][j][k] = hold2[i][j][k];
d2ydx1dx2[i][j][k] = hold12[i][j][k];
}
}
}
}
am = new ArrayMaths(x3);
am = am.sort();
this.x3indices = am.originalIndices();
x3 = am.array();
for(int i=0; i<lPoints; i++){
for(int j=0; j<mPoints; j++){
for(int k=0; k<nPoints; k++){
hold[i][j][k] = y[i][j][this.x3indices[k]];