Ejemplo n.º 1
0
 public void H5Oget_info_by_idxTest2()
 {
     H5O.info_t info = new H5O.info_t();
     Assert.IsFalse(
         H5O.get_info_by_idx(Utilities.RandomInvalidHandle(), "A",
                             H5.index_t.NAME, H5.iter_order_t.NATIVE, 44, ref info) >= 0);
 }
Ejemplo n.º 2
0
        public static ulong NumberOfAttributes(int groupId, string groupName)
        {
            H5O.info_t info = new H5O.info_t();
            var        gid  = H5O.get_info(groupId, ref info);

            return(info.num_attrs);
        }
Ejemplo n.º 3
0
        public void H5Oget_info_by_idxTest1()
        {
            Assert.IsTrue(
                H5G.close(H5G.create(m_v0_test_file, "A")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v0_test_file, "AA")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v0_test_file, "AAA")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v0_test_file, "AAAA")) >= 0);

            H5O.info_t info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info_by_idx(m_v0_test_file, ".",
                                              H5.index_t.NAME, H5.iter_order_t.NATIVE, 2, ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);

            Assert.IsTrue(
                H5G.close(H5G.create(m_v2_test_file, "A")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v2_test_file, "AA")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v2_test_file, "AAA")) >= 0);
            Assert.IsTrue(
                H5G.close(H5G.create(m_v2_test_file, "AAAA")) >= 0);

            info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info_by_idx(m_v2_test_file, ".",
                                              H5.index_t.NAME, H5.iter_order_t.NATIVE, 2, ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);
        }
Ejemplo n.º 4
0
        public static object GetObject(Hdf5Identifier _fileId, AbstractHdf5Object _parent, string _objectName)
        {
            Hdf5Path combinedPath = _parent.Path.Append(_objectName);
            object   output       = null;

            if (combinedPath != null)
            {
                string fullPath = combinedPath.FullPath;

                H5O.info_t gInfo = new H5O.info_t();
                H5O.get_info_by_name(_fileId.Value, fullPath, ref gInfo);

                var id = H5O.open(_fileId.Value, fullPath).ToId();
                if (id.Value > 0)
                {
                    if (gInfo.type == H5O.type_t.DATASET)
                    {
                        output = DatasetHelper.LoadDataset(_fileId, id, fullPath);
                    }

                    if (gInfo.type == H5O.type_t.GROUP)
                    {
                        Hdf5Group group = new Hdf5Group(_fileId, id, fullPath);
                        group.FileId = _fileId;
                        group.LoadChildObjects();
                        output = group;
                    }

                    H5O.close(id.Value);
                }
            }

            return(output);
        }
Ejemplo n.º 5
0
        public static H5O.info_t GroupInfo(long groupId)
        {
            H5O.info_t info = new H5O.info_t();
            var        gid  = H5O.get_info(groupId, ref info);

            return(info);
        }
Ejemplo n.º 6
0
 public void H5Oget_info_by_nameTest2()
 {
     H5O.info_t info = new H5O.info_t();
     Assert.IsFalse(
         H5O.get_info_by_name(Utilities.RandomInvalidHandle(), ".",
                              ref info) >= 0);
 }
Ejemplo n.º 7
0
        public static bool GroupExists(hid_t groupId, string groupName)
        {
            H5O.info_t info = new H5O.info_t();
            var        gid  = H5O.get_info_by_name(groupId, groupName, ref info, H5P.DEFAULT);

            return(gid == 0);
        }
Ejemplo n.º 8
0
        protected Dictionary <string, long> FindChildren(bool dataSets)
        {
            Dictionary <string, long> datasetNames = new Dictionary <string, long>();
            Dictionary <string, long> groupNames   = new Dictionary <string, long>();
            var rootID = Open();

            ulong dummy = 0;

            H5L.iterate(rootID, H5.index_t.NAME, H5.iter_order_t.INC, ref dummy, new H5L.iterate_t(
                            delegate(long objectId, IntPtr namePtr, ref H5L.info_t info, IntPtr op_data)
            {
                string objectName = Marshal.PtrToStringAnsi(namePtr);
                H5O.info_t gInfo  = new H5O.info_t();
                H5O.get_info_by_name(objectId, objectName, ref gInfo);

                if (gInfo.type == H5O.type_t.DATASET)
                {
                    datasetNames[objectName] = objectId;
                }
                else if (gInfo.type == H5O.type_t.GROUP)
                {
                    groupNames[objectName] = objectId;
                }
                return(0);
            }), new IntPtr());

            H5G.close(rootID);

            if (dataSets)
            {
                return(datasetNames);
            }
            return(groupNames);
        }
