@Test
  public void testGetLeaves() throws Exception {
    Assume.assumeTrue(!GraphicsEnvironment.isHeadless());
    final CatalogTree catalogTree = new CatalogTree(null, new DefaultAppContext(""), null);
    List<InvDataset> datasets = new ArrayList<InvDataset>();
    InvCatalog catalog = new InvCatalogImpl("catalogName", "1.0", new URI("http://x.y"));
    final InvDataset rootDataset = createDataset(catalog, "first", "OPENDAP");
    rootDataset.getDatasets().add(createDataset(catalog, "second", "OPENDAP"));
    rootDataset.getDatasets().add(createDataset(catalog, "third", "OPENDAP"));

    datasets.add(rootDataset);
    catalogTree.setNewRootDatasets(datasets);

    OpendapLeaf[] leaves = catalogTree.getLeaves();
    Arrays.sort(
        leaves,
        new Comparator<OpendapLeaf>() {
          @Override
          public int compare(OpendapLeaf o1, OpendapLeaf o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });
    assertEquals(2, leaves.length);
    assertEquals("second", leaves[0].getName());
    assertEquals("third", leaves[1].getName());
  }
Esempio n. 2
0
  private InvAccess getImageAccess(
      InvDataset invDataset, ucar.nc2.util.CancelTask task, Result result) {

    List<InvAccess> accessList =
        new ArrayList<InvAccess>(invDataset.getAccess()); // a list of all the accesses
    while (accessList.size() > 0) {
      InvAccess access = chooseImageAccess(accessList);
      if (access != null) return access;

      // next choice is resolver type.
      access = invDataset.getAccess(ServiceType.RESOLVER);

      // no valid access
      if (access == null) {
        result.errLog.format("No access that could be used for Image Type %s %n", invDataset);
        return null;
      }

      // deal with RESOLVER type
      String datasetLocation = access.getStandardUrlName();
      InvDatasetImpl rds = openResolver(datasetLocation, task, result);
      if (rds == null) return null;

      // use the access list from the resolved dataset
      accessList = new ArrayList<InvAccess>(invDataset.getAccess());
    } // loop over accesses

    return null;
  }
  public void testSingleDataset() throws IOException {
    InvCatalogImpl cat = TestTDSAll.open(null);

    InvDataset ds = cat.findDatasetByID("testSingleDataset");
    assert (ds != null) : "cant find dataset 'testSingleDataset'";
    assert ds.getDataType() == FeatureType.GRID;

    ThreddsDataFactory fac = new ThreddsDataFactory();

    ThreddsDataFactory.Result dataResult = fac.openFeatureDataset(ds, null);

    assert dataResult != null;
    assert !dataResult.fatalError;
    assert dataResult.featureDataset != null;

    GridDataset gds = (GridDataset) dataResult.featureDataset;
    GridDatatype grid = gds.findGridDatatype("Z_sfc");
    assert grid != null;
    GridCoordSystem gcs = grid.getCoordinateSystem();
    assert gcs != null;
    assert null == gcs.getVerticalAxis();

    CoordinateAxis1D time = gcs.getTimeAxis1D();
    assert time != null;
    assert time.getSize() == 1;
    assert 102840.0 == time.readScalarDouble();

    dataResult.featureDataset.close();
  }
Esempio n. 4
0
 /**
  * Get the full, heirarchical name of the dataset, which has all parent collection names.
  *
  * @return full, heirarchical name of the dataset, which has all parent collection names.
  */
 public String getFullName() {
   return (parent == null)
       ? name
       : (parent.getFullName() == null || parent.getFullName().length() == 0)
           ? name
           : parent.getFullName() + "/" + name;
 }
Esempio n. 5
0
  public void init() throws ServletException {
    super.init();
    // allow = ThreddsConfig.getBoolean("NetcdfSubsetService.allow", true);
    // String radarLevel2Dir = ThreddsConfig.get("NetcdfSubsetService.radarLevel2DataDir",
    // "/data/ldm/pub/native/radar/level2/");
    // if (!allow) return;
    contentPath = ServletUtil.getContentPath();
    rm = new RadarMethods(contentPath, logServerStartup);

    // read in radarCollections.xml catalog
    InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false); // no validation
    cat = readCatalog(factory, getPath() + catName, contentPath + getPath() + catName);
    if (cat == null) {
      logServerStartup.info("cat initialization failed");
      return;
    }
    // URI tmpURI = cat.getBaseURI();
    cat.setBaseURI(catURI);
    // get path and location from cat
    List parents = cat.getDatasets();
    for (int i = 0; i < parents.size(); i++) {
      InvDataset top = (InvDataset) parents.get(i);
      datasets = top.getDatasets(); // dataset scans

      for (int j = 0; j < datasets.size(); j++) {
        InvDatasetScan ds = (InvDatasetScan) datasets.get(j);
        if (ds.getPath() != null) {
          dataLocation.put(ds.getPath(), ds.getScanLocation());
          logServerStartup.info("path =" + ds.getPath() + " location =" + ds.getScanLocation());
        }
        ds.setXlinkHref(ds.getPath() + "/dataset.xml");
      }
    }
    logServerStartup.info(getClass().getName() + " initialization complete ");
  } // end init
  /**
   * Getting invDataset list for a single radar station.
   *
   * @param stnName radar station name
   * @param start of the time
   * @param end of the time
   * @return list of invDataset
   * @throws IOException java io exception
   */
  private DqcRadarDatasetInfo queryRadarStation(String stnName, Date start, Date end)
      throws IOException {
    // http://motherlode.ucar.edu:9080/thredds/idd/radarLevel2?returns=catalog&stn=KFTG&dtime=latest
    StringBuffer queryb = new StringBuffer();

    queryb.append(dqc.getQuery().getUriResolved().toString());
    queryb.append("serviceType=OPENDAP");
    queryb.append("&stn=" + stnName);
    if ((start == null) && (end == null)) {
      queryb.append("&dtime=all");
    } else {
      String stime = DateUtil.getTimeAsISO8601(start);
      String etime = DateUtil.getTimeAsISO8601(end);
      queryb.append("&dateStart=" + stime);
      queryb.append("&dateEnd=" + etime);
    }

    URI catalogURI;
    try {
      catalogURI = new URI(queryb.toString());
    } catch (java.net.URISyntaxException e) {
      throw new IOException("** MalformedURLException on URL <" + ">\n" + e.getMessage() + "\n");
    }

    InvCatalogFactory factory = new InvCatalogFactory("default", false);

    InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML(catalogURI);
    StringBuilder buff = new StringBuilder();
    if (!catalog.check(buff)) {
      throw new IOException("Invalid catalog <" + catalogURI + ">\n" + buff.toString());
    }

    List datasets = catalog.getDatasets();

    InvDataset idata = (InvDataset) datasets.get(0);
    //    List ddate = idata.getDates();

    ArrayList dsets = (ArrayList) idata.getDatasets();

    ArrayList absTimeList = new ArrayList();
    ArrayList dURIList = new ArrayList();
    ArrayList dInvList = new ArrayList();

    for (int i = 0; i < dsets.size(); i++) {
      InvDataset tdata = (InvDataset) dsets.get(i);
      List acess = tdata.getAccess();
      List dates = tdata.getDates();
      InvAccess ia = (InvAccess) acess.get(0);
      URI d = ia.getStandardUri();
      Date date = DateUnit.getStandardOrISO(dates.get(0).toString());
      absTimeList.add(date);
      dURIList.add(new DatasetURIInfo(d, date));
      dInvList.add(new InvDatasetInfo(tdata, date));
    }

    DqcRadarDatasetInfo dri = new DqcRadarDatasetInfo(absTimeList, dURIList, dInvList);

    return dri;
  }
