コード例 #1
0
        public void Put(Array data, ulong[] location = null)
        {
            ulong[] shape = data.Shape();

            WithDataSpace((h5Ref, dsRef) =>
            {
                long memDataSpace = H5S.ALL;

                if (location != null)
                {
                    int selection = H5S.select_none(dsRef);
                    if (selection < 0)
                    {
                        throw new H5SSException("Couldn't clear dataspace selection");
                    }
                    ulong[] stride = Ones(shape.Length);
                    selection      = H5S.select_hyperslab(dsRef,
                                                          H5S.seloper_t.SET,
                                                          location,
                                                          stride,
                                                          stride,
                                                          shape
                                                          );
                    if (selection < 0)
                    {
                        throw new H5SSException("Couldn't select hyperslab");
                    }

                    memDataSpace = H5S.create_simple(shape.Length, shape, shape);
                }

                IntPtr iPtr;
                var effectiveSize = data.Length * ElementSize;
                //if (DataType == HDF5DataType.String)
                //{
                //    // Convert to byte array...

                //}
                //else
                //{
                //}
                var dtype = H5D.get_type(h5Ref); // Return?

                iPtr = CreateNativeArray(data, dtype);
                // copy to unmanaged array?
                var success = H5D.write(h5Ref, dtype, memDataSpace, dsRef, H5P.DEFAULT, iPtr);
                H5T.close(dtype);

                if (location != null)
                {
                    H5S.close(memDataSpace);
                }

                Marshal.FreeHGlobal(iPtr);
                if (success < 0)
                {
                    throw new H5SSException(string.Format("Couldn't write to dataset: {0}", this.Path));
                }
            });
        }
コード例 #2
0
ファイル: H5Sselect_none.cs プロジェクト: ywadea/HDF.PInvoke
        public void H5Sselect_noneTest4()
        {
            hid_t space = H5S.create(H5S.class_t.SCALAR);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_none(space) >= 0);
            Assert.IsTrue(H5S.get_select_npoints(space) == 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
コード例 #3
0
ファイル: H5Sselect_none.cs プロジェクト: ywadea/HDF.PInvoke
        public void H5Sselect_noneTest1()
        {
            hsize_t[] dims  = { 1, 2, 3 };
            hid_t     space = H5S.create_simple(dims.Length, dims, null);

            Assert.IsTrue(space > 0);
            Assert.IsTrue(H5S.select_none(space) >= 0);
            Assert.IsTrue(H5S.get_select_npoints(space) == 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
コード例 #4
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);
        }