예제 #1
0
        public void H5Eclose_stackTest1()
        {
            hid_t est = H5E.create_stack();

            Assert.IsTrue(est >= 0);
            Assert.IsTrue(H5E.close_stack(est) >= 0);
        }
예제 #2
0
 public void H5EpushTest2()
 {
     Assert.IsFalse(
         H5E.push(Utilities.RandomInvalidHandle(), "hello.c", "sqrt",
                  77, H5E.ERR_CLS, H5E.NONE_MAJOR, H5E.NONE_MINOR,
                  "Hello, World!") >= 0);
 }
예제 #3
0
        public void H5Eauto_is_v2Test2()
        {
            uint version = 0;

            Assert.IsFalse(
                H5E.auto_is_v2(Utilities.RandomInvalidHandle(), ref version) >= 0);
        }
예제 #4
0
        } // test_getting_info

        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet High-level Table API");
            Console.WriteLine();
            try
            {
                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                make_table();           // create and write to a table to test
                test_getting_info();    // test getting table and field info
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: ", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All table tests passed.");
            }
            Console.WriteLine();
        }
        public void H5Eget_current_stackTest1()
        {
            hid_t est = H5E.get_current_stack();

            Assert.IsTrue(est >= 0);
            Assert.IsTrue(H5E.close_stack(est) >= 0);
        }
예제 #6
0
        public KamaAcquisitionFile(string filename, AcquisitionInterface acquisitionInterface, ILogger logger,
                                   int eitDefaultChunkSize = 24000, int ecgDefaultChunkSize = 10)
        {
            FileName            = filename;
            Logger              = logger;
            EITDefaultChunkSize = eitDefaultChunkSize;
            ECGDefaultChunkSize = ecgDefaultChunkSize;

            RecordNumber = 1;
            H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero);
            fileId               = Hdf5.CreateFile(filename);
            groupRoot            = fileId;
            groupEIT             = Hdf5.CreateOrOpenGroup(groupRoot, "eit");
            ProcedureInformation = new ProcedureInformation(fileId, groupRoot, logger)
            {
                ProcedureDirectory = Path.GetDirectoryName(filename),
                StartDateTime      = DateTime.Now,
                EndDateTime        = DateTime.Now
            };

            SystemInformation            = new SystemInformation(fileId, groupRoot, logger);
            SystemInformation.SystemType = acquisitionInterface.ToString();
            //  InjectionGroup = new InjectionGroup(fileId, groupRoot);
            CalibrationGroup = new CalibrationGroup(fileId, groupRoot, logger);
            SystemEvents     = new SystemEventGroup(fileId, groupRoot, logger);
            RPosition        = new RPositionGroup(fileId, groupRoot, logger);
            Tags             = new TagsGroup(fileId, groupRoot, logger);
            UserEventsGroup  = new UserEventsGroup(fileId, groupRoot, logger);
        }
        public void H5Eset_current_stackTest1()
        {
            hid_t est = H5E.create_stack();

            Assert.IsTrue(est >= 0);
            Assert.IsTrue(H5E.set_current_stack(est) >= 0);
        }
예제 #8
0
        public void H5Eget_autoTest1()
        {
            H5E.auto_t cb          = null;
            IntPtr     client_data = IntPtr.Zero;

            Assert.IsTrue(
                H5E.get_auto(H5E.DEFAULT, ref cb, ref client_data) >= 0);
        }
예제 #9
0
 public void H5EpushTest1()
 {
     Assert.IsTrue(
         H5E.push(H5E.DEFAULT, "hello.c", "sqrt", 77, H5E.ERR_CLS,
                  H5E.NONE_MAJOR, H5E.NONE_MINOR, "Hello, World!") >= 0);
     Assert.IsTrue(
         H5E.get_num(H5E.DEFAULT).ToInt32() > 0);
 }
예제 #10
0
        public void H5Eget_numTest1()
        {
            hid_t est = H5E.get_current_stack();

            Assert.IsTrue(est >= 0);
            ssize_t size = H5E.get_num(est);

            Assert.IsTrue(size.ToInt32() >= 0);
            Assert.IsTrue(H5E.close_stack(est) >= 0);
        }