Esempio n. 7
0
  /**
   * Open a FeatureDataset from an InvAccess object.
   *
   * @param access use this InvAccess.
   * @param task may be null
   * @return ThreddsDataFactory.Result check fatalError for validity
   * @throws IOException on read error
   */
  public ThreddsDataFactory.Result openFeatureDataset(
      InvAccess access, ucar.nc2.util.CancelTask task) throws IOException {
    InvDataset invDataset = access.getDataset();
    ThreddsDataFactory.Result result = new Result();
    if (invDataset.getDataType() == null) {
      result.errLog.format("InvDatasert must specify a FeatureType%n");
      result.fatalError = true;
      return result;
    }

    return openFeatureDataset(invDataset.getDataType(), access, task, result);
  }
  /**
   * Getting URI for a single radar station.
   *
   * @param stnName radar station name
   * @param absTime is absolute time
   * @return URI
   * @throws IOException java io exception
   */
  public URI getRadarDatasetURI(String stnName, Date absTime) throws IOException {
    // absTime is a member of  datasetsDateURI
    InvDataset invdata = queryRadarStation(stnName, absTime);
    List<InvAccess> acess = invdata.getAccess();
    InvAccess ia = (InvAccess) acess.get(0);
    URI ui = ia.getStandardUri();

    if (ui == null) {
      throw new IOException("Invalid time selected: " + absTime.toString() + "\n");
    }

    return ui;
  }
  /**
   * Getting URI for a single radar station.
   *
   * @param stnName radar station name
   * @param productID _more_
   * @param absTime is absolute time
   * @return InvDataset
   * @throws IOException java io exception
   */
  private InvDataset queryRadarStation(String stnName, String productID, Date absTime)
      throws IOException {
    String stime = DateUtil.getTimeAsISO8601(absTime).replaceAll("GMT", "");
    // construct a query like this:
    // http://motherlode.ucar.edu:9080/thredds/idd/radarLevel2?returns=catalog&stn=KFTG&dtime=latest
    StringBuilder queryb = new StringBuilder();
    String baseURI = dsc_location.replaceFirst("/dataset.xml", "?");
    queryb.append(baseURI);
    queryb.append("&stn=" + stnName);
    if (productID != null) {
      queryb.append("&var=" + productID);
    }
    if (absTime == null) {
      queryb.append("&time=present");
    } else {

      queryb.append("&time=" + stime);
    }

    URI catalogURI;

    try {
      catalogURI = new URI(queryb.toString());
    } catch (java.net.URISyntaxException e) {
      throw new IOException("** MalformedURLException on URL <" + ">\n" + e.getMessage() + "\n");
    }

    InvCatalogFactory factory = new InvCatalogFactory("default", false);
    // visad.util.Trace.call1("TDSRadarDatasetCollection.readXML");

    InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML(catalogURI);

    // visad.util.Trace.call2("TDSRadarDatasetCollection.readXML");
    // visad.util.Trace.call1("TDSRadarDatasetCollection.checkCatalog");
    StringBuilder buff = new StringBuilder();
    if (!catalog.check(buff)) {
      throw new IOException("Invalid catalog <" + catalogURI + ">\n" + buff.toString());
    }
    // visad.util.Trace.call2("TDSRadarDatasetCollection.checkCatalog");
    // catalog.writeXML(System.out);  // debugg

    List<InvDataset> datasets = catalog.getDatasets();

    InvDataset idata = (InvDataset) datasets.get(0);
    List<InvDataset> dsets = idata.getDatasets();
    InvDataset tdata = (InvDataset) dsets.get(0);
    return tdata;
  }
