Java Code Examples for ucar.ma2.InvalidRangeException#printStackTrace()

The following examples show how to use ucar.ma2.InvalidRangeException#printStackTrace() . 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: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeExtraVariables() throws IOException {
  if (extra == null)
    return;

  for (Variable v : extra) {
    NetcdfFile ncfile = writer.getOutputFile();
    Variable mv = ncfile.findVariable(v.getFullName());
    if (mv == null)
      continue; // may be removed
    try {
      writer.write(mv, v.read());
    } catch (InvalidRangeException e) {
      e.printStackTrace(); // cant happen haha
    }
  }
}
 
Example 2
Source File: CoverageAsPoint.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
VarData(Coverage cov) throws IOException {
  this.cov = cov;
  try {
    this.array = cov.readData(subset);
    if (debug)
      System.out.printf(" Coverage %s data shape = %s%n", cov.getName(),
          Arrays.toString(array.getData().getShape()));
  } catch (InvalidRangeException e) {
    e.printStackTrace();
  }
}
 
Example 3
Source File: N3iospWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void fillNonRecordVariables() throws IOException {
  // run through each variable
  for (Variable v : ncfile.getVariables()) {
    if (v.isUnlimited())
      continue;
    try {
      writeData(v, v.getShapeAsSection(), makeConstantArray(v));
    } catch (InvalidRangeException e) {
      e.printStackTrace(); // shouldnt happen
    }
  }
}
 
Example 4
Source File: WriterCFPointAbstract.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
int writeStructureData(int recno, Structure s, StructureData sdata, Set<String> varSet) throws IOException {

    // write the recno record
    int[] origin = new int[1];
    origin[0] = recno;
    try {
      if (isExtendedModel) {
        if (s.isUnlimited())
          return writer.appendStructureData(s, sdata); // can write it all at once along unlimited dimension
        else {
          ArrayStructureW as = new ArrayStructureW(sdata.getStructureMembers(), new int[] {1});
          as.setStructureData(sdata, 0);
          writer.write(s, origin, as); // can write it all at once along regular dimension
          return recno + 1;
        }

      } else {
        writeStructureDataClassic(origin, sdata, varSet);
      }

    } catch (InvalidRangeException e) {
      e.printStackTrace();
      throw new IllegalStateException(e);
    }

    return recno + 1;
  }
 
Example 5
Source File: NetcdfCopier.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void copyAll(NetcdfFormatWriter ncwriter, Variable oldVar, Variable newVar) throws IOException {
  Array data = oldVar.read();
  try {
    if (!extended && oldVar.getDataType() == DataType.STRING) {
      data = convertDataToChar(newVar, data);
    }
    if (data.getSize() > 0) { // zero when record dimension = 0
      ncwriter.write(newVar, data);
    }

  } catch (InvalidRangeException e) {
    e.printStackTrace();
    throw new IOException(e.getMessage() + " for Variable " + oldVar.getFullName());
  }
}
 
Example 6
Source File: NetcdfCopier.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Copies data from {@code oldVar} to {@code newVar}. The writes are done in a series of chunks no larger than
 * {@code maxChunkSize}
 * bytes.
 *
 * @param oldVar a variable from the original file to copy data from.
 * @param newVar a variable from the original file to copy data from.
 * @param maxChunkSize the size, <b>in bytes</b>, of the largest chunk to write.
 * @param cancel allow user to cancel, may be null.
 * @throws IOException if an I/O error occurs.
 */
private void copySome(NetcdfFormatWriter ncwriter, Variable oldVar, Variable newVar, long maxChunkSize,
    CancelTask cancel) throws IOException {
  long maxChunkElems = maxChunkSize / oldVar.getElementSize();
  long byteWriteTotal = 0;

  ChunkingIndex index = new ChunkingIndex(oldVar.getShape());
  while (index.currentElement() < index.getSize()) {
    try {
      int[] chunkOrigin = index.getCurrentCounter();
      int[] chunkShape = index.computeChunkShape(maxChunkElems);

      cancel.setProgress(
          "Reading chunk " + new Section(chunkOrigin, chunkShape) + " from variable: " + oldVar.getShortName(), -1);

      Array data = oldVar.read(chunkOrigin, chunkShape);
      if (!getOutputFormat().isNetdf4format() && oldVar.getDataType() == DataType.STRING) {
        data = convertDataToChar(newVar, data);
      }

      if (data.getSize() > 0) { // zero when record dimension = 0
        cancel.setProgress(
            "Writing chunk " + new Section(chunkOrigin, chunkShape) + " from variable: " + oldVar.getShortName(), -1);

        ncwriter.write(newVar, chunkOrigin, data);
        if (debugWrite) {
          System.out.println(" write " + data.getSize() + " bytes at " + new Section(chunkOrigin, chunkShape));
        }

        byteWriteTotal += data.getSize();
      }

      index.setCurrentCounter(index.currentElement() + (int) Index.computeSize(chunkShape));
      if (cancel.isCancel()) {
        return;
      }

    } catch (InvalidRangeException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage());
    }
  }
}