Impoundment.java [src/java/m/weppws] Revision: default Date:
package m.weppws;
import java.util.List;
import csip.api.server.ServiceException;
import csip.SessionLogger;
import java.util.Arrays;
import java.util.Iterator;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONArray;
import util.Grid;
import util.WeppConstants;
/**
* Represents a WEPP impoundment.
*
*/
public class Impoundment {
int chanid;
int weppID;
int id;
boolean inUse;
boolean linked;
String name;
// position of impoundment relative to the channel:
// before-channel
// after-channel
// left-side
// right-side
String position;
Watershed par;
Channel chan; // channel this impoundment is linked to
double discharge;
double sedYield;
Impoundment(int id, int chanid, String name, String position, Watershed par) throws ServiceException {
this.chanid = chanid; // this is the channel this impoundment connects to
this.name = name;
weppID = id;
this.id = id;
this.position = position;
this.par = par;
linked = false;
chan = par.getChannel(chanid);
if (chan == null) {
throw new ServiceException("Impoundment refers to undefined channel: " + chanid);
}
}
String summarizeInput() throws JSONException {
JSONObject so = new JSONObject();
so.put("id", id);
so.put("weppID", weppID);
so.put("name", name);
so.put("position", position);
so.put("channel", chanid);
return so.toString(2);
}
String summarizeOutput(SessionLogger log) throws JSONException {
JSONObject so = new JSONObject();
so.put("id", id);
so.put("weppID", weppID);
so.put("name", name);
so.put("position", position);
so.put("channel", chanid);
so.put("Runoff Volume (ft^3/yr)", Float.valueOf(String.format("%.0f", discharge)));
so.put("Sediment Yield (ton/yr)", Float.valueOf(String.format("%.2f", sedYield)));
return so.toString(2);
}
String getName() {
return name;
}
String getLeftHillslope() {
// this represents a TOPAZ split subcatchment, the left hillslope draining into this impoundment
if (position.equals("left-side")) {
if (chan.hillslope.leftsub != null) {
return "H" + String.valueOf(chan.hillslope.leftsub.weppAltID);
}
}
return("0");
}
String getRightHillslope() {
// this represents a TOPAZ split subcatchment, the right hillslope draining into this impoundment
if (position.equals("right-side")) {
if (chan.hillslope.rightsub != null) {
return "H" + String.valueOf(chan.hillslope.rightsub.weppAltID);
}
}
return("0");
}
String getTopHillslope() {
// this represents a TOPAZ split subcatchment, the top hillslope draining into this impoundment
if (position.equals("before-channel")) {
if (chan.hillslope.topsub != null) {
return "H" + String.valueOf(chan.hillslope.topsub.weppAltID);
}
}
return("0");
}
String getHillslope() {
// this represents a TauDEM subcatchment which surrounds the channel on 2 (or 3) sides.
// the entire subcatchment drains into this impoundment
if (position.equals("left-side") || position.equals("right-side") || (position.equals("before-channel"))) {
return "H" + String.valueOf(chan.hillslope.weppid);
}
return "0";
}
String getLeftChannel() {
// This represents the channel draining into this impoundment from the left
if (position.equals("before-channel")) {
Channel ch2 = chan.leftChannel;
if (ch2 != null) {
return "C" + String.valueOf(ch2.weppID);
} else {
return("0");
}
}
return "0";
}
String getRightChannel() throws ServiceException {
// This represents the channel draining into this impoundment from the right
if (position.equals("before-channel")) {
Channel ch2 = chan.rightChannel;
if (ch2 != null) {
return "C" + String.valueOf(ch2.weppID);
} else {
return("0");
}
}
return "0";
}
String getTopChannel() throws ServiceException {
// This represents the channel draining into this impoundment from the top
if (position.equals("before-channel")) {
Channel ch2 = chan.topChannel;
if (ch2 != null) {
return "C" + String.valueOf(ch2.weppID);
} else {
return("0");
}
} else if (position.equals("after-channel")) {
return "C" + String.valueOf(chan.weppID);
}
return "0";
}
String getLeftImpoundment() {
// currently an impoundment does not connect with another impoundment
return "0";
}
String getRightImpoundment() {
// currently an impoundment does not connect with another impoundment
return "0";
}
String getTopImpoundment() {
// currently an impoundment does not connect with another impoundment
return "0";
}
}