示例#1
0
        public void FirstDataset(Array dataset)
        {
            if (GroupId <= 0)
            {
                throw new Hdf5Exception("cannot call FirstDataset because group or file couldn't be created");
            }

            if (Hdf5Utils.GetRealName(GroupId, Datasetname, string.Empty).valid)
            {
                throw new Hdf5Exception("cannot call FirstDataset because dataset already exists");
            }

            Rank         = dataset.Rank;
            _currentDims = GetDims(dataset);

            /* Create the data space with unlimited dimensions. */
            _spaceId = H5S.create_simple(Rank, _currentDims, _maxDims);

            /* Modify dataset creation properties, i.e. enable chunking  */
            _propId = H5P.create(H5P.DATASET_CREATE);
            _status = H5P.set_chunk(_propId, Rank, _chunkDims);

            /* Create a new dataset within the file using chunk creation properties.  */
            _datasetId = H5D.create(GroupId, Hdf5Utils.NormalizedName(Datasetname), _datatype, _spaceId, H5P.DEFAULT, _propId);

            /* Write data to dataset */
            GCHandle hnd = GCHandle.Alloc(dataset, GCHandleType.Pinned);

            _status = H5D.write(_datasetId, _datatype, H5S.ALL, H5S.ALL, H5P.DEFAULT,
                                hnd.AddrOfPinnedObject());
            if (_status < 0)
            {
                Hdf5Utils.LogError("Unable  to write dataset");
            }

            hnd.Free();
            H5S.close(_spaceId);
            _spaceId = -1;
        }