예제 #1
0
        public void H5Dget_storage_sizeTest1()
        {
            hsize_t[] dims  = { 1024, 2048 };
            hid_t     space = H5S.create_simple(2, dims, null);

            hid_t dcpl = H5P.create(H5P.DATASET_CREATE);

            Assert.IsTrue(dcpl >= 0);
            Assert.IsTrue(
                H5P.set_alloc_time(dcpl, H5D.alloc_time_t.EARLY) >= 0);

            hid_t dset = H5D.create(m_v0_test_file, "dset", H5T.STD_I16LE,
                                    space, H5P.DEFAULT, dcpl);

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

            dset = H5D.create(m_v2_test_file, "dset", H5T.STD_I16LE,
                              space, H5P.DEFAULT, dcpl);
            Assert.IsTrue(dset >= 0);
            Assert.IsTrue(H5D.get_storage_size(dset) == 4194304);
            Assert.IsTrue(H5D.close(dset) >= 0);

            Assert.IsTrue(H5P.close(dcpl) >= 0);
            Assert.IsTrue(H5S.close(space) >= 0);
        }
예제 #2
0
        public void H5Dget_storage_sizeTest2()
        {
            hid_t dset = H5D.create(m_v0_test_file, "dset", H5T.STD_I16LE,
                                    m_space_null);

            Assert.IsTrue(dset >= 0);
            hsize_t size = H5D.get_storage_size(dset);

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

            dset = H5D.create(m_v2_test_file, "dset", H5T.STD_I16LE,
                              m_space_null);
            Assert.IsTrue(dset >= 0);
            size = H5D.get_storage_size(dset);
            Assert.IsTrue(H5D.get_storage_size(dset) == 0);
            Assert.IsTrue(H5D.close(dset) >= 0);
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
 public void H5Dget_storage_sizeTest3()
 {
     Assert.IsFalse(
         H5D.get_storage_size(Utilities.RandomInvalidHandle()) > 0);
 }