Displaying differences for changeset
 
display as  

src/java/m/rusle2/R2Run.java

@@ -155,15 +155,15 @@
     
     // 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
+    int prepareHydraulicElementFlowPath(String hydElemPtr, String r2db, 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 += "wget \"" + hydElemPtr + "\" -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 += "wget \"" + r2db + "/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";
@@ -180,9 +180,12 @@
     
     int DetermineNumberOfFlowPaths(String hydElemPtr) 
     {
+        hydElemPtr = hydElemPtr.substring(hydElemPtr.lastIndexOf("\\")+1);
+
         // 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
-        
+        LOG.info("***********************************************************************************\n\n\n\nHYD ELEM PTR=" + hydElemPtr);        
+        //if (hydElemPtr.substring(hydElemPtr.lastIndexOf("\")+1).startsWith("1"))
         if (hydElemPtr.startsWith("1"))
         {
             if (hydElemPtr.contains("middle"))
@@ -224,10 +227,11 @@
     
     double[] DetermineFlowPathDistribution(String hydElemPtr)
     {
+        hydElemPtr = hydElemPtr.substring(hydElemPtr.lastIndexOf("\\")+1);
         // 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.substring( hydElemPtr.lastIndexOf("\\")+1 ).startsWith("1"))
         {
             if (hydElemPtr.contains("middle"))
                 return new double[]{.5, 1};

src/java/m/rusle2/V2_0.java

@@ -299,10 +299,10 @@
             aTopoLength = JSONUtils.getJSONArrayParam(param, KEY_TOPO_LENGTH);
             for (int i = 0; i < aTopoLength.length(); i++) {
                 LOG.info("Topo Length [" + i + "]=" + aTopoLength.getDouble(i));
-                // this is temporary, since R2 will be using slope segments soon
-                if (i == 0) {
-                    length = aTopoLength.getDouble(i);
-                }
+//                // this is temporary, since R2 will be using slope segments soon
+//                if (i == 0) {
+//                    length = aTopoLength.getDouble(i);
+//                }
             }
         }
 
@@ -549,49 +549,7 @@
             fos.write(text.getBytes());
         }
 
-        if ((contourSystem != null) && (contourSystem.length() > 1)) {
-            // 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)) {
-            // 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";
@@ -619,6 +577,10 @@
         text = "    RomeFileSetAttrValue(profile, 'SLOPE_STEEP', '" + steepness + "', 0)\n";
         fos.write(text.getBytes());
 
+        fos.write("    # SET CLIMATE_PTR\n".getBytes());
+        fos.write("    RomeFileSetAttrValue(profile, 'CLIMATE_PTR','climates\\\\aaa',0)\n".getBytes());
+        fos.write("    print('CLIMATE_PTR=%s' % RomeFileGetAttrValue(profile, 'CLIMATE_PTR', 0))\n".getBytes());
+        
         if (JSONUtils.checkKeyExistsB(param, KEY_SIMPLE_ROCK_COVER)) {
             text = "    RomeFileSetAttrValue(profile, 'SIMPLE_ROCK_COVER', '" + simpleRockCoverPercent + "' ,0)\n";
             fos.write(text.getBytes());
@@ -684,9 +646,59 @@
 //        text = "    RomeFileSetAttrValue(profile, 'MAN_PTR', '" + StringEscapeUtils.escapeJava(managementFormalName[0]) + "',0)\n";
 //        fos.write(text.getBytes());
 //        fos.write("    print('MAN_PTR=%s' % RomeFileGetAttrValue(profile, 'MAN_PTR', 0))\n".getBytes());
-        fos.write("    # SET CLIMATE_PTR\n".getBytes());
-        fos.write("    RomeFileSetAttrValue(profile, 'CLIMATE_PTR','climates\\\\aaa',0)\n".getBytes());
-        fos.write("    print('CLIMATE_PTR=%s' % RomeFileGetAttrValue(profile, 'CLIMATE_PTR', 0))\n".getBytes());
+
+        if ((contourSystem != null) && (contourSystem.length() > 1)) {
+            // Contour Systems can simply point to the nginx XML file - no need to prefetch because of no special
+            // characters in the file name
+            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)) {
+            // for some reason, must reset SLOPE_HORIZ & SLOPE_STEEP immediately before setting a strip and barrier !!! R2 BUG
+            // This is required for the internal Rusle2 wizard to calculate proper slope segment lengths
+            text = "    RomeFileSetAttrValue(profile, 'SLOPE_HORIZ', '" + length + "', 0)\n";
+            fos.write(text.getBytes());
+            text = "    RomeFileSetAttrValue(profile, 'SLOPE_STEEP', '" + steepness + "', 0)\n";
+            fos.write(text.getBytes());
+
+            fos.write("    stripbarr = RomeFilesOpen(files, '#XML:stripbarr_file0.xml',0)\n".getBytes());
+            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)) {
+            // 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);
+            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 = "    RomeFileSetAttrValue(profile, 'FLOW_PATH_HORIZ', '" + length * offsets[i] + "', " + i + ")\n";                
+                fos.write(text.getBytes());
+                if ( i < (numFlowPaths-1))
+                {
+                    text = "    RomeFileSetAttrValue(profile, 'HYD_ELEM_FLOW_PATH_PTR', 'hydraulic-element-flow-paths\\hydelemflowpath1', " + i + ")\n";
+                    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 + ")\n";
+                    fos.write(text.getBytes());
+                }
+            }
+        }        
+        
+        
+
 
 //        if ((contourSystem != null) && (contourSystem.length() > 1)) {
 //            text = "    RomeFileSetAttrValue(profile, 'CONTOUR_SYSTEM_PTR', '" + contourSystem + "',0)\n";
@@ -707,29 +719,29 @@
         }
 
         // Request output for segments (seg 0 for non segmented runs)
-        fos.write("        numflowpaths = RomeFileGetAttrSize(profile, 'NUM_FLOW_PATHS')\n".getBytes());
+        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('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());
+        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) {
@@ -836,7 +848,7 @@
         }
         if (JSONUtils.checkKeyExistsB(param, KEY_HYD_ELEM_SYSTEM_PTR)) {
             String hydelemHttpPtr = r2db + "/" + hydElemSystem.replace("\\", "/") + ".xml";
-            r2run.prepareHydraulicElementFlowPath(hydelemHttpPtr, new File(getWorkspaceDir(), "hydelemflowpath_file.xml"));
+            r2run.prepareHydraulicElementFlowPath(hydelemHttpPtr, r2db, new File(getWorkspaceDir(), "hydelemflowpath_file.xml"));
         }
 
         // prepare climate file

web/META-INF/csip-conf.json

@@ -1,3 +1,3 @@
 {
-    "csip-erosion.version": "$version: 0.2.12 384f8dd2d548 2016-04-01 $"
+    "csip-erosion.version": "$version: 0.2.13 4db1c9639ffe 2016-04-05 $"
 }