From 7e77224340d9d0e33d486a55e6513d2c9c7e8161 Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Thu, 16 Aug 2012 14:12:03 +0200 Subject: [PATCH] import/export emptymatrix Change-Id: I0506c06410e00df84bf900b3f6d45016fda64be7 --- scilab/modules/hdf5/src/c/h5_writeDataToFile.c | 153 ++++---------------- .../hdf5/tests/sample_scilab_data/emptymatrix.sod | Bin 0 -> 1600 bytes .../hdf5/tests/unit_tests/loadhdf5data.dia.ref | 3 + .../modules/hdf5/tests/unit_tests/loadhdf5data.tst | 4 + 4 files changed, 38 insertions(+), 122 deletions(-) create mode 100644 scilab/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod diff --git a/scilab/modules/hdf5/src/c/h5_writeDataToFile.c b/scilab/modules/hdf5/src/c/h5_writeDataToFile.c index ff7daea..a41c69f 100644 --- a/scilab/modules/hdf5/src/c/h5_writeDataToFile.c +++ b/scilab/modules/hdf5/src/c/h5_writeDataToFile.c @@ -88,8 +88,9 @@ static hsize_t* convertDims(int _iDims, int* _piDims, int* _piSize) int iSize = 1; int i = 0; hsize_t* piDims = (hsize_t*)malloc(sizeof(hsize_t) * _iDims); - for(i = 0 ; i < _iDims ; i++) - {//reverse dimensions to improve rendering in external tools + for (i = 0 ; i < _iDims ; i++) + { + //reverse dimensions to improve rendering in external tools piDims[i] = _piDims[_iDims - 1 - i]; iSize *= (int)piDims[i]; } @@ -435,153 +436,60 @@ int writeUndefined(int _iFile, char *_pstDatasetName) return 0; } -static hobj_ref_t writeCommomDoubleMatrix(int _iFile, char *_pstGroupName, char *_pstDatasetName, int _iIndex, int _iRows, int _iCols, - double *_pdblData) +int writeDoubleMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblData) { - hid_t space; - hid_t dset; - hid_t iCompress = 0; - hsize_t dims[1] = { _iRows * _iCols }; + hid_t space = 0; + hid_t dset = 0; herr_t status = 0; - hobj_ref_t iRef = 0; - - if (_iRows * _iCols == 0) - { - double dblZero = 0; - - //tips for empty double matrix - - //Create dataspace. Setting maximum size to NULL sets the maximum - //size to be the current size. - dims[0] = 1; - - space = H5Screate_simple(1, dims, NULL); - if (space < 0) - { - return (hobj_ref_t) (-1); - } - - //Create the dataset and write the array data to it. - iCompress = enableCompression(9, 1, dims); - dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress); - if (dset < 0) - { - return (hobj_ref_t) (-1); - } - - status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &dblZero); - if (status < 0) - { - return (hobj_ref_t) (-1); - } + hsize_t *piDims = NULL; + hid_t iCompress = 0; + int i = 0; + int iSize = 0; - //Add attribute SCILAB_Class = double to dataset - status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE); - if (status < 0) - { - return (hobj_ref_t) (-1); - } + piDims = convertDims(_iDims, _piDims, &iSize); - status = addAttribute(dset, g_SCILAB_CLASS_EMPTY, "true"); - if (status < 0) - { - return (hobj_ref_t) (-1); - } - } - else + if (_iDims == 2 && piDims[0] == 0 && piDims[1] == 0) { - char *pstPathName = NULL; - - //Create dataspace. Setting maximum size to NULL sets the maximum - //size to be the current size. - space = H5Screate_simple(1, dims, NULL); + // [] + space = H5Screate_simple(0, NULL, NULL); if (space < 0) { - return (hobj_ref_t) (-1); + free(piDims); + return -1; } - //createGroupe and dataset name - pstPathName = createPathName(_pstGroupName, _iIndex); - //Create the dataset and write the array data to it. - iCompress = enableCompression(9, 1, dims); - dset = H5Dcreate(_iFile, pstPathName, H5T_NATIVE_DOUBLE, space, iCompress); - if (dset < 0) - { - FREE(pstPathName); - return (hobj_ref_t) (-1); - } + iCompress = enableCompression(9, _iDims, piDims); + free(piDims); - status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pdblData); - if (status < 0) + dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress); + if (dset < 0) { - FREE(pstPathName); - return (hobj_ref_t) (-1); + return -1; } //Add attribute SCILAB_Class = double to dataset status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE); if (status < 0) { - FREE(pstPathName); - return (hobj_ref_t) (-1); - } - - //Add attribute SCILAB_Class_rows = double to dataset - status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows); - if (status < 0) - { - FREE(pstPathName); - return (hobj_ref_t) (-1); + return -1; } - //Add attribute SCILAB_Class_cols = double to dataset - status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols); + //Close and release resources. + status = H5Dclose(dset); if (status < 0) { - FREE(pstPathName); - return (hobj_ref_t) (-1); + return -1; } - // create the ref - status = H5Rcreate(&iRef, _iFile, pstPathName, H5R_OBJECT, -1); + status = H5Sclose(space); if (status < 0) { - FREE(pstPathName); - return (hobj_ref_t) (-1); + return -1; } - - FREE(pstPathName); + return 0; } - //Close and release resources. - status = H5Dclose(dset); - if (status < 0) - { - return (hobj_ref_t) (-1); - } - - status = H5Sclose(space); - if (status < 0) - { - return (hobj_ref_t) (-1); - } - - return iRef; -} - -int writeDoubleMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblData) -{ - hid_t space = 0; - hid_t dset = 0; - herr_t status = 0; - hsize_t *piDims = NULL; - hid_t iCompress = 0; - int i = 0; - int iSize = 0; - - piDims = convertDims(_iDims, _piDims, &iSize); - //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size. space = H5Screate_simple(_iDims, piDims, NULL); if (space < 0) @@ -642,7 +550,8 @@ int writeDoubleComplexMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* //create sub group only for non empty matrix if (_iDims == 2 && _piDims[0] == 0 && _piDims[1] == 0) - {// [] complex + { + // [] complex //a revoir return -1; } @@ -804,7 +713,7 @@ static int writeCommonPolyMatrix(int _iFile, char *_pstDatasetName, char *_pstVa FREE(pstGroupName); FREE(pData); FREE(piDims); - return -1; + return -1; } // create the ref diff --git a/scilab/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod b/scilab/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod new file mode 100644 index 0000000000000000000000000000000000000000..aaeb4b5aebe160ba78f70684fcc3b873e4f207d7 GIT binary patch literal 1600 zcmeD5aB<`1lHy_j0S*oZ76t(@6Gr@p0tYsT2#gPtPk=HQp>zk7Ucm%mFak{k$w@%P z1)%0vutEe*K*d9XTwNJ}Dq-fsXs9%U0Sko10TURdM^p%SxH<-aJRAY_H7q@yfTlB8 zV5H_2lvL&>mK0@HfQ4Y`(gCJ`M4FL-9h`n41Oo#r0|%JN#KZ(Pni-g~K@33!d!P&m zI53!SGno8m26KRN5K)*rIG{O!nGu%4QB$-Kl6r~9IsrTk7GQ%I8F+y*0t~^MWP&cV4F)ukoH#f1k uB(+GvRL?}u0AdjjG(9i^P2fSKr{eq+B*TG91%SyCQsgRtHKN-C%XR=PU|iq; literal 0 HcmV?d00001 diff --git a/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.dia.ref b/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.dia.ref index e79f9da..4bc1581 100644 --- a/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.dia.ref +++ b/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.dia.ref @@ -5,6 +5,9 @@ // This file is distributed under the same license as the Scilab package. // ============================================================================= // Load previously saved data (check backward compatibility) +///// Empty matrix +import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod"); +assert_checkequal(emptymatrix, []); ///// Double import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedoublescalar.sod"); assert_checkequal(ascalar,42); diff --git a/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.tst b/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.tst index 79160de..0f55aa9 100644 --- a/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.tst +++ b/scilab/modules/hdf5/tests/unit_tests/loadhdf5data.tst @@ -8,6 +8,10 @@ // Load previously saved data (check backward compatibility) +///// Empty matrix +import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod"); +assert_checkequal(emptymatrix, []); + ///// Double import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedoublescalar.sod"); assert_checkequal(ascalar,42); -- 1.7.9.5