Ejemplo n.º 1
0
        public void H5Pset_append_flushTestSWMR2()
        {
            hid_t dapl = H5P.create(H5P.DATASET_ACCESS);

            Assert.IsTrue(dapl >= 0);

            hsize_t[] boundary = { 1, 1 };

            H5D.append_cb_t cb = append_func;

            Assert.IsTrue(
                H5P.set_append_flush(dapl, 2, boundary, cb, IntPtr.Zero) >= 0);

            hsize_t[] check_boundary = { 0, 0, 0 };

            H5D.append_cb_t check_cb = null;

            IntPtr check_ptr = new IntPtr(4711);

            Assert.IsTrue(
                H5P.get_append_flush(dapl, 2, check_boundary, ref check_cb,
                                     ref check_ptr) >= 0);

            Assert.IsTrue(check_boundary[0] == 1);
            Assert.IsTrue(check_boundary[1] == 1);
            Assert.IsTrue(check_boundary[2] == 0);

            Assert.IsTrue(check_cb == cb);

            Assert.IsTrue(check_ptr == IntPtr.Zero);

            Assert.IsTrue(H5P.close(dapl) >= 0);
        }
Ejemplo n.º 2
0
        public void H5Pget_virtual_vspaceTestVDS1()
        {
            hid_t vds = H5D.open(m_vds_class_file, "VDS");

            Assert.IsTrue(vds >= 0);

            hid_t dcpl = H5D.get_create_plist(vds);

            Assert.IsTrue(dcpl >= 0);

            IntPtr count = IntPtr.Zero;

            Assert.IsTrue(H5P.get_virtual_count(dcpl, ref count) >= 0);
            Assert.IsTrue(3 == count.ToInt32());

            for (int i = 0; i < count.ToInt32(); ++i)
            {
                size_t index  = new size_t(i);
                hid_t  vspace = H5P.get_virtual_vspace(dcpl, index);
                Assert.IsTrue(vspace >= 0);

                Assert.IsTrue(H5S.is_regular_hyperslab(vspace) > 0);

                Assert.IsTrue(H5S.close(vspace) >= 0);
            }

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5D.close(vds) >= 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Dispose function as suggested in the stackoverflow discussion below
        /// See: http://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface/538238#538238
        /// </summary>
        /// <param name="itIsSafeToAlsoFreeManagedObjects"></param>
        protected virtual void Dispose(bool itIsSafeToAlsoFreeManagedObjects)
        {
            if (!Hdf5Utils.GetRealName(GroupId, Datasetname, string.Empty).valid)
            {
                Hdf5Utils.LogInfo?.Invoke("Dataset does not exist.");
                return;
            }

            if (_datasetId >= 0)
            {
                H5D.close(_datasetId);
            }

            if (_propId >= 0)
            {
                H5P.close(_propId);
            }

            if (_spaceId >= 0)
            {
                H5S.close(_spaceId);
            }

            if (itIsSafeToAlsoFreeManagedObjects)
            {
            }
        }
Ejemplo n.º 4
0
        public void H5Pget_virtual_dsetnameTestVDS1()
        {
            hid_t vds = H5D.open(m_vds_class_file, "VDS");

            Assert.IsTrue(vds >= 0);

            hid_t dcpl = H5D.get_create_plist(vds);

            Assert.IsTrue(dcpl >= 0);

            IntPtr count = IntPtr.Zero;

            Assert.IsTrue(H5P.get_virtual_count(dcpl, ref count) >= 0);
            Assert.IsTrue(3 == count.ToInt32());

            string[] names = { "A", "B", "C" };

            for (int i = 0; i < count.ToInt32(); ++i)
            {
                size_t  index = new ssize_t(i);
                ssize_t len   = H5P.get_virtual_filename(dcpl, index, null,
                                                         IntPtr.Zero);
                Assert.IsTrue(len.ToInt32() > 0);
                StringBuilder name = new StringBuilder(len.ToInt32() + 1);
                len = H5P.get_virtual_dsetname(dcpl, index, name, len + 1);
                Assert.IsTrue(len.ToInt32() > 0);
                Assert.IsTrue(name.ToString() == names[i]);
            }

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5D.close(vds) >= 0);
        }
