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

            Assert.IsTrue(H5S.select_all(space) >= 0);

            double[] v    = new double[10];
            double   fill = 1.0;

            GCHandle v_hnd    = GCHandle.Alloc(v, GCHandleType.Pinned);
            GCHandle fill_hnd = GCHandle.Alloc(fill, GCHandleType.Pinned);

            Assert.IsTrue(
                H5D.fill(fill_hnd.AddrOfPinnedObject(), H5T.NATIVE_DOUBLE,
                         v_hnd.AddrOfPinnedObject(), H5T.NATIVE_DOUBLE, space) >= 0);
            fill_hnd.Free();
            v_hnd.Free();

            for (int i = 0; i < v.Length; ++i)
            {
                Assert.IsTrue(v[i] == 1.0);
            }

            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 2
0
        public void H5DiterateTest1()
        {
            int[] buf = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            IntPtr count_ptr = Marshal.AllocHGlobal(sizeof(int));

            Marshal.WriteInt32(count_ptr, 0);

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

            Assert.IsTrue(space >= 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);

            GCHandle buf_hnd = GCHandle.Alloc(buf, GCHandleType.Pinned);

            H5D.operator_t cb = DelegateMethod;
            Assert.IsTrue(
                H5D.iterate(buf_hnd.AddrOfPinnedObject(), H5T.NATIVE_INT,
                            space, cb, count_ptr) >= 0);

            buf_hnd.Free();

            int count = Marshal.ReadInt32(count_ptr);

            // expect the sum of the buffer elements
            Assert.IsTrue(count == 45);

            Assert.IsTrue(H5S.close(space) >= 0);
            Marshal.FreeHGlobal(count_ptr);
        }
Ejemplo n.º 3
0
        public void H5Sselect_allTest4()
        {
            hid_t space = H5S.create(H5S.class_t.SCALAR);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);
            Assert.IsTrue(H5S.get_select_npoints(space) == 1);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 4
