Displaying differences for changeset
 
display as  

lib/Man2Weps.jar

 

src/java/m/rusle2/R2Run.java

@@ -97,6 +97,9 @@
         return pc.exitValue;
     }
     
+    // to do
+    // prepare functions need to be rewritten to be Java only (no shelling out to linux!)
+    
     int prepareSoilsFile(String soilsHttpPtr, File workingDir, boolean bPyrome, String idx) throws IOException {
         // Generate shell script to prepare soils file for romeshell or pyrome
         ProcessComponent pcPrepareSoils = new ProcessComponent();        
@@ -149,7 +152,120 @@
         stderr += "\n" + pcPrepareCli.stderr;
         return pcPrepareCli.exitValue;
     }
+    
+    // Must find the hydraulic element flow path element of a hydraulic element system
+    // download this file, and modify the header, so it can be fed to python
+    int prepareHydraulicElementFlowPath(String hydElemPtr, File workingDir) throws IOException
+    {
+        ProcessComponent pcPrepareHydElemFP = new ProcessComponent();
+        File preparehydElemFP = new File(workingDir.getParent() + "/preparehydraulic-element.sh");
+        String sPrepHydElemFP = "#! /bin/bash\n";
+        sPrepHydElemFP += "wget \"http://172.1.6.19/r2/hydraulic-element-systems/" + hydElemPtr + ".xml\" -O hydelem_file.tmp\n";
+        sPrepHydElemFP += "flowpathline=`grep HYD_SYSTEM_FLOW_PATH_TYPE hydelem_file.tmp`\n";
+        sPrepHydElemFP += "flowpathfile=`echo $flowpathline | cut -d\"'\" -f 2`\n";
+        sPrepHydElemFP += "wget \"http://172.1.6.19/r2/hydraulic-element-flow-paths/$flowpathfile.xml\" -O hydelemflowpath_file.tmp\n";
+        sPrepHydElemFP += "echo \"<Obj>\" > hydelemflowpath_file.xml\n";
+        sPrepHydElemFP += "echo \"<Filename>hydraulic-element-flow-paths\\hydelemflowpath1</Filename>\" >> hydelemflowpath_file.xml\n";
+        sPrepHydElemFP += "tail -n +2 hydelemflowpath_file.tmp >> hydelemflowpath_file.xml\n";
+        FileUtils.writeStringToFile(preparehydElemFP, sPrepHydElemFP);
+        preparehydElemFP.setExecutable(true);
+        pcPrepareHydElemFP.working_dir = workingDir.getParent();
+        pcPrepareHydElemFP.exe = ".//preparehydraulic-element.sh";
+        pcPrepareHydElemFP.args = new String []{};
+        pcPrepareHydElemFP.execute();
+        stdout += "\n" + pcPrepareHydElemFP.stdout;
+        stderr += "\n" + pcPrepareHydElemFP.stderr;
+        return pcPrepareHydElemFP.exitValue;
+    }
+    
+    int DetermineNumberOfFlowPaths(String hydElemPtr) 
+    {
+        // This rediumentary algorithm for determining the number of flow paths for
+        // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
+        
+        if (hydElemPtr.startsWith("1"))
+        {
+            if (hydElemPtr.contains("middle"))
+                return 2;
+            else
+                return 1;
+        }
+        
+        // presently there are only 2 kinds of hydraulic element systems with 2 elements.  
+        // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
+        // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
+        //
+        // presently there is one hydraulic element with "along" instead of "middle" in the name
+        // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
+        // 
+        if (hydElemPtr.startsWith("2"))
+        {
+            if ( ((hydElemPtr.contains("middle")) || (hydElemPtr.contains("along"))) && (!hydElemPtr.contains("bottom")))
+                return 3;
+            else
+                // These should have middle and bottom
+                return 2;
+        }
 
+        // presently there are only 2 kinds of hydraulic element systems with 3 elements.  
+        // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
+        // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
+        if (hydElemPtr.startsWith("3"))
+        {
+            if ((hydElemPtr.contains("middle")) && (!hydElemPtr.contains("bottom")))
+                return 4;
+            else
+                // These should have middle and bottom
+                return 3;            
+        }
+        // Should not get here.
+        return 0;
+    }
+    
+    double[] DetermineFlowPathDistribution(String hydElemPtr)
+    {
+        // This rediumentary algorithm for determining the hyd elem flow path position relative to slope length for
+        // a hydaulic element system is based on conversation with Jack Carlson in late 03/2016
+        
+        if (hydElemPtr.startsWith("1"))
+        {
+            if (hydElemPtr.contains("middle"))
+                return new double[]{.5, 1};
+            else
+                return new double[]{1};
+        }
+        
+        // presently there are only 2 kinds of hydraulic element systems with 2 elements.  
+        // ones with only "middle" in the name which should have 3 flow paths (all evenly distributed along the slope),
+        // and ones with "middle" and "bottom" in the name which should have 2 flow paths (one in middle, one at bottom).
+        //
+        // presently there is one hydraulic element with "along" instead of "middle" in the name
+        // "2 Water and Sediment Control Basins along RUSLE slope.xml"  This should be treated the same as middle.
+        // 
+        if (hydElemPtr.startsWith("2"))
+        {
+            if ( ((hydElemPtr.contains("middle")) || (hydElemPtr.contains("along"))) && (!hydElemPtr.contains("bottom")))
+                return new double[]{.333,.666,1};
+            else
+                // These should have middle and bottom
+                return new double[]{.5, 1};
+        }
+
+        // presently there are only 2 kinds of hydraulic element systems with 3 elements.  
+        // ones with only "middle" in the name which should have 4 flow paths (all evenly distributed along the slope),
+        // and ones with "middle" and "bottom" in the name which should have 3 flow paths (two in middle, one at bottom).
+        if (hydElemPtr.startsWith("3"))
+        {
+            if ((hydElemPtr.contains("middle")) && (!hydElemPtr.contains("bottom")))
+                return new double[]{.25,.5,.75,1};
+            else
+                // These should have middle and bottom
+                return new double[]{.333,.666,1};            
+        }
+        // Should not get here...
+        return new double[]{0};        
+    }
+    
 //    int prepareContourFile(String contourHttpPtr, File workingDir) throws IOException
 //    {
 //        ProcessComponent pcPrepareContour = new ProcessComponent();