Ejemplo n.º 5
0
        public void H5DflushTestSWMR2()
        {
            hsize_t[] dims       = { 6, 6 };
            hsize_t[] maxdims    = { 6, H5S.UNLIMITED };
            hsize_t[] chunk_dims = { 2, 5 };
            int[]     cbuf       = new int[36];

            hid_t dsp = H5S.create_simple(2, dims, maxdims);

            Assert.IsTrue(dsp >= 0);

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

            Assert.IsTrue(dcpl >= 0);
            Assert.IsTrue(H5P.set_chunk(dcpl, 2, chunk_dims) >= 0);

            hid_t dst = H5D.create(m_v3_test_file_swmr, "dset",
                                   H5T.NATIVE_INT, dsp, H5P.DEFAULT, dcpl);

            Assert.IsTrue(dst >= 0);

            GCHandle hnd = GCHandle.Alloc(cbuf, GCHandleType.Pinned);

            Assert.IsTrue(H5D.write(dst, H5T.NATIVE_INT, H5S.ALL, H5S.ALL,
                                    H5P.DEFAULT, hnd.AddrOfPinnedObject()) >= 0);

            hnd.Free();

            Assert.IsTrue(H5D.flush(dst) >= 0);

            Assert.IsTrue(H5D.close(dst) >= 0);
            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5S.close(dsp) >= 0);
        }
Ejemplo n.º 6
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.º 7
0
        public void H5Dget_storage_sizeTest1()
        {
            hsize_t[] dims  = { 1024, 2048 };
            hid_t     space = H5S.create_simple(2, dims, null);

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

            Assert.IsTrue(dcpl >= 0);
            Assert.IsTrue(
                H5P.set_alloc_time(dcpl, H5D.alloc_time_t.EARLY) >= 0);

            hid_t dset = H5D.create(m_v0_test_file, "dset", H5T.STD_I16LE,
                                    space, H5P.DEFAULT, dcpl);

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

            dset = H5D.create(m_v2_test_file, "dset", H5T.STD_I16LE,
                              space, H5P.DEFAULT, dcpl);
            Assert.IsTrue(dset >= 0);
            Assert.IsTrue(H5D.get_storage_size(dset) == 4194304);
            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 8
0
        public void H5DOappendTestSWMR2()
        {
            hsize_t[] dims       = { 0 };
            hsize_t[] maxdims    = { H5S.UNLIMITED };
            hsize_t[] chunk_dims = { 10 };
            uint[]    cbuf       = { 123, 456, 789 };

            hid_t dsp = H5S.create_simple(1, dims, maxdims);

            Assert.IsTrue(dsp >= 0);

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

            Assert.IsTrue(dcpl >= 0);
            Assert.IsTrue(H5P.set_chunk(dcpl, 1, chunk_dims) >= 0);

            hid_t dst = H5D.create(m_v3_test_file_no_swmr, "dset1",
                                   H5T.NATIVE_UINT, dsp, H5P.DEFAULT, dcpl, H5P.DEFAULT);

            Assert.IsTrue(dst >= 0);

            GCHandle hnd = GCHandle.Alloc(cbuf, GCHandleType.Pinned);

            Assert.IsTrue(
                H5DO.append(dst, H5P.DEFAULT, 0, new IntPtr(3),
                            H5T.NATIVE_UINT, hnd.AddrOfPinnedObject()) >= 0);

            hnd.Free();

            Assert.IsTrue(H5D.close(dst) >= 0);
            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5S.close(dsp) >= 0);
        }
