Parses character-delimited data from a string. This attempts to extract the following information from the string: 1. A title to be used for the tab name 2. One or more columns of double data values 3. Column names for the data columns @param dataString the data string @param fileName name of f
(String dataString, String fileName)
| 85 | * @return DatasetManager with parsed data, or null if none found |
| 86 | */ |
| 87 | public double[][] parseData(String dataString, String fileName) { |
| 88 | BufferedReader input = new BufferedReader(new StringReader(dataString)); |
| 89 | String gnuPlotComment = "#"; //$NON-NLS-1$ |
| 90 | try { |
| 91 | String textLine = input.readLine(); |
| 92 | for(int i = 0; i<DataFile.delimiters.length; i++) { |
| 93 | ArrayList<double[]> rows = new ArrayList<double[]>(); |
| 94 | int columns = Integer.MAX_VALUE; |
| 95 | String[] columnNames = null; |
| 96 | String title = null; |
| 97 | int lineCount = 0; |
| 98 | while(textLine!=null) { // process each line of text |
| 99 | // look for gnuPlot-commented name and/or columnNames |
| 100 | if(textLine.contains(gnuPlotComment)) { |
| 101 | textLine = textLine.trim(); |
| 102 | } |
| 103 | if(textLine.startsWith(gnuPlotComment)) { |
| 104 | int k = textLine.indexOf("name:"); //$NON-NLS-1$ |
| 105 | if(k>-1) { |
| 106 | title = textLine.substring(k+5).trim(); |
| 107 | } |
| 108 | k = textLine.indexOf("columnNames:"); //$NON-NLS-1$ |
| 109 | if(k>-1) { |
| 110 | textLine = textLine.substring(k+12).trim(); |
| 111 | } else { |
| 112 | textLine = input.readLine(); |
| 113 | continue; |
| 114 | } |
| 115 | } |
| 116 | // skip Vernier Format 2 header lines |
| 117 | if((textLine.indexOf("Vernier Format")>-1 //$NON-NLS-1$ |
| 118 | )||(textLine.indexOf(".cmbl")>-1)) { //$NON-NLS-1$ |
| 119 | textLine = input.readLine(); |
| 120 | continue; |
| 121 | } |
| 122 | String[] strings = DataFile.parseStrings(textLine, DataFile.delimiters[i]); |
| 123 | double[] rowData = DataFile.parseDoubles(strings); |
| 124 | // set null title if String[] length > 0, all entries |
| 125 | // are NaN and only one entry is not "" |
| 126 | if(rows.isEmpty()&&(strings.length>0)&&(title==null)) { |
| 127 | String s = ""; //$NON-NLS-1$ |
| 128 | for(int k = 0; k<strings.length; k++) { |
| 129 | if(Double.isNaN(rowData[k])&&!strings[k].equals("")) { //$NON-NLS-1$ |
| 130 | if(s.equals("")) { //$NON-NLS-1$ |
| 131 | s = strings[k]; |
| 132 | } else { |
| 133 | s = ""; //$NON-NLS-1$ |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | if(!s.equals("")) { //$NON-NLS-1$ |
| 139 | title = s; |
| 140 | textLine = input.readLine(); |
| 141 | continue; |
| 142 | } |
| 143 | } |
| 144 | // set null column names if String[] length > 0, |
no test coverage detected