// first line of the file should be the column headers // first column should be the row titles // all other values are expected to be floats // getFloat(0, 0) returns the first data value in the upper lefthand corner // files should be saved as "text, tab-delimited" // empty rows are ignored // extra whitespace is ignored class SeriesGenerator { int rowCount; int columnCount; float[][] data; String[] rowNames; String[] columnNames; SeriesGenerator() { // we are going to generate 3 time series with 100 values each columnCount = 3; rowCount = 100; // create the labels for the x and y axis columnNames = new String[columnCount]; rowNames = new String[rowCount]; for (int i = 0; i < columnCount; i++) { columnNames[i] = "S" + (i + 1); } for (int i = 0; i < rowCount; i++) { rowNames[i] = Integer.toString(i); } // generate the data data = new float[rowCount][columnCount]; for (int i = 0; i < columnCount; i++) { float[] col = new float[columnCount]; col = generateSeries(i); for (int j = 0; j < rowCount; j++) { data[j][i] = col[j]; } } } // This is were the different series are generated. The function // takes an integer that specifies which series we should return. float[] generateSeries( int i ) { float[] series = new float[rowCount]; switch (i) { case 0: for (int j = 0; j < rowCount; j++){ // series 1 here } break; case 1: for (int j = 0; j < rowCount; j++){ // series 2 here } break; case 2: for (int j = 0; j < rowCount; j++){ // series 3 here } break; } return series; } float[] linearFilter(float[] series) { return series; } float[] gaussianFilter(float[] series) { return series; } int getRowCount() { return rowCount; } String getRowName(int rowIndex) { return rowNames[rowIndex]; } String[] getRowNames() { return rowNames; } // Find a row by its name, returns -1 if no row found. // This will return the index of the first row with this name. // A more efficient version of this function would put row names // into a Hashtable (or HashMap) that would map to an integer for the row. int getRowIndex(String name) { for (int i = 0; i < rowCount; i++) { if (rowNames[i].equals(name)) { return i; } } //println("No row named '" + name + "' was found"); return -1; } // technically, this only returns the number of columns // in the very first row (which will be most accurate) int getColumnCount() { return columnCount; } String getColumnName(int colIndex) { return columnNames[colIndex]; } String[] getColumnNames() { return columnNames; } float getFloat(int rowIndex, int col) { // Remove the 'training wheels' section for greater efficiency // It's included here to provide more useful error messages // begin training wheels if ((rowIndex < 0) || (rowIndex >= data.length)) { throw new RuntimeException("There is no row " + rowIndex); } if ((col < 0) || (col >= data[rowIndex].length)) { throw new RuntimeException("Row " + rowIndex + " does not have a column " + col); } // end training wheels return data[rowIndex][col]; } boolean isValid(int row, int col) { if (row < 0) return false; if (row >= rowCount) return false; //if (col >= columnCount) return false; if (col >= data[row].length) return false; if (col < 0) return false; return !Float.isNaN(data[row][col]); } float getColumnMin(int col) { float m = Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { if (!Float.isNaN(data[i][col])) { if (data[i][col] < m) { m = data[i][col]; } } } return m; } float getColumnMax(int col) { float m = -Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { if (isValid(i, col)) { if (data[i][col] > m) { m = data[i][col]; } } } return m; } float getRowMin(int row) { float m = Float.MAX_VALUE; for (int i = 0; i < columnCount; i++) { if (isValid(row, i)) { if (data[row][i] < m) { m = data[row][i]; } } } return m; } float getRowMax(int row) { float m = -Float.MAX_VALUE; for (int i = 1; i < columnCount; i++) { if (!Float.isNaN(data[row][i])) { if (data[row][i] > m) { m = data[row][i]; } } } return m; } float getTableMin() { float m = Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (isValid(i, j)) { if (data[i][j] < m) { m = data[i][j]; } } } } return m; } float getTableMax() { float m = -Float.MAX_VALUE; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (isValid(i, j)) { if (data[i][j] > m) { m = data[i][j]; } } } } return m; } }