Java Code Examples for ucar.ma2.DataType#ENUM1
The following examples show how to use
ucar.ma2.DataType#ENUM1 .
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 | 6 votes |
public static DataType enumTypeFor(DapType type) { switch (type.getTypeSort()) { case Char: case Int8: case UInt8: return DataType.ENUM1; case Int16: case UInt16: return DataType.ENUM2; case Int32: case UInt32: return DataType.ENUM4; case Int64: case UInt64: // Unfortunately, CDM does not support (U)Int64, so truncate to 32. return DataType.ENUM4; case Enum: // Coverity[FB.BC_UNCONFIRMED_CAST] return CDMTypeFcns.enumTypeFor(((DapEnumeration) type).getBaseType()); default: break; } return null; }
Example 2
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected Array convertEnums(Map<Integer, String> map, DataType dataType, Array values) { Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { int ival; if (dataType == DataType.ENUM1) ival = (int) DataType.unsignedByteToShort(values.nextByte()); else if (dataType == DataType.ENUM2) ival = DataType.unsignedShortToInt(values.nextShort()); else ival = values.nextInt(); String sval = map.get(ival); if (sval == null) sval = "Unknown enum value=" + ival; ii.setObjectNext(sval); } return result; }
Example 3
Source File: NcMLReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Read an NcML enumTypedef element. * * @param g put enumTypedef into this group * @param refg parent Group in referenced dataset * @param etdElem ncml enumTypedef element */ private void readEnumTypedef(Group g, Group refg, Element etdElem) { String name = etdElem.getAttributeValue("name"); if (name == null) { errlog.format("NcML enumTypedef name is required (%s)%n", etdElem); return; } String typeS = etdElem.getAttributeValue("type"); DataType baseType = (typeS == null) ? DataType.ENUM1 : DataType.getType(typeS); Map<Integer, String> map = new HashMap<>(100); for (Element e : etdElem.getChildren("enum", ncNS)) { String key = e.getAttributeValue("key"); String value = e.getTextNormalize(); if (key == null) { errlog.format("NcML enumTypedef enum key attribute is required (%s)%n", e); continue; } if (value == null) { errlog.format("NcML enumTypedef enum value is required (%s)%n", e); continue; } try { int keyi = Integer.parseInt(key); map.put(keyi, value); } catch (Exception e2) { errlog.format("NcML enumTypedef enum key attribute not an integer (%s)%n", e); } } EnumTypedef td = new EnumTypedef(name, map, baseType); g.addEnumeration(td); }
Example 4
Source File: NcMLReaderNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Read an NcML enumTypedef element. * * @param g put enumTypedef into this group * @param etdElem ncml enumTypedef element */ private void readEnumTypedef(Group.Builder g, Element etdElem) { String name = etdElem.getAttributeValue("name"); if (name == null) { errlog.format("NcML enumTypedef name is required (%s)%n", etdElem); return; } String typeS = etdElem.getAttributeValue("type"); DataType baseType = (typeS == null) ? DataType.ENUM1 : DataType.getType(typeS); Map<Integer, String> map = new HashMap<>(100); for (Element e : etdElem.getChildren("enum", ncNS)) { String key = e.getAttributeValue("key"); String value = e.getTextNormalize(); if (key == null) { errlog.format("NcML enumTypedef enum key attribute is required (%s)%n", e); continue; } if (value == null) { errlog.format("NcML enumTypedef enum value is required (%s)%n", e); continue; } try { int keyi = Integer.parseInt(key); map.put(keyi, value); } catch (Exception e2) { errlog.format("NcML enumTypedef enum key attribute not an integer (%s)%n", e); } } EnumTypedef td = new EnumTypedef(name, map, baseType); g.addEnumTypedef(td); }
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: 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; }