Example #1
0
        public static object GetObject(Hdf5Identifier _fileId, AbstractHdf5Object _parent, string _objectName)
        {
            Hdf5Path combinedPath = _parent.Path.Append(_objectName);
            object   output       = null;

            if (combinedPath != null)
            {
                string fullPath = combinedPath.FullPath;

                H5O.info_t gInfo = new H5O.info_t();
                H5O.get_info_by_name(_fileId.Value, fullPath, ref gInfo);

                var id = H5O.open(_fileId.Value, fullPath).ToId();
                if (id.Value > 0)
                {
                    if (gInfo.type == H5O.type_t.DATASET)
                    {
                        output = DatasetHelper.LoadDataset(_fileId, id, fullPath);
                    }

                    if (gInfo.type == H5O.type_t.GROUP)
                    {
                        Hdf5Group group = new Hdf5Group(_fileId, id, fullPath);
                        group.FileId = _fileId;
                        group.LoadChildObjects();
                        output = group;
                    }

                    H5O.close(id.Value);
                }
            }

            return(output);
        }
Example #2
0
        public static Hdf5Dataset CreateDatasetAddToDatasets(
            ReadonlyNamedItemList <Hdf5Dataset> _datasets,
            Hdf5Identifier _fileId,
            Hdf5Path _parentPath,
            string _name,
            Hdf5DataTypes _datatype,
            int _numberOfDimensions,
            List <Hdf5DimensionProperty> _properties,
            Hdf5CompressionProperty _compressionProperty = null)
        {
            Hdf5Dataset dataset = CreateDataset(
                _fileId,
                _parentPath,
                _name,
                _datatype,
                _numberOfDimensions,
                _properties,
                _compressionProperty);

            if (dataset != null)
            {
                _datasets.Add(dataset);
            }

            return(dataset);
        }
Example #3
0
        public static Hdf5Dataset CreateDataset(
            Hdf5Identifier _fileId,
            Hdf5Path _parentPath,
            string _name,
            Hdf5DataTypes _datatype,
            int _numberOfDimensions,
            List <Hdf5DimensionProperty> _properties)
        {
            Hdf5Path path = _parentPath.Append(_name);

            UInt64[] dimensionSize = new UInt64[_numberOfDimensions];
            UInt64[] maxSize       = null; // new UInt64[_numberOfDimensions];

            int i = 0;

            foreach (var property in _properties)
            {
                dimensionSize[i] = property.CurrentSize;

                //if (property.MaximumSize == UInt64.MaxValue)
                //{
                //    maxSize[i] = H5S.UNLIMITED;
                //}
                //else
                //{
                //    maxSize[i] = property.MaximumSize;
                //}

                i++;
            }

            Hdf5Identifier dataspaceId = H5S.create_simple(_numberOfDimensions, dimensionSize, maxSize).ToId();

            //TODO handle string datasets
            Hdf5Identifier typeId = H5T.copy(TypeHelper.GetNativeType(_datatype).Value).ToId();
            var            status = H5T.set_order(typeId.Value, H5T.order_t.LE);

            Hdf5Identifier datasetId = H5D.create(_fileId.Value, path.FullPath, typeId.Value, dataspaceId.Value).ToId();

            Hdf5Dataset dataset = null;

            if (datasetId.Value > 0)
            {
                dataset = new Hdf5Dataset(_fileId, datasetId, path.FullPath)
                {
                    DataType  = TypeHelper.GetDataTypeFromDataset(datasetId),
                    Dataspace = DataspaceHelper.GetDataspace(datasetId)
                };

                H5D.close(datasetId.Value);
            }

            H5T.close(typeId.Value);

            FileHelper.FlushToFile(_fileId);

            return(dataset);
        }
Example #4
0
        public static Hdf5Group CreateGroupAddToList(
            ReadonlyNamedItemList <Hdf5Group> _groups,
            Hdf5Identifier _fileId,
            Hdf5Path _parentPath,
            string _name)
        {
            Hdf5Group group = CreateGroup(_fileId, _parentPath, _name);

            if (group != null)
            {
                _groups.Add(group);
            }
            return(group);
        }
