private void copySome(NetcdfFileWriteable ncfile, Variable oldVar, int nelems) throws IOException { String newName = N3iosp.makeValidNetcdfObjectName(oldVar.getShortName()); int[] shape = oldVar.getShape(); int[] origin = new int[oldVar.getRank()]; int size = shape[0]; for (int i = 0; i < size; i += nelems) { origin[0] = i; int left = size - i; shape[0] = Math.min(nelems, left); Array data; try { data = oldVar.read(origin, shape); if (oldVar.getDataType() == DataType.STRING) { data = convertToChar(ncfile.findVariable(newName), data); } if (data.getSize() > 0) { // zero when record dimension = 0 ncfile.write(newName, origin, data); if (debug) System.out.println("write " + data.getSize() + " bytes"); } } catch (InvalidRangeException e) { e.printStackTrace(); throw new IOException(e.getMessage()); } } }
// @todo Make sure units are meters public double getElevation(int point) throws IOException // optional; units meters; missing = NaN. { Array array = null; try { array = getElevation(this.getPointRange(point)); } catch (InvalidRangeException e) { IllegalArgumentException iae = new IllegalArgumentException( "Point <" + point + "> not in valid range <0, " + (this.getNumberPoints() - 1) + ">: " + e.getMessage()); iae.initCause(e); throw iae; } if (array instanceof ArrayDouble) { return array.getDouble(array.getIndex()); } else if (array instanceof ArrayFloat) { return array.getFloat(array.getIndex()); } else { throw new IOException( "Elevation variable not float or double <" + array.getElementType().toString() + ">."); } }
// @todo Make sure units are degrees_east public double getLongitude(int point) throws IOException // required, units degrees_east { Array array = null; try { array = getLongitude(this.getPointRange(point)); } catch (InvalidRangeException e) { IllegalArgumentException iae = new IllegalArgumentException( "Point <" + point + "> not in valid range <0, " + (this.getNumberPoints() - 1) + ">: " + e.getMessage()); iae.initCause(e); throw iae; } if (array instanceof ArrayDouble) { return (array.getDouble(array.getIndex())); } else if (array instanceof ArrayFloat) { return (array.getFloat(array.getIndex())); } else { throw new IOException( "Longitude variable not float or double <" + array.getElementType().toString() + ">."); } }
public double getTimeValue(int point) throws IOException { Array array = null; try { array = getTime(this.getPointRange(point)); } catch (InvalidRangeException e) { IllegalArgumentException iae = new IllegalArgumentException( "Point <" + point + "> not in valid range <0, " + (this.getNumberPoints() - 1) + ">: " + e.getMessage()); iae.initCause(e); throw iae; } if (array instanceof ArrayDouble) { return (array.getDouble(array.getIndex())); } else if (array instanceof ArrayFloat) { return (array.getFloat(array.getIndex())); } else if (array instanceof ArrayInt) { return (array.getInt(array.getIndex())); } else { throw new IOException( "Time variable not float, double, or integer <" + array.getElementType().toString() + ">."); } }
public StructureData getData() throws IOException { if (sdata != null) return sdata; try { return (SingleTrajectory.this.getData(point)); } catch (InvalidRangeException e) { throw new IllegalStateException(e.getMessage()); } }
private void copyAll(NetcdfFileWriteable ncfile, Variable oldVar) throws IOException { String newName = N3iosp.makeValidNetcdfObjectName(oldVar.getShortName()); Array data = oldVar.read(); try { if (oldVar.getDataType() == DataType.STRING) { data = convertToChar(ncfile.findVariable(newName), data); } if (data.getSize() > 0) // zero when record dimension = 0 ncfile.write(newName, data); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IOException(e.getMessage() + " for Variable " + oldVar.getFullName()); } }
public Range getFullRange() { Range range = null; try { range = new Range(0, this.getNumberPoints() - 1); } catch (InvalidRangeException e) { IllegalStateException ise = new IllegalStateException( "Full trajectory range invalid <0, " + (this.getNumberPoints() - 1) + ">: " + e.getMessage()); ise.initCause(e); throw (ise); } return range; }
public Array getData(int point, String parameterName) throws IOException { try { return (getData(this.getPointRange(point), parameterName)); } catch (InvalidRangeException e) { IllegalArgumentException iae = new IllegalArgumentException( "Point <" + point + "> not in valid range <0, " + (this.getNumberPoints() - 1) + ">: " + e.getMessage()); iae.initCause(e); throw iae; } }