Java Code Examples for ucar.unidata.io.RandomAccessFile#BIG_ENDIAN

The following examples show how to use ucar.unidata.io.RandomAccessFile#BIG_ENDIAN . 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: GempakFileReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the byte order for the machine type.
 *
 * @param kmachn maching type
 * @return byte order
 */
public int getByteOrder(int kmachn) {
  if ((kmachn == MTVAX) || (kmachn == MTULTX) || (kmachn == MTALPH) || (kmachn == MTLNUX) || (kmachn == MTIGPH)) {
    return RandomAccessFile.LITTLE_ENDIAN;
  }
  return RandomAccessFile.BIG_ENDIAN;
}
 
Example 2
Source File: GempakFileReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * LOOK WTF ??
 * Set the machine type for this system.
 *
 * @see <a href="http://lopica.sourceforge.net/os.html">http://lopica.sourceforge.net/os.html</a>
 */
void setByteOrder() {
  String arch = System.getProperty("os.arch");
  if (arch.equals("x86") || // Windows, Linux
      arch.equals("arm") || // Window CE
      arch.equals("x86_64") || // Windows64, Mac OS-X
      arch.equals("amd64") || // Linux64?
      arch.equals("alpha")) { // Utrix, VAX, DECOS
    MTMACH = RandomAccessFile.LITTLE_ENDIAN;
  } else {
    MTMACH = RandomAccessFile.BIG_ENDIAN;
  }
}
 
Example 3
Source File: GempakFileReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Read in all the info based on the block of integer words.
 * Modeled after DM_RLBL.
 *
 * @return true if okay.
 * @throws IOException problem reading the file
 */
boolean init() throws IOException {
  rf.order(RandomAccessFile.BIG_ENDIAN);
  if (rf.length() < getOffset(31) + 4)
    return false;

  int mmmm = DM_RINT(26);
  if (mmmm > 100) {
    mmmm = GempakUtil.swp4(mmmm);
    needToSwap = true;
  }
  kmachn = mmmm;
  mvmst = (getByteOrder() == RandomAccessFile.BIG_ENDIAN);
  kvmst =
      ((kmachn == MTVAX) || (kmachn == MTULTX) || (kmachn == MTALPH) || (kmachn == MTLNUX) || (kmachn == MTIGPH));

  // Set the file values of the missing data values to the current
  // system values so that random values will not be converted.
  kmissd = IMISSD;
  smissd = RMISSD;

  String label = DM_RSTR(1, 28);
  if (!label.equals(DMLABEL)) {
    return false;
  }

  int[] words = new int[23];
  DM_RINT(8, words);
  kversn = words[0];
  kfhdrs = words[1];
  kpfile = words[2];
  krow = words[3];
  krkeys = words[4];
  kprkey = words[5];
  kprowh = words[6];
  kcol = words[7];
  kckeys = words[8];
  kpckey = words[9];
  kpcolh = words[10];
  kprt = words[11];
  kppart = words[12];
  kpdmgt = words[13];
  kldmgt = words[14];
  kpdata = words[15];
  kftype = words[16];
  kfsrce = words[17];
  // kmachn = words[18]; // set above
  kmissd = words[19];
  smissd = DM_RFLT(31);

  return true;
}
 
Example 4
Source File: H5headerNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TypeInfo calcNCtype(MessageDatatype mdt) {
  int hdfType = mdt.type;
  int byteSize = mdt.byteSize;
  byte[] flags = mdt.flags;
  // boolean unsigned = mdt.unsigned;

  TypeInfo tinfo = new TypeInfo(hdfType, byteSize);

  if (hdfType == 0) { // int, long, short, byte
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
    tinfo.unsigned = ((flags[0] & 8) == 0);

  } else if (hdfType == 1) { // floats, doubles
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;

  } else if (hdfType == 2) { // time
    tinfo.dataType = DataType.STRING;
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;

  } else if (hdfType == 3) { // fixed length strings map to CHAR. String is used for Vlen type = 1.
    tinfo.dataType = DataType.CHAR;
    tinfo.vpad = (flags[0] & 0xf);
    // when elem length = 1, there is a problem with dimensionality.
    // eg char cr(2); has a storage_size of [1,1].

  } else if (hdfType == 4) { // bit field
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);

  } else if (hdfType == 5) { // opaque
    tinfo.dataType = DataType.OPAQUE;

  } else if (hdfType == 6) { // structure
    tinfo.dataType = DataType.STRUCTURE;

  } else if (hdfType == 7) { // reference
    tinfo.endian = RandomAccessFile.LITTLE_ENDIAN;
    tinfo.dataType = DataType.LONG; // file offset of the referenced object
    // LOOK - should get the object, and change type to whatever it is (?)

  } else if (hdfType == 8) { // enums
    if (tinfo.byteSize == 1)
      tinfo.dataType = DataType.ENUM1;
    else if (tinfo.byteSize == 2)
      tinfo.dataType = DataType.ENUM2;
    else if (tinfo.byteSize == 4)
      tinfo.dataType = DataType.ENUM4;
    else {
      log.warn("Illegal byte suze for enum type = {}", tinfo.byteSize);
      throw new IllegalStateException("Illegal byte suze for enum type = " + tinfo.byteSize);
    }

    // enumMap = mdt.map;

  } else if (hdfType == 9) { // variable length array
    tinfo.isVString = mdt.isVString;
    tinfo.isVlen = mdt.isVlen;
    if (mdt.isVString) {
      tinfo.vpad = ((flags[0] >> 4) & 0xf);
      tinfo.dataType = DataType.STRING;
    } else {
      tinfo.dataType = getNCtype(mdt.getBaseType(), mdt.getBaseSize(), mdt.base.unsigned);
      tinfo.endian = mdt.base.endian;
      tinfo.unsigned = mdt.base.unsigned;
    }
  } else if (hdfType == 10) { // array : used for structure members
    tinfo.endian = (mdt.getFlags()[0] & 1) == 0 ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
    if (mdt.isVString()) {
      tinfo.dataType = DataType.STRING;
    } else {
      int basetype = mdt.getBaseType();
      tinfo.dataType = getNCtype(basetype, mdt.getBaseSize(), mdt.unsigned);
    }
  } else if (warnings) {
    log.debug("WARNING not handling hdf dataType = " + hdfType + " size= " + byteSize);
  }

  if (mdt.base != null) {
    tinfo.base = calcNCtype(mdt.base);
  }
  return tinfo;
}
 
