Example #1
0
  private void showDeclaration(BeanTableSorted from, boolean isNcml) {
    Variable v = getCurrentVariable(from);
    if (v == null) return;
    infoTA.clear();
    if (isNcml) {
      Formatter out = new Formatter();
      try {
        NCdumpW.writeNcMLVariable(v, out);
      } catch (IOException e) {
        e.printStackTrace();
      }
      infoTA.appendLine(out.toString());

    } else {
      infoTA.appendLine(v.toString());
    }

    if (Debug.isSet("Xdeveloper")) {
      infoTA.appendLine("\n");
      infoTA.appendLine("FULL NAME = " + v.getFullName());
      infoTA.appendLine("\n");
      infoTA.appendLine(v.toStringDebug());
    }
    infoTA.gotoTop();
    infoWindow.setTitle("Variable Info");
    infoWindow.show();
  }
  private void showValues2D(CoordinateAxis2D axis2D) {

    Formatter f = new Formatter();

    if (axis2D.isInterval()) {
      ArrayDouble.D2 coords = axis2D.getCoordValuesArray();
      ArrayDouble.D3 bounds = axis2D.getCoordBoundsArray();
      if (bounds == null) {
        infoTA.appendLine("No bounds for interval " + axis2D.getFullName());
        return;
      }

      IndexIterator coordIter = coords.getIndexIterator();
      IndexIterator boundsIter = bounds.getIndexIterator();
      while (coordIter.hasNext()) {
        double coordValue = coordIter.getDoubleNext();
        if (!boundsIter.hasNext()) break;
        double bounds1 = boundsIter.getDoubleNext();
        if (!boundsIter.hasNext()) break;
        double bounds2 = boundsIter.getDoubleNext();
        f.format("%f (%f,%f) = %f%n", coordValue, bounds1, bounds2, bounds2 - bounds1);
      }

    } else {
      ArrayDouble.D2 coords = axis2D.getCoordValuesArray();
      IndexIterator coordIter = coords.getIndexIterator();
      while (coordIter.hasNext()) {
        double coordValue = coordIter.getDoubleNext();
        f.format("%f%n", coordValue);
      }
    }

    infoTA.appendLine(f.toString());
  }
 private void printArrays(String title, double vals[], double vals2[]) {
   Formatter sbuff = new Formatter();
   sbuff.format(" %s%n", title);
   for (int i = 0; i < vals.length; i++) {
     sbuff.format(" %3d: %10.2f  %10.2f%n", i, vals[i], vals2[i]);
   }
   sbuff.format("%n");
   infoTA.appendLine(sbuff.toString());
 }
 private void printArray(String title, double vals[]) {
   Formatter sbuff = new Formatter();
   sbuff.format(" %s=", title);
   for (double val : vals) {
     sbuff.format(" %f", val);
   }
   sbuff.format("%n");
   infoTA.appendLine(sbuff.toString());
 }
 private String showMissing(Variable v) {
   if (!(v instanceof VariableDS)) return "";
   VariableDS ve = (VariableDS) v;
   Formatter buff = new Formatter();
   buff.format("%s:", v.getFullName());
   EnumSet<NetcdfDataset.Enhance> enhanceMode = ve.getEnhanceMode();
   buff.format("enhanceMode= %s%n", enhanceMode);
   ve.showScaleMissingProxy(buff);
   return buff.toString();
 }
  /**
   * Converts the byte array to hex string.
   *
   * @param raw the data.
   * @return the hex string.
   */
  private String getHex(byte[] raw) {
    if (raw == null) return null;

    StringBuilder hex = new StringBuilder(2 * raw.length);
    Formatter f = new Formatter(hex);
    try {
      for (byte b : raw) f.format("%02x", b);
    } finally {
      f.close();
    }
    return hex.toString();
  }
  public void summaryInfo(Formatter f) {
    if (ds == null) return;
    f.format("%s%n", ds.getLocation());
    int ngrids = 0;

    for (Object varo : varTable.getBeans()) {
      VariableBean varBean = (VariableBean) varo;
      if (varBean.getDataType().trim().equalsIgnoreCase("grid")) ngrids++;
    }
    int ncoordSys = csTable.getBeans().size();
    int ncoords = axisTable.getBeans().size();

    f.format(" ngrids=%d, ncoords=%d, ncoordSys=%d%n", ngrids, ncoords, ncoordSys);
  }
 private void showDates1D(CoordinateAxis1D axis1D, CalendarDateUnit cdu) {
   if (!axis1D.isInterval()) {
     for (double val : axis1D.getCoordValues()) {
       if (Double.isNaN(val)) infoTA.appendLine(" N/A");
       else infoTA.appendLine(" " + cdu.makeCalendarDate(val));
     }
   } else { // is interval
     Formatter f = new Formatter();
     double[] b1 = axis1D.getBound1();
     double[] b2 = axis1D.getBound2();
     for (int i = 0; i < b1.length; i++)
       f.format(
           " (%f, %f) == (%s, %s)%n",
           b1[i], b2[i], cdu.makeCalendarDate((b1[i])), cdu.makeCalendarDate((b2[i])));
     infoTA.appendLine(f.toString());
   }
 }
  private void showValuesAsDates(CoordinateAxis axis) {
    String units = axis.getUnitsString();
    String cal = getCalendarAttribute(axis);
    CalendarDateUnit cdu = CalendarDateUnit.of(cal, units);

    try {
      infoTA.appendLine(units);
      infoTA.appendLine(NCdumpW.printVariableData(axis, null));

      if (axis.getDataType().isNumeric()) {
        if (axis instanceof CoordinateAxis2D) {
          showDates2D((CoordinateAxis2D) axis, cdu);

        } else if (axis instanceof CoordinateAxis1D) { // 1D
          showDates1D((CoordinateAxis1D) axis, cdu);

        } else { // > 2D
          Array data = axis.read();
          IndexIterator ii = data.getIndexIterator();
          while (ii.hasNext()) {
            double val = ii.getDoubleNext();
            infoTA.appendLine(makeCalendarDateStringOrMissing(cdu, val));
          }
        }

      } else { // must be iso dates
        Array data = axis.read();
        Formatter f = new Formatter();
        if (data instanceof ArrayChar) {
          ArrayChar dataS = (ArrayChar) data;
          ArrayChar.StringIterator iter = dataS.getStringIterator();
          while (iter.hasNext()) f.format(" %s%n", iter.next());
          infoTA.appendLine(f.toString());

        } else if (data instanceof ArrayObject) {
          IndexIterator iter = data.getIndexIterator();
          while (iter.hasNext()) f.format(" %s%n", iter.next());
          infoTA.appendLine(f.toString());
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      infoTA.appendLine(ex.getMessage());
    }
  }
 /**
  * Calculates the hash of the certificate known as the "thumbprint" and returns it as a string
  * representation.
  *
  * @param cert The certificate to hash.
  * @param algorithm The hash algorithm to use.
  * @return The SHA-1 hash of the certificate.
  * @throws CertificateException
  */
 private static String getThumbprint(X509Certificate cert, String algorithm)
     throws CertificateException {
   MessageDigest digest;
   try {
     digest = MessageDigest.getInstance(algorithm);
   } catch (NoSuchAlgorithmException e) {
     throw new CertificateException(e);
   }
   byte[] encodedCert = cert.getEncoded();
   StringBuilder sb = new StringBuilder(encodedCert.length * 2);
   Formatter f = new Formatter(sb);
   try {
     for (byte b : digest.digest(encodedCert)) f.format("%02x", b);
   } finally {
     f.close();
   }
   return sb.toString();
 }
Example #11
0
  public SummaryTab(VMPanel vmPanel) {
    super(vmPanel, getTabName());

    setLayout(new BorderLayout());

    info = new HTMLPane();
    setAccessibleName(info, getTabName());
    add(new JScrollPane(info));

    headerDateTimeFormat =
        Formatter.getDateTimeFormat(Messages.SUMMARY_TAB_HEADER_DATE_TIME_FORMAT);
  }
Example #12
0
  private void compareDataset(CompareDialog.Data data) {
    if (data.name == null) return;

    NetcdfFile compareFile = null;
    try {
      compareFile = NetcdfDataset.openFile(data.name, null);

      Formatter f = new Formatter();
      CompareNetcdf2 cn = new CompareNetcdf2(f, data.showCompare, data.showDetails, data.readData);
      if (data.howMuch == CompareDialog.HowMuch.All) cn.compare(ds, compareFile);
      else {
        NestedTable nested = nestedTableList.get(0);
        Variable org = getCurrentVariable(nested.table);
        if (org == null) return;
        Variable ov = compareFile.findVariable(org.getFullNameEscaped());
        if (ov != null) cn.compareVariable(org, ov);
      }

      infoTA.setText(f.toString());
      infoTA.gotoTop();
      infoWindow.setTitle("Compare");
      infoWindow.show();

    } catch (Throwable ioe) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(10000);
      ioe.printStackTrace(new PrintStream(bos));
      infoTA.setText(bos.toString());
      infoTA.gotoTop();
      infoWindow.show();

    } finally {
      if (compareFile != null)
        try {
          compareFile.close();
        } catch (Exception eek) {
        }
    }
  }
Example #13
0
  private void showValues(CoordinateAxis axis) {

    try {

      if (axis instanceof CoordinateAxis1D && axis.isNumeric()) {
        CoordinateAxis1D axis1D = (CoordinateAxis1D) axis;
        printArray("midpoints=", axis1D.getCoordValues());

        if (!axis1D.isInterval()) {
          printArray("edges=", axis1D.getCoordEdges());

        } else {
          printArray("bound1=", axis1D.getBound1());
          printArray("bound2=", axis1D.getBound2());

          Formatter f = new Formatter();
          double[] mid = axis1D.getCoordValues();
          double[] b1 = axis1D.getBound1();
          double[] b2 = axis1D.getBound2();
          for (int i = 0; i < b1.length; i++) {
            f.format("%f (%f,%f) = %f%n", mid[i], b1[i], b2[i], b2[i] - b1[i]);
          }
          infoTA.appendLine(f.toString());
        }

      } else if (axis instanceof CoordinateAxis2D && axis.isNumeric()) {
        infoTA.appendLine(NCdumpW.printVariableData(axis, null));
        showValues2D((CoordinateAxis2D) axis);

      } else {
        infoTA.appendLine(NCdumpW.printVariableData(axis, null));
      }

    } catch (IOException e1) {
      e1.printStackTrace();
      infoTA.appendLine(e1.getMessage());
    }
  }
  private void dumpDDS() {
    List<MessageBean> beans = messageTable.getBeans();
    HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size());

    for (MessageBean mb : beans) {
      map.put(mb.m.hashCode(), mb.m);
    }

    if (fileChooser == null)
      fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

    String defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
    int pos = defloc.lastIndexOf(".");
    if (pos > 0) defloc = defloc.substring(0, pos);
    String filename = fileChooser.chooseFilenameToSave(defloc + ".txt");
    if (filename == null) return;

    try {
      File file = new File(filename);
      FileOutputStream fos = new FileOutputStream(file);

      int count = 0;
      for (Message m : map.values()) {
        Formatter f = new Formatter(fos);
        m.dump(f);
        f.flush();
        count++;
      }
      fos.close();
      JOptionPane.showMessageDialog(
          BufrMessageViewer.this, count + " successfully written to " + filename);

    } catch (IOException e1) {
      JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
      e1.printStackTrace();
    }
  }
