/* * Interpolate.java * * Created on March 15, 2005, 9:00 AM */ package org.das2.math; /** * * @author Jeremy */ public class Interpolate { public interface DDoubleArray { double get( int i, int j ); void put( int i, int j, double value ); int rows(); int columns(); } public interface FDoubleArray { float get( int i, int j ); void put( int i, int j, float value ); int rows(); int columns(); } public static DDoubleArray newDDoubleArray( final double[][] array ) { return new DDoubleArray() { public double get( int i, int j ) { return array[i][j]; } public void put( int i, int j, double value ) { array[i][j]= value; }; public int rows() { return array.length; } public int columns() { return array[0].length; } }; } public static DDoubleArray newDDoubleArray( int columns, int rows ) { return new DDoubleArrayImpl( columns, rows ); } private static final class DDoubleArrayImpl implements DDoubleArray { // return DDoubleArray backed by single array, storing the double array column major. double[] back; int rows; // index by i int columns; static final boolean boundsCheck= false; DDoubleArrayImpl( int columns, int rows ) { back= new double[ rows * columns ]; this.columns= columns; this.rows= rows; } public double get( int i, int j ) { if ( boundsCheck ) { if ( i>=rows ) throw new ArrayIndexOutOfBoundsException("index i="+i+" out of bounds"); if ( i<0 ) throw new ArrayIndexOutOfBoundsException("index i="+i+" out of bounds"); if ( j>=columns ) throw new ArrayIndexOutOfBoundsException("index j="+j+" out of bounds"); } return back[ j*rows + i ]; } public void put( int i, int j, double value ) { if ( boundsCheck ) { if ( i>=rows ) throw new ArrayIndexOutOfBoundsException("index i="+i+" out of bounds"); if ( i<0 ) throw new ArrayIndexOutOfBoundsException("index i="+i+" out of bounds"); if ( j>=columns ) throw new ArrayIndexOutOfBoundsException("index j="+j+" out of bounds"); } back[ j*rows + i ]= value; }; public int rows() { return rows; } public int columns() { return columns; } } public static DDoubleArray interpolate2( DDoubleArray source, float[] xFindex, float[] yFindex ) { DDoubleArray result= newDDoubleArray( xFindex.length, yFindex.length ); double[] xfp0= new double[xFindex.length]; double[] xfp1= new double[xFindex.length]; int[] xip0= new int[xFindex.length]; int[] xip1= new int[xFindex.length]; for ( int i=0; i