Search in sources :

Example 1 with MatFileIncrementalWriter

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();
}
Also used : AlarmSeverity(org.diirt.vtype.AlarmSeverity) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) ValueIterator(org.csstudio.archive.reader.ValueIterator) MatFileIncrementalWriter(com.jmatio.io.MatFileIncrementalWriter) MLDouble(com.jmatio.types.MLDouble) MLStructure(com.jmatio.types.MLStructure) VType(org.diirt.vtype.VType)

Example 2 with MatFileIncrementalWriter

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();
}
Also used : MLDouble(com.jmatio.types.MLDouble) MLStructure(com.jmatio.types.MLStructure) VType(org.diirt.vtype.VType) MLCell(com.jmatio.types.MLCell) ArchiveVNumber(org.csstudio.archive.vtype.ArchiveVNumber) MatFileIncrementalWriter(com.jmatio.io.MatFileIncrementalWriter)

Example 3 with MatFileIncrementalWriter

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();
}
Also used : MLDouble(com.jmatio.types.MLDouble) MLChar(com.jmatio.types.MLChar) MLArray(com.jmatio.types.MLArray) ArrayList(java.util.ArrayList) MatFileIncrementalWriter(com.jmatio.io.MatFileIncrementalWriter)

Aggregations

MatFileIncrementalWriter (com.jmatio.io.MatFileIncrementalWriter)3 MLDouble (com.jmatio.types.MLDouble)3 MLStructure (com.jmatio.types.MLStructure)2 ArrayList (java.util.ArrayList)2 VType (org.diirt.vtype.VType)2 MLArray (com.jmatio.types.MLArray)1 MLCell (com.jmatio.types.MLCell)1 MLChar (com.jmatio.types.MLChar)1 Instant (java.time.Instant)1 ValueIterator (org.csstudio.archive.reader.ValueIterator)1 ArchiveVNumber (org.csstudio.archive.vtype.ArchiveVNumber)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1 AlarmSeverity (org.diirt.vtype.AlarmSeverity)1