Example 5
Source File: H5header.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TypeInfo calcNCtype(MessageDatatype mdt) {
  int hdfType = mdt.type;
  int byteSize = mdt.byteSize;
  byte[] flags = mdt.flags;
  // boolean unsigned = mdt.unsigned;

  TypeInfo tinfo = new TypeInfo(hdfType, byteSize);

  if (hdfType == 0) { // int, long, short, byte
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
    tinfo.unsigned = ((flags[0] & 8) == 0);

  } else if (hdfType == 1) { // floats, doubles
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;

  } else if (hdfType == 2) { // time
    tinfo.dataType = DataType.STRING;
    tinfo.endian = ((flags[0] & 1) == 0) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;

  } else if (hdfType == 3) { // fixed length strings map to CHAR. String is used for Vlen type = 1.
    tinfo.dataType = DataType.CHAR;
    tinfo.vpad = (flags[0] & 0xf);
    // when elem length = 1, there is a problem with dimensionality.
    // eg char cr(2); has a storage_size of [1,1].

  } else if (hdfType == 4) { // bit field
    tinfo.dataType = getNCtype(hdfType, byteSize, mdt.unsigned);

  } else if (hdfType == 5) { // opaque
    tinfo.dataType = DataType.OPAQUE;

  } else if (hdfType == 6) { // structure
    tinfo.dataType = DataType.STRUCTURE;

  } else if (hdfType == 7) { // reference
    tinfo.endian = RandomAccessFile.LITTLE_ENDIAN;
    tinfo.dataType = DataType.LONG; // file offset of the referenced object
    // LOOK - should get the object, and change type to whatever it is (?)

  } else if (hdfType == 8) { // enums
    if (tinfo.byteSize == 1)
      tinfo.dataType = DataType.ENUM1;
    else if (tinfo.byteSize == 2)
      tinfo.dataType = DataType.ENUM2;
    else if (tinfo.byteSize == 4)
      tinfo.dataType = DataType.ENUM4;
    else {
      log.warn("Illegal byte suze for enum type = {}", tinfo.byteSize);
      throw new IllegalStateException("Illegal byte suze for enum type = " + tinfo.byteSize);
    }

    // enumMap = mdt.map;

  } else if (hdfType == 9) { // variable length array
    tinfo.isVString = mdt.isVString;
    tinfo.isVlen = mdt.isVlen;
    if (mdt.isVString) {
      tinfo.vpad = ((flags[0] >> 4) & 0xf);
      tinfo.dataType = DataType.STRING;
    } else {
      tinfo.dataType = getNCtype(mdt.getBaseType(), mdt.getBaseSize(), mdt.base.unsigned);
      tinfo.endian = mdt.base.endian;
      tinfo.unsigned = mdt.base.unsigned;
    }
  } else if (hdfType == 10) { // array : used for structure members
    tinfo.endian = (mdt.getFlags()[0] & 1) == 0 ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
    if (mdt.isVString()) {
      tinfo.dataType = DataType.STRING;
    } else {
      int basetype = mdt.getBaseType();
      tinfo.dataType = getNCtype(basetype, mdt.getBaseSize(), mdt.unsigned);
    }
  } else if (warnings) {
    log.debug("WARNING not handling hdf dataType = " + hdfType + " size= " + byteSize);
  }

  if (mdt.base != null) {
    tinfo.base = calcNCtype(mdt.base);
  }
  return tinfo;
}
 
Example 6
Source File: GradsBinaryGridServiceProvider.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the byte order from the data descriptor file
 *
 * @return the byte order
 */
private int getByteOrder() {
  return (gradsDDF.isBigEndian()) ? RandomAccessFile.BIG_ENDIAN : RandomAccessFile.LITTLE_ENDIAN;
}