public class Sharc2DPolynomialFit extends LinearCoefficientFit {
    int order = 0;
    double[][] term, aterm;
    double[] bolIndex;

    public Sharc2DPolynomialFit(int nOrder) { 
	super((nOrder+1)*(nOrder+2)/2); 
	order = nOrder;

	double[] x = new double[order + 1];
	double[] y = new double[order + 1];
	
	term = new double[32*12][parameter.length];
	aterm = new double[32*12][parameter.length];
	bolIndex = new double[32*12];

	for(int bol=0; bol<384; bol++) {
	    bolIndex[bol] = bol;
	    term[bol][0] = 1.0;
	    aterm[bol][0] = 1.0;
	    x[0] = 1.0;
	    y[0] = 1.0;
	    
	    double dx = bol%32 - 15.5;
	    double dy = bol/32 - 5.5;

	    for(int p=1, i=1; p <= order; p++) {
		x[p] = x[p-1] * dx;
		y[p] = y[p-1] * dy;
		
		for(int px=p, py=0; px >= 0; px--, py++, i++) {
		    term[bol][i] = x[px] * y[py]; 
		    aterm[bol][i] = Math.abs(term[bol][i]);
		}
	    }
	}
    }

    public void fit(double y[], double sigma[]) throws IllegalStateException {
	super.fit(bolIndex, y, sigma);
    }

    public double[] getTerms(double bol) { return term[(int)bol]; }
}
