Example #1
0
        public void H5Aget_infoTest1()
        {
            H5A.info_t info = new H5A.info_t();
            hid_t      att  = H5A.create(m_v2_test_file, "A", H5T.IEEE_F64LE,
                                         m_space_scalar);

            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.get_info(att, ref info) >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);

            att = H5A.create(m_v0_test_file, "A", H5T.IEEE_F64LE,
                             m_space_scalar);
            Assert.IsTrue(att >= 0);
            Assert.IsTrue(H5A.get_info(att, ref info) >= 0);
            Assert.IsTrue(H5A.close(att) >= 0);
        }
Example #2
0
        private object GetAttributeValue(int _h5FileId, string attributeName)
        {
            H5AttributeId attId = H5A.open(_h5FileId, attributeName);

            if (attId == 0)
            {
                return(null);
            }
            H5DataTypeId typeId = 0;
            H5DataTypeId dtId   = 0;

            H5A.info_t    attInfo   = new H5A.info_t();
            H5DataSpaceId spaceId   = 0;
            H5DataTypeId  oldTypeId = 0;
            object        retObject = null;

            try
            {
                typeId = H5A.get_type(attId);
                H5A.get_info(attId, ref attInfo);
                dtId    = H5A.get_type(attId);
                spaceId = H5A.get_space(attId);
                IntPtr dataSize = H5T.get_size(dtId);
                //
                oldTypeId = typeId;
                typeId    = H5T.get_native_type(typeId, H5T.direction_t.DEFAULT);
                H5T.class_t typeClass = H5T.get_class(typeId);
                int         ndims     = H5S.get_simple_extent_ndims(spaceId);
                ulong[]     dims      = new ulong[ndims];
                H5S.get_simple_extent_dims(spaceId, dims, null);
                ulong dimSize = 1;
                if (dims.Length == 0)
                {
                    dimSize = 1;
                }
                else
                {
                    foreach (ulong dim in dims)
                    {
                        dimSize *= dim;
                    }
                }
                switch (typeClass)
                {
                case H5T.class_t.NO_CLASS:
                    break;

                case H5T.class_t.INTEGER:
                    // H5T.Sign.TWOS_COMPLEMENT;
                    H5T.sign_t sign = H5T.get_sign(oldTypeId);
                    switch (dataSize.ToInt32())
                    {
                    case 1:
                        retObject = ReadArray <byte>(dimSize, attId, typeId);
                        break;

                    case 2:
                        switch (sign)
                        {
                        case H5T.sign_t.SGN_2:
                            retObject = ReadArray <Int16>(dimSize, attId, typeId);
                            break;

                        case H5T.sign_t.NONE:
                            retObject = ReadArray <UInt16>(dimSize, attId, typeId);
                            break;
                        }
                        break;

                    case 4:
                        switch (sign)
                        {
                        case H5T.sign_t.SGN_2:
                            retObject = ReadArray <Int32>(dimSize, attId, typeId);
                            break;

                        case H5T.sign_t.NONE:
                            retObject = ReadArray <UInt32>(dimSize, attId, typeId);
                            break;
                        }
                        break;

                    case 8:
                        switch (sign)
                        {
                        case H5T.sign_t.SGN_2:
                            retObject = ReadArray <Int64>(dimSize, attId, typeId);
                            break;

                        case H5T.sign_t.NONE:
                            retObject = ReadArray <UInt64>(dimSize, attId, typeId);
                            break;
                        }
                        break;
                    }
                    break;

                case H5T.class_t.FLOAT:
                    switch (dataSize.ToInt32())
                    {
                    case 4:
                        retObject = ReadArray <float>(dimSize, attId, typeId);
                        break;

                    case 8:
                        retObject = ReadArray <double>(dimSize, attId, typeId);
                        break;
                    }
                    break;

                case H5T.class_t.STRING:
                    ulong  size  = attInfo.data_size;
                    byte[] chars = ReadArray <byte>(size, attId, typeId);
                    retObject = Encoding.ASCII.GetString(chars);
                    break;

                default:
                    break;
                }
                return(retObject);
            }
            finally
            {
                if (spaceId != 0)
                {
                    H5S.close(spaceId);
                }
                if (attId != 0)
                {
                    H5A.close(attId);
                }
                if (oldTypeId != 0)
                {
                    H5T.close(oldTypeId);
                }
                if (typeId != 0)
                {
                    H5T.close(typeId);
                }
                if (dtId != 0)
                {
                    H5T.close(dtId);
                }
            }
        }
Example #3
0
 public void H5Aget_infoTest2()
 {
     H5A.info_t info = new H5A.info_t();
     Assert.IsFalse(
         H5A.get_info(Utilities.RandomInvalidHandle(), ref info) >= 0);
 }