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();
  }
Ejemplo n.º 2
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
Ejemplo n.º 3
0
  /**
   * 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;
  }
Ejemplo n.º 4
0
  private void level2level3catalog(
      RadarType radarType,
      String pathInfo,
      PrintWriter pw,
      HttpServletRequest req,
      HttpServletResponse res)
      throws IOException {

    try {
      String type;
      if (pathInfo.contains("level2")) type = radarType.toString() + "/level2";
      else type = radarType.toString() + "/level3";

      ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
      InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false);
      factory.writeXML(cat, os, true);
      InvCatalogImpl tCat = factory.readXML(new ByteArrayInputStream(os.toByteArray()), catURI);

      Iterator parents = tCat.getDatasets().iterator();
      while (parents.hasNext()) {
        ArrayList<InvDatasetImpl> delete = new ArrayList<InvDatasetImpl>();
        InvDatasetImpl top = (InvDatasetImpl) parents.next();
        Iterator tDatasets = top.getDatasets().iterator();
        while (tDatasets.hasNext()) {
          InvDatasetImpl ds = (InvDatasetImpl) tDatasets.next();
          if (ds instanceof InvDatasetScan) {
            InvDatasetScan ids = (InvDatasetScan) ds;
            if (ids.getPath() == null) continue;
            if (ids.getPath().contains(type)) {
              ids.setXlinkHref(ids.getPath() + "/dataset.xml");
            } else {
              delete.add(ds);
            }
          }
        }
        // remove datasets
        for (InvDatasetImpl idi : delete) {
          top.removeDataset(idi);
        }
      }
      if (pathInfo.endsWith("xml")) {
        String catAsString = factory.writeXML(tCat);
        pw.println(catAsString);
        pw.flush();
      } else {
        HtmlWriter.getInstance().writeCatalog(req, res, tCat, true); // show catalog as HTML
      }
    } catch (Throwable e) {
      log.error("RadarServer.level2level3catalog failed", e);
      if (!res.isCommitted()) res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
    return;
  }
Ejemplo n.º 5
0
  /**
   * 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;
  }
Ejemplo n.º 6
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);
   }
 }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  public static void main(String args[]) {
    JFrame frame;
    final DatasetEditor editor = new DatasetEditor();

    frame = new JFrame("Test DatasetEditor");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    JButton save = new JButton("Accept");
    save.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            editor.accept();
            editor.store2Dataset();
            try {
              cat.writeXML(System.out, true);
            } catch (IOException e1) {
              e1.printStackTrace();
            }
          }
        });
    JPanel main = new JPanel(new BorderLayout());
    main.add(editor, BorderLayout.CENTER);
    main.add(save, BorderLayout.NORTH);

    frame.getContentPane().add(main);
    frame.pack();
    frame.setLocation(150, 10);
    frame.setVisible(true);

    // LOOK-NOSAVE
    java.net.Authenticator.setDefault(new UrlAuthenticatorDialog(frame));

    // String url = "http://uni10.unidata.ucar.edu:8088/thredds/content/idd/models.xml";
    String url = "http://thredds.ucar.edu/thredds/content/idd/models.xml";
    InvCatalogFactory catFactory = InvCatalogFactory.getDefaultFactory(true);
    cat = catFactory.readXML(url);
    InvDatasetImpl ds = (InvDatasetImpl) cat.findDatasetByID("NCEP/NAM/V");

    editor.setDataset(ds);
  }
Ejemplo n.º 9
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;
  }