Java Code Examples for ucar.unidata.io.RandomAccessFile#readFloat()

The following examples show how to use ucar.unidata.io.RandomAccessFile#readFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Grib2Drs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
Type50002(RandomAccessFile raf) throws IOException {
  // according to https://github.com/erdc-cm/grib_api/blob/master/definitions/grib2/template.5.50002.def
  this.referenceValue = raf.readFloat();
  this.binaryScaleFactor = GribNumbers.int2(raf);
  this.decimalScaleFactor = GribNumbers.int2(raf);
  this.numberOfBits = raf.read();
  this.widthOfFirstOrderValues = raf.read();
  this.p1 = GribNumbers.int4(raf);
  this.p2 = GribNumbers.int4(raf);
  this.widthOfWidth = raf.read();
  this.widthOfLength = raf.read();
  this.boustrophonic = raf.read();
  this.orderOfSPD = raf.read();
  this.widthOfSPD = raf.read();
  this.spd = new int[orderOfSPD + 1];
  BitReader bitReader = new BitReader(raf, raf.getFilePointer());
  for (int i = 0; i < orderOfSPD; i++) {
    this.spd[i] = (int) bitReader.bits2UInt(widthOfSPD);
  }
  this.spd[orderOfSPD] = (int) bitReader.bits2SInt(widthOfSPD);
  this.lengthOfSection6 = GribNumbers.int4(raf);
  this.section6 = raf.read();
  this.bitMapIndicator = raf.read();
  this.lengthOfSection7 = GribNumbers.int4(raf);
  this.section7 = raf.read();
}
 
Example 2
Source File: Grib2Drs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Type0(RandomAccessFile raf) throws IOException {
  this.referenceValue = raf.readFloat();
  this.binaryScaleFactor = GribNumbers.int2(raf);
  this.decimalScaleFactor = GribNumbers.int2(raf);
  this.numberOfBits = raf.read();
  this.originalType = raf.read();
}
 
Example 3
Source File: Grib2Drs.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Type2(RandomAccessFile raf) throws IOException {
  super(raf);
  this.splittingMethod = raf.read();
  this.missingValueManagement = raf.read();
  this.primaryMissingValue = raf.readFloat();
  this.secondaryMissingValue = raf.readFloat();
  this.numberOfGroups = GribNumbers.int4(raf);
  this.referenceGroupWidths = raf.read();
  this.bitsGroupWidths = raf.read();
  this.referenceGroupLength = GribNumbers.int4(raf);
  this.lengthIncrement = raf.read();
  this.lengthLastGroup = GribNumbers.int4(raf);
  this.bitsScaledGroupLength = raf.read();
}
 
Example 4
Source File: V5DStruct.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Read a compressed grid from a COMP* file.
 * 
 * @return true = ok, false = error.
 */
boolean read_comp_grid(int time, int vr, float[] ga, float[] gb, byte[] compdata1)
    throws IOException, BadFormException {
  long pos;
  short bias;
  int i, n, nl;
  RandomAccessFile f = FileDesc;

  // move to position in file
  pos = grid_position(time, vr);
  f.seek(pos);

  if (FileFormat == 0x80808083) {
    // read McIDAS grid and file numbers
    int mcfile, mcgrid;
    mcfile = f.readInt();
    mcgrid = f.readInt();
    McFile[time][vr] = (short) mcfile;
    McGrid[time][vr] = (short) mcgrid;
  }

  nl = Nl[vr];

  if (FileFormat == 0x80808080 || FileFormat == 0x80808081) {
    // single ga, gb pair for whole grid
    float a, b;
    a = f.readFloat();
    b = f.readFloat();
    // convert a, b to new v5d ga, gb values
    for (i = 0; i < nl; i++) {
      if (a == 0.0) {
        ga[i] = gb[i] = 0.0f;
      } else {
        gb[i] = (b + 128.0f) / -a;
        ga[i] = 1.0f / a;
      }
    }
    bias = 128;
  } else {
    // read ga, gb arrays
    read_float4_array(f, ga, Nl[vr]);
    read_float4_array(f, gb, Nl[vr]);

    // convert ga, gb values to v5d system
    for (i = 0; i < nl; i++) {
      if (ga[i] == 0.0) {
        ga[i] = gb[i] = 0.0f;
      } else {
        // gb[i] = (gb[i]+125.0) / -ga[i];
        gb[i] = (gb[i] + 128.0f) / -ga[i];
        ga[i] = 1.0f / ga[i];
      }
    }
    bias = 128; // 125 ???
  }

  // read compressed grid data
  n = Nr * Nc * Nl[vr];
  if (f.read(compdata1, 0, n) != n)
    return false;

  // convert data values to v5d system
  n = Nr * Nc * Nl[vr];
  for (i = 0; i < n; i++)
    compdata1[i] += bias;

  return true;
}
 
Example 5
Source File: Level2Record.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private float getDataBlockValue1(RandomAccessFile raf, short offset, int skip) throws IOException {
  long off = offset + message_offset + MESSAGE_HEADER_SIZE;
  raf.seek(off);
  raf.skipBytes(skip);
  return raf.readFloat();
}
 
Example 6
Source File: V5DStruct.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Read an array of 4-byte IEEE floats.
 * 
 * @param f file descriptor
 * @param x address to put floats
 * @param n number of floats to read
 * @return number of floats read
 */
private static int read_float4_array(RandomAccessFile f, float[] x, int n) throws IOException {
  for (int i = 0; i < n; i++)
    x[i] = f.readFloat();
  return n;
}