/** * Add information from the InvDataset to the NetcdfDataset. * * @param ds get info from here * @param ncDataset add to here */ public static void annotate(InvDataset ds, NetcdfDataset ncDataset) { ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getID()); // add properties as global attributes for (InvProperty p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) { ncDataset.addAttribute(null, new Attribute(name, p.getValue())); } } /* ThreddsMetadata.GeospatialCoverage geoCoverage = ds.getGeospatialCoverage(); if (geoCoverage != null) { if ( null != geoCoverage.getNorthSouthRange()) { ncDataset.addAttribute(null, new Attribute("geospatial_lat_min", new Double(geoCoverage.getLatSouth()))); ncDataset.addAttribute(null, new Attribute("geospatial_lat_max", new Double(geoCoverage.getLatNorth()))); } if ( null != geoCoverage.getEastWestRange()) { ncDataset.addAttribute(null, new Attribute("geospatial_lon_min", new Double(geoCoverage.getLonWest()))); ncDataset.addAttribute(null, new Attribute("geospatial_lon_max", new Double(geoCoverage.getLonEast()))); } if ( null != geoCoverage.getUpDownRange()) { ncDataset.addAttribute(null, new Attribute("geospatial_vertical_min", new Double(geoCoverage.getHeightStart()))); ncDataset.addAttribute(null, new Attribute("geospatial_vertical_max", new Double(geoCoverage.getHeightStart() + geoCoverage.getHeightExtent()))); } } DateRange timeCoverage = ds.getTimeCoverage(); if (timeCoverage != null) { ncDataset.addAttribute(null, new Attribute("time_coverage_start", timeCoverage.getStart().toDateTimeStringISO())); ncDataset.addAttribute(null, new Attribute("time_coverage_end", timeCoverage.getEnd().toDateTimeStringISO())); } */ ncDataset.finish(); }
private NetcdfDataset openDataset( InvAccess access, boolean acquire, ucar.nc2.util.CancelTask task, Result result) throws IOException { InvDataset invDataset = access.getDataset(); String datasetId = invDataset.getID(); String title = invDataset.getName(); String datasetLocation = access.getStandardUrlName(); ServiceType serviceType = access.getService().getServiceType(); if (debugOpen) System.out.println("ThreddsDataset.openDataset= " + datasetLocation); // deal with RESOLVER type if (serviceType == ServiceType.RESOLVER) { InvDatasetImpl rds = openResolver(datasetLocation, task, result); if (rds == null) return null; return openDataset(rds, acquire, task, result); } // ready to open it through netcdf API NetcdfDataset ds; // open DODS type if ((serviceType == ServiceType.OPENDAP) || (serviceType == ServiceType.DODS)) { String curl = DODSNetcdfFile.canonicalURL(datasetLocation); ds = acquire ? NetcdfDataset.acquireDataset(curl, enhanceMode, task) : NetcdfDataset.openDataset(curl, enhanceMode, task); } // open CdmRemote else if (serviceType == ServiceType.CdmRemote) { String curl = CdmRemote.canonicalURL(datasetLocation); ds = acquire ? NetcdfDataset.acquireDataset(curl, enhanceMode, task) : NetcdfDataset.openDataset(curl, enhanceMode, task); } /* open ADDE type else if (serviceType == ServiceType.ADDE) { try { ds = ucar.nc2.adde.AddeDatasetFactory.openDataset(access, task); } catch (IOException e) { log.append("Cant open as ADDE dataset= "+datasetLocation); accessList.remove( access); continue; } } */ else { // open through NetcdfDataset API ds = acquire ? NetcdfDataset.acquireDataset(datasetLocation, enhanceMode, task) : NetcdfDataset.openDataset(datasetLocation, enhanceMode, task); } if (ds != null) { ds.setId(datasetId); ds.setTitle(title); annotate(invDataset, ds); } // see if there's metadata LOOK whats this List list = invDataset.getMetadata(MetadataType.NcML); if (list.size() > 0) { InvMetadata ncmlMetadata = (InvMetadata) list.get(0); NcMLReader.wrapNcML(ds, ncmlMetadata.getXlinkHref(), null); } result.accessUsed = access; return ds; }