Displaying differences for changeset
 
display as  

src/java/m/rusle2/R2Run.java

@@ -53,7 +53,7 @@
      */
     int execute(File r2_rsh) throws IOException {
         LOG.info("Execute method");
-        String binDir = Config.getString("m.bin.dir", "/tmp/csip/bin");
+        String binDir = Config.getString("csip.bin.dir", "/tmp/csip/bin");
 
         File romeshell = Binaries.unpackResource("/bin/win-x86/RomeShell.exe", new File(binDir));
         Binaries.unpackResource("/bin/win-x86/RomeDLL.dll", new File(binDir));
@@ -151,37 +151,35 @@
         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();        
-//        File preparesoils = new File(workingDir.getParent() + "/preparesoils" + idx + ".sh");
-//        String prepsoils = "wget \"" + soilsHttpPtr + "\" -O soils_file" + idx + ".tmp\n"; 
-//        if (bPyrome) 
-//        {
-//            prepsoils += "echo \"<?xml version=\"\\\"1.0\\\"\"?>\" > soils_file" + idx + ".xml\n";
-//        }
-//        prepsoils += "numlines=`cat soils_file" + idx + ".tmp | wc -l`\n";
-//        prepsoils += "if [ $numlines -eq 1 ]\n";
-//        prepsoils += "then\n";
-//        prepsoils += "  tail -n +1 soils_file" + idx + ".tmp >> soils_file" + idx + ".xml\n";
-//        prepsoils += "else\n";
-//        prepsoils += "  tail -n +2 soils_file" + idx + ".tmp >> soils_file" + idx + ".xml\n";
-//        prepsoils += "fi\n";
-//        FileUtils.writeStringToFile(preparesoils, prepsoils);
-//        preparesoils.setExecutable(true);
-//        LOG.info("soilsHttpPtr=" + soilsHttpPtr);
-//        LOG.info("the pc-exe is=" + pcPrepareSoils.exe);
-//        pcPrepareSoils.working_dir = workingDir.getParent();
-//        pcPrepareSoils.exe = "./preparesoils" + idx + ".sh";
-//        pcPrepareSoils.args = new String[]{};
-//        pcPrepareSoils.execute();
-//        stdout += "\n" + pcPrepareSoils.stdout;
-//        stderr += "\n" + pcPrepareSoils.stderr;
-//        return pcPrepareSoils.exitValue;
-//    }
+    // prepares soils file for legacy 1.3 rusle2 service
+    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();        
+        File preparesoils = new File(workingDir.getParent() + "/preparesoils" + idx + ".sh");
+        String prepsoils = "wget \"" + soilsHttpPtr + "\" -O soils_file" + idx + ".tmp\n"; 
+        if (bPyrome) 
+        {
+            prepsoils += "echo \"<?xml version=\"\\\"1.0\\\"\"?>\" > soils_file" + idx + ".xml\n";
+        }
+        prepsoils += "numlines=`cat soils_file" + idx + ".tmp | wc -l`\n";
+        prepsoils += "if [ $numlines -eq 1 ]\n";
+        prepsoils += "then\n";
+        prepsoils += "  tail -n +1 soils_file" + idx + ".tmp >> soils_file" + idx + ".xml\n";
+        prepsoils += "else\n";
+        prepsoils += "  tail -n +2 soils_file" + idx + ".tmp >> soils_file" + idx + ".xml\n";
+        prepsoils += "fi\n";
+        FileUtils.writeStringToFile(preparesoils, prepsoils);
+        preparesoils.setExecutable(true);
+        LOG.info("soilsHttpPtr=" + soilsHttpPtr);
+        LOG.info("the pc-exe is=" + pcPrepareSoils.exe);
+        pcPrepareSoils.working_dir = workingDir.getParent();
+        pcPrepareSoils.exe = "./preparesoils" + idx + ".sh";
+        pcPrepareSoils.args = new String[]{};
+        pcPrepareSoils.execute();
+        stdout += "\n" + pcPrepareSoils.stdout;
+        stderr += "\n" + pcPrepareSoils.stderr;
+        return pcPrepareSoils.exitValue;
+    }
     
 ////    @Deprecated
 //    int prepareClimateFile(String climateHttpPtr, File workingDir) throws IOException

src/java/m/rusle2/V1_3.java

@@ -394,8 +394,8 @@
         // commented out - using default for now
         fos.write(("FilesOpen \"#XML:" + new File(getWorkspaceDir(), "soils_file0.xml" + "\"\n")).getBytes());
         String soilHttpPtr = r2db + "/" + soilPtr.replace("\\", "/") + ".xml";