src/java/m/rusle2/V2_0.java

@@ -214,10 +214,10 @@
                     JSONArray aStripBarrierSystems = new JSONArray(r2run.getResultPyromeArray("STRIP_BARRIER_SYS", true, true));
                     results.put(JSONUtils.data(KEY_STRIP_BARRIER_SYSTEMS, aStripBarrierSystems));
                 }
-                if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_CONTOURSYSTEMS)) {
-                    JSONArray aContourSystems = new JSONArray(r2run.getResultPyromeArray("CONTOUR_SYS", true, true));
-                    results.put(JSONUtils.data(KEY_CONTOURSYSTEMS, aContourSystems));
-                }
+//                if (JSONUtils.checkKeyExistsB(getParamMap(), KEY_CONTOURSYSTEMS)) {
+//                    JSONArray aContourSystems = new JSONArray(r2run.getResultPyromeArray("CONTOUR_SYS", true, true));
+//                    results.put(JSONUtils.data(KEY_CONTOURSYSTEMS, aContourSystems));
+//                }
             }
         } else {
             results.put(JSONUtils.data(KEY_CLIMATES, climate));
@@ -264,44 +264,37 @@
 //                soilPtr = Integer.toString(aSoils.getInt(i));
         }
 
-        JSONArray diversions = new JSONArray();
-        JSONArray contoursytems = new JSONArray();
-        JSONArray stripBarrrierSystems = new JSONArray();
+        //JSONArray diversions = new JSONArray();
+        //JSONArray contoursytems = new JSONArray();
+        //JSONArray stripBarrrierSystems = new JSONArray();
 
         // scalar variables for non-segmented runs
         String contourSystem = "";
         String stripBarrierSystem = "";
         String hydElemSystem = "";
