Displaying differences for changeset
 
display as  

.hgignore

@@ -9,3 +9,4 @@
 nbproject/private
 test/service_tests/rhem/simple-res
 test/service_tests/rhem/simple-res.json
+nbproject/build-impl\.xml~

nbproject/ant-deploy.xml

 

nbproject/build-impl.xml

@@ -1014,16 +1014,16 @@
     <target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest">
         <copyfiles files="${reference.csip-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${reference.csip-gis-objects.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
+        <copyfiles files="${libs.csip-geotools-15.1-2.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${libs.CSIP-Jersey-2.16.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
-        <copyfiles files="${libs.csip-geotools-15.1-2.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
         <mkdir dir="${build.web.dir}/META-INF"/>
         <manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
     </target>
     <target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir">
         <copyfiles files="${reference.csip-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
         <copyfiles files="${reference.csip-gis-objects.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
+        <copyfiles files="${libs.csip-geotools-15.1-2.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
         <copyfiles files="${libs.CSIP-Jersey-2.16.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
-        <copyfiles files="${libs.csip-geotools-15.1-2.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
     </target>
     <target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
         <delete dir="${build.web.dir}/WEB-INF/lib"/>

nbproject/genfiles.properties

@@ -3,8 +3,8 @@
 build.xml.stylesheet.CRC32=651128d4@1.65.1.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=2e3fb3c9
-nbproject/build-impl.xml.script.CRC32=5d218bc1
+nbproject/build-impl.xml.data.CRC32=1312fa57
+nbproject/build-impl.xml.script.CRC32=364b5ac0
 nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1
 nbproject/rest-build.xml.data.CRC32=bff4a8fe
 nbproject/rest-build.xml.script.CRC32=4734534b

nbproject/project.properties

@@ -1,4 +1,4 @@
-j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.1.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-spdy.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
+j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
 #Thu Dec 17 13:44:22 MST 2015
 javadoc.splitindex=true
 lib.dir=${web.docbase.dir}/WEB-INF/lib
@@ -54,8 +54,8 @@
 javac.classpath=\
     ${reference.csip-core.jar}:\
     ${reference.csip-gis-objects.jar}:\
-    ${libs.CSIP-Jersey-2.16.classpath}:\
-    ${libs.csip-geotools-15.1-2.classpath}
+    ${libs.csip-geotools-15.1-2.classpath}:\
+    ${libs.CSIP-Jersey-2.16.classpath}
 javadoc.noindex=false
 webinf.dir=web/WEB-INF
 annotation.processing.enabled.in.editor=true

nbproject/project.xml

@@ -20,11 +20,11 @@
                     <path-in-war>WEB-INF/lib</path-in-war>
                 </library>
                 <library dirs="200">
-                    <file>${libs.CSIP-Jersey-2.16.classpath}</file>
+                    <file>${libs.csip-geotools-15.1-2.classpath}</file>
                     <path-in-war>WEB-INF/lib</path-in-war>
                 </library>
                 <library dirs="200">
-                    <file>${libs.csip-geotools-15.1-2.classpath}</file>
+                    <file>${libs.CSIP-Jersey-2.16.classpath}</file>
                     <path-in-war>WEB-INF/lib</path-in-war>
                 </library>
             </web-module-libraries>

src/java/m/rhem/model/AoA.java

@@ -38,7 +38,7 @@
             String slopeShape, double slopeSteepness,
             double bunchGgrassCanopyCover, double forbsCanopyCover,
             double shrubsCanopyCover, double sodGrassCanopyCover, double basalCover,
