Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_objectId"></param>
        /// <param name="_attribute"></param>
        public static void UpdateAttribute(Hdf5Identifier _objectId, Hdf5Attribute _attribute)
        {
            Hdf5Identifier attributeId = H5A.open(_objectId.Value, _attribute.Name).ToId();

            if (attributeId.Value > 0)
            {
                Hdf5DataType  type     = TypeHelper.GetDataTypeFromAttribute(attributeId);
                Hdf5DataTypes enumType = TypeHelper.GetDataTypesEnum(_attribute.Value.GetType());

                if (type.Type == enumType)
                {
                    if (enumType == Hdf5DataTypes.String)
                    {
                        H5A.close(attributeId.Value);
                        DeleteAttribute(_objectId, _attribute.Name);
                        Hdf5Attribute attribute = CreateAttribute(_objectId, _attribute.Name, _attribute.Value);

                        if (attribute != null)
                        {
                            _attribute.Id    = attribute.Id;
                            _attribute.Name  = attribute.Name;
                            _attribute.Value = attribute.Value;
                        }
                    }
                    else
                    {
                        WriteObjectValue(type, attributeId, _attribute.Value);
                    }
                }
                else
                {
                    throw new Hdf5TypeMismatchException();
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public void SetData <T>(T[,] _array)
        {
            Hdf5DataTypes internalType = TypeHelper.GetDataTypesEnum(typeof(T));

            if (_array == null)
            {
                throw new ArgumentNullException();
            }

            if (!internalType.Equals(DataType.Type))
            {
                throw new Hdf5TypeMismatchException();
            }

            DatasetHelper.Write2DArray <T>(this, _array);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a dataset
        /// </summary>
        /// <param name="_name"></param>
        /// <param name="_datatype"></param>
        /// <param name="_dimensionProperties"></param>
        /// <returns></returns>
        public Hdf5Dataset Add(
            string _name,
            Hdf5DataTypes _datatype,
            List <Hdf5DimensionProperty> _dimensionProperties)
        {
            int numberOfDimensions = _dimensionProperties.Count;

            return(DatasetHelper.CreateDatasetAddToDatasets(
                       this,
                       ParentObject.FileId,
                       ParentObject.Path,
                       _name,
                       _datatype,
                       numberOfDimensions,
                       _dimensionProperties));
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the native type from HDF5
        /// </summary>
        /// <param name="_datatype"></param>
        /// <returns></returns>
        public static Hdf5Identifier GetNativeType(Hdf5DataTypes _datatype)
        {
            switch (_datatype)
            {
            case Hdf5DataTypes.UInt8:
                return(H5T.NATIVE_UINT8.ToId());

            case Hdf5DataTypes.UInt16:
                return(H5T.NATIVE_UINT16.ToId());

            case Hdf5DataTypes.UInt32:
                return(H5T.NATIVE_UINT32.ToId());

            case Hdf5DataTypes.UInt64:
                return(H5T.NATIVE_UINT64.ToId());

            case Hdf5DataTypes.Int8:
                return(H5T.NATIVE_INT8.ToId());

            case Hdf5DataTypes.Int16:
                return(H5T.NATIVE_INT16.ToId());

            case Hdf5DataTypes.Int32:
                return(H5T.NATIVE_INT32.ToId());

            case Hdf5DataTypes.Int64:
                return(H5T.NATIVE_INT64.ToId());

            case Hdf5DataTypes.Single:
                return(H5T.NATIVE_FLOAT.ToId());

            case Hdf5DataTypes.Double:
                return(H5T.NATIVE_DOUBLE.ToId());

            case Hdf5DataTypes.String:
                return(H5T.C_S1.ToId());
            }

            throw new ArgumentOutOfRangeException("_datatype", "Unknown type");
        }
Esempio n. 7
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);
        }