Commit e8b47c46 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Make sure fields names are properly set.

Due to the way MATLAB stores field names for structures, individual items
in the structure don't have names.  Thus, one must use the field name.  Fix
the grab bag parsing to do this correctly, and add a test to verify correct
behaviour.
parent bf24d775
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -532,11 +532,12 @@ public class MatFileReader
        // Finally, merge in attributes from the global grab bag.
        MLCell attribBag = (MLCell) mcosInfo.get(mcosInfo.getSize() -1); // Get the grab bag.
        for (MatMCOSObjectInformation it : objectInfoList.values()) {
            Collection<MLArray> attributes = ((MLStructure) attribBag.get(it.classId)).getAllFields();
            MLStructure attributes = (MLStructure) attribBag.get(it.classId);
            Collection<String> attributeNames = attributes.getFieldNames();
            MLStructure objAttributes = it.structure;
            for (MLArray attribute : attributes) {
                if (objAttributes.getField(attribute.getName()) == null) {
                    objAttributes.setField(attribute.getName(), attribute);
            for (String attributeName : attributeNames) {
                if (objAttributes.getField(attributeName) == null) {
                    objAttributes.setField(attributeName, attributes.getField(attributeName));
                }
            }
        }
+2 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ public class MatlabMCOSTest {

        MLChar field = (MLChar) fields.toArray()[0];
        assertThat(field.getString(0), is("Default text"));

        assertThat(obj.getObject().getFieldNames().iterator().next(), is("test_text"));
    }

    private File fileFromStream(String location) throws IOException