MCPcopy Index your code
hub / github.com/diffplug/matfilerw / readMatrix

Method readMatrix

src/main/java/com/jmatio/io/MatFileReader.java:859–1241  ·  view source on GitHub ↗

Reads miMATRIX from from input stream. If reading was not finished (which is normal for filtered results) returns null . Modifies buf position to the position when reading finished. Uses recursive processing for some ML data types. @param buf - input byte b

(ByteBuffer buf, boolean isRoot)

Source from the content-addressed store, hash-verified

857 * @throws IOException when error occurs while reading the buffer.
858 */
859 private MLArray readMatrix(ByteBuffer buf, boolean isRoot) throws IOException {
860 //result
861 MLArray mlArray;
862 ISMatTag tag;
863
864 //read flags
865 int[] flags = readFlags(buf);
866 int attributes = (flags.length != 0) ? flags[0] : 0;
867 int nzmax = (flags.length != 0) ? flags[1] : 0;
868 int type = attributes & 0xff;
869
870 //read Array dimension
871 int[] dims = readDimension(buf);
872
873 //read array Name
874 String name = readName(buf, matFileHeader);
875
876 //if this array is filtered out return immediately
877 if (isRoot && !filter.matches(name)) {
878 return null;
879 }
880
881 //read data >> consider changing it to stategy pattern
882 switch (type) {
883 case MLArray.mxSTRUCT_CLASS:
884
885 MLStructure struct = new MLStructure(name, dims, attributes);
886
887 //field name lenght - this subelement always uses the compressed data element format
888 new ISMatTag(buf);
889 int maxlen = buf.getInt(); //maximum field length
890
891 ////// read fields data as Int8
892 tag = new ISMatTag(buf);
893 //calculate number of fields
894 int numOfFields = tag.size / maxlen;
895
896 String[] fieldNames = new String[numOfFields];
897 for (int i = 0; i < numOfFields; i++) {
898 byte[] names = new byte[maxlen];
899 buf.get(names);
900 fieldNames[i] = zeroEndByteArrayToString(names);
901 }
902 buf.position(buf.position() + tag.padding);
903 //read fields
904 for (int index = 0; index < struct.getM() * struct.getN(); index++) {
905 for (int i = 0; i < numOfFields; i++) {
906 //read matrix recursively
907 tag = new ISMatTag(buf);
908
909 MLArray array;
910 if (tag.size > 0) {
911 array = readMatrix(buf, false);
912 } else {
913 array = new MLEmptyArray();
914 }
915 array.name = fieldNames[i];
916 struct.setField(fieldNames[i], array, index);

Callers 1

readDataMethod · 0.95

Calls 15

readFlagsMethod · 0.95
readDimensionMethod · 0.95
readNameMethod · 0.95
getMethod · 0.95
getMMethod · 0.95
getNMethod · 0.95
setMethod · 0.95
readToByteBufferMethod · 0.95
isComplexMethod · 0.95
readToStringMethod · 0.95
setCharMethod · 0.95

Tested by

no test coverage detected