-        //r2run.prepareSoilsFile(soilHttpPtr, new File(getWorkspaceDir(), "soils_file0.xml"), false, "0");
-        r2run.prepareFileJ(soilHttpPtr, new File(getWorkspaceDir(), "soils_file0.xml"), "SOILS", "", "", false);
+        r2run.prepareSoilsFile(soilHttpPtr, new File(getWorkspaceDir(), "soils_file0.xml"), false, "0");
+        //r2run.prepareFileJ(soilHttpPtr, new File(getWorkspaceDir(), "soils_file0.xml"), "SOILS", "", "", false);
 
         String cliHttpPtr = r2db + "/" + climatePtr.replace("\\", "/") + ".xml";
         r2run.prepareFileJ(cliHttpPtr, new File(getWorkspaceDir(), "cli_file0.xml"), "CLIMATE", "climates", "",false);

src/java/m/rusle2/V2_0.java

@@ -657,6 +657,10 @@
                 fos.write(text.getBytes());
             }
         }
+        else
+        {
+            // IF no array provided, could default to single later mgmt here
+        }
 
         // This segment implementation is currently commented out in favor of populating the
         // individual topo, soil, and man layers above for now...
@@ -786,10 +790,31 @@
 //        fos.write("    results.append(RomeFileGetAttrValue(profile, 'SLOPE_DEGRAD', 0))\n".getBytes());
 
         // Request specific outputs from Rusle2
+        // Must check size and return arrays when params are arrays...
         for (String r : JSONUtils.getRequestedResults(metainfo)) {
+            text = "    paramsize = RomeFileGetAttrSize(profile,'" + r + "')\n";
+            fos.write(text.getBytes());
+            text = "    if paramsize > 1:\n";
+            fos.write(text.getBytes());
+            text = "        text = '['\n";
+            fos.write(text.getBytes());
+            text = "        for x in range (paramsize):\n";
+            fos.write(text.getBytes());
+            text = "            text += RomeFileGetAttrValue(profile,'" + r + "',x)\n";
+            fos.write(text.getBytes());
+            text = "            if x < (paramsize-1):\n";
+            fos.write(text.getBytes());
+            text = "                text += ', '\n";
+            fos.write(text.getBytes());
+            text = "        text += ']'\n";
+            fos.write(text.getBytes());
+            text = "    else:\n";
+            fos.write(text.getBytes());
+            text = "        text = RomeFileGetAttrValue(profile, '" + r + "', 0)\n";
+            fos.write(text.getBytes());
             text = "    results.append(RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
             fos.write(text.getBytes());
-            text = "    print('" + r + "=%s' % RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
+            text = "    print('" + r + "=%s' % text)\n";
             fos.write(text.getBytes());
         }
 

src/java/m/rusle2/V2_0_1.java

@@ -835,9 +835,29 @@
 
         // Request specific outputs from Rusle2
         for (String r : JSONUtils.getRequestedResults(metainfo)) {
+            text = "    paramsize = RomeFileGetAttrSize(profile,'" + r + "')\n";
+            fos.write(text.getBytes());
+            text = "    if paramsize > 1:\n";
+            fos.write(text.getBytes());
+            text = "        text = '['\n";
+            fos.write(text.getBytes());
+            text = "        for x in range (paramsize):\n";
+            fos.write(text.getBytes());
+            text = "            text += RomeFileGetAttrValue(profile,'" + r + "',x)\n";
+            fos.write(text.getBytes());
+            text = "            if x < (paramsize-1):\n";
+            fos.write(text.getBytes());
+            text = "                text += ', '\n";
+            fos.write(text.getBytes());
+            text = "        text += ']'\n";
+            fos.write(text.getBytes());
+            text = "    else:\n";
+            fos.write(text.getBytes());
+            text = "        text = RomeFileGetAttrValue(profile, '" + r + "', 0)\n";
+            fos.write(text.getBytes());
             text = "    results.append(RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
             fos.write(text.getBytes());
-            text = "    print('" + r + "=%s' % RomeFileGetAttrValue(profile, '" + r + "', 0))\n";
+            text = "    print('" + r + "=%s' % text)\n";
             fos.write(text.getBytes());
         }
 

web/META-INF/csip-conf.json

@@ -1,5 +1,5 @@
 {
-    "csip-erosion.version": "$version: 0.2.63 d8ea14008c5a 2016-05-16 wlloyd@titan, built at 2016-05-16 17:39 by wlloyd$",
+    "csip-erosion.version": "$version: 0.2.66 754f674216e4 2016-05-16 wlloyd@titan, built at 2016-05-17 18:58 by wlloyd$",
     "weps.version" : "1.3.9",
     "lmod.db": "jdbc:sqlserver:\/\/129.82.20.242:1433;databaseName=lmod_zedx;user=lmod-rw;password=managements",
     "conservation_resources.db": "jdbc:sqlserver://129.82.20.241:1433;databaseName=conservation_resources;user=sa;password=csurams#1",