/**
   * This class is designed to be a stand-alone program to validate that the DataSet.properties file
   * contains valid information for all datasets listed by validDataSets in DataSet.properties.
   * Don't run this on the coastwatch computer.
   *
   * @param args is ignored
   */
  public static void main(String args[]) throws Exception {

    String2.log("ValidatDataSetProperties (testing DataSet.properties validDataSets");

    // find a browser properties file (e.g., CWBrowser.properties)
    String contextDirectory = SSR.getContextDirectory(); // with / separator and / at the end
    String[] propList =
        RegexFilenameFilter.list(
            contextDirectory + "WEB-INF/classes/gov/noaa/pfel/coastwatch/", ".+\\.properties");
    int which = -1;
    for (int i = 0; i < propList.length; i++) {
      if (!propList[i].equals("DataSet.properties")) {
        which = i;
        break;
      }
    }
    Test.ensureNotEqual(
        which,
        -1,
        String2.ERROR
            + ": No non-DataSet.properties properties files found in\n"
            + contextDirectory
            + "WEB-INF/classes/gov/noaa/pfel/coastwatch/.\n"
            + ".properties files="
            + String2.toCSSVString(propList));

    FileNameUtility fnu =
        new FileNameUtility(
            "gov.noaa.pfel.coastwatch." + File2.getNameNoExtension(propList[which]));
    ResourceBundle2 dataSetRB2 = new ResourceBundle2("gov.noaa.pfel.coastwatch.DataSet");
    String infoUrlBaseUrl = dataSetRB2.getString("infoUrlBaseUrl", null);
    String tDataSetList[] = String2.split(dataSetRB2.getString("validDataSets", null), '`');
    int nDataSets = tDataSetList.length;
    // Test.ensureEqual(nDataSets, 228, "nDataSets"); //useful to me, but Dave can't add dataset
    // without recompiling this
    String2.log("  testing " + nDataSets + " data sets");
    boolean excessivelyStrict = true;
    for (int i = OneOf.N_DUMMY_GRID_DATASETS;
        i < nDataSets;
        i++) { // "2" in order to skip 0=OneOf.NO_DATA, 1=BATHYMETRY
      String seven = tDataSetList[i];
      Test.ensureTrue(seven != null && seven.length() > 0, "  tDataSetList[" + i + "] is ''.");
      fnu.ensureValidDataSetProperties(seven, excessivelyStrict);
      String infoUrl = dataSetRB2.getString(seven + "InfoUrl", null);
      Test.ensureNotNull(infoUrl, seven + "InfoUrl is null.");
      SSR.getUrlResponse(
          infoUrlBaseUrl
              + infoUrl); // on all computers except coastwatch, all are accessible as urls
    }
    String2.log(
        "  ValidatDataSetProperties successfully tested n="
            + nDataSets
            + " last="
            + tDataSetList[nDataSets - 1]);
  }
예제 #2
0
  /**
   * Saves an image as a gif. Currently this uses ImageMagick's "convert" (Windows or Linux) because
   * it does the best job at color reduction (and is fast and is cross-platform). This will
   * overwrite an existing file.
   *
   * @param bi
   * @param fullGifName but without the .gif at the end
   * @throws Exception if trouble
   */
  public static void saveAsGif(BufferedImage bi, String fullGifName) throws Exception {

    // POLICY: because this procedure may be used in more than one thread,
    // do work on unique temp files names using randomInt, then rename to proper file name.
    // If procedure fails half way through, there won't be a half-finished file.
    int randomInt = Math2.random(Integer.MAX_VALUE);

    // save as .bmp     (note: doesn't support transparent pixels)
    long time = System.currentTimeMillis();
    if (verbose) String2.log("SgtUtil.saveAsGif");
    ImageIO.write(bi, "bmp", new File(fullGifName + randomInt + ".bmp"));
    if (verbose) String2.log("  make .bmp done. time=" + (System.currentTimeMillis() - time));

    // "convert" to .gif
    SSR.dosOrCShell(
        "convert " + fullGifName + randomInt + ".bmp" + " " + fullGifName + randomInt + ".gif", 30);
    File2.delete(fullGifName + randomInt + ".bmp");

    // try fancy color reduction algorithms
    // Image2.saveAsGif(Image2.reduceTo216Colors(bi), fullGifName + randomInt + ".gif");

    // try dithering
    // Image2.saveAsGif216(bi, fullGifName + randomInt + ".gif", true);

    // last step: rename to final gif name
    File2.rename(fullGifName + randomInt + ".gif", fullGifName + ".gif");

    if (verbose)
      String2.log(
          "SgtUtil.saveAsGif done. TOTAL TIME=" + (System.currentTimeMillis() - time) + "\n");
  }
