Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: HebiRobotics/MFL
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: diffplug/MFL
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 153 files changed
  • 1 contributor

Commits on Nov 14, 2018

  1. Release 0.2 (#19)

    * Moved `common.util` to `mat.util`
    * Removed unused utilities
    * Removed multi-release jar dependency due to lack of support for some build tools (e.g. obfuscation)
    * Improved streaming file sink implementation
    * Changed `StreamingDoubleMatrix2D` to be a test example
    * `MatFile` API
    ** Renamed `size()` to `getNumEntries()`
    ** Added `clear()`
    ** Added `getEntries()` for accessing `Iterable<NamedArray>`
    ennerf authored Nov 14, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6b7cc26 View commit details
Showing with 14,014 additions and 14,692 deletions.
  1. +1 −0 .gitignore
  2. +21 −0 CHANGELOG.adoc
  3. +4 −5 Jenkinsfile
  4. +12 −12 NOTICE
  5. +162 −16 README.adoc
  6. +0 −11 mat-file-io/CHANGELOG.adoc
  7. +0 −201 mat-file-io/LICENSE
  8. +0 −13 mat-file-io/NOTICE
  9. +0 −177 mat-file-io/README.adoc
  10. +0 −327 mat-file-io/pom.xml
  11. +0 −30 mat-file-io/src/main/java/module-info.java
  12. +0 −68 mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeAccess.java
  13. +0 −104 mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeAtomicAccess.java
  14. +0 −142 mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeMemory.java
  15. +0 −133 mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeOrderConverter.java
  16. +0 −104 mat-file-io/src/main/java/us/hebi/matlab/common/memory/NativeRegularAccess.java
  17. +279 −28 pom.xml
  18. +60 −60 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/BufferAllocator.java
  19. +223 −224 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/CharEncoding.java
  20. +53 −53 ...src/main/java/us/hebi/matlab/common/util → src/main/java/us/hebi/matlab/mat/format}/Charsets.java
  21. +266 −259 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5.java
  22. +87 −87 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5ArrayFlags.java
  23. +305 −306 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5File.java
  24. +679 −679 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Reader.java
  25. +63 −63 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Serializable.java
  26. +115 −115 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Subsystem.java
  27. +192 −192 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Tag.java
  28. +307 −307 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5TagStreamer.java
  29. +264 −264 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Type.java
  30. +166 −167 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5WriteUtil.java
  31. +243 −240 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/Mat5Writer.java
  32. +71 −71 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatCell.java
  33. +91 −91 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatChar.java
  34. +71 −71 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatFunction.java
  35. +88 −88 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatJavaObject.java
  36. +157 −157 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatMatrix.java
  37. +55 −55 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatObjectStruct.java
  38. +79 −79 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatOpaque.java
  39. +214 −214 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatSparseCSC.java
  40. +149 −150 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/MatStruct.java
  41. +416 −416 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/McosFileWrapper.java
  42. +84 −84 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/McosObject.java
  43. +205 −205 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/McosReference.java
  44. +42 −42 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/McosRegistry.java
  45. +51 −51 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/NumberStore.java
  46. +220 −228 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/format/UniversalNumberStore.java
  47. +132 −132 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractArray.java
  48. +69 −69 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractCell.java
  49. +147 −147 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractCellBase.java
  50. +102 −102 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractCharBase.java
  51. +114 −109 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractMatFile.java
  52. +91 −91 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractMatFileBase.java
  53. +431 −431 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractMatrixBase.java
  54. +208 −208 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractSink.java
  55. +197 −197 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractSource.java
  56. +72 −72 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractSparse.java
  57. +114 −114 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractStruct.java
  58. +204 −204 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/AbstractStructBase.java
  59. +55 −55 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Array.java
  60. +76 −76 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Cell.java
  61. +52 −52 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Char.java
  62. +31 −31 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/FunctionHandle.java
  63. +36 −36 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/JavaObject.java
  64. +111 −105 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/MatFile.java
  65. +93 −93 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/MatlabType.java
  66. +220 −220 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Matrix.java
  67. +59 −59 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/NamedArray.java
  68. +42 −42 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/ObjectStruct.java
  69. +39 −39 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Opaque.java
  70. +138 −138 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Sink.java
  71. +280 −250 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Sinks.java
  72. +120 −120 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Source.java
  73. +260 −260 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Sources.java
  74. +57 −57 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Sparse.java
  75. +180 −180 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/StringHelper.java
  76. +122 −122 {mat-file-io → }/src/main/java/us/hebi/matlab/mat/types/Struct.java
  77. +104 −104 ...common/memory/CheckArrayBounds.java → src/main/java/us/hebi/matlab/mat/util/ArrayBoundsCheck.java
  78. +53 −53 ...ain/java/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/ByteConverter.java
  79. +62 −76 ...in/java/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/ByteConverters.java
  80. +91 −91 ...io/src/main/java/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/Bytes.java
  81. +146 −146 {mat-file-io/src/main/java/us/hebi/matlab/common → src/main/java/us/hebi/matlab/mat}/util/Casts.java
  82. +152 −152 ...java/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/HeapByteConverter.java
  83. +136 −136 ...main/java/us/hebi/matlab/common → src/main/java/us/hebi/matlab/mat}/util/IndentingAppendable.java
  84. +101 −101 ...io/src/main/java/us/hebi/matlab/common → src/main/java/us/hebi/matlab/mat}/util/PlatformInfo.java
  85. +447 −447 ...o/src/main/java/us/hebi/matlab/common → src/main/java/us/hebi/matlab/mat}/util/Preconditions.java
  86. +77 −77 {mat-file-io/src/main/java/us/hebi/matlab/common → src/main/java/us/hebi/matlab/mat}/util/Tasks.java
  87. +147 −0 src/main/java/us/hebi/matlab/mat/util/Unsafe9R.java
  88. +75 −75 ...main/java/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/UnsafeAccess.java
  89. +122 −122 ...va/us/hebi/matlab/common/memory → src/main/java/us/hebi/matlab/mat/util}/UnsafeByteConverter.java
  90. +62 −62 {mat-file-io → }/src/test/java/us/hebi/matlab/mat/format/Mat5TagStreamerTest.java
  91. +153 −153 {mat-file-io → }/src/test/java/us/hebi/matlab/mat/format/Mat5WriterTest.java
  92. +293 −293 ...e-io/src/test/java/us/hebi/matlab/mat → src/test/java/us/hebi/matlab/mat/tests}/Mat5Examples.java
  93. +407 −407 ...hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/ArrayReadTest.java
  94. +66 −66 ...us/hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/FigureTest.java
  95. +183 −183 ...s/hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/MatTestUtil.java
  96. +287 −287 ...a/us/hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/McosTest.java
  97. +101 −101 .../hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/SimulinkTest.java
  98. +50 −50 ...hebi/matlab/mat/format/mat5test → src/test/java/us/hebi/matlab/mat/tests/mat5}/SubsystemTest.java
  99. +81 −81 ...rmat/experimental → src/test/java/us/hebi/matlab/mat/tests/serialization}/EjmlDMatrixWrapper.java
  100. +98 −98 ...t/experimental → src/test/java/us/hebi/matlab/mat/tests/serialization}/EjmlSerializationTest.java
  101. +123 −123 ...ormat/experimental → src/test/java/us/hebi/matlab/mat/tests/serialization}/EjmlSparseWrapper.java
  102. +167 −167 ...experimental → src/test/java/us/hebi/matlab/mat/tests/serialization}/StreamingDoubleMatrix2D.java
  103. +137 −93 ...rimental → src/test/java/us/hebi/matlab/mat/tests/serialization}/StreamingDoubleMatrix2DTest.java
  104. +156 −156 {mat-file-io → }/src/test/java/us/hebi/matlab/mat/types/SinkTest.java
  105. +113 −113 {mat-file-io → }/src/test/java/us/hebi/matlab/mat/types/SourceTest.java
  106. +294 −295 ...java/us/hebi/matlab/common/memory → src/test/java/us/hebi/matlab/mat/util}/ByteConverterTest.java
  107. +43 −43 ...rc/test/java/us/hebi/matlab/common/memory → src/test/java/us/hebi/matlab/mat/util}/BytesTest.java
  108. +80 −81 ...lab/common/memory/NativeMemoryTest.java → src/test/java/us/hebi/matlab/mat/util/Unsafe9RTest.java
  109. +6 −6 ...t/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/HandleClass.m
  110. +6 −6 ...at/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/OtherClass.m
  111. 0 .../mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/README.txt
  112. +10 −10 ...t/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/SimpleEmpty.m
  113. +12 −12 ...mat/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/SimpleSingleText.m
  114. +18 −18 ...rmat/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/MatlabClasses/TestHandleClass.m
  115. BIN ...tlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/bigsparse.mat
  116. BIN ...bi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/cell.mat
  117. BIN .../mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/complexSparse.mat
  118. BIN .../format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/denseRowColSparse.mat
  119. BIN ...tlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/emptyname.mat
  120. BIN ...i/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/int32.mat
  121. BIN ...i/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/int64.mat
  122. BIN ...bi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/int8.mat
  123. BIN ...bi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/java.mat
  124. BIN ...matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/logical.mat
  125. BIN ...at/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/matnativedouble.mat
  126. BIN ...t/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/matnativedouble2.mat
  127. BIN ...mat/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/multiDimComplexMatrix.mat
  128. BIN ...mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/multiDimMatrix.mat
  129. BIN ...ebi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/nan.mat
  130. BIN .../matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/object.mat
  131. BIN ...b/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/simplestruct.mat
  132. BIN .../matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/single.mat
  133. BIN .../matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/sparse.mat
  134. BIN .../matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/uint32.mat
  135. BIN .../matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/uint64.mat
  136. BIN ...i/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/uint8.mat
  137. +8 −8 .../hebi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/utf.m
  138. BIN ...ebi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/arrays/utf.mat
  139. BIN ...mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/figures/plot-advanced.fig
  140. BIN ...b/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/figures/plot-simple.fig
  141. BIN ...b/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/figures/plot-simple.mat
  142. BIN ...i/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/handles.mat
  143. BIN ...ormat/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/handlesingle_multiple.mat
  144. BIN ...tlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/simpleempty.mat
  145. BIN ...format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/simpleempty_multiple.mat
  146. BIN ...t/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/simplesingletext_multiple.mat
  147. BIN ...5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/simplesingletext_multiplearray.mat
  148. BIN ...mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/simplesingletext_unmodified.mat
  149. BIN ...bi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/string.mat
  150. BIN ...ebi/matlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/table.mat
  151. BIN ...atlab/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/mcos/timeseries.mat
  152. BIN ...format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/simulink/simulink_tet_out.mat
  153. BIN ...b/mat/format/mat5test → src/test/resources/us/hebi/matlab/mat/tests/mat5}/simulink/statespace.mat
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
*.iml
/.idea
settings.xml
target/
21 changes: 21 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
= Mat-File IO - Changelog

