Java Code Examples for ucar.ma2.DataType#ULONG
The following examples show how to use
ucar.ma2.DataType#ULONG .
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: CDMTypeFcns.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static DataType daptype2cdmtype(DapType type) { assert (type != null); switch (type.getTypeSort()) { case Char: return DataType.CHAR; case UInt8: return DataType.UBYTE; case Int8: return DataType.BYTE; case Int16: return DataType.SHORT; case UInt16: return DataType.USHORT; case Int32: return DataType.INT; case UInt32: return DataType.UINT; case Int64: return DataType.LONG; case UInt64: return DataType.ULONG; case Float32: return DataType.FLOAT; case Float64: return DataType.DOUBLE; case String: case URL: return DataType.STRING; case Opaque: return DataType.OPAQUE; case Enum: // Coverity[FB.BC_UNCONFIRMED_CAST] DapEnumeration dapenum = (DapEnumeration) type; switch (dapenum.getBaseType().getTypeSort()) { case Char: case UInt8: case Int8: return DataType.ENUM1; case Int16: case UInt16: return DataType.ENUM2; case Int32: case UInt32: return DataType.ENUM4; case Int64: case UInt64: // since there is no ENUM8, use ENUM4 return DataType.ENUM4; default: break; } break; case Structure: return DataType.STRUCTURE; case Sequence: return DataType.SEQUENCE; default: break; } return null; }
Example 2
Source File: NcStream.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static DataType convertDataType(ucar.nc2.stream.NcStreamProto.DataType dtype) { switch (dtype) { case CHAR: return DataType.CHAR; case BYTE: return DataType.BYTE; case SHORT: return DataType.SHORT; case INT: return DataType.INT; case LONG: return DataType.LONG; case FLOAT: return DataType.FLOAT; case DOUBLE: return DataType.DOUBLE; case STRING: return DataType.STRING; case STRUCTURE: return DataType.STRUCTURE; case SEQUENCE: return DataType.SEQUENCE; case ENUM1: return DataType.ENUM1; case ENUM2: return DataType.ENUM2; case ENUM4: return DataType.ENUM4; case OPAQUE: return DataType.OPAQUE; case UBYTE: return DataType.UBYTE; case USHORT: return DataType.USHORT; case UINT: return DataType.UINT; case ULONG: return DataType.ULONG; } throw new IllegalStateException("illegal data type " + dtype); }
Example 3
Source File: Attribute.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Write CDL representation into a Formatter. * * @param f write into this * @param strict if true, create strict CDL, escaping names * @deprecated use CDLWriter */ @Deprecated protected void writeCDL(Formatter f, boolean strict, String parentname) { if (strict && (isString() || this.getEnumType() != null)) // Force type explicitly for string. f.format("string "); // note lower case and trailing blank if (strict && parentname != null) f.format(NetcdfFiles.makeValidCDLName(parentname)); f.format(":"); f.format("%s", strict ? NetcdfFiles.makeValidCDLName(getShortName()) : getShortName()); if (isString()) { f.format(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) f.format(", "); String val = getStringValue(i); if (val != null) f.format("\"%s\"", encodeString(val)); } } else if (getEnumType() != null) { f.format(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) f.format(", "); EnumTypedef en = getEnumType(); String econst = getStringValue(i); Integer ecint = en.lookupEnumInt(econst); if (ecint == null) throw new ForbiddenConversionException("Illegal enum constant: " + econst); f.format("\"%s\"", encodeString(econst)); } } else { f.format(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) f.format(", "); Number number = getNumericValue(i); if (dataType.isUnsigned()) { // 'number' is unsigned, but will be treated as signed when we print it below, because Java only has signed // types. If it is large enough ( >= 2^(BIT_WIDTH-1) ), its most-significant bit will be interpreted as the // sign bit, which will result in an invalid (negative) value being printed. To prevent that, we're going // to widen the number before printing it. number = DataType.widenNumber(number); } f.format("%s", number); if (dataType.isUnsigned()) { f.format("U"); } if (dataType == DataType.FLOAT) f.format("f"); else if (dataType == DataType.SHORT || dataType == DataType.USHORT) { f.format("S"); } else if (dataType == DataType.BYTE || dataType == DataType.UBYTE) { f.format("B"); } else if (dataType == DataType.LONG || dataType == DataType.ULONG) { f.format("L"); } } } }
Example 4
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
DataType getNCtype(int hdfType, int size, boolean unsigned) { if ((hdfType == 0) || (hdfType == 4)) { // integer, bit field DataType.Signedness signedness = unsigned ? DataType.Signedness.UNSIGNED : DataType.Signedness.SIGNED; if (size == 1) return DataType.BYTE.withSignedness(signedness); else if (size == 2) return DataType.SHORT.withSignedness(signedness); else if (size == 4) return DataType.INT.withSignedness(signedness); else if (size == 8) return DataType.LONG.withSignedness(signedness); else if (warnings) { log.debug("WARNING HDF5 file " + raf.getLocation() + " not handling hdf integer type (" + hdfType + ") with size= " + size); log.warn( "HDF5 file " + raf.getLocation() + " not handling hdf integer type (" + hdfType + ") with size= " + size); return null; } } else if (hdfType == 1) { if (size == 4) return DataType.FLOAT; else if (size == 8) return DataType.DOUBLE; else if (warnings) { log.debug("WARNING HDF5 file " + raf.getLocation() + " not handling hdf float type with size= " + size); log.warn("HDF5 file " + raf.getLocation() + " not handling hdf float type with size= " + size); return null; } } else if (hdfType == 3) { // fixed length strings. String is used for Vlen type = 1 return DataType.CHAR; } else if (hdfType == 6) { return DataType.STRUCTURE; } else if (hdfType == 7) { // reference return DataType.ULONG; } else if (hdfType == 9) { return null; // dunno } else if (warnings) { log.debug("WARNING not handling hdf type = " + hdfType + " size= " + size); log.warn("HDF5 file " + raf.getLocation() + " not handling hdf type = " + hdfType + " size= " + size); } return null; }
Example 5
Source File: H4type.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static DataType setDataType(short type, Variable v) { DataType dt; switch (type) { case 3: case 21: dt = DataType.UBYTE; break; case 4: dt = DataType.CHAR; break; case 5: dt = DataType.FLOAT; break; case 6: dt = DataType.DOUBLE; break; case 20: dt = DataType.BYTE; break; case 22: dt = DataType.SHORT; break; case 23: dt = DataType.USHORT; break; case 24: dt = DataType.INT; break; case 25: dt = DataType.UINT; break; case 26: dt = DataType.LONG; break; case 27: dt = DataType.ULONG; break; default: throw new IllegalStateException("unknown type= " + type); } if (v != null) { v.setDataType(dt); } return dt; }
Example 6
Source File: CDLWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void writeCDL(Attribute att, String parentname) { if (strict && (att.isString() || att.getEnumType() != null)) { // Force type explicitly for string. out.format("string "); // note lower case and trailing blank } if (strict && parentname != null) { out.format(NetcdfFiles.makeValidCDLName(parentname)); } out.format(":"); out.format("%s", strict ? NetcdfFiles.makeValidCDLName(att.getShortName()) : att.getShortName()); if (att.isString()) { out.format(" = "); for (int i = 0; i < att.getLength(); i++) { if (i != 0) { out.format(", "); } String val = att.getStringValue(i); if (val != null) { out.format("\"%s\"", encodeString(val)); } } } else if (att.getEnumType() != null) { out.format(" = "); for (int i = 0; i < att.getLength(); i++) { if (i != 0) { out.format(", "); } EnumTypedef en = att.getEnumType(); String econst = att.getStringValue(i); Integer ecint = en.lookupEnumInt(econst); if (ecint == null) { throw new ForbiddenConversionException("Illegal enum constant: " + econst); } out.format("\"%s\"", encodeString(econst)); } } else { out.format(" = "); for (int i = 0; i < att.getLength(); i++) { if (i != 0) out.format(", "); DataType dataType = att.getDataType(); Number number = att.getNumericValue(i); if (dataType.isUnsigned()) { // 'number' is unsigned, but will be treated as signed when we print it below, because Java only has signed // types. If it is large enough ( >= 2^(BIT_WIDTH-1) ), its most-significant bit will be interpreted as the // sign bit, which will result in an invalid (negative) value being printed. To prevent that, we're going // to widen the number before printing it. number = DataType.widenNumber(number); } out.format("%s", number); if (dataType.isUnsigned()) { out.format("U"); } if (dataType == DataType.FLOAT) out.format("f"); else if (dataType == DataType.SHORT || dataType == DataType.USHORT) { out.format("S"); } else if (dataType == DataType.BYTE || dataType == DataType.UBYTE) { out.format("B"); } else if (dataType == DataType.LONG || dataType == DataType.ULONG) { out.format("L"); } } } }