2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Scilab Enterprises - Antoine ELIAS
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
20 #include "sci_types.h"
22 #include "core_math.h"
23 #include "h5_writeDataToFile.h"
24 #include "h5_readDataFromFile.h"
25 #include "h5_attributeConstants.h"
26 #include "doublecomplex.h"
29 static hid_t enableCompression(int _iLevel, int _iRank, const hsize_t * _piDims)
32 int iLevel = _iLevel;*/
48 iRet = H5Pcreate(H5P_DATASET_CREATE);
55 if(H5Pset_layout(iRet,H5D_COMPACT)<0)
62 if(H5Pset_chunk(iRet,_iRank, _piDims)<0)
69 if(H5Pset_deflate(iRet,iLevel)<0)
80 iRet = H5Pcopy(H5P_DEFAULT);
86 static hsize_t* convertDims(int _iDims, int* _piDims, int* _piSize)
90 hsize_t* piDims = (hsize_t*)malloc(sizeof(hsize_t) * _iDims);
91 for(i = 0 ; i < _iDims ; i++)
92 {//reverse dimensions to improve rendering in external tools
93 piDims[i] = _piDims[_iDims - 1 - i];
94 iSize *= (int)piDims[i];
101 static herr_t addIntAttribute(int _iDatasetId, const char *_pstName, const int _iVal)
103 hsize_t attributeDims[1] = { 1 };
104 hid_t attributeTypeId, attributeSpace;
107 //Create attribute dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
108 attributeSpace = H5Screate_simple(1, attributeDims, NULL);
110 //Create the attribute and write it.
111 attributeTypeId = H5Acreate(_iDatasetId, _pstName, H5T_NATIVE_INT, attributeSpace, H5P_DEFAULT);
112 if (attributeTypeId < 0)
117 status = H5Awrite(attributeTypeId, H5T_NATIVE_INT, &_iVal);
123 //Close and release resources.
124 status = H5Aclose(attributeTypeId);
130 status = H5Sclose(attributeSpace);
139 static herr_t addAttribute(int _iDatasetId, const char *_pstName, const char *_pstValue)
141 hsize_t attributeDims[1] = { 1 };
142 hid_t attributeTypeId, attributeSpace, attr;
145 //Create attribute dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
146 attributeSpace = H5Screate_simple(1, attributeDims, NULL);
148 //Create special attribute type
149 attributeTypeId = H5Tcopy(H5T_C_S1);
150 status = H5Tset_size(attributeTypeId, strlen(_pstValue));
156 //Create the attribute and write it.
157 attr = H5Acreate(_iDatasetId, _pstName, attributeTypeId, attributeSpace, H5P_DEFAULT);
163 status = H5Awrite(attr, attributeTypeId, _pstValue);
169 //Close and release resources.
170 status = H5Aclose(attr);
176 status = H5Tclose(attributeTypeId);
186 int updateScilabVersion(int _iFile)
189 //try to read attribute
190 char* pstScilabVersion = getScilabVersionAttribute(_iFile);
191 if (pstScilabVersion)
193 //delete before write
194 status = H5Adelete(_iFile, g_SCILAB_CLASS_SCI_VERSION);
201 if (strstr(SCI_VERSION_STRING, "branch"))
205 sprintf(pstVersion, "%s %d.%d.%d", SCI_VERSION_STRING, SCI_VERSION_MAJOR, SCI_VERSION_MINOR, SCI_VERSION_MAINTENANCE);
206 status = addAttribute(_iFile, g_SCILAB_CLASS_SCI_VERSION, pstVersion);
210 //compiled by compilation chain
211 status = addAttribute(_iFile, g_SCILAB_CLASS_SCI_VERSION, SCI_VERSION_STRING);
217 int updateFileVersion(int _iFile)
220 //try to read attribute
221 int iHdf5Version = getSODFormatAttribute(_iFile);
222 if (iHdf5Version != -1)
224 status = H5Adelete(_iFile, g_SCILAB_CLASS_SOD_VERSION);
231 return addIntAttribute(_iFile, g_SCILAB_CLASS_SOD_VERSION, SOD_FILE_VERSION);
234 int writeStringMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, char **data)
237 hsize_t* piDims = NULL;
238 hid_t typeId, space, dset;
242 piDims = convertDims(_iDims, _piDims, &iSize);
243 //Create string dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
244 space = H5Screate_simple(_iDims, piDims, NULL);
251 //Create special string type
252 typeId = H5Tcopy(H5T_C_S1);
253 status = H5Tset_size(typeId, H5T_VARIABLE);
260 //Create the data set and write it.
261 iCompress = enableCompression(9, _iDims, piDims);
263 dset = H5Dcreate(_iFile, _pstDatasetName, typeId, space, iCompress);
269 status = H5Dwrite(dset, typeId, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
275 //Add attribute SCILAB_Class = string to dataset
276 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_STRING);
282 //Close and release resources.
283 status = H5Dclose(dset);
289 status = H5Tclose(typeId);
298 char *createGroupName(char *_pstGroupName)
300 char *pstSlash = NULL;
301 char *pstGroupName = (char *)MALLOC((strlen(_pstGroupName) + 3) * sizeof(char));
303 // Generate groupname #<dataSetName>#
304 sprintf(pstGroupName, "#%s#", _pstGroupName);
305 pstSlash = strstr(pstGroupName, "/");
306 if (pstSlash != NULL)
314 char* createPathName(char *_pstGroupName, int _iIndex)
316 char *pstName = NULL;
317 char *pstPathName = NULL;
319 int iNameLen = (int)log10((double)_iIndex + 1) + 1;
320 iNameLen += 2; //for both '#'
321 iNameLen += 1; //for null termanation
323 pstName = (char *)MALLOC(iNameLen * sizeof(char));
324 //1 for null termination, 2 for '#' characters
325 sprintf(pstName, "#%d#", _iIndex);
327 pstPathName = (char *)MALLOC((strlen(_pstGroupName) + strlen(pstName) + 2) * sizeof(char));
328 //1 for null termination, 1 for separator, 2 for '#' characters
329 sprintf(pstPathName, "%s/%s", _pstGroupName, pstName);
334 int writeVoid(int _iFile, char *_pstDatasetName)
336 hsize_t piDims[1] = { 1 };
343 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
344 iSpace = H5Screate_simple(1, piDims, NULL);
349 //Create the dataset and write the array data to it.
350 iCompress = enableCompression(9, 1, piDims);
351 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
357 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, &cData);
363 //Add attribute SCILAB_Class = double to dataset
364 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_VOID);
370 //Close and release resources.
371 status = H5Dclose(iDataset);
377 status = H5Sclose(iSpace);
386 int writeUndefined(int _iFile, char *_pstDatasetName)
388 hsize_t piDims[1] = { 1 };
395 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
396 iSpace = H5Screate_simple(1, piDims, NULL);
401 //Create the dataset and write the array data to it.
402 iCompress = enableCompression(9, 1, piDims);
403 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
409 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, &cData);
415 //Add attribute SCILAB_Class = double to dataset
416 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_UNDEFINED);
422 //Close and release resources.
423 status = H5Dclose(iDataset);
429 status = H5Sclose(iSpace);
438 static hobj_ref_t writeCommomDoubleMatrix(int _iFile, char *_pstGroupName, char *_pstDatasetName, int _iIndex, int _iRows, int _iCols,
444 hsize_t dims[1] = { _iRows * _iCols };
448 if (_iRows * _iCols == 0)
452 //tips for empty double matrix
454 //Create dataspace. Setting maximum size to NULL sets the maximum
455 //size to be the current size.
458 space = H5Screate_simple(1, dims, NULL);
461 return (hobj_ref_t) (-1);
464 //Create the dataset and write the array data to it.
465 iCompress = enableCompression(9, 1, dims);
466 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress);
469 return (hobj_ref_t) (-1);
472 status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &dblZero);
475 return (hobj_ref_t) (-1);
478 //Add attribute SCILAB_Class = double to dataset
479 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
482 return (hobj_ref_t) (-1);
485 status = addAttribute(dset, g_SCILAB_CLASS_EMPTY, "true");
488 return (hobj_ref_t) (-1);
493 char *pstPathName = NULL;
495 //Create dataspace. Setting maximum size to NULL sets the maximum
496 //size to be the current size.
497 space = H5Screate_simple(1, dims, NULL);
500 return (hobj_ref_t) (-1);
503 //createGroupe and dataset name
504 pstPathName = createPathName(_pstGroupName, _iIndex);
506 //Create the dataset and write the array data to it.
507 iCompress = enableCompression(9, 1, dims);
508 dset = H5Dcreate(_iFile, pstPathName, H5T_NATIVE_DOUBLE, space, iCompress);
512 return (hobj_ref_t) (-1);
515 status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pdblData);
519 return (hobj_ref_t) (-1);
522 //Add attribute SCILAB_Class = double to dataset
523 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
527 return (hobj_ref_t) (-1);
530 //Add attribute SCILAB_Class_rows = double to dataset
531 status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows);
535 return (hobj_ref_t) (-1);
538 //Add attribute SCILAB_Class_cols = double to dataset
539 status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols);
543 return (hobj_ref_t) (-1);
547 status = H5Rcreate(&iRef, _iFile, pstPathName, H5R_OBJECT, -1);
551 return (hobj_ref_t) (-1);
557 //Close and release resources.
558 status = H5Dclose(dset);
561 return (hobj_ref_t) (-1);
564 status = H5Sclose(space);
567 return (hobj_ref_t) (-1);
573 int writeDoubleMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblData)
578 hsize_t *piDims = NULL;
583 piDims = convertDims(_iDims, _piDims, &iSize);
585 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
586 space = H5Screate_simple(_iDims, piDims, NULL);
593 //Create the dataset and write the array data to it.
594 iCompress = enableCompression(9, _iDims, piDims);
597 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress);
603 status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pdblData);
609 //Add attribute SCILAB_Class = double to dataset
610 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
616 //Close and release resources.
617 status = H5Dclose(dset);
623 status = H5Sclose(space);
632 int writeDoubleComplexMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblReal, double *_pdblImg)
637 hsize_t *piDims = NULL;
641 doublecomplex* pData = NULL;
643 //create sub group only for non empty matrix
644 if (_iDims == 2 && _piDims[0] == 0 && _piDims[1] == 0)
650 compoundId = H5Tcreate (H5T_COMPOUND, sizeof(doublecomplex));
651 H5Tinsert(compoundId, "real", HOFFSET(doublecomplex, r), H5T_NATIVE_DOUBLE);
652 H5Tinsert(compoundId, "imag", HOFFSET(doublecomplex, i), H5T_NATIVE_DOUBLE);
653 piDims = convertDims(_iDims, _piDims, &iSize);
655 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
656 space = H5Screate_simple(_iDims, piDims, NULL);
663 //Create the dataset and write the array data to it.
664 iCompress = enableCompression(9, _iDims, piDims);
667 dset = H5Dcreate(_iFile, _pstDatasetName, compoundId, space, iCompress);
673 //convert double data doublecomplex data
674 pData = oGetDoubleComplexFromPointer(_pdblReal, _pdblImg, iSize);
675 status = H5Dwrite(dset, compoundId, H5S_ALL, H5S_ALL, H5P_DEFAULT, pData);
682 //Add attribute SCILAB_Class = double to dataset
683 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
689 //Close and release resources.
690 status = H5Dclose(dset);
696 status = H5Sclose(space);
705 int writeBooleanMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, int *_piData)
708 hsize_t* piDims = NULL;
714 piDims = convertDims(_iDims, _piDims, &iSize);
716 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
717 iSpace = H5Screate_simple(_iDims, piDims, NULL);
723 //Create the dataset and write the array data to it.
724 iCompress = enableCompression(9, _iDims, piDims);
725 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT, iSpace, iCompress);
731 status = H5Dwrite(iDataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, _piData);
737 //Add attribute SCILAB_Class = double to dataset
738 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_BOOLEAN);
744 //Close and release resources.
745 status = H5Dclose(iDataset);
751 status = H5Sclose(iSpace);
760 static int writeCommonPolyMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iComplex, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal, double **_pdblImg)
763 hsize_t* piDims = NULL;
769 hobj_ref_t *pData = 0;
772 char *pstPathName = NULL;
773 char *pstGroupName = NULL;
775 piDims = convertDims(_iDims, _piDims, &iSize);
777 pData = (hobj_ref_t *)MALLOC(iSize * sizeof(hobj_ref_t));
779 // Generate groupname #<dataSetName>#
780 pstGroupName = createGroupName(_pstDatasetName);
782 //First create a group to store all referenced objects.
783 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
784 status = H5Gclose(group);
786 //Now create each String as a dedicated DataSet.
787 for (i = 0 ; i < iSize ; i++)
789 pstPathName = createPathName(pstGroupName, i);
791 // Write the string to ref
794 status = writeDoubleComplexMatrix(_iFile, pstPathName, 1, &_piNbCoef[i], _pdblReal[i], _pdblImg[i]);
798 status = writeDoubleMatrix(_iFile, pstPathName, 1, &_piNbCoef[i], _pdblReal[i]);
811 status = H5Rcreate(&pData[i], _iFile, pstPathName, H5R_OBJECT, -1);
825 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
826 space = H5Screate_simple(_iDims, piDims, NULL);
834 //Create the dataset and write the array data to it.
835 iCompress = enableCompression(9, _iDims, piDims);
837 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
844 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pData);
852 //Add attribute SCILAB_Class = poly to dataset
853 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_POLY);
859 //Add attribute Varname attribute to dataset
860 status = addAttribute(dset, g_SCILAB_CLASS_VARNAME, _pstVarName);
868 //Add attribute Varname attribute to dataset
869 status = addAttribute(dset, g_SCILAB_CLASS_COMPLEX, "true");
876 //Close and release resources.
877 status = H5Dclose(dset);
883 status = H5Sclose(space);
892 int writePolyMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal)
894 return writeCommonPolyMatrix(_iFile, _pstDatasetName, _pstVarName, 0, _iDims, _piDims, _piNbCoef, _pdblReal, NULL);
897 int writePolyComplexMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal,
900 return writeCommonPolyMatrix(_iFile, _pstDatasetName, _pstVarName, 1, _iDims, _piDims, _piNbCoef, _pdblReal, _pdblImg);
903 int writeInteger8Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, char *_pcData)
905 hsize_t* piDims = NULL;
912 piDims = convertDims(_iDims, _piDims, &iSize);
914 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
915 iSpace = H5Screate_simple(_iDims, piDims, NULL);
921 //Create the dataset and write the array data to it.
922 iCompress = enableCompression(9, _iDims, piDims);
924 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
930 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pcData);
936 //Add attribute SCILAB_Class = double to dataset
937 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
943 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "8");
949 //Close and release resources.
950 status = H5Dclose(iDataset);
956 status = H5Sclose(iSpace);
965 int writeInteger16Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, short *_psData)
967 hsize_t* piDims = NULL;
974 piDims = convertDims(_iDims, _piDims, &iSize);
976 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
977 iSpace = H5Screate_simple(_iDims, piDims, NULL);
983 //Create the dataset and write the array data to it.
984 iCompress = enableCompression(9, _iDims, piDims);
986 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT16, iSpace, iCompress);
991 status = H5Dwrite(iDataset, H5T_NATIVE_INT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, _psData);
997 //Add attribute SCILAB_Class = double to dataset
998 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1004 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "16");
1010 //Close and release resources.
1011 status = H5Dclose(iDataset);
1017 status = H5Sclose(iSpace);
1026 int writeInteger32Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, int *_piData)
1028 hsize_t* piDims = NULL;
1032 hid_t iCompress = 0;
1035 piDims = convertDims(_iDims, _piDims, &iSize);
1037 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1038 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1044 //Create the dataset and write the array data to it.
1045 iCompress = enableCompression(9, _iDims, piDims);
1047 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT32, iSpace, iCompress);
1053 status = H5Dwrite(iDataset, H5T_NATIVE_INT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, _piData);
1059 //Add attribute SCILAB_Class = double to dataset
1060 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1066 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "32");
1072 //Close and release resources.
1073 status = H5Dclose(iDataset);
1079 status = H5Sclose(iSpace);
1088 int writeInteger64Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, long long *_pllData)
1090 hsize_t* piDims = NULL;
1094 hid_t iCompress = 0;
1097 piDims = convertDims(_iDims, _piDims, &iSize);
1099 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1100 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1106 //Create the dataset and write the array data to it.
1107 iCompress = enableCompression(9, _iDims, piDims);
1109 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT64, iSpace, iCompress);
1115 status = H5Dwrite(iDataset, H5T_NATIVE_INT64, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pllData);
1121 //Add attribute SCILAB_Class = double to dataset
1122 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1128 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "64");
1134 //Close and release resources.
1135 status = H5Dclose(iDataset);
1141 status = H5Sclose(iSpace);
1150 int writeUnsignedInteger8Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned char *_pucData)
1152 hsize_t* piDims = NULL;
1156 hid_t iCompress = 0;
1159 piDims = convertDims(_iDims, _piDims, &iSize);
1161 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1162 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1168 //Create the dataset and write the array data to it.
1169 iCompress = enableCompression(9, _iDims, piDims);
1171 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT8, iSpace, iCompress);
1177 status = H5Dwrite(iDataset, H5T_NATIVE_UINT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pucData);
1183 //Add attribute SCILAB_Class = double to dataset
1184 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1190 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u8");
1196 //Close and release resources.
1197 status = H5Dclose(iDataset);
1203 status = H5Sclose(iSpace);
1212 int writeUnsignedInteger16Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned short *_pusData)
1214 hsize_t* piDims = NULL;
1218 hid_t iCompress = 0;
1221 piDims = convertDims(_iDims, _piDims, &iSize);
1223 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1224 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1230 //Create the dataset and write the array data to it.
1231 iCompress = enableCompression(9, _iDims, piDims);
1233 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT16, iSpace, iCompress);
1239 status = H5Dwrite(iDataset, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pusData);
1245 //Add attribute SCILAB_Class = double to dataset
1246 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1252 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u16");
1258 //Close and release resources.
1259 status = H5Dclose(iDataset);
1265 status = H5Sclose(iSpace);
1274 int writeUnsignedInteger32Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned int *_puiData)
1276 hsize_t* piDims = NULL;
1280 hid_t iCompress = 0;
1283 piDims = convertDims(_iDims, _piDims, &iSize);
1285 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1286 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1292 //Create the dataset and write the array data to it.
1293 iCompress = enableCompression(9, _iDims, piDims);
1295 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT32, iSpace, iCompress);
1301 status = H5Dwrite(iDataset, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, _puiData);
1307 //Add attribute SCILAB_Class = double to dataset
1308 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1314 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u32");
1320 //Close and release resources.
1321 status = H5Dclose(iDataset);
1327 status = H5Sclose(iSpace);
1336 int writeUnsignedInteger64Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned long long *_pullData)
1338 hsize_t* piDims = NULL;
1342 hid_t iCompress = 0;
1345 piDims = convertDims(_iDims, _piDims, &iSize);
1347 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1348 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1354 //Create the dataset and write the array data to it.
1355 iCompress = enableCompression(9, _iDims, piDims);
1357 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT64, iSpace, iCompress);
1363 status = H5Dwrite(iDataset, H5T_NATIVE_UINT64, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pullData);
1369 //Add attribute SCILAB_Class = double to dataset
1370 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1376 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u64");
1382 //Close and release resources.
1383 status = H5Dclose(iDataset);
1389 status = H5Sclose(iSpace);
1398 int writeCommonSparseComplexMatrix(int _iFile, char *_pstDatasetName, int _iComplex, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow,
1399 int *_piColPos, double *_pdblReal, double *_pdblImg)
1401 hsize_t dims[1] = { 3 };
1406 hid_t iCompress = 0;
1407 hobj_ref_t pDataRef[3] = {0};
1409 char *pstRowPath = NULL;
1410 char *pstColPath = NULL;
1411 char *pstDataPath = NULL;
1412 char *pstGroupName = NULL;
1414 // Generate groupname #<dataSetName>#
1415 pstGroupName = createGroupName(_pstDatasetName);
1417 //First create a group to store all referenced objects.
1418 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
1419 status = H5Gclose(group);
1426 //Create each sub dataset and insert data
1427 pstRowPath = createPathName(pstGroupName, 0);
1428 status = writeInteger32Matrix(_iFile, pstRowPath, 1, &_iRows, _piNbItemRow);
1436 status = H5Rcreate(&pDataRef[0], _iFile, pstRowPath, H5R_OBJECT, -1);
1444 pstColPath = createPathName(pstGroupName, 1);
1445 status = writeInteger32Matrix(_iFile, pstColPath, 1, &_iNbItem, _piColPos);
1454 status = H5Rcreate(&pDataRef[1], _iFile, pstColPath, H5R_OBJECT, -1);
1463 pstDataPath = createPathName(pstGroupName, 2);
1466 status = writeDoubleComplexMatrix(_iFile, pstDataPath, 1, &_iNbItem, _pdblReal, _pdblImg);
1470 status = writeDoubleMatrix(_iFile, pstDataPath, 1, &_iNbItem, _pdblReal);
1482 status = H5Rcreate(&pDataRef[2], _iFile, pstDataPath, H5R_OBJECT, -1);
1498 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1499 space = H5Screate_simple(1, dims, NULL);
1505 //Create the dataset and write the array data to it.
1506 iCompress = enableCompression(9, 1, dims);
1507 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
1513 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pDataRef);
1518 //Add attribute SCILAB_Class = poly to dataset
1519 //sprintf(pstRow, "%d", _iRows);
1520 //sprintf(pstCol, "%d", _iCols);
1521 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_SPARSE);
1527 status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows);
1533 status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols);
1539 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1547 //Add attribute Varname attribute to dataset
1548 status = addAttribute(dset, g_SCILAB_CLASS_COMPLEX, "true");
1555 //Close and release resources.
1556 status = H5Dclose(dset);
1562 status = H5Sclose(space);
1571 int writeSparseMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos, double *_pdblReal)
1573 return writeCommonSparseComplexMatrix(_iFile, _pstDatasetName, 0, _iRows, _iCols, _iNbItem, _piNbItemRow, _piColPos, _pdblReal, NULL);
1576 int writeSparseComplexMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos,
1577 double *_pdblReal, double *_pdblImg)
1579 return writeCommonSparseComplexMatrix(_iFile, _pstDatasetName, 1, _iRows, _iCols, _iNbItem, _piNbItemRow, _piColPos, _pdblReal, _pdblImg);
1582 int writeBooleanSparseMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos)
1584 hsize_t dims[1] = { 2 };
1589 hid_t iCompress = 0;
1590 hobj_ref_t pDataRef[2] = {0};
1592 char *pstRowPath = NULL;
1593 char *pstColPath = NULL;
1594 char *pstGroupName = NULL;
1596 // Generate groupname #<dataSetName>#
1597 pstGroupName = createGroupName(_pstDatasetName);
1599 //First create a group to store all referenced objects.
1600 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
1601 status = H5Gclose(group);
1608 //Create each sub dataset and insert data
1609 pstRowPath = createPathName(pstGroupName, 0);
1610 status = writeInteger32Matrix(_iFile, pstRowPath, 1, &_iRows, _piNbItemRow);
1618 status = H5Rcreate(&pDataRef[0], _iFile, pstRowPath, H5R_OBJECT, -1);
1626 pstColPath = createPathName(pstGroupName, 1);
1627 status = writeInteger32Matrix(_iFile, pstColPath, 1, &_iNbItem, _piColPos);
1636 status = H5Rcreate(&pDataRef[1], _iFile, pstColPath, H5R_OBJECT, -1);
1650 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1651 space = H5Screate_simple(1, dims, NULL);
1657 //Create the dataset and write the array data to it.
1658 iCompress = enableCompression(9, 1, dims);
1659 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
1665 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pDataRef);
1671 //Add attribute SCILAB_Class = boolean sparse to dataset
1672 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_BSPARSE);
1678 status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows);
1684 status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols);
1690 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1695 //Close and release resources.
1696 status = H5Dclose(dset);
1702 status = H5Sclose(space);
1711 //create a group and create hobj_ref_t array
1712 void *openList(int _iFile, char *pstDatasetName, int _iNbItem)
1716 hobj_ref_t *pobjArray = NULL;
1718 //First create a group to store all referenced objects.
1719 group = H5Gcreate(_iFile, pstDatasetName, H5P_DEFAULT);
1720 status = H5Gclose(group);
1728 pobjArray = MALLOC(sizeof(hobj_ref_t) * _iNbItem);
1734 int addItemInList(int _iFile, void *_pvList, int _iPos, char *_pstItemName)
1736 hobj_ref_t *pobjArray = (hobj_ref_t *) _pvList;
1738 return H5Rcreate(&pobjArray[_iPos], _iFile, _pstItemName, H5R_OBJECT, -1);
1741 int closeList(int _iFile, void *_pvList, char *_pstListName, int _iNbItem, int _iVarType)
1744 hsize_t dims[1] = { _iNbItem };
1747 hid_t iCompress = 0;
1748 const char *pcstClass = NULL;
1753 pcstClass = g_SCILAB_CLASS_LIST;
1756 pcstClass = g_SCILAB_CLASS_TLIST;
1759 pcstClass = g_SCILAB_CLASS_MLIST;
1767 //tips for empty list
1768 //insert a fake refence in the array, value = 0
1770 hobj_ref_t pvList[1];
1773 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1776 space = H5Screate_simple(1, dims, NULL);
1782 //Create the dataset and write the array data to it.
1783 iCompress = enableCompression(9, 1, dims);
1784 dset = H5Dcreate(_iFile, _pstListName, H5T_STD_REF_OBJ, space, iCompress);
1790 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, (hobj_ref_t *) pvList);
1796 //Add attribute SCILAB_Class = string to dataset
1797 status = addAttribute(dset, g_SCILAB_CLASS, pcstClass);
1803 status = addAttribute(dset, g_SCILAB_CLASS_EMPTY, "true");
1811 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1812 space = H5Screate_simple(1, dims, NULL);
1818 //Create the dataset and write the array data to it.
1819 iCompress = enableCompression(9, 1, dims);
1820 dset = H5Dcreate(_iFile, _pstListName, H5T_STD_REF_OBJ, space, iCompress);
1826 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, (hobj_ref_t *) _pvList);
1832 //Add attribute SCILAB_Class = string to dataset
1833 status = addAttribute(dset, g_SCILAB_CLASS, pcstClass);
1839 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1846 //Close and release resources.
1847 status = H5Dclose(dset);
1853 status = H5Sclose(space);