public TestDatasetWrapP(String filename) { durl = new DatasetUrl(null, filename); }
public GribCollectionImmutable getGribCollection() throws IOException { String path = getIndexFilenameInCache(); if (path == null) { if (Grib.debugIndexOnly) { // we are running in debug mode where we only have the indices, not the data files // tricky: substitute the current root File orgParentDir = new File(directory); File currentFile = new File(PartitionCollectionMutable.this.indexFilename); File currentParent = currentFile.getParentFile(); File currentParentWithDir = new File(currentParent, orgParentDir.getName()); File nestedIndex = isPartitionOfPartitions ? new File(currentParentWithDir, filename) : new File(currentParent, filename); // JMJ path = nestedIndex.getPath(); } else { throw new FileNotFoundException("No index filename for partition= "+this.toString()); } } // LOOK not cached return (GribCollectionImmutable) PartitionCollectionImmutable.partitionCollectionFactory.open(new DatasetUrl(null, path), -1, null, this); }
static public GribCollectionImmutable acquireGribCollection(FileFactory factory, Object hashKey, String location, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException { FileCacheable result; DatasetUrl durl = new DatasetUrl(null, location); if (gribCollectionCache != null) { // FileFactory factory, Object hashKey, String location, int buffer_size, CancelTask cancelTask, Object spiObject result = GribCdmIndex.gribCollectionCache.acquire(factory, hashKey, durl, buffer_size, cancelTask, spiObject); } else { // String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object iospMessage result = factory.open(durl, buffer_size, cancelTask, spiObject); } return (GribCollectionImmutable) result; }
static public RandomAccessFile acquire(String location, int buffer_size) throws IOException { if (cache == null) return new RandomAccessFile(location, "r", buffer_size); else return (RandomAccessFile) cache.acquire(factory, location, new DatasetUrl(null, location), buffer_size, null, null); }
static public RandomAccessFile acquire(String location) throws IOException { if (cache == null) return new RandomAccessFile(location, "r"); else return (RandomAccessFile) cache.acquire(factory, new DatasetUrl(null, location)); }
/** * Open a file, keep track of open files * @param location open this location * @param openFiles keep track of open files * @return file or null if not found */ private NetcdfDataset open(String location, Map<String, NetcdfDataset> openFiles) throws IOException { NetcdfDataset ncd; if (openFiles != null) { ncd = openFiles.get(location); if (ncd != null) return ncd; } if (config.innerNcml == null) { ncd = NetcdfDataset.acquireDataset(new DatasetUrl(null, location), true, null); // default enhance } else { NetcdfFile nc = NetcdfDataset.acquireFile(new DatasetUrl(null, location), null); ncd = NcMLReader.mergeNcML(nc, config.innerNcml); // create new dataset ncd.enhance(); // now that the ncml is added, enhance "in place", ie modify the NetcdfDataset } if (openFiles != null && ncd != null) { openFiles.put(location, ncd); } return ncd; }
static private NetcdfFile acquireDODS(FileCache cache, FileFactory factory, Object hashKey, String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { if (cache == null) { return openDodsByReflection(location, cancelTask); } if (factory == null) factory = new DodsFactory(); return (NetcdfFile) cache.acquire(factory, hashKey, new DatasetUrl(ServiceType.OPENDAP, location), buffer_size, cancelTask, spiObject); }
static private NetcdfFile acquireCdmRemote(FileCache cache, FileFactory factory, Object hashKey, String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { if (cache == null) return new CdmRemote(location); if (factory == null) factory = new RemoteFactory(); return (NetcdfFile) cache.acquire(factory, hashKey, new DatasetUrl(ServiceType.CdmRemote, location), buffer_size, cancelTask, spiObject); }
public FileCacheable call() throws Exception { DatasetUrl durl = new DatasetUrl(null, location); return cache.acquire(factory, durl); } }
static private NetcdfFile acquireDap4(FileCache cache, FileFactory factory, Object hashKey, String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { if (cache == null) { return openDap4ByReflection(location, cancelTask); } if (factory == null) factory = new Dap4Factory(); return (NetcdfFile) cache.acquire(factory, hashKey, new DatasetUrl(ServiceType.DAP4, location), buffer_size, cancelTask, spiObject); }
return new DatasetUrl(svctype, trueurl);
void loadFilesIntoCache(File dir, FileCache cache) { File[] files = dir.listFiles(); if ( files == null) return; for (File f : files) { if (f.isDirectory()) loadFilesIntoCache(f, cache); else if (f.getPath().endsWith(".nc") && f.length() > 0) { //System.out.println(" open "+f.getPath()); try { String want = StringUtil2.replace(f.getPath(), '\\', "/"); DatasetUrl durl = new DatasetUrl(null, want); cache.acquire(factory, durl); count++; } catch (IOException e) { // e.printStackTrace(); System.out.println(" *** failed on " + f.getPath()); } } } }
public void run() { try { DatasetUrl durl = new DatasetUrl(null, location); FileCacheable fc = cache.acquire(factory, durl); NetcdfFile ncfile = (NetcdfFile) fc; //assert ncfile.isLocked(); assert (null != ncfile.getIosp()); Thread.sleep(wait); ncfile.close(); int d = done.incrementAndGet(); if (d % PRINT_EVERY == 0) System.out.printf(" done %d%n", d); } catch (InterruptedException e) { System.out.println(" InterruptedException="+e.getMessage()); } catch (Throwable e) { System.out.println(" fail="+e.getMessage()); e.printStackTrace(); assert false; } } }
private void doOne(String filename) throws Exception { try (NetcdfFile ncfile = NetcdfDataset.acquireFile(new DatasetUrl(null, filename), null); NetcdfDataset ncWrap = new NetcdfDataset(ncfile, true)) { NetcdfDataset ncd = NetcdfDataset.acquireDataset(new DatasetUrl(null, filename), true , null); System.out.println(" dataset wraps= " + filename); ucar.unidata.util.test.CompareNetcdf.compareFiles(ncd, ncWrap); ncd.close(); ncWrap.close(); } }
NetcdfFile nc = NetcdfDataset.acquireFile(new DatasetUrl(null, mfile.getPath()), null);
@Test public void testRemove() throws IOException, InvalidRangeException { String inName = TestDir.cdmLocalTestDataDir + "testWrite.nc"; String outName = tempFolder.newFile().getAbsolutePath(); DatasetUrl durl = new DatasetUrl(null, inName); try (NetcdfDataset ncd = NetcdfDataset.acquireDataset(durl, true, null)) { assert ncd.removeVariable(null, "temperature"); ncd.finish(); FileWriter2 writer = new FileWriter2(ncd, outName, NetcdfFileWriter.Version.netcdf3, null); try (NetcdfFile ncdnew = writer.write()) { // ok empty } } DatasetUrl durl2 = new DatasetUrl(null, outName); try (NetcdfDataset ncdnew2 = NetcdfDataset.acquireDataset(durl2, true, null)) { assert ncdnew2.findVariable("temperature") == null; } }
@Test public void testEnhanceDefer() throws IOException { DatasetUrl durl = new DatasetUrl(null, filename);
DatasetUrl durl = new DatasetUrl(serviceType, datasetLocation); NetcdfDataset ncd = acquire ? NetcdfDataset.acquireDataset(durl, true, task) : NetcdfDataset.openDataset(durl, null, -1, task, null);
public void testDatasetAddRecord() throws InvalidRangeException, IOException { String location = TestDir.cdmLocalTestDataDir + "testWriteRecord.nc"; DatasetUrl durl = new DatasetUrl(null, location); NetcdfDataset nc = NetcdfDataset.openDataset(durl, NetcdfDataset.getDefaultEnhanceMode(), -1, null, NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);