Java Code Examples for ucar.ma2.Section#computeSize()

The following examples show how to use ucar.ma2.Section#computeSize() . 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: OpendapServlet.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
long computeArraySize(SDArray da) throws Exception {
  assert (da.getContainerVar() instanceof DPrimitive);
  BaseType base = da.getPrimitiveVector().getTemplate();
  DataType dtype = DODSNetcdfFile.convertToNCType(base, false);
  int elemSize = dtype.getSize();
  int n = da.numDimensions();
  List<Range> ranges = new ArrayList<>(n);
  long size = 0;
  for (int i = 0; i < n; i++) {
    ranges.add(new Range(da.getStart(i), da.getStop(i), da.getStride(i)));
  }
  Section s = new Section(ranges);
  size += s.computeSize() * elemSize;

  return size;
}
 
Example 2
Source File: NcStreamIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
NcsMess(long filePos, int len, Object what) {
  this.filePos = filePos;
  this.len = len;
  this.what = what;
  if (what instanceof NcStreamProto.Data) {
    NcStreamProto.Data dataMess = (NcStreamProto.Data) what;
    this.dataType = NcStream.convertDataType(dataMess.getDataType());
    this.varName = dataMess.getVarName();
    Section s = NcStream.decodeSection(dataMess.getSection());
    if (s != null)
      this.nelems = (int) s.computeSize();
  } else if (what instanceof DataStorage)
    this.nelems = ((DataStorage) what).nelems;
}
 
Example 3
Source File: TimeCdmRemote.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static Section makeSubset(Variable v) throws InvalidRangeException {
  int[] shape = v.getShape();
  shape[0] = 1;
  Section s = new Section(shape);
  long size = s.computeSize();
  shape[0] = (int) Math.max(1, max_size / size);
  return new Section(shape);
}
 
Example 4
Source File: TestDir.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static Section makeSubset(Variable v) {
  int[] shape = v.getShape();
  shape[0] = 1;
  Section s = new Section(shape);
  long size = s.computeSize();
  shape[0] = (int) Math.max(1, max_size / size);
  return new Section(shape);
}
 
Example 5
Source File: TestDir.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static Section makeSubset(Variable v) throws InvalidRangeException {
  int[] shape = v.getShape();
  shape[0] = 1;
  Section s = new Section(shape);
  long size = s.computeSize();
  shape[0] = (int) Math.max(1, max_size / size);
  return new Section(shape);
}
 
Example 6
Source File: Coverage.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public long getSizeInBytes() {
  Section section = new Section(coordSys.getShape());
  return section.computeSize() * getDataType().getSize();
}
 
Example 7
Source File: N3iospNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Read data from record structure. For N3, this is the only possible structure, and there can be no nesting.
 * Read all variables for each record, put in ByteBuffer.
 *
 * @param s the record structure
 * @param section the record range to read
 * @return an ArrayStructure, with all the data read in.
 * @throws IOException on error
 */
private ucar.ma2.Array readRecordData(ucar.nc2.Structure s, Section section) throws java.io.IOException {
  // has to be 1D
  Range recordRange = section.getRange(0);

  // create the ArrayStructure
  StructureMembers members = s.makeStructureMembers();
  for (StructureMembers.Member m : members.getMembers()) {
    Variable v2 = s.findVariable(m.getName());
    Vinfo vinfo = (Vinfo) v2.getSPobject();
    m.setDataParam((int) (vinfo.begin - header.recStart));
  }

  // protect against too large of reads
  if (header.recsize > Integer.MAX_VALUE)
    throw new IllegalArgumentException("Cant read records when recsize > " + Integer.MAX_VALUE);
  long nrecs = section.computeSize();
  if (nrecs * header.recsize > Integer.MAX_VALUE)
    throw new IllegalArgumentException(
        "Too large read: nrecs * recsize= " + (nrecs * header.recsize) + "bytes exceeds " + Integer.MAX_VALUE);

  members.setStructureSize((int) header.recsize);
  ArrayStructureBB structureArray = new ArrayStructureBB(members, new int[] {recordRange.length()});

  // loop over records
  byte[] result = structureArray.getByteBuffer().array();
  int count = 0;
  for (int recnum : recordRange) {
    if (debugRecord)
      System.out.println(" read record " + recnum);
    raf.seek(header.recStart + recnum * header.recsize); // where the record starts

    if (recnum != header.numrecs - 1) {
      raf.readFully(result, (int) (count * header.recsize), (int) header.recsize);
    } else {
      // "wart" allows file to be one byte short. since its always padding, we allow
      raf.read(result, (int) (count * header.recsize), (int) header.recsize);
    }
    count++;
  }

  return structureArray;
}