Displaying differences for changeset
 
display as  

src/java/m/rhem/model/Parameter.java

@@ -22,425 +22,459 @@
  */
 public class Parameter {
 
-    private static final String DEFAULT_DOUBLE_PRECISION_FORMAT = "%.14f";
-    private static final String DEFAULT_DOUBLE_FORMAT = "%.6f";
+  private static final String DEFAULT_DOUBLE_PRECISION_FORMAT = "%.14f";
+  private static final String DEFAULT_DOUBLE_FORMAT = "%.6f";
 
-    private static final double CLEN_MULTIPLIER = 2.5;
+  private static final double CLEN_MULTIPLIER = 2.5;
 
-    protected String clen;
-    protected String diams;
-    protected String density;
+  protected String clen;
+  protected String diams;
+  protected String density;
 
-    protected String len, chezy, rchezy;
-    protected String sl, sx;
-    protected String cv, sat, kss, komega, kcm, ke, adf, alf, bare;
+  protected String len, chezy, rchezy;
+  protected String sl, sx;
+  protected String cv, sat, kss, komega, kcm, ke, adf, alf, bare;
 
-    protected String g, dist, por;
-    protected String fract;
+  protected String g, dist, por;
+  protected String fract;
 
-    private AoA aoa = null;
-    private double slopeLength = 0.0;
+  private AoA aoa = null;
+  private double slopeLength = 0.0;
 
-    public Parameter(String diams, String density, String len,
-            String chezy, String rchezy, String sl, String sx, String cv,
-            String sat, String kss, String komega, String kcm, String ke,
-            String adf, String alf, String bare, String g, String dist,
-            String por, String fract) {
-        this.diams = diams;
-        this.density = density;
-        this.len = len;
-        this.chezy = chezy;
-        this.rchezy = rchezy;
-        this.sl = sl;
-        this.sx = sx;
-        this.cv = cv;
-        this.sat = sat;
-        this.kss = kss;
-        this.komega = komega;
-        this.kcm = kcm;
-        this.ke = ke;
-        this.adf = adf;
-        this.alf = alf;
-        this.bare = bare;
-        this.g = g;
-        this.dist = dist;
-        this.por = por;
-        this.fract = fract;
-        this.aoa = null;
 
-        this.clen = String.valueOf(Double.parseDouble(len) * CLEN_MULTIPLIER);
+  public Parameter(String diams, String density, String len,
+      String chezy, String rchezy, String sl, String sx, String cv,
+      String sat, String kss, String komega, String kcm, String ke,
+      String adf, String alf, String bare, String g, String dist,
+      String por, String fract) {
+    this.diams = diams;
+    this.density = density;
+    this.len = len;
+    this.chezy = chezy;
+    this.rchezy = rchezy;
+    this.sl = sl;
+    this.sx = sx;
+    this.cv = cv;
+    this.sat = sat;
+    this.kss = kss;
+    this.komega = komega;
+    this.kcm = kcm;
+    this.ke = ke;
+    this.adf = adf;
+    this.alf = alf;
+    this.bare = bare;
+    this.g = g;
+    this.dist = dist;
+    this.por = por;
+    this.fract = fract;
+    this.aoa = null;
+
+    this.clen = String.valueOf(Double.parseDouble(len) * CLEN_MULTIPLIER);
+  }
+
+
+  public Parameter(AoA aoa) throws ServiceException {
+    if (null != aoa) {
+      this.cv = "1.00";
+      this.sat = "0.25;";
+      this.komega = "0.000007747";
+      this.kcm = "0.00029936430000";
+      this.adf = "0.0";
+      this.alf = "0.8";
+      this.bare = "0 ! INACTIVE";
+      this.aoa = aoa;
+      this.slopeLength = aoa.slopeLength;
+    } else {
+      throw new ServiceException("AoA specified was NULL; Cannot continue.");
+    }
+  }
+
+
+  protected String formatPrecisionDouble(double value) {
+    return formatDoubleString(value, DEFAULT_DOUBLE_PRECISION_FORMAT);
+  }
+
+
+  public static String formatDouble(double value) {
+    return formatDoubleString(value, DEFAULT_DOUBLE_FORMAT);
+  }
+
+
+  private static String formatDoubleString(double value, String format) {
+    return String.format(format, value);
+  }
+
+
+  public void computeParameters(Connection connection) throws SQLException, ServiceException {
+    if (null == aoa) {
+      throw new ServiceException("Invalid AoA specified in the Parameter object.");
+    }
+    // canopy cover for grass
+//        double grasscanopycover = aoa.bunchGgrassCanopyCover + aoa.forbsCanopyCover + aoa.sodGrassCanopyCover;
+    // TOTAL CANOPY COVER
+    double totalcanopycover = aoa.bunchGgrassCanopyCover + aoa.forbsCanopyCover + aoa.shrubsCanopyCover + aoa.sodGrassCanopyCover;
+    // TOTAL GROUND COVER
+    double totalgroundcover = aoa.rockCover + aoa.basalCover + aoa.litterCover + aoa.cryptogamsCover;
+
+    if (aoa.unit == 2) {
+      slopeLength = aoa.slopeLength * 0.3048;
+    } else {
+      slopeLength = aoa.slopeLength;
     }
 
-    public Parameter(AoA aoa) throws ServiceException {
-        if (null != aoa) {
-            this.cv = "1.00";
-            this.sat = "0.25;";
-            this.komega = "0.000007747";
-            this.kcm = "0.00029936430000";
-            this.adf = "0.0";
-            this.alf = "0.8";
-            this.bare = "0 ! INACTIVE";
-            this.aoa = aoa;
-            this.slopeLength = aoa.slopeLength;
-        } else {
-            throw new ServiceException("AoA specified was NULL; Cannot continue.");
+    len = String.valueOf(slopeLength);
+
+    computeChezyValue();
+    computeSlSxValues();
+    computeClenValue();
+    getValuesFmDb(connection);
+    computeKeValue(totalcanopycover);
+    computeKssValue(totalcanopycover, totalgroundcover);
+  }
+
+
+  public void computeChezyValue() {
+    double ft = (-1 * 0.109) + (1.425 * aoa.litterCover)
+        + (0.442 * aoa.rockCover) + (1.764 * (aoa.basalCover
+        + aoa.cryptogamsCover)) + (2.068 * aoa.slopeSteepness);
+    ft = Math.pow(10, ft);
+    if (ft != 0.0) {
+      rchezy = chezy = String.valueOf(Math.pow((8 * 9.8) / ft, 0.5));
+    } else {
+      throw new ArithmeticException("Divide by zero for ft value while computing ChezyValue; Cannot continue.");
+    }
+  }
+
+
+  public void computeSlSxValues() throws ServiceException {
+    if (null != aoa) {
+      switch (aoa.slopeShape.toLowerCase()) {
+        case "uniform":
+          sl = fmt(aoa.slopeSteepness) + ", " + fmt(aoa.slopeSteepness);
+          sx = 0.00 + ", " + 1.00;
+          break;
+        case "convex":
+          sl = 0.001 + ", " + fmt(aoa.slopeSteepness * 2);
+          sx = 0.00 + ", " + 1.00;
+          break;
+        case "concave":
+          sl = fmt(aoa.slopeSteepness * 2) + ", " + 0.001;
+          sx = 0.00 + ", " + 1.00;
+          break;
+        case "s-shaped":
+          sl = 0.001 + ", " + fmt(aoa.slopeSteepness * 2) + ", " + 0.001;
+          sx = 0.00 + ", " + 0.50 + ", " + 1.00;
+          break;
+        default:
+          throw new ServiceException("Invalid slope shape, " + aoa.slopeShape + ", specified for this AoA; Cannot continue.");
+      }
+    } else {
+      throw new ServiceException("No AoA object was found; Canot contiue.");
+    }
+  }
+
+  // format a double and avoid scientific notation for small values.
+
+  public static String fmt(double d) {
+    // DecimalFormat might not be thread safe!
+    DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
+    df.setMaximumFractionDigits(340);
+    return df.format(d);
+  }
+
+
+  public void computeClenValue() {
+    clen = String.valueOf(slopeLength * CLEN_MULTIPLIER);
+  }
+
+
+  public void getValuesFmDb(Connection connection) throws SQLException {
+    try (Statement statement = connection.createStatement()) {
+      try (ResultSet resultSet = statement.executeQuery(DBQueries.RunRHEMQuery01(aoa.soilTexture))) {
+        while (resultSet.next()) {
+          double diam1 = resultSet.getDouble("clay_diameter");
+          double diam2 = resultSet.getDouble("silt_diameter");
+          double diam3 = resultSet.getDouble("small_aggregates_diameter");
+          double diam4 = resultSet.getDouble("large_aggregates_diameter");
+          double diam5 = resultSet.getDouble("sand_diameter");
+          diams = formatDouble(diam1) + " "
+              + formatDouble(diam2) + " "
+              + formatDouble(diam3) + " "
+              + formatDouble(diam4) + " "
+              + formatDouble(diam5);
+          double density1 = resultSet.getDouble("clay_specific_gravity");
+          double density2 = resultSet.getDouble("silt_specific_gravity");
+          double density3 = resultSet.getDouble("small_aggregates_specific_gravity");
+          double density4 = resultSet.getDouble("large_aggregates_specific_gravity");
+          double density5 = resultSet.getDouble("sand_specific_gravity");
+          density = formatDouble(density1) + " "
+              + formatDouble(density2) + " "
+              + formatDouble(density3) + " "
+              + formatDouble(density4) + " "
+              + formatDouble(density5);
+          g = formatDouble(resultSet.getDouble("mean_matric_potential"));
+          dist = formatDouble(resultSet.getDouble("pore_size_distribution"));
+          por = formatDouble(resultSet.getDouble("mean_porosity"));
+          double fract1 = resultSet.getDouble("clay_fraction");
+          double fract2 = resultSet.getDouble("silt_fraction");
+          double fract3 = resultSet.getDouble("small_aggregates_fraction");
+          double fract4 = resultSet.getDouble("large_aggregates_fraction");
+          double fract5 = resultSet.getDouble("sand_fraction");
+          fract = formatDouble(fract1) + " "
+              + formatDouble(fract2) + " "
+              + formatDouble(fract3) + " "
+              + formatDouble(fract4) + " "
+              + formatDouble(fract5);
         }
+      }
+    }
+  }
+
+
+  private void computeKeValue(double totalcanopycover) throws ServiceException {
+    double Keb = 0;
+    if ((null != aoa) && (!aoa.soilTexture.isEmpty())) {
+      switch (aoa.soilTexture) {
+        case "Sand":
+          Keb = 24 * Math.exp(0.3483 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Loamy Sand":
+          Keb = 10 * Math.exp(0.8755 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Sandy Loam":
+          Keb = 5 * Math.exp(1.1632 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Loam":
+          Keb = 2.5 * Math.exp(1.5686 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Silt Loam":
+          Keb = 1.2 * Math.exp(2.0149 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Silt":
+          Keb = 1.2 * Math.exp(2.0149 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Sandy Clay Loam":
+          Keb = 0.80 * Math.exp(2.1691 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Clay Loam":
+          Keb = 0.50 * Math.exp(2.3026 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Silty Clay Loam":
+          Keb = 0.40 * Math.exp(2.1691 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Sandy Clay":
+          Keb = 0.30 * Math.exp(2.1203 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Silty Clay":
+          Keb = 0.25 * Math.exp(1.7918 * (aoa.basalCover + aoa.litterCover));
+          break;
+        case "Clay":
+          Keb = 0.2 * Math.exp(1.3218 * (aoa.basalCover + aoa.litterCover));
+          break;
+        default:
+          throw new ServiceException("Invalid soilTexture specified in the AoA, " + aoa.soilTexture);
+      }
+    } else {
+      throw new ServiceException("No soil Texture specified, cannot continue");
+    }
+    double weightedKe = 0;
+
+    // calculate weighted Ke and Kss values for the vegetation types that have non-zero values
+    if (totalcanopycover != 0.0) {
+      weightedKe = weightedKe + ((aoa.shrubsCanopyCover / totalcanopycover) * (Keb * 1.2));
+      weightedKe = weightedKe + ((aoa.sodGrassCanopyCover / totalcanopycover) * (Keb * 0.8));
+      weightedKe = weightedKe + ((aoa.bunchGgrassCanopyCover / totalcanopycover) * (Keb * 1.0));
+      weightedKe = weightedKe + ((aoa.forbsCanopyCover / totalcanopycover) * (Keb * 1.0));
+    } else {
+      weightedKe = Keb;
+    }
+    ke = String.valueOf(weightedKe);
+  }
+
+
+  public void computeKssValue(double totalcanopycover, double totalgroundcover) {
+    // Kss variables
+    double Kss_Seg_Bunch, Kss_Seg_Sod, Kss_Seg_Shrub, Kss_Seg_Shrub_0, Kss_Seg_Forbs;
+    double Kss_Average = 0.0;  //If totalcanopycover is 0, then this value will never be changed, but also not used.
+    double Kss_Final;
+
+    // 1)
+    //   a) CALCULATE KSS FOR EACH VEGETATION COMMUNITY USING TOTAL FOLIAR COVER
+    //        A)   BUNCH GRASS
+    if (totalgroundcover < 0.475) {
+      Kss_Seg_Bunch = 4.154 + 2.5535 * aoa.slopeSteepness
+          - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Bunch = Math.pow(10, Kss_Seg_Bunch);
+
+      Kss_Seg_Sod = 4.2169 + 2.5535 * aoa.slopeSteepness
+          - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Sod = Math.pow(10, Kss_Seg_Sod);
+
+      Kss_Seg_Shrub = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Shrub = Math.pow(10, Kss_Seg_Shrub);
+
+      Kss_Seg_Forbs = 4.1106 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Forbs = Math.pow(10, Kss_Seg_Forbs);
+
+      Kss_Seg_Shrub_0 = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover;
+      Kss_Seg_Shrub_0 = Math.pow(10, Kss_Seg_Shrub_0);
+
+    } else {
+      Kss_Seg_Bunch = 3.1726975 + 2.5535 * aoa.slopeSteepness
+          - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Bunch = Math.pow(10, Kss_Seg_Bunch);
+
+      Kss_Seg_Sod = 3.2355975 + 2.5535 * aoa.slopeSteepness
+          - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Sod = Math.pow(10, Kss_Seg_Sod);
+
+      Kss_Seg_Shrub = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Shrub = Math.pow(10, Kss_Seg_Shrub);
+
+      Kss_Seg_Forbs = 3.1292975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
+      Kss_Seg_Forbs = Math.pow(10, Kss_Seg_Forbs);
+
+      Kss_Seg_Shrub_0 = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover;
+      Kss_Seg_Shrub_0 = Math.pow(10, Kss_Seg_Shrub_0);
     }
 
-    protected String formatPrecisionDouble(double value) {
-        return formatDoubleString(value, DEFAULT_DOUBLE_PRECISION_FORMAT);
+    if (totalcanopycover > 0 && totalcanopycover < 0.02) {
+      Kss_Average = totalcanopycover / 0.02 * ((aoa.shrubsCanopyCover / totalcanopycover) * Kss_Seg_Shrub
+          + (aoa.sodGrassCanopyCover / totalcanopycover) * Kss_Seg_Sod
+          + (aoa.bunchGgrassCanopyCover / totalcanopycover) * Kss_Seg_Bunch
+          + (aoa.forbsCanopyCover / totalcanopycover) * Kss_Seg_Forbs)
+          + (0.02 - totalcanopycover) / 0.02 * Kss_Seg_Shrub_0;
+    } else {
+      if (totalcanopycover >= 0.02) {
+        Kss_Average = (aoa.shrubsCanopyCover / totalcanopycover) * Kss_Seg_Shrub
+            + (aoa.sodGrassCanopyCover / totalcanopycover) * Kss_Seg_Sod
+            + (aoa.bunchGgrassCanopyCover / totalcanopycover) * Kss_Seg_Bunch
+            + (aoa.forbsCanopyCover / totalcanopycover) * Kss_Seg_Forbs;
+      } //  Otherwise, see below, if statement in step 3, don't ever use Kss_Average in this case and won't divide anywhere else by totalcanopycover.            
     }
 
-    public static String formatDouble(double value) {
-        return formatDoubleString(value, DEFAULT_DOUBLE_FORMAT);
+    // 3) CALCULATE KSS USED FOR RHEM
+    if (totalcanopycover == 0.0) {
+      if (totalgroundcover < 0.475) {
+        Kss_Final = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover;
+        Kss_Final = Math.pow(10, Kss_Final);
+      } else {
+        Kss_Final = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover;
+        Kss_Final = Math.pow(10, Kss_Final);
+      }
+    } else if (totalgroundcover < 0.475) {
+      Kss_Final = totalgroundcover / 0.475 * Kss_Average + (0.475 - totalgroundcover) / 0.475 * Kss_Seg_Shrub;
+    } else {
+      Kss_Final = Kss_Average;
     }
+    // if aoa.sar is 0, the last expr will be 0
+    Kss_Final = ((Kss_Final * 1.3) * 2.0) + (711.0 * aoa.sar);
+    kss = String.valueOf(Kss_Final);
+  }
 
-    private static String formatDoubleString(double value, String format) {
-        return String.format(format, value);
-    }
 
-    public void computeParameters(Connection connection) throws SQLException, ServiceException {
-        if (null == aoa) {
-            throw new ServiceException("Invalid AoA specified in the Parameter object.");
-        }
-        // canopy cover for grass
-//        double grasscanopycover = aoa.bunchGgrassCanopyCover + aoa.forbsCanopyCover + aoa.sodGrassCanopyCover;
-        // TOTAL CANOPY COVER
-        double totalcanopycover = aoa.bunchGgrassCanopyCover + aoa.forbsCanopyCover + aoa.shrubsCanopyCover + aoa.sodGrassCanopyCover;
-        // TOTAL GROUND COVER
-        double totalgroundcover = aoa.rockCover + aoa.basalCover + aoa.litterCover + aoa.cryptogamsCover;
+  public String getClen() {
+    return clen;
+  }
 
-        if (aoa.unit == 2) {
-            slopeLength = aoa.slopeLength * 0.3048;
-        } else {
-            slopeLength = aoa.slopeLength;
-        }
 
-        len = String.valueOf(slopeLength);
+  public String getDiams() {
+    return diams;
+  }
 
-        computeChezyValue();
-        computeSlSxValues();
-        computeClenValue();
-        getValuesFmDb(connection);
-        computeKeValue(totalcanopycover);
-        computeKssValue(totalcanopycover, totalgroundcover);
-    }
 
-    public void computeChezyValue() {
-        double ft = (-1 * 0.109) + (1.425 * aoa.litterCover)
-                + (0.442 * aoa.rockCover) + (1.764 * (aoa.basalCover
-                + aoa.cryptogamsCover)) + (2.068 * aoa.slopeSteepness);
-        ft = Math.pow(10, ft);
-        if (ft != 0.0) {
-            rchezy = chezy = String.valueOf(Math.pow((8 * 9.8) / ft, 0.5));
-        } else {
-            throw new ArithmeticException("Divide by zero for ft value while computing ChezyValue; Cannot continue.");
-        }
-    }
+  public String getDensity() {
+    return density;
+  }
 
-    public void computeSlSxValues() throws ServiceException {
-        if (null != aoa) {
-            switch (aoa.slopeShape.toLowerCase()) {
-                case "uniform":
-                    sl = fmt(aoa.slopeSteepness) + ", " + fmt(aoa.slopeSteepness);
-                    sx = 0.00 + ", " + 1.00;
-                    break;
-                case "convex":
-                    sl = 0.001 + ", " + fmt(aoa.slopeSteepness * 2);
-                    sx = 0.00 + ", " + 1.00;
-                    break;
-                case "concave":
-                    sl = fmt(aoa.slopeSteepness * 2) + ", " + 0.001;
-                    sx = 0.00 + ", " + 1.00;
-                    break;
-                case "s-shaped":
-                    sl = 0.001 + ", " + fmt(aoa.slopeSteepness * 2) + ", " + 0.001;
-                    sx = 0.00 + ", " + 0.50 + ", " + 1.00;
-                    break;
-                default:
-                    throw new ServiceException("Invalid slope shape, " + aoa.slopeShape + ", specified for this AoA; Cannot continue.");
-            }
-        } else {
-            throw new ServiceException("No AoA object was found; Canot contiue.");
-        }
-    }
 
-    // format a double and avoid scientific notation for small values.
-    public static String fmt(double d) {
-      // DecimalFormat might not be thread safe!
-      DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
-      df.setMaximumFractionDigits(340);
-      return df.format(d);
-    }
+  public String getLen() {
+    return len;
+  }
 
-    public void computeClenValue() {
-        clen = String.valueOf(slopeLength * CLEN_MULTIPLIER);
-    }
 
-    public void getValuesFmDb(Connection connection) throws SQLException {
-        try (Statement statement = connection.createStatement()) {
-            try (ResultSet resultSet = statement.executeQuery(DBQueries.RunRHEMQuery01(aoa.soilTexture))) {
-                while (resultSet.next()) {
-                    double diam1 = resultSet.getDouble("clay_diameter");
-                    double diam2 = resultSet.getDouble("silt_diameter");
-                    double diam3 = resultSet.getDouble("small_aggregates_diameter");
-                    double diam4 = resultSet.getDouble("large_aggregates_diameter");
-                    double diam5 = resultSet.getDouble("sand_diameter");
-                    diams = formatDouble(diam1) + " "
-                            + formatDouble(diam2) + " "
-                            + formatDouble(diam3) + " "
-                            + formatDouble(diam4) + " "
-                            + formatDouble(diam5);
-                    double density1 = resultSet.getDouble("clay_specific_gravity");
-                    double density2 = resultSet.getDouble("silt_specific_gravity");
-                    double density3 = resultSet.getDouble("small_aggregates_specific_gravity");
-                    double density4 = resultSet.getDouble("large_aggregates_specific_gravity");
-                    double density5 = resultSet.getDouble("sand_specific_gravity");
-                    density = formatDouble(density1) + " "
-                            + formatDouble(density2) + " "
-                            + formatDouble(density3) + " "
-                            + formatDouble(density4) + " "
-                            + formatDouble(density5);
-                    g = formatDouble(resultSet.getDouble("mean_matric_potential"));
-                    dist = formatDouble(resultSet.getDouble("pore_size_distribution"));
-                    por = formatDouble(resultSet.getDouble("mean_porosity"));
-                    double fract1 = resultSet.getDouble("clay_fraction");
-                    double fract2 = resultSet.getDouble("silt_fraction");
-                    double fract3 = resultSet.getDouble("small_aggregates_fraction");
-                    double fract4 = resultSet.getDouble("large_aggregates_fraction");
-                    double fract5 = resultSet.getDouble("sand_fraction");
-                    fract = formatDouble(fract1) + " "
-                            + formatDouble(fract2) + " "
-                            + formatDouble(fract3) + " "
-                            + formatDouble(fract4) + " "
-                            + formatDouble(fract5);
-                }
-            }
-        }
-    }
+  public String getChezy() {
+    return chezy;
+  }
 
-    private void computeKeValue(double totalcanopycover) throws ServiceException {
-        double Keb = 0;
-        if ((null != aoa) && (!aoa.soilTexture.isEmpty())) {
-            switch (aoa.soilTexture) {
-                case "Sand":
-                    Keb = 24 * Math.exp(0.3483 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Loamy Sand":
-                    Keb = 10 * Math.exp(0.8755 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Sandy Loam":
-                    Keb = 5 * Math.exp(1.1632 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Loam":
-                    Keb = 2.5 * Math.exp(1.5686 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Silt Loam":
-                    Keb = 1.2 * Math.exp(2.0149 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Silt":
-                    Keb = 1.2 * Math.exp(2.0149 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Sandy Clay Loam":
-                    Keb = 0.80 * Math.exp(2.1691 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Clay Loam":
-                    Keb = 0.50 * Math.exp(2.3026 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Silty Clay Loam":
-                    Keb = 0.40 * Math.exp(2.1691 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Sandy Clay":
-                    Keb = 0.30 * Math.exp(2.1203 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Silty Clay":
-                    Keb = 0.25 * Math.exp(1.7918 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                case "Clay":
-                    Keb = 0.2 * Math.exp(1.3218 * (aoa.basalCover + aoa.litterCover));
-                    break;
-                default:
-                    throw new ServiceException("Invalid soilTexture specified in the AoA, " + aoa.soilTexture);
-            }
-        } else {
-            throw new ServiceException("No soil Texture specified, cannot continue");
-        }
-        double weightedKe = 0;
 
-        // calculate weighted Ke and Kss values for the vegetation types that have non-zero values
-        if (totalcanopycover != 0.0) {
-            weightedKe = weightedKe + ((aoa.shrubsCanopyCover / totalcanopycover) * (Keb * 1.2));
-            weightedKe = weightedKe + ((aoa.sodGrassCanopyCover / totalcanopycover) * (Keb * 0.8));
-            weightedKe = weightedKe + ((aoa.bunchGgrassCanopyCover / totalcanopycover) * (Keb * 1.0));
-            weightedKe = weightedKe + ((aoa.forbsCanopyCover / totalcanopycover) * (Keb * 1.0));
-        } else {
-            weightedKe = Keb;
-        }
-        ke = String.valueOf(weightedKe);
-    }
+  public String getRchezy() {
+    return rchezy;
+  }
 
-    public void computeKssValue(double totalcanopycover, double totalgroundcover) {
-        // Kss variables
-        double Kss_Seg_Bunch, Kss_Seg_Sod, Kss_Seg_Shrub, Kss_Seg_Shrub_0, Kss_Seg_Forbs;
-        double Kss_Average = 0.0;  //If totalcanopycover is 0, then this value will never be changed, but also not used.
-        double Kss_Final;
 
-        // 1)
-        //   a) CALCULATE KSS FOR EACH VEGETATION COMMUNITY USING TOTAL FOLIAR COVER
-        //        A)   BUNCH GRASS
-        if (totalgroundcover < 0.475) {
-            Kss_Seg_Bunch = 4.154 + 2.5535 * aoa.slopeSteepness
-                    - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Bunch = Math.pow(10, Kss_Seg_Bunch);
+  public String getSl() {
+    return sl;
+  }
 
-            Kss_Seg_Sod = 4.2169 + 2.5535 * aoa.slopeSteepness
-                    - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Sod = Math.pow(10, Kss_Seg_Sod);
 
-            Kss_Seg_Shrub = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Shrub = Math.pow(10, Kss_Seg_Shrub);
+  public String getSx() {
+    return sx;
+  }
 
-            Kss_Seg_Forbs = 4.1106 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Forbs = Math.pow(10, Kss_Seg_Forbs);
 
-            Kss_Seg_Shrub_0 = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover;
-            Kss_Seg_Shrub_0 = Math.pow(10, Kss_Seg_Shrub_0);
+  public String getCv() {
+    return cv;
+  }
 
-        } else {
-            Kss_Seg_Bunch = 3.1726975 + 2.5535 * aoa.slopeSteepness
-                    - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Bunch = Math.pow(10, Kss_Seg_Bunch);
 
-            Kss_Seg_Sod = 3.2355975 + 2.5535 * aoa.slopeSteepness
-                    - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Sod = Math.pow(10, Kss_Seg_Sod);
+  public String getSat() {
+    return sat;
+  }
 
-            Kss_Seg_Shrub = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Shrub = Math.pow(10, Kss_Seg_Shrub);
 
-            Kss_Seg_Forbs = 3.1292975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover - 0.7822 * totalcanopycover;
-            Kss_Seg_Forbs = Math.pow(10, Kss_Seg_Forbs);
+  public String getKss() {
+    return kss;
+  }
 
-            Kss_Seg_Shrub_0 = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover;
-            Kss_Seg_Shrub_0 = Math.pow(10, Kss_Seg_Shrub_0);
-        }
-        
-        if (totalcanopycover > 0 && totalcanopycover < 0.02) {
-            Kss_Average = totalcanopycover / 0.02 * ((aoa.shrubsCanopyCover / totalcanopycover) * Kss_Seg_Shrub
-                    + (aoa.sodGrassCanopyCover / totalcanopycover) * Kss_Seg_Sod
-                    + (aoa.bunchGgrassCanopyCover / totalcanopycover) * Kss_Seg_Bunch
-                    + (aoa.forbsCanopyCover / totalcanopycover) * Kss_Seg_Forbs)
-                    + (0.02 - totalcanopycover) / 0.02 * Kss_Seg_Shrub_0;
-        } else {
-            if (totalcanopycover >= 0.02) {
-                Kss_Average = (aoa.shrubsCanopyCover / totalcanopycover) * Kss_Seg_Shrub
-                        + (aoa.sodGrassCanopyCover / totalcanopycover) * Kss_Seg_Sod
-                        + (aoa.bunchGgrassCanopyCover / totalcanopycover) * Kss_Seg_Bunch
-                        + (aoa.forbsCanopyCover / totalcanopycover) * Kss_Seg_Forbs;
-            } //  Otherwise, see below, if statement in step 3, don't ever use Kss_Average in this case and won't divide anywhere else by totalcanopycover.            
-        }
 
-        // 3) CALCULATE KSS USED FOR RHEM
-        if (totalcanopycover == 0.0) {
-            if (totalgroundcover < 0.475) {
-                Kss_Final = 4.2587 + 2.5535 * aoa.slopeSteepness - 2.547 * totalgroundcover;
-                Kss_Final = Math.pow(10, Kss_Final);
-            } else {
-                Kss_Final = 3.2773975 + 2.5535 * aoa.slopeSteepness - 0.4811 * totalgroundcover;
-                Kss_Final = Math.pow(10, Kss_Final);
-            }
-        } else if (totalgroundcover < 0.475) {
-            Kss_Final = totalgroundcover / 0.475 * Kss_Average + (0.475 - totalgroundcover) / 0.475 * Kss_Seg_Shrub;
-        } else {
-            Kss_Final = Kss_Average;
-        }
-        // if aoa.sar is 0, the last expr will be 0
-        Kss_Final = ((Kss_Final * 1.3) * 2.0) + (711.0 * aoa.sar);
-        kss = String.valueOf(Kss_Final);
-    }
+  public String getKomega() {
+    return komega;
+  }
 
-    public String getClen() {
-        return clen;
-    }
 
-    public String getDiams() {
-        return diams;
-    }
+  public String getKcm() {
+    return kcm;
+  }
 
-    public String getDensity() {
-        return density;
-    }
 
-    public String getLen() {
-        return len;
-    }
+  public String getKe() {
+    return ke;
+  }
 
-    public String getChezy() {
-        return chezy;
-    }
 
-    public String getRchezy() {
-        return rchezy;
-    }
+  public String getAdf() {
+    return adf;
+  }
 
-    public String getSl() {
-        return sl;
-    }
 
-    public String getSx() {
-        return sx;
-    }
+  public String getAlf() {
+    return alf;
+  }
 
-    public String getCv() {
-        return cv;
-    }
 
-    public String getSat() {
-        return sat;
-    }
+  public String getBare() {
+    return bare;
+  }
 
-    public String getKss() {
-        return kss;
-    }
 
-    public String getKomega() {
-        return komega;
-    }
+  public String getG() {
+    return g;
+  }
 
-    public String getKcm() {
-        return kcm;
-    }
 
-    public String getKe() {
-        return ke;
-    }
+  public String getDist() {
+    return dist;
+  }
 
-    public String getAdf() {
-        return adf;
-    }
 
-    public String getAlf() {
-        return alf;
-    }
+  public String getPor() {
+    return por;
+  }
 
-    public String getBare() {
-        return bare;
-    }
 
-    public String getG() {
-        return g;
-    }
-
-    public String getDist() {
-        return dist;
-    }
-
-    public String getPor() {
-        return por;
-    }
-
-    public String getFract() {
-        return fract;
-    }
+  public String getFract() {
+    return fract;
+  }
 
 }

src/java/m/rhem/model/RhemModel.java

@@ -4,11 +4,17 @@
 import csip.ServiceException;
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import org.apache.commons.io.FileUtils;
 
 /**
@@ -95,27 +101,34 @@
   }
 
 
-  public void generateStormFile(String cligen_db, double Ke) throws ServiceException {
+  public void generateStormFile(String cligen_db, double Ke) throws ServiceException, URISyntaxException {
     try {
       String cligenFileName;
       if (isIntl()) {
-        cligenFileName = "/international/" + climatestationId + ".txt";
-        URLConnection conn = new URL(cligen_db + cligenFileName).openConnection();
-        FileUtils.copyInputStreamToFile(conn.getInputStream(), new File(workSpaceDir, stormFileName));
+        try {
+          cligenFileName = "/international/" + climatestationId + ".txt";
+          URL url = new URL(cligen_db + cligenFileName);
+
+//          FileUtils.copyInputStreamToFile(url.openStream(), new File(workSpaceDir, stormFileName));
+//          File file = Paths.get(url.toURI()).toFile();
+          Files.createSymbolicLink(Paths.get(workSpaceDir.toString(), stormFileName), Paths.get(url.toURI()));
+
+        } catch (IOException E) {
+          throw new ServiceException("Climate Station not found: " + climatestationId);
+        }
         return;
-      } else {
-        cligenFileName = "/" + stateId.toLowerCase() + "/300yr/" + stateId + "_" + climatestationId + "_300yr.out";
       }
-      URLConnection conn = new URL(cligen_db + cligenFileName).openConnection();
 
-      String file = stateId + "_" + climatestationId + ".out";
-      File workSpaceFile = new File(workSpaceDir, file);
+      cligenFileName = "/" + stateId.toLowerCase() + "/300yr/" + stateId + "_" + climatestationId + "_300yr.out";
+      URL conn = new URL(cligen_db + cligenFileName);
 
-      FileUtils.copyInputStreamToFile(conn.getInputStream(), workSpaceFile);
+//      String file = stateId + "_" + climatestationId + ".out";
+//      File workSpaceFile = new File(workSpaceDir, file);
+//      FileUtils.copyInputStreamToFile(conn.openStream(), workSpaceFile);
 
       long counter = 0;
-      try (BufferedReader bufferedReader = new BufferedReader(new FileReader(workSpaceFile))) {
-//      try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
+//      try (BufferedReader bufferedReader = new BufferedReader(new FileReader(workSpaceFile))) {
+      try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.openStream()))) {
         File tempFile = new File(workSpaceDir, "tempSummaryFile.pre");
         try (PrintWriter writer = new PrintWriter(tempFile)) {
           for (int i = 0; i <= 17; i++) {

src/java/m/rhem/rhem01_runmodel/V1_0.java

@@ -35,6 +35,7 @@
 import csip.annotations.Description;
 import csip.annotations.Name;
 import static csip.annotations.ResourceType.EXECUTABLE;
+import java.net.URISyntaxException;
 import static m.rhem.rhem01_runmodel.V1_0.RHEM4_EXE;
 import static m.rhem.rhem01_runmodel.V1_0.RHEM4_INTL_EXE;
 import rhem.utils.DBQueries;
@@ -145,15 +146,15 @@
 
 
   @Override
-  public void doProcess() throws ServiceException {
+  public void doProcess() throws ServiceException, URISyntaxException {
     SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a");
-    Date now = new Date();
-    String today = sdf.format(now);
+    String today = sdf.format(new Date());
 
     String fileName = aoa.getScenarioName();
     if (fileName.length() > 15) {
       fileName = fileName.substring(0, 15);
     }
+    fileName = fileName.replace(' ', '_');
     parameterFileName = "scenario_input_" + fileName + ".par";
     stormFileName = "storm_input_" + fileName + ".pre";
     summaryFileName = "scenario_output_summary_" + fileName + ".sum";

src/java/m/rhem/rhem07_editparfile/V1_0.java

@@ -31,6 +31,7 @@
 import csip.annotations.Description;
 import csip.annotations.Name;
 import static csip.annotations.ResourceType.EXECUTABLE;
+import java.net.URISyntaxException;
 import rhem.utils.DBQueries;
 import rhem.utils.DBResources;
 
@@ -102,7 +103,7 @@
 
 
   @Override
-  public void doProcess() throws ServiceException {
+  public void doProcess() throws ServiceException, URISyntaxException {
 
     SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a");
     Date now = new Date();

web/WEB-INF/csip-defaults.json

@@ -1,5 +1,5 @@
 {  
-    "csip.context.version": "$version: 2.1.1 default 175 3fd0c2701713 2020-07-17 od, built at 2020-07-17 15:27 by od$",
+    "csip.context.version": "$version: 2.1.2 default 176 bdcaf0b18354 2020-07-17 od, built at 2020-07-17 17:18 by od$",
     "csip.archive.max.filesize": "1KB",
     "esd.db": "jdbc:sqlserver://129.82.20.129:1433;databaseName=esd;user=sa;password=csurams#1",
     "crdb.db": "jdbc:sqlserver://129.82.20.129:1433;databaseName=conservation_resources;user=sa;password=csurams#1",