@@ -12,6 +12,9 @@ |
import csip.utils.Binaries; |
import csip.utils.JSONUtils; |
import java.io.*; |
+import java.math.RoundingMode; |
+import java.text.DecimalFormat; |
+import java.text.NumberFormat; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.HashMap; |
@@ -167,11 +170,25 @@ |
// Our WEPS model call uses the following cmd line args |
// /weps -W1 -u0 -I2 -t1 -P./ >stdout.txt 2>stderr.txt |
pc = new ProcessComponent(); |
+ |
+ // linux based WEPS |
pc.exe = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/weps", new File(binDir)).toString(); |
pc.args = new String[]{"-W1", "-u0", "-I2", "-t1", "-T1", "-P./"}; |
pc.working_dir = sessionWorkDir; |
pc.execute(); |
|
+ // windows 32-bit WEPS - WARNING Runs much slower |
+// pc.exe = Binaries.unpackResource("/bin/win-x86/weps.exe", new File(binDir)).toString(); |
+// File wepssh = new File(sessionWorkDir + "/runweps.sh"); |
+// String invokeWeps = "wine " + pc.exe + " -W1 -u0 -I2 -t1 -T1 -P./"; |
+// FileUtils.writeStringToFile(wepssh, invokeWeps); |
+// wepssh.setExecutable(true); |
+// |
+// pc.working_dir = sessionWorkDir; |
+// pc.exe = "./runweps.sh"; |
+// pc.args = new String[]{}; |
+// pc.execute(); |
+ |
// Check standard out for "inpsub" error - occurs when no soil file is available |
if (pc.stdout.contains("inpsub error")) |
throw new Exception("ERROR RUNNING WEPS--Standard output:" + pc.stdout); |
@@ -561,7 +578,13 @@ |
|
// Generate weights file |
ProcessComponent pcInterpolate = new ProcessComponent(); |
+ |
+ // windows |
+ //String exepath = Binaries.unpackResource("/bin/win-x86/interpolate.exe", new File(binDir)).toString(); |
+ |
+ // linux |
String exepath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/interpolate", new File(binDir)).toString(); |
+ |
String dbpath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/wind_gen_his_upper_US_NRCS.idx", new File(binDir)).toString(); |
String polygon = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/interpolation_boundary.pol", new File(binDir)).toString(); |
|
@@ -570,7 +593,17 @@ |
|
// Generate shell script to invoke interpolate |
File interpolatesh = new File(sessionWorkDir + "/interpolate.sh"); |
- String invokeInterpolate = exepath + " -f " + dbpath + " -p " + polygon + " -lat " + wepsCounty.county_centroid_Y + " -long " + wepsCounty.county_centroid_X; |
+ NumberFormat nf = DecimalFormat.getInstance(); |
+ nf.setMaximumFractionDigits(2); |
+ nf.setMinimumFractionDigits(2); |
+ nf.setRoundingMode(RoundingMode.HALF_UP); |
+ double countyCentroidLat = Double.parseDouble(wepsCounty.county_centroid_Y); |
+ double countyCentroidLon = Double.parseDouble(wepsCounty.county_centroid_X); |
+ LOG.log(Level.INFO, "***county centroid lat=" + countyCentroidLat + " lon=" + countyCentroidLon); |
+ // windows |
+ //String invokeInterpolate = "wine " + exepath + " -f " + dbpath + " -p " + polygon + " -lat " + nf.format(countyCentroidLat) + " -long " + nf.format(countyCentroidLon); |
+ // linux |
+ String invokeInterpolate = exepath + " -f " + dbpath + " -p " + polygon + " -lat " + nf.format(countyCentroidLat) + " -long " + nf.format(countyCentroidLon); |
FileUtils.writeStringToFile(interpolatesh, invokeInterpolate); |
interpolatesh.setExecutable(true); |
|
@@ -597,8 +630,12 @@ |
// therefore everything has to be extracted to the workdir and done locally there. |
// This is BAD (inefficient) because it is extra work to always extract wind station wdb's for every model run! |
ProcessComponent pcInterpWdb = new ProcessComponent(); |
+ |
+ // windows |
+ //exepath = Binaries.unpackResource("/bin/win-x86/interp_wdb.exe", new File(binDir)).toString(); |
+ // linux |
exepath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/interp_wdb", new File(binDir)).toString(); |
- |
+ |
// String station1Db = BinUtils.unpackResourceAbsolute("/bin/" + BinUtils.getArch() + "/windstations/" + wp.station1 + ".wdb", sessionWorkDir + "/" + wp.station1 + ".wdb").toString(); |
// String station2Db = BinUtils.unpackResourceAbsolute("/bin/" + BinUtils.getArch() + "/windstations/" + wp.station2 + ".wdb", sessionWorkDir + "/" + wp.station2 + ".wdb").toString(); |
// String station3Db = BinUtils.unpackResourceAbsolute("/bin/" + BinUtils.getArch() + "/windstations/" + wp.station3 + ".wdb", sessionWorkDir + "/" + wp.station3 + ".wdb").toString(); |
@@ -608,6 +645,9 @@ |
|
// Generate shell script to invoke interpolate |
File interpwdbsh = new File(sessionWorkDir + "/interpwdb.sh"); |
+ // windows |
+ //String invokeInterpWdb = "wine " + exepath + " test.wdb" + " " + station1Db + wp.weight1 + " " + station2Db + wp.weight2 + " " + station3Db + wp.weight3; |
+ // linux |
String invokeInterpWdb = exepath + " test.wdb" + " " + station1Db + wp.weight1 + " " + station2Db + wp.weight2 + " " + station3Db + wp.weight3; |
FileUtils.writeStringToFile(interpwdbsh, invokeInterpWdb); |
interpwdbsh.setExecutable(true); |
@@ -639,8 +679,8 @@ |
} |
// generate win file using this station (or interpolated one) |
ProcessComponent pcWindGen = new ProcessComponent(); |
- String exepath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/wind_gen4", new File(binDir)).toString(); |
- String winexepath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/wind_gen4.exe", new File(binDir)).toString(); |
+ //String exepath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/wind_gen4", new File(binDir)).toString(); |
+ String winexepath = Binaries.unpackResource("/bin/win-x86/wind_gen4.exe", new File(binDir)).toString(); |
LOG.log(Level.INFO, "Using wind database:" + windDbPath); |
|
// Generate shell script to invoke windgen |