Java Code Examples for ucar.ma2.DataType#LONG
The following examples show how to use
ucar.ma2.DataType#LONG .
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: NcStream.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static DataType decodeAttributeType(ucar.nc2.stream.NcStreamProto.Attribute.Type dtype) { switch (dtype) { case STRING: return DataType.STRING; 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; } throw new IllegalStateException("illegal att type " + dtype); }
Example 2
Source File: ModisSatellite.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { for (Variable v : ds.getVariables()) { checkIfAxis(v); } AttributeContainer gatts = ds.getRootGroup().attributes(); int year = gatts.findAttributeInteger("YEAR", -1); int doy = gatts.findAttributeInteger("DAY", -1); double time = gatts.findAttributeDouble("TIME", Double.NaN); if ((year > 0) && (doy > 0) && !Double.isNaN(time)) { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); cal.clear(); cal.set(Calendar.YEAR, year); cal.set(Calendar.DAY_OF_YEAR, doy); int hour = (int) time; cal.set(Calendar.HOUR_OF_DAY, hour); time -= hour; time *= 60; int minute = (int) time; cal.set(Calendar.MINUTE, minute); time -= minute; time *= 60; cal.set(Calendar.SECOND, (int) time); VariableDS var = new VariableDS(ds, null, null, "timeFromAtts", DataType.LONG, "", "seconds since 1970-01-01 00:00", "time generated from global attributes"); // LOOK : cant handle scalar coordinates yet // var.addAttribute( new Attribute(_Coordinate.AxisType, AxisType.Time.toString())); ds.addVariable(null, var); ArrayLong.D0 data = new ArrayLong.D0(false); data.set(cal.getTime().getTime() / 1000); var.setCachedData(data, true); } ds.finish(); }
Example 3
Source File: H4header.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
Number get(DataType dataType, int index) { if (dataType == DataType.BYTE) return bb.get(index); if (dataType == DataType.SHORT) return bb.asShortBuffer().get(index); if (dataType == DataType.INT) return bb.asIntBuffer().get(index); if (dataType == DataType.LONG) return bb.asLongBuffer().get(index); if (dataType == DataType.FLOAT) return bb.asFloatBuffer().get(index); if (dataType == DataType.DOUBLE) return bb.asDoubleBuffer().get(index); return Double.NaN; }
Example 4
Source File: TestPointDatasets.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
static private void checkData(StructureData sdata) { for (StructureMembers.Member member : sdata.getMembers()) { DataType dt = member.getDataType(); if (dt == DataType.FLOAT) { sdata.getScalarFloat(member); sdata.getJavaArrayFloat(member); } else if (dt == DataType.DOUBLE) { sdata.getScalarDouble(member); sdata.getJavaArrayDouble(member); } else if (dt == DataType.BYTE) { sdata.getScalarByte(member); sdata.getJavaArrayByte(member); } else if (dt == DataType.SHORT) { sdata.getScalarShort(member); sdata.getJavaArrayShort(member); } else if (dt == DataType.INT) { sdata.getScalarInt(member); sdata.getJavaArrayInt(member); } else if (dt == DataType.LONG) { sdata.getScalarLong(member); sdata.getJavaArrayLong(member); } else if (dt == DataType.CHAR) { sdata.getScalarChar(member); sdata.getJavaArrayChar(member); sdata.getScalarString(member); } else if (dt == DataType.STRING) { sdata.getScalarString(member); } if ((dt != DataType.STRING) && (dt != DataType.CHAR) && (dt != DataType.STRUCTURE) && (dt != DataType.SEQUENCE)) { sdata.convertScalarFloat(member.getName()); } } }
Example 5
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 6
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 7
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 8
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 9
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 10
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"); } } } }