@@ -5,23 +5,20 @@ |
*/ |
package m.hydrotools.efh2; |
|
-import csip.Config; |
import csip.Executable; |
import csip.annotations.*; |
import static csip.annotations.ResourceType.EXECUTABLE; |
-import csip.utils.Binaries; |
import java.io.File; |
import java.io.FileWriter; |
import java.io.IOException; |
import java.io.Writer; |
-import java.util.ArrayList; |
+import java.util.Arrays; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import java.util.Properties; |
import javax.ws.rs.Path; |
import oms3.annotations.*; |
-import oms3.util.ProcessExecution; |
import org.apache.commons.io.FileUtils; |
import org.apache.velocity.VelocityContext; |
import org.apache.velocity.app.VelocityEngine; |
@@ -34,9 +31,7 @@ |
@Name("Hydrotools") |
@Description("EFH2 service based on TR20") |
@Path("m/efh2/2.0") |
-@Resources({ |
- @Resource(file = "/bin/lin-amd64/TR20.exe", type = EXECUTABLE, id = "tr20") |
-}) |
+@Resource(file = "/bin/lin-amd64/TR20.exe", type = EXECUTABLE, id = "tr20") |
@Polling(first = 10000, next = 2000) |
public class V2_0 extends csip.ModelDataService { |
|
@@ -54,14 +49,15 @@ |
static final String RUNOFF_VOLUME = "runoff_volume"; |
static final String PEAK_DISCHARGE = "peak_discharge"; |
static final String PEAK_TIME = "peak_time"; |
+ static final String TOC = "time_of_concentration"; |
|
// internal result string. |
private String[] res; |
+ String st_name; |
+ String toc; |
|
static String format = "%-10.3f"; |
|
- String st_name; |
- |
|
@Override |
protected void preProcess() throws Exception { |
@@ -91,7 +87,6 @@ |
|
@Override |
protected String process() throws Exception { |
- |
Executable tr20 = getResourceExe("tr20"); |
int ret = tr20.exec(); |
if (ret != 0) { |
@@ -100,12 +95,26 @@ |
return FileUtils.readFileToString(err); |
} |
} |
- res = parseOutput(st_name, new File(getWorkspaceDir(), "TR20.out")); |
- if (res.length == 3) { |
- return EXEC_OK; |
- } else { |
+ File out = new File(getWorkspaceDir(), "TR20.out"); |
+ if (out.exists()) { |
+ return "Missing File : TR20.out"; |
+ } |
+ File dbg = new File(getWorkspaceDir(), "TR20.dbg"); |
+ if (dbg.exists()) { |
+ return "Missing File : TR20.dbg"; |
+ } |
+ |
+ res = parseOutput(st_name, out); |
+ if (res == null || res.length != 3) { |
return "Missing output."; |
} |
+ |
+ toc = parseDebug(dbg); |
+ if (toc == null) { |
+ return "Missing tocs."; |
+ } |
+// System.out.println("toc " + toc); |
+ return EXEC_OK; |
} |
|
|
@@ -114,12 +123,25 @@ |
putResult(RUNOFF_VOLUME, res[0], "inches"); |
putResult(PEAK_TIME, res[1], "h"); |
putResult(PEAK_DISCHARGE, res[2], "cfs"); |
+ putResult(TOC, toc, "h"); |
+ } |
+ |
+ |
+ static private String parseDebug(File debugFile) throws IOException { |
+ List<String> out = FileUtils.readLines(debugFile); |
+ for (int i = 0; i < out.size(); i++) { |
+ String l = out.get(i); |
+ if (l.trim().toLowerCase().startsWith("time of concentration =")) { |
+ String[] vals = l.trim().split("\\s+"); |
+ return (vals.length == 5) ? vals[4] : null; |
+ } |
+ } |
+ return null; |
} |
|
|
static private String[] parseOutput(String st_name, File outFile) throws IOException { |
List<String> out = FileUtils.readLines(outFile); |
- |
int st_index = 0; |
for (int i = 0; i < out.size(); i++) { |
String l = out.get(i); |
@@ -134,9 +156,9 @@ |
if (l.trim().startsWith("sub 1")) { |
String[] vals = l.split("\\s+"); |
if (vals.length > 5) { |
- System.out.println("runoff " + vals[3]); |
- System.out.println("time " + vals[4]); |
- System.out.println("rate " + vals[5]); |
+// System.out.println("runoff " + vals[3]); |
+// System.out.println("time " + vals[4]); |
+// System.out.println("rate " + vals[5]); |
return new String[]{vals[3], vals[4], vals[5]}; |
} |
break; |