Ejemplo n.º 9
0
        private string[] CollectObjects(H5O.type_t type)
        {
            const int     CONTINUE = 0;
            int           status;
            List <string> rv = new List <string>();

            // the callback function, called for each item in the iteration
#if HDF5_VER1_10
            H5L.iterate_t op_fun = (long loc, IntPtr name, ref H5L.info_t info, IntPtr op_data) =>
#else
            H5L.iterate_t op_fun = (int loc, IntPtr name, ref H5L.info_t info, IntPtr op_data) =>
#endif
            {
                H5O.info_t oinfo = new H5O.info_t();
                var        bname = Marshal.PtrToStringAnsi(name);
                if ((status = H5O.get_info_by_name(loc, bname, ref oinfo, H5P.DEFAULT)) < 0)
                {
                    return(status);
                }

                if (oinfo.type == type)
                {
                    rv.Add(bname);
                }

                return(CONTINUE);
            };
            ulong tracking_index = 0;
            if ((status = H5L.iterate(ID, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref tracking_index, op_fun, IntPtr.Zero)) < 0)
            {
                throw new H5LibraryException($"H5Literate() returned {status}");
            }

            return(rv.ToArray());
        }
Ejemplo n.º 10
0
        public void H5RdereferenceTest4()
        {
            byte[] path =
                Encoding.UTF8.GetBytes(String.Join("/", m_utf8strings));
            // make room for the trailling \0
            byte[] name = new byte[path.Length + 1];
            Array.Copy(path, name, path.Length);

            hsize_t[] dims  = new hsize_t[] { 10, 20 };
            hid_t     space = H5S.create_simple(2, dims, null);

            Assert.IsTrue(space >= 0);
            hid_t dset = H5D.create(m_v2_test_file, name, H5T.STD_I32LE, space,
                                    m_lcpl_utf8);

            H5O.info_t info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info(dset, ref info) >= 0);
            haddr_t address = info.addr;

            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(dset >= 0);
            hsize_t[] start = { 5, 10 };
            hsize_t[] count = { 1, 1 };
            hsize_t[] block = { 2, 4 };
            Assert.IsTrue(
                H5S.select_hyperslab(space, H5S.seloper_t.SET, start, null,
                                     count, block) >= 0);

            byte[]   refer = new byte[H5R.DSET_REG_REF_BUF_SIZE];
            GCHandle hnd   = GCHandle.Alloc(refer, GCHandleType.Pinned);

            Assert.IsTrue(
                H5R.create(hnd.AddrOfPinnedObject(), m_v2_test_file, name,
                           H5R.type_t.DATASET_REGION, space) >= 0);

            #if HDF5_VER1_10
            dset = H5R.dereference(m_v2_test_file, H5P.DEFAULT,
                                   H5R.type_t.DATASET_REGION, hnd.AddrOfPinnedObject());
            #else
            dset = H5R.dereference(m_v2_test_file, H5R.type_t.DATASET_REGION,
                                   hnd.AddrOfPinnedObject());
            #endif
            Assert.IsTrue(dset >= 0);

            hnd.Free();

            Assert.IsTrue(H5O.get_info(dset, ref info) >= 0);
            Assert.IsTrue(address == info.addr);
            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(H5S.close(space) >= 0);
        }
