public class bandec
{
void SWAP(double a,double b)
{double dum=a;a=b;b=dum;}

void SWAP(double a[],double b[])
{double dum[];dum=a;a=b;b=dum;}

void SWAP(double a[][],double b[][])
{double dum[][];dum=a;a=b;b=dum;}

void bandec(double a[][], int m1, int m2, double al[][],
	int indx[], double d)
{   double TINY=1.0e-20;
    int n=a.length;
    int mm=m1+m2+1; 
	int i,j,k,l;
	double dum;
	l=m1;
	for (i=0;i<m1;i++) {
		for (j=m1+2-i;j<mm;j++) a[i][j-l]=a[i][j];
		l--;
		for (j=mm-l;j<mm;j++) a[i][j]=0.0;
	}
	d=1.0;
	l=m1;
	for (k=0;k<n;k++) {
		dum=a[k][1];
		i=k;
		if (l < n) l++;
		for (j=k+1;j<l;j++) {
			if (Math.abs(a[j][1]) > Math.abs(dum)) {
				dum=a[j][1];
				i=j;
			}
		}
		indx[k]=i;
		if (dum == 0.0) a[k][1]=TINY;
		if (i != k) {
			d = -d;
			for (j=0;j<mm;j++) SWAP(a[k][j],a[i][j]);
		}
		for (i=k+1;i<l;i++) {
			dum=a[i][1]/a[k][1];
			al[k][i-k]=dum;
			for (j=1;j<mm;j++) a[i][j-1]=a[i][j]-dum*a[k][j];
			a[i][mm]=0.0;
		}
	}
}
void banbks(float a[][], int m1, int m2, double al[][],
	int indx[], double b[])
{
	int i,k,l;
	int n=a.length;
	int mm;
	double dum;
	mm=m1+m2+1;
	l=m1;
	for (k=0;k<n;k++) {
		i=indx[k];
		if (i != k) SWAP(b[k],b[i]);
		if (l < n) l++;
		for (i=k+1;i<l;i++) b[i] -= al[k][i-k]*b[k];
	}
	l=1;
	for (i=(n-1);i>=0;i--) {
		dum=b[i];
		for (k=1;k<l;k++) dum -= a[i][k]*b[k+i-1];
		b[i]=dum/a[i][1];
		if (l < mm) l++;
	}
}
}