Esempio n. 10
0
  /**
   * Return the resource control value which indicates that only users with proper permission can
   * access this resource.
   *
   * <p>??? Not sure if the value indicates anything or just set or not set.
   *
   * @return the resource control value for this dataset (inherited from ancestor datasets).
   */
  public String getRestrictAccess() {
    if (restrictAccess != null) return restrictAccess;
    // not found, look in parent
    if (parent != null) return parent.getRestrictAccess();

    return null;
  }
Esempio n. 11
0
  /**
   * tds radar dataset collection factory
   *
   * @param ds _more_
   * @param dsc_location _more_
   * @param errlog _more_
   * @return any foctory
   * @throws IOException _more_
   * @throws java.net.URISyntaxException _more_
   */
  public static TDSRadarDatasetCollection factory(
      InvDataset ds, String dsc_location, StringBuffer errlog)
      throws IOException, java.net.URISyntaxException {

    // URI catalogURI = new URI(dsc_location);
    // this.docURI =    catalogURI;
    return factory(ds.getDocumentation("summary"), dsc_location, errlog);
  }
Esempio n. 12
0
  private NetcdfDataset openDataset(
      InvDataset invDataset, boolean acquire, ucar.nc2.util.CancelTask task, Result result)
      throws IOException {

    IOException saveException = null;

    List<InvAccess> accessList =
        new ArrayList<InvAccess>(invDataset.getAccess()); // a list of all the accesses
    while (accessList.size() > 0) {
      InvAccess access = chooseDatasetAccess(accessList);

      // no valid access
      if (access == null) {
        result.errLog.format("No access that could be used in dataset %s %n", invDataset);
        if (saveException != null) throw saveException;
        return null;
      }

      String datasetLocation = access.getStandardUrlName();
      ServiceType serviceType = access.getService().getServiceType();
      if (debugOpen)
        System.out.println("ThreddsDataset.openDataset try " + datasetLocation + " " + serviceType);

      // deal with RESOLVER type
      if (serviceType == ServiceType.RESOLVER) {
        InvDatasetImpl rds = openResolver(datasetLocation, task, result);
        if (rds == null) return null;
        accessList = new ArrayList<InvAccess>(rds.getAccess());
        continue;
      }

      // ready to open it through netcdf API
      NetcdfDataset ds;

      // try to open
      try {
        ds = openDataset(access, acquire, task, result);

      } catch (IOException e) {
        result.errLog.format("Cant open %s %n err=%s%n", datasetLocation, e.getMessage());
        if (debugOpen) {
          System.out.println("Cant open= " + datasetLocation + " " + serviceType);
          e.printStackTrace();
        }

        accessList.remove(access);
        saveException = e;
        continue;
      }

      result.accessUsed = access;
      return ds;
    } // loop over accesses

    if (saveException != null) throw saveException;
    return null;
  }