Ejemplo n.º 9
0
        public void H5Pset_mdc_image_configTest1()
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            Assert.IsTrue(fapl >= 0);

            Assert.IsTrue(H5P.set_libver_bounds(fapl, H5F.libver_t.LATEST) >= 0);

            H5AC.cache_image_config_t conf = new H5AC.cache_image_config_t();
            conf.version      = H5AC.CURR_CACHE_IMAGE_CONFIG_VERSION;
            conf.entry_ageout = H5AC.CACHE_IMAGE__ENTRY_AGEOUT__NONE;

            IntPtr config_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(conf));

            Marshal.StructureToPtr(conf, config_ptr, false);

            H5AC.cache_image_config_t conf1 = new H5AC.cache_image_config_t();

            conf1 = (H5AC.cache_image_config_t)Marshal.PtrToStructure(
                config_ptr, typeof(H5AC.cache_image_config_t));

            //Assert.IsTrue(H5P.set_mdc_image_config(fapl, config_ptr) >= 0);

            Assert.IsTrue(H5P.close(fapl) >= 0);
            Marshal.FreeHGlobal(config_ptr);
        }
Ejemplo n.º 10
0
        public void H5Pset_object_flush_cbTestSWMR2()
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            Assert.IsTrue(fapl >= 0);

            H5F.flush_cb_t cb = flush_func;

            Assert.IsTrue(
                H5P.set_object_flush_cb(fapl, cb, IntPtr.Zero) >= 0);

            H5F.flush_cb_t check_cb = null;

            IntPtr check_ptr = new IntPtr(4711);

            Assert.IsTrue(
                H5P.get_object_flush_cb(fapl, ref check_cb,
                                        ref check_ptr) >= 0);

            Assert.IsTrue(check_cb == cb);

            Assert.IsTrue(check_ptr == IntPtr.Zero);

            Assert.IsTrue(H5P.close(fapl) >= 0);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create a temporary HDF5 with SWMR access and return
        /// its name and a file handle.
        /// </summary>
        public static hid_t H5TempFileSWMR(ref string fileName)
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            if (fapl < 0)
            {
                throw new ApplicationException("H5P.create failed.");
            }
            if (H5P.set_libver_bounds(fapl, H5F.libver_t.LATEST) < 0)
            {
                throw new ApplicationException("H5P.set_libver_bounds failed.");
            }
            if (H5P.set_fclose_degree(fapl, H5F.close_degree_t.STRONG) < 0)
            {
                throw new ApplicationException("H5P.set_fclose_degree failed.");
            }
            fileName = Path.GetTempFileName();
            hid_t file = H5F.create(fileName, H5F.ACC_TRUNC | H5F.ACC_SWMR_WRITE,
                                    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.º 12
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.º 13
0
        // information: https://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/hdf5-examples/1_8/C/H5T/h5ex_t_cmpd.c
        //or: https://www.hdfgroup.org/HDF5/doc/UG/HDF5_Users_Guide-Responsive%20HTML5/index.html#t=HDF5_Users_Guide%2FDatatypes%2FHDF5_Datatypes.htm%3Frhtocid%3Dtoc6.5%23TOC_6_8_Complex_Combinationsbc-22

        public static int WriteCompounds <T>(hid_t groupId, string name, IEnumerable <T> list) //where T : struct
        {
            Type type = typeof(T);
            var  size = Marshal.SizeOf(type);
            var  cnt  = list.Count();

            var typeId = create_type(type);

            var   log10 = (int)Math.Log10(cnt);
            ulong pow   = (ulong)Math.Pow(10, log10);
            ulong c_s   = Math.Min(1000, pow);

            ulong[] chunk_size = new ulong[] { c_s };

            ulong[] dims = new ulong[] { (ulong)cnt };

            long dcpl = 0;

            if (list.Count() == 0 || log10 == 0)
            {
            }
            else
            {
                dcpl = create_property(chunk_size);
            }

            // Create dataspace.  Setting maximum size to NULL sets the maximum
            // size to be the current size.
            var spaceId = H5S.create_simple(dims.Length, dims, null);

            // Create the dataset and write the compound data to it.
            var datasetId = H5D.create(groupId, name, typeId, spaceId, H5P.DEFAULT, dcpl);

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

            var          ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            foreach (var strct in list)
            {
                writer.Write(getBytes(strct));
            }
            var bytes = ms.ToArray();

            GCHandle hnd      = GCHandle.Alloc(bytes, GCHandleType.Pinned);
            var      statusId = H5D.write(datasetId, typeId, spaceId, H5S.ALL,
                                          H5P.DEFAULT, hnd.AddrOfPinnedObject());

            hnd.Free();

            /*
             * Close and release resources.
             */
            H5D.close(datasetId);
            H5S.close(spaceId);
            H5T.close(typeId);
            H5P.close(dcpl);
            Marshal.FreeHGlobal(p);
            return(statusId);
        }
Ejemplo n.º 14
0
        public void H5Lget_name_by_idxTest2()
        {
            hid_t lcpl = H5P.copy(m_lcpl);

            Assert.IsTrue(lcpl >= 0);
            Assert.IsTrue(H5P.set_char_encoding(lcpl, H5T.cset_t.UTF8) >= 0);

            for (int i = 0; i < m_utf8strings.Length; ++i)
            {
                Assert.IsTrue(
                    H5L.create_external(m_v0_class_file_name, "/",
                                        m_v0_class_file, m_utf8strings[i], lcpl) >= 0);
            }

            for (int i = 0; i < m_utf8strings.Length; ++i)
            {
                size_t  buf_size = IntPtr.Zero;
                ssize_t size     = H5L.get_name_by_idx(m_v0_test_file, ".",
                                                       H5.index_t.NAME, H5.iter_order_t.NATIVE, (hsize_t)i, null,
                                                       buf_size);
                buf_size = new IntPtr(size.ToInt32() + 1);
                StringBuilder nameBuilder = new StringBuilder(buf_size.ToInt32());
                size = H5L.get_name_by_idx(m_v0_test_file, ".",
                                           H5.index_t.NAME, H5.iter_order_t.NATIVE, (hsize_t)i, nameBuilder,
                                           buf_size);
            }

            Assert.IsTrue(H5P.close(lcpl) >= 0);
        }
Ejemplo n.º 15
0
        public static unsafe void AddExternalDataset(long fileId, string datasetName, string absolutePrefix, H5DatasetAccess datasetAccess)
        {
            long res;

            var bytesoftype = 4;
            var dcpl_id     = H5P.create(H5P.DATASET_CREATE);
            var dapl_id     = H5P.create(H5P.DATASET_ACCESS);

            res = H5P.set_layout(dcpl_id, H5D.layout_t.CONTIGUOUS);

            // a (more than one chunk in file)
            var pathA = H5Utils.ConstructExternalFilePath(Path.Combine(absolutePrefix, $"{datasetName}_a.raw"), datasetAccess);

            if (File.Exists(pathA))
            {
                File.Delete(pathA);
            }

            res = H5P.set_external(dcpl_id, pathA, new IntPtr(120), (ulong)(10 * bytesoftype));
            res = H5P.set_external(dcpl_id, pathA, new IntPtr(80), (ulong)(10 * bytesoftype));
            res = H5P.set_external(dcpl_id, pathA, new IntPtr(0), (ulong)(10 * bytesoftype));

            // b (file size smaller than set size)
            var pathB = H5Utils.ConstructExternalFilePath(Path.Combine(absolutePrefix, $"{datasetName}_b.raw"), datasetAccess);

            if (File.Exists(pathB))
            {
                File.Delete(pathB);
            }

            res = H5P.set_external(dcpl_id, pathB, new IntPtr(0), (ulong)(10 * bytesoftype));

            // c (normal file)
            var pathC = H5Utils.ConstructExternalFilePath(Path.Combine(absolutePrefix, $"{datasetName}_c.raw"), datasetAccess);

            if (File.Exists(pathC))
            {
                File.Delete(pathC);
            }

            res = H5P.set_external(dcpl_id, pathC, new IntPtr(0), (ulong)((TestData.MediumData.Length - 40) * bytesoftype));

            // write data
            if (datasetAccess.ExternalFilePrefix is not null)
            {
                H5P.set_efile_prefix(dapl_id, datasetAccess.ExternalFilePrefix);
            }

            TestUtils.Add(ContainerType.Dataset, fileId, "external", datasetName, H5T.NATIVE_INT32, TestData.MediumData.AsSpan(), apl: dapl_id, cpl: dcpl_id);

            // truncate file b
            using (var fileStream2 = File.OpenWrite(pathB))
            {
                fileStream2.SetLength(10);
            };

            res = H5P.close(dapl_id);
            res = H5P.close(dcpl_id);
        }
Ejemplo n.º 16
0
        public void H5Pset_evict_on_closeTest2()
        {
            hid_t fcpl = H5P.create(H5P.FILE_CREATE);

            Assert.IsTrue(fcpl >= 0);
            Assert.IsFalse(H5P.set_evict_on_close(fcpl, 1) >= 0);
            Assert.IsTrue(H5P.close(fcpl) >= 0);
        }
Ejemplo n.º 17
0
        public void H5Pset_evict_on_closeTest1()
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            Assert.IsTrue(fapl >= 0);
            Assert.IsTrue(H5P.set_evict_on_close(fapl, 1) >= 0);
            Assert.IsTrue(H5P.close(fapl) >= 0);
        }