== 0.2
* Moved `common.util` to `mat.util`
* Removed unused utilities
* Removed multi-release jar dependency due to lack of support for some build tools (e.g. obfuscation)
* Improved streaming file sink implementation
* Changed `StreamingDoubleMatrix2D` to be a test example
* `MatFile` API
** Renamed `size()` to `getNumEntries()`
** Added `clear()`
** Added `getEntries()` for accessing `Iterable<NamedArray>`

== 0.1.2
* fixed binary incompatibilities with Java 6 that were introduced by compiling with JDK 9

== 0.1.1
* added license headers to all files

== 0.1
* initial release
9 changes: 4 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ pipeline {
jdk 'jdk8'
}
steps {
bat 'mvn clean package -PnoJava9'
bat 'mvn clean verify'
}
post {
always {
@@ -51,7 +51,7 @@ pipeline {
jdk 'jdk8'
}
steps {
sh 'mvn clean package -PnoJava9'
sh 'mvn clean verify'
}
post {
always {
@@ -71,15 +71,14 @@ pipeline {
jdk 'jdk8'
}
steps {
sh 'mvn clean package -PnoJava9'
sh 'mvn clean verify'
}
post {
always {
cleanWs()
}
}
}
/*
stage('Windows Java 9') {
agent {
node {
@@ -138,7 +137,7 @@ pipeline {
cleanWs()
}
}
}*/
}

}
}
24 changes: 12 additions & 12 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
MatlabTools - A collection of Java libraries for interfacing with MATLAB
Copyright (C) 2018 HEBI Robotics.
This library is free software; you can redistribute it and/or
modify it under the terms of the Apache 2.0 License as published
by the Apache Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Mat-File IO - a Java library for reading and writing MAT Files

