Exemplo n.º 1
0
        /// <summary>
        /// Dispose function as suggested in the stackoverflow discussion below
        /// See: http://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface/538238#538238
        /// </summary>
        /// <param name="itIsSafeToAlsoFreeManagedObjects"></param>
        protected virtual void Dispose(bool itIsSafeToAlsoFreeManagedObjects)
        {
            if (!Hdf5Utils.GetRealName(GroupId, Datasetname, string.Empty).valid)
            {
                Hdf5Utils.LogInfo?.Invoke("Dataset does not exist.");
                return;
            }

            if (_datasetId >= 0)
            {
                H5D.close(_datasetId);
            }

            if (_propId >= 0)
            {
                H5P.close(_propId);
            }

            if (_spaceId >= 0)
            {
                H5S.close(_spaceId);
            }

            if (itIsSafeToAlsoFreeManagedObjects)
            {
            }
        }
Exemplo n.º 2
0
        public void AppendDataset(Array dataset)
        {
            if (!Hdf5Utils.GetRealName(GroupId, Datasetname, string.Empty).valid)
            {
                string msg = "call constructor or FirstDataset first before appending.";
                Hdf5Utils.LogError?.Invoke(msg);
                throw new Hdf5Exception(msg);
            }
            _oldDims     = _currentDims;
            _currentDims = GetDims(dataset);
            int rank = dataset.Rank;

            ulong[] zeros = Enumerable.Range(0, rank).Select(z => (ulong)0).ToArray();

            /* Extend the dataset. Dataset becomes 10 x 3  */
            var size = new[] { _oldDims[0] + _currentDims[0] }.Concat(_oldDims.Skip(1)).ToArray();

            _status = H5D.set_extent(_datasetId, size);
            ulong[] offset = new[] { _oldDims[0] }.Concat(zeros.Skip(1)).ToArray();

            /* Select a hyperslab in extended portion of dataset  */
            var filespaceId = H5D.get_space(_datasetId);

            _status = H5S.select_hyperslab(filespaceId, H5S.seloper_t.SET, offset, null,
                                           _currentDims, null);

            /* Define memory space */
            var memId = H5S.create_simple(Rank, _currentDims, null);

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

            _status = H5D.write(_datasetId, _datatype, memId, filespaceId,
                                H5P.DEFAULT, hnd.AddrOfPinnedObject());
            hnd.Free();

            _currentDims = size;
            H5S.close(memId);
            H5S.close(filespaceId);
        }
Exemplo n.º 3
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;
        }