RF: refactor matlab endian fixes

Fix endian check for writing arrays.
Simplfy code from fix for unicode endianness on read.
Add tests.
Merge pull request #487 from matthew-brett/refactor-mio-fixes

RF: refactor matlab endian fixes