Exemplo n.º 1
0
        public void ComplexDatatypeCreate()
        {
            var points = new NamedPoint[10];
            for (int i = 0; i < 10; i++)
            {
                var p = new NamedPoint {point = {x = i*2, y = i*3}};
                var name = Encoding.ASCII.GetBytes(i.ToString());
                unsafe
                {
                    Marshal.Copy(name, 0, (IntPtr)p.name, name.Length);
                }
                points[i] = p;
            }

            using (var file = new H5File(TEST_FILE))
            {
                var stringType = file.CreateDatatype("STRING", H5T.H5TClass.STRING, 40);
                var pointType = file.CreateDatatype("POINT",
                                                    new[] {"x", "y"},
                                                    new[]
                                                        {
                                                            new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                            new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                        });

                var type = file.CreateDatatype("NAMED_POINT",
                                                new[] {"name", "point"},
                                                new[] {stringType, pointType});

                var dataset = file.AddDataset("points", type, points);
                Assert.AreEqual(points, dataset.GetData<NamedPoint>());
            }
        }
Exemplo n.º 2
0
        public void SimpleDatatypeCreateFind()
        {
            var points = new Point[10];
            for (int i = 0; i < points.Length; i++)
            {
                points[i].x = i;
                points[i].y = i*3;
            }

            using (var file = new H5File(TEST_FILE))
            {
                var type = file.CreateDatatype("POINT",
                                               new[] {"x", "y"},
                                               new[]
                                                   {
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                   });

                var dataset = file.AddDataset("points", type, points);
            }

            using (var file = new H5File(TEST_FILE))
            {
                Assert.AreEqual(1, file.Datasets.Count());

                var dataset = file.Datasets.First();
                var actual = dataset.GetData<Point>();
                Assert.AreEqual(points, actual);
            }
        }
Exemplo n.º 3
0
        public void ShouldExtendChunkDataset()
        {
            using (var file = new H5File(TEST_FILE))
            {
                var type = file.CreateDatatype("POINT",
                                               new[] { "x", "y" },
                                               new[]
                                                   {
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE),
                                                       new H5Datatype(H5T.H5Type.NATIVE_DOUBLE)
                                                   });

                var dataset = file.AddDataset("points", type, new long[] {0}, new long[] {-1}, new long[] {64});

                var points = new[] {new Point {x = 1, y = 2}};

                // Dataset not yet extended
                dataset.SetData(points);
                Assert.AreEqual(0, dataset.GetData<Point>().Count());

                dataset.Extend(new long[] {1});
                dataset.SetData(points);
                Assert.AreEqual(1, dataset.GetData<Point>().Count());
                Assert.AreEqual(points, dataset.GetData<Point>());
            }
        }