Esempio n. 13
0
  /**
   * Find the named service declared in this dataset or one of its parents.
   *
   * @param name match this name
   * @return first service that matches the given name, or null if none found.
   */
  public InvService findService(String name) {
    if (name == null) return null;

    // search local (but expanded) services
    for (InvService p : services) {
      if (p.getName().equals(name)) return p;
    }

    // not found, look in parent
    if (parent != null) return parent.findService(name);
    return (catalog == null) ? null : catalog.findService(name);
  }
Esempio n. 14
0
 private InvDatasetImpl openResolver(
     String urlString, ucar.nc2.util.CancelTask task, Result result) {
   InvCatalogFactory catFactory = new InvCatalogFactory("", false);
   InvCatalogImpl catalog = catFactory.readXML(urlString);
   if (catalog == null) {
     result.errLog.format("Couldnt open Resolver %s %n ", urlString);
     return null;
   }
   StringBuilder buff = new StringBuilder();
   if (!catalog.check(buff)) {
     result.errLog.format("Invalid catalog from Resolver <%s>%n%s%n", urlString, buff.toString());
     result.fatalError = true;
     return null;
   }
   InvDataset top = catalog.getDataset();
   if (top.hasAccess()) return (InvDatasetImpl) top;
   else {
     java.util.List datasets = top.getDatasets();
     return (InvDatasetImpl) datasets.get(0);
   }
 }