-            double rockCover, double litterCover, double cryptogamsCover) {
+            double rockCover, double litterCover, double cryptogamsCover, double moisturecontent) {
         this.aoaId = aoaId;
         this.rhemSiteId = rhemSiteId;
         this.scenarioName = scenarioName;

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

@@ -57,7 +57,6 @@
 
     String cligen_db = Config.getString("rhem.cligen_db", "file:/Users/rumpal/Documents/Work/csipDocuments/RHEM/cligen");
 
-
     @Override
     public void preProcess() throws ServiceException {
         try {
@@ -69,7 +68,6 @@
             String stateId = getStringParam("stateid");
             String climatestationId = getStringParam("climatestationid");
             String soilTexture = getStringParam("soiltexture");
-            double slopeLength = getDoubleParam("slopelength", 0.0);
             String slopeShape = getStringParam("slopeshape");
             double slopeSteepness = getDoubleParam("slopesteepness", 0.0);
             double bunchGgrassCanopyCover = getDoubleParam("bunchgrasscanopycover", 0.0);
@@ -87,20 +85,25 @@
                 LOG.log(Level.SEVERE, "RHEM-01: Invalid unit");
                 throw new ServiceException("Unit should be 1-metric or 2 - English. Digit " + unit + " is not valid.");
             }
+            double slopeLength;
+            if (unit == 1) {
+                slopeLength = 50;
+            } else {
+                slopeLength = 164.04;
+            }
 
             aoa = new AoA(aoaId, rhemSiteId, scenarioName,
                     scenarioDescription, unit, stateId, climatestationId,
                     soilTexture, slopeLength, slopeShape, slopeSteepness,
                     bunchGgrassCanopyCover, forbsCanopyCover, shrubsCanopyCover,
                     sodGrassCanopyCover, basalCover, rockCover, litterCover,
-                    cryptogamsCover);
+                    cryptogamsCover, 25);
         } catch (ServiceException ex) {
             LOG.log(Level.SEVERE, "RHEM-01: Error in processing the request JSON.", ex);
             throw new ServiceException("Error in processing the request JSON.", ex);
         }
     }
 
-
     @Override
     public void doProcess() throws ServiceException, IOException {
         SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, YYYY, hh:mm a");
@@ -132,7 +135,7 @@
         rhemModel.generateParamFile(parameter);
         rhemModel.generateStormFile(cligen_db, Double.parseDouble(parameter.getKe()));
         rhemModel.generateRunFile();
-        
+
         runModel();
 
         //If the run is successful then edit the summary file.
@@ -159,7 +162,6 @@
         }
     }
 
-
     @Override
     public void postProcess() {
         putResult("AoAID", aoa.getAoaId(), "Area of Analysis Identifier");

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

@@ -42,19 +42,6 @@
             "value": "Clay Loam"
         },
         {
-            "name": "moisturecontent",
-            "description": "",
-            "value": 25
-        },
-        {
-            "name": "slopelength",
-            "description": "Slope Length",
-            "value": 50,
-            "unit": "ft/m",
-            "min": 0.01,
-            "max": "394 feet/120 meters"
-        },
-        {
             "name": "slopeshape",
             "description": "Slope Shape",
             "value": "Uniform"

src/java/m/rhem/rhem03_compEsd/V1_0.java

@@ -49,8 +49,7 @@
     private JSONObject rhemSiteGeometryPoint;
 
     //Result Payload
-    private ArrayList<Mapuint> mapunitList;
-
+    private ArrayList<Mapunit> mapunitList;
 
     @Override
     public void preProcess() throws ServiceException {
@@ -64,7 +63,6 @@
         }
     }
 
-
     @Override
     public void doProcess() throws ServiceException {
         try (Connection sdmConnection = getResourceJDBC(RHEMResources.SDM_DB);
@@ -78,7 +76,6 @@
         }
     }
 
-
     private void getMapunitValues(Connection sdmConnection) throws ServiceException {
         try (Statement statement = sdmConnection.createStatement();) {
             GISEngine gisEngine = createGISEngine(sdmConnection);
@@ -106,7 +103,7 @@
                                 resultSet.getInt("slope_h")));
                     }
                 }
-                mapunitList.add(new Mapuint(musym, muname, componentList));
+                mapunitList.add(new Mapunit(musym, muname, componentList));
             }
         } catch (SQLException | GISObjectException | JSONException | IOException ex) {
             LOG.log(Level.SEVERE, "RHEM-03: SQLException.", ex);
@@ -114,11 +111,10 @@
         }
     }
 
-
     private void getComponentValues(Connection connection, Connection esdConnection) throws ServiceException {
         try (Statement statement = connection.createStatement();) {
-            for (Mapuint mapuint : mapunitList) {
-                for (Component component : mapuint.getComponentList()) {
+            for (Mapunit mapunit : mapunitList) {
+                for (Component component : mapunit.getComponentList()) {
                     ArrayList<EcologicalSite> ecoList = new ArrayList<>();
                     String ecoclassid = null;
                     try (ResultSet resultSet = statement.executeQuery(DBQueries.RHEM03Query03(component.getCokey()))) {
@@ -145,11 +141,10 @@
         }
     }
 
-
     private void getSurfaceTextureClass(Connection connection, Connection rhemConnection) throws ServiceException {
         try (Statement statement = connection.createStatement();) {
-            for (Mapuint mapuint : this.mapunitList) {
-                for (Component component : mapuint.getComponentList()) {
+            for (Mapunit mapunit : this.mapunitList) {
+                for (Component component : mapunit.getComponentList()) {
                     ArrayList<SurfaceTexture> surfaceTextureList = new ArrayList<>();
                     try (ResultSet resultSet = statement.executeQuery(DBQueries.RHEM03Query05(component.cokey));) {
                         while (resultSet.next()) {
@@ -175,7 +170,6 @@
         }
     }
 
-
     @Override
     public void postProcess() throws Exception {
         try {
@@ -183,10 +177,10 @@
             putResult("rhem_site_id", this.rhemSiteId, "RHEM Evaluation Site Identifier");
 
             JSONArray mapUnitArray = new JSONArray();
-            for (Mapuint mapunit : this.mapunitList) {
-                JSONArray mapuintArr = new JSONArray();
-                mapuintArr.put(JSONUtils.dataDesc("musym", mapunit.getMusym(), "Mapunit Symbol"));
-                mapuintArr.put(JSONUtils.dataDesc("muname", mapunit.getMuname(), "Mapunit Name"));
+            for (Mapunit mapunit : this.mapunitList) {
+                JSONArray mapunitArr = new JSONArray();
+                mapunitArr.put(JSONUtils.dataDesc("musym", mapunit.getMusym(), "Mapunit Symbol"));
+                mapunitArr.put(JSONUtils.dataDesc("muname", mapunit.getMuname(), "Mapunit Name"));
 
                 JSONArray componentArray = new JSONArray();
                 for (Component component : mapunit.getComponentList()) {
@@ -219,17 +213,16 @@
                     componentArr.put(JSONUtils.dataDesc("surface_texture_class_list", surfaceTestureArray, "Soil Component Surface Texture Class List"));
                     componentArray.put(JSONUtils.dataDesc("component", componentArr, "Component"));
                 }
-                mapuintArr.put(JSONUtils.dataDesc("component_list", componentArray, "Component List"));
-                mapUnitArray.put(JSONUtils.dataDesc("mapunit", mapuintArr, "Mapuint"));
+                mapunitArr.put(JSONUtils.dataDesc("component_list", componentArray, "Component List"));
+                mapUnitArray.put(JSONUtils.dataDesc("mapunit", mapunitArr, "Mapunit"));
             }
-            putResult("mapunit_list", mapUnitArray, "Mapuint List");
+            putResult("mapunit_list", mapUnitArray, "Mapunit List");
         } catch (JSONException ex) {
             LOG.log(Level.SEVERE, "RHEM-03: Error in processing the reponse JSON.", ex);
             throw new ServiceException("Error in processing the reponse JSON.", ex);
         }
     }
 
-
     /**
      * Get the full JSON parameter record.
      *
@@ -244,31 +237,27 @@
         return p;
     }
 
-    static class Mapuint {
+    static class Mapunit {
 
         protected String musym;
         protected String muname;
         protected ArrayList<Component> componentList;
 
-
-        public Mapuint(String musym, String muname,
+        public Mapunit(String musym, String muname,
                 ArrayList<Component> componentList) {
             this.musym = musym;
             this.muname = muname;
             this.componentList = componentList;
         }
 
-
         public String getMusym() {
             return this.musym;
         }
 
-
         public String getMuname() {
             return this.muname;
         }
 
-
         public ArrayList<Component> getComponentList() {
             return this.componentList;
         }
@@ -287,7 +276,6 @@
         protected ArrayList<EcologicalSite> ecoSiteList;
         protected ArrayList<SurfaceTexture> surfaceTextureList;
 
-
         public Component(String cokey, String compName, int comppctR,
                 int slopePctL, int slopePctR, int slopePctH) {
             this.cokey = cokey;
@@ -298,32 +286,26 @@
             this.slopePctH = slopePctH;
         }
 
-
         public String getCokey() {
             return this.cokey;
         }
 
-
         public String getCompName() {
             return this.compName;
         }
 
-
         public int getComppctR() {
             return this.comppctR;
         }
 
-
         public int getSlopePctL() {
             return this.slopePctL;
         }
 
-
         public int getSlopePctR() {
             return this.slopePctR;
         }
 
-
         public int getSlopePctH() {
             return this.slopePctH;
         }
@@ -332,17 +314,14 @@
             return this.ecoSiteList;
         }
 
-
         public ArrayList<SurfaceTexture> getSurfaceTextureList() {
             return this.surfaceTextureList;
         }
 
-
         public void setEcoSiteList(ArrayList<EcologicalSite> list) {
             this.ecoSiteList = list;
         }
 
-
         public void setSurfaceTextureList(ArrayList<SurfaceTexture> list) {
             this.surfaceTextureList = list;
         }
@@ -354,18 +333,15 @@
         protected String esId;
         protected String esRangeName;
 
-
         public EcologicalSite(String esId, String esRangeName) {
             this.esId = esId;
             this.esRangeName = esRangeName;
         }
 
-
         public String getEsId() {
             return esId;
         }
 
-
         public String getEsRangeName() {
             return esRangeName;
         }
@@ -378,7 +354,6 @@
         protected String textureClass;
         protected String textureClassLabel;
 
-
         public SurfaceTexture(String texcl, int textureId, String textureClass,
                 String textureClassLabel) {
             this.texcl = texcl;
@@ -387,22 +362,18 @@
             this.textureClassLabel = textureClassLabel;
         }
 
-
         public String getTexcl() {
             return this.texcl;
         }
 
-
         public int getTextureId() {
             return this.textureId;
         }
 
-
         public String getTextureClass() {
             return this.textureClass;
         }
 
-
         public String getTextureClassLabel() {
             return this.textureClassLabel;
         }

src/java/m/rhem/rhem06_riskassessment/V1_0.java

@@ -10,10 +10,11 @@
 import csip.ServiceException;
 import csip.annotations.Polling;
 import csip.annotations.Resource;
-import static csip.annotations.ResourceType.EXECUTABLE;
 import static csip.annotations.ResourceType.OUTPUT;
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
@@ -22,6 +23,8 @@
 import javax.ws.rs.Path;
 import oms3.annotations.Description;
 import oms3.annotations.Name;
+import rhem.utils.LinearInterpolate;
+import rhem.utils.RHEMResources;
 import static rhem.utils.RHEMResources.RHEM_RA_EXE;
 
 /**
@@ -33,11 +36,12 @@
 @Path("m/rhem/riskassessment/1.0")
 @Polling(first = 10000, next = 2000)
 @Resource(file = "*.out *.run", type = OUTPUT)
+@Resource(from = RHEMResources.class)
 public class V1_0 extends ModelDataService {
 
     private String baseLineScenarioFileName;
     private List<String> raScenarioFilenameList;
-
+    private ArrayList<String> scenarioNames;
 
     @Override
     public void preProcess() throws ServiceException {
@@ -52,15 +56,17 @@
         baseLineScenarioFileName = getStringParam("base_line_scenario_file");
     }
 
-
     @Override
     public void doProcess() throws ServiceException, IOException {
         writeOutFilesToWorkspace();
         generateRARunFile();
         runRiskAssessment();
+
+        double[][] outRAarray = readRiskAssessmentOutFile();
+        ArrayList<ArrayList> interpolatedResultsArray = calculateReturnPeriods(outRAarray);
+        writeInterpolatedResultsArray(interpolatedResultsArray);
     }
 
-
     private void writeOutFilesToWorkspace() throws ServiceException {
         getFileInput(baseLineScenarioFileName);
         for (String filename : raScenarioFilenameList) {
@@ -68,7 +74,6 @@
         }
     }
 
-
     private void generateRARunFile() throws ServiceException {
         try (PrintWriter writer = new PrintWriter(new File(getWorkspaceDir(), "risk_assessment.run"))) {
             writer.println(baseLineScenarioFileName);
@@ -82,7 +87,6 @@
         }
     }
 
-
     private void runRiskAssessment() throws ServiceException, IOException {
         Executable rh = getResourceExe(RHEM_RA_EXE);
         rh.setArguments("-b", getWorkspaceFile("risk_assessment.run").toPath());
@@ -91,4 +95,147 @@
             throw new ServiceException("Problem in running risk assessment.");
         }
     }
+
+    private double[][] readRiskAssessmentOutFile() throws ServiceException {
+        scenarioNames = new ArrayList<>();
+        double outputRAArray[][] = new double[12][raScenarioFilenameList.size() + 2];
+        int count = -1;
+        boolean check = false;
+        try {
+            FileReader fileReader = new FileReader(getWorkspaceFile("risk_assessment.OUT"));
+            try (BufferedReader bufferedReader
+                    = new BufferedReader(fileReader)) {
+                String line;
+
+                while ((line = bufferedReader.readLine()) != null && !check) {
+                    if (line.contains("FREQUENCY ANALYSIS")) {
+                        check = true;
+                        for (int i = 0; i < 3; i++) {
+                            line = bufferedReader.readLine();
+                            if (i == 2) {
+                                String[] test = line.trim().split("\\s+");
+                                for (int j = 1; j < test.length; j++) {
+                                    scenarioNames.add(test[j]);
+                                }
+                            }
+                        }
+                    }
+                }
+
+                do {
+                    count++;
+                    String[] test = line.trim().split("\\s+");
+                    for (int i = 0; i < test.length; i++) {
+                        outputRAArray[count][i] = Double.parseDouble(test[i].trim());
+                    }
+                } while ((line = bufferedReader.readLine()) != null && check);
+
+            }
+        } catch (IOException exception) {
+            throw new ServiceException("Problem in reading the risk assessment out file.", exception);
+        }
+        return outputRAArray;
+    }
+
+    public ArrayList<ArrayList> calculateReturnPeriods(double outputRAArray[][]) {
+        /* Sample outputRAArray
+        double[][] outputRAArray = {
+            {2, 0.15, 0.28, 1.09, 1.45},
+            {5, 0.3, 0.54, 2.03, 2.75},
+            {10, 0.4, 0.72, 2.75, 3.76},
+            {20, 0.53, 0.96, 3.65, 4.88},
+            {30, 0.58, 1.05, 3.9, 5.27},
+            {40, 0.59, 1.07, 3.91, 5.33},
+            {50, 0.63, 1.14, 4.22, 5.72},
+            {60, 0.64, 1.16, 4.34, 5.83},
+            {70, 0.66, 1.18, 4.37, 5.91},
+            {80, 0.68, 1.22, 4.49, 6.1},
+            {90, 0.7, 1.26, 4.67, 6.32},
+            {100, 0.71, 1.3, 4.84, 6.52}};
+         */
+        ArrayList<ArrayList> interpolatedResultsArray = new ArrayList();
+        outputRAArray = roundValues(outputRAArray);
+        double[][] trasposedMatrix = trasposeMatrix(outputRAArray);
+
+        for (int x = 0; x < trasposedMatrix[0].length; x++) {
+            double currentRP = trasposedMatrix[0][x];
+            double currentSoilLoss = trasposedMatrix[1][x];
+            double maxBaselineSoilLoss = trasposedMatrix[1][x];
+            ArrayList<Double> rpPeriodArray = new ArrayList<>();
+            rpPeriodArray.add(currentSoilLoss);
+            rpPeriodArray.add(currentRP);
+
+            for (int i = 2; i < trasposedMatrix.length; i++) {
+                ArrayList<Double> alt_scenario = new ArrayList<>();
+                for (int k = 0; k < trasposedMatrix[i].length; k++) {
+                    if (trasposedMatrix[i][k] <= maxBaselineSoilLoss) {
+                        alt_scenario.add(trasposedMatrix[i][k]);
+                    }
+                }
+                // default the altenative scenario interpolated value to 1
+                double altScenarioInterp = 1;
+                if (!alt_scenario.isEmpty()) {
+                    altScenarioInterp = LinearInterpolate.interpolate(maxBaselineSoilLoss, trasposedMatrix[i], trasposedMatrix[0]);
+                    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)) {
+                        altScenarioInterp = 100;
+                    }
+                }
+                // round the interpolated year to the nearest 10th place
+                altScenarioInterp = Math.round(altScenarioInterp * 10) / 10.0;
+                rpPeriodArray.add(altScenarioInterp);
+            }
+            interpolatedResultsArray.add(rpPeriodArray);
+        }
+        return interpolatedResultsArray;
+    }
+
+    public static double[][] roundValues(double[][] matrix) {
+        double[][] outputMatrix = new double[matrix.length][matrix[0].length];
+        for (int i = 0; i < matrix.length; i++) {
+            for (int j = 0; j < matrix[i].length; j++) {
+                outputMatrix[i][j] = Math.round(matrix[i][j] * 100.0) / 100.0;
+            }
+        }
+        return outputMatrix;
+    }
+
+    public static double[][] trasposeMatrix(double[][] matrix) {
+        int x = matrix.length;
+        int y = matrix[0].length;
+
+        double[][] trasposedMatrix = new double[y][x];
+
+        for (int i = 0; i < y; i++) {
+            for (int j = 0; j < x; j++) {
+                trasposedMatrix[i][j] = matrix[j][i];
+            }
+        }
+        return trasposedMatrix;
+    }
+
+    public void writeInterpolatedResultsArray(ArrayList<ArrayList> interpolatedResultsArray) throws ServiceException {
+
+        try (PrintWriter writer = new PrintWriter(new File(getWorkspaceDir(), "frequencyAnalysisReturnPeriodTable.out"));) {
+            writer.print(String.format("%-20s %-20s", "BASELINE SCENARIO", "RETURN PERIOD"));
+            for (String name : scenarioNames) {
+                writer.print(String.format("%-20s", name + "(years)"));
+            }
+            writer.println();
+
+            for (int i = 0; i < interpolatedResultsArray.size(); i++) {
+                for (int j = 0; j < interpolatedResultsArray.get(i).size(); j++) {
+                    writer.print(String.format("%-20s", interpolatedResultsArray.get(i).get(j).toString()));
+                }
+                writer.println();
+            }
+            writer.close();
+        } catch (FileNotFoundException ex) {
+            throw new ServiceException("Problem in generating the parameter file.", ex);
+        }
+
+    }
+
 }

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

@@ -25,6 +25,7 @@
 import m.rhem.model.RhemModel;
 import oms3.annotations.Description;
 import oms3.annotations.Name;
+import rhem.utils.DBQueries;
 import rhem.utils.RHEMResources;
 import static rhem.utils.RHEMResources.RHEM_EXE;
 
@@ -55,7 +56,6 @@
     private String stateId;
     private String climatestationId;
 
-
     @Override
     public void preProcess() throws ServiceException {
         try {
@@ -96,7 +96,6 @@
         }
     }
 
-
     @Override
     public void doProcess() throws ServiceException, IOException {
 
@@ -127,10 +126,7 @@
         double avgYearlyPrecip = 0;
         try (Connection connection = getResourceJDBC(RHEMResources.RHEM_DB);
                 Statement statement = connection.createStatement();) {
-            String query = "SELECT avg_yearly_precip_mm "
-                    + "FROM rhem.d_rhem_climate_stations_avg_300yr_est_rain "
-                    + "WHERE station_id = '" + climatestationId + "';";
-            try (ResultSet rs = statement.executeQuery(query)) {
+            try (ResultSet rs = statement.executeQuery(DBQueries.RHEM07Query01(climatestationId))) {
                 while (rs.next()) {
                     avgYearlyPrecip = rs.getDouble("avg_yearly_precip_mm");
                 }
@@ -141,7 +137,6 @@
         rhemModel.appendToSumFile(avgYearlyPrecip);
     }
 
-
     private void runModel() throws ServiceException, IOException {
         int run = -1;
         Executable rh = getResourceExe(RHEM_EXE);
@@ -152,7 +147,6 @@
         }
     }
 
-
     @Override
     public void postProcess() {
         putResult("AoAID", aoaId, "Area of Analysis Identifier");

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

@@ -27,6 +27,14 @@
             "value": "415596"
         },
         {
+            "name": "DIAMS",
+            "value": "0.002   0.01   0.038   0.58   0.2"
+        },
+        {
+            "name": "DENSITY",
+            "value": "2.6  2.65  1.8  1.6  2.65"
+        },
+        {
             "name": "LEN",
             "value": "50"
         },
@@ -71,6 +79,18 @@
             "value": "0.86792028824819"
         },
         {
+            "name": "G",
+            "value": "260"
+        },
+        {
+            "name": "DIST",
+            "value": "0.24"
+        },
+        {
+            "name": "POR",
+            "value": "0.4589"
+        },
+        {
             "name": "ADF",
             "value": "0.00"
         },
@@ -83,26 +103,6 @@
             "value": "0.23"
         },
         {
-            "name": "DIAMS",
-            "value": "0.002   0.01   0.038   0.58   0.2"
-        },
-        {
-            "name": "DENSITY",
-            "value": "2.6  2.65  1.8  1.6  2.65"
-        },
-        {
-            "name": "G",
-            "value": "260"
-        },
-        {
-            "name": "DIST",
-            "value": "0.24"
-        },
-        {
-            "name": "POR",
-            "value": "0.4589"
-        },
-        {
             "name": "FRACT",
             "value": "0.0848   0.0397   0.3157   0.5148   0.045"
         }

src/java/rhem/utils/DBQueries.java

@@ -28,6 +28,13 @@
         return query;
     }
 
+    public static String RHEM01Query02(String climateStationId) {
+        String query = "SELECT avg_yearly_precip_mm "
+                + "FROM rhem.d_rhem_climate_stations_avg_300yr_est_rain "
+                + "WHERE station_id = '" + climateStationId + "';";
+        return query;
+    }
+
     public static String RHEM02Query01(String stateId) {
         String query = "SELECT state_name, latitude, longitude, zoom "
                 + "FROM rhem.d_rhem_climate_station_states "
@@ -53,21 +60,6 @@
     }
 
     public static String RHEM03Query01(GISObject geometry) {
-//        String query = "SELECT mukey "
-//                + "FROM ssurgo.soilmu_a "
-//                + "WITH (index(geom_sidx)) "
-//                + "WHERE the_geom.STContains(geometry::STGeomFromText('"
-//                + geometry.getGeometry() + "', 0))=1 "
-//                + "AND (geometry::STGeomFromText('"
-//                + geometry.getGeometry() + "', 0).STIsValid())=1;";
-
-//        String query = "SELECT mupoly.mukey, mapunit.musym, mapunit.muname "
-//                + "FROM dbo.mupolygon AS mupoly "
-//                + "WITH (index(SI_mupolygon_24876)) "
-//                + "JOIN dbo.mapunit AS mapunit "
-//                + "ON mupoly.mukey = mapunit.mukey "
-//                + "WHERE mupoly.mupolygongeo.STIntersects( geometry::STGeomFromText('"
-//                + geometry.getGeometry() + "', 4326)) = 1;";
         String query = "SELECT mupoly.mukey, mapunit.musym, mapunit.muname "
                 + "FROM dbo.mupolygon AS mupoly "
                 + "WITH (index(SI_mupolygon_24876)) "
@@ -141,10 +133,10 @@
         return query;
     }
 
-    public static String RHEM01Query02(String climateStationId) {
+    public static String RHEM07Query01(String climatestationId) {
         String query = "SELECT avg_yearly_precip_mm "
                 + "FROM rhem.d_rhem_climate_stations_avg_300yr_est_rain "
-                + "WHERE station_id = '" + climateStationId + "';";
+                + "WHERE station_id = '" + climatestationId + "';";
         return query;
     }
 

web/META-INF/csip-conf.json

@@ -1,8 +1,9 @@
-{
-    "rhem.db": "jdbc:sqlserver://129.82.20.241:1433;databaseName=conservation_resources;user=sa;password=csurams#1",
-    "esd.db": "jdbc:sqlserver://129.82.20.241:1433;databaseName=esd;user=sa;password=csurams#1",
-    "SDM.db": "jdbc:sqlserver://129.82.20.129:1433;databaseName=sdmOnline;user=sa;password=csurams#1",
-    "wine.path": "/usr/local/bin/wine",
-    "csip.session.ttl": "PT20S",
-    "csip.session.ttl.failed": "PT300S"
+{  
+    "csip.archive.max.filesize": "1KB",
+    "mssql-rhem.db": "jdbc:sqlserver:\/\/129.82.20.241:1433;databaseName=conservation_resources;user=sa;password=csurams#1",
+    "mssql-esd.db": "jdbc:sqlserver:\/\/129.82.20.241:1433;databaseName=esd;user=sa;password=csurams#1",
+    "wine.path":"/usr/local/bin/wine",
+    
+    "csip.session.ttl": "PT300S",
+    "csip.session.ttl.failed": "PT3000S"    
 }