static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog); if (isGrid(ncd.getCoordinateSystems())) { ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset(ncd); if (gds.getGrids().size() > 0) { FeatureDatasetFactory useFactory = null; for (Factory fac : factoryList) { if (!featureTypeOk(null, fac.featureType)) continue; if (debug) System.out.println(" wrapUnknown try factory " + fac.factory.getClass().getName());
public static FeatureDataset open(String location) throws IOException { return open(null, location, null, new Formatter()); }
/** * Register a class that implements a FeatureDatasetFactory. * * @param className name of class that implements FeatureDatasetFactory. * @throws ClassNotFoundException if loading error */ static public void registerFactory(String className) throws ClassNotFoundException { Class c = Class.forName(className); registerFactory(c); }
static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog);
return wrapUnknown(ncd, task, errlog); FeatureDatasetFactory useFactory = null; for (Factory fac : factoryList) { if (!featureTypeOk(wantFeatureType, fac.featureType)) continue; if (debug) System.out.println(" wrap try factory " + fac.factory.getClass().getName());
/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
ThreddsDataFactory.Result result = new ThreddsDataFactory().openFeatureDataset(wantFeatureType, location, task); errlog.format("%s", result.errLog); if (!featureTypeOk(wantFeatureType, result.featureType)) { errlog.format("wanted %s but dataset is of type %s%n", wantFeatureType, result.featureType); return null; return wrap(wantFeatureType, ncd, task, errlog);
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) { // find datatype FeatureType featureType = FeatureDatasetFactoryManager.findFeatureType( ds); if (featureType != FeatureType.STATION_PROFILE) return false; String conv = ds.findAttValueIgnoreCase(null, CDM.CONVENTIONS, null); if (conv == null) return false; StringTokenizer stoke = new StringTokenizer(conv, ","); while (stoke.hasMoreTokens()) { String toke = stoke.nextToken().trim(); if (toke.equalsIgnoreCase("Unidata Point Feature v1.0")) return true; } return false; }
public boolean featureTypeOk(FeatureType ftype, Formatter errlog) { for (NestedTable nt : leaves) { if (!nt.hasCoords()) errlog.format("Table %s featureType %s: lat/lon/time coord not found%n", nt.getName(), nt.getFeatureType()); if (!FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) errlog.format("Table %s featureType %s doesnt match desired type %s%n", nt.getName(), nt.getFeatureType(), ftype); if (nt.hasCoords() && FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) return true; } return false; }
/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
setCoordMap(); ftFromMetadata = FeatureDatasetFactoryManager.findFeatureType(ds); FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog); info.append("FeatureDatasetFactoryManager errlog = "); info.append(errlog.toString());
ThreddsDataFactory.Result result = new ThreddsDataFactory().openFeatureDataset(wantFeatureType, location, task); errlog.format("%s", result.errLog); if (!featureTypeOk(wantFeatureType, result.featureType)) { errlog.format("wanted %s but dataset is of type %s%n", wantFeatureType, result.featureType); return null; FeatureDataset result = wrap(wantFeatureType, ncd, task, errlog); if (result == null) ncd.close();
return wrapUnknown(ncd, task, errlog); FeatureDatasetFactory useFactory = null; for (Factory fac : factoryList) { if (!featureTypeOk(wantFeatureType, fac.featureType)) continue; if (debug) System.out.println(" wrap try factory " + fac.factory.getClass().getName());
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) { // find datatype FeatureType featureType = FeatureDatasetFactoryManager.findFeatureType( ds); if (featureType != FeatureType.STATION_PROFILE) return false; String conv = ds.findAttValueIgnoreCase(null, CDM.CONVENTIONS, null); if (conv == null) return false; StringTokenizer stoke = new StringTokenizer(conv, ","); while (stoke.hasMoreTokens()) { String toke = stoke.nextToken().trim(); if (toke.equalsIgnoreCase("Unidata Point Feature v1.0")) return true; } return false; }
public boolean featureTypeOk(FeatureType ftype, Formatter errlog) { for (NestedTable nt : leaves) { if (!nt.hasCoords()) errlog.format("Table %s featureType %s: lat/lon/time coord not found%n", nt.getName(), nt.getFeatureType()); if (!FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) errlog.format("Table %s featureType %s doesnt match desired type %s%n", nt.getName(), nt.getFeatureType(), ftype); if (nt.hasCoords() && FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) return true; } return false; }
public static void main(String[] args) throws IOException { String server = "http://thredds.ucar.edu/"; String dataset = "/thredds/dodsC/fmrc/NCEP/GFS/Global_0p5deg/runs/NCEP-GFS-Global_0p5deg_RUN_2009-05-13T12:00:00Z"; String testFile = "Q:/cdmUnitTest/formats/hdf4/MOD021KM.A2004328.1735.004.2004329164007.hdf"; Formatter errlog = new Formatter(); FeatureDataset fd = null; //FeatureDataset fd = FeatureDatasetFactoryManager.open( FeatureType.ANY, testFile, null, errlog ); //System.out.printf("ANY = %s%n", fd); if (fd == null) { fd = FeatureDatasetFactoryManager.open( FeatureType.SWATH, testFile, null, errlog ); System.out.printf("Swath = %s%n", fd); } if (fd == null) { fd = FeatureDatasetFactoryManager.open( FeatureType.GRID, testFile, null, errlog ); System.out.printf("Grid = %s%n", fd); } }
/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog); if (isGrid(ncd.getCoordinateSystems())) { ucar.nc2.dt.grid.GridDataset gds = new ucar.nc2.dt.grid.GridDataset(ncd); if (gds.getGrids().size() > 0) { FeatureDatasetFactory useFactory = null; for (Factory fac : factoryList) { if (!featureTypeOk(null, fac.featureType)) continue; if (debug) System.out.println(" wrapUnknown try factory " + fac.factory.getClass().getName());
info.append(errlog.toString()); ftFromMetadata = FeatureDatasetFactoryManager.findFeatureType(ds); FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog); info.append("FeatureDatasetFactoryManager errlog = "); info.append(errlog.toString());
DataFactory.Result result = new DataFactory().openFeatureDataset(wantFeatureType, location, task); errlog.format("%s", result.errLog); if (!featureTypeOk(wantFeatureType, result.featureType)) { errlog.format("wanted %s but dataset is of type %s%n", wantFeatureType, result.featureType); result.close(); FeatureDataset fd = wrap(wantFeatureType, ncd, task, errlog); if (fd == null) ncd.close();