Ejemplo n.º 18
0
        public void H5Pset_userblockTest1()
        {
            hid_t fcpl = H5P.create(H5P.FILE_CREATE);

            Assert.IsTrue(fcpl >= 0);
            Assert.IsTrue(H5P.set_userblock(fcpl, 1024) >= 0);
            Assert.IsTrue(H5P.close(fcpl) >= 0);
        }
Ejemplo n.º 19
0
        public void H5Fget_create_plistTest1()
        {
            hid_t fcpl = H5F.get_create_plist(m_v0_class_file);

            Assert.IsTrue(fcpl >= 0);
            Assert.IsTrue(H5P.close(fcpl) >= 0);
            fcpl = H5F.get_create_plist(m_v2_class_file);
            Assert.IsTrue(fcpl >= 0);
            Assert.IsTrue(H5P.close(fcpl) >= 0);
        }
Ejemplo n.º 20
0
        public void H5Fget_access_plistTest1()
        {
            hid_t fapl = H5F.get_access_plist(m_v0_class_file);

            Assert.IsTrue(fapl >= 0);
            Assert.IsTrue(H5P.close(fapl) >= 0);
            fapl = H5F.get_access_plist(m_v2_class_file);
            Assert.IsTrue(fapl >= 0);
            Assert.IsTrue(H5P.close(fapl) >= 0);
        }