Copyright (C) 2018 HEBI Robotics.

This library is free software; you can redistribute it and/or
modify it under the terms of the Apache 2.0 License as published
by the Apache Software Foundation.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you have any questions please contact us via https://github.com/HebiRobotics/
178 changes: 162 additions & 16 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,39 +1,185 @@
= MatlabTools
= Mat-File IO

The `MatlabTools` repository is a collection of MATLAB related Java libraries maintained by link:http://www.hebirobotics.com/[HEBI Robotics].
== Introduction

Migrating our internal libraries to open source is an ongoing effort, so we will be adding more over time. Depending on the interest, selected projects may be moved into dedicated repositories in the future.
Mat-File IO is a Java library for reading and writing MAT Files that are compatible with MATLAB's MAT-File Format.

== Modules
It's overall design goals are; 1) to support working with large amounts of data on heap constrained and allocation limited environments, 2) to allow users to serialize custom data classes without having to convert to temporary objects, 3) to provide a user-friendly API that adheres to MATLAB's semantic behavior.

This library currently supports the https://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf[Level 5 MAT-File Format] which has been the default for `.mat` and `.fig` files since https://en.wikipedia.org/wiki/MATLAB#Release_history[MATLAB 5.0 (R8)] in 1996. This includes `save` flags `-v6` and `-v7`, but not `-v4` or `-v7.3`. See MAT-File https://de.mathworks.com/help/matlab/import_export/mat-file-versions.html[Versions] for more info.

