Displaying differences for changeset
 
display as  

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

@@ -100,11 +100,11 @@
         + (0.442 * aoa.rockCover) + (1.764 * (aoa.basalCover
         + aoa.cryptogamsCover)) + (2.068 * aoa.slopeSteepness);
     ft = Math.pow(10, ft);
-    if (ft != 0.0) {
+    if (ft != 0.0)
       rchezy = chezy = String.valueOf(Math.pow((8 * 9.8) / ft, 0.5));
-    } else {
+    else
       throw new ArithmeticException("Divide by zero for ft value while computing ChezyValue; Cannot continue.");
-    }
+
   }
 
 
@@ -139,8 +139,8 @@
 
 
   private void getValuesFmDb(Connection con, AoA aoa) throws SQLException {
-    try (Statement st = con.createStatement()) {
-      try (ResultSet rs = st.executeQuery(DBResources.RunRHEMQuery01(aoa.soilTexture))) {
+    try ( Statement st = con.createStatement()) {
+      try ( ResultSet rs = st.executeQuery(DBResources.RunRHEMQuery01(aoa.soilTexture))) {
         while (rs.next()) {
           diams = formatDouble(rs.getDouble("clay_diameter")) + " "
               + formatDouble(rs.getDouble("silt_diameter")) + " "
@@ -215,10 +215,10 @@
 
     // calculate weighted Ke and Kss values for the vegetation types that have non-zero values
     if (totalcanopycover != 0.0) {
-      weightedKe += ((aoa.shrubsCanopyCover / totalcanopycover) * (Keb * 1.2));
-      weightedKe += ((aoa.sodGrassCanopyCover / totalcanopycover) * (Keb * 0.8));
-      weightedKe += ((aoa.bunchGgrassCanopyCover / totalcanopycover) * Keb);
-      weightedKe += ((aoa.forbsCanopyCover / totalcanopycover) * Keb);
+      weightedKe += (aoa.shrubsCanopyCover / totalcanopycover) * (Keb * 1.2);
+      weightedKe += (aoa.sodGrassCanopyCover / totalcanopycover) * (Keb * 0.8);
+      weightedKe += (aoa.bunchGgrassCanopyCover / totalcanopycover) * Keb;
+      weightedKe += (aoa.forbsCanopyCover / totalcanopycover) * Keb;
     } else {
       weightedKe = Keb;
     }
@@ -236,38 +236,18 @@
     double canopy = 0.7822 * totalcanopycover;
     if (totalgroundcover < 0.475) {
       double ground = 2.547 * totalgroundcover;
-
-      kssSegBunch = 4.154 + steepness - ground - canopy;
-      kssSegBunch = Math.pow(10, kssSegBunch);
-
-      kssSegSod = 4.2169 + steepness - ground - canopy;
-      kssSegSod = Math.pow(10, kssSegSod);
-
-      kssSegShrub = 4.2587 + steepness - ground - canopy;
-      kssSegShrub = Math.pow(10, kssSegShrub);
-
-      kssSegForbs = 4.1106 + steepness - ground - canopy;
-      kssSegForbs = Math.pow(10, kssSegForbs);
-
-      kssSegShrub0 = 4.2587 + steepness - ground;
-      kssSegShrub0 = Math.pow(10, kssSegShrub0);
-
+      kssSegBunch = Math.pow(10, 4.154 + steepness - ground - canopy);
+      kssSegSod = Math.pow(10, 4.2169 + steepness - ground - canopy);
+      kssSegShrub = Math.pow(10, 4.2587 + steepness - ground - canopy);
+      kssSegForbs = Math.pow(10, 4.1106 + steepness - ground - canopy);
+      kssSegShrub0 = Math.pow(10, 4.2587 + steepness - ground);
     } else {
       double ground = 0.4811 * totalgroundcover;
-      kssSegBunch = 3.1726975 + steepness - ground - canopy;
-      kssSegBunch = Math.pow(10, kssSegBunch);
-
-      kssSegSod = 3.2355975 + steepness - ground - canopy;
-      kssSegSod = Math.pow(10, kssSegSod);
-
-      kssSegShrub = 3.2773975 + steepness - ground - canopy;
-      kssSegShrub = Math.pow(10, kssSegShrub);
-
-      kssSegForbs = 3.1292975 + steepness - ground - canopy;
-      kssSegForbs = Math.pow(10, kssSegForbs);
-
-      kssSegShrub0 = 3.2773975 + steepness - ground;
-      kssSegShrub0 = Math.pow(10, kssSegShrub0);
+      kssSegBunch = Math.pow(10, 3.1726975 + steepness - ground - canopy);
+      kssSegSod = Math.pow(10, 3.2355975 + steepness - ground - canopy);
+      kssSegShrub = Math.pow(10, 3.2773975 + steepness - ground - canopy);
+      kssSegForbs = Math.pow(10, 3.1292975 + steepness - ground - canopy);
+      kssSegShrub0 = Math.pow(10, 3.2773975 + steepness - ground);
     }
 
     double kssAverage = 0.0;  //If totalcanopycover is 0, then this value will never be changed, but also not used.
@@ -304,7 +284,7 @@
       kssFinal = kssAverage;
     }
     // if aoa.sar is 0, the last expr will be 0
-    kssFinal = ((kssFinal * 1.3) * 2.0) + (711.0 * aoa.sar);
+    kssFinal = (kssFinal * 1.3 * 2.0) + (711.0 * aoa.sar);
     kss = String.valueOf(kssFinal);
   }
 

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

@@ -6,10 +6,8 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.net.URISyntaxException;
-import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.text.DecimalFormat;
@@ -26,6 +24,8 @@
  */
 public class RhemModel {
 
+  static final List<String> INTL = Arrays.asList("INTL_", "INTL_AF", "INTL_SA");
+
   String scenarioName;
   File workSpaceDir;
 
@@ -100,38 +100,41 @@
 
   public void generateStormFile(String cligen_db, double Ke, String stateId, String climatestationId)
       throws ServiceException, URISyntaxException {
+
     stateId = stateId.toUpperCase();
     try {
       if (isIntl(stateId)) {
+        // International stations
+        File cs = new File(cligen_db + "/" + stateId + "/" + climatestationId + ".txt");
+        if (!cs.exists())
+          throw new ServiceException("International climate station not found: " + climatestationId + ".txt for " + stateId);
         try {
-          File cs = new File(cligen_db + "/" + stateId + "/" + climatestationId + ".txt");
-          if (!cs.exists())
-            throw new ServiceException("Climate station not found: " + climatestationId + ".txt for " + stateId);
-
-//          URL u = new URL(cligen_db + "/international/" + climatestationId + ".txt");
           Files.createSymbolicLink(Paths.get(workSpaceDir.toString(), stormFileName), Paths.get(cs.toURI()));
         } catch (IOException E) {
-          throw new ServiceException("Climate station not found: " + climatestationId + ".txt for " + stateId);
+          throw new ServiceException("Error creating workspace link for: " + cs.toString(), E);
         }
         return;
       }
 
-      String cligenFileName = "/" + stateId + "/300yr/" + stateId + "_" + climatestationId + "_300yr.out";
-      URL u = new URL(cligen_db + cligenFileName);
+      // US  stations
+      File f = new File(cligen_db + "/" + stateId + "/300yr/" + stateId + "_" + climatestationId + "_300yr.out");
+      if (!f.exists())
+        throw new ServiceException("US climate station not found: " + climatestationId + "_300yr.out for " + stateId);
+
       long counter = 0;
-      try ( BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(u.openStream()))) {
+      try ( BufferedReader r = new BufferedReader(new FileReader(f))) {
         File tempFile = new File(workSpaceDir, "tempSummaryFile.pre");
-        try ( PrintWriter writer = new PrintWriter(tempFile)) {
+        try ( PrintWriter w = new PrintWriter(tempFile)) {
           for (int i = 0; i <= 17; i++) {
-            bufferedReader.readLine();
+            r.readLine();
           }
           String line;
-          while ((line = bufferedReader.readLine()) != null) {
+          while ((line = r.readLine()) != null) {
             String[] test = line.split("\\s+");
             double keComparison = Double.parseDouble(test[8]) * (Double.parseDouble(test[5]) / Double.parseDouble(test[6]));
             if (Ke < keComparison && test.length > 8) {
               counter++;
-              writer.println(String.format("    %-5s %-5s %-5s %-5s %-5s %-6s %-6s %-6s",
+              w.println(String.format("    %-5s %-5s %-5s %-5s %-5s %-6s %-6s %-6s",
                   counter, test[2], test[3], test[4], test[5], test[6], test[7], test[8]));
             }
           }
@@ -140,26 +143,26 @@
         tempFile.delete();
       }
     } catch (IOException E) {
-      throw new ServiceException("Problem in generating the storm file.", E);
+      throw new ServiceException("Problem generating the storm file.", E);
     }
   }
 
 
   void appendInfo(File tempFile, long counter, String stateId, String climatestationId) throws ServiceException {
-    try ( PrintWriter writer = new PrintWriter(new File(workSpaceDir, stormFileName))) {
+    try ( PrintWriter w = new PrintWriter(new File(workSpaceDir, stormFileName))) {
       String now = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a").format(new Date());
-      writer.println("# Storm file for scenario: " + scenarioName);
-      writer.println("# Date built: " + now + " (Version 2.3)");
-      writer.println("# State: " + stateId);
-      writer.println("# Climate Station: " + climatestationId);
-      writer.println(counter + " # The number of rain events");
-      writer.println("0 # Breakpoint data? (0 for no, 1 for yes)");
-      writer.println("#  id     day  month  year  Rain   Dur    Tp     Ip");
-      writer.println("#                           (mm)   (h)");
-      try ( BufferedReader bufferedReader = new BufferedReader(new FileReader(tempFile))) {
+      w.println("# Storm file for scenario: " + scenarioName);
+      w.println("# Date built: " + now + " (Version 2.3)");
+      w.println("# State: " + stateId);
+      w.println("# Climate Station: " + climatestationId);
+      w.println(counter + " # The number of rain events");
+      w.println("0 # Breakpoint data? (0 for no, 1 for yes)");
+      w.println("#  id     day  month  year  Rain   Dur    Tp     Ip");
+      w.println("#                           (mm)   (h)");
+      try ( BufferedReader r = new BufferedReader(new FileReader(tempFile))) {
         String line;
-        while ((line = bufferedReader.readLine()) != null) {
-          writer.println(line);
+        while ((line = r.readLine()) != null) {
+          w.println(line);
         }
       }
     } catch (IOException E) {
@@ -179,34 +182,34 @@
     DecimalFormat df = new DecimalFormat("#.#####");
     File summaryFile = new File(workSpaceDir, summaryFileName);
     File tempSummaryFile = new File(workSpaceDir, "temp_" + summaryFileName);
-    try ( PrintWriter writer = new PrintWriter(tempSummaryFile)) {
-      writer.println("     -ANNUAL-AVERAGES-");
-      writer.println();
-      writer.println("  Avg. Precipitation(mm/year)=   " + df.format(avgYearlyPrecip));
-      try ( BufferedReader bufferedReader = new BufferedReader(new FileReader(summaryFile))) {
+    try ( PrintWriter w = new PrintWriter(tempSummaryFile)) {
+      w.println("     -ANNUAL-AVERAGES-");
+      w.println();
+      w.println("  Avg. Precipitation(mm/year)=   " + df.format(avgYearlyPrecip));
+      try ( BufferedReader r = new BufferedReader(new FileReader(summaryFile))) {
         for (int i = 0; i < 3; i++) {
-          bufferedReader.readLine();
+          r.readLine();
         }
         String line;
-        while ((line = bufferedReader.readLine()) != null) {
+        while ((line = r.readLine()) != null) {
           if (line.toLowerCase().contains("variable")) {
             int c = 0;
             while (c < 6) {
-              if (c != 0) {
-                line = bufferedReader.readLine();
-              }
+              if (c != 0)
+                line = r.readLine();
+
               String[] test = line.split("\\s+");
               if (c == 2) {
-                writer.print(String.format("%-25s", test[1] + test[2]));
+                w.print(String.format("%-25s", test[1] + test[2]));
                 for (int i = 3; i < test.length; i++) {
-                  writer.print(String.format("%-25s", test[i]));
+                  w.print(String.format("%-25s", test[i]));
                 }
               } else {
                 for (int i = 1; i < test.length; i++) {
-                  writer.print(String.format("%-25s", test[i]));
+                  w.print(String.format("%-25s", test[i]));
                 }
               }
-              writer.println();
+              w.println();
               c++;
             }
           } else {
@@ -214,8 +217,8 @@
               String asl = line.substring(line.indexOf('=') + 1);
               avgSoilLoss = Double.parseDouble(asl.trim());
             }
-            writer.print(line);
-            writer.println();
+            w.print(line);
+            w.println();
           }
         }
       }
@@ -236,12 +239,9 @@
     return formatDouble((2.36 * (asl * 1000) + 0.99) / 1000.0);
   }
 
-  static final List<String> intl = Arrays.asList("INTL_", "INTL_AF", "INTL_SA");
-
 
   public boolean isIntl(String stateId) {
-    return intl.contains(stateId.toUpperCase());
-    //return stateId.toLowerCase().startsWith("intl_");
+    return INTL.contains(stateId.toUpperCase());
   }
 
 }

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

@@ -93,13 +93,11 @@
 
     ///////////////////////////////
     //  BEGIN  Validations of input 
-    if (sar < 0.0 || sar > 50.0) 
+    if (sar < 0.0 || sar > 50.0)
       throw new ServiceException("invalid sar (0.0 ... 50.0): " + sar);
-    
 
-    if (slopeSteepness <= 0.0) 
+    if (slopeSteepness <= 0.0)
       throw new ServiceException("The slopesteepness input parameter must be greater than 0.");
-    
 
     double slopeLength = RHEMUtils.getSlopelength(parameter());
 
@@ -119,9 +117,9 @@
   public void doProcess() throws Exception {
 
     String fileName = aoa.getScenarioName();
-    if (fileName.length() > 15) 
+    if (fileName.length() > 15)
       fileName = fileName.substring(0, 15);
-    
+
     fileName = fileName.replace(' ', '_');
 
     parameterFileName = "scenario_input_" + fileName + ".par";
@@ -130,7 +128,7 @@
     detailedOutputFileName = "scenario_output_summary_" + fileName + ".out";
     runFileName = fileName + ".run";
 
-    try (Connection connection = resources().getJDBC(DBResources.CRDB)) {
+    try ( Connection connection = resources().getJDBC(DBResources.CRDB)) {
       parameter.computeParameters(connection, aoa);
     }
 
@@ -146,9 +144,9 @@
     //If the run is successful then edit the summary file.
     if (!rhemModel.isIntl(stateId)) {
       double avgYearlyPrecip = 0.0;
-      try (Connection connection = resources().getJDBC(DBResources.CRDB);
+      try (Connection connection = resources().getJDBC(DBResources.CRDB);  
           Statement statement = connection.createStatement();) {
-        try (ResultSet rs = statement.executeQuery(DBResources.RHEM01Query02(climatestationId))) {
+        try ( ResultSet rs = statement.executeQuery(DBResources.RHEM01Query02(climatestationId))) {
           while (rs.next()) {
             avgYearlyPrecip = rs.getDouble("avg_yearly_precip_mm");
           }
@@ -163,9 +161,8 @@
     Executable rh = resources().getExe(rhemModel.isIntl(stateId) ? RHEM4_INTL_EXE : RHEM4_EXE);
     rh.setArguments("-b", workspace().getFile(runFileName).toPath());
     int run = rh.exec();
-    if (run != 0) 
+    if (run != 0)
       throw new ServiceException("Error running rhem: " + run);
-    
   }
 
 

src/java/rhem/utils/RHEMUtils.java

@@ -41,37 +41,32 @@
 
 
   public static double interpolate(double pointToEvaluate, double[] functionValuesX, double[] functionValuesY) {
-    double result = 0;
     int index = findIntervalLeftBorderIndex(pointToEvaluate, functionValuesX);
-    if (index == functionValuesX.length - 1) {
+    if (index == functionValuesX.length - 1) 
       index--;
-    }
-    result = linearInterpolation(pointToEvaluate, functionValuesX[index], functionValuesY[index],
+    
+    return linearInterpolation(pointToEvaluate, functionValuesX[index], functionValuesY[index],
         functionValuesX[index + 1], functionValuesY[index + 1]);
-    return result;
   }
 
 
   public static int findIntervalLeftBorderIndex(double point, double[] intervals) {
-    if (point < intervals[0]) {
+    if (point < intervals[0]) 
       return 0;
-    }
-    if (point > intervals[intervals.length - 1]) {
+    
+    if (point > intervals[intervals.length - 1]) 
       return intervals.length - 1;
-    }
 
     int leftBorderIndex = 0;
     int indexOfNumberToCompare;
     int rightBorderIndex = intervals.length - 1;
 
     while ((rightBorderIndex - leftBorderIndex) != 1) {
-      indexOfNumberToCompare = leftBorderIndex
-          + (int) Math.floor(((rightBorderIndex - leftBorderIndex) / 2));
-      if (point >= intervals[indexOfNumberToCompare]) {
+      indexOfNumberToCompare = leftBorderIndex + (int) Math.floor(((rightBorderIndex - leftBorderIndex) / 2));
+      if (point >= intervals[indexOfNumberToCompare]) 
         leftBorderIndex = indexOfNumberToCompare;
-      } else {
+      else
         rightBorderIndex = indexOfNumberToCompare;
-      }
     }
     return leftBorderIndex;
   }
@@ -161,9 +156,8 @@
       for (int i = 2; i < transposedMatrix.length; i++) {
         List<Double> alt_scenario = new ArrayList<>();
         for (int k = 0; k < transposedMatrix[i].length; k++) {
-          if (transposedMatrix[i][k] <= maxBaselineSoilLoss) {
+          if (transposedMatrix[i][k] <= maxBaselineSoilLoss) 
             alt_scenario.add(transposedMatrix[i][k]);
-          }
         }
         // default the altenative scenario interpolated value to 1
         double altScenarioInterp = 1;
@@ -172,9 +166,8 @@
           altScenarioInterp = Math.round(altScenarioInterp * 1000.0) / 1000.0;
 
           // set the return period to 100 if the interpolated value is greater than 100
-          if (altScenarioInterp > 100 || Double.isNaN(altScenarioInterp)) {
+          if (altScenarioInterp > 100 || Double.isNaN(altScenarioInterp)) 
             altScenarioInterp = 100;
-          }
         }
         // round the interpolated year to the nearest 10th place
         altScenarioInterp = Math.round(altScenarioInterp * 10) / 10.0;
@@ -200,9 +193,9 @@
           throw new ServiceException("Illegal unit for slopelength: " + p.getUnit("slopelength"));
       }
     }
-    if (slopeLength <= 0.0) {
+    if (slopeLength <= 0.0) 
       throw new ServiceException("'slopelength' parameter must be greater than 0.");
-    }
+    
     return slopeLength;
   }
 

web/WEB-INF/csip-defaults.json

@@ -1,5 +1,5 @@
 {  
-    "csip.context.version": "$version: 2.1.31 default 205 2f3bd7380f82 2022-01-18 od, built at 2022-09-30 09:37 by od$",
+    "csip.context.version": "$version: 2.1.34 default 208 a6cc2895acb3 2022-10-25 casesp, built at 2022-10-25 11:00 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",