use of com.jmatio.io.MatFileIncrementalWriter in project org.csstudio.display.builder by kasemir.
the class MatlabFileExportJob method performExport.
/**
* {@inheritDoc}
*/
@Override
protected void performExport(final IProgressMonitor monitor, final PrintStream out) throws Exception {
// This exporter does its own file handling
if (out != null)
throw new IllegalStateException();
final MatFileIncrementalWriter writer = new MatFileIncrementalWriter(filename);
int i = 0;
for (ModelItem item : model.getItems()) {
// Get data
monitor.subTask(NLS.bind("Fetching data for {0}", item.getName()));
final ValueIterator iter = createValueIterator(item);
final List<Instant> times = new ArrayList<Instant>();
final List<Double> values = new ArrayList<Double>();
final List<AlarmSeverity> severities = new ArrayList<AlarmSeverity>();
while (iter.hasNext() && !monitor.isCanceled()) {
final VType value = iter.next();
times.add(VTypeHelper.getTimestamp(value));
values.add(VTypeHelper.toDouble(value));
severities.add(VTypeHelper.getSeverity(value));
if (values.size() % PROGRESS_UPDATE_LINES == 0)
monitor.subTask(NLS.bind("{0}: Obtained {1} samples", item.getName(), values.size()));
}
// Add to Matlab file
final MLStructure struct = createMLStruct(i++, item.getName(), times, values, severities);
writer.write(struct);
}
writer.close();
}
use of com.jmatio.io.MatFileIncrementalWriter in project org.csstudio.display.builder by kasemir.
the class JMatioDemo method writeMatlabFile2.
public void writeMatlabFile2() throws Exception {
// Example values
final VType[] values = new VType[10];
for (int i = 0; i < 10; ++i) values[i] = new ArchiveVNumber(VTypeHelper.getTimestamp(null), AlarmSeverity.NONE, "OK", ValueFactory.displayNone(), Math.exp(-((5.0 - i) * (5.0 - i))));
// Turn values into Matlab data
final int[] dims = new int[] { values.length, 1 };
final MLDouble value = new MLDouble(null, dims);
final MLCell time = new MLCell(null, dims);
final MLCell severity = new MLCell(null, dims);
final MLCell status = new MLCell(null, dims);
for (int i = 0; i < values.length; ++i) {
value.set(VTypeHelper.toDouble(values[i]), i);
setCellText(time, i, TimestampHelper.format(VTypeHelper.getTimestamp(values[i])));
setCellText(severity, i, VTypeHelper.getSeverity(values[i]).toString());
setCellText(severity, i, VTypeHelper.getMessage(values[i]));
}
final MLStructure struct = new MLStructure("channel0", new int[] { 1, 1 });
struct.setField("value", value);
struct.setField("time", time);
struct.setField("severity", severity);
struct.setField("status", status);
// Write to file
final MatFileIncrementalWriter writer = new MatFileIncrementalWriter("mat_file2.mat");
writer.write(struct);
writer.close();
}
use of com.jmatio.io.MatFileIncrementalWriter in project org.csstudio.display.builder by kasemir.
the class JMatioDemo method writeMatlabFile1.
public void writeMatlabFile1() throws Exception {
// 1. First create example arrays
double[] src = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
MLDouble mlDouble = new MLDouble("double_arr", src, 2);
MLChar mlChar = new MLChar("char_arr", "I am dummy");
// 2. write arrays to file
ArrayList<MLArray> list = new ArrayList<MLArray>();
list.add(mlDouble);
list.add(mlChar);
MatFileIncrementalWriter writer = new MatFileIncrementalWriter("mat_file.mat");
writer.write(mlDouble);
writer.write(mlChar);
writer.close();
}
Aggregations