Esempio n. 1
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;
            }));
        }
Esempio n. 2
0
        public static unsafe void AddChunkedDatasetWithFillValueAndAllocationLate(long fileId, int fillValue)
        {
            long res;

            var length  = (ulong)TestData.MediumData.Length;
            var dcpl_id = H5P.create(H5P.DATASET_CREATE);

            res = H5P.set_alloc_time(dcpl_id, H5D.alloc_time_t.LATE);
            res = H5P.set_chunk(dcpl_id, 1, new ulong[] { 1000 });

            var handle = GCHandle.Alloc(BitConverter.GetBytes(fillValue), GCHandleType.Pinned);

            H5P.set_fill_value(dcpl_id, H5T.NATIVE_INT, handle.AddrOfPinnedObject());
            handle.Free();

            TestUtils.Add(ContainerType.Dataset, fileId, "fillvalue", $"{LayoutClass.Chunked}", H5T.NATIVE_INT32, (void *)0, length, cpl: dcpl_id);
            res = H5P.close(dcpl_id);
        }
Esempio n. 3
0
        private static void createVDS()
        {
            // create files
            m_a_class_file = Utilities.H5TempFile(ref m_a_class_file_name,
                                                  H5F.libver_t.LATEST, true);
            Assert.IsTrue(m_a_class_file >= 0);
            m_b_class_file = Utilities.H5TempFile(ref m_b_class_file_name,
                                                  H5F.libver_t.LATEST, true);
            Assert.IsTrue(m_b_class_file >= 0);
            m_c_class_file = Utilities.H5TempFile(ref m_c_class_file_name,
                                                  H5F.libver_t.LATEST, true);
            Assert.IsTrue(m_c_class_file >= 0);
            m_vds_class_file = Utilities.H5TempFile(ref m_vds_class_file_name);
            Assert.IsTrue(m_vds_class_file >= 0);

            //
            // create target datasets
            //
            hid_t dcpl = H5P.create(H5P.DATASET_CREATE);

            Assert.IsTrue(dcpl >= 0);
            int      fill_value = 1;
            GCHandle hnd        = GCHandle.Alloc(fill_value, GCHandleType.Pinned);

            Assert.IsTrue(H5P.set_fill_value(dcpl, H5T.NATIVE_INT,
                                             hnd.AddrOfPinnedObject()) >= 0);

            hsize_t[] dims    = { 6 };
            hid_t     src_dsp = H5S.create_simple(1, dims, null);

            // A
            fill_value = 1;
            hid_t a = H5D.create(m_a_class_file, "A", H5T.STD_I32LE, src_dsp);

            Assert.IsTrue(a >= 0);
            Assert.IsTrue(H5D.close(a) >= 0);
            // B
            fill_value = 2;
            hid_t b = H5D.create(m_b_class_file, "B", H5T.STD_I32LE, src_dsp);

            Assert.IsTrue(b >= 0);
            Assert.IsTrue(H5D.close(b) >= 0);
            // B
            fill_value = 3;
            hid_t c = H5D.create(m_c_class_file, "C", H5T.STD_I32LE, src_dsp);

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

            //
            // create the VDS
            //
            fill_value = -1;
            hsize_t[] vds_dims = { 4, 6 };
            hid_t     vds_dsp  = H5S.create_simple(2, vds_dims, null);

            hsize_t[] start = { 0, 0 };
            hsize_t[] count = { 1, 1 };
            hsize_t[] block = { 1, 6 };

            start[0] = 0;
            Assert.IsTrue(H5S.select_hyperslab(vds_dsp, H5S.seloper_t.SET,
                                               start, null, count, block) >= 0);
            Assert.IsTrue(H5P.set_virtual(dcpl, vds_dsp,
                                          m_a_class_file_name, "A", src_dsp) >= 0);

            start[0] = 1;
            Assert.IsTrue(H5S.select_hyperslab(vds_dsp, H5S.seloper_t.SET,
                                               start, null, count, block) >= 0);
            Assert.IsTrue(H5P.set_virtual(dcpl, vds_dsp,
                                          m_b_class_file_name, "B", src_dsp) >= 0);

            start[0] = 2;
            Assert.IsTrue(H5S.select_hyperslab(vds_dsp, H5S.seloper_t.SET,
                                               start, null, count, block) >= 0);
            Assert.IsTrue(H5P.set_virtual(dcpl, vds_dsp,
                                          m_c_class_file_name, "C", src_dsp) >= 0);

            hid_t vds = H5D.create(m_vds_class_file, "VDS", H5T.STD_I32LE,
                                   vds_dsp, H5P.DEFAULT, dcpl, H5P.DEFAULT);

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

            Assert.IsTrue(H5S.close(vds_dsp) >= 0);
            Assert.IsTrue(H5S.close(src_dsp) >= 0);
            Assert.IsTrue(H5P.close(dcpl) >= 0);

            hnd.Free();

            // close the satellite files
            Assert.IsTrue(H5F.close(m_a_class_file) >= 0);
            Assert.IsTrue(H5F.close(m_b_class_file) >= 0);
            Assert.IsTrue(H5F.close(m_c_class_file) >= 0);
        }