Example #15
0
  private void showDates2D(CoordinateAxis2D axis2D, CalendarDateUnit cdu) {
    Formatter f = new Formatter();

    if (axis2D.isInterval()) {
      ArrayDouble.D2 coords = axis2D.getCoordValuesArray();
      ArrayDouble.D3 bounds = axis2D.getCoordBoundsArray();
      if (bounds == null) {
        infoTA.appendLine("No bounds for interval " + axis2D.getFullName());
        return;
      }

      IndexIterator coordIter = coords.getIndexIterator();
      IndexIterator boundsIter = bounds.getIndexIterator();
      while (coordIter.hasNext()) {
        double coordValue = coordIter.getDoubleNext();
        if (!boundsIter.hasNext()) break;
        double bounds1 = boundsIter.getDoubleNext();
        if (!boundsIter.hasNext()) break;
        double bounds2 = boundsIter.getDoubleNext();
        f.format(
            "%s (%s,%s)%n",
            makeCalendarDateStringOrMissing(cdu, coordValue),
            makeCalendarDateStringOrMissing(cdu, bounds1),
            makeCalendarDateStringOrMissing(cdu, bounds2));
      }

    } else {
      ArrayDouble.D2 coords = axis2D.getCoordValuesArray();
      IndexIterator coordIter = coords.getIndexIterator();
      while (coordIter.hasNext()) {
        double coordValue = coordIter.getDoubleNext();
        f.format("%s%n", makeCalendarDateStringOrMissing(cdu, coordValue));
      }
    }

    infoTA.appendLine(f.toString());
  }