-        // Retrieve contourSystem, stripBarrierSystem, hydElemSystem elements:
-        if (JSONUtils.checkKeyExistsB(param, KEY_TOPO_LENGTH)) {   // for slope segments
-            if (JSONUtils.checkKeyExistsB(param, KEY_DIVERSIONS)) {
-                diversions = JSONUtils.getJSONArrayParam(param, KEY_DIVERSIONS);
-            }
-            if (JSONUtils.checkKeyExistsB(param, KEY_CONTOURSYSTEMS)) {
-                contoursytems = JSONUtils.getJSONArrayParam(param, KEY_CONTOURSYSTEMS);
-            }
-            if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_SYSTEMS)) {
-                stripBarrrierSystems = JSONUtils.getJSONArrayParam(param, KEY_STRIP_BARRIER_SYSTEMS);
-            }
-        } else {   // for single slope segment
-            if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_SYSTEM_PTR)) {
-                contourSystem = JSONUtils.getStringParam(param, KEY_CONTOUR_SYSTEM_PTR, "");
-            }
-            if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_SYSTEM_PTR)) {
-                stripBarrierSystem = JSONUtils.getStringParam(param, KEY_STRIP_BARRIER_SYSTEM_PTR, "");
-            }
-            if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
-                hydElemSystem = JSONUtils.getStringParam(param, KEY_HYD_ELEM_SYSTEM_PTR, "");
-            }
+
+        // Get the Contour System if not default
+        if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_SYSTEM_PTR)) {
+            contourSystem = JSONUtils.getStringParam(param, KEY_CONTOUR_SYSTEM_PTR, "");
         }
 
+        // Get the Strip Barrier System
+        if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_SYSTEM_PTR)) {
+            stripBarrierSystem = JSONUtils.getStringParam(param, KEY_STRIP_BARRIER_SYSTEM_PTR, "");
+        }
+        
+        // Get the Hydraylic Element System Pointer  
+        if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
+            hydElemSystem = JSONUtils.getStringParam(param, KEY_HYD_ELEM_SYSTEM_PTR, "");
+        }
+        
         JSONArray aTopoLength = new JSONArray();
         JSONArray aTopoSteepness = new JSONArray();
         JSONArray aSoilIdx = new JSONArray();
         JSONArray aManIdx = new JSONArray();
-        JSONArray aDiversionIdx = new JSONArray();
-        JSONArray aContourIdx = new JSONArray();
-        JSONArray aStripBarrierIdx = new JSONArray();
+//        JSONArray aDiversionIdx = new JSONArray();
+//        JSONArray aContourIdx = new JSONArray();
+//        JSONArray aStripBarrierIdx = new JSONArray();
         if (JSONUtils.checkKeyExistsB(param, KEY_TOPO_LENGTH)) {
             aTopoLength = JSONUtils.getJSONArrayParam(param, KEY_TOPO_LENGTH);
             for (int i = 0; i < aTopoLength.length(); i++) {
@@ -341,24 +334,26 @@
             }
         }
 
-        if (JSONUtils.checkKeyExistsB(param, KEY_DIVERSION_INDEX)) {
-            aDiversionIdx = JSONUtils.getJSONArrayParam(param, KEY_DIVERSION_INDEX);
-            for (int i = 0; i < aDiversionIdx.length(); i++) {
-                LOG.info("Diversion Index [" + i + "]=" + aDiversionIdx.getInt(i));
-            }
-        }
-        if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_INDEX)) {
-            aContourIdx = JSONUtils.getJSONArrayParam(param, KEY_CONTOUR_INDEX);
-            for (int i = 0; i < aContourIdx.length(); i++) {
-                LOG.info("Contour Index [" + i + "]=" + aContourIdx.getInt(i));
-            }
-        }
-        if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_INDEX)) {
-            aStripBarrierIdx = JSONUtils.getJSONArrayParam(param, KEY_STRIP_BARRIER_INDEX);
-            for (int i = 0; i < aStripBarrierIdx.length(); i++) {
-                LOG.info("Strip Barrier Index [" + i + "]=" + aStripBarrierIdx.getInt(i));
-            }
-        }
+//        if (JSONUtils.checkKeyExistsB(param, KEY_DIVERSION_INDEX)) {
+//            aDiversionIdx = JSONUtils.getJSONArrayParam(param, KEY_DIVERSION_INDEX);
+//            for (int i = 0; i < aDiversionIdx.length(); i++) {
+//                LOG.info("Diversion Index [" + i + "]=" + aDiversionIdx.getInt(i));
+//            }
+//        }
+        
+//        if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_INDEX)) {
+//            aContourIdx = JSONUtils.getJSONArrayParam(param, KEY_CONTOUR_INDEX);
+//            for (int i = 0; i < aContourIdx.length(); i++) {
+//                LOG.info("Contour Index [" + i + "]=" + aContourIdx.getInt(i));
+//            }
+//        }
+        
+//        if (JSONUtils.checkKeyExistsB(param, KEY_STRIP_BARRIER_INDEX)) {
+//            aStripBarrierIdx = JSONUtils.getJSONArrayParam(param, KEY_STRIP_BARRIER_INDEX);
+//            for (int i = 0; i < aStripBarrierIdx.length(); i++) {
+//                LOG.info("Strip Barrier Index [" + i + "]=" + aStripBarrierIdx.getInt(i));
+//            }
+//        }
 
         if (JSONUtils.checkKeyExistsB(param, KEY_TOPO_LENGTH)) {
             if (!allEqual(aTopoLength.length(), aTopoSteepness.length(), aSoilIdx.length(), aManIdx.length())) {
@@ -524,14 +519,14 @@
                 text += (i == aManIdx.length() - 1) ? "]\n" : ",";
             }
             fos.write(text.getBytes());
-            if ((aDiversionIdx != null) && (aDiversionIdx.length() > 0)) {
-                text = "    diversionIndex=[";
-                for (int i = 0; i < aDiversionIdx.length(); i++) {
-                    text += aDiversionIdx.getInt(i) + "";
-                    text += (i == aDiversionIdx.length() - 1) ? "]\n" : ",";
-                }
-                fos.write(text.getBytes());
-            }
+//            if ((aDiversionIdx != null) && (aDiversionIdx.length() > 0)) {
+//                text = "    diversionIndex=[";
+//                for (int i = 0; i < aDiversionIdx.length(); i++) {
+//                    text += aDiversionIdx.getInt(i) + "";
+//                    text += (i == aDiversionIdx.length() - 1) ? "]\n" : ",";
+//                }
+//                fos.write(text.getBytes());
+//            }
 
         } else {
             String text = "    slopes=['" + steepness + "']\n";
@@ -553,45 +548,71 @@
             String text = "    soil" + i + " = RomeFilesOpen(files, '#XML:soils_file" + i + ".xml',0)\n";
             fos.write(text.getBytes());
         }
+
         if ((contourSystem != null) && (contourSystem.length() > 1)) {
-            fos.write("    contour = RomeFilesOpen(files, '#XML:contour_file0.xml',0)\n".getBytes());
-            String text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa', 0)\n";
+            // Contour Systems can simply point to the nginx XML file - no need to prefetch because of no special
+            // characters in the file name
+            String text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', '" + contourSystem + "', 0)\n";
             fos.write(text.getBytes());
         }
 
+        // To prevent issues with pyrome converting special chars in filenames to invalid chars for web server retrieval,
+        // we prefetch the file, insert a dummy name, and point to it here
         if ((stripBarrierSystem != null) && (stripBarrierSystem.length() > 1)) {
             fos.write("    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file0.xml',0)\n".getBytes());
             String text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa', 0)\n";
             fos.write(text.getBytes());
         }
 
+        // Runs with a Hydraulic Element System, use a hydraulic element flow path
         if ((hydElemSystem != null) && (hydElemSystem.length() > 1)) {
-            fos.write("    hydelem = RomeFilesOpen(files, '#XML:hydelem_file0.xml',0)\n".getBytes());
-            String text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa', 0)\n";
+            // Load the hyd elem flow path into the workspace
+            fos.write("    hydelem = RomeFilesOpen(files, '#XML:hydelemflowpath_file.xml',0)\n".getBytes());
+//            String r2db = Config.getString("r2.db", "http://oms-db.engr.colostate.edu/r2");
+//            String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml";
+            int numFlowPaths =  r2run.DetermineNumberOfFlowPaths(hydElemSystem);
+            String text = "    RomeFileSetAttrSize(profile, 'NUM_FLOW_PATHS', " + numFlowPaths + ")\n";
             fos.write(text.getBytes());
+            double offsets[] = r2run.DetermineFlowPathDistribution(hydElemSystem);
+            for (int i=0 ; i< numFlowPaths; i++)
+            {
+                text = "    RomeFileSetAttrSize(profile, 'FLOW_PATH_HORIZ', '" + length * offsets[i] + "', " + i + ")\n";                
+                fos.write(text.getBytes());
+                if ( i < numFlowPaths)
+                {
+                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\hydelemflowpath1', " + i + ")";
+                    fos.write(text.getBytes());
+                }
+                else
+                {
+                    // last flow path is always the default
+                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\default', " + i + ")";
+                    fos.write(text.getBytes());
+                }
+            }
         }
-// need to set these elements based on array settings
-        for (int i = 0; i < aDiversionIdx.length(); i++) {
-            String text = "    hydelem = RomeFilesOpen(files, '#XML:hydelem_file" + i + ".xml',0)\n";
-            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + i + "', 0)\n";
+        
+//// need to set these elements based on array settings
+//        for (int i = 0; i < aDiversionIdx.length(); i++) {
+//            String text = "    hydelem = RomeFilesOpen(files, '#XML:hydelem_file" + i + ".xml',0)\n";
 //            fos.write(text.getBytes());
-        }
+////            text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + i + "', 0)\n";
+////            fos.write(text.getBytes());
+//        }
 
-        for (int i = 0; i < aStripBarrierIdx.length(); i++) {
-            String text = "    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file" + i + ".xml',0)\n";
-            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + i + "', 0)\n";
+//        for (int i = 0; i < aStripBarrierIdx.length(); i++) {
+//            String text = "    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file" + i + ".xml',0)\n";
 //            fos.write(text.getBytes());
-        }
+////            text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + i + "', 0)\n";
+////            fos.write(text.getBytes());
+//        }
 
-        for (int i = 0; i < aContourIdx.length(); i++) {
-            String text = "    contour = RomeFilesOpen(files, '#XML:contour_file" + i + ".xml',0)\n";
-            fos.write(text.getBytes());
-//            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + i + "', 0)\n";
+//        for (int i = 0; i < aContourIdx.length(); i++) {
+//            String text = "    contour = RomeFilesOpen(files, '#XML:contour_file" + i + ".xml',0)\n";
 //            fos.write(text.getBytes());
-
-        }
+////            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + i + "', 0)\n";
+////            fos.write(text.getBytes());
+//        }
 
         String text = "    RomeFileSetAttrValue(profile, 'SLOPE_HORIZ', '" + length + "', 0)\n";
         fos.write(text.getBytes());
@@ -633,18 +654,18 @@
                 text = "    print('SEG_SOIL_LAYER=%s' % str(soilIndex[" + i + "]), " + i + ")\n";
                 fos.write(text.getBytes());
 
-                if ((diversions != null) && (diversions.length() > 0)) {
-                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + aDiversionIdx.getInt(i) + "', " + i + ")\n";
-                    fos.write(text.getBytes());
-                }
-                if ((stripBarrrierSystems != null) && (stripBarrrierSystems.length() > 0)) {
-                    text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + aStripBarrierIdx.getInt(i) + "', " + i + ")\n";
-                    fos.write(text.getBytes());
-                }
-                if ((contoursytems != null) && (contoursytems.length() > 0)) {
-                    text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + aContourIdx.getInt(i) + "', " + i + ")\n";
-                    fos.write(text.getBytes());
-                }
+//                if ((diversions != null) && (diversions.length() > 0)) {
+//                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', 'hydraulic-element-systems\\\\aaa" + aDiversionIdx.getInt(i) + "', " + i + ")\n";
+//                    fos.write(text.getBytes());
+//                }
+//                if ((stripBarrrierSystems != null) && (stripBarrrierSystems.length() > 0)) {
+//                    text = "    RomeFileSetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', 'strip-barrier-systems\\\\aaa" + aStripBarrierIdx.getInt(i) + "', " + i + ")\n";
+//                    fos.write(text.getBytes());
+//                }
+//                if ((contoursytems != null) && (contoursytems.length() > 0)) {
+//                    text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', 'contour-systems\\\\aaa" + aContourIdx.getInt(i) + "', " + i + ")\n";
+//                    fos.write(text.getBytes());
+//                }
             }
 
         } else {
@@ -685,48 +706,75 @@
             fos.write(text.getBytes());
         }
 
-        // request erosion by segment, if a segmented run
-        if (aTopoLength.length() > 1) {
-            for (int i = 0; i < aTopoLength.length(); i++) {
-                text = "    results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + "))\n";
-                fos.write(text.getBytes());
-                text = "    print('SEG_SOIL_LOSS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
-                fos.write(text.getBytes());
-//                text = "    results.append(float(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
+        // Request output for segments (seg 0 for non segmented runs)
+        fos.write("        numflowpaths = RomeFileGetAttrSize(profile, 'NUM_FLOW_PATHS')\n".getBytes());
+        fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+        fos.write("        print('NUMBER OF FLOWPATHS=%d' % numflowpaths)\n".getBytes());
+        fos.write("        for xx in range (numflowpaths):\n".getBytes());
+        fos.write("            print('FLOW_PATH_HORIZ:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'FLOW_PATH_HORIZ', xx)))\n".getBytes());
+        fos.write("            print('HYD_ELEM_FLOW_PATH_PTR:%d=%s' % (xx, RomeFileGetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', xx)))\n".getBytes());
+        fos.write("        numsegs = RomeFileGetAttrSize(profile, 'SEGMENT')\n".getBytes());
+        fos.write("        print('NUMBER OF SEGMENTS=%d' % numsegs)\n".getBytes());
+        fos.write("        for x in range (numsegs):\n".getBytes());
+        fos.write("            print('------------------------------------------------------------------------------')\n".getBytes());
+        fos.write("            print('SEGMENT:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEGMENT', x)))\n".getBytes());
+        fos.write("            print('SEG_HORIZ:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_HORIZ', x)))\n".getBytes());
+        fos.write("            print('SEG_STEEP:%d=%s' % (x,RomeFileGetAttrValue(profile, 'SEG_STEEP', x)))\n".getBytes());
+        fos.write("            print('SEG_MAN:%d=%s' % (x, RomeFileGetAttrValue(profile, 'MAN_PTR', x)))\n".getBytes());
+        fos.write("            print('SEG_SOIL:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SOIL_PTR', x)))\n".getBytes());
+        fos.write("            results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x))\n".getBytes());
+        fos.write("            print('SEG_SOIL_LOSS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', x)))\n".getBytes());
+        fos.write("            print('SEG_SOIL_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', x)))\n".getBytes());
+        fos.write("            print('SEG_MAN_LAYER %d=%s' % (x, RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', x)))\n".getBytes());
+        fos.write("            print('HYD_ELEM_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', x)))\n".getBytes());
+        fos.write("            print('STRIP_BARRIER_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', x)))\n".getBytes());
+        fos.write("            print('CONTOUR_SYS:%d=%s' % (x, RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', x)))\n".getBytes());
+        fos.write("        print('------------------------------------------------------------------------------')\n".getBytes());
+
+//        // request erosion by segment, if a segmented run
+//        if (aTopoLength.length() > 1) {
+//            for (int i = 0; i < aTopoLength.length(); i++) {
+//                text = "    results.append(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + "))\n";
 //                fos.write(text.getBytes());
-//                text = "    print('seg man layer %i =%s' % (" +i + " , RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
+//                text = "    print('SEG_SOIL_LOSS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
 //                fos.write(text.getBytes());
-//                text = "    print('seg soil layer %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
+////                text = "    results.append(float(RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
+////                fos.write(text.getBytes());
+////                text = "    print('seg man layer %i =%s' % (" +i + " , RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
+////                fos.write(text.getBytes());
+////                text = "    print('seg soil layer %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
+////                fos.write(text.getBytes());
+////                text = "    print('seg soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
+////                fos.write(text.getBytes());
+////                text = "    print('slope soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + ")))\n";
+////                fos.write(text.getBytes());
+////                text = "    results.append(RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + "))\n";
+////                fos.write(text.getBytes());
+//                text = "    print('SEG_SOIL:" + i + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + i + "))\n";
 //                fos.write(text.getBytes());
-//                text = "    print('seg soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SEG_SOIL_LOSS', " + i + ")))\n";
+//                text = "    print('SEG_MAN:" + i + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + i + "))\n";
 //                fos.write(text.getBytes());
-//                text = "    print('slope soil loss %i =%s' % (" + i + " , RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + ")))\n";
+//                text = "    print('SEG_SOIL_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
 //                fos.write(text.getBytes());
-//                text = "    results.append(RomeFileGetAttrValue(profile, 'SLOPE_SOIL_LOSS', " + i + "))\n";
+//                text = "    print('SEG_MAN_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
 //                fos.write(text.getBytes());
-                text = "    print('SEG_SOIL:" + i + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + i + "))\n";
-                fos.write(text.getBytes());
-                text = "    print('SEG_MAN:" + i + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + i + "))\n";
-                fos.write(text.getBytes());
-                text = "    print('SEG_SOIL_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_SOIL_LAYER', " + i + ")))\n";
-                fos.write(text.getBytes());
-                text = "    print('SEG_MAN_LAYER " + i + "=%s' % (RomeFileGetAttrValue(profile, 'SEG_MAN_LAYER', " + i + ")))\n";
-                fos.write(text.getBytes());
-                text = "    print('HYD_ELEM_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', " + i + ")))\n";
-                fos.write(text.getBytes());
-                text = "    print('STRIP_BARRIER_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', " + i + ")))\n";
-                fos.write(text.getBytes());
-                text = "    print('CONTOUR_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', " + i + ")))\n";
-                fos.write(text.getBytes());
-            }
-        } else {
-            // always return soil and man ptrs at index 0 - requested by Lucas for IET
-            text = "    print('SEG_SOIL:0" + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + 0 + "))\n";
-            fos.write(text.getBytes());
-            text = "    print('SEG_MAN:0" + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + 0 + "))\n";
-            fos.write(text.getBytes());
-            // 
-        }
+//                text = "    print('HYD_ELEM_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'HYD_ELEM_SYSTEM_PTR', " + i + ")))\n";
+//                fos.write(text.getBytes());
+//                text = "    print('STRIP_BARRIER_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'STRIP_BARRIER_SYSTEM_PTR', " + i + ")))\n";
+//                fos.write(text.getBytes());
+//                text = "    print('CONTOUR_SYS:" + i + "=%s' % (RomeFileGetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', " + i + ")))\n";
+//                fos.write(text.getBytes());
+//            }
+//        } else {
+//            // always return soil and man ptrs at index 0 - requested by Lucas for IET
+//            text = "    print('SEG_SOIL:0" + "=%s' % RomeFileGetAttrValue(profile, 'SOIL_PTR', " + 0 + "))\n";
+//            fos.write(text.getBytes());
+//            text = "    print('SEG_MAN:0" + "=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', " + 0 + "))\n";
+//            fos.write(text.getBytes());
+//            // 
+//        }
+
+
 //        fos.write("    print('SLOPE_DELIVERY=%s' % RomeFileGetAttrValue(profile, 'SLOPE_DELIVERY', 0))\n".getBytes());
 //        fos.write("    print('SLOPE_T_VALUE=%s' % RomeFileGetAttrValue(profile, 'SLOPE_T_VALUE', 0))\n".getBytes());
 //        fos.write("    print('SLOPE_DEGRAD=%s' % RomeFileGetAttrValue(profile, 'SLOPE_DEGRAD', 0))\n".getBytes());
@@ -756,26 +804,26 @@
         fos.write("    RomeDatabaseClose(database)\n".getBytes());
         fos.write("    RomeExit(romeDLL)\n".getBytes());
 
-        // Prepare multiple soils, contour sys, strips barriers, and hydraulic element files
+        // Prepare multiple soils, strips barriers, and hydraulic element files
         for (int i = 0; i < aSoils.length(); i++) {
             String soilHttpPtr = r2db + "/" + soilPtr[i].replace("\\", "/") + ".xml";
             r2run.prepareSoilsFile(soilHttpPtr, new File(getWorkspaceDir(), "soils_file" + i + ".xml"), true, String.valueOf(i));
         }
-        for (int i = 0; i < contoursytems.length(); i++) {
-            String contourSys = contoursytems.getString(i);
-            String contourHttpPtr = r2db + "/" + contourSys.replace("\\", "/") + ".xml";
-            r2run.prepareFile(contourHttpPtr, new File(getWorkspaceDir(), "contour_file" + i + ".xml"), "contour", "contour-systems", Integer.toString(i));
-        }
-        for (int i = 0; i < stripBarrrierSystems.length(); i++) {
-            String stripBarrierSys = stripBarrrierSystems.getString(i);
-            String stripbarrHttpPtr = r2db + "/" + stripBarrierSys.replace("\\", "/") + ".xml";
-            r2run.prepareFile(stripbarrHttpPtr, new File(getWorkspaceDir(), "stripbarr_file" + i + ".xml"), "strip-barrier", "strip-barrier-systems", Integer.toString(i));
-        }
-        for (int i = 0; i < diversions.length(); i++) {
-            String hydElemSys = diversions.getString(i);
-            String hydelemHttpPtr = r2db + "/" + hydElemSys.replace("\\", "/") + ".xml";
-            r2run.prepareFile(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelem_file" + i + ".xml"), "hydraulic-element", "hydraulic-element-systems", Integer.toString(i));
-        }
+//        for (int i = 0; i < contoursytems.length(); i++) {
+//            String contourSys = contoursytems.getString(i);
+//            String contourHttpPtr = r2db + "/" + contourSys.replace("\\", "/") + ".xml";
+//            r2run.prepareFile(contourHttpPtr, new File(getWorkspaceDir(), "contour_file" + i + ".xml"), "contour", "contour-systems", Integer.toString(i));
+//        }
+//        for (int i = 0; i < stripBarrrierSystems.length(); i++) {
+//            String stripBarrierSys = stripBarrrierSystems.getString(i);
+//            String stripbarrHttpPtr = r2db + "/" + stripBarrierSys.replace("\\", "/") + ".xml";
+//            r2run.prepareFile(stripbarrHttpPtr, new File(getWorkspaceDir(), "stripbarr_file" + i + ".xml"), "strip-barrier", "strip-barrier-systems", Integer.toString(i));
+//        }
+//        for (int i = 0; i < diversions.length(); i++) {
+//            String hydElemSys = diversions.getString(i);
+//            String hydelemHttpPtr = r2db + "/" + hydElemSys.replace("\\", "/") + ".xml";
+//            r2run.prepareFile(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelem_file" + i + ".xml"), "hydraulic-element", "hydraulic-element-systems", Integer.toString(i));
+//        }
 
         // prepare individual contour system, strip barrier system, hyd elem sys, if not provided in an array
         if (JSONUtils.checkKeyExistsB(param, KEY_CONTOUR_SYSTEM_PTR)) {
@@ -788,7 +836,7 @@
         }
         if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
             String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml";
-            r2run.prepareFile(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelem_file0.xml"), "hydraulic-element", "hydraulic-element-systems", "");
+            r2run.prepareHydraulicElementFlowPath(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelemflowpath_file.xml"));
         }
 
         // prepare climate file
@@ -859,7 +907,11 @@
         //LOG.info("Rusle2 report output obj=" + reportObj.toString());        
     }
 
-
+    private void prepareHydraulicFlowElementFile()
+    {
+        // Given a Hydraulic Element Pointer, parse the XML and return a Hydraulic Flow Element
+    }
+    
     private JSONObject processReportElement(JSONObject obj, String type, String value) throws Exception {
         if ((type.equals("TEXT")) || (type.equals("FILENAME")) || (type.equals("DATE"))) {
             // because the RomeShell returns escaped strings, and the JSONObject in Java re-escapes them

web/META-INF/csip-conf.json

@@ -1,3 +1,3 @@
 {
-    "csip-erosion.version": "$version: 0.2.11 7e52adac9c51 2016-03-30 od, built at: 2016-04-01 14:28 by wlloyd$"
+    "csip-erosion.version": "$version: 0.2.12 384f8dd2d548 2016-04-01 $"
 }