Ejemplo n.º 11
0
        public void H5Oget_info_by_nameTest1()
        {
            Assert.IsTrue(
                H5G.close(H5G.create(m_v0_test_file, "A/B/C", m_lcpl)) >= 0);

            H5O.info_t info = new H5O.info_t();
            Assert.IsTrue(
                H5O.get_info_by_name(m_v0_test_file, "A/B", ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);

            Assert.IsTrue(
                H5G.close(H5G.create(m_v2_test_file, "A/B/C", m_lcpl)) >= 0);

            info = new H5O.info_t();
            Assert.IsTrue(
                H5O.get_info_by_name(m_v2_test_file, "A/B", ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);
        }
Ejemplo n.º 12
0
        // Callback for H5O.visit and H5O.visit_by_name
        // We expect an array list as op_data, add the attribute names to the
        // array list as we go
        public herr_t DelegateMethod
        (
            hid_t obj,
            IntPtr name,
            ref H5O.info_t info,
            IntPtr op_data
        )
        {
            GCHandle  hnd = (GCHandle)op_data;
            ArrayList al  = (hnd.Target as ArrayList);
            int       len = 0;

            while (Marshal.ReadByte(name, len) != 0)
            {
                ++len;
            }
            byte[] name_buf = new byte[len];
            Marshal.Copy(name, name_buf, 0, len);
            al.Add(Encoding.UTF8.GetString(name_buf));
            return(0);
        }
Ejemplo n.º 13
0
        public void H5Oget_infoTest1()
        {
            hid_t gid = H5G.create(m_v0_test_file, "A/B/C", m_lcpl);

            Assert.IsTrue(gid >= 0);

            H5O.info_t info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info(gid, ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);

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

            gid = H5G.create(m_v2_test_file, "A/B/C", m_lcpl);
            Assert.IsTrue(gid >= 0);

            info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info(gid, ref info) >= 0);
            Assert.IsTrue(info.type == H5O.type_t.GROUP);

            Assert.IsTrue(H5G.close(gid) >= 0);
        }
Ejemplo n.º 14
0
        public void H5RdereferenceTest2()
        {
            byte[] path =
                Encoding.UTF8.GetBytes(String.Join("/", m_utf8strings));
            // make room for the trailling \0
            byte[] name = new byte[path.Length + 1];
            Array.Copy(path, name, path.Length);

            hid_t gid = H5G.create(m_v2_test_file, path, m_lcpl_utf8);

            Assert.IsTrue(gid >= 0);
            H5O.info_t info = new H5O.info_t();
            Assert.IsTrue(H5O.get_info(gid, ref info) >= 0);
            haddr_t address = info.addr;

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

            byte[]   refer = new byte[H5R.OBJ_REF_BUF_SIZE];
            GCHandle hnd   = GCHandle.Alloc(refer, GCHandleType.Pinned);

            Assert.IsTrue(
                H5R.create(hnd.AddrOfPinnedObject(), m_v2_test_file, name,
                           H5R.type_t.OBJECT, -1) >= 0);

            #if HDF5_VER1_10
            gid = H5R.dereference(m_v2_test_file, H5P.DEFAULT,
                                  H5R.type_t.OBJECT, hnd.AddrOfPinnedObject());
            #else
            gid = H5R.dereference(m_v2_test_file, H5P.DEFAULT,
                                  hnd.AddrOfPinnedObject());
            #endif
            Assert.IsTrue(gid >= 0);

            hnd.Free();

            Assert.IsTrue(H5O.get_info(gid, ref info) >= 0);
            Assert.IsTrue(address == info.addr);
            Assert.IsTrue(H5G.close(gid) >= 0);
        }
Ejemplo n.º 15
0
        public H5Group(FileFormat theFile, string name, string path, Group parent, IntPtr oid) : base(theFile, name, path, parent, oid)
        {
            nMembersInFile = -1;
            obj_info       = new H5O.info_t();

            if (theFile != null)
            {
                // throw new Exception("??");
                // retrieve the object ID
                try
                {
                    IntPtr ptr       = new IntPtr();
                    var    reference = H5R.create(ptr, theFile.getFID(), this.getFullName(), H5R.type_t.OBJECT, -1);
                    //todo:
                    address = ptr;
                    //this.oid = new long[1];
                    //this.oid[0] = HDFNativeData.byteToLong(ref_buf, 0);
                }
                catch (Exception ex)
                {
                    Hdf5Utils.LogError?.Invoke("ERROR: " + ex);
                }
            }
        }
Ejemplo n.º 16
0
        private void GetGroupDatasetNames(string groupName)
        {
            ulong         pos        = 0;
            List <string> groupNames = new List <string>();
            Int32         groupId    = H5G.open(_h5FileId, groupName);

            if (groupId > 0)
            {
                ArrayList al      = new ArrayList();
                GCHandle  hnd     = GCHandle.Alloc(al);
                IntPtr    op_data = (IntPtr)hnd;
                H5L.iterate(groupId, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref pos,
                            delegate(int _objectId, IntPtr _namePtr, ref H5L.info_t _info, IntPtr _data)
                {
                    string objectName = Marshal.PtrToStringAnsi(_namePtr);
                    groupNames.Add(objectName);
                    return(0);
                }, op_data);
                hnd.Free();
                H5G.close(groupId);

                foreach (var itemName in groupNames)
                {
                    //判断是不是数据集
                    string curPath = string.Empty;
                    if (groupName == "/")
                    {
                        curPath = itemName;
                    }
                    else
                    {
                        curPath = groupName + itemName;
                    }
                    H5O.info_t gInfo = new H5O.info_t();
                    H5O.get_info_by_name(_h5FileId, curPath, ref gInfo);
                    var objId = H5O.open(_h5FileId, curPath);
                    if (objId > 0)
                    {
                        if (gInfo.type == H5O.type_t.DATASET)
                        {
                            _datasetNames.Add(curPath);
                        }
                        if (gInfo.type == H5O.type_t.GROUP)
                        {
                            GetGroupDatasetNames(curPath + "/");
                        }
                        H5O.close(objId);
                    }
                }
            }



            //    H5GroupId h5GroupId = H5G.open(_h5FileId, groupName);
            //try
            //{

            //    long dscount = H5G.getNumObjects(h5GroupId);
            //    for (int i = 0; i < dscount; i++)
            //    {
            //        string objname = H5G.getObjectNameByIndex(h5GroupId, (ulong)i);
            //        ObjectInfo objInfo = H5G.getObjectInfo(h5GroupId, objname, false);
            //        switch (objInfo.objectType)
            //        {
            //            case H5GType.DATASET:
            //                if (objInfo.objectType == H5GType.DATASET)
            //                {
            //                    if (groupName == "/")
            //                        _datasetNames.Add(objname);
            //                    else
            //                        _datasetNames.Add(groupName + objname);
            //                }
            //                break;
            //            case H5GType.GROUP:
            //                if (groupName == "/")
            //                    GetGroupDatasetNames(objname + "/");
            //                else
            //                    GetGroupDatasetNames(groupName + objname + "/");
            //                break;
            //            case H5GType.LINK:
            //                break;
            //            case H5GType.TYPE:
            //                break;
            //            default:
            //                break;
            //        }
            //    }
            //}
            //finally
            //{
            //    if (h5GroupId != null)
            //        H5G.close(h5GroupId);
            //}
        }