예제 #3
0
  /**
   * Saves an image as a gif. Currently this uses ImageMagick's "convert" (Windows or Linux) because
   * it does the best job at color reduction (and is fast and is cross-platform). This will
   * overwrite an existing file.
   *
   * @param bi
   * @param transparent the color to be made transparent
   * @param fullGifName but without the .gif at the end
   * @throws Exception if trouble
   */
  public static void saveAsTransparentGif(BufferedImage bi, Color transparent, String fullGifName)
      throws Exception {

    // POLICY: because this procedure may be used in more than one thread,
    // do work on unique temp files names using randomInt, then rename to proper file name.
    // If procedure fails half way through, there won't be a half-finished file.
    int randomInt = Math2.random(Integer.MAX_VALUE);

    // convert transparent color to be transparent
    long time = System.currentTimeMillis();
    Image image = Image2.makeImageBackgroundTransparent(bi, transparent, 10000);

    // convert image back to bufferedImage
    bi = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.getGraphics();
    g.drawImage(image, 0, 0, bi.getWidth(), bi.getHeight(), null);
    image = null; // encourage garbage collection

    // save as png
    int random = Math2.random(Integer.MAX_VALUE);
    ImageIO.write(bi, "png", new File(fullGifName + randomInt + ".png"));

    // "convert" to .gif
    SSR.dosOrCShell(
        "convert " + fullGifName + randomInt + ".png" + " " + fullGifName + randomInt + ".gif", 30);
    File2.delete(fullGifName + randomInt + ".png");

    // try fancy color reduction algorithms
    // Image2.saveAsGif(Image2.reduceTo216Colors(bi), fullGifName + randomInt + ".gif");

    // try dithering
    // Image2.saveAsGif216(bi, fullGifName + randomInt + ".gif", true);

    // last step: rename to final gif name
    File2.rename(fullGifName + randomInt + ".gif", fullGifName + ".gif");

    if (verbose)
      String2.log(
          "SgtUtil.saveAsTransparentGif TIME=" + (System.currentTimeMillis() - time) + "\n");
  }
예제 #4
0
  /**
   * This gets the data from CWDataBrowserReset (if any is available)
   *
   * @return true if reset info was successfully retrieved
   */
  public boolean getDataFromReset() {
    // is there no resetThread?
    if (resetThread == null) return false;

    // is the resetThread still running?
    if (resetThread.isAlive()) return false;

    // did the resetThread throw an exception?
    String2.log(cwDataBrowserReset.runInfo.toString());
    if (cwDataBrowserReset.runError.length() > 0) {
      // error already printed to Tomcat's log
      // there is nothing more to be done
      // keep using old data
      // send email to Bob Simons?
      cwDataBrowserReset = null;
      resetThread = null;
      return false;
    }

    // store dataSet info
    activeDataSetOptions = cwDataBrowserReset.activeDataSetOptions;
    activeDataSetTitles = cwDataBrowserReset.activeDataSetTitles;
    activeDataSetContents = cwDataBrowserReset.activeDataSetContents;
    dataSet.setOptions(activeDataSetOptions); // 1 time only; doesn't change till next reset()
    dataSet.setTitles(activeDataSetTitles); // 1 time only; doesn't change till next reset()
    if (verbose)
      String2.log("activeDataSetTitles: " + String2.toNewlineString(activeDataSetTitles));

    // print lots of useful information
    String2.log(
        "\n"
            + String2.makeString('*', 80)
            + "\nCWDataBrowser.getDataFromReset "
            + Calendar2.getCurrentISODateTimeStringLocal());
    String2.log("CWDataBrowser construction was at " + constructorDateTime + ".  Since then...\n");
    String2.log("Data files found which have matching .gif files:");
    String2.log(getUsageStatistics());
    String2.log("  number of page requests initiated since construction: " + nRequestsInitiated);
    String2.log("  number of page requests completed since construction: " + nRequestsCompleted);
    if (nRequestsInitiated > 0) {
      DecimalFormat percent = new DecimalFormat("##0.000");
      double nRequests = nRequestsInitiated / 100.0;
      String2.log("Data Set Usage:");
      for (int i = 0; i < dataSetOptions.length; i++)
        String2.log(
            String2.right(percent.format(dataSetRequests[i] / nRequests), 9)
                + "% were for "
                + dataSetOptions[i]);
      String2.log("Time Period Usage:");
      for (int i = 0; i < timePeriodOptions.length; i++)
        String2.log(
            String2.right(percent.format(timePeriodRequests[i] / nRequests), 9)
                + "% were for "
                + timePeriodOptions[i]);
      String2.log("Region Usage:");
      for (int i = 0; i < regionOptions.length; i++)
        String2.log(
            String2.right(percent.format(regionRequests[i] / nRequests), 9)
                + "% were for "
                + regionOptions[i]);
    }

    String2.log(
        SSR.getTopN(printTopNMostRequested, " Most Requested .gif files", requestedFilesMap));

    // data was successfully gathered from CWDataBrowserReset
    resetThread = null;
    cwDataBrowserReset = null;
    return true;
  }