Java Code Examples for ucar.ma2.DataType#CHAR
The following examples show how to use
ucar.ma2.DataType#CHAR .
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: NetcdfFormatWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Write String data to a CHAR variable. * * @param v variable to write to * @param origin offset to start writing, ignore the strlen dimension. * @param values write this array; must be ArrayObject of String * @throws IOException if I/O error * @throws InvalidRangeException if values Array has illegal shape */ public void writeStringDataToChar(Variable v, int[] origin, Array values) throws IOException, InvalidRangeException { if (values.getElementType() != String.class) throw new IllegalArgumentException("values must be an ArrayObject of String "); if (v.getDataType() != DataType.CHAR) throw new IllegalArgumentException("variable " + v.getFullName() + " is not type CHAR"); int rank = v.getRank(); int strlen = v.getShape(rank - 1); // turn it into an ArrayChar ArrayChar cvalues = ArrayChar.makeFromStringArray((ArrayObject) values, strlen); int[] corigin = new int[rank]; System.arraycopy(origin, 0, corigin, 0, rank - 1); write(v, corigin, cvalues); }
Example 2
Source File: H4header.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void addGlobalAttributes(TagVGroup group) throws IOException { // look for attributes for (int i = 0; i < group.nelems; i++) { Tag tag = tagMap.get(tagid(group.elem_ref[i], group.elem_tag[i])); if (tag == null) throw new IllegalStateException(); if (tag.code == 1962) { TagVH vh = (TagVH) tag; if (vh.className.startsWith("Att")) { String lowername = vh.name.toLowerCase(); if ((vh.nfields == 1) && (H4type.setDataType(vh.fld_type[0], null) == DataType.CHAR) && ((vh.fld_isize[0] > 4000) || lowername.startsWith("archivemetadata") || lowername.startsWith("coremetadata") || lowername.startsWith("productmetadata") || lowername.startsWith("structmetadata"))) { root.addVariable(makeVariable(vh)); // // large EOS metadata - make into variable in root group } else { Attribute att = makeAttribute(vh); if (null != att) root.addAttribute(att); // make into attribute in root group } } } } group.used = true; }
Example 3
Source File: NcDDS.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
private BaseType createScalarVariable(NetcdfFile ncfile, Variable v) { DataType dt = v.getDataType(); if (dt == DataType.DOUBLE) return new NcSDFloat64(v); else if (dt == DataType.FLOAT) return new NcSDFloat32(v); else if (dt == DataType.INT) return new NcSDInt32(v); else if (dt == DataType.UINT) return new NcSDUInt32(v); else if (dt == DataType.SHORT) return new NcSDInt16(v); else if (dt == DataType.USHORT) return new NcSDUInt16(v); else if ((dt == DataType.BYTE) || (dt == DataType.UBYTE)) return new NcSDByte(v); else if (dt == DataType.CHAR) return new NcSDString(v); else if (dt == DataType.STRING) return new NcSDString(v); else if (dt == DataType.STRUCTURE) return createStructure(ncfile, (Structure) v); else throw new UnsupportedOperationException("NcDDS Variable data type = " + dt); }
Example 4
Source File: NcDDS.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
private BaseType createVariable(NetcdfFile ncfile, Variable v) { BaseType bt; if (v.getRank() == 0) // scalar bt = createScalarVariable(ncfile, v); else if (v.getDataType() == DataType.CHAR) { if (v.getRank() > 1) bt = new NcSDCharArray(v); else bt = new NcSDString(v); } else if (v.getDataType() == DataType.STRING) { if (v.getRank() == 0) bt = new NcSDString(v); else bt = new NcSDArray(v, new NcSDString(v)); } else // non-char multidim array bt = createArray(ncfile, v); return bt; }
Example 5
Source File: CoordSystemBuilder.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Does this axis "fit" this variable. True if all of the dimensions in the axis also appear in * the variable. If char variable, last dimension is left out. * * @param axis check if this axis is ok for the given variable * @param vp the given variable * @return true if all of the dimensions in the axis also appear in the variable. */ protected boolean isCoordinateAxisForVariable(CoordinateAxis.Builder<?> axis, VarProcess vp) { ImmutableList<Dimension> varDims = vp.vb.getDimensions(); ImmutableList<Dimension> axisDims = axis.getDimensions(); // a CHAR variable must really be a STRING, so leave out the last (string length) dimension int checkDims = axisDims.size(); if (axis.dataType == DataType.CHAR) checkDims--; for (int i = 0; i < checkDims; i++) { Dimension axisDim = axisDims.get(i); if (!varDims.contains(axisDim)) { return false; } } return true; }
Example 6
Source File: CoordSysBuilder.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Does this axis "fit" this variable. * True if all of the dimensions in the axis also appear in the variable. * If char variable, last dimension is left out. * * @param axis check if this axis is ok for the given variable * @param v the given variable * @return true if all of the dimensions in the axis also appear in the variable. */ protected boolean isCoordinateAxisForVariable(Variable axis, Variable v) { List<Dimension> varDims = v.getDimensionsAll(); List<Dimension> axisDims = axis.getDimensionsAll(); // a CHAR variable must really be a STRING, so leave out the last (string length) dimension int checkDims = axisDims.size(); if (axis.getDataType() == DataType.CHAR) checkDims--; for (int i = 0; i < checkDims; i++) { Dimension axisDim = axisDims.get(i); if (!varDims.contains(axisDim)) { return false; } } return true; }
Example 7
Source File: CFPointObWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public List<Dimension> getDimensions() { if (pov.getLen() > 1) { List<Dimension> dims = new ArrayList<Dimension>(1); String suffix = (pov.getDataType() == DataType.STRING) || (pov.getDataType() == DataType.CHAR) ? "_strlen" : "_len"; dims.add(new Dimension(pov.getName() + suffix, pov.getLen(), false, false, false)); return dims; } else return new ArrayList<Dimension>(0); }
Example 8
Source File: H5headerNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public String extraInfo() { StringBuilder buff = new StringBuilder(); if ((typeInfo.dataType != DataType.CHAR) && (typeInfo.dataType != DataType.STRING)) buff.append(typeInfo.unsigned ? " unsigned" : " signed"); if (typeInfo.endian >= 0) buff.append((typeInfo.endian == RandomAccessFile.LITTLE_ENDIAN) ? " LittleEndian" : " BigEndian"); if (useFillValue) buff.append(" useFillValue"); return buff.toString(); }
Example 9
Source File: PointConfigXML.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void makeMultidimInner(NetcdfDataset ds, TableConfig parentTable, TableConfig childTable) { Dimension parentDim = ds.findDimension(parentTable.dimName); Dimension childDim = ds.findDimension(childTable.innerName); // divide up the variables between the parent and the child List<String> obsVars; List<Variable> vars = ds.getVariables(); List<String> parentVars = new ArrayList<>(vars.size()); obsVars = new ArrayList<>(vars.size()); for (Variable orgV : vars) { if (orgV instanceof Structure) continue; Dimension dim0 = orgV.getDimension(0); if ((dim0 != null) && dim0.equals(parentDim)) { if ((orgV.getRank() == 1) || ((orgV.getRank() == 2) && orgV.getDataType() == DataType.CHAR)) { parentVars.add(orgV.getShortName()); } else { Dimension dim1 = orgV.getDimension(1); if ((dim1 != null) && dim1.equals(childDim)) obsVars.add(orgV.getShortName()); } } } parentTable.vars = parentVars; childTable.vars = obsVars; }
Example 10
Source File: NcStream.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Attribute decodeAtt(NcStreamProto.Attribute attp) { // BARF LOOK DataType dtOld = decodeAttributeType(attp.getType()); DataType dtNew = convertDataType(attp.getDataType()); DataType dtUse; if (dtNew != DataType.CHAR) dtUse = dtNew; else if (dtOld != DataType.STRING) dtUse = dtOld; else if (attp.getSdataCount() > 0) dtUse = DataType.STRING; else dtUse = DataType.CHAR; int len = attp.getLen(); if (len == 0) // deal with empty attribute return Attribute.builder(attp.getName()).setDataType(dtUse).build(); if (dtUse == DataType.STRING) { int lenp = attp.getSdataCount(); if (lenp != len) System.out.println("HEY lenp != len"); if (lenp == 1) return new Attribute(attp.getName(), attp.getSdata(0)); else { Array data = Array.factory(dtUse, new int[] {lenp}); for (int i = 0; i < lenp; i++) data.setObject(i, attp.getSdata(i)); return new Attribute(attp.getName(), data); } } else { ByteString bs = attp.getData(); ByteBuffer bb = ByteBuffer.wrap(bs.toByteArray()); // if null, then use int[]{bb.limit()} return new Attribute(attp.getName(), Array.factory(dtUse, (int[]) null, bb)); } }
Example 11
Source File: NcMLReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse the values element * * @param s JDOM element to parse * @return Array with parsed values * @throws IllegalArgumentException if string values not parsable to specified data type */ public static ucar.ma2.Array readAttributeValues(Element s) throws IllegalArgumentException { String valString = s.getAttributeValue("value"); // can also be element text if (valString == null) { valString = s.getTextNormalize(); } // no value specified hmm technically this is not illegal !! if (valString == null) throw new IllegalArgumentException("No value specified"); String type = s.getAttributeValue("type"); DataType dtype = (type == null) ? DataType.STRING : DataType.getType(type); if (dtype == DataType.CHAR) dtype = DataType.STRING; // backwards compatibility with deprecated isUnsigned attribute String unS = s.getAttributeValue("isUnsigned"); boolean isUnsignedSet = "true".equalsIgnoreCase(unS); if (isUnsignedSet && dtype.isIntegral() && !dtype.isUnsigned()) { dtype = dtype.withSignedness(DataType.Signedness.UNSIGNED); } String sep = s.getAttributeValue("separator"); if ((sep == null) && (dtype == DataType.STRING)) { List<String> list = new ArrayList<>(); list.add(valString); return Array.makeArray(dtype, list); } if (sep == null) sep = " "; // default whitespace separated List<String> stringValues = new ArrayList<>(); StringTokenizer tokn = new StringTokenizer(valString, sep); while (tokn.hasMoreTokens()) stringValues.add(tokn.nextToken()); return Array.makeArray(dtype, stringValues); }
Example 12
Source File: NcMLReaderNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse the values element * * @param s JDOM element to parse * @return Array with parsed values * @throws IllegalArgumentException if string values not parsable to specified data type */ private static ucar.ma2.Array readAttributeValues(Element s) throws IllegalArgumentException { String valString = s.getAttributeValue("value"); // can also be element text if (valString == null) { valString = s.getTextNormalize(); } // no value specified hmm technically this is not illegal !! if (valString == null) { throw new IllegalArgumentException("No value specified"); } String type = s.getAttributeValue("type"); DataType dtype = (type == null) ? DataType.STRING : DataType.getType(type); if (dtype == DataType.CHAR) { dtype = DataType.STRING; } // backwards compatibility with deprecated isUnsigned attribute String unS = s.getAttributeValue("isUnsigned"); boolean isUnsignedSet = "true".equalsIgnoreCase(unS); if (isUnsignedSet && dtype.isIntegral() && !dtype.isUnsigned()) { dtype = dtype.withSignedness(DataType.Signedness.UNSIGNED); } String sep = s.getAttributeValue("separator"); if ((sep == null) && (dtype == DataType.STRING)) { List<String> list = new ArrayList<>(); list.add(valString); return Array.makeArray(dtype, list); } if (sep == null) { sep = " "; // default whitespace separated } List<String> stringValues = new ArrayList<>(); StringTokenizer tokn = new StringTokenizer(valString, sep); while (tokn.hasMoreTokens()) { stringValues.add(tokn.nextToken()); } return Array.makeArray(dtype, stringValues); }
Example 13
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 14
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 15
Source File: Evaluator.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static boolean isEffectivelyScaler(Variable v) { return (v.getRank() == 0) || (v.getRank() == 1 && v.getDataType() == DataType.CHAR); }
Example 16
Source File: CFpointObs.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private TableConfig makeMultidimInner3D(NetcdfDataset ds, TableConfig outerTable, TableConfig middleTable, Dimension innerDim, Formatter errlog) { Dimension outerDim = ds.findDimension(outerTable.dimName); Dimension middleDim = ds.findDimension(middleTable.innerName); Table.Type obsTableType = (outerTable.structureType == TableConfig.StructureType.PsuedoStructure) ? Table.Type.MultidimInnerPsuedo3D : Table.Type.MultidimInner3D; TableConfig obsTable = new TableConfig(obsTableType, innerDim.getShortName()); obsTable.structureType = TableConfig.StructureType.PsuedoStructure2D; obsTable.dimName = outerTable.dimName; obsTable.outerName = middleTable.innerName; obsTable.innerName = innerDim.getShortName(); obsTable.structName = innerDim.getShortName(); obsTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, outerDim, middleDim, innerDim); obsTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, outerDim, middleDim, innerDim); obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, outerDim, middleDim, innerDim); if (obsTable.elev == null) obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, middleDim, innerDim); if (obsTable.elev == null) obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, middleDim, innerDim); obsTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, outerDim, middleDim, innerDim); // divide up the variables between the 3 tables List<Variable> vars = ds.getVariables(); List<String> outerVars = new ArrayList<>(vars.size()); List<String> middleVars = new ArrayList<>(vars.size()); List<String> innerVars = new ArrayList<>(vars.size()); for (Variable orgV : vars) { if (orgV instanceof Structure) continue; if ((orgV.getRank() == 1) || ((orgV.getRank() == 2) && orgV.getDataType() == DataType.CHAR)) { if (outerDim.equals(orgV.getDimension(0))) outerVars.add(orgV.getShortName()); } else if (orgV.getRank() == 2) { if (outerDim.equals(orgV.getDimension(0)) && middleDim.equals(orgV.getDimension(1))) middleVars.add(orgV.getShortName()); } else if (orgV.getRank() == 3) { if (outerDim.equals(orgV.getDimension(0)) && middleDim.equals(orgV.getDimension(1)) && innerDim.equals(orgV.getDimension(2))) innerVars.add(orgV.getShortName()); } } outerTable.vars = outerVars; middleTable.vars = middleVars; obsTable.vars = innerVars; return obsTable; }
Example 17
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 18
Source File: CFpointObs.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private TableConfig makeMultidimInner(NetcdfDataset ds, TableConfig parentTable, Dimension obsDim, EncodingInfo info, Formatter errlog) { Dimension parentDim = ds.findDimension(parentTable.dimName); Table.Type obsTableType = (parentTable.structureType == TableConfig.StructureType.PsuedoStructure) ? Table.Type.MultidimInnerPsuedo : Table.Type.MultidimInner; // if (info.time.isMemberOfStructure()) obsTableType = Table.Type.Structure; TableConfig obsTable = new TableConfig(obsTableType, obsDim.getShortName()); obsTable.lat = matchAxisTypeAndDimension(ds, AxisType.Lat, parentDim, obsDim); obsTable.lon = matchAxisTypeAndDimension(ds, AxisType.Lon, parentDim, obsDim); obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Height, parentDim, obsDim); if (obsTable.elev == null) obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.Pressure, parentDim, obsDim); if (obsTable.elev == null) obsTable.elev = matchAxisTypeAndDimension(ds, AxisType.GeoZ, parentDim, obsDim); obsTable.time = matchAxisTypeAndDimension(ds, AxisType.Time, parentDim, obsDim); // divide up the variables between the parent and the obs List<String> obsVars; List<Variable> vars = ds.getVariables(); List<String> parentVars = new ArrayList<>(vars.size()); obsVars = new ArrayList<>(vars.size()); for (Variable orgV : vars) { if (orgV instanceof Structure) continue; Dimension dim0 = orgV.getDimension(0); if ((dim0 != null) && dim0.equals(parentDim)) { if ((orgV.getRank() == 1) || ((orgV.getRank() == 2) && orgV.getDataType() == DataType.CHAR)) { parentVars.add(orgV.getShortName()); } else { Dimension dim1 = orgV.getDimension(1); if (obsDim.equals(dim1)) obsVars.add(orgV.getShortName()); } } } parentTable.vars = parentVars; // parentTable.vars = parentTable.isPsuedoStructure ? parentVars : null; // restrict to these if psuedoStruct obsTable.structureType = parentTable.structureType; obsTable.outerName = parentDim.getShortName(); obsTable.innerName = obsDim.getShortName(); obsTable.dimName = (parentTable.structureType == TableConfig.StructureType.PsuedoStructure) ? obsTable.outerName : obsTable.innerName; obsTable.structName = obsDim.getShortName(); obsTable.vars = obsVars; return obsTable; }
Example 19
Source File: NetcdfCopier.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Variable.Builder copyVariable(Group.Builder parent, Variable oldVar) throws IOException { Variable.Builder vb; DataType newType = oldVar.getDataType(); String dimNames = Dimensions.makeDimensionsString(oldVar.getDimensions()); if (newType == DataType.STRUCTURE) { Structure oldStruct = (Structure) oldVar; Structure.Builder sb = Structure.builder().setName(oldVar.getShortName()); for (Variable nested : oldStruct.getVariables()) { sb.addMemberVariable(copyVariable(parent, nested)); } vb = sb; } else { vb = Variable.builder().setName(oldVar.getShortName()).setDataType(newType); if (!extended && newType == DataType.STRING) { // find maximum length Array data = oldVar.read(); IndexIterator ii = data.getIndexIterator(); int max_len = 0; while (ii.hasNext()) { String s = (String) ii.getObjectNext(); max_len = Math.max(max_len, s.length()); } // add last dimension String strlenDimName = oldVar.getShortName() + "_strlen"; parent.addDimension(Dimension.builder(strlenDimName, max_len).setIsShared(false).build()); newType = DataType.CHAR; vb.setDataType(DataType.CHAR); dimNames += " " + strlenDimName; } } vb.setParentGroupBuilder(parent).setDimensionsByName(dimNames); if (newType.isEnum()) { EnumTypedef en = oldVar.getEnumTypedef(); vb.setEnumTypeName(en.getShortName()); } // attributes for (Attribute att : oldVar.attributes()) { vb.addAttribute(convertAttribute(att)); if (debug) { System.out.println("add varAtt= " + att); } } return vb; }
Example 20
Source File: CFPointObWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public DataType getDataType() { return (pov.getDataType() == DataType.STRING) ? DataType.CHAR : pov.getDataType(); }