Ejemplo n.º 21
0
        public static unsafe void AddCompactDataset(long fileId)
        {
            long res;

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

            res = H5P.set_layout(dcpl_id, H5D.layout_t.COMPACT);
            TestUtils.Add(ContainerType.Dataset, fileId, "compact", "compact", H5T.NATIVE_INT32, TestData.SmallData.AsSpan(), cpl: dcpl_id);
            res = H5P.close(dcpl_id);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Dispose function as suggested in the stackoverflow discussion below
        /// See: http://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface/538238#538238
        /// </summary>
        /// <param name="itIsSafeToAlsoFreeManagedObjects"></param>
        protected virtual void Dispose(bool itIsSafeToAlsoFreeManagedObjects)
        {
            H5D.close(datasetId);
            H5P.close(propId);
            H5S.close(spaceId);

            if (itIsSafeToAlsoFreeManagedObjects)
            {
            }
        }
Ejemplo n.º 23
0
 public static void ClassCleanup()
 {
     Assert.IsTrue(H5P.close(m_acpl) >= 0);
     // close the global test files
     Assert.IsTrue(H5F.close(m_v0_class_file) >= 0);
     Assert.IsTrue(H5F.close(m_v2_class_file) >= 0);
     Assert.IsTrue(H5S.close(m_space_null) >= 0);
     Assert.IsTrue(H5S.close(m_space_scalar) >= 0);
     File.Delete(m_v0_class_file_name);
     File.Delete(m_v2_class_file_name);
 }
Ejemplo n.º 24
0
        public static void ClassCleanup()
        {
            Assert.IsTrue(H5P.close(m_lcpl) >= 0);
            Assert.IsTrue(H5P.close(m_lcpl_utf8) >= 0);

            // close the global test files
            Assert.IsTrue(H5F.close(m_v0_class_file) >= 0);
            Assert.IsTrue(H5F.close(m_v2_class_file) >= 0);
            File.Delete(m_v0_class_file_name);
            File.Delete(m_v2_class_file_name);
        }
Ejemplo n.º 25
0
        public static void ClassCleanup()
        {
#if HDF5_VER1_10
            Assert.IsTrue(H5P.close(m_lcpl) >= 0);
            Assert.IsTrue(H5P.close(m_lcpl_utf8) >= 0);

            // close the global test files
            Assert.IsTrue(H5F.close(m_v3_class_file) >= 0);
            File.Delete(m_v3_class_file_name);
#endif
        }
Ejemplo n.º 26
0
        public void H5Pset_userblockTest3()
        {
            hid_t fcpl = H5P.create(H5P.FILE_CREATE);

            Assert.IsTrue(fcpl >= 0);
            Assert.IsTrue(H5P.set_userblock(fcpl, 0) >= 0);
            Assert.IsFalse(H5P.set_userblock(fcpl, 111) >= 0);
            Assert.IsTrue(H5P.set_userblock(fcpl, 512) >= 0);
            Assert.IsFalse(H5P.set_userblock(fcpl, 513) >= 0);
            Assert.IsTrue(H5P.close(fcpl) >= 0);
        }
Ejemplo n.º 27
0
        public static void ClassInit(TestContext testContext)
        {
            hid_t fapl = H5P.create(H5P.FILE_ACCESS);

            Assert.IsTrue(fapl >= 0);
            Assert.IsTrue(
                H5P.set_libver_bounds(fapl, H5F.libver_t.LATEST) >= 0);
            m_shared_file_id = H5F.create(m_shared_file_name, H5F.ACC_TRUNC,
                                          H5P.DEFAULT, fapl);
            Assert.IsTrue(H5P.close(fapl) >= 0);
        }
Ejemplo n.º 28
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.º 29
0
        static void test_attr_plist()
        {
            try
            {
                Console.Write("Testing attribute property lists");
                hssize_t[] dims = { 256, 512 };

                const string PLST_FILE_NAME = ("tattr_plist.h5");
                hssize_t[]   dims1          = { SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3 };
                hssize_t[]   dims2          = { ATTR1_DIM };

                // Create file.
                H5FileId fileId = H5F.create(PLST_FILE_NAME, H5F.CreateMode.ACC_TRUNC);

                // Create dataspace for dataset.
                H5DataSpaceId space1_Id = H5S.create_simple(SPACE1_RANK, dims1);

                // Create a dataset.
                H5DataSetId dsetId = H5D.create(fileId, DSET1_NAME, H5T.H5Type.NATIVE_UCHAR, space1_Id);

                // Create dataspace for attribute.
                H5DataSpaceId space2_Id = H5S.create_simple(ATTR1_RANK, dims2);

                // Create default property list for attribute.
                H5PropertyListId plist
                    = H5P.create(H5P.PropertyListClass.ATTRIBUTE_CREATE);

                // Create an attribute for the dataset using the property list.
                H5AttributeId attrId = H5A.create(dsetId, ATTR1_NAME, new H5DataTypeId(H5T.H5Type.NATIVE_INT), space2_Id, plist);

                // Close all objects.
                H5S.close(space1_Id);
                H5S.close(space2_Id);
                H5P.close(plist);
                H5A.close(attrId);
                H5D.close(dsetId);
                H5F.close(fileId);

                Console.WriteLine("\t\t\tPASSED");
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
        } // test_attr_plist
Ejemplo n.º 30
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);
        }