Commit 3b5d9fd2 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Generalize MCOS object arrays to properties.

Support MCOS object arrays in MCOS object properties.  Also adds some tests
to the TET test to ensure that data was properly pulled out.
parent aff2d006
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,9 +12,9 @@ import java.util.Arrays;
 * @author Matthew Dawson <matthew@mjdsystems.ca>
 */
class MLObjectPlaceholder extends MLArray {
    MLObjectPlaceholder(String name, String className, int[] dims, int[][] information)
    MLObjectPlaceholder(String name, String className, int[][] information)
    {
        super( name, dims, -1, 0 );
        super( name, new int[]{information[2][0], information[3][0]}, -1, 0 );
        this.className = className;
        this.information = information;

+19 −15
Original line number Diff line number Diff line
@@ -558,10 +558,9 @@ public class MatFileReader
                }
                if (property instanceof MLUInt32) {
                    int[][] data = ((MLUInt32) property).getArray();
                    if (data[0][0] == 0xdd000000 && data[1][0] == 0x02 && data[2][0] == 0x01 && data[3][0] == 0x01) {
                        MatMCOSObjectInformation objectInformation = objectInfoList.get(data[4][0] - 1);
                        property = new MLObject(propertyName, classNamesList.get(objectInformation.classId - 1), new int[]{1, 1}, 0)
                                .setFields(0, objectInformation.structure);
                    if (data[0][0] == 0xdd000000 && data[1][0] == 0x02) {
                        MLObjectPlaceholder objHolder = new MLObjectPlaceholder(propertyName, "", data);
                        property = processMCOS(objHolder, classNamesList, objectInfoList);
                    }
                }
                properties.put(propertyName, property);
@@ -605,9 +604,15 @@ public class MatFileReader
        for (Map.Entry<String, MLArray> it : data.entrySet()) {
            if ( it.getValue() instanceof MLObjectPlaceholder ) {
                MLObjectPlaceholder objHolder = (MLObjectPlaceholder) it.getValue();
                it.setValue(processMCOS(objHolder, classNamesList, objectInfoList));
            }
        }
    }

    private MLObject processMCOS(MLObjectPlaceholder objHolder, List<String> classNamesList, Map<Integer, MatMCOSObjectInformation> objectInfoList)
    {
        int classId = objHolder.classId;
        MLObject obj = new MLObject(objHolder.name, classNamesList.get(classId - 1), objHolder.getDimensions(), 0);
                it.setValue(obj);
        for (int i = 0; i < obj.getSize(); ++i) {
            MatMCOSObjectInformation objectInformation = objectInfoList.get(objHolder.objectIds[i] - 1);
            if (classId != objectInformation.classId) {
@@ -615,8 +620,7 @@ public class MatFileReader
            }
            obj.setFields(i, objectInformation.structure);
        }
            }
        }
        return obj;
    }

    /**
@@ -1209,7 +1213,7 @@ public class MatFileReader
                                throw new IOException("MCOS per-object header was different then expected!  Got: " + content.contentToString());
                            }

                            mlArray = new MLObjectPlaceholder(arrName, className, new int[]{t[2][0], t[3][0]}, t);
                            mlArray = new MLObjectPlaceholder(arrName, className, t);
                            haveMCOS = true;
                        } else { // This is where we get the useful MCOS data.  Only used on FileWrapper__ classes.
                            mlArray = readMatrix(buf, false);
+5 −3
Original line number Diff line number Diff line
@@ -62,11 +62,13 @@ public class SimulinkMatTest
        // Next, verify Grid2, as it is easiest.
        MLObject Grid2 = (MLObject) dataO.get("Grid2");
        assertThat(Grid2.getClassName(), is("Grid"));
        assertThat(Grid2.getSize(), is(1));
        Map<String, MLArray> gridO = Grid2.getFields(0);

        System.out.println(Grid2.getFields(0).get("cells").contentToString());
        System.out.println(Grid2.getFields(0));

        assertThat(((MLDouble) gridO.get("num_cells")).get(0), is(2.0));

        MLObject cells = (MLObject) gridO.get("cells");
        assertThat(cells.getSize(), is(2));
    }

    // This just ensures the SimulinkDecoder actually decodes correctly.