use of edu.cmu.tetrad.data.TimeSeriesData in project tetrad by cmu-phil.
the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.
/**
* Method loadDataSet_TabDelim
*/
private void loadTimeSeriesDataSet() {
// select a file to load using the file chooser
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(this.editor);
// get the file
File file = chooser.getSelectedFile();
Preferences.userRoot().put("fileSaveLocation", file.getParent());
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
StringTokenizer st;
// read in variable name and set up DataSet.
List<Node> variables = new LinkedList<>();
st = new StringTokenizer(in.readLine());
while (st.hasMoreTokens()) {
String name = st.nextToken();
ContinuousVariable var = new ContinuousVariable(name);
variables.add(var);
}
DataSet dataSet = new ColtDataSet(0, variables);
int row = -1;
while ((line = in.readLine()) != null) {
int col = -1;
st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String literal = st.nextToken();
if (literal.length() == 0) {
continue;
}
dataSet.setObject(row, ++col, literal);
}
}
TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
editor.getDataWrapper().setDataModel(dataSet3);
firePropertyChange("modelChanged", null, null);
editor.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations