ucar.nc2.util.CancelTask Java Examples
The following examples show how to use
ucar.nc2.util.CancelTask.
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: McIDASGridServiceProvider.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Open the service provider for reading. * * @param raf file to read from * @param ncfile netCDF file we are writing to (memory) * @param cancelTask task for cancelling * @throws IOException problem reading file */ public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { // debugProj = true; super.open(raf, ncfile, cancelTask); long start = System.currentTimeMillis(); if (mcGridReader == null) { mcGridReader = new McIDASGridReader(); } mcGridReader.init(raf); GridIndex index = mcGridReader.getGridIndex(); open(index, cancelTask); if (debugOpen) { System.out.println( " GridServiceProvider.open " + ncfile.getLocation() + " took " + (System.currentTimeMillis() - start)); } }
Example #2
Source File: AreaServiceProvider.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Open the service provider for reading. * * @param raf file to read from * @param ncfile netCDF file we are writing to (memory) * @param cancelTask task for cancelling * @throws IOException problem reading file */ public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); if (areaReader == null) areaReader = new AreaReader(); try { areaReader.init(raf.getLocation(), ncfile); } catch (Throwable e) { close(); // try not to leak files throw new IOException(e); } finally { raf.close(); // avoid leaks } }
Example #3
Source File: NetcdfFile.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Open a RandomAccessFile as a NetcdfFile, if possible. * * @param raf The open raf, is not cloised by this method. * @param location human readable locatoin of this dataset. * @param cancelTask used to monitor user cancellation; may be null. * @param iospMessage send this message to iosp; may be null. * @return NetcdfFile or throw an Exception. * @throws IOException if cannot open as a CDM NetCDF. * @deprecated use NetcdfFiles.open */ @Deprecated public static NetcdfFile open(RandomAccessFile raf, String location, CancelTask cancelTask, Object iospMessage) throws IOException { IOServiceProvider spi = getIosp(raf); if (spi == null) { raf.close(); throw new IOException("Cant read " + location + ": not a valid CDM file."); } // send iospMessage before the iosp is opened if (iospMessage != null) spi.sendIospMessage(iospMessage); if (log.isDebugEnabled()) log.debug("Using IOSP {}", spi.getClass().getName()); NetcdfFile result = new NetcdfFile(spi, raf, location, cancelTask); // send iospMessage after iosp is opened if (iospMessage != null) spi.sendIospMessage(iospMessage); return result; }
Example #4
Source File: H5iospNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), cancelTask); raf.order(RandomAccessFile.BIG_ENDIAN); header = new H5headerNew(raf, rootGroup, this); header.read(null); // 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"); } }); } }
Example #5
Source File: AggDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected Array read(Variable mainv, CancelTask cancelTask) throws IOException { NetcdfFile ncd = null; try { ncd = acquireFile(cancelTask); if ((cancelTask != null) && cancelTask.isCancel()) return null; Variable v = findVariable(ncd, mainv); if (debugRead) System.out.printf("Agg.read %s from %s in %s%n", mainv.getNameAndDimensions(), v.getNameAndDimensions(), getLocation()); return v.read(); } finally { close(ncd); } }
Example #6
Source File: BufrIosp2.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), cancelTask); scanner = new MessageScanner(raf); protoMessage = scanner.getFirstDataMessage(); if (protoMessage == null) throw new IOException("No data messages in the file= " + raf.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 new BufrIospBuilder(protoMessage, config, rootGroup, raf.getLocation()); isSingle = false; }
Example #7
Source File: NmcObsLegacy.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); init(); ncfile.addAttribute(null, new Attribute(CDM.HISTORY, "Direct read of NMC ON29 by CDM")); ncfile.addAttribute(null, new Attribute(CDM.CONVENTIONS, "Unidata")); ncfile.addAttribute(null, new Attribute(CF.FEATURE_TYPE, CF.FeatureType.timeSeriesProfile.toString())); try { ncfile.addDimension(null, new Dimension("station", stations.size())); Structure station = makeStationStructure(); ncfile.addVariable(null, station); ncfile.addDimension(null, new Dimension("report", reports.size())); Structure reportIndexVar = makeReportIndexStructure(); ncfile.addVariable(null, reportIndexVar); Structure reportVar = makeReportStructure(); ncfile.addVariable(null, reportVar); } catch (InvalidRangeException e) { logger.error("open ON29 File", e); throw new IllegalStateException(e.getMessage()); } }
Example #8
Source File: DapperDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public List readStationData(ucar.unidata.geoloc.Station s, CancelTask cancel) throws IOException { String CE = outerSequence.getShortName() + "." + innerSequence.getShortName() + "&" + outerSequence.getShortName() + "." + ID + "=" + s.getName(); ArrayStructure as = (ArrayStructure) dodsFile.readWithCE(outerSequence, CE); /* * unwrap the outer structure * StructureMembers outerMembers = as.getStructureMembers(); * StructureMembers.Member outerMember = outerMembers.findMember(outerSequence.getShortName()); */ StructureData outerStructure = as.getStructureData(0); // get at the inner sequence ArrayStructure asInner = (ArrayStructure) outerStructure.getArray(innerSequence.getShortName()); StructureMembers innerMembers = asInner.getStructureMembers(); StructureMembers.Member timeMember = innerMembers.findMember(timeVar.getShortName()); int n = (int) asInner.getSize(); ArrayList stationData = new ArrayList(n); for (int i = 0; i < n; i++) { StructureData sdata = asInner.getStructureData(i); double obsTime = sdata.convertScalarDouble(timeMember); stationData.add(new SeqStationObs(s, obsTime, sdata)); } return stationData; }
Example #9
Source File: MadisPointObsDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public List getData(CancelTask cancel) throws IOException { ArrayList allData = new ArrayList(); for (int i = 0; i < getDataCount(); i++) { allData.add(makeObs(i)); if ((cancel != null) && cancel.isCancel()) return null; } return allData; }
Example #10
Source File: StructurePseudoDS.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Array reallyRead(Variable mainv, CancelTask cancelTask) throws IOException { if (debugRecord) System.out.println(" read all psuedo records "); StructureMembers smembers = makeStructureMembers(); ArrayStructureMA asma = new ArrayStructureMA(smembers, getShape()); for (Variable v : orgVariables) { Array data = v.read(); StructureMembers.Member m = smembers.findMember(v.getShortName()); m.setDataArray(data); } return asma; }
Example #11
Source File: CFPointWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { String progName = CFPointWriter.class.getName(); try { CommandLine cmdLine = new CommandLine(progName, args); if (cmdLine.help) { cmdLine.printUsage(); return; } FeatureType wantFeatureType = FeatureType.ANY_POINT; String location = cmdLine.inputFile.getAbsolutePath(); CancelTask cancel = null; Formatter errlog = new Formatter(); try (FeatureDatasetPoint fdPoint = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(wantFeatureType, location, cancel, errlog)) { if (fdPoint == null) { System.err.println(errlog); } else { System.out.printf("CFPointWriter: reading from %s, writing to %s%n", cmdLine.inputFile, cmdLine.outputFile); writeFeatureCollection(fdPoint, cmdLine.outputFile.getAbsolutePath(), cmdLine.getCFPointWriterConfig()); System.out.println("Done."); } } } catch (ParameterException e) { System.err.println(e.getMessage()); System.err.printf("Try \"%s --help\" for more information.%n", progName); } }
Example #12
Source File: DefaultConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
Example #13
Source File: GDVConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { projCT = makeProjectionCT(ds); if (projCT != null) { VariableDS v = makeCoordinateTransformVariable(ds, projCT); ds.addVariable(null, v); String xname = findCoordinateName(ds, AxisType.GeoX); String yname = findCoordinateName(ds, AxisType.GeoY); if (xname != null && yname != null) v.addAttribute(new Attribute(_Coordinate.Axes, xname + " " + yname)); } ds.finish(); }
Example #14
Source File: FmrcDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { try (NetcdfFile ncfile = open(location, null)) { Variable proxyV = findVariable(ncfile, client); if ((cancelTask != null) && cancelTask.isCancel()) return null; return proxyV.read(section); } }
Example #15
Source File: BufrFeatureDatasetFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public FeatureDataset open(FeatureType ftype, NetcdfDataset ncd, Object analysis, CancelTask task, Formatter errlog) throws IOException { // must have an index file File indexFile = BufrCdmIndex.calcIndexFile(ncd.getLocation()); if (indexFile == null) return null; BufrCdmIndex index = BufrCdmIndex.readIndex(indexFile.getPath()); return new BufrStationDataset(ncd, index); }
Example #16
Source File: Variable.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * public by accident, do not call directly. * * @return Array * @throws IOException on error */ @Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { if (isMemberOfStructure()) { throw new UnsupportedOperationException("Cannot directly read section of Member Variable=" + getFullName()); } // read just this section return ncfile.readData(this, section); }
Example #17
Source File: GempakStationFileIOSP.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Open the service provider for reading. * * @param raf file to read from * @param ncfile netCDF file we are writing to (memory) * @param cancelTask task for cancelling * @throws IOException problem reading file */ @Override public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); if (gemreader == null) { gemreader = makeStationReader(); } initTables(); gemreader.init(raf, true); buildNCFile(); }
Example #18
Source File: NetcdfDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Factory method for opening a dataset through the netCDF API, and identifying its coordinate variables. * * @param location location of file * @param enhanceMode set of enhancements. If null, then none * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param spiObject sent to iosp.setSpecial() if not null * @return NetcdfDataset object * @throws java.io.IOException on read error * @deprecated use NetcdfDatasets.openDataset */ @Deprecated public static NetcdfDataset openDataset(DatasetUrl location, Set<Enhance> enhanceMode, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { NetcdfFile ncfile = openProtocolOrFile(location, buffer_size, cancelTask, spiObject); NetcdfDataset ds; if (ncfile instanceof NetcdfDataset) { ds = (NetcdfDataset) ncfile; enhance(ds, enhanceMode, cancelTask); // enhance "in place", ie modify the NetcdfDataset } else { ds = new NetcdfDataset(ncfile, enhanceMode); // enhance when wrapping } return ds; }
Example #19
Source File: DapNetcdfFile.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Open a Dap4 connection or file via a D4DSP. * * @param location URL for the request. Note that if this is * intended to send to a file oriented * DSP, then if must be converted to an absolute path. * @param cancelTask check if task is cancelled; may be null. * @throws IOException */ public DapNetcdfFile(String location, CancelTask cancelTask) throws IOException { super(); this.location = location; // Figure out the location: url vs path XURI xuri; try { xuri = new XURI(location); } catch (URISyntaxException use) { throw new IOException(use); } boolean isfile = xuri.isFile(); if (isfile) { this.dsplocation = DapUtil.absolutize(xuri.getPath()); } else { // Not a file url this.dsplocation = xuri.assemble(XURI.URLBASE); } DapContext cxt = new DapContext(); cancel = (cancelTask == null ? nullcancel : cancelTask); // 1. Get and parse the constrained DMR and Data v-a-v URL this.dsp = dspregistry.findMatchingDSP(location, cxt); // will set dsp context if (this.dsp == null) throw new IOException("No matching DSP: " + this.location); this.dsp.setContext(cxt); this.dsp.open(this.dsplocation); // 2. Construct an equivalent CDM tree and populate // this NetcdfFile object. CDMCompiler compiler = new CDMCompiler(this, this.dsp); compiler.compile(); // set the pseudo-location, otherwise we get a name that is full path. setLocation(this.dsp.getDMR().getDataset().getShortName()); finish(); this.arraymap = compiler.getArrayMap(); }
Example #20
Source File: PartitionCollectionImmutable.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public FileCacheable open(DatasetUrl durl, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException { try (RandomAccessFile raf = RandomAccessFile.acquire(durl.trueurl)) { Partition p = (Partition) iospMessage; return GribCdmIndex.openGribCollectionFromIndexFile(raf, p.getConfig(), p.getLogger()); // do we know its a // partition ? } catch (Throwable t) { RandomAccessFile.eject(durl.trueurl); throw t; } }
Example #21
Source File: CatalogCrawler.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Constructor. * * @param type CatalogCrawler.Type * @param max if > 0, only process max datasets, then exit (random_direct_max only) * @param filter dont process this dataset or its descendants. may be null * @param listen each dataset gets passed to the listener. if null, send the dataset name to standard out * @param task user can cancel the task (may be null) * @param out send status messages to here (may be null) * @param context caller can pass this object to Listener (eg used for thread safety) */ public CatalogCrawler(Type type, int max, Filter filter, Listener listen, CancelTask task, PrintWriter out, Object context) { this.type = type == null ? Type.all : type; this.max = max; this.filter = filter; this.listen = listen; this.task = task; this.out = out; this.context = context; if (type == Type.random_direct || type == Type.random_direct_middle || type == Type.random_direct_max) this.random = new Random(System.currentTimeMillis()); }
Example #22
Source File: NsslRadarMosaicConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void augment3D(NetcdfDataset ds, CancelTask cancelTask) { ds.addAttribute(null, new Attribute(CDM.CONVENTIONS, "NSSL National Reflectivity Mosaic")); addLongName(ds, "mrefl_mosaic", "3-D reflectivity mosaic grid"); addCoordinateAxisType(ds, "Height", AxisType.Height); addCoordSystem(ds); Variable var = ds.findVariable("mrefl_mosaic"); assert var != null; float scale_factor = Float.NaN; Attribute att = var.attributes().findAttributeIgnoreCase("Scale"); if (att != null) { scale_factor = att.getNumericValue().floatValue(); var.addAttribute(new Attribute(CDM.SCALE_FACTOR, 1.0f / scale_factor)); } att = ds.findGlobalAttributeIgnoreCase("MissingData"); if (null != att) { float val = att.getNumericValue().floatValue(); if (!Float.isNaN(scale_factor)) val *= scale_factor; var.addAttribute(new Attribute(CDM.MISSING_VALUE, (short) val)); } // hack Array missingData = Array.factory(DataType.SHORT, new int[] {2}, new short[] {-990, -9990}); var.addAttribute(new Attribute(CDM.MISSING_VALUE, missingData)); var.addAttribute(new Attribute(_Coordinate.Axes, "Height Lat Lon")); }
Example #23
Source File: VariableDS.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { // see if its really a full read if ((null == section) || section.computeSize() == getSize()) return reallyRead(client, cancelTask); if (orgVar == null) return getMissingDataArray(section.getShape()); return orgVar.read(section); }
Example #24
Source File: ReduceReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { Section.Builder orgSection = Section.builder().appendRanges(section.getRanges()); for (int dim : dims) { orgSection.insertRange(dim, Range.ONE); // lowest first } Array data = orgClient._read(orgSection.build()); for (int i = dims.size() - 1; i >= 0; i--) data = data.reduce(dims.get(i)); // highest first return data; }
Example #25
Source File: FileCacheGuava.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public FileCacheable acquire(FileFactory factory, Object hashKey, DatasetUrl durl, int buffer_size, CancelTask cancelTask, Object spiObject) { if (null == hashKey) hashKey = durl.trueurl; if (null == hashKey) throw new IllegalArgumentException(); try { // If the key wasn't in the "easy to compute" group, we need to use the factory. return cache.get((String) hashKey, () -> factory.open(durl, buffer_size, cancelTask, spiObject)); } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } }
Example #26
Source File: N3iospNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), 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(); header.read(raf, rootGroup, null); }
Example #27
Source File: SequenceObsDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public List getData(CancelTask cancel) throws IOException { ArrayList allData = new ArrayList(); for (int i = 0; i < getDataCount(); i++) { // allData.add( makeObs(i)); if ((cancel != null) && cancel.isCancel()) return null; } return allData; }
Example #28
Source File: FmrcDataset.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Array reallyRead(Variable mainv, CancelTask cancelTask) throws IOException { try { return reallyRead(mainv, mainv.getShapeAsSection(), cancelTask); } catch (InvalidRangeException e) { throw new IOException(e); } }
Example #29
Source File: GtopoIosp.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #30
Source File: HdfEosModisConvention.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) { addTimeCoord = addTimeCoordinate(ds); augmentGroup(ds, ds.getRootGroup()); ds.addAttribute(ds.getRootGroup(), new Attribute(CDM.CONVENTIONS, "CF-1.0")); ds.finish(); }