Beispiel #1
0
  public void setDataset(InvDataset ds) {
    if (ds == null) return;

    OpenDatasetTask openTask = new OpenDatasetTask(ds);
    ProgressMonitor pm = new ProgressMonitor(openTask);
    pm.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("success")) {
              controller.showDataset();
              gridTable.setDataset(controller.getFields());
              datasetNameLabel.setText("Dataset:  " + controller.getDatasetUrlString());
              setSelected(true);
              gtWindow.hide();
            }
          }
        });
    pm.start(this, "Open Dataset " + ds.getName(), 100);
  }
  /**
   * 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;
  }
  public ThreddsDataFactory.Result openFeatureDataset(
      FeatureType wantFeatureType,
      InvDataset invDataset,
      ucar.nc2.util.CancelTask task,
      Result result)
      throws IOException {

    result.featureType = invDataset.getDataType();
    if (result.featureType == null) result.featureType = wantFeatureType;

    // look for remote FeatureDataset
    if ((result.featureType != null) && result.featureType.isPointFeatureType()) {
      InvAccess access = findAccessByServiceType(invDataset.getAccess(), ServiceType.CdmrFeature);
      if (access != null) return openFeatureDataset(result.featureType, access, task, result);
    }

    // special handling for images
    if (result.featureType == FeatureType.IMAGE) {
      InvAccess access = getImageAccess(invDataset, task, result);
      if (access != null) {
        return openFeatureDataset(result.featureType, access, task, result);
      } else result.fatalError = true;
      return result;
    }

    // special handling for DQC
    InvAccess qc = invDataset.getAccess(ServiceType.QC);
    if (qc != null) {
      String dqc_location = qc.getStandardUrlName();

      if (result.featureType == FeatureType.STATION) {

        /* DqcFactory dqcFactory = new DqcFactory(true);
        QueryCapability dqc = dqcFactory.readXML(dqc_location);
        if (dqc.hasFatalError()) {
          result.errLog.append(dqc.getErrorMessages());
          result.fatalError = true;
        } */

        result.featureDataset =
            null; // LOOK FIX ucar.nc2.thredds.DqcStationObsDataset.factory(invDataset,
                  // dqc_location, result.errLog);
        result.fatalError = (result.featureDataset == null);

      } else {
        result.errLog.format("DQC must be station DQC, dataset = %s %n", invDataset.getName());
        result.fatalError = true;
      }

      return result;
    }

    NetcdfDataset ncd = openDataset(invDataset, true, task, result.errLog);
    if (null != ncd)
      result.featureDataset =
          FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog);

    if (null == result.featureDataset) result.fatalError = true;
    else {
      result.location = result.featureDataset.getLocation();
      if ((result.featureType == null) && (result.featureDataset != null))
        result.featureType = result.featureDataset.getFeatureType();
    }

    return result;
  }
Beispiel #5
0
  public void read(String src) {
    //		addXML ax = new addXML();
    InvCatalogFactory factory = new InvCatalogFactory("default", false);
    InvCatalog catalog = (InvCatalog) factory.readXML(src);
    StringBuilder buff = new StringBuilder();
    int count = catalog.getDatasets().size();
    if (!catalog.check(buff, true)) {
      log.error("Invalid catalog <" + src + ">\n" + buff.toString());
    } else {

      for (int index = 0; index < count; index++) {
        factory = new InvCatalogFactory("default", false);
        catalog = (InvCatalog) factory.readXML(src);
        InvDataset invDataset = catalog.getDatasets().get(index);
        System.out.println(invDataset.getName());
        String file = "/home/rhs/NCAR/las_categories_";
        try {
          file = file + JDOMUtils.MD5Encode(invDataset.getName()) + ".xml";
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        Element las_categories = new Element("las_categories");

        //				CategoryBean cb = new CategoryBean();
        //				cb.setName(invDataset.getName());
        //				cb.setID(invDataset.getID());
        //				// This is the top level...
        //				//cb.setContributors(getContributors(invDataset));
        //				Vector topCats = new Vector();
        for (Iterator topLevelIt = invDataset.getDatasets().iterator(); topLevelIt.hasNext(); ) {
          InvDataset topDS = (InvDataset) topLevelIt.next();
          //					CategoryBean topCB = new CategoryBean();
          //					topCB.setName(topDS.getName());
          String id = topDS.getID();
          if (id == null) {
            try {
              id = "id_" + JDOMUtils.MD5Encode(topDS.getName());
            } catch (UnsupportedEncodingException e) {
              id = "id_" + String.valueOf(Math.random());
            }
          }
          System.out.println("top: " + topDS.getName() + ", " + topDS.getID());
          // topCB.setID(id);

          //					for (Iterator subDatasetsIt = topDS.getDatasets().iterator();
          // subDatasetsIt.hasNext(); ) {
          //						InvDataset subDataset = (InvDataset) subDatasetsIt.next();
          //						topCB.addCatID(subDataset.getID());
          //						// These will be the catalog containers that will contain the aggregations...
          //						for (Iterator grandChildrenIt = subDataset.getDatasets().iterator();
          // grandChildrenIt.hasNext(); ) {
          //							InvDataset grandChild = (InvDataset) grandChildrenIt.next();
          //							if ( grandChild.hasAccess() && grandChild.getName().contains("aggregation")) {
          //								// We are done.
          //								String url = null;
          //								InvAccess access = null;
          //								for (Iterator ait = grandChild.getAccess().iterator(); ait.hasNext(); ) {
          //									access = (InvAccess) ait.next();
          //									if (access.getService().getServiceType() == ServiceType.DODS ||
          //											access.getService().getServiceType() == ServiceType.OPENDAP ||
          //											access.getService().getServiceType() == ServiceType.NETCDF) {
          //										url = access.getStandardUrlName();
          //									}
          //								}
          //								if ( url != null && url.contains("aggregation") ){
          //									FilterBean filter = new FilterBean();
          //									filter.setAction("apply-variable");
          //									String tag = grandChild.getID();
          //									filter.setContainstag(tag);
          //									topCB.addFilter(filter);
          //									topCB.addCatID(grandChild.getID());
          //								}
          //							}
          //						}
          //					}
          //					if ( topCB.getFilters().size() > 0 ) {
          //						topCats.add(topCB);
          //					}
        }
        //				if ( topCats.size() > 0 ) {
        //					cb.setCategories(topCats);
        //				}
        //				las_categories.addContent(cb.toXml());

        //				ax.processESGCategories(invDataset, las_categories);
        //				LASDocument document = new LASDocument();
        //				document.setRootElement(las_categories);
        //				System.out.println("Writing "+file+" for "+invDataset.getName());
        //				document.write(file);
        //				document = null;
      }
    }
  }
Beispiel #6
0
 /**
  * Find an immediate child dataset by its name.
  *
  * @param name match on this name
  * @return dataset if found or null if not exist.
  */
 public InvDatasetImpl findDatasetByName(String name) {
   for (InvDataset ds : getDatasets()) {
     if (ds.getName().equals(name)) return (InvDatasetImpl) ds;
   }
   return null;
 }