tbeu / matio

MATLAB MAT File I/O Library
https://matio.sourceforge.io
BSD 2-Clause "Simplified" License
338 stars 97 forks source link

Appending data ocurs error #206

Closed allwaysFindFood closed 1 year ago

allwaysFindFood commented 1 year ago

When using Mat_VarWriteAppend to append data in HDF5 file format, an error will be reported if the amount of data appended exceeds the existing data. However, the total amount of data in the file has not exceeded the upper limit. For example, if the existing data is a float32 array of size 10x100000, and I try to append a new array of size 10x200000, an error will occur.

`

    mat_t* mat = Mat_CreateVer("D:/MatioTest/test.mat", NULL, MAT_FT_MAT73);

    size_t dims[2] = { 60000, 16 };

    matvar_t* newVar = Mat_VarCreate("data",matio_classes::MAT_C_SINGLE,
                                     matio_types::MAT_T_SINGLE, 2, dims, newData, 0);

    int success = Mat_VarWriteAppend(mat, newVar,MAT_COMPRESSION_NONE,2);

    qDebug()<<success;

    size_t dims2[2] = { 190000, 16 };

    newVar = Mat_VarCreate("data",matio_classes::MAT_C_SINGLE,
                                     matio_types::MAT_T_SINGLE, 2, dims2, newData1, 0);

    success = Mat_VarWriteAppend(mat, newVar,MAT_COMPRESSION_NONE,2);

    qDebug()<<success;

    Mat_Close(mat);

`

HIF5-DIAG: Error detected in HF5 (1.8.22) thread 0:

000: D:\hdf5\hdf5-1.8.22\src\H5Dio.c line 303 in H5Dwrite(): file selection + offset not within extent

major: Dataspace minor: Out of range

I find the reason: the dim is not right... success = Mat_VarWriteAppend(mat, newVar,MAT_COMPRESSION_NONE,1);