From 20e247e31fb40bf2228a2ed84b93896fc48b5eff Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sat, 4 Apr 2026 17:41:01 -0400 Subject: feat: Producing a Readable MAT-File Producing a readable MAT-File of a 1x5 Array of doubles. The file is somewhat manually generated, but currently works. --- include/matfile.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 include/matfile.h (limited to 'include/matfile.h') diff --git a/include/matfile.h b/include/matfile.h new file mode 100644 index 0000000..586dbea --- /dev/null +++ b/include/matfile.h @@ -0,0 +1,92 @@ +#ifndef INCLUDE_MATFILE_H_ +#define INCLUDE_MATFILE_H_ + +#include +#include +#include + +typedef enum { + miINT8 = 1, + miUINT8 = 2, + miINT16 = 3, + miUINT16 = 4, + miINT32 = 5, + miUINT32 = 6, + miSINGLE = 7, + // 8 -- Reserved + miDOUBLE = 9, + // 10 -- Reserved + // 11 -- Reserved + miINT64 = 12, + miUINT64 = 13, + miMATRIX = 14, + miCOMPRESSED = 15, + miUTF8 = 16, + miUTF16 = 17, + miUTF32 = 18 +} mTypes_t; + +typedef enum { + mxCELL_CLASS = 1, + mxSTRUCT_CLASS = 2, + mxOBJECT_CLASS = 3, + mxCHAR_CLASS = 4, + mxSPARSE_CLASS = 5, + mxDOUBLE_CLASS = 6, + mxSINGLE_CLASS = 7, + mxINT8_CLASS = 8, + mxUINT8_CLASS = 9, + mxINT16_CLASS = 10, + mxUINT16_CLASS = 11, + mxINT32_CLASS = 12, + mxUINT32_CLASS = 13, + mxINT64_CLASS = 14, + mxUINT64_CLASS = 15, +} mClasses_t; + +typedef struct { + char description[116]; + uint32_t subsystem_offset_high; + uint32_t subsystem_offset_low; + uint16_t version; + uint16_t endian_indicator; +} mHeader_t; + +typedef struct { + uint32_t type; + uint32_t size; +} mTag_t; + +typedef struct { + uint16_t type; + uint16_t size; +} mSmallTag_t; + +typedef struct { + mTag_t tag; + void *data; +} mData_t; + +typedef struct { + mSmallTag_t tag; + uint32_t data; +} mSmallData_t; + +typedef struct { + uint8_t class; + struct { + uint8_t unused1 : 1; + uint8_t logical : 1; + uint8_t global : 1; + uint8_t complex : 1; + uint8_t unused2 : 4; + }; + uint16_t unused3; + uint32_t unused0; +} mArrayFlags_t; + +bool write_header(FILE *file); +bool write_data(FILE *file, mData_t data); +bool write_small_data(FILE *file, mSmallData_t data); + +#endif // INCLUDE_MATFILE_H_ -- cgit v1.2.3