Esempio n. 1
0
    void DCDataSet::create(const CollectionType& colType,
            hid_t group, const Dimensions size, uint32_t ndims, bool compression)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::create (%s, size %s)", name.c_str(), size.toString().c_str());

        if (opened)
            throw DCException(getExceptionString("create: dataset is already open"));

        // if the dataset already exists, remove/unlink it
        // note that this won't free the memory occupied by this
        // dataset, however, there currently is no function to delete
        // a dataset
        if (!checkExistence || (checkExistence && H5Lexists(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT)))
            H5Ldelete(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT);

        this->ndims = ndims;
        this->compression = compression;
        this->datatype = colType.getDataType();

        getLogicalSize().set(size);

        setChunking(colType.getSize());
        setCompression();

        if (getPhysicalSize().getScalarSize() != 0)
        {
            hsize_t *max_dims = new hsize_t[ndims];
            for (size_t i = 0; i < ndims; ++i)
                max_dims[i] = H5F_UNLIMITED;

            dataspace = H5Screate_simple(ndims, getPhysicalSize().getPointer(), max_dims);

            delete[] max_dims;
            max_dims = NULL;
        } else
            dataspace = H5Screate(H5S_NULL);



        if (dataspace < 0)
            throw DCException(getExceptionString("create: Failed to create dataspace"));

        // create the new dataset
        dataset = H5Dcreate(group, this->name.c_str(), this->datatype, dataspace,
                H5P_DEFAULT, dsetProperties, H5P_DEFAULT);

        if (dataset < 0)
            throw DCException(getExceptionString("create: Failed to create dataset"));

        isReference = false;
        opened = true;
    }