Commit 4240e667 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

So, the value I had though was the object id is not. Fix.

In the third segment, it appeared that there was an object id, related back
to the object id given in a structure.  However, this is not true at all, as
MATLAB will randomly decide what values go here.  However, the index into this
segment seems to be the actual object id.  Thus switch to using that value.
The meaning of the other field is left for someone else to divine, it isn't
important here.
parent 74e040b5
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -505,6 +505,7 @@ public class MatFileReader
        if (mcosDataBuf.getLong() != 0 || mcosDataBuf.getLong() != 0 || mcosDataBuf.getLong() != 0) {
            throw new IllegalStateException("MAT file's MCOS data has different byte values for unknown fields!  Aborting!");
        }
        int objectCount = 1;
        while (mcosDataBuf.position() < segmentIndexes[3]) {
            // First fetch the data.
            int classIndex = mcosDataBuf.getInt();
@@ -513,7 +514,10 @@ public class MatFileReader
            }
            int segment2Index = mcosDataBuf.getInt();
            int segment4Index = mcosDataBuf.getInt();
            int objectId = mcosDataBuf.getInt();
            mcosDataBuf.getInt(); // This value is random.  But we need to move the buffer forward, so read it without a check.
            int objectId = objectCount++;   // It would appear that the "objectId" is in fact some other MATLAB value.  Thus ignore,
                                        // and use the index into this segment as the id instead.

            // Then parse it into the form needed for the object.

            MatMCOSObjectInformation objHolder = objectInfoList.get(objectId - 1);
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import ca.mjdsystems.jmatio.io.MatFileFilter;
import ca.mjdsystems.jmatio.io.MatFileReader;
import ca.mjdsystems.jmatio.io.MatFileType;
import ca.mjdsystems.jmatio.io.SimulinkDecoder;
import ca.mjdsystems.jmatio.types.MLObject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -16,6 +17,7 @@ import org.junit.runners.JUnit4;
import java.io.*;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

/** This test verifies that ReducedHeader generated mat files work correctly.
@@ -33,6 +35,11 @@ public class SimulinkMatTest
    {
        File file = fileFromStream("/simulink_tet_out.mat");
        MatFileReader reader = new MatFileReader(file, new MatFileFilter(), MatFileType.ReducedHeader);
        MLObject data = (MLObject)reader.getContent().get("@");

        // First check that the root element is correct.
        assertThat(data, is(notNullValue()));
        assertThat(data.getClassName(), is("Data"));
    }

    // This just ensures the SimulinkDecoder actually decodes correctly.