/**
   * Getting data for a single radar station, with time range.
   *
   * @param sName radar station name
   * @param dateSelect the date time selection information
   * @param cancel _more_
   * @return list of radialDatasetSweep
   * @throws IOException _more_
   */
  public List getData(String sName, DateSelection dateSelect, ucar.nc2.util.CancelTask cancel)
      throws IOException {
    if ((cancel != null) && cancel.isCancel()) {
      return null;
    }
    TDSRadarDatasetInfo dri =
        queryRadarStation(sName, dateSelect.getStartFixedDate(), dateSelect.getEndFixedDate());
    List datasetList = new ArrayList();

    List datasetINVs = dateSelect.apply(dri.getInvList());

    Iterator it = datasetINVs.iterator();
    while (it.hasNext()) {
      InvDatasetInfo ifo = (InvDatasetInfo) it.next();
      InvDataset tdata = ifo.inv;
      ThreddsDataFactory tdFactory = new ThreddsDataFactory();
      ThreddsDataFactory.Result result;
      result = tdFactory.openFeatureDataset(tdata, null);
      datasetList.add(result.featureDataset);
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return datasetList;
  }
示例#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
  /**
   * get all radar station within box.
   *
   * @param boundingBox the bounding box
   * @param cancel the cancel task
   * @return List Station objects
   * @throws IOException java io exception
   */
  public List<Station> getStations(LatLonRect boundingBox, ucar.nc2.util.CancelTask cancel)
      throws IOException {
    Collection<Station> sl = stationHMap.values();
    List<Station> dsl = new ArrayList<Station>();

    if (!boundingBox.containedIn(radarRegion)) {
      return null;
    }

    // for (Iterator it = sl.iterator(); it.hasNext(); ) {
    //    Station         s        = (Station) it.next();
    for (Station s : sl) {
      // LatLonPointImpl latlonPt = new LatLonPointImpl();
      // latlonPt.set(s.getLatitude(), s.getLongitude());
      // if (boundingBox.contains(latlonPt)) {
      if (boundingBox.contains(s.getLatLon())) {
        dsl.add(s);
      }
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return dsl;
  }
  /**
   * get all radar station.
   *
   * @return List of type Station objects
   */
  public List<Station> getRadarStations() {
    List<Station> slist = new ArrayList<Station>();
    Iterator it = this.stationHMap.values().iterator();
    while (it.hasNext()) {
      slist.add((Station) it.next());
    }

    return slist;
  }
  /**
   * get all radar station.
   *
   * @return List of type DqcRadarStation objects
   * @throws IOException java io exception
   */
  public List getRadarStations() {
    List sl = selStation.getStations();
    ArrayList dsl = new ArrayList();

    for (Iterator it = sl.iterator(); it.hasNext(); ) {
      Station s = (Station) it.next();
      dsl.add(s);
    }
    return dsl;
  }
  /**
   * Getting data for a single radar station.
   *
   * @param stnName radar station name
   * @param start of the time
   * @param end of the time
   * @return data URI list
   * @throws IOException java io exception
   */
  public List getRadarStationURIs(String stnName, Date start, Date end) throws IOException {

    TDSRadarDatasetInfo dri = queryRadarStation(stnName, start, end);
    List<DatasetURIInfo> uList = dri.getURIList();
    List<URI> datasetsURI = new ArrayList();
    for (DatasetURIInfo du : uList) {
      datasetsURI.add(du.uri);
    }

    return datasetsURI;
  }
  /**
   * 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;
  }
  /**
   * Getting data Iterator for a single radar station.
   *
   * @param stnName radar station name
   * @param start of the time
   * @param end of the time
   * @return dataset list
   * @throws IOException java io exception
   */
  public List getRadarStationDatasets(String stnName, Date start, Date end) throws IOException {

    List datasetList = new ArrayList();

    TDSRadarDatasetInfo dri = queryRadarStation(stnName, start, end);
    List<InvDatasetInfo> iList = dri.getInvList();
    for (InvDatasetInfo iv : iList) {
      InvDataset tdata = iv.inv;
      ThreddsDataFactory tdFactory = new ThreddsDataFactory();
      ThreddsDataFactory.Result result;
      result = tdFactory.openFeatureDataset(tdata, null);
      datasetList.add(result.featureDataset);
    }

    return datasetList;
  }
  /**
   * get start and end elemnt form parent element
   *
   * @param elem _more_
   * @param ns _more_
   * @return list of times
   */
  public List<String> readSelectTime(Element elem, Namespace ns) {
    // look for stations

    Element region = elem.getChild("TimeSpan", ns);

    java.util.List regionInfo = region.getChildren();
    // lat, lon
    Element start = region.getChild("start", ns);
    String sv = start.getValue();
    Element end = region.getChild("end", ns);
    String ev = end.getValue();

    List<String> ll = new ArrayList<String>();
    ll.add(sv);
    ll.add(ev);
    return ll;
  }
  /**
   * initiate a new TDS radar dataset collection object
   *
   * @param desc description
   * @param dsc_location location of dataset
   * @param elem dataset root element
   * @param ns dataset namespace
   * @param errlog error log
   * @throws IOException _more_
   */
  private TDSRadarDatasetCollection(
      String desc, String dsc_location, Element elem, Namespace ns, StringBuffer errlog)
      throws IOException {
    super();
    Element serviceElem = readElements(elem, "service");
    Element dsElem = readElements(elem, "dataset");

    Element metaElem = readElements(dsElem, "metadata");
    // HashMap stationHMap = readSelectStations(metaElem, ns);
    String sts = dsc_location.replaceFirst("dataset.xml", "stations.xml");
    HashMap<String, Station> stationHMap = readRadarStations(sts);
    LatLonRect radarRegion = readSelectRegion(metaElem, ns);
    List<String> radarTimeSpan = readSelectTime(metaElem, ns);
    List<Product> productList = readSelectVariable(metaElem, ns);
    String summary = readSelectDocument(metaElem, ns);

    // gotta have these
    if (stationHMap == null) {
      errlog.append("TDSRadarDatasetCollection must have station selected");
      return;
    }
    if (radarRegion == null) {
      errlog.append("TDSRadarDatasetCollection must have region selected");
      return;
    }
    if (radarTimeSpan == null) {
      errlog.append("TDSRadarDatasetCollection must have time span selected");
      return;
    }

    this.desc = desc;
    this.dsc_location = dsc_location;
    this.radarProducts = productList;
    this.summary = summary;
    this.stationHMap = stationHMap;
    this.radarRegion = radarRegion;
    this.radarTimeSpan = radarTimeSpan;
    this.startDate = DateUnit.getStandardOrISO((String) radarTimeSpan.get(0));
    this.endDate = DateUnit.getStandardOrISO((String) radarTimeSpan.get(1));

    try {
      timeUnit = new DateUnit("hours since 1991-01-01T00:00");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * get all radar station within box.
   *
   * @param boundingBox _more_
   * @param cancel _more_
   * @return List of type DqcRadarStation objects
   * @throws IOException java io exception
   */
  public List getStations(
      ucar.unidata.geoloc.LatLonRect boundingBox, ucar.nc2.util.CancelTask cancel)
      throws IOException {
    List sl = selStation.getStations();
    ArrayList dsl = new ArrayList();

    for (Iterator it = sl.iterator(); it.hasNext(); ) {
      Station s = (Station) it.next();
      LatLonPointImpl latlonPt = new LatLonPointImpl();
      latlonPt.set(s.getLocation().getLatitude(), s.getLocation().getLongitude());
      if (boundingBox.contains(latlonPt)) {
        dsl.add(s);
      }
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return dsl;
  }
  /**
   * get variable list from parent element
   *
   * @param elem _more_
   * @param ns _more_
   * @return list of varibles
   */
  public List<Product> readSelectVariable(Element elem, Namespace ns) {
    // look for stations
    List<Product> varlist = new ArrayList<Product>();
    Element v = elem.getChild("Variables", ns);

    List<Element> varInfo = v.getChildren();
    for (Element p : varInfo) {
      Product s;
      String id = p.getAttributeValue("name");
      if (id.contains("/")) {
        String c[] = id.split("/");
        s = new Product(c[0], c[1]);
        varlist.add(s);

      } else {
        String name = p.getAttributeValue("vocabulary_name");
        s = new Product(id, name);
        varlist.add(s);
      }
    }
    return varlist;
  }
  /**
   * 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;
  }
  /**
   * getting data uri list
   *
   * @param sName station name
   * @param dateSelect the date selection
   * @param cancel the cancel task
   * @return the list of URIs
   * @throws IOException problem reading URIs
   */
  public List<URI> getDataURIs(
      String sName, DateSelection dateSelect, ucar.nc2.util.CancelTask cancel) throws IOException {
    if ((cancel != null) && cancel.isCancel()) {
      return null;
    }
    TDSRadarDatasetInfo dri =
        queryRadarStation(sName, dateSelect.getStartFixedDate(), dateSelect.getEndFixedDate());

    // create a list to hold URIs
    List<DatasetURIInfo> datasetsURIs = dateSelect.apply(dri.getURIList());
    List<URI> uriList = new ArrayList<URI>();

    for (DatasetURIInfo ufo : datasetsURIs) {
      URI u = ufo.uri;
      uriList.add(u);
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return uriList;
  }
  /**
   * 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;
  }
  /**
   * _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;
  }
  /**
   * _more_
   *
   * @param sName _more_
   * @param dateSelect _more_
   * @param cancel _more_
   * @return _more_
   * @throws IOException _more_
   */
  public ArrayList getDataURIs(
      String sName, DateSelection dateSelect, ucar.nc2.util.CancelTask cancel) throws IOException {
    if ((cancel != null) && cancel.isCancel()) {
      return null;
    }
    DqcRadarDatasetInfo dri =
        queryRadarStation(sName, dateSelect.getStartFixedDate(), dateSelect.getEndFixedDate());

    // create a list to hold URIs
    List datasetsURIs = dateSelect.apply(dri.getURIList());
    ArrayList uriList = new ArrayList();

    Iterator it = datasetsURIs.iterator();
    while (it.hasNext()) {
      DatasetURIInfo ufo = (DatasetURIInfo) it.next();
      URI u = ufo.uri;
      uriList.add(u);
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return uriList;
  }
示例#19
0
  private void datasetInfoHtml(
      RadarType radarType, String pathInfo, PrintWriter pw, HttpServletResponse res)
      throws IOException {
    pathInfo = pathInfo.replace("/dataset.html", "");
    pathInfo = pathInfo.replace("/catalog.html", "");
    Element root = new Element("RadarNexrad");
    Document doc = new Document(root);

    if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1);
    for (int i = 0; i < datasets.size(); i++) {
      InvDatasetScan ds = (InvDatasetScan) datasets.get(i);
      if (!(pathInfo.equals(ds.getPath()))) {
        continue;
      }

      // at this point a valid dataset
      // fix the location
      root.setAttribute("location", "/thredds/radarServer/" + ds.getPath());

      // spatial range
      ThreddsMetadata.GeospatialCoverage gc = ds.getGeospatialCoverage();
      LatLonRect bb = new LatLonRect();
      gc.setBoundingBox(bb);
      String north = Double.toString(gc.getLatNorth());
      String south = Double.toString(gc.getLatSouth());
      String east = Double.toString(gc.getLonEast());
      String west = Double.toString(gc.getLonWest());

      Element LatLonBox = new Element("LatLonBox");
      LatLonBox.addContent(new Element("north").addContent(north));
      LatLonBox.addContent(new Element("south").addContent(south));
      LatLonBox.addContent(new Element("east").addContent(east));
      LatLonBox.addContent(new Element("west").addContent(west));
      root.addContent(LatLonBox);

      // get the time range
      Element timeSpan = new Element("TimeSpan");
      CalendarDateRange dr = ds.getCalendarDateCoverage();
      timeSpan.addContent(new Element("begin").addContent(dr.getStart().toString()));
      timeSpan.addContent(new Element("end").addContent(dr.getEnd().toString()));
      root.addContent(timeSpan);

      ThreddsMetadata.Variables cvs = (ThreddsMetadata.Variables) ds.getVariables().get(0);
      List vl = cvs.getVariableList();

      for (int j = 0; j < vl.size(); j++) {
        ThreddsMetadata.Variable v = (ThreddsMetadata.Variable) vl.get(j);
        Element variable = new Element("variable");
        variable.setAttribute("name", v.getName());
        root.addContent(variable);
      }

      // add pointer to the station list XML
      /*
      Element stnList = new Element("stationList");
      stnList.setAttribute("title", "Available Stations", XMLEntityResolver.xlinkNS);
      stnList.setAttribute("href", "/thredds/radarServer/"+ pathInfo +"/stations.xml",
          XMLEntityResolver.xlinkNS);
      root.addContent(stnList);
      */
      // String[] stations = rns.stationsDS( dataLocation.get( ds.getPath() ));
      // rns.printStations( stations );

      // add accept list
      Element a = new Element("AcceptList");
      a.addContent(new Element("accept").addContent("xml"));
      a.addContent(new Element("accept").addContent("html"));
      root.addContent(a);
    }
    ServerMethods sm = new ServerMethods(log);
    InputStream xslt = sm.getInputStream(contentPath + getPath() + "radar.xsl", RadarServer.class);

    try {
      // what's wrong here xslt = getXSLT( "radar.xsl" );
      XSLTransformer transformer = new XSLTransformer(xslt);
      Document html = transformer.transform(doc);
      XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
      String infoString = fmt.outputString(html);
      res.setContentType("text/html; charset=iso-8859-1");
      pw = res.getWriter();
      pw.println(infoString);
      pw.flush();

    } catch (Exception e) {
      log.error("radarServer reading " + contentPath + getPath() + "radar.xsl");
      log.error("radarServer XSLTransformer problem for web form ", e);
    } finally {
      if (xslt != null) {
        try {
          xslt.close();
        } catch (IOException e) {
          log.error("radarServer radar.xsl: error closing" + contentPath + getPath() + "radar.xsl");
        }
      }
    }
    return;
  }
  /**
   * 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;
  }
  /**
   * _more_
   *
   * @param desc _more_
   * @param dqc_location _more_
   * @param errlog _more_
   * @return _more_
   * @throws IOException _more_
   */
  public static DqcRadarDatasetCollection factory(
      String desc, String dqc_location, StringBuffer errlog) throws IOException {

    DqcFactory dqcFactory = new DqcFactory(true);
    QueryCapability dqc = dqcFactory.readXML(dqc_location + "?returns=dqc");
    if (dqc.hasFatalError()) {
      errlog.append(dqc.getErrorMessages());
      return null;
    }

    // have a look at what selectors there are before proceeding
    SelectStation selStation = null;
    SelectList selTime = null;
    SelectService selService = null;
    // SelectGeoRegion selRegion = null;

    ArrayList selectors = dqc.getSelectors();
    for (int i = 0; i < selectors.size(); i++) {
      Selector s = (Selector) selectors.get(i);
      if (s instanceof SelectStation) {
        selStation = (SelectStation) s;
      }
      if (s instanceof SelectList) {
        selTime = (SelectList) s;
      }
      if (s instanceof SelectService) {
        selService = (SelectService) s;
      }
      // if (s instanceof SelectGeoRegion)
      //   selRegion = (SelectGeoRegion) s;
    }

    // gotta have these
    if (selService == null) {
      errlog.append("DqcStationaryRadarDataset must have Service selector");
      return null;
    }
    if (selStation == null) {
      errlog.append("DqcStationaryRadarDataset must have Station selector");
      return null;
    }
    if (selTime == null) {
      errlog.append("DqcStationaryRadarDataset must have Date selector");
      return null;
    }
    // if (selRegion == null) {
    //   errlog.append("DqcStationaryRadarDataset must have GeoRegion selector");
    //   return null;
    // }

    // decide on which service
    SelectService.ServiceChoice wantServiceChoice = null;
    List services = selService.getChoices();
    for (int i = 0; i < services.size(); i++) {
      SelectService.ServiceChoice serviceChoice = (SelectService.ServiceChoice) services.get(i);
      if (serviceChoice.getService().equals("HTTPServer")
          && serviceChoice.getDataFormat().equals("text/xml")) {
        // && serviceChoice.getReturns().equals("data")     ) // LOOK kludge
        wantServiceChoice = serviceChoice;
      }
    }

    if (wantServiceChoice == null) {
      errlog.append(
          "DqcStationObsDataset must have HTTPServer Service with DataFormat=text/plain, and returns=data");
      return null;
    }

    return new DqcRadarDatasetCollection(
        desc, dqc, selService, wantServiceChoice, selStation, null, selTime);
  }
  /**
   * _more_
   *
   * @param args _more_
   * @throws IOException _more_
   */
  public static void main(String args[]) throws IOException {
    StringBuffer errlog = new StringBuffer();
    String dqc_location = "http://thredds.ucar.edu/thredds/idd/radarLevel2";
    DqcRadarDatasetCollection ds = factory("test", dqc_location, errlog);
    System.out.println(" errs= " + errlog);

    List stns = ds.getStations();
    System.out.println(" nstns= " + stns.size());

    Station stn = (Station) (stns.get(2));

    // List ulist = stn.getRadarStationURIs();
    // assert null != ulist;
    Date ts1 = DateUnit.getStandardOrISO("2007-06-9T12:12:00");
    Date ts2 = DateUnit.getStandardOrISO("2007-06-9T23:12:00");

    List tlist = ds.getRadarStationTimes(stn.getValue(), ts1, ts2);
    int sz = tlist.size();
    Date ts0 = DateUnit.getStandardOrISO((String) tlist.get(1));
    RadialDatasetSweep rds = ds.getRadarDataset(stn.getValue(), ts0);
    URI stURL = ds.getRadarDatasetURI(stn.getValue(), ts0);
    assert null != stURL;
    assert 0 != sz;
    DateSelection dateS = new DateSelection(ts1, ts2);
    dateS.setInterval((double) 3600 * 1000);
    dateS.setRoundTo((double) 3600 * 1000);
    dateS.setPreRange((double) 500 * 1000);
    dateS.setPostRange((double) 500 * 1000);

    for (int i = 0; i < stns.size(); i++) {
      stn = (Station) stns.get(i);
      List times =
          ds.getRadarStationTimes(
              stn.getValue(),
              new Date(System.currentTimeMillis() - 3600 * 1000 * 24 * 100),
              new Date(System.currentTimeMillis()));
      if (times.size() > 0) {
        System.err.println(
            stn
                + " times:"
                + times.size()
                + " "
                + times.get(0)
                + " - "
                + times.get(times.size() - 1));
      } else {
        System.err.println(stn + " no times");
      }
    }
    System.exit(0);

    List jList = ds.getDataURIs("KABX", dateS);

    assert null != jList;
    List mList = ds.getData("KABX", dateS, null);
    assert null != mList;

    // Date ts0 =
    // DateFromString.getDateUsingCompleteDateFormat((String)tlist.get(1),"yyyy-MM-dd'T'HH:mm:ss");
    Date ts = DateUnit.getStandardOrISO((String) tlist.get(1));
    java.text.SimpleDateFormat isoDateTimeFormat;
    isoDateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    isoDateTimeFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    String st = isoDateTimeFormat.format(ts);
  }
 /**
  * get the number of products
  *
  * @param sName _more_
  * @return _more_
  */
 public int getStationProductCount(String sName) {
   return radarProducts.size();
 }
示例#24
0
  private void datasetInfoXml(RadarType radarType, String pathInfo, PrintWriter pw)
      throws IOException {

    try {
      pw.println(
          "<catalog xmlns=\"http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" name=\"Radar Data\" version=\"1.0.1\">\n");
      // add service
      pw.println(
          "  <service name=\"radarServer\" base=\"/thredds/radarServer/\" serviceType=\"DQC\" />\n");
      pathInfo = pathInfo.replace("/dataset.xml", "");
      pathInfo = pathInfo.replace("/catalog.xml", "");
      if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1);
      for (int i = 0; i < datasets.size(); i++) {
        InvDatasetScan ds = (InvDatasetScan) datasets.get(i);
        if (!(pathInfo.equals(ds.getPath()))) {
          continue;
        }

        pw.println("  <dataset ID=\"" + ds.getID() + "\" serviceName=\"radarServer\">");

        pw.println("    <urlpath>" + ds.getPath() + "</urlpath>");
        pw.println("    <dataType>" + ds.getDataType() + "</dataType>");

        pw.println("    <dataFormat>" + ds.getDataFormatType() + "</dataFormat>");

        pw.println("   <serviceName>radarServer</serviceName>");

        pw.println("    <metadata inherited=\"true\">");

        pw.println("    <documentation type=\"summary\">" + ds.getSummary() + "</documentation>");
        CalendarDateRange dr = ds.getCalendarDateCoverage();
        pw.println("      <TimeSpan>");
        pw.print("        <start>");
        if (pathInfo.contains("IDD")) {
          pw.print(rm.getStartDateTime(ds.getPath()));
        } else {
          pw.print(dr.getStart().toString());
        }
        pw.println("</start>");
        pw.println("        <end>" + dr.getEnd().toString() + "</end>");
        pw.println("      </TimeSpan>");
        ThreddsMetadata.GeospatialCoverage gc = ds.getGeospatialCoverage();
        LatLonRect bb = new LatLonRect();
        gc.setBoundingBox(bb);
        pw.println("      <LatLonBox>");
        pw.println("        <north>" + gc.getLatNorth() + "</north>");
        pw.println("        <south>" + gc.getLatSouth() + "</south>");
        pw.println("        <east>" + gc.getLonEast() + "</east>");
        pw.println("        <west>" + gc.getLonWest() + "</west>");
        pw.println("      </LatLonBox>");

        ThreddsMetadata.Variables cvs = (ThreddsMetadata.Variables) ds.getVariables().get(0);
        List vl = cvs.getVariableList();

        pw.println("      <Variables>");
        for (int j = 0; j < vl.size(); j++) {
          ThreddsMetadata.Variable v = (ThreddsMetadata.Variable) vl.get(j);
          pw.println(
              "        <variable name=\""
                  + v.getName()
                  + "\" vocabulary_name=\""
                  + v.getVocabularyName()
                  + "\" units=\""
                  + v.getUnits()
                  + "\" />");
        }
        pw.println("      </Variables>");
        String[] stations = rm.stationsDS(radarType, dataLocation.get(ds.getPath()));
        rm.printStations(stations, pw, radarType);

        pw.println("    </metadata>");
        pw.println("  </dataset>");
      }
      pw.println("</catalog>");
      pw.flush();
    } catch (Throwable e) {
      log.error("RadarServer.datasetInfoXml", e);
    }
    return;
  }
  /**
   * Test the program
   *
   * @param args the args
   * @throws IOException _more_
   */
  public static void main(String args[]) throws IOException {
    StringBuffer errlog = new StringBuffer();
    String ds_location = null;
    TDSRadarDatasetCollection dsc = null;
    List stns = null;

    ds_location =
        // "http://localhost:8080/thredds/radarServer/nexrad/level3/CCS039/dataset.xml";
        // "http://motherlode.ucar.edu:8081/thredds/radarServer/nexrad/level3/CCS039/dataset.xml";
        "http://thredds.ucar.edu/thredds/radarServer/nexrad/level3/CCS039/dataset.xml";
    dsc = TDSRadarDatasetCollection.factory("test", ds_location, errlog);
    System.out.println(" errs= " + errlog);
    stns = dsc.getStations();
    System.out.println(" nstns= " + stns.size());

    // System.exit(0);
    stns = dsc.getStations();
    System.out.println(" nstns= " + stns.size());

    Station stn = dsc.getRadarStation("DVN"); // (StationImpl)stns.get(12);
    System.out.println("stn = " + stn);

    // List ulist = stn.getRadarStationURIs();
    // assert null != ulist;
    List tl = dsc.getRadarTimeSpan();
    Date ts1 = DateUnit.getStandardOrISO("1998-06-28T01:01:21Z");
    Date ts2 = DateUnit.getStandardOrISO("1998-07-30T19:01:21Z");
    List pd = dsc.getRadarProducts();
    List<Date> tlist = dsc.getRadarStationTimes(stn.getName(), "BREF1", ts1, ts2);
    int sz = tlist.size();
    for (int i = 0; i < 3; i++) {
      Date ts0 = (Date) tlist.get(i);
      RadialDatasetSweep rds = dsc.getRadarDataset(stn.getName(), "BREF1", ts0);
      int tt = 0;
    }

    Date ts0 = (Date) tlist.get(0);
    URI stURL = dsc.getRadarDatasetURI(stn.getName(), "BREF1", ts0);
    assert null != stURL;
    DateSelection dateS = new DateSelection(ts1, ts2);
    dateS.setInterval((double) 3600 * 1000);
    dateS.setRoundTo((double) 3600 * 1000);
    dateS.setPreRange((double) 500 * 1000);
    dateS.setPostRange((double) 500 * 1000);

    for (int i = 0; i < stns.size(); i++) {
      stn = (Station) stns.get(i);
      List<Date> times =
          dsc.getRadarStationTimes(
              stn.getName(),
              "BREF1",
              new Date(System.currentTimeMillis() - 3600 * 1000 * 24 * 100),
              new Date(System.currentTimeMillis()));
      if (times.size() > 0) {
        System.err.println(
            stn
                + " times:"
                + times.size()
                + " "
                + times.get(0)
                + " - "
                + times.get(times.size() - 1));
      } else {
        System.err.println(stn + " no times");
      }
    }

    Date ts = (Date) tlist.get(1);
    java.text.SimpleDateFormat isoDateTimeFormat;
    isoDateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    isoDateTimeFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
    String st = isoDateTimeFormat.format(ts);
  }