Example #5
0
        public static Hdf5Group CreateGroup(Hdf5Identifier _fileId, Hdf5Path _parentPath, string _name)
        {
            Hdf5Path path = _parentPath.Append(_name);
            var      id   = H5G.create(_fileId.Value, path.FullPath);

            if (id > 0)
            {
                Hdf5Group group = new Hdf5Group(_fileId, id.ToId(), path.FullPath);
                H5G.close(id);
                FileHelper.FlushToFile(_fileId);
                return(group);
            }
            return(null);
        }
Example #6
0
        public void AppendToRoot()
        {
            try
            {
                Hdf5Path path = new Hdf5Path("/");

                var newpath = path.Append("addthis");

                Assert.AreEqual(newpath.FullPath, "addthis");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentNullException>(ex);
            }
        }
Example #7
0
        public void AppendToSlash()
        {
            try
            {
                Hdf5Path path = new Hdf5Path("thepath/");

                var newpath = path.Append("isclear");

                Assert.AreEqual(newpath.FullPath, "thepath/isclear");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentNullException>(ex);
            }
        }
Example #8
0
        public void AppendNull()
        {
            try
            {
                Hdf5Path path = new Hdf5Path("thepath");

                path.Append(null);

                Assert.Fail("Should have caused an exception");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOf <ArgumentNullException>(ex);
            }
        }
Example #9
0
        public static Hdf5Path Append(this Hdf5Path _path, string _childName)
        {
            if (_childName == null)
            {
                throw new ArgumentNullException("_childName");
            }

            if (_path != null &&
                _path.FullPath != "/")
            {
                string fullPath = _path.FullPath;

                if (fullPath.EndsWith("/"))
                {
                    return(new Hdf5Path(fullPath + _childName));
                }

                return(new Hdf5Path(fullPath + "/" + _childName));
            }

            return(new Hdf5Path(_childName));
        }
Example #10
0
        public static Hdf5Dataset CreateDataset(
            Hdf5Identifier _fileId,
            Hdf5Path _parentPath,
            string _name,
            Hdf5DataTypes _datatype,
            int _numberOfDimensions,
            List <Hdf5DimensionProperty> _properties,
            Hdf5CompressionProperty _compressionProperty = null)
        {
            Hdf5Path path = _parentPath.Append(_name);

            UInt64[] dimensionSize = new UInt64[_numberOfDimensions];
            UInt64[] maxSize       = null; // new UInt64[_numberOfDimensions];

            if (_numberOfDimensions != _properties.Count ||
                (_compressionProperty != null && _numberOfDimensions != _compressionProperty.ChunkDimensions.Length))
            {
                throw new Hdf5ArrayDimensionsMismatchException();
            }

            int i = 0;

            foreach (var property in _properties)
            {
                dimensionSize[i] = property.CurrentSize;

                if (_compressionProperty != null && _compressionProperty.ChunkDimensions[i] > property.CurrentSize)
                {
                    throw new Hdf5ArraySizeMismatchException();
                }

                i++;
            }

            Hdf5Identifier dataspaceId = H5S.create_simple(_numberOfDimensions, dimensionSize, maxSize).ToId();

            //TODO handle string datasets
            Hdf5Identifier typeId = H5T.copy(TypeHelper.GetNativeType(_datatype).Value).ToId();
            var            status = H5T.set_order(typeId.Value, H5T.order_t.LE);

            var plist_id = _compressionProperty != null?H5P.create(H5P.DATASET_CREATE) : 0;

            if (plist_id != 0)
            {
                H5P.set_chunk(plist_id, _compressionProperty.ChunkDimensions.Length, _compressionProperty.ChunkDimensions);
                H5P.set_deflate(plist_id, _compressionProperty.CompressionLevel);
            }

            Hdf5Identifier datasetId = H5D.create(_fileId.Value, path.FullPath, typeId.Value, dataspaceId.Value, dcpl_id: plist_id).ToId();

            Hdf5Dataset dataset = null;

            if (datasetId.Value > 0)
            {
                dataset = new Hdf5Dataset(_fileId, datasetId, path.FullPath)
                {
                    DataType  = TypeHelper.GetDataTypeFromDataset(datasetId),
                    Dataspace = DataspaceHelper.GetDataspace(datasetId)
                };

                H5D.close(datasetId.Value);
            }

            H5T.close(typeId.Value);
            if (plist_id != 0)
            {
                H5P.close(plist_id);
            }

            FileHelper.FlushToFile(_fileId);

            return(dataset);
        }