Example #1
0
  @Test
  public void testFloatingPointCompare() throws Exception {
    String spec =
        TestDir.cdmUnitTestDir + "ft/fmrc/fp_precision/sediment_thickness_#yyMMddHHmm#.*\\.nc$";
    System.out.printf("%n====================FMRC dataset %s%n", spec);
    Formatter errlog = new Formatter();
    Fmrc fmrc = Fmrc.open(spec, errlog);
    assert (fmrc != null) : errlog;

    try (ucar.nc2.dt.GridDataset gridDs = fmrc.getDatasetBest()) {
      GridDatatype v = gridDs.findGridByShortName("thickness_of_sediment");
      assert v != null;
      GridCoordSystem gcs = v.getCoordinateSystem();
      CoordinateAxis1DTime time = gcs.getTimeAxis1D();

      Assert.assertEquals("hours since 2015-03-08 12:51:00.000 UTC", time.getUnitsString());
      Assert.assertEquals(74, time.getSize());
      Array data = time.read();
      System.out.printf("%s%n", NCdumpW.toString(data));

      for (CalendarDate cd : time.getCalendarDates()) {
        assert cd.getFieldValue(CalendarPeriod.Field.Minute) == 0 : System.out.printf("%s%n", cd);
      }
    }
  }
Example #2
0
  /**
   * Display package name and version information for javax.mail.internet.
   *
   * <p>This example is a bit artificial, since examining the version of a jar from Sun Microsystems
   * is unusual.
   *
   * @return _more_
   * @throws IOException _more_
   */
  private static HashMap<String, String> getBuildInfo() throws IOException {
    GribVariableRenamer renamer = new GribVariableRenamer();
    HashMap<String, String> buildInfo = new HashMap<String, String>();

    Enumeration<URL> resources =
        renamer.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
    while (resources.hasMoreElements()) {
      try {
        Manifest manifest = new Manifest(resources.nextElement().openStream());
        Attributes attrs = manifest.getMainAttributes();
        if (attrs != null) {
          String implTitle = attrs.getValue("Implementation-Title");
          if ((implTitle != null) && (implTitle.contains("ncIdv"))) {
            buildInfo.put("version", attrs.getValue("Implementation-Version"));
            String strDate = attrs.getValue("Built-On");

            CalendarDate cd = CalendarDate.parseISOformat(null, strDate);
            buildInfo.put("buildDate", cd.toString());

            break;
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return buildInfo;
  }
  private double getTime(StructureMembers.Member timeVar, StructureData sdata) {
    if (timeVar == null) return 0.0;

    if ((timeVar.getDataType() == DataType.CHAR) || (timeVar.getDataType() == DataType.STRING)) {
      String time = sdata.getScalarString(timeVar);
      CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, time);
      if (date == null) {
        log.error("Cant parse date - not ISO formatted, = " + time);
        return 0.0;
      }
      return date.getMillis() / 1000.0;

    } else {
      return sdata.convertScalarDouble(timeVar);
    }
  }
  public void writeProfileData(ProfileFeature profile, int nobs) throws IOException {
    trackBB(profile.getLatLon(), CalendarDate.of(profile.getTime()));

    StructureDataScalar profileCoords = new StructureDataScalar("Coords");
    profileCoords.addMember(
        latName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLatitude());
    profileCoords.addMember(
        lonName, null, null, DataType.DOUBLE, false, profile.getLatLon().getLongitude());
    if (profile.getTime() != null)
      profileCoords.addMember(
          profileTimeName,
          null,
          null,
          DataType.DOUBLE,
          false,
          timeUnit.makeValue(profile.getTime())); // LOOK time not always part of profile
    profileCoords.addMemberString(profileIdName, null, null, profile.getName().trim(), id_strlen);
    profileCoords.addMember(numberOfObsName, null, null, DataType.INT, false, nobs);

    StructureData profileData = profile.getFeatureData();
    StructureDataComposite sdall = new StructureDataComposite();
    sdall.add(profileCoords); // coords first so it takes precedence
    sdall.add(profileData);

    profileRecno = super.writeStructureData(profileRecno, profileStruct, sdall, featureVarMap);
  }
Example #5
0
 /**
  * @param threddsURI
  * @param startDate
  * @param endDate
  * @param dataVarShortNames
  * @param stationNames
  * @param gridDataset
  * @param gridBbox
  */
 public void setOperationGetObs(
     String threddsURI,
     CalendarDate startDate,
     CalendarDate endDate,
     List<String> dataVarShortNames,
     String[] stationNames,
     boolean gridDataset,
     LatLonRect gridBbox,
     FeatureType ftype) {
   // set url info
   setOperationMethods((Element) getObs.getElementsByTagName("ows:HTTP").item(0), threddsURI);
   // set info for get observation operation
   // get our parameters that need to be filled
   Element eventtime = null, offering = null, observedproperty = null, procedure = null;
   NodeList nodes = getObs.getElementsByTagName("ows:Parameter");
   for (int i = 0; i < nodes.getLength(); i++) {
     Element elem = (Element) nodes.item(i);
     if (elem.getAttribute("name").equalsIgnoreCase("offering")) {
       offering = elem;
     } else if (elem.getAttribute("name").equalsIgnoreCase("observedProperty")) {
       observedproperty = elem;
     } else if (elem.getAttribute("name").equalsIgnoreCase("eventTime")) {
       eventtime = elem;
     } else if (elem.getAttribute("name").equalsIgnoreCase("procedure")) {
       procedure = elem;
     }
   }
   // set eventtime
   if (eventtime != null && endDate != null && startDate != null) {
     Element allowedValues = getDocument().createElement("ows:AllowedValues");
     eventtime.appendChild(allowedValues);
     Element range = getDocument().createElement("ows:Range");
     allowedValues.appendChild(range);
     // min value
     Element min = getDocument().createElement("ows:MinimumValue");
     min.setTextContent(startDate.toString());
     allowedValues.appendChild(min);
     // max value
     Element max = getDocument().createElement("ows:MaximumValue");
     max.setTextContent(endDate.toString());
     allowedValues.appendChild(max);
   }
   // set observedProperty parameter
   if (observedproperty != null) {
     Element allowedValues = getDocument().createElement("ows:AllowedValues");
     observedproperty.appendChild(allowedValues);
     for (String name : dataVarShortNames) {
       Element value = getDocument().createElement("ows:value");
       value.setTextContent(name);
       allowedValues.appendChild(value);
     }
   }
   // set offering parameter - list of station names
   if (offering != null && stationNames != null) {
     Element aV = getDocument().createElement("ows:AllowedValues");
     offering.appendChild(aV);
     // add network-all as an offering
     Element network = document.createElement("ows:Value");
     network.setTextContent("network-all");
     aV.appendChild(network);
     for (String name : stationNames) {
       Element value = getDocument().createElement("ows:Value");
       value.setTextContent(name);
       aV.appendChild(value);
     }
   }
   // set procedure parameter - list of procedures
   // add allowed values node
   Element allowedValues = getDocument().createElement("ows:AllowedValues");
   procedure.appendChild(allowedValues);
   // add network-all value
   Element na = getDocument().createElement("ows:Value");
   na.setTextContent(SOSBaseRequestHandler.getGMLNetworkAll());
   allowedValues.appendChild(na);
   for (String stationName : stationNames) {
     Element elem = getDocument().createElement("ows:Value");
     elem.setTextContent(SOSBaseRequestHandler.getGMLName(stationName));
     allowedValues.appendChild(elem);
     for (String senName : dataVarShortNames) {
       Element sElem = getDocument().createElement("ows:Value");
       sElem.setTextContent(SOSBaseRequestHandler.getSensorGMLName(stationName, senName));
       allowedValues.appendChild(sElem);
     }
   }
   // set additional response formats, supported
   switch (ftype) {
     case STATION:
       // add new ioos response format for TimeSeries data
       NodeList nlist = getObs.getElementsByTagName("ows:Parameter");
       for (int n = 0; n < nlist.getLength(); n++) {
         Element elm = (Element) nlist.item(n);
         if ("responseFormat".equals(elm.getAttribute("name"))) {
           Element av = (Element) elm.getElementsByTagName("ows:AllowedValues").item(0);
           Element rf = document.createElement("ows:Value");
           rf.setTextContent("text/xml;subtype=\"om/1.0.0/profiles/ioos_sos/1.0\"");
           av.appendChild(rf);
         }
       }
       break;
   }
   // add lat and lon as parameters if we are a grid dataset
   if (gridDataset) addLatLonParameters(getObs, gridBbox);
 }