예제 #1
0
        private void Write(H5GroupId parent, string name, IEnumerable <IMeasurement> measurements)
        {
            H5DataSpaceId spaceId = H5S.create_simple(1, new long[1] {
                (long)measurements.Count()
            });


            // Set compression options for dataset
            H5PropertyListId dataSetPropertyList = H5P.create(H5P.PropertyListClass.DATASET_CREATE);

            H5P.setDeflate(dataSetPropertyList, NumericDataCompression);
            H5P.setChunk(dataSetPropertyList, new long[] { (long)measurements.Count() });

            H5DataSetId dataSetId = H5D.create(parent,
                                               name,
                                               measurement_t,
                                               spaceId,
                                               new H5PropertyListId(H5P.Template.DEFAULT),
                                               dataSetPropertyList,
                                               new H5PropertyListId(H5P.Template.DEFAULT));

            MeasurementT[] ms       = new MeasurementT[measurements.Count()];
            int            ilmCount = 0;

            foreach (IMeasurement m in measurements)
            {
                MeasurementT mt = Convert(m);
                ms[ilmCount++] = mt;
            }

            H5D.write <MeasurementT>(dataSetId, measurement_t, new H5Array <MeasurementT>(ms));

            H5D.close(dataSetId);
            H5S.close(spaceId);
        }
예제 #2
0
        private static H5DataSetId CreateDatasetIfNoneExists(H5FileId fileId, string setName, int dim1, H5DataTypeId dataType)
        {
            H5DataSetId dataSetId = null;

            char[] sep     = { '/' };
            var    strings = setName.Split(sep);
            var    path    = "/";

            for (var x = 0; x < strings.Length - 1; x++)
            {
                path += strings[x] + "/";
                var groupId = CreateGroupIfNoneExists(fileId, path);
            }

            var dims = new long[] {
                dim1
            };
            var maxDims = new long[] {
                -1
            };

            if (H5L.Exists(fileId, setName))
            {
                dataSetId = H5D.open(fileId, setName);
                H5D.setExtent(dataSetId, dims);
            }
            else
            {
                var linkp   = H5P.create(H5P.PropertyListClass.LINK_CREATE);
                var accessp = H5P.create(H5P.PropertyListClass.DATASET_ACCESS);
                var createp = H5P.create(H5P.PropertyListClass.DATASET_CREATE);
                H5P.setChunk(createp, dims);
                H5P.setDeflate(createp, 1);

                var sId = H5S.create_simple(1, dims, maxDims);

                dataSetId = H5D.create(fileId, setName, dataType, sId, linkp, createp, accessp);
            }

            return(dataSetId);
        }
예제 #3
0
        } // test_buffer

        // Create a new dataset that uses chunked storage instead of the default layout.
        static void test_chunked_dset()
        {
            try
            {
                Console.Write("Testing dataset with chunked storage layout");

                const string     FILE_NAME         = ("SDSchunked.h5");
                const string     DSET_CHUNKED_NAME = ("Chunked IntArray");
                const int        NX        = 50; // data set dimension
                const int        NY        = 20;
                const int        RANK      = 2;  // two-dimension
                H5PropertyListId P_DEFAULT = new H5PropertyListId(H5P.Template.DEFAULT);

                // Data and input buffer initialization.
                int i, j;
                int[,] data = new int[NX, NY];
                for (i = 0; i < NX; i++)
                {
                    for (j = 0; j < NY; j++)
                    {
                        data[i, j] = i + j;
                    }
                }

                // Create a new file using H5F_ACC_TRUNC access,
                // default file creation properties, and default file
                // access properties.
                H5FileId fileId = H5F.create(FILE_NAME, H5F.CreateMode.ACC_TRUNC);

                // Describe the size of the array and create the data space for fixed
                // size dataset.
                long[] dims = new long[RANK];
                dims[0] = NX;
                dims[1] = NY;
                H5DataSpaceId dspaceId = H5S.create_simple(RANK, dims);

                // Define datatype for the data in the file.
                H5DataTypeId dtypeId = H5T.copy(H5T.H5Type.NATIVE_INT);

                // Create dataset creation property list.
                H5PropertyListId crtpltId
                    = H5P.create(H5P.PropertyListClass.DATASET_CREATE);

                // Set chunk sizes for the dataset.
                long[] csize = new long[2] {
                    5, 2
                };
                H5P.setChunk(crtpltId, csize);

                // Set deflate for the dataset.
                H5P.setDeflate(crtpltId, 9);

                // Create the data set DATASETNAME.
                H5DataSetId dsetId = H5D.create(fileId, DSET_CHUNKED_NAME, dtypeId, dspaceId, P_DEFAULT, crtpltId, P_DEFAULT);

                // Write the one-dimensional data set array
                H5D.write(dsetId, dtypeId, new H5Array <int>(data));

                // Close dataset and file.
                H5D.close(dsetId);
                H5F.close(fileId);

                // Open the file again in read only mode.
                fileId = H5F.open(FILE_NAME, H5F.OpenMode.ACC_RDONLY);

                // Open the dataset using its name.
                dsetId = H5D.open(fileId, DSET_CHUNKED_NAME);

                int[,] outdata = new int[NX, NY];
                for (i = 0; i < NX; i++)
                {
                    for (j = 0; j < NY; j++)
                    {
                        outdata[i, j] = 0;
                    }
                }

                // Read data back.
                H5D.read(dsetId, new H5DataTypeId(H5T.H5Type.NATIVE_INT), new H5Array <int>(outdata));

                // Compare against input buffer to verify.
                for (i = 0; i < NX; i++)
                {
                    for (j = 0; j < NY; j++)
                    {
                        if (outdata[i, j] != data[i, j])
                        {
                            Console.WriteLine("\ntest_chunked_dset: read value differs from input: read {0} - input {1}",
                                              outdata[i, j], data[i, j]);
                            nerrors++;
                        }
                    }
                }

                // Close all objects and file.
                H5D.close(dsetId);
                H5T.close(dtypeId);
                H5S.close(dspaceId);
                H5F.close(fileId);

                Console.WriteLine("\t\tPASSED");
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
        } // test_chunked_dset