@Override protected boolean identifyEncodingStation(NetcdfDataset ds, EncodingInfo info, CF.FeatureType ftype, Formatter errlog) { Structure obs = info.time.getParentStructure(); if (obs.getRank() == 0) { errlog.format("CFpointObs: must have a non-scalar Time coordinate%n"); return false; } Dimension obsDim = obs.getDimension(0); Structure station = info.lat.getParentStructure(); if (station.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension stnDim = station.getDimension(0); // the raggeds if (identifyRaggeds(ds, info, stnDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s Must have Lat/Lon coordinates of rank 0 or 1%n", ftype); return false; }
@Override protected boolean identifyEncodingStation(NetcdfDataset ds, EncodingInfo info, CF.FeatureType ftype, Formatter errlog) { Structure obs = info.time.getParentStructure(); if (obs.getRank() == 0) { errlog.format("CFpointObs: must have a non-scalar Time coordinate%n"); return false; } Dimension obsDim = obs.getDimension(0); Structure station = info.lat.getParentStructure(); if (station.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension stnDim = station.getDimension(0); // the raggeds if (identifyRaggeds(ds, info, stnDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s Must have Lat/Lon coordinates of rank 0 or 1%n", ftype); return false; }
@Override protected boolean identifyEncodingTraj(NetcdfDataset ds, EncodingInfo info, Formatter errlog) { // find the obs structure info.childStruct = info.lat.getParentStructure(); Dimension obsDim = info.childStruct.getDimension(0); // find the traj structure Variable varatt = Evaluator.findVariableWithAttributeValue(ds, CF.CF_ROLE, CF.TRAJECTORY_ID); Structure traj = varatt.getParentStructure(); if (traj.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension trajDim = traj.getDimension(0); if (identifyRaggeds(ds, info, trajDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s only supports ragged array representation%n", CF.FeatureType.trajectory); return false; }
@Override protected boolean identifyEncodingTraj(NetcdfDataset ds, EncodingInfo info, Formatter errlog) { // find the obs structure info.childStruct = info.lat.getParentStructure(); Dimension obsDim = info.childStruct.getDimension(0); // find the traj structure Variable varatt = Evaluator.findVariableWithAttributeValue(ds, CF.CF_ROLE, CF.TRAJECTORY_ID); Structure traj = varatt.getParentStructure(); if (traj.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension trajDim = traj.getDimension(0); if (identifyRaggeds(ds, info, trajDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s only supports ragged array representation%n", CF.FeatureType.trajectory); return false; }
private static float[][] readModeInfo(NetcdfFile ncFile) throws IOException { Variable modeInfoVar = ncFile.getRootGroup().findVariable(ChrisConstants.VS_NAME_MODE_INFO); if (modeInfoVar instanceof Structure) { Structure modeInfoStruct = (Structure) modeInfoVar; int numRecords = modeInfoStruct.getDimension(0).getLength(); String[] fieldNames = ChrisConstants.VS_NAME_MODE_FIELDS; Variable[] fieldVariables = new Variable[fieldNames.length]; for (int i = 0; i < fieldVariables.length; i++) { fieldVariables[i] = modeInfoStruct.findVariable(fieldNames[i]); if (fieldVariables[i] == null) { throw new IOException("Failed to read 'Mode Info' Structure."); } } float[][] modeInfo = new float[numRecords][fieldNames.length]; for (int i = 0; i < fieldNames.length; i++) { Array array = fieldVariables[i].read(); for (int j = 0; j < numRecords; j++) { modeInfo[j][i] = array.getFloat(j); } } return modeInfo; } throw new IOException("Failed to read 'Mode Info' Structure."); }
private static Map<Integer, Float> readGainInfo(NetcdfFile ncFile) throws IOException { Variable gainInfoVar = ncFile.getRootGroup().findVariable(ChrisConstants.VS_NAME_GAIN_INFO); if (gainInfoVar instanceof Structure) { Structure gainInfoStruct = (Structure) gainInfoVar; int recordCount = gainInfoStruct.getDimension(0).getLength(); Variable gainSetting = gainInfoStruct.findVariable(ChrisConstants.VS_NAME_GAIN_SETTING); Variable gainValue = gainInfoStruct.findVariable(ChrisConstants.VS_NAME_GAIN_VALUE); if (gainSetting != null && gainValue != null && recordCount > 0) { final Map<Integer, Float> gainInfoMap = new HashMap<Integer, Float>(recordCount); Array settingsArray = gainSetting.read(); Array valuesArray = gainValue.read(); for (int i = 0; i < recordCount; i++) { gainInfoMap.put(settingsArray.getInt(i), valuesArray.getFloat(i)); } return gainInfoMap; } } throw new IOException("Failed to read 'Gain Info' Structure."); }
@Override public int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException { Vinfo vinfo = (Vinfo) s.getSPobject(); Dimension dim = s.getDimension(0); // LOOK must be outer dim int dimid = vinfo.g4.dimHash.get(dim); SizeTByReference lenp = new SizeTByReference(); int ret = nc4.nc_inq_dimlen(vinfo.g4.grpid, dimid, lenp); if (ret != 0) throw new IOException(errMessage("nc_inq_dimlen", ret, vinfo.g4.grpid, dimid)); SizeT[] origin = new SizeT[]{lenp.getValue()}; SizeT[] shape = new SizeT[]{new SizeT(1)}; SizeT[] stride = new SizeT[]{new SizeT(1)}; //ArrayStructureBB valuesBB = IospHelper.copyToArrayBB(sdata, ByteOrder.nativeOrder()); // n4 wants native byte order // ByteBuffer bbuff = valuesBB.getByteBuffer(); ByteBuffer bbuff = makeBB(s, sdata); // write the data //ret = nc4.nc_put_vara(vinfo.g4.grpid, vinfo.varid, origin, shape, bbuff); //ret = nc4.nc_put_vars(vinfo.g4.grpid, vinfo.varid, origin, shape, stride, bbuff); ret = nc4.nc_put_vars(vinfo.g4.grpid, vinfo.varid, origin, shape, stride, bbuff.array()); if (ret != 0) throw new IOException(errMessage("appendStructureData (nc_put_vars)", ret, vinfo.g4.grpid, vinfo.varid)); return origin[0].intValue(); // recnum }
@Override public int appendStructureData(Structure s, StructureData sdata) throws IOException, InvalidRangeException { Vinfo vinfo = (Vinfo) s.getSPobject(); Dimension dim = s.getDimension(0); // LOOK must be outer dim int dimid = vinfo.g4.dimHash.get(dim); SizeTByReference lenp = new SizeTByReference(); int ret = nc4.nc_inq_dimlen(vinfo.g4.grpid, dimid, lenp); if (ret != 0) throw new IOException(errMessage("nc_inq_dimlen", ret, vinfo.g4.grpid, dimid)); SizeT[] origin = new SizeT[]{lenp.getValue()}; SizeT[] shape = new SizeT[]{new SizeT(1)}; SizeT[] stride = new SizeT[]{new SizeT(1)}; //ArrayStructureBB valuesBB = IospHelper.copyToArrayBB(sdata, ByteOrder.nativeOrder()); // n4 wants native byte order // ByteBuffer bbuff = valuesBB.getByteBuffer(); ByteBuffer bbuff = makeBB(s, sdata); // write the data //ret = nc4.nc_put_vara(vinfo.g4.grpid, vinfo.varid, origin, shape, bbuff); //ret = nc4.nc_put_vars(vinfo.g4.grpid, vinfo.varid, origin, shape, stride, bbuff); ret = nc4.nc_put_vars(vinfo.g4.grpid, vinfo.varid, origin, shape, stride, bbuff.array()); if (ret != 0) throw new IOException(errMessage("appendStructureData (nc_put_vars)", ret, vinfo.g4.grpid, vinfo.varid)); return origin[0].intValue(); // recnum }
@Override protected boolean identifyEncodingProfile(NetcdfDataset ds, EncodingInfo info, Formatter errlog) { Evaluator.VarAtt varatt = Evaluator.findVariableWithAttribute(ds, CF.SAMPLE_DIMENSION); if (varatt == null) return false; String dimName = varatt.att.getStringValue(); Dimension obsDim = ds.findDimension(dimName); Structure profile = info.lat.getParentStructure(); if (profile.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension profileDim = profile.getDimension(0); // now find the child structure info.childStruct = Evaluator.findStructureWithDimensions(ds, obsDim, null); // the raggeds if (identifyRaggeds(ds, info, profileDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s only supports ragged array representation%n", CF.FeatureType.profile); return false; }
@Override protected boolean identifyEncodingProfile(NetcdfDataset ds, EncodingInfo info, Formatter errlog) { Evaluator.VarAtt varatt = Evaluator.findVariableWithAttribute(ds, CF.SAMPLE_DIMENSION); if (varatt == null) return false; String dimName = varatt.att.getStringValue(); Dimension obsDim = ds.findDimension(dimName); Structure profile = info.lat.getParentStructure(); if (profile.getRank() == 0) { // could be scalar info.set(Encoding.single, null, obsDim); } Dimension profileDim = profile.getDimension(0); // now find the child structure info.childStruct = Evaluator.findStructureWithDimensions(ds, obsDim, null); // the raggeds if (identifyRaggeds(ds, info, profileDim, obsDim, errlog)) return true; errlog.format("CFpointObsExt: %s only supports ragged array representation%n", CF.FeatureType.profile); return false; }
public boolean match(CoordinateAxis axis) { if ((outer == null) && (axis.getRank() == 0)) return true; if ((outer != null) && (axis.getRank() == 1) && (outer.equals(axis.getDimension(0)))) return true; // if axis is structure member, try pulling dimension out of parent structure if (axis.getParentStructure() != null) { Structure parent = axis.getParentStructure(); if ((outer != null) && (parent.getRank() == 1) && (outer.equals(parent.getDimension(0)))) return true; } return false; } });
public boolean match(CoordinateAxis axis) { if ((outer == null) && (axis.getRank() == 0)) return true; if ((outer != null) && (axis.getRank() == 1) && (outer.equals(axis.getDimension(0)))) return true; // if axis is structure member, try pulling dimension out of parent structure if (axis.getParentStructure() != null) { Structure parent = axis.getParentStructure(); if ((outer != null) && (parent.getRank() == 1) && (outer.equals(parent.getDimension(0)))) return true; } return false; } });
public boolean match(CoordinateAxis axis) { if ((outer == null) && (axis.getRank() == 0)) return true; if ((outer != null) && (axis.getRank() == 1) && (outer.equals(axis.getDimension(0)))) return true; // if axis is structure member, try pulling dimension out of parent structure if (axis.getParentStructure() != null) { Structure parent = axis.getParentStructure(); if ((outer != null) && (parent.getRank() == 1) && (outer.equals(parent.getDimension(0)))) return true; } return false; } });
static public Variable findVariableWithAttributeAndDimension(NetcdfDataset ds, String att_name, String att_value, Dimension outer, Formatter errlog) { for (Variable v : ds.getVariables()) { String attValue = ds.findAttValueIgnoreCase(v, att_name, null); if ((attValue != null) && attValue.equalsIgnoreCase(att_value)) { if (v.getRank() > 0 && v.getDimension(0).equals(outer)) return v; if (isEffectivelyScaler(v) && (outer == null)) return v; } } // descend into structures for (Variable v : ds.getVariables()) { if (v instanceof Structure) { Structure s = (Structure) v; if (s.getRank() > 0 && s.getDimension(0).equals(outer) || (s.getRank() == 0 && outer == null)) { for (Variable vs : s.getVariables()) { Attribute att = vs.findAttributeIgnoreCase(att_name); if ((att != null) && att.isString() && att.getStringValue().equalsIgnoreCase(att_value)) return vs; } } } } // failed return null; }
else if (info.time.getParentStructure() != null) { obsDim = parent.getDimension(parent.getRank() - 1);
private void testReadDataAsShort(Structure v, String memberName) { Array a = null; assert(null != v); assert(null != v.getDimension(0)); try { a = v.read(); assert(null != a); } catch (java.io.IOException e) { e.printStackTrace(); assert(false); } assert( v.getSize() == a.getSize() ); assert (a instanceof ArrayStructure); int sum = 0; ArrayStructure as = (ArrayStructure) a; int n = (int) as.getSize(); for (int i = 0; i < n; i++) { StructureData sdata = as.getStructureData(i); sum += sdata.getScalarShort(memberName); } System.out.println("test short sum = "+sum); }
static public Variable findVariableWithAttributeAndDimension(NetcdfDataset ds, String att_name, String att_value, Dimension outer, Formatter errlog) { for (Variable v : ds.getVariables()) { String attValue = ds.findAttValueIgnoreCase(v, att_name, null); if ((attValue != null) && attValue.equalsIgnoreCase(att_value)) { if (v.getRank() > 0 && v.getDimension(0).equals(outer)) return v; if (isEffectivelyScaler(v) && (outer == null)) return v; } } // descend into structures for (Variable v : ds.getVariables()) { if (v instanceof Structure) { Structure s = (Structure) v; if (s.getRank() > 0 && s.getDimension(0).equals(outer) || (s.getRank() == 0 && outer == null)) { for (Variable vs : s.getVariables()) { Attribute att = vs.findAttributeIgnoreCase(att_name); if ((att != null) && att.isString() && att.getStringValue().equalsIgnoreCase(att_value)) return vs; } } } } // failed return null; }
else if (info.time.getParentStructure() != null) { obsDim = parent.getDimension(parent.getRank() - 1);
else if (info.time.getParentStructure() != null) { obsDim = parent.getDimension(parent.getRank() - 1);
Structure rs = (Structure) record; assert rs.getRank() == 1; assert rs.getDimension(0).getLength() == 2;