Example #1
0
        void FindAttribute(int i)
        {
            var attr_field = "FIELD_" + i + "_NAME";

            var attr = H5A.open(Id, attr_field);
            var dtype = H5A.getType(attr);
            var size = H5T.getSize(dtype);

            var mtype = H5T.create(H5T.CreateClass.STRING, size);
            var buffer = new byte[size];
            H5A.read(attr, mtype, new H5Array<byte>(buffer));

            var attr_datatype = H5T.getMemberType(H5D.getType(Id), i);
            var attr_size = H5T.getSize(attr_datatype);

            var attr_class = H5T.getMemberClass(H5D.getType(Id), i).ToString();
            var attr_name = Encoding.GetString(buffer).Replace('\0', ' ').Trim();

            switch (attr_class)
            {
                case "STRING":
                    _attributes[i] = new StringAttribute(attr_name, attr_size);
                    break;
                case "INTEGER":
                    _attributes[i] = new IntegerAttribute(attr_name, attr_size);
                    break;
                case "FLOAT":
                    _attributes[i] = new FloatingPointAttribute(attr_name, attr_size);
                    break;
                default:
                    throw new ArgumentException("Unknown attribute type " + attr_class, "attr_type");
            }
        }
Example #2
0
        void FindAttribute(int i)
        {
            var attr_field = "FIELD_" + i + "_NAME";

            var attr  = H5A.open(Id, attr_field);
            var dtype = H5A.getType(attr);
            var size  = H5T.getSize(dtype);

            var mtype  = H5T.create(H5T.CreateClass.STRING, size);
            var buffer = new byte[size];

            H5A.read(attr, mtype, new H5Array <byte>(buffer));

            var attr_datatype = H5T.getMemberType(H5D.getType(Id), i);
            var attr_size     = H5T.getSize(attr_datatype);

            var attr_class = H5T.getMemberClass(H5D.getType(Id), i).ToString();
            var attr_name  = Encoding.GetString(buffer).Replace('\0', ' ').Trim();

            switch (attr_class)
            {
            case "STRING":
                _attributes[i] = new StringAttribute(attr_name, attr_size);
                break;

            case "INTEGER":
                _attributes[i] = new IntegerAttribute(attr_name, attr_size);
                break;

            case "FLOAT":
                _attributes[i] = new FloatingPointAttribute(attr_name, attr_size);
                break;

            default:
                throw new ArgumentException("Unknown attribute type " + attr_class, "attr_type");
            }
        }
Example #3
0
        protected override void LoadData()
        {
            //Determine type and size of data
            var dtype = H5D.getType(Id);
            var size  = H5T.getSize(dtype);

            var space = H5D.getSpace(Id);
            var dims  = H5S.getSimpleExtentDims(space);

            var num_dimensions = dims.Length;

            if (num_dimensions != 1 && num_dimensions != 2)
            {
                throw new ArgumentException("Scalar dataset has more than 2 dimensions! Cannot be handled.", "datasetname");
            }

            var member_type = H5T.getClass(dtype).ToString();
            var member_size = size;

            //Setup parser
            Attribute parser = null;

            switch (member_type)
            {
            case "STRING":
                parser = new StringAttribute("data", member_size);
                break;

            case "INTEGER":
                parser = new IntegerAttribute("data", member_size);
                break;

            case "FLOAT":
                parser = new FloatingPointAttribute("data", member_size);
                break;

            default:
                throw new ArgumentException("Unsupported member type " + member_type, "member_type");
            }

            if (num_dimensions == 1)
            {
                var _row_data = new byte[dims[0], size];
                H5D.read(Id, dtype, new H5Array <byte>(_row_data));

                //Parse rows
                for (int i = 0; i < dims[0]; i++)
                {
                    var dat = new Dictionary <string, object>();
                    dat["0"] = parser.Parse(_row_data.Field(i));
                    AddRow(new Row(dat));
                }
            }
            else if (num_dimensions == 2)
            {
                var _row_data = new byte[dims[0], dims[1], size];
                H5D.read(Id, dtype, new H5Array <byte>(_row_data));

                //Parse rows
                for (int i = 0; i < dims[0]; i++)
                {
                    var dat = new Dictionary <string, object>();
                    for (int j = 0; j < dims[1]; j++)
                    {
                        dat["" + j] = parser.Parse(_row_data.Field(i, j));
                    }
                    AddRow(new Row(dat));
                }
            }
        }