This library is free, written in 100% Java, and has been released under an Apache v2.0 license. It works with Java 6 and higher, including Java 9 and 10.

=== Mat-File IO
== Maven Central

link:./mat-file-io[Mat-File IO] is a Java library for reading and writing MAT Files that are compatible with MATLAB's MAT-File Format.
Mat-File IO is in the Maven central repository and can easily be added to Maven, Gradle, and similar project managers.

```XML
<dependency>
<groupId>us.hebi.matlab</groupId>
<artifactId>mat-file-io</artifactId>
<version>0.1.2</version>
<version>0.2</version>
</dependency>
```

It's overall design goals are; 1) to support working with large amounts of data on heap constrained and allocation limited environments, 2) to allow users to serialize custom data classes without having to convert to temporary objects, 3) to provide a user-friendly API that adheres to MATLAB's semantic behavior.
[NOTE]
====
The initial release was done as version 0.x because we are still doing final integration tests. However, it is likely that there won't be any more breaking changes, so 1.0 is expected to be fully compatible and should be released in the near future.
====

This library is free, written in 100% Java, and has been released under an Apache v2.0 license. It works with Java 6 and higher, including Java 9 and 10.
== Basic Usage

For more information and usage examples, please refer to the link:./mat-file-io[documentation].
The **link:./src/main/java/us/hebi/matlab/mat/format/Mat5.java[Mat5]** class contains static factory methods that serve as the starting points for the public API. The basic types (e.g. `Struct`, `Cell`, `Sparse`, `Char`) follow their corresponding MATLAB semantics (e.g. a struct can't be logical) and provide a fluent API for the most common use cases. All of the numerical types (e.g. `double`, `uint8`, `int16`, `logical`, ...) are represented by the `Matrix` type which offers a unified interface for handling numeric conversions.

== Building Sources
Similarly to MATLAB, all types are internally represented as a multi-dimensional `Array`. For example, a scalar struct is really a `1x1` array of structs. Most types offer convenience overloads for scalar, linear, 2-dimensional, and N-dimensional access.

Below are some example snippets on how to use the API. For more examples, please refer to **link:./src/test/java/us/hebi/matlab/mat/tests/Mat5Examples.java[Mat5Examples]** and the various unit tests.

=== Creating and Writing MAT Files

A `MatFile` is a data structure that contains a collection of named `Array` variables.

```Java
// Create MAT file with a scalar in a nested struct
MatFile matFile = Mat5.newMatFile()
.addArray("var1", Mat5.newString("Test"))
.addArray("var2", Mat5.newScalar(7))
.addArray("var3", Mat5.newStruct().set("x", Mat5.newScalar(42)))
```

The created `MatFile` can be written to a data `Sink`. Sinks for various outputs (e.g. buffer, stream, or file) can be created via the `Sinks` factory or by extending `AbstractSink`.

```Java
// Serialize to streaming file using default configuration
try(Sink sink = Sinks.newStreamingFile("data.mat")){
matFile.writeTo(sink);
}
```

The `MatFile` can also be written to disk using a memory-mapped file. We can initialize the file with the maximum expected size, and then automatically truncate it once the `Sink` is closed.

```Java
// Serialize to memory-mapped file w/ custom deflate level
int safetySize = 256; // some (small) arrays may become larger when compressed
long maxExpectedSize = matFile.getUncompressedSerializedSize() + safetySize;
try(Sink sink = Sinks.newMappedFile("data.mat", (int) maxExpectedSize)){
Mat5.newWriter(sink)
.setDeflateLevel(Deflater.BEST_SPEED)
.writeMat(matFile);
}
```

=== Reading MAT Files

A `MatFile` can be read from a `Source`. Similar to `Sink`, a `Source` can represent various types of data inputs. The read API is setup such that users can navigate through known file structures without requiring casts or temporary variables.

```Java
// Read scalar from nested struct
try(Source source = Sources.openFile("data.mat"){
double value = Mat5.newReader(source).readFile()
.getStruct("var3")
.getMatrix("x")
.getDouble(0);
}
```

=== Advanced Filtering

In cases where users are only interested in reading a subset of `Array` variables, unwanted entries can be ignored by specifying an `ArrayFilter`.

```Java
// Filter arrays that follow some criteria based on the name, type, dimension, or global/logical flags
try(Source source = Sources.openFile("data.mat"){
MatFile mat = Mat5.newReader(source)
.setArrayFilter(header -> header.isGlobal())
.readFile();
}
```

The filter gets applied only at the root level, so arrays inside a struct or cell array won't be filtered separately.

=== Concurrent Compression

The created sources include Java 9's `module-info.java`, but are otherwise backwards compatible with Java 6. The contained unit tests may use Java 8 syntax, so the project needs to be compiled with at least JDK 8.
Almost all of the CPU time spent on reading or writing MAT files is related to compression. Fortunately, root entries are compressed independently from one another, so it's possible to do the work multi-threaded.

Building with JDK 9 and above
Users can enable concurrent reading by passing an executor service into the reader. In order to activate, the `Source` must also support sub-views (slices) on the underlying data (i.e. byte buffers or memory mapped files).

```Java
// Concurrent Decompression
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
try(Source source = Sources.openFile("data.mat"){
MatFile mat = Mat5.newReader(source)
.enableConcurrentDecompression(executor)
.readFile()
} finally {
executor.shutdown();
}
```

Concurrent writing unfortunately requires a temporary buffer for each root variable due to the size not being known ahead of time. The buffer allocation can be customized in case users want to use buffer-pools or memory-mapped buffers.

```Java
// Concurrent Compression
try(Sink sink = Sinks.newStreamingFile("data.mat")){
Mat5.newWriter(sink)
.enableConcurrentCompression(executorService)
.setDeflateLevel(Deflater.BEST_SPEED)
.writeMat(mat);
}
```

The table below shows a rough performance comparison of working with one of our production data logs.

[width="100%",options="header",cols="a,a,a,a,a"]
|====================
| Compression | Size | Threads | Write Time | Read Time
| BEST_COMPRESSION | 144 MB | 1 | 280 sec | 3.5 sec
| BEST_COMPRESSION | 144 MB | 8 | 47 sec | 0.8 sec
| BEST_SPEED | 156 MB | 1 | 7.2 sec | 3.6 sec
| BEST_SPEED | 156 MB | 8 | 1.5 sec | 0.8 sec
| NO_COMPRESSION | 422 MB | 1 | 0.07 sec | 0.2 sec
|====================

The data set was very multi-threading friendly (33x [95946x18] double matrices on the root level) and first loaded into memory to avoid disk access bottlenecks. The tests were done on a quad core with hyper-threading (Intel NUC6i7kyk).

=== Serializing Custom Classes

We often encountered cases where we needed to serialize data from an existing math library. Rather than having to convert the data into an API class, we added the ability to create light-weight wrapper classes that serialize the desired data directly.

In order for a class to be serializable, it needs to implement the `Array` interface (easiest way is to extend `AbstractArray`) as well as the `Mat5Serializable` interface. Below are examples:

* link:./src/test/java/us/hebi/matlab/mat/tests/serialization/EjmlDMatrixWrapper.java[EjmlDMatrixWrapper] serializes link:http://ejml.org[EJML]'s `DMatrix` type

* link:./src/test/java/us/hebi/matlab/mat/tests/serialization/EjmlSparseWrapper.java[EjmlSparseWrapper] serializes link:http://ejml.org[EJML]'s `DMatrixSparseCSC` sparse matrix

* link:./src/test/java/us/hebi/matlab/mat/tests/serialization/StreamingDoubleMatrix2D.java[StreamingDoubleMatrix2D] streams incoming row-major data into temporary files and combines them on serialization

== General Notes

=== Memory Efficient Serialization

The MAT 5 format stores all data fields with a header tag that contains the number of bytes and how they should be interpreted. Rather than writing into temporary buffers to determine the serialized size, we added ways to pre-compute all deterministic sizes beforehand.

The only non-deterministic case is compressing data at the root level, which we can work around by writing a dummy size and overwriting it once the final size is known. Thus, enabling compression requires the root level sink to support position seeking (i.e. in-memory buffers, memory mapped files, or random access files).

=== Support for Undocumented Features

Unfortunately, MAT 5 files have several features that aren't covered in the official documentation. This includes most of the recently added types (`table`, `timeseries`, `string`, ...), `handle` classes, `function handles`, `.fig` files, `Simulink` outputs, etc.

Our current implementation supports reading all of the `.mat` and `.fig` files we were able to generate. It also supports editing and saving of the loaded MAT files, e.g., adding entries, changing matrices, or using a different compression level. However, changes to the undocumented parts, such as setting a property on a `handle` class, will not be saved.

== Building Sources

The created sources include unit tests that make use of Java 7 and 8 syntax, so the project needs to be compiled with at least JDK 8.

mvn package

Building with JDK 8
For more information, please check the CI build-script link:Jenkinsfile[]

== Acknowledgements

https://github.com/diffplug/matfilerw[MatFileRW] (active fork of https://github.com/gradusnikov/jmatio[JMatIO] maintained by link:http://diffplug.com/[DiffPlug]) served as an inspiration for parts of the implementation as well as a source for test data. We ended up porting and supporting all of their unit tests with the exception of `Base64 MDL` decoding (which we couldn't figure out the use case for).

mvn package -PnoJava9
The implementation for reading the undocumented `MCOS` (MATLAB Class Object System) data is based on https://github.com/mbauman[Matt Bauman]'s http://nbviewer.jupyter.org/gist/mbauman/9121961[reverse engineering efforts] as well as MatFileRW's implementation by https://github.com/MJDSys[Matthew Dawson].

For more information, please check the CI build-script link:Jenkinsfile[]
`Preconditions` was copied from link:https://github.com/google/guava[Guava].
11 changes: 0 additions & 11 deletions mat-file-io/CHANGELOG.adoc

This file was deleted.

Loading