/** * Create a Structure "from scratch". * @param ncfile the containing NetcdfFile. * @param group the containing group; if null, use rootGroup * @param parent parent Structure, may be null * @param shortName variable shortName, must be unique within the Group * @param dimList list of Dimensions */ public Structure(NetcdfFile ncfile, Group group, Structure parent, String shortName, List<Dimension> dimList) { this(ncfile, group, parent, shortName); setDimensions(dimList); }
synchronized boolean makeRecordStructure() { // create record structure if (uvars.size() > 0) { Structure recordStructure = new Structure(ncfile, ncfile.getRootGroup(), null, "record"); recordStructure.setDimensions(udim.getShortName()); for (Variable v : uvars) { Variable memberV; try { memberV = v.slice(0, 0); // set unlimited dimension to 0 } catch (InvalidRangeException e) { log.warn("N3header.makeRecordStructure cant slice variable " +v+ " "+e.getMessage()); return false; } memberV.setParentStructure(recordStructure); //memberV.createNewCache(); // decouple caching - could use this ?? //remove record dimension //List<Dimension> dims = new ArrayList<Dimension>(v.getDimensions()); //dims.remove(0); //memberV.setDimensions(dims); recordStructure.addMemberVariable(memberV); } uvars.add(recordStructure); ncfile.getRootGroup().addVariable(recordStructure); ncfile.finish(); return true; } return false; }
synchronized boolean makeRecordStructure() { // create record structure if (uvars.size() > 0) { Structure recordStructure = new Structure(ncfile, ncfile.getRootGroup(), null, "record"); recordStructure.setDimensions(udim.getShortName()); for (Variable v : uvars) { Variable memberV; try { memberV = v.slice(0, 0); // set unlimited dimension to 0 } catch (InvalidRangeException e) { log.warn("N3header.makeRecordStructure cant slice variable " +v+ " "+e.getMessage()); return false; } memberV.setParentStructure(recordStructure); //memberV.createNewCache(); // decouple caching - could use this ?? //remove record dimension //List<Dimension> dims = new ArrayList<Dimension>(v.getDimensions()); //dims.remove(0); //memberV.setDimensions(dims); recordStructure.addMemberVariable(memberV); } uvars.add(recordStructure); ncfile.getRootGroup().addVariable(recordStructure); ncfile.finish(); return true; } return false; }
synchronized boolean makeRecordStructure() { // create record structure if (uvars.size() > 0) { Structure recordStructure = new Structure(ncfile, ncfile.getRootGroup(), null, "record"); recordStructure.setDimensions(udim.getShortName()); for (Variable v : uvars) { Variable memberV; try { memberV = v.slice(0, 0); // set unlimited dimension to 0 } catch (InvalidRangeException e) { log.warn("N3header.makeRecordStructure cant slice variable " +v+ " "+e.getMessage()); return false; } memberV.setParentStructure(recordStructure); //memberV.createNewCache(); // decouple caching - could use this ?? //remove record dimension //List<Dimension> dims = new ArrayList<Dimension>(v.getDimensions()); //dims.remove(0); //memberV.setDimensions(dims); recordStructure.addMemberVariable(memberV); } uvars.add(recordStructure); ncfile.getRootGroup().addVariable(recordStructure); ncfile.finish(); return true; } return false; }
/** * Adds a copy of the specified structure to the file (netcdf4 only). DO NOT USE YET * * @param g add to this group in the new file * @param original the structure to make a copy of in the new file. * @param shortName name of Variable, must be unique with the file. * @param dims list of Dimensions for the variable in the new file, must already have been added. * Use a list of length 0 for a scalar variable. * @return the Structure variable that has been added */ public Structure addCopyOfStructure(Group g, @Nonnull Structure original, String shortName, List<Dimension> dims) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); if (original == null) throw new NullPointerException("Original structure must be non-null"); shortName = makeValidObjectName(shortName); if (!version.isExtendedModel()) throw new IllegalArgumentException("Structure type only supported in extended model, version="+version); Structure s = new Structure(ncfile, g, null, shortName); s.setDimensions(dims); for (Variable m : original.getVariables()) { // LOOK no nested structs Variable nest = new Variable(ncfile, g, s, m.getShortName()); nest.setDataType(m.getDataType()); nest.setDimensions(m.getDimensions()); nest.addAll(m.getAttributes()); s.addMemberVariable(nest); } ncfile.addVariable(g, s); return s; }
} else if (utype != null) { Structure s = new Structure(ncfile, g, parent, vname); s.setDimensions(dimList); v = s; if (utype.flds == null)
private Variable makeVariable(Group g, Structure parent, String vname, int typeid, String dimList) throws IOException { //if (typeid == Nc4prototypes.NC_STRING) // System.out.println("HEY"); ConvertedType cvttype = convertDataType(typeid); DataType dtype = cvttype.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(); //Coverity[FORWARD_NULL] for (Field f : utype.flds) { s.addMemberVariable(f.makeMemberVariable(g, s)); } } else { throw new IllegalStateException("Dunno what to with " + dtype); } if (cvttype.isUnsigned) v.addAttribute(new Attribute(CDM.UNSIGNED, "true")); if (dtype.isEnum()) { EnumTypedef enumTypedef = g.findEnumeration(utype.name); v.setEnumTypedef(enumTypedef); } return v; }
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; }
/** * Add a structure to the file (netcdf4 only). DO NOT USE YET * * @param g add to this group in the new file * @param org rent Structure (netcdf4 only), or null if not a member of a Structure * @param shortName name of Variable, must be unique with the file. * @param dims list of Dimensions for the variable in the new file, must already have been added. * Use a list of length 0 for a scalar variable. * @return the Structure vaiable that has been added */ public Structure addStructure(Group g, Structure org, String shortName, List<Dimension> dims) { if (!defineMode) throw new UnsupportedOperationException("not in define mode"); shortName = makeValidObjectName(shortName); if (!version.isExtendedModel()) throw new IllegalArgumentException("Structure type only supported in extended model, version="+version); Structure s = new Structure(ncfile, g, null, shortName); s.setDimensions(dims); for (Variable m : org.getVariables()) { // LOOK no nested structs Variable nest = new Variable(ncfile, g, s, m.getShortName()); nest.setDataType(m.getDataType()); nest.setDimensions(m.getDimensions()); s.addMemberVariable(nest); } ncfile.addVariable(g, s); return s; }
dist.setDimensions(dims); ncfile.addVariable(null, dist); dist.addAttribute( new Attribute(CDM.LONG_NAME, "special graphic symbol for code "+code));
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; }
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; }
dist.setDimensions(dims); ncfile.addVariable(null, dist); dist.addAttribute( new Attribute(CDM.LONG_NAME, "Circle Packet"));
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 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; }
private Structure makeStationStructure() throws IOException, InvalidRangeException { Structure station = new Structure(ncfile, null, null, "station"); station.setDimensions("station"); station.addAttribute(new Attribute(CDM.LONG_NAME, "unique stations within this file"));
private Structure makeStationStructure() throws IOException, InvalidRangeException { Structure station = new Structure(ncfile, null, null, "station"); station.setDimensions("station"); station.addAttribute(new Attribute(CDM.LONG_NAME, "unique stations within this file"));