예제 #1
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
예제 #2
0
 /**
  * get the number of products
  *
  * @param sName _more_
  * @return _more_
  */
 public int getStationProductCount(String sName) {
   return radarProducts.size();
 }
예제 #3
0
  /**
   * 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);
  }
예제 #4
0
  /**
   * _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);
  }
예제 #5
0
  /**
   * _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);
  }
예제 #6
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;
  }
예제 #7
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;
  }