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++)
93 //reverse dimensions to improve rendering in external tools
94 piDims[i] = _piDims[_iDims - 1 - i];
95 iSize *= (int)piDims[i];
102 static herr_t addIntAttribute(int _iDatasetId, const char *_pstName, const int _iVal)
104 hsize_t attributeDims[1] = { 1 };
105 hid_t attributeTypeId, attributeSpace;
108 //Create attribute dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
109 attributeSpace = H5Screate_simple(1, attributeDims, NULL);
111 //Create the attribute and write it.
112 attributeTypeId = H5Acreate(_iDatasetId, _pstName, H5T_NATIVE_INT, attributeSpace, H5P_DEFAULT);
113 if (attributeTypeId < 0)
118 status = H5Awrite(attributeTypeId, H5T_NATIVE_INT, &_iVal);
124 //Close and release resources.
125 status = H5Aclose(attributeTypeId);
131 status = H5Sclose(attributeSpace);
140 static herr_t addAttribute(int _iDatasetId, const char *_pstName, const char *_pstValue)
142 hsize_t attributeDims[1] = { 1 };
143 hid_t attributeTypeId, attributeSpace, attr;
146 //Create attribute dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
147 attributeSpace = H5Screate_simple(1, attributeDims, NULL);
149 //Create special attribute type
150 attributeTypeId = H5Tcopy(H5T_C_S1);
151 status = H5Tset_size(attributeTypeId, strlen(_pstValue));
157 //Create the attribute and write it.
158 attr = H5Acreate(_iDatasetId, _pstName, attributeTypeId, attributeSpace, H5P_DEFAULT);
164 status = H5Awrite(attr, attributeTypeId, _pstValue);
170 //Close and release resources.
171 status = H5Aclose(attr);
177 status = H5Tclose(attributeTypeId);
187 int updateScilabVersion(int _iFile)
190 //try to read attribute
191 char* pstScilabVersion = getScilabVersionAttribute(_iFile);
192 if (pstScilabVersion)
194 //delete before write
195 status = H5Adelete(_iFile, g_SCILAB_CLASS_SCI_VERSION);
202 if (strstr(SCI_VERSION_STRING, "branch"))
206 sprintf(pstVersion, "%s %d.%d.%d", SCI_VERSION_STRING, SCI_VERSION_MAJOR, SCI_VERSION_MINOR, SCI_VERSION_MAINTENANCE);
207 status = addAttribute(_iFile, g_SCILAB_CLASS_SCI_VERSION, pstVersion);
211 //compiled by compilation chain
212 status = addAttribute(_iFile, g_SCILAB_CLASS_SCI_VERSION, SCI_VERSION_STRING);
218 int updateFileVersion(int _iFile)
221 //try to read attribute
222 int iHdf5Version = getSODFormatAttribute(_iFile);
223 if (iHdf5Version != -1)
225 status = H5Adelete(_iFile, g_SCILAB_CLASS_SOD_VERSION);
232 return addIntAttribute(_iFile, g_SCILAB_CLASS_SOD_VERSION, SOD_FILE_VERSION);
235 int writeStringMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, char **data)
238 hsize_t* piDims = NULL;
239 hid_t typeId, space, dset;
243 piDims = convertDims(_iDims, _piDims, &iSize);
244 //Create string dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
245 space = H5Screate_simple(_iDims, piDims, NULL);
252 //Create special string type
253 typeId = H5Tcopy(H5T_C_S1);
254 status = H5Tset_size(typeId, H5T_VARIABLE);
261 //Create the data set and write it.
262 iCompress = enableCompression(9, _iDims, piDims);
264 dset = H5Dcreate(_iFile, _pstDatasetName, typeId, space, iCompress);
270 status = H5Dwrite(dset, typeId, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
276 //Add attribute SCILAB_Class = string to dataset
277 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_STRING);
283 //Close and release resources.
284 status = H5Dclose(dset);
290 status = H5Tclose(typeId);
299 char *createGroupName(char *_pstGroupName)
301 char *pstSlash = NULL;
302 char *pstGroupName = (char *)MALLOC((strlen(_pstGroupName) + 3) * sizeof(char));
304 // Generate groupname #<dataSetName>#
305 sprintf(pstGroupName, "#%s#", _pstGroupName);
306 pstSlash = strstr(pstGroupName, "/");
307 if (pstSlash != NULL)
315 char* createPathName(char *_pstGroupName, int _iIndex)
317 char *pstName = NULL;
318 char *pstPathName = NULL;
320 int iNameLen = (int)log10((double)_iIndex + 1) + 1;
321 iNameLen += 2; //for both '#'
322 iNameLen += 1; //for null termanation
324 pstName = (char *)MALLOC(iNameLen * sizeof(char));
325 //1 for null termination, 2 for '#' characters
326 sprintf(pstName, "#%d#", _iIndex);
328 pstPathName = (char *)MALLOC((strlen(_pstGroupName) + strlen(pstName) + 2) * sizeof(char));
329 //1 for null termination, 1 for separator, 2 for '#' characters
330 sprintf(pstPathName, "%s/%s", _pstGroupName, pstName);
335 int writeVoid(int _iFile, char *_pstDatasetName)
337 hsize_t piDims[1] = { 1 };
344 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
345 iSpace = H5Screate_simple(1, piDims, NULL);
350 //Create the dataset and write the array data to it.
351 iCompress = enableCompression(9, 1, piDims);
352 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
358 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, &cData);
364 //Add attribute SCILAB_Class = double to dataset
365 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_VOID);
371 //Close and release resources.
372 status = H5Dclose(iDataset);
378 status = H5Sclose(iSpace);
387 int writeUndefined(int _iFile, char *_pstDatasetName)
389 hsize_t piDims[1] = { 1 };
396 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
397 iSpace = H5Screate_simple(1, piDims, NULL);
402 //Create the dataset and write the array data to it.
403 iCompress = enableCompression(9, 1, piDims);
404 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
410 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, &cData);
416 //Add attribute SCILAB_Class = double to dataset
417 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_UNDEFINED);
423 //Close and release resources.
424 status = H5Dclose(iDataset);
430 status = H5Sclose(iSpace);
439 int writeDoubleMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblData)
444 hsize_t *piDims = NULL;
449 piDims = convertDims(_iDims, _piDims, &iSize);
451 if (_iDims == 2 && piDims[0] == 0 && piDims[1] == 0)
454 space = H5Screate_simple(0, NULL, NULL);
461 //Create the dataset and write the array data to it.
462 iCompress = enableCompression(9, _iDims, piDims);
465 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress);
471 //Add attribute SCILAB_Class = double to dataset
472 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
478 //Close and release resources.
479 status = H5Dclose(dset);
485 status = H5Sclose(space);
493 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
494 space = H5Screate_simple(_iDims, piDims, NULL);
501 //Create the dataset and write the array data to it.
502 iCompress = enableCompression(9, _iDims, piDims);
505 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_DOUBLE, space, iCompress);
511 status = H5Dwrite(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pdblData);
517 //Add attribute SCILAB_Class = double to dataset
518 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
524 //Close and release resources.
525 status = H5Dclose(dset);
531 status = H5Sclose(space);
540 int writeDoubleComplexMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, double *_pdblReal, double *_pdblImg)
545 hsize_t *piDims = NULL;
549 doublecomplex* pData = NULL;
551 //create sub group only for non empty matrix
552 if (_iDims == 2 && _piDims[0] == 0 && _piDims[1] == 0)
559 compoundId = H5Tcreate (H5T_COMPOUND, sizeof(doublecomplex));
560 H5Tinsert(compoundId, "real", HOFFSET(doublecomplex, r), H5T_NATIVE_DOUBLE);
561 H5Tinsert(compoundId, "imag", HOFFSET(doublecomplex, i), H5T_NATIVE_DOUBLE);
562 piDims = convertDims(_iDims, _piDims, &iSize);
564 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
565 space = H5Screate_simple(_iDims, piDims, NULL);
572 //Create the dataset and write the array data to it.
573 iCompress = enableCompression(9, _iDims, piDims);
576 dset = H5Dcreate(_iFile, _pstDatasetName, compoundId, space, iCompress);
582 //convert double data doublecomplex data
583 pData = oGetDoubleComplexFromPointer(_pdblReal, _pdblImg, iSize);
584 status = H5Dwrite(dset, compoundId, H5S_ALL, H5S_ALL, H5P_DEFAULT, pData);
591 //Add attribute SCILAB_Class = double to dataset
592 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_DOUBLE);
598 //Close and release resources.
599 status = H5Dclose(dset);
605 status = H5Sclose(space);
614 int writeBooleanMatrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, int *_piData)
617 hsize_t* piDims = NULL;
623 piDims = convertDims(_iDims, _piDims, &iSize);
625 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
626 iSpace = H5Screate_simple(_iDims, piDims, NULL);
632 //Create the dataset and write the array data to it.
633 iCompress = enableCompression(9, _iDims, piDims);
634 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT, iSpace, iCompress);
640 status = H5Dwrite(iDataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, _piData);
646 //Add attribute SCILAB_Class = double to dataset
647 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_BOOLEAN);
653 //Close and release resources.
654 status = H5Dclose(iDataset);
660 status = H5Sclose(iSpace);
669 static int writeCommonPolyMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iComplex, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal, double **_pdblImg)
672 hsize_t* piDims = NULL;
678 hobj_ref_t *pData = 0;
681 char *pstPathName = NULL;
682 char *pstGroupName = NULL;
684 piDims = convertDims(_iDims, _piDims, &iSize);
686 pData = (hobj_ref_t *)MALLOC(iSize * sizeof(hobj_ref_t));
688 // Generate groupname #<dataSetName>#
689 pstGroupName = createGroupName(_pstDatasetName);
691 //First create a group to store all referenced objects.
692 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
693 status = H5Gclose(group);
695 //Now create each String as a dedicated DataSet.
696 for (i = 0 ; i < iSize ; i++)
698 pstPathName = createPathName(pstGroupName, i);
700 // Write the string to ref
703 status = writeDoubleComplexMatrix(_iFile, pstPathName, 1, &_piNbCoef[i], _pdblReal[i], _pdblImg[i]);
707 status = writeDoubleMatrix(_iFile, pstPathName, 1, &_piNbCoef[i], _pdblReal[i]);
720 status = H5Rcreate(&pData[i], _iFile, pstPathName, H5R_OBJECT, -1);
734 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
735 space = H5Screate_simple(_iDims, piDims, NULL);
743 //Create the dataset and write the array data to it.
744 iCompress = enableCompression(9, _iDims, piDims);
746 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
753 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pData);
761 //Add attribute SCILAB_Class = poly to dataset
762 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_POLY);
768 //Add attribute Varname attribute to dataset
769 status = addAttribute(dset, g_SCILAB_CLASS_VARNAME, _pstVarName);
777 //Add attribute Varname attribute to dataset
778 status = addAttribute(dset, g_SCILAB_CLASS_COMPLEX, "true");
785 //Close and release resources.
786 status = H5Dclose(dset);
792 status = H5Sclose(space);
801 int writePolyMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal)
803 return writeCommonPolyMatrix(_iFile, _pstDatasetName, _pstVarName, 0, _iDims, _piDims, _piNbCoef, _pdblReal, NULL);
806 int writePolyComplexMatrix(int _iFile, char *_pstDatasetName, char *_pstVarName, int _iDims, int* _piDims, int *_piNbCoef, double **_pdblReal,
809 return writeCommonPolyMatrix(_iFile, _pstDatasetName, _pstVarName, 1, _iDims, _piDims, _piNbCoef, _pdblReal, _pdblImg);
812 int writeInteger8Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, char *_pcData)
814 hsize_t* piDims = NULL;
821 piDims = convertDims(_iDims, _piDims, &iSize);
823 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
824 iSpace = H5Screate_simple(_iDims, piDims, NULL);
830 //Create the dataset and write the array data to it.
831 iCompress = enableCompression(9, _iDims, piDims);
833 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT8, iSpace, iCompress);
839 status = H5Dwrite(iDataset, H5T_NATIVE_INT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pcData);
845 //Add attribute SCILAB_Class = double to dataset
846 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
852 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "8");
858 //Close and release resources.
859 status = H5Dclose(iDataset);
865 status = H5Sclose(iSpace);
874 int writeInteger16Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, short *_psData)
876 hsize_t* piDims = NULL;
883 piDims = convertDims(_iDims, _piDims, &iSize);
885 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
886 iSpace = H5Screate_simple(_iDims, piDims, NULL);
892 //Create the dataset and write the array data to it.
893 iCompress = enableCompression(9, _iDims, piDims);
895 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT16, iSpace, iCompress);
900 status = H5Dwrite(iDataset, H5T_NATIVE_INT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, _psData);
906 //Add attribute SCILAB_Class = double to dataset
907 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
913 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "16");
919 //Close and release resources.
920 status = H5Dclose(iDataset);
926 status = H5Sclose(iSpace);
935 int writeInteger32Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, int *_piData)
937 hsize_t* piDims = NULL;
944 piDims = convertDims(_iDims, _piDims, &iSize);
946 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
947 iSpace = H5Screate_simple(_iDims, piDims, NULL);
953 //Create the dataset and write the array data to it.
954 iCompress = enableCompression(9, _iDims, piDims);
956 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT32, iSpace, iCompress);
962 status = H5Dwrite(iDataset, H5T_NATIVE_INT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, _piData);
968 //Add attribute SCILAB_Class = double to dataset
969 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
975 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "32");
981 //Close and release resources.
982 status = H5Dclose(iDataset);
988 status = H5Sclose(iSpace);
997 int writeInteger64Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, long long *_pllData)
999 hsize_t* piDims = NULL;
1003 hid_t iCompress = 0;
1006 piDims = convertDims(_iDims, _piDims, &iSize);
1008 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1009 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1015 //Create the dataset and write the array data to it.
1016 iCompress = enableCompression(9, _iDims, piDims);
1018 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_INT64, iSpace, iCompress);
1024 status = H5Dwrite(iDataset, H5T_NATIVE_INT64, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pllData);
1030 //Add attribute SCILAB_Class = double to dataset
1031 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1037 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "64");
1043 //Close and release resources.
1044 status = H5Dclose(iDataset);
1050 status = H5Sclose(iSpace);
1059 int writeUnsignedInteger8Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned char *_pucData)
1061 hsize_t* piDims = NULL;
1065 hid_t iCompress = 0;
1068 piDims = convertDims(_iDims, _piDims, &iSize);
1070 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1071 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1077 //Create the dataset and write the array data to it.
1078 iCompress = enableCompression(9, _iDims, piDims);
1080 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT8, iSpace, iCompress);
1086 status = H5Dwrite(iDataset, H5T_NATIVE_UINT8, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pucData);
1092 //Add attribute SCILAB_Class = double to dataset
1093 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1099 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u8");
1105 //Close and release resources.
1106 status = H5Dclose(iDataset);
1112 status = H5Sclose(iSpace);
1121 int writeUnsignedInteger16Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned short *_pusData)
1123 hsize_t* piDims = NULL;
1127 hid_t iCompress = 0;
1130 piDims = convertDims(_iDims, _piDims, &iSize);
1132 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1133 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1139 //Create the dataset and write the array data to it.
1140 iCompress = enableCompression(9, _iDims, piDims);
1142 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT16, iSpace, iCompress);
1148 status = H5Dwrite(iDataset, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pusData);
1154 //Add attribute SCILAB_Class = double to dataset
1155 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1161 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u16");
1167 //Close and release resources.
1168 status = H5Dclose(iDataset);
1174 status = H5Sclose(iSpace);
1183 int writeUnsignedInteger32Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned int *_puiData)
1185 hsize_t* piDims = NULL;
1189 hid_t iCompress = 0;
1192 piDims = convertDims(_iDims, _piDims, &iSize);
1194 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1195 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1201 //Create the dataset and write the array data to it.
1202 iCompress = enableCompression(9, _iDims, piDims);
1204 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT32, iSpace, iCompress);
1210 status = H5Dwrite(iDataset, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, _puiData);
1216 //Add attribute SCILAB_Class = double to dataset
1217 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1223 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u32");
1229 //Close and release resources.
1230 status = H5Dclose(iDataset);
1236 status = H5Sclose(iSpace);
1245 int writeUnsignedInteger64Matrix(int _iFile, char *_pstDatasetName, int _iDims, int* _piDims, unsigned long long *_pullData)
1247 hsize_t* piDims = NULL;
1251 hid_t iCompress = 0;
1254 piDims = convertDims(_iDims, _piDims, &iSize);
1256 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1257 iSpace = H5Screate_simple(_iDims, piDims, NULL);
1263 //Create the dataset and write the array data to it.
1264 iCompress = enableCompression(9, _iDims, piDims);
1266 iDataset = H5Dcreate(_iFile, _pstDatasetName, H5T_NATIVE_UINT64, iSpace, iCompress);
1272 status = H5Dwrite(iDataset, H5T_NATIVE_UINT64, H5S_ALL, H5S_ALL, H5P_DEFAULT, _pullData);
1278 //Add attribute SCILAB_Class = double to dataset
1279 status = addAttribute(iDataset, g_SCILAB_CLASS, g_SCILAB_CLASS_INT);
1285 status = addAttribute(iDataset, g_SCILAB_CLASS_PREC, "u64");
1291 //Close and release resources.
1292 status = H5Dclose(iDataset);
1298 status = H5Sclose(iSpace);
1307 int writeCommonSparseComplexMatrix(int _iFile, char *_pstDatasetName, int _iComplex, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow,
1308 int *_piColPos, double *_pdblReal, double *_pdblImg)
1310 hsize_t dims[1] = { 3 };
1315 hid_t iCompress = 0;
1316 hobj_ref_t pDataRef[3] = {0};
1318 char *pstRowPath = NULL;
1319 char *pstColPath = NULL;
1320 char *pstDataPath = NULL;
1321 char *pstGroupName = NULL;
1323 // Generate groupname #<dataSetName>#
1324 pstGroupName = createGroupName(_pstDatasetName);
1326 //First create a group to store all referenced objects.
1327 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
1328 status = H5Gclose(group);
1335 //Create each sub dataset and insert data
1336 pstRowPath = createPathName(pstGroupName, 0);
1337 status = writeInteger32Matrix(_iFile, pstRowPath, 1, &_iRows, _piNbItemRow);
1345 status = H5Rcreate(&pDataRef[0], _iFile, pstRowPath, H5R_OBJECT, -1);
1353 pstColPath = createPathName(pstGroupName, 1);
1354 status = writeInteger32Matrix(_iFile, pstColPath, 1, &_iNbItem, _piColPos);
1363 status = H5Rcreate(&pDataRef[1], _iFile, pstColPath, H5R_OBJECT, -1);
1372 pstDataPath = createPathName(pstGroupName, 2);
1375 status = writeDoubleComplexMatrix(_iFile, pstDataPath, 1, &_iNbItem, _pdblReal, _pdblImg);
1379 status = writeDoubleMatrix(_iFile, pstDataPath, 1, &_iNbItem, _pdblReal);
1391 status = H5Rcreate(&pDataRef[2], _iFile, pstDataPath, H5R_OBJECT, -1);
1407 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1408 space = H5Screate_simple(1, dims, NULL);
1414 //Create the dataset and write the array data to it.
1415 iCompress = enableCompression(9, 1, dims);
1416 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
1422 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pDataRef);
1427 //Add attribute SCILAB_Class = poly to dataset
1428 //sprintf(pstRow, "%d", _iRows);
1429 //sprintf(pstCol, "%d", _iCols);
1430 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_SPARSE);
1436 status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows);
1442 status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols);
1448 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1456 //Add attribute Varname attribute to dataset
1457 status = addAttribute(dset, g_SCILAB_CLASS_COMPLEX, "true");
1464 //Close and release resources.
1465 status = H5Dclose(dset);
1471 status = H5Sclose(space);
1480 int writeSparseMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos, double *_pdblReal)
1482 return writeCommonSparseComplexMatrix(_iFile, _pstDatasetName, 0, _iRows, _iCols, _iNbItem, _piNbItemRow, _piColPos, _pdblReal, NULL);
1485 int writeSparseComplexMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos,
1486 double *_pdblReal, double *_pdblImg)
1488 return writeCommonSparseComplexMatrix(_iFile, _pstDatasetName, 1, _iRows, _iCols, _iNbItem, _piNbItemRow, _piColPos, _pdblReal, _pdblImg);
1491 int writeBooleanSparseMatrix(int _iFile, char *_pstDatasetName, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos)
1493 hsize_t dims[1] = { 2 };
1498 hid_t iCompress = 0;
1499 hobj_ref_t pDataRef[2] = {0};
1501 char *pstRowPath = NULL;
1502 char *pstColPath = NULL;
1503 char *pstGroupName = NULL;
1505 // Generate groupname #<dataSetName>#
1506 pstGroupName = createGroupName(_pstDatasetName);
1508 //First create a group to store all referenced objects.
1509 group = H5Gcreate(_iFile, pstGroupName, H5P_DEFAULT);
1510 status = H5Gclose(group);
1517 //Create each sub dataset and insert data
1518 pstRowPath = createPathName(pstGroupName, 0);
1519 status = writeInteger32Matrix(_iFile, pstRowPath, 1, &_iRows, _piNbItemRow);
1527 status = H5Rcreate(&pDataRef[0], _iFile, pstRowPath, H5R_OBJECT, -1);
1535 pstColPath = createPathName(pstGroupName, 1);
1536 status = writeInteger32Matrix(_iFile, pstColPath, 1, &_iNbItem, _piColPos);
1545 status = H5Rcreate(&pDataRef[1], _iFile, pstColPath, H5R_OBJECT, -1);
1559 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1560 space = H5Screate_simple(1, dims, NULL);
1566 //Create the dataset and write the array data to it.
1567 iCompress = enableCompression(9, 1, dims);
1568 dset = H5Dcreate(_iFile, _pstDatasetName, H5T_STD_REF_OBJ, space, iCompress);
1574 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pDataRef);
1580 //Add attribute SCILAB_Class = boolean sparse to dataset
1581 status = addAttribute(dset, g_SCILAB_CLASS, g_SCILAB_CLASS_BSPARSE);
1587 status = addIntAttribute(dset, g_SCILAB_CLASS_ROWS, _iRows);
1593 status = addIntAttribute(dset, g_SCILAB_CLASS_COLS, _iCols);
1599 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1604 //Close and release resources.
1605 status = H5Dclose(dset);
1611 status = H5Sclose(space);
1620 //create a group and create hobj_ref_t array
1621 void *openList(int _iFile, char *pstDatasetName, int _iNbItem)
1625 hobj_ref_t *pobjArray = NULL;
1627 //First create a group to store all referenced objects.
1628 group = H5Gcreate(_iFile, pstDatasetName, H5P_DEFAULT);
1629 status = H5Gclose(group);
1637 pobjArray = MALLOC(sizeof(hobj_ref_t) * _iNbItem);
1643 int addItemInList(int _iFile, void *_pvList, int _iPos, char *_pstItemName)
1645 hobj_ref_t *pobjArray = (hobj_ref_t *) _pvList;
1647 return H5Rcreate(&pobjArray[_iPos], _iFile, _pstItemName, H5R_OBJECT, -1);
1650 int closeList(int _iFile, void *_pvList, char *_pstListName, int _iNbItem, int _iVarType)
1653 hsize_t dims[1] = { _iNbItem };
1656 hid_t iCompress = 0;
1657 const char *pcstClass = NULL;
1662 pcstClass = g_SCILAB_CLASS_LIST;
1665 pcstClass = g_SCILAB_CLASS_TLIST;
1668 pcstClass = g_SCILAB_CLASS_MLIST;
1676 //tips for empty list
1677 //insert a fake refence in the array, value = 0
1679 hobj_ref_t pvList[1];
1682 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1685 space = H5Screate_simple(1, dims, NULL);
1691 //Create the dataset and write the array data to it.
1692 iCompress = enableCompression(9, 1, dims);
1693 dset = H5Dcreate(_iFile, _pstListName, H5T_STD_REF_OBJ, space, iCompress);
1699 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, (hobj_ref_t *) pvList);
1705 //Add attribute SCILAB_Class = string to dataset
1706 status = addAttribute(dset, g_SCILAB_CLASS, pcstClass);
1712 status = addAttribute(dset, g_SCILAB_CLASS_EMPTY, "true");
1720 //Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
1721 space = H5Screate_simple(1, dims, NULL);
1727 //Create the dataset and write the array data to it.
1728 iCompress = enableCompression(9, 1, dims);
1729 dset = H5Dcreate(_iFile, _pstListName, H5T_STD_REF_OBJ, space, iCompress);
1735 status = H5Dwrite(dset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, (hobj_ref_t *) _pvList);
1741 //Add attribute SCILAB_Class = string to dataset
1742 status = addAttribute(dset, g_SCILAB_CLASS, pcstClass);
1748 status = addIntAttribute(dset, g_SCILAB_CLASS_ITEMS, _iNbItem);
1755 //Close and release resources.
1756 status = H5Dclose(dset);
1762 status = H5Sclose(space);