# tbeu/matio architecture

> Architecture diagram of the GitHub repository tbeu/matio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tbeu/matio
- Repository: https://github.com/tbeu/matio

## Overview

Matio is a C library for reading and writing MATLAB MAT files. A client program calls its public API to open or create a file, then reads variables or writes them; the library supports MAT versions 4, 5, and optionally 7.3. Version-specific handlers implement the file formats, with shared data and variable helpers, and optional zlib and HDF5 support. MCOS and a Fortran interface are additional capabilities. Relationships among internal modules are limited to those supported by the source index; unsampled call paths are omitted or marked unverified.

Main entry points: [`src/mat.c`](https://github.com/tbeu/matio/blob/master/src/mat.c) (File Operations), [`src/mat5.c`](https://github.com/tbeu/matio/blob/master/src/mat5.c) (MAT v5 Handler), [`src/mat73.c`](https://github.com/tbeu/matio/blob/master/src/mat73.c) (MAT v7.3 Handler), [`src/matio.h`](https://github.com/tbeu/matio/blob/master/src/matio.h) (Public C API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Library API"]
  node_publicapi["Public C API<br/>[matio.h]"]
  node_matcore["File Operations<br/>[mat.c]"]
end

subgraph group_formats["MAT File Formats"]
  node_mat4["MAT v4 Handler<br/>[mat4.c]"]
  node_mat5["MAT v5 Handler<br/>[mat5.c]"]
  node_mat73["MAT v7.3 Handler<br/>[mat73.c]"]
end

subgraph group_data["Variables and Data"]
  node_readdata["Data Reading<br/>[read_data.c]"]
  node_cellvars["Cell Variables<br/>[matvar_cell.c]"]
  node_structvars["Struct Variables<br/>[matvar_struct.c]"]
  node_mcos["MCOS Objects<br/>[mcos.c]"]
  node_io["File and Byte I/O<br/>[io.c]"]
  node_inflate["Decompression<br/>[inflate.c]"]
  node_safe_math["Safe Arithmetic<br/>[safe-math.h]"]
end

subgraph group_extras["Additional Interfaces"]
  node_fortran["Fortran Interface"]
  node_matdump["MAT File Dumper<br/>[matdump.c]"]
end

node_client(("Client Program"))
node_matfile["MAT File"]
node_zlib["zlib"]
node_hdf5["HDF5"]

node_client -->|"calls"| node_publicapi
node_publicapi -.->|"exposes operations"| node_matcore
node_matcore -.->|"opens or creates"| node_matfile
node_matcore -.->|"dispatches"| node_mat4
node_matcore -->|"dispatches"| node_mat5
node_matcore -->|"dispatches"| node_mat73
node_mat4 -.->|"reads or writes"| node_matfile
node_mat5 -.->|"reads or writes"| node_matfile
node_mat73 -.->|"reads or writes"| node_matfile
node_mat5 -->|"uses"| node_mcos
node_mat73 -->|"uses"| node_mcos
node_matcore -->|"uses"| node_safe_math
node_readdata -->|"uses"| node_safe_math
node_matcore -.->|"reads data"| node_readdata
node_matcore -.->|"handles cells"| node_cellvars
node_matcore -.->|"handles structs"| node_structvars
node_matcore -.->|"uses"| node_io
node_mat5 -.->|"decompresses"| node_inflate
node_mat5 -.->|"optional compression"| node_zlib
node_mat73 -.->|"optional storage"| node_hdf5
node_client -.->|"may use"| node_fortran
node_client -.->|"may run"| node_matdump
node_matdump -->|"uses library API"| node_publicapi

click node_publicapi "https://github.com/tbeu/matio/blob/master/src/matio.h"
click node_matcore "https://github.com/tbeu/matio/blob/master/src/mat.c"
click node_mat4 "https://github.com/tbeu/matio/blob/master/src/mat4.c"
click node_mat5 "https://github.com/tbeu/matio/blob/master/src/mat5.c"
click node_mat73 "https://github.com/tbeu/matio/blob/master/src/mat73.c"
click node_readdata "https://github.com/tbeu/matio/blob/master/src/read_data.c"
click node_cellvars "https://github.com/tbeu/matio/blob/master/src/matvar_cell.c"
click node_structvars "https://github.com/tbeu/matio/blob/master/src/matvar_struct.c"
click node_mcos "https://github.com/tbeu/matio/blob/master/src/mcos.c"
click node_io "https://github.com/tbeu/matio/blob/master/src/io.c"
click node_inflate "https://github.com/tbeu/matio/blob/master/src/inflate.c"
click node_safe_math "https://github.com/tbeu/matio/blob/master/src/safe-math.h"
click node_fortran "https://github.com/tbeu/matio/tree/master/src/fortran"
click node_matdump "https://github.com/tbeu/matio/blob/master/tools/matdump.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_publicapi,node_matcore,node_client toneBlue
class node_mat4,node_mat5,node_mat73 toneAmber
class node_readdata,node_cellvars,node_structvars,node_mcos,node_io,node_inflate,node_safe_math toneMint
class node_fortran,node_matdump toneRose
class node_matfile,node_zlib,node_hdf5 toneIndigo
```

## Components

### Library API

- [Public C API](https://github.com/tbeu/matio/blob/master/src/matio.h): `src/matio.h`
- [File Operations](https://github.com/tbeu/matio/blob/master/src/mat.c): `src/mat.c`

### MAT File Formats

- [MAT v4 Handler](https://github.com/tbeu/matio/blob/master/src/mat4.c): `src/mat4.c`
- [MAT v5 Handler](https://github.com/tbeu/matio/blob/master/src/mat5.c): `src/mat5.c`
- [MAT v7.3 Handler](https://github.com/tbeu/matio/blob/master/src/mat73.c): `src/mat73.c`

### Variables and Data

- [Data Reading](https://github.com/tbeu/matio/blob/master/src/read_data.c): `src/read_data.c`
- [Cell Variables](https://github.com/tbeu/matio/blob/master/src/matvar_cell.c): `src/matvar_cell.c`
- [Struct Variables](https://github.com/tbeu/matio/blob/master/src/matvar_struct.c): `src/matvar_struct.c`
- [MCOS Objects](https://github.com/tbeu/matio/blob/master/src/mcos.c): `src/mcos.c`
- [File and Byte I/O](https://github.com/tbeu/matio/blob/master/src/io.c): `src/io.c`
- [Decompression](https://github.com/tbeu/matio/blob/master/src/inflate.c): `src/inflate.c`
- [Safe Arithmetic](https://github.com/tbeu/matio/blob/master/src/safe-math.h): `src/safe-math.h`

### Additional Interfaces

- [Fortran Interface](https://github.com/tbeu/matio/tree/master/src/fortran): `src/fortran`
- [MAT File Dumper](https://github.com/tbeu/matio/blob/master/tools/matdump.c): `tools/matdump.c`

### Other components

- **Client Program**
- **MAT File**
- **zlib**
- **HDF5**

## Connections

- Client Program → Public C API: calls (evidence: `README.md`)
- Public C API → File Operations: exposes operations
- File Operations → MAT File: opens or creates
- File Operations → MAT v4 Handler: dispatches
- File Operations → MAT v5 Handler: dispatches (evidence: `src/mat.c`)
- File Operations → MAT v7.3 Handler: dispatches (evidence: `src/mat.c`)
- MAT v4 Handler → MAT File: reads or writes
- MAT v5 Handler → MAT File: reads or writes
- MAT v7.3 Handler → MAT File: reads or writes
- MAT v5 Handler → MCOS Objects: uses (evidence: `src/mat5.c`)
- MAT v7.3 Handler → MCOS Objects: uses (evidence: `src/mat73.c`)
- File Operations → Safe Arithmetic: uses (evidence: `src/mat.c`)
- Data Reading → Safe Arithmetic: uses (evidence: `src/read_data.c`)
- File Operations → Data Reading: reads data
- File Operations → Cell Variables: handles cells
- File Operations → Struct Variables: handles structs
- File Operations → File and Byte I/O: uses
- MAT v5 Handler → Decompression: decompresses
- MAT v5 Handler → zlib: optional compression (evidence: `README.md`)
- MAT v7.3 Handler → HDF5: optional storage (evidence: `README.md`)
- Client Program → Fortran Interface: may use (evidence: `README.md`)
- Client Program → MAT File Dumper: may run
- MAT File Dumper → Public C API: uses library API (evidence: `tools/matdump.c`)