Esempio n. 15
0
  /**
   * Getting URI for a single radar station.
   *
   * @param stnName radar station name
   * @param absTime is absolute time
   * @return InvDataset
   * @throws IOException java io exception
   */
  private InvDataset queryRadarStation(String stnName, Date absTime) throws IOException {
    String stime = DateUtil.getTimeAsISO8601(absTime);
    // construct a query like this:
    // http://motherlode.ucar.edu:9080/thredds/idd/radarLevel2?returns=catalog&stn=KFTG&dtime=latest
    StringBuffer queryb = new StringBuffer();

    queryb.append(dqc.getQuery().getUriResolved().toString());
    queryb.append("serviceType=OPENDAP");
    queryb.append("&stn=" + stnName);
    queryb.append("&dtime=" + stime);

    URI catalogURI;

    try {
      catalogURI = new URI(queryb.toString());
    } catch (java.net.URISyntaxException e) {
      throw new IOException("** MalformedURLException on URL <" + ">\n" + e.getMessage() + "\n");
    }

    InvCatalogFactory factory = new InvCatalogFactory("default", false);

    InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML(catalogURI);

    StringBuilder buff = new StringBuilder();
    if (!catalog.check(buff)) {
      throw new IOException("Invalid catalog <" + catalogURI + ">\n" + buff.toString());
    }

    List datasets = catalog.getDatasets();

    InvDataset idata = (InvDataset) datasets.get(0);
    ArrayList dsets = (ArrayList) idata.getDatasets();

    InvDataset tdata = (InvDataset) dsets.get(0);
    return tdata;
  }
Esempio n. 16
0
  /**
   * _more_
   *
   * @param stnName _more_
   * @param productID _more_
   * @param absTime _more_
   * @return _more_
   * @throws IOException _more_
   */
  public URI getRadarDatasetURI(String stnName, String productID, Date absTime) throws IOException {
    // absTime is a member of  datasetsDateURI

    if (productID == null) {
      return getRadarDatasetURI(stnName, absTime);
    }

    InvDataset invdata = queryRadarStation(stnName, productID, absTime);
    /*  List dsets = idata.getDatasets();
    int siz = dsets.size();
    if(siz != 1)
        return null;

    InvDataset invdata = (InvDataset)dsets.get(0);     */
    List acess = invdata.getAccess();
    InvAccess ia = (InvAccess) acess.get(0);
    URI ui = ia.getStandardUri();

    if (ui == null) {
      throw new IOException("Invalid time selected: " + absTime.toString() + "\n");
    }

    return ui;
  }
Esempio n. 17
0
  /**
   * 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();
  }
Esempio n. 18
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);
  }
  /**
   * Open an ADDE Station Dataset from an InvAccess, which must be type ADDE and Station.
   *
   * @param access open Invdataset from this access.
   * @throws IOException
   */
  public AddeStationObsDataset(InvAccess access, ucar.nc2.util.CancelTask cancelTask)
      throws IOException {
    super();
    InvDataset invDs = access.getDataset();
    this.location =
        (invDs.getID() != null)
            ? "thredds:" + access.getDataset().getCatalogUrl()
            : access.getStandardUrlName();

    addeURL = access.getStandardUrlName();

    // see if we have a stationDB file
    InvDataset invds = access.getDataset();
    String pv = invds.findProperty("_StationDBlocation");
    if (pv != null) {
      stationDBlocation = InvDatasetImpl.resolve(invds, pv);
    }

    init();

    // Get the bounding box if possible
    ThreddsMetadata.GeospatialCoverage geoCoverage = invds.getGeospatialCoverage();
    if (null != geoCoverage) boundingBox = geoCoverage.getBoundingBox();
    else // otherwise, stationHelper constructs from the station locations
    boundingBox = stationHelper.getBoundingBox();

    // get the date range if possible
    DateRange timeCoverage = invds.getTimeCoverage();
    if (timeCoverage != null) {
      startDate = timeCoverage.getStart().getDate();
      endDate = timeCoverage.getEnd().getDate();
    } else {
      startDate = new Date(0); // fake
      endDate = new Date();
    }

    /*    // LOOK maybe its already annotated ??
    LOOK set title, description
    ThreddsDataFactory.annotate( access.getDataset(), this);
    finish(); */
  }
