@Override protected Variable copy() { return new Structure(this); }
@Override protected Variable copy() { return new Structure(this); }
@Override protected Variable copy() { return new Structure(this); }
private void addStructure(Structure parent, DataDescriptor dataDesc, int count) { String structName = "struct" + structNum; structNum++; Structure struct = new Structure(ncfile, null, parent, structName); try { struct.setDimensionsAnonymous(new int[]{count}); // anon vector } catch (InvalidRangeException e) { log.error("illegal count= " + count + " for " + dataDesc); } for (DataDescriptor subKey : dataDesc.getSubKeys()) addMember(struct, subKey); parent.addMemberVariable(struct); struct.setSPobject(dataDesc); dataDesc.name = structName; dataDesc.refersTo = struct; }
private void addStructure(Structure parent, BufrConfig.FieldConverter fld, int count) { DataDescriptor dkey = fld.dds; String uname = findUniqueName(parent, fld.getName(), "struct"); dkey.name = uname; // name may need to be changed for uniqueness //String structName = dataDesc.name != null ? dataDesc.name : "struct" + structNum++; Structure struct = new Structure(ncfile, null, parent, uname); try { struct.setDimensionsAnonymous(new int[]{count}); // anon vector } catch (InvalidRangeException e) { log.error("illegal count= " + count + " for " + fld); } for (BufrConfig.FieldConverter subKey : fld.flds) addMember(struct, subKey); parent.addMemberVariable(struct); struct.setSPobject(fld); dkey.refersTo = struct; }
v = new Variable(ncfile, g, parent, vname, dtype, dimList); } else if (utype != null) { Structure s = new Structure(ncfile, g, parent, vname); s.setDimensions(dimList); v = s;
private Variable makeVariable(Group g, Structure parent, String vname, int typeid, String dimList) throws IOException { DataType dtype = convertDataType(typeid).dt; UserType utype = userTypes.get(typeid); Variable v; if (dtype != DataType.STRUCTURE) { v = new Variable(ncfile, g, parent, vname, dtype, dimList); } else if (utype != null) { Structure s = new Structure(ncfile, g, parent, vname); s.setDimensions(dimList); v = s; if (utype.flds == null) utype.readFields(); for (Field f : utype.flds) { s.addMemberVariable(f.makeMemberVariable(g, s)); } } else { throw new IllegalStateException("Dunno what to with " + dtype); } if (isUnsigned(typeid)) v.addAttribute(new Attribute(CDM.UNSIGNED, "true")); if (dtype.isEnum()) { EnumTypedef enumTypedef = g.findEnumeration(utype.name); v.setEnumTypedef(enumTypedef); } return v; }
static Structure decodeStructure(NetcdfFile ncfile, Group g, Structure parent, NcStreamProto.Structure s) { Structure ncvar = (s.getDataType() == ucar.nc2.stream.NcStreamProto.DataType.SEQUENCE) ? new Sequence(ncfile, g, parent, s.getName()) : new Structure(ncfile, g, parent, s.getName()); ncvar.setDataType(decodeDataType(s.getDataType())); List<Dimension> dims = new ArrayList<Dimension>(6); for (ucar.nc2.stream.NcStreamProto.Dimension dim : s.getShapeList()) { Dimension ncdim = decodeDim(dim); if (!ncdim.isShared()) dims.add(ncdim); else { Dimension d = g.findDimension(ncdim.getShortName()); if (d == null) throw new IllegalStateException("Can find shared dimension " + dim.getName()); dims.add(d); } } ncvar.setDimensions(dims); for (ucar.nc2.stream.NcStreamProto.Attribute att : s.getAttsList()) ncvar.addAttribute(decodeAtt(att)); for (ucar.nc2.stream.NcStreamProto.Variable vp : s.getVarsList()) ncvar.addMemberVariable(decodeVar(ncfile, g, ncvar, vp)); for (NcStreamProto.Structure sp : s.getStructsList()) ncvar.addMemberVariable(decodeStructure(ncfile, g, ncvar, sp)); return ncvar; }
private void addDpiStructure(Structure parent, DataDescriptor parentDD, DataDescriptor dpiField) { String structName = findUnique(parent, dpiField.name); Structure struct = new Structure(ncfile, null, parent, structName); int n = parentDD.replication; try { struct.setDimensionsAnonymous(new int[]{n}); // anon vector } catch (InvalidRangeException e) { log.error("illegal count= " + 1 + " for " + dpiField); } Variable v = new Variable(ncfile, null, struct, "name"); v.setDataType(DataType.STRING); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); v = new Variable(ncfile, null, struct, "data"); v.setDataType(DataType.FLOAT); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); parent.addMemberVariable(struct); struct.setSPobject(dpiField); // ?? dpiField.name = structName; dpiField.refersTo = struct; // add some fake dkeys corresponding to above // DataDescriptor nameDD = new DataDescriptor(); }
static Structure decodeStructure(NetcdfFile ncfile, Group g, Structure parent, NcStreamProto.Structure s) { Structure ncvar = (s.getDataType() == ucar.nc2.stream.NcStreamProto.DataType.SEQUENCE) ? new Sequence(ncfile, g, parent, s.getName()) : new Structure(ncfile, g, parent, s.getName()); ncvar.setDataType(convertDataType(s.getDataType())); List<Dimension> dims = new ArrayList<>(6); for (ucar.nc2.stream.NcStreamProto.Dimension dim : s.getShapeList()) { Dimension ncdim = decodeDim(dim); if (!ncdim.isShared()) dims.add(ncdim); else { Dimension d = g.findDimension(ncdim.getShortName()); if (d == null) throw new IllegalStateException("Can find shared dimension " + dim.getName()); dims.add(d); } } ncvar.setDimensions(dims); for (ucar.nc2.stream.NcStreamProto.Attribute att : s.getAttsList()) ncvar.addAttribute(decodeAtt(att)); for (ucar.nc2.stream.NcStreamProto.Variable vp : s.getVarsList()) ncvar.addMemberVariable(decodeVar(ncfile, g, ncvar, vp)); for (NcStreamProto.Structure sp : s.getStructsList()) ncvar.addMemberVariable(decodeStructure(ncfile, g, ncvar, sp)); return ncvar; }
private Variable makeVariableMember(Group g, Structure s, String name, long dataPos, MessageDatatype mdt) throws IOException { Variable v; Vinfo vinfo = new Vinfo(mdt, null, dataPos); // LOOK need mds if (vinfo.getNCDataType() == null) { debugOut.println("SKIPPING DataType= " + vinfo.typeInfo.hdfType + " for variable " + name); return null; } if (mdt.type == 6) { v = new Structure(ncfile, g, s, name); makeVariableShapeAndType(v, mdt, null, vinfo, null); addMembersToStructure(g, (Structure) v, vinfo, mdt); v.setElementSize(mdt.byteSize); } else { v = new Variable(ncfile, g, s, name); makeVariableShapeAndType(v, mdt, null, vinfo, null); } // special case of variable length strings if (v.getDataType() == DataType.STRING) v.setElementSize(16); // because the array has elements that are HeapIdentifier v.setSPobject(vinfo); vinfo.setOwner(v); if (vinfo.typeInfo.unsigned) v.addAttribute(new Attribute(CDM.UNSIGNED, "true")); return v; }
private void addDpiStructure(Structure parent, BufrConfig.FieldConverter parentFld, BufrConfig.FieldConverter dpiField) { DataDescriptor dpiKey = dpiField.dds; String uname = findUniqueName(parent, dpiField.getName(), "struct"); dpiKey.name = uname; // name may need to be changed for uniqueness //String structName = findUnique(parent, dpiField.name); Structure struct = new Structure(ncfile, null, parent, uname); int n = parentFld.dds.replication; try { struct.setDimensionsAnonymous(new int[]{n}); // anon vector } catch (InvalidRangeException e) { log.error("illegal count= " + 1 + " for " + dpiField); } Variable v = new Variable(ncfile, null, struct, "name"); v.setDataType(DataType.STRING); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); v = new Variable(ncfile, null, struct, "data"); v.setDataType(DataType.FLOAT); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); parent.addMemberVariable(struct); struct.setSPobject(dpiField); // ?? dpiKey.refersTo = struct; // add some fake dkeys corresponding to above // DataDescriptor nameDD = new DataDescriptor(); }
private void addDpiSequence(Structure parent, BufrConfig.FieldConverter fld) { Structure struct = new Structure(ncfile, null, parent, "statistics"); try { struct.setDimensionsAnonymous(new int[]{fld.dds.replication}); // scalar } catch (InvalidRangeException e) { e.printStackTrace(); } Variable v = new Variable(ncfile, null, struct, "name"); v.setDataType(DataType.STRING); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); v = new Variable(ncfile, null, struct, "data"); v.setDataType(DataType.FLOAT); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); parent.addMemberVariable(struct); }
private void addDpiSequence(Structure parent, DataDescriptor dataDesc) { Structure struct = new Structure(ncfile, null, parent, "statistics"); try { struct.setDimensionsAnonymous(new int[] {dataDesc.replication}); // scalar } catch (InvalidRangeException e) { e.printStackTrace(); } Variable v = new Variable(ncfile, null, struct, "name"); v.setDataType(DataType.STRING); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); v = new Variable(ncfile, null, struct, "data"); v.setDataType(DataType.FLOAT); // scalar v.setDimensions(""); // scalar struct.addMemberVariable(v); parent.addMemberVariable(struct); }
static Structure decodeStructure(NetcdfFile ncfile, Group g, Structure parent, NcStreamProto.Structure s) { Structure ncvar = (s.getDataType() == ucar.nc2.stream.NcStreamProto.DataType.SEQUENCE) ? new Sequence(ncfile, g, parent, s.getName()) : new Structure(ncfile, g, parent, s.getName()); ncvar.setDataType(decodeDataType(s.getDataType())); List<Dimension> dims = new ArrayList<Dimension>(6); for (ucar.nc2.stream.NcStreamProto.Dimension dim : s.getShapeList()) { if (dim.getIsPrivate() || dim.getIsVlen()) dims.add(new Dimension(dim.getName(), (int) dim.getLength(), false, dim.getIsUnlimited(), dim.getIsVlen())); else { Dimension d = g.findDimension(dim.getName()); if (d == null) throw new IllegalStateException("Can find shared dimension " + dim.getName()); dims.add(d); } } ncvar.setDimensions(dims); for (ucar.nc2.stream.NcStreamProto.Attribute att : s.getAttsList()) ncvar.addAttribute(decodeAtt(att)); for (ucar.nc2.stream.NcStreamProto.Variable vp : s.getVarsList()) ncvar.addMemberVariable(decodeVar(ncfile, g, ncvar, vp)); for (NcStreamProto.Structure sp : s.getStructsList()) ncvar.addMemberVariable(decodeStructure(ncfile, g, ncvar, sp)); return ncvar; }
private Variable makeVariableMember(Group g, Structure s, String name, long dataPos, MessageDatatype mdt) throws IOException { Variable v; Vinfo vinfo = new Vinfo(mdt, null, dataPos); // LOOK need mds if (vinfo.getNCDataType() == null) { debugOut.println("SKIPPING DataType= " + vinfo.typeInfo.hdfType + " for variable " + name); return null; } if (mdt.type == 6) { v = new Structure(ncfile, g, s, name); makeVariableShapeAndType(v, mdt, null, vinfo, null); addMembersToStructure(g, (Structure) v, vinfo, mdt); v.setElementSize(mdt.byteSize); } else { v = new Variable(ncfile, g, s, name); makeVariableShapeAndType(v, mdt, null, vinfo, null); } // special case of variable length strings if (v.getDataType() == DataType.STRING) v.setElementSize(16); // because the array has elements that are HeapIdentifier else if (v.getDataType() == DataType.OPAQUE) // special case of opaque v.setElementSize(mdt.getBaseSize()); v.setSPobject(vinfo); vinfo.setOwner(v); if (vinfo.typeInfo.unsigned) v.addAttribute(new Attribute(CDM.UNSIGNED, "true")); return v; }
private Structure makeReportIndexStructure() throws IOException { Structure reportIndex = new Structure(ncfile, null, null, BufrIosp.obsIndex); ncfile.addVariable(null, reportIndex); reportIndex.setDimensions("record"); reportIndex.addAttribute(new Attribute("long_name", "index on report")); Variable v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "name", DataType.STRING, "")); v.addAttribute(new Attribute("long_name", "name of station")); v.addAttribute(new Attribute("standard_name", "station_name")); v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "time", DataType.LONG, "")); v.addAttribute(new Attribute("units", "msecs since 1970-01-01 00:00")); v.addAttribute(new Attribute("long_name", "observation time")); v.addAttribute(new Attribute(_Coordinate.AxisType, "Time")); return reportIndex; }
private Structure makeReportIndexStructure() throws InvalidRangeException, IOException { Structure reportIndex = new Structure(ncfile, null, null, "reportIndex"); reportIndex.setDimensions("report"); reportIndex.addAttribute(new Attribute(CDM.LONG_NAME, "index on report - in memory")); int pos = 0; Variable v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "stationName", DataType.CHAR, "")); v.setDimensionsAnonymous(new int[]{6}); v.addAttribute(new Attribute(CDM.LONG_NAME, "name of station")); v.addAttribute(new Attribute("standard_name", "station_name")); v.setSPobject(new Vinfo(pos)); pos += 6; v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "time", DataType.INT, "")); v.addAttribute(new Attribute(CDM.UNITS, "secs since 1970-01-01 00:00")); v.addAttribute(new Attribute(CDM.LONG_NAME, "observation time")); v.setSPobject(new Vinfo(pos)); return reportIndex; }
private Structure makeReportIndexStructure() throws InvalidRangeException, IOException { Structure reportIndex = new Structure(ncfile, null, null, "reportIndex"); reportIndex.setDimensions("report"); reportIndex.addAttribute(new Attribute(CDM.LONG_NAME, "index on report - in memory")); int pos = 0; Variable v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "stationName", DataType.CHAR, "")); v.setDimensionsAnonymous(new int[]{6}); v.addAttribute(new Attribute(CDM.LONG_NAME, "name of station")); v.addAttribute(new Attribute("standard_name", "station_name")); v.setSPobject(new Vinfo(pos)); pos += 6; v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "time", DataType.INT, "")); v.addAttribute(new Attribute(CDM.UNITS, "secs since 1970-01-01 00:00")); v.addAttribute(new Attribute(CDM.LONG_NAME, "observation time")); v.setSPobject(new Vinfo(pos)); return reportIndex; }
private Structure makeReportIndexStructure() throws InvalidRangeException, IOException { Structure reportIndex = new Structure(ncfile, null, null, "reportIndex"); reportIndex.setDimensions("report"); reportIndex.addAttribute(new Attribute(CDM.LONG_NAME, "index on report - in memory")); int pos = 0; Variable v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "stationName", DataType.CHAR, "")); v.setDimensionsAnonymous(new int[]{6}); v.addAttribute(new Attribute(CDM.LONG_NAME, "name of station")); v.addAttribute(new Attribute("standard_name", "station_name")); v.setSPobject(new Vinfo(pos)); pos += 6; v = reportIndex.addMemberVariable(new Variable(ncfile, null, reportIndex, "time", DataType.INT, "")); v.addAttribute(new Attribute(CDM.UNITS, "secs since 1970-01-01 00:00")); v.addAttribute(new Attribute(CDM.LONG_NAME, "observation time")); v.setSPobject(new Vinfo(pos)); pos += 4; return reportIndex; }