import java.io.*; import java.util.*; public class FunctionFromTable { // data members int numPoints; double[] x; double[] y; double yScale; // constructors public FunctionFromTable(String file) { final int MAXPOINTS = 1000; x = new double[MAXPOINTS]; y = new double[MAXPOINTS]; this.readData(file); // sets x[], y[], numPoints yScale = 1; } // Allow for scaling (dividing) all y values by yScale public FunctionFromTable(String file, double yScale) { this(file); for (int i=0; i exit } // Read in line from input file and assign values to array elements boolean readLines = true; int n = 0; // index of line while ( readLines ) { // try to read a line String s; try { s = br.readLine(); } catch (IOException ioe) { System.out.println("Cannot read line " + ioe); s = null; } readLines = (s != null); if ( readLines ) { boolean useLine = !( s.startsWith("!") || s.startsWith("#") ); if ( useLine ) { // parse line, put values into buffer StringTokenizer st = new StringTokenizer(s); double[] buffer = new double[MAXCOL]; int column = 0; while (st.hasMoreTokens()) { String token = st.nextToken(); buffer[column] = Double.parseDouble(token); column++; } // here only using first two columns x[n] = buffer[0]; y[n] = buffer[1]; n++; } } } // end of loop reading lines numPoints = n; // close up try { br.close(); } catch (IOException e){ System.out.println ("Cannot close buffered reader " + e); return; // ----------------------------------> exit } } // end of readData } // end of class FunctionFromTable