private byte[] readCharData(DataDescriptor dkey, BitReader reader, Request req) throws IOException { int nchars = dkey.getByteWidthCDM(); byte[] b = new byte[nchars]; for (int i = 0; i < nchars; i++) b[i] = (byte) reader.bits2UInt(8); if (req.wantRow()) { for (int i = 0; i < nchars; i++) req.bb.put(b[i]); } return b; }
/** * Read the next nb bits and return an Signed Long . * * @param nb the number of bits to convert to int, must be <= 64. * @return result * @throws java.io.IOException on read error */ public long bits2SInt(int nb) throws IOException { long result = bits2UInt(nb); // check if we're negative if (getBit(result, nb)) { // it's negative! reset leading bit result = setBit(result, nb, false); // build 2's-complement result = ~result & LONG_BITMASK; result = result + 1; } return result; }
/** * Read the next nb bits and return an Signed Long . * * @param nb the number of bits to convert to int, must be <= 64. * @return result * @throws java.io.IOException on read error */ public long bits2SInt(int nb) throws IOException { long result = bits2UInt(nb); // check if we're negative if (getBit(result, nb)) { // it's negative! reset leading bit result = setBit(result, nb, false); // build 2's-complement result = ~result & LONG_BITMASK; result = result + 1; } return result; }
private long readNumericData(DataDescriptor dkey, BitReader reader, Request req) throws IOException { long result = reader.bits2UInt(dkey.bitWidth);
if (nb != 0) { for (int i = 0; i < NG; i++) X1[i] = (int) reader.bits2UInt(nb); reader.incrByte(); for (int i = 0; i < NG; i++) NB[i] = (int) reader.bits2UInt(nb); L[i] = ref + (int) reader.bits2UInt(nb) * len_inc; L[NG - 1] = gdrs.lengthLastGroup; // enter Length of Last Group int X2 = (int) reader.bits2UInt(NB[i]); if (mvm == 0) { data[count++] = (R + (X1[i] + X2) * EE) / DD;
if (nb != 0) { for (int i = 0; i < NG; i++) X1[i] = (int) reader.bits2UInt(nb); reader.incrByte(); for (int i = 0; i < NG; i++) NB[i] = (int) reader.bits2UInt(nb); L[i] = ref + (int) reader.bits2UInt(nb) * len_inc; L[NG - 1] = gdrs.lengthLastGroup; // enter Length of Last Group int X2 = (int) reader.bits2UInt(NB[i]); if (mvm == 0) { data[count++] = (R + (X1[i] + X2) * EE) / DD;
int[] groupWidth = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { groupWidth[i] = (int) reader.bits2UInt(gdrs.widthOfWidth); int[] groupLength = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { groupLength[i] = (int) reader.bits2UInt(gdrs.widthOfLength); int[] firstOrderValues = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { firstOrderValues[i] = (int) reader.bits2UInt(gdrs.widthOfFirstOrderValues); data[cnt]=(int) reader.bits2UInt(groupWidth[i]);
int[] groupWidth = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { groupWidth[i] = (int) reader.bits2UInt(gdrs.widthOfWidth); int[] groupLength = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { groupLength[i] = (int) reader.bits2UInt(gdrs.widthOfLength); int[] firstOrderValues = new int[gdrs.p1]; for (int i = 0; i < gdrs.p1; i++) { firstOrderValues[i] = (int) reader.bits2UInt(gdrs.widthOfFirstOrderValues); data[cnt]=(int) reader.bits2UInt(groupWidth[i]);
int[] getDataRaw(RandomAccessFile raf, byte[] bitmap) throws IOException { raf.seek(startPos); // go to the data section int msgLength = GribNumbers.uint3(raf); // octet 4, 1st half (packing flag) int unusedbits = raf.read(); if ((unusedbits & 192) != 0) { logger.error("Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing for {} len={}", raf.getLocation(), msgLength); throw new IllegalStateException("Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing "); } GribNumbers.int2(raf); // octets 5-6 (binary scale factor) GribNumbers.float4(raf); // octets 7-10 (reference point = minimum value) // octet 11 (number of bits per value) int numbits = raf.read(); // boolean isConstant = (numbits == 0); // *** read int values ******************************************************* BitReader reader = new BitReader(raf, startPos + 11); int[] ivals = new int[nPts]; for (int i = 0; i < nPts; i++) { ivals[i] = (int) reader.bits2UInt(numbits); } return ivals; }
int[] groupWidth = new int[NG]; for (int group = 0; group < NG; group++) { groupWidth[group] = (int) reader.bits2UInt(widthOfWidths); groupLength[group] = (int) reader.bits2UInt(widthOfLengths); showOffset(f, "FirstOrderValues", raf, startPos, N1 - 1); firstOrderValues[group] = (int) reader.bits2UInt(foWidth);
@Test @Ignore("why is this failing?") public void testSignedNegative3() throws IOException { BitReader bu = new BitReader(new byte[] {(byte)199,(byte)242,(byte)0,(byte)0,(byte)6,(byte)6}); assertEquals(799, (int) bu.bits2UInt(10)); assertEquals(800, (int) bu.bits2UInt(10)); assertEquals(-344, (int) bu.bits2SInt(10)); }
int count = (int) reader.bits2UInt(dkey.replicationCountSize); bitOffset += dkey.replicationCountSize; reader.bits2UInt(6); byte[] minValue = new byte[nc]; for (int i = 0; i < nc; i++) minValue[i] = (byte) reader.bits2UInt(8); int dataWidth = (int) reader.bits2UInt(6); // incremental data width in bytes counter.setDataWidth(8*dataWidth); int totalWidth = dkey.bitWidth + 6 + 8*dataWidth * ndatasets; // total width in bits for this compressed set of values byte[] incValue = new byte[nc]; for (int i = 0; i < nt; i++) incValue[i] = (byte) reader.bits2UInt(8); for (int i = nt; i < nc; i++) // can dataWidth < n ? incValue[i] = 0; long dataMin = reader.bits2UInt(useBitWidth); int dataWidth = (int) reader.bits2UInt(6); // increment data width - always in 6 bits, so max is 2^6 = 64 if (dataWidth > useBitWidth && (null != out)) out.f.format(" BAD WIDTH "); long cv = reader.bits2UInt(dataWidth); if ( BufrNumbers.isMissing(cv, dataWidth))
int count = (int) reader.bits2UInt(dkey.replicationCountSize); if (out != null) out.f.format("%4d delayed replication count=%d %n", out.fldno++, count); if ((out != null) && (count > 0)) {
this.spd[i] = (int) bitReader.bits2UInt(widthOfSPD);