MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / parseData

Method parseData

src/org/opensourcephysics/tools/DataTool.java:1172–1456  ·  view source on GitHub ↗

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 fi

(String dataString, String fileName)

Source from the content-addressed store, hash-verified

1170 * @return DatasetManager[] with parsed data, or null if none found
1171 */
1172 public static DatasetManager[] parseData(String dataString, String fileName) {
1173 final String gnuPlotComment = "#"; //$NON-NLS-1$
1174 BufferedReader input = null;
1175 // if dataString is a file path then return null
1176 if (new File(dataString).exists())
1177 return null;
1178 // if datastring is XML, return null
1179 if (dataString.trim().startsWith("<?xml"))
1180 return null;
1181 // if datastring is XMLControl code, return null
1182 if (dataString.trim().startsWith("<object class="))
1183 return null;
1184 try {
1185 for (int i = 0; i < delimiters.length; i++) {
1186 input = new BufferedReader(new StringReader(dataString));
1187 String textLine = input.readLine();
1188 ArrayList<double[]> rows = new ArrayList<double[]>();
1189 int columns = Integer.MAX_VALUE;
1190 String[] columnNames = null;
1191 String title = null;
1192 ArrayList<String> titles = new ArrayList<String>();
1193 boolean isMulti = false;
1194 int lineCount = 0;
1195 int columnStride = -1;
1196 while (textLine != null) {
1197 // process each line of text
1198 if (textLine.startsWith("//")) { //$NON-NLS-1$
1199 // ignore comments (lines starting with "//")
1200 textLine = input.readLine();
1201 continue;
1202 }
1203 if (textLine.contains(gnuPlotComment)) {
1204 // trim gnuPlot comments
1205 textLine = textLine.trim(); // added by W. Christian
1206 }
1207 // look for gnuPlot-commented name and/or columnNames
1208 // or multitrack hint
1209 if (textLine.startsWith(gnuPlotComment)) {
1210 int k = textLine.indexOf("name:"); //$NON-NLS-1$
1211 if (k > -1) {
1212 title = textLine.substring(k + 5).trim();
1213 }
1214 k = textLine.indexOf("columnNames:"); //$NON-NLS-1$
1215 if (k > -1) {
1216 textLine = textLine.substring(k + 12).trim();
1217 }
1218 k = textLine.indexOf("multi:"); //$NON-NLS-1$
1219 if (k > -1) {
1220 textLine = textLine.substring(k + 6).trim();
1221 isMulti = true;
1222 if (textLine.length() == 0) {
1223 textLine = input.readLine();
1224 continue;
1225 }
1226 } else {
1227 textLine = input.readLine();
1228 continue;
1229 }

Callers 7

setDelimitedDataMethod · 0.95
openMethod · 0.95
loadDatasetMethod · 0.95
importFileIntoTabMethod · 0.95
pasteActionMethod · 0.95
isPastableDataMethod · 0.95
actionPerformedMethod · 0.95

Calls 15

parseStringsMethod · 0.95
parseDoublesMethod · 0.95
containsDelimeterMethod · 0.95
getRowArrayMethod · 0.95
getNameMethod · 0.95
setXYColumnNamesMethod · 0.95
setXColumnVisibleMethod · 0.95
appendMethod · 0.95
finestMethod · 0.95
existsMethod · 0.80
lengthMethod · 0.80
isNaNMethod · 0.80

Tested by

no test coverage detected