2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
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
13 #ifndef __HDF5SCILAB_HXX__
14 #define __HDF5SCILAB_HXX__
18 #include "H5Object.hxx"
20 #include "H5Group.hxx"
21 #include "H5Dataset.hxx"
22 #include "H5Attribute.hxx"
24 #include "H5VariableScope.hxx"
28 #include "api_scilab.h"
30 #include "HDF5Objects.h"
32 #include "localization.h"
35 namespace org_modules_hdf5
43 static int getH5ObjectId(int * mlist, void * pvApiCtx);
45 static H5Object * getH5Object(int * mlist, void * pvApiCtx);
47 static bool isH5Object(int * mlist, void * pvApiCtx);
49 static void scilabPrint(const std::string & str);
51 static void split(const std::string & str, std::vector<std::string> & v, const char c = '\n');
53 static void readData(const std::string & filename, const std::string & name, int pos, void * pvApiCtx);
55 static void readData(H5Object & obj, const std::string & name, int pos, void * pvApiCtx);
57 static void readAttributeData(H5Object & obj, const std::string & path, const std::string & attrName, int pos, void * pvApiCtx);
59 static void readAttributeData(const std::string & filename, const std::string & path, const std::string & attrName, int pos, void * pvApiCtx);
61 static void deleteLink(H5Object & parent, const std::string & name);
63 static void createLink(H5Object & parent, const std::string & name, const std::string & targetPath, const bool hard);
65 static void createLink(H5Object & parent, const std::string & name, H5Object & targetObject, const bool hard);
67 static void createLink(H5Object & parent, const std::string & name, const std::string & targetFile, const std::string & targetPath);
69 static void createLink(H5Object & parent, const std::string & name, H5Object & targetObject);
71 template <typename T, typename U>
72 static U & create(H5Object & parent, const std::string & name, const unsigned int rank, const hsize_t * dims, const hsize_t * maxdims, T * data, const hid_t targetType)
80 hsize_t * _maxdims = 0;
81 bool mustDelete = false;
83 H5T_cdata_t * pcdata = 0;
85 if (rank > __SCILAB_HDF5_MAX_DIMS__)
87 throw H5Exception(__LINE__, __FILE__, _("Invalid rank, must be in the interval [0, %d]."), __SCILAB_HDF5_MAX_DIMS__);
92 loc = &reinterpret_cast<H5File *>(&parent)->getRoot();
99 type = H5Type::getBaseType(data);
102 throw H5Exception(__LINE__, __FILE__, _("Cannot create a data type."));
105 if (targetType == (hid_t) - 1)
111 targettype = targetType;
114 if (!H5Tfind(type, targettype, &pcdata))
117 throw H5Exception(__LINE__, __FILE__, _("No converter found for the specified target datatype."));
122 _maxdims = new hsize_t[rank];
123 memcpy(_maxdims, dims, rank * sizeof(hsize_t));
128 _maxdims = const_cast<hsize_t *>(maxdims);
131 space = H5Screate_simple(rank, dims, maxdims);
140 throw H5Exception(__LINE__, __FILE__, _("Cannot create a new dataspace."));
145 obj = U::create(*loc, name, type, targettype, space, data);
149 catch (H5Exception & e)
156 return *new U(*loc, obj, name);
159 template <typename T, typename U>
160 static U & create(H5Object & parent, const std::string & name, const unsigned int rank, const hsize_t * dims, const hsize_t * maxdims, T * data, const std::string & targetType)
163 if (targetType.empty())
165 targettype = (hid_t) - 1;
169 targettype = H5Type::getBaseType(targetType);
172 throw H5Exception(__LINE__, __FILE__, _("Cannot create the target type."));
178 U & obj = create<T, U>(parent, name, rank, dims, maxdims, data, targettype);
181 H5Tclose(targettype);
185 catch (H5Exception & e)
189 H5Tclose(targettype);
197 #endif // __HDF5SCILAB_HXX__