public Grib1BitMapSection(FileStream fs) { long position = fs.Position; int[] bitmask = new int[] { 128, 64, 32, 16, 8, 4, 2, 1 }; // octet 1-3 (length of section) _sectionLength = GribNumberHelper.Uint3(fs); // octet 4 unused bits int unused = fs.ReadByte(); // octets 5-6 int bm = GribNumberHelper.Int2(fs); sbyte[] data = new sbyte[_sectionLength - 6]; StreamReadHelper.ReadInput(fs, data, 0, data.Length); // 创建新位图, octet 4包含末尾使用过的位数 _bitmap = new bool[(_sectionLength - 6) * 8 - unused]; // 填充位图 for (int i = 0; i < _bitmap.Length; i++) { _bitmap[i] = (data[i / 8] & bitmask[i % 8]) != 0; } fs.Seek(position + _sectionLength, SeekOrigin.Begin); }
private bool[] _bitmap = null;//是否是位图 public GRIB2BitMapSection(FileStream fs, int numberPoints) { int[] bitmask = new int[] { 128, 64, 32, 16, 8, 4, 2, 1 }; _sectionHeader = new GRIB2SectionHeader(fs); _bitMapIndicator = fs.ReadByte(); // no bitMap if (_bitMapIndicator != 0) { return; } sbyte[] data = new sbyte[_sectionHeader.SectionLength - 6]; StreamReadHelper.ReadInput(fs, data, 0, data.Length); // create new bit map, octet 4 contains number of unused bits at the end _bitmap = new bool[numberPoints]; // fill bit map for (int i = 0; i < _bitmap.Length; i++) { _bitmap[i] = (data[i / 8] & bitmask[i % 8]) != 0; } }