/**
   * function to compute hazard curves and make the lat/lon files
   *
   * @param imtLogFlag
   * @param xValues
   * @param griddedSites
   * @param imr
   * @param eqkRupForecast
   * @param mapParametersInfo
   */
  private void calculate(
      boolean imtLogFlag,
      double[] xValues,
      SitesInGriddedRegion sites,
      ScalarIntensityMeasureRelationshipAPI imr,
      EqkRupForecast eqkRupForecast,
      String mapParametersInfo,
      String email) {
    Site site;
    this.xLogFlag = imtLogFlag;
    int numSites = sites.getRegion().getNodeCount();
    try {
      HazardCurveCalculator hazCurveCalc = new HazardCurveCalculator();
      // hazCurveCalc.showProgressBar(false);

      int numPoints = xValues.length;
      for (int j = 0; j < numSites; ++j) {
        site = sites.getSite(j);
        // make and initialize the haz function
        ArbitrarilyDiscretizedFunc hazFunction = new ArbitrarilyDiscretizedFunc();
        this.initX_Values(hazFunction, xValues);
        hazCurveCalc.getHazardCurve(hazFunction, site, imr, eqkRupForecast);
        String lat = decimalFormat.format(site.getLocation().getLatitude());
        String lon = decimalFormat.format(site.getLocation().getLongitude());

        hazFunction = this.toggleHazFuncLogValues(hazFunction, xValues);
        try {
          FileWriter fr = new FileWriter(DATASETS_PATH + newDir + "/" + lat + "_" + lon + ".txt");
          for (int i = 0; i < numPoints; ++i)
            fr.write(hazFunction.getX(i) + " " + hazFunction.getY(i) + "\n");
          fr.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // make the metadata.data and sites.data files
    try {
      FileWriter fr = new FileWriter(DATASETS_PATH + newDir + "/metadata.txt");
      fr.write(mapParametersInfo + "\n");
      fr.close();
      fr = new FileWriter(DATASETS_PATH + newDir + "/sites.txt");
      fr.write(
          sites.getRegion().getMinLat()
              + " "
              + sites.getRegion().getMaxLat()
              + " "
              + sites.getRegion().getSpacing()
              + "\n"
              + sites.getRegion().getMinLon()
              + " "
              + sites.getRegion().getMaxLon()
              + " "
              + sites.getRegion().getSpacing()
              + "\n");
      fr.close();
      if (email != null || !email.equals("")) {
        HazardMapCalcPostProcessing mapPostProcessing =
            new HazardMapCalcPostProcessing(
                numSites,
                email,
                newDir,
                java.util.Calendar.getInstance().getTime().toString().replaceAll(" ", "_"));
      }

    } catch (IOException ee) {
      ee.printStackTrace();
    }
  }