Java Code Examples for ucar.nc2.NetcdfFile#finish()

The following examples show how to use ucar.nc2.NetcdfFile#finish() . 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: NcStreamReader.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private NetcdfFile proto2nc(NcStreamProto.Header proto, NetcdfFile ncfile) {
  if (ncfile == null)
    ncfile = new NetcdfFileSubclass(); // not used i think
  ncfile.setLocation(proto.getLocation());
  if (!proto.getId().isEmpty())
    ncfile.setId(proto.getId());
  if (!proto.getTitle().isEmpty())
    ncfile.setTitle(proto.getTitle());

  NcStreamProto.Group root = proto.getRoot();
  Group.Builder rootBuilder = Group.builder().setNcfile(ncfile).setName("");
  NcStream.readGroup(root, rootBuilder);
  ncfile.setRootGroup(rootBuilder.build());
  ncfile.finish();
  return ncfile;
}
 
Example 2
Source File: H5iospNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);
  Group.Builder rootGroup = Group.builder().setName("").setNcfile(ncfile);
  header = new H5headerNew(raf, rootGroup, this);
  header.read(null);
  ncfile.setRootGroup(rootGroup.build());

  // check if its an HDF5-EOS file
  if (useHdfEos) {
    rootGroup.findGroupLocal(HdfEos.HDF5_GROUP).ifPresent(eosGroup -> {
      try {
        isEos = HdfEos.amendFromODL(raf.getLocation(), header, eosGroup);
      } catch (IOException e) {
        log.warn(" HdfEos.amendFromODL failed");
      }
    });
  }

  ncfile.finish();
}
 
Example 3
Source File: N3iospNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Deprecated
@Override
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);

  String location = raf.getLocation();
  if (!location.startsWith("http:")) {
    File file = new File(location);
    if (file.exists())
      lastModified = file.lastModified();
  }

  raf.order(RandomAccessFile.BIG_ENDIAN);
  header = createHeader();

  Group.Builder rootGroup = Group.builder().setName("").setNcfile(ncfile);
  header.read(raf, rootGroup, null);
  ncfile.setRootGroup(rootGroup.build());
  ncfile.finish();
}
 
Example 4
Source File: BufrIosp2.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);

  scanner = new MessageScanner(raf);
  protoMessage = scanner.getFirstDataMessage();
  if (protoMessage == null)
    throw new IOException("No data messages in the file= " + ncfile.getLocation());
  if (!protoMessage.isTablesComplete())
    throw new IllegalStateException("BUFR file has incomplete tables");

  // just get the fields
  config = BufrConfig.openFromMessage(raf, protoMessage, iospParam);

  // this fills the netcdf object
  Construct2 construct = new Construct2(protoMessage, config, ncfile);
  obsStructure = construct.getObsStructure();
  ncfile.finish();
  isSingle = false;
}
 
Example 5
Source File: BufrIosp2.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void open(RandomAccessFile raf, NetcdfFile ncfile, Message single) throws IOException {
  this.raf = raf;

  protoMessage = single;
  protoMessage.getRootDataDescriptor(); // construct the data descriptors, check for complete tables
  if (!protoMessage.isTablesComplete())
    throw new IllegalStateException("BUFR file has incomplete tables");

  BufrConfig config = BufrConfig.openFromMessage(raf, protoMessage, null);

  // this fills the netcdf object
  Construct2 construct = new Construct2(protoMessage, config, ncfile);
  obsStructure = construct.getObsStructure();
  isSingle = true;

  ncfile.finish();
  this.ncfile = ncfile;
}
 
Example 6
Source File: DatasetSourceExample.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public NetcdfFile getNetcdfFile(HttpServletRequest req, HttpServletResponse res) throws IOException {
  String path = TdsPathUtils.extractPath(req, prefix);

  DataRootManager.DataRootMatch match = DataRootManager.getInstance().findDataRootMatch(path);
  if (match == null) {
    res.sendError(HttpServletResponse.SC_NOT_FOUND, path);
    return null;
  }

  int pos = match.remaining.lastIndexOf('.');
  String filename = match.remaining.substring(0, pos);

  File file = new File(match.dirLocation + filename);
  if (!file.exists()) {
    res.sendError(HttpServletResponse.SC_NOT_FOUND, match.dirLocation + filename);
    return null;
  }

  NetcdfFile ncfile = NetcdfDatasets.openFile(file.getPath(), null);
  ncfile.addAttribute(null, new Attribute("Special", req.getRequestURI()));
  ncfile.finish();
  return ncfile;
}
 
Example 7
Source File: GtopoIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);

  readHDR();

  ncfile.addDimension(null, new Dimension("lat", nlats));
  ncfile.addDimension(null, new Dimension("lon", nlons));

  Variable elev = new Variable(ncfile, null, null, "elevation");
  elev.setDataType(DataType.SHORT);
  elev.setDimensions("lat lon");

  elev.addAttribute(new Attribute(CDM.UNITS, "m"));
  elev.addAttribute(new Attribute("units_desc", "meters above sea level"));
  elev.addAttribute(new Attribute(CDM.LONG_NAME, "digital elevation in meters above mean sea level"));
  elev.addAttribute(new Attribute(CDM.MISSING_VALUE, (short) -9999));
  ncfile.addVariable(null, elev);

  Variable lat = new Variable(ncfile, null, null, "lat");
  lat.setDataType(DataType.FLOAT);
  lat.setDimensions("lat");
  lat.addAttribute(new Attribute(CDM.UNITS, CDM.LAT_UNITS));
  ncfile.addVariable(null, lat);
  Array data = Array.makeArray(DataType.FLOAT, nlats, starty, -incr);
  lat.setCachedData(data, false);

  Variable lon = new Variable(ncfile, null, null, "lon");
  lon.setDataType(DataType.FLOAT);
  lon.setDimensions("lon");
  lon.addAttribute(new Attribute(CDM.UNITS, CDM.LON_UNITS));
  ncfile.addVariable(null, lon);
  Array lonData = Array.makeArray(DataType.FLOAT, nlons, startx, incr);
  lon.setCachedData(lonData, false);

  ncfile.addAttribute(null, new Attribute(CDM.CONVENTIONS, "CF-1.0"));
  ncfile.addAttribute(null, new Attribute("History", "Direct read by Netcdf-Java CDM library"));
  ncfile.addAttribute(null, new Attribute("Source", "http://eros.usgs.gov/products/elevation/gtopo30.html"));

  ncfile.finish();
}
 
Example 8
Source File: H4iosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);
  Group.Builder rootGroup = Group.builder().setName("").setNcfile(ncfile);
  getHeader().read(raf, rootGroup, null);
  ncfile.setRootGroup(rootGroup.build());
  ncfile.finish();
}
 
Example 9
Source File: H4iosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException {
  super.open(raf, ncfile, cancelTask);
  header.read(raf, ncfile);
  ncfile.finish();
}