예제 #11
0
 public void H5EpopTest1()
 {
     Assert.IsTrue(
         H5E.push(H5E.DEFAULT, "hello.c", "sqrt", 77, H5E.ERR_CLS,
                  H5E.NONE_MAJOR, H5E.NONE_MINOR, "Hello, World!") >= 0);
     Assert.IsTrue(
         H5E.push(H5E.DEFAULT, "hello.c", "sqr", 78, H5E.ERR_CLS,
                  H5E.NONE_MAJOR, H5E.NONE_MINOR, "Hello, World!") >= 0);
     Assert.IsTrue(H5E.pop(H5E.DEFAULT, new IntPtr(2)) >= 0);
 }
예제 #12
0
        public bool EnableErrorReporting(bool enable)
        {
            ErrorLoggingEnable = enable;
            if (enable)
            {
                return(H5E.set_auto(H5E.DEFAULT, Hdf5Errors.ErrorDelegateMethod, IntPtr.Zero) >= 0);
            }

            return(H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero) >= 0);
        }
예제 #13
0
        public void H5Eauto_is_v2Test1()
        {
            hid_t est = H5E.create_stack();

            Assert.IsTrue(est >= 0);
            uint version = 0;

            Assert.IsTrue(H5E.auto_is_v2(est, ref version) >= 0);
            Assert.IsTrue(version == 1);
            Assert.IsTrue(H5E.close_stack(est) >= 0);
        }
예제 #14
0
        public void H5EwalkTest1()
        {
            H5E.auto_t auto_cb = ErrorDelegateMethod;
            Assert.IsTrue(
                H5E.set_auto(H5E.DEFAULT, auto_cb, IntPtr.Zero) >= 0);

            H5E.walk_t walk_cb = WalkDelegateMethod;
            Assert.IsTrue(
                H5E.walk(H5E.DEFAULT, H5E.direction_t.H5E_WALK_DOWNWARD,
                         walk_cb, IntPtr.Zero) >= 0);
        }
예제 #15
0
        // private readonly ReaderWriterLockSlim lock_ = new ReaderWriterLockSlim();

        public Hdf5AcquisitionFileWriter(string aFilename, string groupName = "/EEG")
        {
            H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero);
            //lock_.EnterWriteLock();
            _filename  = aFilename;
            fileId     = Hdf5.CreateFile(aFilename);
            _groupName = groupName;
            _groupId   = Hdf5.CreateGroup(fileId, _groupName);

            Header       = new Hdf5AcquisitionFile();
            _nrOfRecords = 0;
            _sampleCount = 0;
            //lock_.ExitWriteLock();
        }
예제 #16
0
        // private readonly ReaderWriterLockSlim lock_ = new ReaderWriterLockSlim();

        public Hdf5AcquisitionFileWriter(string filename, string groupName = "ROOT")
        {
            H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero);
            //lock_.EnterWriteLock();
            _filename  = filename;
            fileId     = Hdf5.CreateFile(filename);
            _groupName = groupName;
            _groupId   = Hdf5.CreateGroup(fileId, Hdf5Utils.NormalizedName(_groupName));

            Header       = new Hdf5AcquisitionFile();
            _nrOfRecords = 0;
            _sampleCount = 0;
            //lock_.ExitWriteLock();
        }
예제 #17
0
        } // test_copy

        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Datatype API");
            Console.WriteLine();
            try
            {
                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                // Create the file
                H5FileId fileId = H5F.create("test_types.h5", H5F.CreateMode.ACC_TRUNC);

                // Invokes individual datatype tests
                test_classes();
                test_integer_dtype();
                test_float_dtype();
                test_compound_dtype(fileId);
                test_enum_dtype(fileId);
                test_vlen_dtype(fileId);
                test_copy();

                // Close the file
                H5F.close(fileId);
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }

            // Report results.
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: {0}", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All datatype tests passed.");
            }
            Console.WriteLine();
        }
예제 #18
0
        public static void SuppressErrors(Action action)
        {
            H5E.auto_t func;
            IntPtr     clientData;

            func       = null;
            clientData = IntPtr.Zero;

            H5E.get_auto(H5E.DEFAULT, ref func, ref clientData);
            H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero);

            action.Invoke();

            H5E.set_auto(H5E.DEFAULT, func, clientData);
        }
예제 #19
0
        public static void CaptureHdfLibOutput(ITestOutputHelper logger)
        {
            H5E.set_auto(H5E.DEFAULT, ErrorDelegateMethod, IntPtr.Zero);

            int ErrorDelegateMethod(long estack, IntPtr client_data)
            {
                H5E.walk(estack, H5E.direction_t.H5E_WALK_DOWNWARD, WalkDelegateMethod, IntPtr.Zero);
                return(0);
            }

            int WalkDelegateMethod(uint n, ref H5E.error_t err_desc, IntPtr client_data)
            {
                logger.WriteLine($"{n}: {err_desc.desc}");
                return(0);
            }
        }
예제 #20
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Dataset API");
            Console.WriteLine();
            try
            {
                const string FILE_NAME = ("Dataset.h5");

                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                // 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);

                test_create(fileId);         // test creating dataset
                test_onedim_array(fileId);   // test writing one-dimensional array
                test_twodims_array();        // test writing multiple-dimensional arrays
                test_fivedims_array(fileId);

                // Close the file.
                H5F.close(fileId);
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: ", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All dataset tests passed.");
            }
            Console.WriteLine();
        }
예제 #21
0
        } // test_chunked_dset

        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Property List API");
            Console.WriteLine();
            try
            {
                const string FILE_NAME = ("Dataset.h5");

                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                // 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);

                test_buffer();
                test_chunked_dset();

                // Close the file.
                H5F.close(fileId);
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: ", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All property list tests passed.");
            }
            Console.WriteLine();
        }
예제 #22
0
        public void H5EwalkTest2()
        {
            // H5E.set_auto(H5E.DEFAULT, ErrorDelegateMethod, IntPtr.Zero);
            Assert.IsTrue(
                H5E.set_auto(H5E.DEFAULT, ErrorDelegateMethod, IntPtr.Zero) >= 0);

            H5E.walk_t walk_cb = WalkDelegateMethod;
            Assert.IsTrue(
                H5E.push(H5E.DEFAULT, "hello.c", "sqrt", 77, H5E.ERR_CLS,
                         H5E.NONE_MAJOR, H5E.NONE_MINOR, "Hello, World!") >= 0);

            Assert.IsTrue(
                H5E.push(H5E.DEFAULT, "hello.c", "sqr", 78, H5E.ERR_CLS,
                         H5E.NONE_MAJOR, H5E.NONE_MINOR, "Hello, World!") >= 0);

            Assert.IsTrue(
                H5E.walk(H5E.DEFAULT, H5E.direction_t.H5E_WALK_DOWNWARD,
                         walk_cb, IntPtr.Zero) >= 0);
        }
예제 #23
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Attribute API");
            Console.WriteLine();
            try
            {
                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                test_attr_basic_write();    // test basic writing attributes
                test_attr_basic_read();     // test basic reading attributes
                test_attr_plist();          // test attribute property lists
                test_attr_compound_write(); // test writing compound values to attributes
                test_attr_compound_read();  // test reading compound values from attributes
                test_attr_iterate();        // test iterating attributes
                test_attr_delete();         // test deleting attributes
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: ", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All attribute tests passed.");
            }
            Console.WriteLine();
        }
예제 #24
0
        } // test_select

        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Dataspace API");
            Console.WriteLine();
            try
            {
                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                test_h5s_basic();   // test basic dataspace functionalities
                test_h5s_scalar();  // test scalar dataspace
                test_select();      // test dataspace select
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test failed: ", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("All dataspace tests passed.");
            }
            Console.WriteLine();
        }
예제 #25
0
        } // test_group_info

        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("TEST: HDF5DotNet Group API");
            Console.WriteLine();
            try
            {
                // Suppress error printing from the C library.
                H5E.suppressPrinting();

                test_group_basics();
                test_group_iterate();
                test_group_info();
            }
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
            Console.WriteLine();
            if (nerrors > 0)
            {
                Console.WriteLine("Test(s) failed: {0}", nerrors, "occurred!");
            }
            else
            {
                Console.WriteLine("---- All group tests passed.");
            }
            Console.WriteLine();
        }
예제 #26
0
 public void H5EpopTest2()
 {
     Assert.IsFalse(
         H5E.pop(Utilities.RandomInvalidHandle(), IntPtr.Zero) >= 0);
 }
예제 #27
0
 internal static int ErrorDelegateMethod(long estack, IntPtr client_data)
 {
     H5E.walk(estack, H5E.direction_t.H5E_WALK_DOWNWARD, WalkDelegateMethod, IntPtr.Zero);
     return(0);
 }
예제 #28
0
 public void H5Eclose_stackTest2()
 {
     Assert.IsFalse(
         H5E.close_stack(Utilities.RandomInvalidHandle()) >= 0);
 }
예제 #29
0
        static void Main(string[] args)
        {
            try
            {
                // We will write and read an int array of this length.
                const int DATA_ARRAY_LENGTH = 12;

                // Rank is the number of dimensions of the data array.
                const int RANK = 1;

                // Create an HDF5 file.
                // The enumeration type H5F.CreateMode provides only the legal
                // creation modes.  Missing H5Fcreate parameters are provided
                // with default values.
                H5FileId fileId = H5F.create("myCSharp.h5",
                                             H5F.CreateMode.ACC_TRUNC);

                // Create a HDF5 group.
                H5GroupId groupId  = H5G.create(fileId, "/cSharpGroup");
                H5GroupId subGroup = H5G.create(groupId, "mySubGroup");

                // Close the subgroup.
                H5G.close(subGroup);

                // Prepare to create a data space for writing a 1-dimensional
                // signed integer array.
                long[] dims = new long[RANK];
                dims[0] = DATA_ARRAY_LENGTH;

                // Put descending ramp data in an array so that we can
                // write it to the file.
                int[] dset_data = new int[DATA_ARRAY_LENGTH];
                for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
                {
                    dset_data[i] = DATA_ARRAY_LENGTH - i;
                }

                // Create a data space to accommodate our 1-dimensional array.
                // The resulting H5DataSpaceId will be used to create the
                // data set.
                H5DataSpaceId spaceId = H5S.create_simple(RANK, dims);

                // Create a copy of a standard data type.  We will use the
                // resulting H5DataTypeId to create the data set.  We could
                // have  used the HST.H5Type data directly in the call to
                // H5D.create, but this demonstrates the use of H5T.copy
                // and the use of a H5DataTypeId in H5D.create.
                H5DataTypeId typeId = H5T.copy(H5T.H5Type.NATIVE_INT);

                // Find the size of the type
                int typeSize = H5T.getSize(typeId);
                Console.WriteLine("typeSize is {0}", typeSize);

                // Set the order to big endian
                H5T.setOrder(typeId, H5T.Order.BE);

                // Set the order to little endian
                H5T.setOrder(typeId, H5T.Order.LE);

                // Create the data set.
                H5DataSetId dataSetId = H5D.create(fileId, "/csharpExample",
                                                   typeId, spaceId);

                // Write the integer data to the data set.
                H5D.write(dataSetId, new H5DataTypeId(H5T.H5Type.NATIVE_INT),
                          new H5Array <int>(dset_data));

                // If we were writing a single value it might look like this.
                //  int singleValue = 100;
                //  H5D.writeScalar(dataSetId,
                //                 new H5DataTypeId(H5T.H5Type.NATIVE_INT),
                //                 ref singleValue);

                // Create an integer array to receive the read data.
                int[] readDataBack = new int[DATA_ARRAY_LENGTH];

                // Read the integer data back from the data set
                H5D.read(dataSetId, new H5DataTypeId(H5T.H5Type.NATIVE_INT),
                         new H5Array <int>(readDataBack));

                // Echo the data
                for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
                {
                    Console.WriteLine(readDataBack[i]);
                }

                // Close all the open resources.
                H5D.close(dataSetId);

                // Reopen and close the data sets to show that we can.
                dataSetId = H5D.open(fileId, "/csharpExample");
                H5D.close(dataSetId);
                dataSetId = H5D.open(groupId, "/csharpExample");

                H5D.close(dataSetId);
                H5T.close(typeId);
                H5G.close(groupId);

                // Get H5O info
                H5ObjectInfo objectInfo = H5O.getInfoByName(fileId,
                                                            "/csharpExample");

                Console.WriteLine("header.space.message is {0}",
                                  objectInfo.header.space.message);
                Console.WriteLine("fileNumber is {0}", objectInfo.fileNumber);
                Console.WriteLine("address is {0}", objectInfo.address);
                Console.WriteLine("type is {0}",
                                  objectInfo.objectType.ToString());
                Console.WriteLine("reference count is {0}",
                                  objectInfo.referenceCount);
                Console.WriteLine("modification time is {0}",
                                  objectInfo.modificationTime);
                Console.WriteLine("birth time is {0}",
                                  objectInfo.birthTime);
                Console.WriteLine("access time is {0}",
                                  objectInfo.accessTime);
                Console.WriteLine("change time is {0}",
                                  objectInfo.changeTime);
                Console.WriteLine("number of attributes is {0}",
                                  objectInfo.nAttributes);

                Console.WriteLine("header version is {0}",
                                  objectInfo.header.version);

                Console.WriteLine("header nMessages is {0}",
                                  objectInfo.header.nMessages);

                Console.WriteLine("header nChunks is {0}",
                                  objectInfo.header.nChunks);

                Console.WriteLine("header flags is {0}",
                                  objectInfo.header.flags);

                H5LinkInfo linkInfo = H5L.getInfo(fileId, "/cSharpGroup");

                Console.WriteLine(
                    "address: {0:x}, charSet: {1}, creationOrder: {2}",
                    linkInfo.address, linkInfo.charSet, linkInfo.creationOrder);

                Console.WriteLine("linkType: {0}, softLinkSizeOrUD: {1}",
                                  linkInfo.linkType, linkInfo.softLinkSizeOrUD);

                // Reopen the group id to show that we can.
                groupId = H5G.open(fileId, "/cSharpGroup");


                // Use H5L.iterate to visit links
                H5LIterateCallback myDelegate;
                myDelegate = MyH5LFunction;
                ulong             linkNumber = 0;
                H5IterationResult result     =
                    H5L.iterate(groupId, H5IndexType.NAME,
                                H5IterationOrder.INCREASING,
                                ref linkNumber, myDelegate, 0);

                // Create some attributes
                H5DataTypeId attributeType = H5T.copy(H5T.H5Type.NATIVE_INT);
                long[]       attributeDims = new long[1];
                const int    RAMP_LENGTH   = 5;
                attributeDims[0] = RAMP_LENGTH;
                int[] ascendingRamp = new int[RAMP_LENGTH] {
                    1, 2, 3, 4, 5
                };
                int[] descendingRamp = new int[RAMP_LENGTH] {
                    5, 4, 3, 2, 1
                };
                int[] randomData = new int[RAMP_LENGTH] {
                    3, 123, 27, 6, 1
                };
                int[] readBackRamp = new int[RAMP_LENGTH];



                // Call set buffer using H5Memory
                // Allocate memory from "C" runtime heap (not garbage collected)
                H5Memory typeConversionBuffer = new H5Memory(new IntPtr(DATA_ARRAY_LENGTH));
                H5Memory backgroundBuffer     = new H5Memory(new IntPtr(DATA_ARRAY_LENGTH));

                // Set the property list type conversion and background buffers.
                H5PropertyListId myPropertyListId =
                    H5P.create(H5P.PropertyListClass.DATASET_XFER);
                H5P.setBuffer(myPropertyListId,
                              typeConversionBuffer, backgroundBuffer);

                // Test use of vlen

                // Create a vlen data type
                H5DataTypeId tid1 = H5T.vlenCreate(H5T.H5Type.NATIVE_UINT);

                H5DataSetId vDataSetId = H5D.create(fileId, "/vlenTest", tid1,
                                                    spaceId);

                // Create a jagged array of integers.
                hvl_t[] vlArray = new hvl_t[DATA_ARRAY_LENGTH];

                // HDF5 variable length data types require the use of void
                // pointers.  C# requires that sections of code that deal
                // directly with pointer be marked
                // as unsafe.
                unsafe
                {
                    for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
                    {
                        IntPtr ptr = new IntPtr((i + 1) * sizeof(int));
                        // Allocate memory that is not garbage collected.
                        vlArray[i].p = H5CrtHeap.Allocate(
                            new IntPtr((i + 1) * sizeof(int))
                            ).ToPointer();

                        // Fill the array with integers = the row number
                        int *intPointer = (int *)vlArray[i].p;
                        for (int j = 0; j < i + 1; j++)
                        {
                            intPointer[j] = (int)i;
                        }

                        if (IntPtr.Size == 8)
                        {
                            vlArray[i].len = (ulong)i + 1;
                        }
                        else
                        {
                            vlArray[i].len = (uint)i + 1;
                        }
                    }

                    // Write the variable length data
                    H5D.write(vDataSetId, tid1,
                              new H5Array <hvl_t>(vlArray));

                    // Create an array to read back the array.
                    hvl_t[] vlReadBackArray = new hvl_t[DATA_ARRAY_LENGTH];

                    // Read the array back
                    H5D.read(vDataSetId, tid1, new H5Array <hvl_t>(vlReadBackArray));

                    // Write the data to the console
                    for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
                    {
                        int *iPointer = (int *)vlReadBackArray[i].p;
                        for (int j = 0; j < i + 1; j++)
                        {
                            Console.WriteLine(iPointer[j]);
                        }
                    }

                    // Reclaim the memory that read allocated
                    H5D.vlenReclaim(tid1, spaceId, new H5PropertyListId(H5P.Template.DEFAULT),
                                    new H5Array <hvl_t>(vlReadBackArray));

                    // Now read it back again using our own memory manager


                    //H5AllocateCallback allocDelegate = new H5AllocCallback(userAlloc);
                    H5FreeCallback freeDelegate = new H5FreeCallback(userFree);

                    H5PropertyListId memManagerPlist = H5P.create(H5P.PropertyListClass.DATASET_XFER);

                    unsafe
                    {
                        H5P.setVlenMemManager(memManagerPlist, userAlloc, IntPtr.Zero,
                                              freeDelegate, IntPtr.Zero);
                    }

                    // Read the array back
                    H5D.read(vDataSetId, tid1,
                             new H5DataSpaceId(H5S.H5SType.ALL),
                             new H5DataSpaceId(H5S.H5SType.ALL),
                             memManagerPlist,
                             new H5Array <hvl_t>(vlReadBackArray));

                    // Write the data to the console
                    for (int i = 0; i < DATA_ARRAY_LENGTH; i++)
                    {
                        int *iPointer = (int *)vlReadBackArray[i].p;
                        for (int j = 0; j < i + 1; j++)
                        {
                            Console.WriteLine(iPointer[j]);
                        }
                    }

                    // Reclaim the memory that read allocated using our free routines
                    H5D.vlenReclaim(tid1, spaceId, memManagerPlist,
                                    new H5Array <hvl_t>(vlReadBackArray));
                }
                H5S.close(spaceId);


                H5DataSpaceId attributeSpace =
                    H5S.create_simple(1, attributeDims);

                H5AttributeId attributeId =
                    H5A.create(groupId, "ascendingRamp", attributeType, attributeSpace);

                int offset = H5T.getOffset(attributeType);
                Console.WriteLine("Offset is {0}", offset);

                H5DataTypeId float32BE = H5T.copy(H5T.H5Type.IEEE_F32BE);
                H5T.Norm     norm      = H5T.getNorm(float32BE);
                Console.WriteLine("Norm is {0}", norm);


                int precision = H5T.getPrecision(float32BE);
                Console.WriteLine("Precision is {0}", precision);

                H5FloatingBitFields bitFields = H5T.getFields(float32BE);
                Console.WriteLine("getFields: sign bit position: {0}", bitFields.signBitPosition);
                Console.WriteLine("getFields: exponent bit position: {0}", bitFields.exponentBitPosition);
                Console.WriteLine("getFields: number of exponent bits: {0}", bitFields.nExponentBits);
                Console.WriteLine("getFields: mantissa bit position: {0} ", bitFields.mantissaBitPosition);
                Console.WriteLine("getFields: number of mantissa bits: {0}", bitFields.nMantissaBits);

                Console.Write("{0}", bitFields);
                // Write to an attribute
                H5A.write <int>(attributeId, attributeType,
                                new H5Array <int>(ascendingRamp));

                // Read from an attribute
                H5A.read <int>(attributeId, attributeType,
                               new H5Array <int>(readBackRamp));

                // Echo results
                Console.WriteLine("ramp elements are: ");
                foreach (int rampElement in readBackRamp)
                {
                    Console.WriteLine("   {0}", rampElement);
                }
                H5A.close(attributeId);

                // Create and write two more attributes.
                attributeId = H5A.createByName(groupId, ".", "descendingRamp",
                                               attributeType, attributeSpace);
                H5A.write <int>(attributeId, attributeType,
                                new H5Array <int>(descendingRamp));
                H5A.close(attributeId);

                attributeId = H5A.createByName(groupId, ".",
                                               "randomData", attributeType,
                                               attributeSpace);
                H5A.write <int>(attributeId, attributeType,
                                new H5Array <int>(randomData));

                // Read back the attribute data
                H5A.read <int>(attributeId, attributeType,
                               new H5Array <int>(readBackRamp));
                Console.WriteLine("ramp elements are: ");
                foreach (int rampElement in readBackRamp)
                {
                    Console.WriteLine("   {0}", rampElement);
                }
                H5A.close(attributeId);

                // Iterate through the attributes.
                long position = 0;
                H5AIterateCallback attributeDelegate;
                attributeDelegate = MyH5AFunction;
                H5ObjectInfo groupInfo = H5O.getInfo(groupId);
                Console.WriteLine(
                    "fileNumber: {0}, total space: {1}, referceCount: {2}, modification time: {3}",
                    groupInfo.fileNumber, groupInfo.header.space.total,
                    groupInfo.referenceCount, groupInfo.modificationTime);

                // While iterating, collect the names of all the attributes.
                ArrayList attributeNames = new ArrayList();
                H5A.iterate(groupId, H5IndexType.CRT_ORDER,
                            H5IterationOrder.INCREASING,
                            ref position, attributeDelegate,
                            (object)attributeNames);

                // Write out the names of the attributes
                foreach (string attributeName in attributeNames)
                {
                    Console.WriteLine("attribute name is {0}", attributeName);
                }

                // Demonstrate H5A.openName
                attributeId = H5A.openName(groupId, "descendingRamp");
                Console.WriteLine("got {0} by name", H5A.getName(attributeId));
                H5A.close(attributeId);

                // Demonstrate H5A.getNameByIndex
                string secondAttribute = H5A.getNameByIndex(groupId, ".",
                                                            H5IndexType.CRT_ORDER, H5IterationOrder.INCREASING, 1);

                Console.WriteLine("second attribute is named {0}",
                                  secondAttribute);

                // Demonstrate H5G.getInfo
                H5GInfo gInfo = H5G.getInfo(groupId);
                Console.WriteLine(
                    "link storage: {0}, max creation order: {1}, nLinks: {2}",
                    gInfo.linkStorageType, gInfo.maxCreationOrder, gInfo.nLinks);


                // Demonstrate H5A.getSpace
                //attributeId = H5A.openByName(groupId, ".", "descendingRamp");
                attributeId = H5A.open(groupId, "descendingRamp");
                H5DataSpaceId rampSpaceId = H5A.getSpace(attributeId);
                H5S.close(rampSpaceId);

                // Demonstrate H5A.getType
                H5DataTypeId rampTypeId = H5A.getType(attributeId);
                Console.WriteLine("size of ramp data type is {0} bytes.",
                                  H5T.getSize(rampTypeId));
                H5T.close(rampTypeId);

                // Demonstrate H5A.getInfo
                H5AttributeInfo rampInfo = H5A.getInfo(attributeId);
                Console.WriteLine(
                    "characterset: {0}, creationOrder: {1}, creationOrderValid: {2}, dataSize: {3}",
                    rampInfo.characterSet, rampInfo.creationOrder,
                    rampInfo.creationOrderValid, rampInfo.dataSize);

                // Demonstrate H5A.Delete
                H5A.Delete(groupId, "descendingRamp");
                //H5A.DeleteByName(groupId, ".", "descendingRamp");

                // Iterate through the attributes to show that the deletion
                // was successful.
                position = 0;
                ArrayList namesAfterDeletion = new ArrayList();
                H5A.iterate(groupId, H5IndexType.CRT_ORDER,
                            H5IterationOrder.DECREASING, ref position,
                            attributeDelegate,
                            (object)namesAfterDeletion);


                H5G.close(groupId);

                H5F.close(fileId);

                // Reopen and reclose the file.
                H5FileId openId = H5F.open("myCSharp.h5",
                                           H5F.OpenMode.ACC_RDONLY);
                H5F.close(openId);

                // Set the function to be called on error.
                unsafe
                {
                    H5AutoCallback myErrorDelegate = new H5AutoCallback(myErrorFunction);
                    H5E.setAuto(0, myErrorDelegate, IntPtr.Zero);
                }

                // Uncomment the next line if you want to generate an error to
                // test H5E.setAuto
                // H5G.open(openId, "noGroup");
            }
            // This catches all the HDF exception classes.  Because each call
            // generates a unique exception, different exception can be handled
            // separately.  For example, to catch open errors we could have used
            // catch (H5FopenException openException).
            catch (HDFException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Processing complete!");
            Console.ReadLine();
        }
예제 #30
0
        public static List <(string Path, string Name)> GetPathSet(long locationId, int maxDepth, bool includeGroups, bool includeDatasets)
        {
            ulong idx;
            List <(string Path, string Name)> datasetPathSet;

            H5E.auto_t func;
            IntPtr     clientData;

            idx            = default;
            datasetPathSet = new List <(string Path, string Name)>();
            func           = null;
            clientData     = IntPtr.Zero;

            H5E.get_auto(H5E.DEFAULT, ref func, ref clientData);
            H5E.set_auto(H5E.DEFAULT, null, IntPtr.Zero);
            H5L.iterate(locationId, H5.index_t.NAME, H5.iter_order_t.INC, ref idx, Callback, Marshal.StringToHGlobalAnsi("/"));
            H5E.set_auto(H5E.DEFAULT, func, clientData);

            return(datasetPathSet);

            int Callback(long groupId, IntPtr intPtrName, ref H5L.info_t info, IntPtr intPtrUserData)
            {
                long datasetId = -1;

                ulong idx2 = default;
                int   level;

                string name;
                string userData;

                H5O.type_t objectType;

                name     = Marshal.PtrToStringAnsi(intPtrName);
                userData = Marshal.PtrToStringAnsi(intPtrUserData);
                level    = userData.Split("/".ToArray()).Count();

                // this is necessary, since H5Oget_info_by_name is slow because it wants verbose object header data
                // and H5G_loc_info is not directly accessible
                // only chance is to modify source code (H5Oget_info_by_name) or use V2 B-tree
                datasetId = H5D.open(groupId, name);

                if (datasetId > -1)
                {
                    objectType = H5O.type_t.DATASET;
                }
                else
                {
                    groupId = H5G.open(groupId, name);

                    if (groupId > -1)
                    {
                        objectType = H5O.type_t.GROUP;
                    }
                    else
                    {
                        objectType = H5O.type_t.UNKNOWN;
                    }
                }

                switch (objectType)
                {
                case H5O.type_t.GROUP:

                    if (level <= maxDepth)
                    {
                        H5L.iterate(groupId, H5.index_t.NAME, H5.iter_order_t.INC, ref idx2, Callback, Marshal.StringToHGlobalAnsi(GeneralHelper.CombinePath(userData, name)));

                        if (includeGroups)
                        {
                            datasetPathSet.Add((userData, name));
                        }

                        H5G.close(groupId);
                    }

                    break;

                case H5O.type_t.DATASET:

                    if (includeDatasets)
                    {
                        datasetPathSet.Add((userData, name));
                    }

                    H5D.close(datasetId);
                    break;

                default:
                    break;
                }

                return(0);
            }
        }