Exemple #1
0
        public void H5Iget_nameTest2()
        {
            IntPtr size = H5I.get_name(Utilities.RandomInvalidHandle(), null,
                                       IntPtr.Zero);

            Assert.IsFalse(size.ToInt32() >= 0);
        }
Exemple #2
0
        public void H5Iget_nameTest1()
        {
            hid_t gid = H5G.create(m_v0_test_file, "AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(gid > 0);

            ssize_t buf_size = H5I.get_name(gid, (StringBuilder)null,
                                            IntPtr.Zero) + 1;

            Assert.IsTrue(buf_size.ToInt32() > 1);
            StringBuilder nameBuilder = new StringBuilder(buf_size.ToInt32());
            IntPtr        size        = H5I.get_name(gid, nameBuilder, buf_size);

            Assert.IsTrue(size.ToInt32() > 0);
            Assert.IsTrue(nameBuilder.ToString() == "/AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(H5G.close(gid) >= 0);

            gid = H5G.create(m_v2_test_file, "AAAAAAAAAAAAAAAAAAAAA");
            Assert.IsTrue(gid > 0);

            buf_size = H5I.get_name(gid, (StringBuilder)null, IntPtr.Zero) + 1;
            Assert.IsTrue(buf_size.ToInt32() > 1);
            nameBuilder = new StringBuilder(buf_size.ToInt32());
            size        = H5I.get_name(gid, nameBuilder, buf_size);
            Assert.IsTrue(size.ToInt32() > 0);
            Assert.IsTrue(nameBuilder.ToString() == "/AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(H5G.close(gid) >= 0);
        }
Exemple #3
0
        private static List <HDF5info> ScanInfo(hid_t gId, List <HDF5info> fields, string fullname)
        {
            IntPtr MAX_NAME = new IntPtr(1024);

            System.Text.StringBuilder group_name  = new System.Text.StringBuilder();
            System.Text.StringBuilder member_name = new System.Text.StringBuilder();
            IntPtr len = H5I.get_name(gId, group_name, MAX_NAME);

            hsize_t nobj = new hsize_t();

            H5G.get_num_objs(gId, ref nobj);

            for (int i = 0; i < (int)nobj; i++)
            {
                member_name          = new System.Text.StringBuilder();
                member_name.Capacity = 1024;
                IntPtr len2    = H5G.get_objname_by_idx(gId, (ulong)i, member_name, MAX_NAME);
                int    objtype = H5G.get_objtype_by_idx(gId, (ulong)i);

                if (objtype == 0) //group
                {
                    hid_t gId2 = H5G.open(gId, member_name.ToString());
                    fields = ScanInfo(gId2, fields, string.Format("{0}/{1}", fullname, member_name));
                }
                else if (objtype == 1) //Object is a dataset.
                {
                    HDF5info hDF5Info = new HDF5info();
                    hid_t    dset     = H5D.open(gId, member_name.ToString());
                    hid_t    fspace   = H5D.get_space(dset);

                    hid_t count = H5S.get_simple_extent_ndims(fspace);
                    hid_t type  = H5D.get_type(dset);


                    hDF5Info.HDFclass = getH5Tstring(type);
                    hDF5Info.field    = string.Format("{0}/{1}", fullname, member_name);
                    if (H5T.get_class(type) == H5T.class_t.STRING)
                    {
                        hDF5Info.description = nirs.io.ReadDataString(gId, string.Format("{0}", member_name));
                    }
                    else if (H5T.get_class(type) == H5T.class_t.FLOAT |
                             H5T.get_class(type) == H5T.class_t.INTEGER)
                    {
                        hsize_t[] dims    = new hsize_t[count];
                        hsize_t[] maxdims = new hsize_t[count];
                        H5S.get_simple_extent_dims(fspace, dims, maxdims);
                        if (dims.Length == 1 & dims[0] == 1)
                        {
                            var val = nirs.io.ReadDataValue(gId, string.Format("{0}", member_name));
                            hDF5Info.description = string.Format("{0}", val);
                        }
                        else if (dims.Length == 1 & dims[0] > 1)
                        {
                            hDF5Info.description = string.Format("Vector <{0} x 1>", dims[0]);
                        }
                        else
                        {
                            hDF5Info.description = string.Format("Array <{0} x {1}>", dims[0], dims[1]);

                            if (hDF5Info.field.Contains("dataTimeSeries") & dims[0] > dims[1])
                            {
                                hDF5Info.description += " TRANSPOSE WARNING ";
                            }
                            if (hDF5Info.field.Contains("Pos") & dims[1] != 3)
                            {
                                hDF5Info.description += " TRANSPOSE WARNING ";
                            }
                            if (hDF5Info.field.Contains("stim") & hDF5Info.field.Contains("data") & dims[1] != 3)
                            {
                                hDF5Info.description += " TRANSPOSE WARNING ";
                            }
                        }
                    }
                    else
                    {
                        hDF5Info.description = "";
                    }
                    fields.Add(hDF5Info);
                }
            }


            H5G.close(gId);


            return(fields);
        }