0
        public void H5Sget_select_npointsTest3()
        {
            hid_t space = H5S.create(H5S.class_t.NULL);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);
            Assert.IsTrue(H5S.get_select_npoints(space) == 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 5
0
        public void H5Sselect_allTest1()
        {
            hsize_t[] dims  = { 1, 2, 3 };
            hid_t     space = H5S.create_simple(dims.Length, dims, null);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);
            Assert.IsTrue(H5S.get_select_npoints(space) == 6);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 6
0
        public void H5Dget_chunk_infoTest1()
        {
            hsize_t[] dims     = { 10, 10 };
            hsize_t[] max_dims = { H5S.UNLIMITED, H5S.UNLIMITED };
            hid_t     space    = H5S.create_simple(2, dims, max_dims);

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

            Assert.IsTrue(dcpl >= 0);
            hsize_t[] chunk = { 4, 4 };
            Assert.IsTrue(H5P.set_chunk(dcpl, 2, chunk) >= 0);
            Assert.IsTrue(H5P.set_alloc_time(dcpl, H5D.alloc_time_t.EARLY) >= 0);
            Assert.IsTrue(H5P.set_fill_time(dcpl, H5D.fill_time_t.ALLOC) >= 0);

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

            Assert.IsTrue(dset >= 0);

            // This should work but doesn't:
            // Assert.IsTrue(H5D.get_num_chunks(dset, H5S.ALL, ref nchunks) >= 0);
            hid_t fspace = H5D.get_space(dset);

            Assert.IsTrue(fspace >= 0);
            Assert.IsTrue(H5S.select_all(fspace) >= 0);

            hsize_t index = 8, size = 0;

            hsize_t[] offset      = { 4711, 4712 };
            uint32_t  filter_mask = 0;
            haddr_t   addr        = 0;

            Assert.IsTrue(H5D.get_chunk_info(dset, fspace, index, offset, ref filter_mask, ref addr, ref size) >= 0);
            Assert.IsTrue(offset[0] > 0);
            Assert.IsTrue(filter_mask == 0 && size > 0 && addr > 0);

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

            dset = H5D.create(m_v2_test_file, "Early Bird1", H5T.IEEE_F32BE,
                              space, H5P.DEFAULT, dcpl);
            Assert.IsTrue(dset >= 0);

            // This should work but doesn't:
            // Assert.IsTrue(H5D.get_num_chunks(dset, H5S.ALL, ref nchunks) >= 0);
            fspace = H5D.get_space(dset);
            Assert.IsTrue(fspace >= 0);
            Assert.IsTrue(H5S.select_all(fspace) >= 0);

            Assert.IsTrue(H5D.get_chunk_info(dset, fspace, index, offset, ref filter_mask, ref addr, ref size) >= 0);
            Assert.IsTrue(offset[0] > 0);
            Assert.IsTrue(filter_mask == 0 && size > 0 && addr > 0);

            Assert.IsTrue(H5D.close(dset) >= 0);
        }
Ejemplo n.º 7
0
        public void H5Sget_select_typeTest3()
        {
            hsize_t[] dims  = { 1, 2, 3 };
            hid_t     space = H5S.create_simple(dims.Length, dims, dims);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);
            Assert.IsTrue(
                H5S.get_select_type(space) == H5S.sel_type.ALL);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 8
0
        public void H5Dget_num_chunksTest1()
        {
            hsize_t[] dims     = { 10, 10 };
            hsize_t[] max_dims = { H5S.UNLIMITED, H5S.UNLIMITED };
            hid_t     space    = H5S.create_simple(2, dims, max_dims);

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

            Assert.IsTrue(dcpl >= 0);
            hsize_t[] chunk = { 4, 4 };
            Assert.IsTrue(H5P.set_chunk(dcpl, 2, chunk) >= 0);
            Assert.IsTrue(H5P.set_alloc_time(dcpl, H5D.alloc_time_t.EARLY) >= 0);
            Assert.IsTrue(H5P.set_fill_time(dcpl, H5D.fill_time_t.ALLOC) >= 0);

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

            Assert.IsTrue(dset >= 0);

            // This should work but doesn't:
            // Assert.IsTrue(H5D.get_num_chunks(dset, H5S.ALL, ref nchunks) >= 0);
            hid_t fspace = H5D.get_space(dset);

            Assert.IsTrue(fspace >= 0);
            Assert.IsTrue(H5S.select_all(fspace) >= 0);

            hsize_t nchunks = 0;

            Assert.IsTrue(H5D.get_num_chunks(dset, fspace, ref nchunks) >= 0);
            Assert.IsTrue(nchunks == 9);

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

            dset = H5D.create(m_v2_test_file, "Early Bird", H5T.IEEE_F32BE,
                              space, H5P.DEFAULT, dcpl);
            Assert.IsTrue(dset >= 0);

            // This should work but doesn't:
            // Assert.IsTrue(H5D.get_num_chunks(dset, H5S.ALL, ref nchunks) >= 0);
            fspace = H5D.get_space(dset);
            Assert.IsTrue(fspace >= 0);
            Assert.IsTrue(H5S.select_all(fspace) >= 0);

            nchunks = 0;
            Assert.IsTrue(H5D.get_num_chunks(dset, fspace, ref nchunks) >= 0);
            Assert.IsTrue(nchunks == 9);

            Assert.IsTrue(H5D.close(dset) >= 0);
        }
Ejemplo n.º 9
0
        public void H5Sget_select_boundsTest1()
        {
            hsize_t[] dims  = { 1, 2, 3 };
            hid_t     space = H5S.create_simple(dims.Length, dims, dims);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_all(space) >= 0);

            hsize_t[] start = new hsize_t[dims.Length];
            hsize_t[] stop  = new hsize_t[dims.Length];

            Assert.IsTrue(H5S.get_select_bounds(space, start, stop) >= 0);
            for (int i = 0; i < dims.Length; ++i)
            {
                Assert.IsTrue(start[i] == 0);
                Assert.IsTrue(stop[i] == dims[i] - 1);
            }

            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 10
0
        public void H5DfillTest2()
        {
            hsize_t[] dims  = { 5 };
            hid_t     space = H5S.create_simple(1, dims, null);

            Assert.IsTrue(H5S.select_all(space) >= 0);

            double[] v = new double[5] {
                0.0, 1.0, 2.0, 3.0, 4.0
            };
            GCHandle v_hnd = GCHandle.Alloc(v, GCHandleType.Pinned);

            Assert.IsTrue(
                H5D.fill(IntPtr.Zero, H5T.NATIVE_DOUBLE,
                         v_hnd.AddrOfPinnedObject(), H5T.NATIVE_DOUBLE, space) >= 0);
            v_hnd.Free();

            for (int i = 0; i < v.Length; ++i)
            {
                Assert.IsTrue(v[i] == 0.0);
            }

            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 11
0
 public void H5Sselect_allTest2()
 {
     Assert.IsFalse(
         H5S.select_all(Utilities.RandomInvalidHandle()) >= 0);
 }
Ejemplo n.º 12
0
        public Array Get()
        {
            Array result = null;

            WithDataSpace((h5Ref, dsRef) =>
            {
                var success = H5S.select_none(dsRef);
                if (success < 0)
                {
                    throw new H5SSException("Error with dataspace: select_none");
                }
                success = H5S.select_all(dsRef);
                if (success < 0)
                {
                    throw new H5SSException("Error with dataspace: select_all");
                }
                int selectElemNpoints = (int)H5S.get_select_npoints(dsRef);
                var effectiveSize     = ElementSize * selectElemNpoints;
                if (DataType == HDF5DataType.String)
                {
                    effectiveSize *= _stringLength;
                }
                IntPtr iPtr = Marshal.AllocHGlobal(effectiveSize); // TODO Deallocate

                try
                {
                    var dtype = H5D.get_type(h5Ref); // Return?
                    success   = H5D.read(h5Ref, dtype, H5S.ALL, dsRef, H5P.DEFAULT, iPtr);
                    H5T.close(dtype);

                    if (success < 0)
                    {
                        throw new H5SSException("Error reading dataset");
                    }

                    var tmp   = CreateClrArray(iPtr, selectElemNpoints);
                    var shape = Shape.Select(ul => (long)ul).ToArray();
                    if (ClrType == typeof(byte))
                    {
                        shape = shape.Concat(new[] { (long)_stringLength }).ToArray();
                    }

                    result = Array.CreateInstance(ClrType, shape);
                    Buffer.BlockCopy(tmp, 0, result, 0, effectiveSize);
                }
                finally
                {
                    Marshal.FreeHGlobal(iPtr);
                }

                // Convert bytes to characters...
                if (DataType == HDF5DataType.String)
                {
                    byte[,] byteArray = (byte[, ])result;
                    result            = Enumerable.Range(0, byteArray.GetLength(0)).Select(i =>
                    {
                        var slice = Enumerable.Range(0, byteArray.GetLength(1)).Select(j => byteArray[i, j]).ToArray();
                        //return System.Text.Encoding.Default.GetString(slice);
                        return(Encoding.ASCII.GetString(slice).TrimEnd((Char)0));
                    }).ToArray();
                }
                H5S.get_simple_extent_dims(dsRef, _shape, _maxDims); // WTF?
            });
            return(result);
        }
Ejemplo n.º 13
0
        public void H5Dvlen_get_buf_sizeTest1()
        {
            // write a VLEN dataset

            hid_t vlen = H5T.vlen_create(H5T.NATIVE_INT);

            Assert.IsTrue(vlen >= 0);

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

            Assert.IsTrue(space >= 0);


            hid_t dset = H5D.create(m_v0_test_file, "vlen", vlen, space);

            Assert.IsTrue(space >= 0);
            hid_t dset1 = H5D.create(m_v2_test_file, "vlen", vlen, space);

            Assert.IsTrue(space >= 0);

            H5T.hvl_t[] wdata  = new H5T.hvl_t[dims[0]];
            GCHandle[]  whndl  = new GCHandle[wdata.Length];
            int[][]     jagged = new int[dims[0]][];
            for (int i = 0; i < wdata.Length; ++i)
            {
                jagged[i]    = new int[i + 1];
                whndl[i]     = GCHandle.Alloc(jagged[i], GCHandleType.Pinned);
                wdata[i].len = new IntPtr(i + 1);
                wdata[i].p   = whndl[i].AddrOfPinnedObject();
            }

            GCHandle wdata_hndl = GCHandle.Alloc(wdata, GCHandleType.Pinned);

            Assert.IsTrue(H5D.write(dset, vlen, H5S.ALL, H5S.ALL, H5P.DEFAULT,
                                    wdata_hndl.AddrOfPinnedObject()) >= 0);
            Assert.IsTrue(H5D.write(dset1, vlen, H5S.ALL, H5S.ALL, H5P.DEFAULT,
                                    wdata_hndl.AddrOfPinnedObject()) >= 0);
            wdata_hndl.Free();

            for (int i = 0; i < wdata.Length; ++i)
            {
                whndl[i].Free();
            }

            hsize_t size = 0;

            Assert.IsTrue(H5S.select_all(space) >= 0);
            Assert.IsTrue(
                H5D.vlen_get_buf_size(dset, vlen, space, ref size) >= 0);
            Assert.IsTrue(size == 220);  // (1 + 2 + ... + 10) x sizeof(int)

            Assert.IsTrue(
                H5D.vlen_get_buf_size(dset1, vlen, space, ref size) >= 0);
            Assert.IsTrue(size == 220);  // (1 + 2 + ... + 10) x sizeof(int)

            Assert.IsTrue(H5D.close(dset1) >= 0);
            Assert.IsTrue(H5D.close(dset) >= 0);
            Assert.IsTrue(H5T.close(vlen) >= 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }