Ejemplo n.º 1
0
        public void H5Dcreate_anonTest2()
        {
            hsize_t[] dims     = { 10, 10, 10 };
            hsize_t[] max_dims = { H5S.UNLIMITED, H5S.UNLIMITED, H5S.UNLIMITED };
            hid_t     space    = H5S.create_simple(3, dims, max_dims);

            hid_t dcpl = H5P.create(H5P.DATASET_CREATE);

            Assert.IsTrue(dcpl >= 0);
            hsize_t[] chunk = { 64, 64, 64 };
            Assert.IsTrue(H5P.set_chunk(dcpl, 3, chunk) >= 0);
            Assert.IsTrue(H5P.set_deflate(dcpl, 9) >= 0);

            hid_t dset = H5D.create_anon(m_v0_test_file, H5T.IEEE_F32BE,
                                         space, dcpl);

            Assert.IsTrue(dset >= 0);
            Assert.IsTrue(H5D.close(dset) >= 0);

            dset = H5D.create_anon(m_v2_test_file, H5T.IEEE_F32BE,
                                   space, dcpl);
            Assert.IsTrue(dset >= 0);
            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 2
0
        private static long create_property(ulong[] chunk_size)
        {
            var dcpl = H5P.create(H5P.DATASET_CREATE);

            H5P.set_layout(dcpl, H5D.layout_t.CHUNKED);
            H5P.set_chunk(dcpl, chunk_size.Length, chunk_size);
            H5P.set_deflate(dcpl, 6);
            return(dcpl);
        }
Ejemplo n.º 3
0
        static void Main2222(string[] args)
        {
            var h5 = H5F.create(@"D:\test.h5", H5F.ACC_TRUNC);

            var typeId = H5T.create(H5T.class_t.COMPOUND, new IntPtr(40));

            var strtype = H5T.copy(H5T.C_S1);

            H5T.set_size(strtype, new IntPtr(16));

            H5T.insert(typeId, "Name", new IntPtr(0), strtype);
            H5T.insert(typeId, "x_pos", new IntPtr(16), H5T.NATIVE_INT32);
            H5T.insert(typeId, "y_pos", new IntPtr(20), H5T.NATIVE_INT32);
            H5T.insert(typeId, "Mass", new IntPtr(24), H5T.NATIVE_FLOAT);
            H5T.insert(typeId, "Temperature", new IntPtr(32), H5T.NATIVE_DOUBLE);

            ulong[] dims       = new ulong[] { 10000 };
            ulong[] chunk_size = new ulong[] { 1000 };

            var spaceid = H5S.create_simple(dims.Length, dims, null);


            var dcpl = H5P.create(H5P.DATASET_CREATE);

            H5P.set_layout(dcpl, H5D.layout_t.COMPACT);
            H5P.set_deflate(dcpl, 6);

            H5P.set_chunk(dcpl, chunk_size.Length, chunk_size);



            var datasetid = H5D.create(h5, "Table1", typeId, spaceid, H5P.DEFAULT, dcpl);

            ComType ct = new ComType()
            {
                Name        = "aabb",
                x_pos       = 2,
                y_pos       = 1,
                Mass        = 1.24F,
                Temperature = 45.7,
            };

            IntPtr p = Marshal.AllocHGlobal(40 * (int)dims[0]);

            Marshal.StructureToPtr(ct, p, false);



            H5D.write(datasetid, typeId, spaceid, H5S.ALL, H5P.DEFAULT, p);

            H5F.close(h5);
        }
Ejemplo n.º 4
0
        public HDF5DataSet CreateDataset(string name, ulong[] shape, Type dType, long maxSize = 1,
                                         bool[] unlimited = null, ulong[] chunkShape = null, bool compress = false)
        {
            HDF5DataSet result = null;

            With((id) =>
            {
                int nDims = shape.Length;
                if (unlimited == null)
                {
                    unlimited = Enumerable.Range(0, nDims).Select(d => false).ToArray();
                }

                ulong[] maxShape =
                    Enumerable.Range(0, nDims).Select(d => unlimited[d] ? H5S.UNLIMITED : shape[d]).ToArray();
                var dataspaceID = H5S.create_simple(nDims, shape, maxShape);
                long dataTypeID = HDF5DataSet.OpenHDFDataType(dType, maxSize);

                long creationPropertyList = 0L;
                if (compress)
                {
                    if (chunkShape == null)
                    {
                        chunkShape = shape;
                    }

                    creationPropertyList = H5P.create(H5P.DATASET_CREATE);
                    H5P.set_layout(creationPropertyList, H5D.layout_t.CHUNKED);
                    H5P.set_deflate(creationPropertyList, 9);
                    H5P.set_chunk(creationPropertyList, shape.Length, chunkShape);
                }

                var newID = H5D.create(id, name, dataTypeID, dataspaceID, 0L, creationPropertyList, 0L);

                if (creationPropertyList > 0)
                {
                    H5P.close(creationPropertyList);
                }
                H5T.close(dataTypeID);
                H5S.close(dataspaceID);

                if (newID <= 0)
                {
                    throw new H5SSException("Couldn't create DataSet");
                }

                // write!
                H5D.close(newID);
                result = new HDF5DataSet(name, this);
            });
            return(result);
        }
Ejemplo n.º 5
0
        public static (long DatasetId, bool IsNew) OpenOrCreateDataset(long locationId, string datasetPath, long datasetTypeId, ulong chunkLength, ulong chunkCount, IntPtr fillValue = default)
        {
            return(IOHelper.OpenOrCreateDataset(locationId, datasetPath, datasetTypeId, () =>
            {
                long dcPropertyId = -1;
                long lcPropertyId = -1;
                long dataspaceId = -1;
                long datasetId = -1;

                try
                {
                    dcPropertyId = H5P.create(H5P.DATASET_CREATE);

                    if (fillValue != IntPtr.Zero)
                    {
                        H5P.set_fill_value(dcPropertyId, datasetTypeId, fillValue);
                    }

                    H5P.set_shuffle(dcPropertyId);
                    H5P.set_deflate(dcPropertyId, 7);
                    H5P.set_chunk(dcPropertyId, 1, new ulong[] { chunkLength });

                    lcPropertyId = H5P.create(H5P.LINK_CREATE);
                    H5P.set_create_intermediate_group(lcPropertyId, 1);

                    dataspaceId = H5S.create_simple(1, new ulong[] { chunkLength *chunkCount }, null);
                    datasetId = H5D.create(locationId, datasetPath, datasetTypeId, dataspaceId, lcPropertyId, dcPropertyId);

                    if (H5I.is_valid(datasetId) <= 0)
                    {
                        throw new Exception($"{ ErrorMessage.IOHelper_CouldNotOpenOrCreateDataset } Dataset: '{ datasetPath }'.");
                    }
                }
                finally
                {
                    if (H5I.is_valid(dcPropertyId) > 0)
                    {
                        H5P.close(dcPropertyId);
                    }
                    if (H5I.is_valid(lcPropertyId) > 0)
                    {
                        H5P.close(lcPropertyId);
                    }
                    if (H5I.is_valid(dataspaceId) > 0)
                    {
                        H5S.close(dataspaceId);
                    }
                }

                return datasetId;
            }));
        }
Ejemplo n.º 6
0
        public static unsafe void AddFilteredDataset_Multi(long fileId)
        {
            long res;

            var length  = (ulong)TestData.MediumData.Length / 4;
            var dims    = new ulong[] { length, 4 };
            var dcpl_id = H5P.create(H5P.DATASET_CREATE);

            res = H5P.set_chunk(dcpl_id, 2, new ulong[] { 1000, 4 });
            res = H5P.set_fletcher32(dcpl_id);
            res = H5P.set_shuffle(dcpl_id);
            res = H5P.set_deflate(dcpl_id, level: 5);

            TestUtils.Add(ContainerType.Dataset, fileId, "filtered", $"multi", H5T.NATIVE_INT32, TestData.MediumData.AsSpan(), dims, cpl: dcpl_id);
        }
Ejemplo n.º 7
0
        public void H5PglobalsTest1()
        {
            hsize_t[] dims     = { 10, 10, 10 };
            hsize_t[] max_dims = { H5S.UNLIMITED, H5S.UNLIMITED, H5S.UNLIMITED };
            hid_t     space    = H5S.create_simple(3, dims, max_dims);

            hid_t lcpl = H5P.create(H5P.LINK_CREATE);

            Assert.IsTrue(H5P.set_create_intermediate_group(lcpl, 1) >= 0);

            hid_t dcpl = H5P.create(H5P.DATASET_CREATE);

            Assert.IsTrue(dcpl >= 0);
            hsize_t[] chunk = { 64, 64, 64 };
            Assert.IsTrue(H5P.set_chunk(dcpl, 3, chunk) >= 0);
            Assert.IsTrue(H5P.set_deflate(dcpl, 9) >= 0);

            hid_t dset = H5D.create(m_v0_test_file, "A/B/C", H5T.IEEE_F32BE,
                                    space, lcpl, dcpl);

            Assert.IsTrue(dset >= 0);

            hid_t plist = H5D.get_create_plist(dset);

            Assert.IsTrue(H5D.layout_t.CHUNKED == H5P.get_layout(plist));
            Assert.IsTrue(H5P.close(plist) >= 0);

            Assert.IsTrue(H5D.close(dset) >= 0);

            dset = H5D.create(m_v2_test_file, "A/B/C", H5T.IEEE_F32BE,
                              space, lcpl, dcpl);
            Assert.IsTrue(dset >= 0);

            plist = H5D.get_create_plist(dset);
            Assert.IsTrue(H5D.layout_t.CHUNKED == H5P.get_layout(plist));
            Assert.IsTrue(H5P.close(plist) >= 0);

            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5P.close(lcpl) >= 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 8
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);
        }