Example #16
0
  public void saveFile() {
    try {
      cardFormatter = new Formatter(currentFile);
    } catch (Exception e) {
      System.out.print("That File doesn't exist");
    }
    cardFormatter.format("%s%n", currentPlayer.getName());
    cardFormatter.format("%d%n", currentPlayer.getTotalCardsOwned());
    cardFormatter.format("%d%n", currentPlayer.getNumberOfCardsInDeck());
    cardFormatter.format("%d%n", currentPlayer.getWins());
    cardFormatter.format("%d%n", currentPlayer.getLosses());
    cardFormatter.format("%d%n", currentPlayer.getMoney());

    Card[] deck = currentPlayer.getDeck();

    for (int count = 0; count < deck.length; count++) {
      cardFormatter.format("%d%n", deck[count].getCardIndex());
      cardFormatter.format("%b%n", deck[count].getInDeck());
    }
    cardFormatter.close();
  }
Example #17
0
 private String tryGrid(VariableEnhanced v) {
   Formatter buff = new Formatter();
   buff.format("%s:", v.getFullName());
   List<CoordinateSystem> csList = v.getCoordinateSystems();
   if (csList.size() == 0) buff.format(" No Coord System found");
   else {
     for (CoordinateSystem cs : csList) {
       buff.format("%s:", cs.getName());
       if (GridCoordSys.isGridCoordSys(buff, cs, v)) {
         buff.format("GRID OK%n");
       } else {
         buff.format(" NOT GRID");
       }
     }
   }
   return buff.toString();
 }