示例#1
0
        public static Dictionary <uint, string> GetLabelWorkingSet(long group_id)
        {
            Dictionary <uint, string> labelWorkingSet = new Dictionary <uint, string>();

            H5A.operator_t callBackMethod  = DelegateMethod;
            ArrayList      attrNameArray   = new ArrayList();
            GCHandle       nameArrayAlloc  = GCHandle.Alloc(attrNameArray);
            IntPtr         ptrOnAllocArray = (IntPtr)nameArrayAlloc;
            int            status;
            ulong          beginAt = 0;

            status = H5A.iterate(group_id, H5.index_t.CRT_ORDER, H5.iter_order_t.INC, ref beginAt, callBackMethod, ptrOnAllocArray);

            for (int i = 0; i < attrNameArray.Count; i++)
            {
                string   attr_name  = Convert.ToString(attrNameArray[i]);
                long     attr_id    = H5A.open(group_id, attr_name);
                uint[]   attr_value = { 0 };
                GCHandle valueAlloc = GCHandle.Alloc(attr_value, GCHandleType.Pinned);

                status = H5A.read(attr_id, H5T.NATIVE_UINT32, valueAlloc.AddrOfPinnedObject());
                status = H5A.close(attr_id);
                labelWorkingSet.Add(attr_value[0], attr_name);
            }

            status = H5G.close(group_id);

            return(labelWorkingSet);
        }
示例#2
0
        private void GetAllFileAttributes()
        {
            //所有Attributes的键
            ArrayList arrayList = new ArrayList();
            GCHandle  handle    = GCHandle.Alloc(arrayList);
            ulong     n         = 0;

            // the callback is defined in H5ATest.cs
            H5A.operator_t cb = (int location_id, IntPtr attr_name, ref H5A.info_t ainfo, IntPtr op_data) =>
            {
                GCHandle  hnd = (GCHandle)op_data;
                ArrayList al  = (hnd.Target as ArrayList);
                int       len = 0;
                while (Marshal.ReadByte(attr_name, len) != 0)
                {
                    ++len;
                }
                byte[] buf = new byte[len];
                Marshal.Copy(attr_name, buf, 0, len);
                al.Add(Encoding.UTF8.GetString(buf));
                return(0);
            };
            H5A.iterate(_h5FileId, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n, cb, (IntPtr)handle);
            handle.Free();

            foreach (string attributeName in arrayList)
            {
                _fileAttrs.Add(attributeName, ReadAttributeValue(_h5FileId, attributeName));
            }
        }
