Ejemplo n.º 1
0
        /// <summary>
        /// Create a temporary HDF5 file IN MEMORY and return its name and
        /// a file handle.
        /// </summary>
        public static hid_t H5TempFile(ref string fileName,
                                       H5F.libver_t version = H5F.libver_t.LATEST,
                                       bool backing_store   = false)
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            if (fapl < 0)
            {
                throw new ApplicationException("H5P.create failed.");
            }
            if (H5P.set_libver_bounds(fapl, version) < 0)
            {
                throw new ApplicationException("H5P.set_libver_bounds failed.");
            }
            // use the core VFD, 64K increments, no backing store
            if (H5P.set_fapl_core(fapl, new IntPtr(65536),
                                  (uint)(backing_store ? 1 : 0)) < 0)
            {
                throw new ApplicationException("H5P.set_fapl_core failed.");
            }
            fileName = Path.GetTempFileName();
            hid_t file = H5F.create(fileName, H5F.ACC_TRUNC, H5P.DEFAULT, fapl);

            if (file < 0)
            {
                throw new ApplicationException("H5F.create failed.");
            }
            if (H5P.close(fapl) < 0)
            {
                throw new ApplicationException("H5P.close failed.");
            }
            return(file);
        }
Ejemplo n.º 2
0
        public void CanReadDataset_Chunked_Legacy()
        {
            var versions = new H5F.libver_t[]
            {
                H5F.libver_t.EARLIEST,
                H5F.libver_t.V18
            };

            TestUtils.RunForVersions(versions, version =>
            {
                foreach (var withShuffle in new bool[] { false, true })
                {
                    // Arrange
                    var filePath = TestUtils.PrepareTestFile(version, fileId => TestUtils.AddChunkedDataset_Legacy(fileId, withShuffle));

                    // Act
                    using var root = H5File.OpenReadCore(filePath, deleteOnClose: true);
                    var parent     = root.Group("chunked");
                    var dataset    = parent.Dataset("chunked");
                    var actual     = dataset.Read <int>();

                    // Assert
                    Assert.True(actual.SequenceEqual(TestData.MediumData));
                }
            });
        }
Ejemplo n.º 3
0
        public static unsafe void AddHuge(long fileId, ContainerType container, H5F.libver_t version)
        {
            var length = version switch
            {
                H5F.libver_t.EARLIEST => 16368UL, // max 64 kb in object header
                _ => (ulong)TestData.HugeData.Length,
            };

            TestUtils.Add(container, fileId, "huge", "huge", H5T.NATIVE_INT32, TestData.HugeData.AsSpan(), length);
        }
Ejemplo n.º 4
0
        public static void RunForAllVersions(Action <H5F.libver_t> action)
        {
            var versions = new H5F.libver_t[]
            {
                H5F.libver_t.EARLIEST,
                H5F.libver_t.V18,
                H5F.libver_t.V110
            };

            foreach (var version in versions)
            {
                action(version);
            }
        }
Ejemplo n.º 5
0
        public static unsafe string PrepareTestFile(H5F.libver_t version, Action <long> action)
        {
            var  filePath = Path.GetTempFileName();
            long res;

            // file
            var faplId = H5P.create(H5P.FILE_ACCESS);

            res = H5P.set_libver_bounds(faplId, version, version);
            var fileId = H5F.create(filePath, H5F.ACC_TRUNC, 0, faplId);

            action?.Invoke(fileId);
            res = H5F.close(fileId);

            return(filePath);
        }