Esempio n. 20
0
  /**
   * Getting invDataset list for a single radar station.
   *
   * @param stnName radar station name
   * @param productID _more_
   * @param start of the time
   * @param end of the time
   * @return list of invDataset
   * @throws IOException java io exception
   */
  private TDSRadarDatasetInfo queryRadarStation(
      String stnName, String productID, Date start, Date end) throws IOException {
    // http://motherlode.ucar.edu:9080/thredds/idd/radarLevel2?returns=catalog&stn=KFTG&dtime=latest
    StringBuilder queryb = new StringBuilder();
    String baseURI = dsc_location.replaceFirst("/dataset.xml", "?");
    queryb.append(baseURI);
    queryb.append("stn=" + stnName);
    if (productID != null) {
      queryb.append("&var=" + productID);
    }
    if ((start == null) && (end == null)) {
      queryb.append("&time=present");
    } else if (end == null) {
      String stime = DateUtil.getTimeAsISO8601(start).replaceAll("GMT", "");
      queryb.append("&time_start=" + stime);
      queryb.append("&time_end=present");
    } else {
      String stime = DateUtil.getTimeAsISO8601(start).replaceAll("GMT", "");
      String etime = DateUtil.getTimeAsISO8601(end).replaceAll("GMT", "");
      queryb.append("&time_start=" + stime);
      queryb.append("&time_end=" + etime);
    }

    URI catalogURI;
    try {
      catalogURI = new URI(queryb.toString());
    } catch (java.net.URISyntaxException e) {
      throw new IOException("** MalformedURLException on URL <" + ">\n" + e.getMessage() + "\n");
    }

    InvCatalogFactory factory = new InvCatalogFactory("default", false);

    // visad.util.Trace.call1("TDSRadarDatasetCollection.readXML");
    InvCatalogImpl catalog = (InvCatalogImpl) factory.readXML(catalogURI);
    // visad.util.Trace.call2("TDSRadarDatasetCollection.readXML");
    StringBuilder buff = new StringBuilder();
    // visad.util.Trace.call1("TDSRadarDatasetCollection.checkCatalog");
    if (!catalog.check(buff)) {
      throw new IOException("Invalid catalog <" + catalogURI + ">\n" + buff.toString());
    }
    // visad.util.Trace.call2("TDSRadarDatasetCollection.checkCatalog");

    List<InvDataset> datasets = catalog.getDatasets();

    InvDataset idata = (InvDataset) datasets.get(0);

    List<InvDataset> dsets = idata.getDatasets();

    List<Date> absTimeList = new ArrayList<Date>();
    List<DatasetURIInfo> dURIList = new ArrayList<DatasetURIInfo>();
    List<InvDatasetInfo> dInvList = new ArrayList<InvDatasetInfo>();

    // visad.util.Trace.call1("TDSRadarDatasetCollection.getLists");
    for (InvDataset tdata : dsets) {
      List<InvAccess> acess = tdata.getAccess();
      List<DateType> dates = tdata.getDates();
      InvAccess ia = (InvAccess) acess.get(0);
      URI d = ia.getStandardUri();
      Date date = ((DateType) dates.get(0)).getDate();
      absTimeList.add(date);
      dURIList.add(new DatasetURIInfo(d, date));
      dInvList.add(new InvDatasetInfo(tdata, date));
    }
    // visad.util.Trace.call2("TDSRadarDatasetCollection.getLists");

    TDSRadarDatasetInfo dri = new TDSRadarDatasetInfo(absTimeList, dURIList, dInvList);

    return dri;
  }
Esempio n. 21
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;
 }
Esempio n. 22
0
 /**
  * Get containing catalog.
  *
  * @return containing catalog.
  */
 public InvCatalog getParentCatalog() {
   if (catalog != null) return catalog;
   return (parent != null) ? parent.getParentCatalog() : null;
 }
Esempio n. 23
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;
      }
    }
  }
Esempio n. 24
0
 /**
  * _more_
  *
  * @param ds _more_
  * @param dqc_location _more_
  * @param errlog _more_
  * @return _more_
  * @throws IOException _more_
  */
 public static DqcRadarDatasetCollection factory(
     InvDataset ds, String dqc_location, StringBuffer errlog) throws IOException {
   return factory(ds.getDocumentation("summary"), dqc_location, errlog);
 }
Esempio n. 25
0
  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;
  }
Esempio n. 26
0
  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;
  }