示例#3
0
        public void H5AiterateTest1()
        {
            hid_t att = H5A.create(m_v2_test_file, "IEEE_F32BE",
                                   H5T.IEEE_F32BE, m_space_scalar);

            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v2_test_file, "IEEE_F64BE", H5T.IEEE_F64BE,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v2_test_file, "NATIVE_B8", H5T.NATIVE_B8,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            ArrayList al      = new ArrayList();
            GCHandle  hnd     = GCHandle.Alloc(al);
            IntPtr    op_data = (IntPtr)hnd;
            hsize_t   n       = 0;

            // the callback is defined in H5ATest.cs
            H5A.operator_t cb = DelegateMethod;
            Assert.IsTrue(H5A.iterate(m_v2_test_file, H5.index_t.NAME,
                                      H5.iter_order_t.NATIVE, ref n, cb, op_data) >= 0);
            // we should have 3 elements in the array list
            Assert.IsTrue(al.Count == 3);

            att = H5A.create(m_v0_test_file, "IEEE_F32BE",
                             H5T.IEEE_F32BE, m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v0_test_file, "IEEE_F64BE", H5T.IEEE_F64BE,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v0_test_file, "NATIVE_B8", H5T.NATIVE_B8,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            al.Clear();
            n = 0;
            Assert.IsTrue(H5A.iterate(m_v0_test_file, H5.index_t.NAME,
                                      H5.iter_order_t.NATIVE, ref n, cb, op_data) >= 0);
            // we should have 3 elements in the array list
            Assert.IsTrue(al.Count == 3);

            hnd.Free();
        }
示例#4
0
        public void H5Aiterate_by_nameTest2()
        {
            ArrayList al      = new ArrayList();
            GCHandle  hnd     = GCHandle.Alloc(al);
            IntPtr    op_data = (IntPtr)hnd;
            hsize_t   n       = 0;

            // the callback is defined in H5ATest.cs
            H5A.operator_t cb = DelegateMethod;

            Assert.IsFalse(
                H5A.iterate_by_name(Utilities.RandomInvalidHandle(), ".",
                                    H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n,
                                    cb, op_data) >= 0);

            hnd.Free();
        }
示例#5
0
        public Dictionary <string, string> GetDatasetAttributes(string originalDatasetName)
        {
            H5DataSetId   datasetId = 0;
            H5GroupId     groupId   = 0;
            H5DataTypeId  typeId    = 0;
            H5DataSpaceId spaceId   = 0;

            try
            {
                if (_h5FileId < 0)
                {
                    return(null);
                }
                string datasetName = GetDatasetFullNames(originalDatasetName, _h5FileId);
                if (string.IsNullOrEmpty(datasetName))
                {
                    return(null);
                }
                int groupIndex = datasetName.LastIndexOf('/');
                if (groupIndex == -1)
                {
                    datasetId = H5D.open(_h5FileId, datasetName);
                }
                else
                {
                    string groupName = datasetName.Substring(0, groupIndex + 1);
                    string dsName    = datasetName.Substring(groupIndex + 1);
                    groupId   = H5G.open(_h5FileId, groupName);
                    datasetId = H5D.open(groupId, dsName);
                }
                if (datasetId == 0)
                {
                    return(null);
                }
                Dictionary <string, string> attValues = new Dictionary <string, string>();

                typeId = H5D.get_type(datasetId);
                H5T.class_t type  = H5T.get_class(typeId);
                IntPtr      tSize = H5T.get_size(typeId);

                spaceId = H5D.get_space(datasetId);

                int     length = H5S.get_simple_extent_ndims(spaceId);
                ulong[] dims   = new ulong[length];
                H5S.get_simple_extent_dims(spaceId, dims, null);
                ulong storageSize = H5D.get_storage_size(datasetId);

                attValues.Add("DataSetName", datasetName);
                attValues.Add("DataType", type.ToString());
                attValues.Add("DataTypeSize", tSize.ToString() + "Byte");
                attValues.Add("Dims", String.Join("*", dims));
                attValues.Add("StorageSize", storageSize.ToString() + "Byte");


                //所有Attributes的键
                ArrayList arrayList = new ArrayList();
                GCHandle  handle    = GCHandle.Alloc(arrayList);
                ulong     n         = 0;
                // the callback is defined in H5ATest.cs
                H5A.operator_t cb = (int location_id, IntPtr attr_name, ref H5A.info_t ainfo, IntPtr op_data) =>
                {
                    GCHandle  hnd = (GCHandle)op_data;
                    ArrayList al  = (hnd.Target as ArrayList);
                    int       len = 0;
                    while (Marshal.ReadByte(attr_name, len) != 0)
                    {
                        ++len;
                    }
                    byte[] buf = new byte[len];
                    Marshal.Copy(attr_name, buf, 0, len);
                    al.Add(Encoding.UTF8.GetString(buf));
                    return(0);
                };
                H5A.iterate(datasetId, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n, cb, (IntPtr)handle);
                handle.Free();

                foreach (string attName in arrayList)
                {
                    attValues.Add(attName, ReadAttributeValue(datasetId, attName));
                }
                return(attValues);
            }
            finally
            {
                if (spaceId != 0)
                {
                    H5S.close(spaceId);
                }
                if (typeId != 0)
                {
                    H5T.close(typeId);
                }
                if (datasetId != 0)
                {
                    H5D.close(datasetId);
                }
                if (groupId != 0)
                {
                    H5G.close(groupId);
                }
            }
        }
示例#6
0
        public void H5Aiterate_by_nameTest1()
        {
            hid_t att = H5A.create(m_v2_test_file, "IEEE_F32BE",
                                   H5T.IEEE_F32BE, m_space_scalar);

            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v2_test_file, "IEEE_F64BE", H5T.IEEE_F64BE,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v2_test_file, "NATIVE_B8", H5T.NATIVE_B8,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);
            ArrayList al = new ArrayList();
            hsize_t   n  = 0;

            // if we define the callback as lambda we can simple capture the array list
            H5A.operator_t cb = (hid_t location_id, IntPtr attr_name, ref H5A.info_t ainfo, IntPtr op_data
                                 ) => {
                Assert.IsTrue(op_data.ToInt64() == -99);
                int len = 0;
                while (Marshal.ReadByte(attr_name, len) != 0)
                {
                    ++len;
                }
                byte[] buf = new byte[len];
                Marshal.Copy(attr_name, buf, 0, len);
                al.Add(Encoding.UTF8.GetString(buf));
                return(0);
            };

            Assert.IsTrue(H5A.iterate_by_name(m_v2_test_file, ".",
                                              H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n, cb,
                                              // the op_data argument is simply tested as a constant
                                              new IntPtr(-99)) >= 0);
            // we should have 3 elements in the array list [now obsolete]
            Assert.IsTrue(al.Count == 3);
            Assert.IsFalse(al.ToArray().Any(s => s == null || String.IsNullOrEmpty(s.ToString())));
            // let's be specific
            Assert.IsTrue(al[0].ToString() == "IEEE_F32BE");
            Assert.IsTrue(al[1].ToString() == "IEEE_F64BE");
            Assert.IsTrue(al[2].ToString() == "NATIVE_B8");

            att = H5A.create(m_v0_test_file, "IEEE_F32BE",
                             H5T.IEEE_F32BE, m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v0_test_file, "IEEE_F64BE", H5T.IEEE_F64BE,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v0_test_file, "NATIVE_B8", H5T.NATIVE_B8,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            al.Clear();
            n = 0;
            Assert.IsTrue(H5A.iterate_by_name(m_v0_test_file, ".",
                                              H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n, cb,
                                              new IntPtr(-99)) >= 0);
            // we should have 3 elements in the array list [now obsolete]
            Assert.IsTrue(al.Count == 3);
            Assert.IsFalse(al.ToArray().Any(s => s == null || String.IsNullOrEmpty(s.ToString())));
            // let's be specific
            Assert.IsTrue(al[0].ToString() == "IEEE_F32BE");
            Assert.IsTrue(al[1].ToString() == "IEEE_F64BE");
            Assert.IsTrue(al[2].ToString() == "NATIVE_B8");
        }