@@ -1038,8 +1038,8 @@ |
</target> |
<target depends="init,compile,compile-jsps,-pre-dist,-do-dist-with-manifest,-do-dist-without-manifest" name="do-dist"/> |
<target depends="init" if="dist.ear.dir" name="library-inclusion-in-manifest"> |
+ <copyfiles files="${file.reference.Lmod2Rusle2.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
<copyfiles files="${reference.csip-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
- <copyfiles files="${file.reference.Lmod2Rusle2.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
<copyfiles files="${reference.Man2Weps.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
<copyfiles files="${file.reference.WepsReportData.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
<copyfiles files="${file.reference.commons-lang-2.4.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/> |
@@ -1057,8 +1057,8 @@ |
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/> |
</target> |
<target depends="init" name="library-inclusion-in-archive" unless="dist.ear.dir"> |
+ <copyfiles files="${file.reference.Lmod2Rusle2.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
<copyfiles files="${reference.csip-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
- <copyfiles files="${file.reference.Lmod2Rusle2.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
<copyfiles files="${reference.Man2Weps.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
<copyfiles files="${file.reference.WepsReportData.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
<copyfiles files="${file.reference.commons-lang-2.4.jar}" todir="${build.web.dir}/WEB-INF/lib"/> |
@@ -163,8 +163,9 @@ |
|
} |
} |
+ |
|
- private FileQryResult find(String select, double lng) throws SQLException { |
+ private FileQryResult findFile(String select, double lng) throws SQLException { |
// Statement s = createStatement(getConnection()); |
Statement s = createStatement(lng); |
logger.info("query sql=" + select); |
@@ -191,6 +192,28 @@ |
return res; |
} |
|
+ private double findDbl(String select, double lng, int colcnt) throws SQLException { |
+ // Statement s = createStatement(getConnection()); |
+ Statement s = createStatement(lng); |
+ logger.info("query sql=" + select); |
+ ResultSet r = s.executeQuery(select); |
+ int cols = r.getMetaData().getColumnCount(); |
+ if (cols != colcnt) { |
+ //s.close(); |
+ logger.severe("invalid number of columns returned in find dbl query:" + select); |
+ throw new IllegalArgumentException("invalid Columns"); |
+ } |
+ if (!r.next()) { |
+ //s.close(); |
+ logger.severe("no result from find dbl query!"); |
+ return 0.0; |
+ } |
+ logger.info("value=" + r.getDouble(1)); |
+ return r.getDouble(1); |
+ //s.close(); |
+ } |
+ |
+ |
private Collection<Soil> findPolygons(String select, double lng) throws SQLException { |
// Statement s = createStatement(getConnection()); |
LinkedList<Soil> soilLst = new LinkedList<Soil>(); |
@@ -494,7 +517,7 @@ |
|
public FileQryResult findSoils(double lat, double lon) throws SQLException { |
// new query - mbound |
- return find ("SELECT m.musym, r2_path, r2_name FROM soil_geom AS g, map_soils AS m " + |
+ return findFile ("SELECT m.musym, r2_path, r2_name FROM soil_geom AS g, map_soils AS m " + |
"WHERE ST_Within(ST_SetSRID(ST_Point(" + lon + "," + lat + "),4326), g.geometry) " + |
"AND g.mukey = m.mukey LIMIT 1;", lon); |
// old query - had nasty join on a nested query - dbound |
@@ -509,7 +532,7 @@ |
// |
// added string matching to fix a problem which requires us to regenerate r2 soils |
public FileQryResult findSoilsByCokey(String cokey, double lon) throws SQLException { |
- return find ("SELECT distinct m.musym, r2_path, r2_name FROM soil_geom AS g, map_soils AS m " + |
+ return findFile ("SELECT distinct m.musym, r2_path, r2_name FROM soil_geom AS g, map_soils AS m " + |
"WHERE m.cokey='" + cokey + "' " + |
"AND g.mukey = m.mukey and m.r2_name like '%' || m.compname || '%' limit 1; ", lon); |
} |
@@ -603,13 +626,13 @@ |
|
|
public FileQryResult findSoilsWeps(double lat, double lon) throws SQLException { |
- return find ("SELECT m.musym, weps_path, weps_name FROM soil_geom AS g, map_soils_weps AS m " + |
+ return findFile ("SELECT m.musym, weps_path, weps_name FROM soil_geom AS g, map_soils_weps AS m " + |
"WHERE ST_Within(ST_GeomFromText('POINT(" + lon + " " + lat + ")',4326), g.geometry) " + |
"AND g.mukey = m.mukey LIMIT 1;", lon); |
} |
|
public FileQryResult findSoilsWepsByCokey(String cokey, double lon) throws SQLException { |
- return find ("SELECT m.musym, weps_path, weps_name FROM soil_geom AS g, map_soils_weps AS m " + |
+ return findFile ("SELECT m.musym, weps_path, weps_name FROM soil_geom AS g, map_soils_weps AS m " + |
"WHERE m.cokey='" + cokey + "' " + |
"AND g.mukey = m.mukey limit 1; ", lon); |
} |
@@ -622,7 +645,7 @@ |
public FileQryResult findClimate(double lat, double lon) throws SQLException { |
// new query - mbound |
// changed from using cnty_geom to cli_geom table |
- return find("SELECT m.co_fips, r2_path, r2_name FROM cli_geom as g, map_climates AS m " + |
+ return findFile("SELECT m.co_fips, r2_path, r2_name FROM cli_geom as g, map_climates AS m " + |
"WHERE ST_Within(ST_Point(" + lon + "," + lat + "), g.geometry) " + |
"AND g.co_fips = m.co_fips " + |
"AND (g.ei_rang=m.ei_rang or g.ei_rang is null) " + |
@@ -639,6 +662,32 @@ |
// + ")' ), geometry)) AS g WHERE m.co_fips = g.co_fips LIMIT 1;"); |
} |
|
+ public County findCounty(double lat, double lon) throws SQLException { |
+ String select = "SELECT m.st_abbr, m.co_numb FROM cnty_geom as g, cnty_data AS m " + |
+ "WHERE ST_Within(ST_Point(" + lon + "," + lat + "), g.geometry) " + |
+ "AND g.co_fips = m.co_fips;"; |
+ Statement s = createStatement(lon); |
+ logger.info("query sql=" + select); |
+ ResultSet r = s.executeQuery(select); |
+ int cols = r.getMetaData().getColumnCount(); |
+ if (cols != 2) { |
+ //s.close(); |
+ logger.severe("invalid columns in cligen station query"); |
+ throw new IllegalArgumentException("invalid Columns"); |
+ } |
+ if (!r.next()) { |
+ //s.close(); |
+ logger.severe("no result from cligen station query!"); |
+ return null; |
+ } |
+ County cnty = new County(); |
+ cnty.state_code = r.getString(1); |
+ cnty.county_code = r.getString(2); |
+ //s.close(); |
+ logger.info("state code=" + cnty.state_code + " county code=" + cnty.county_code); |
+ return cnty; |
+ } |
+ |
public StationResult findCligenStation(double lat, double lon) throws SQLException { |
|
String select = "SELECT st_numb, station_id, st_x(point), st_y(point), elevation, ST_Distance(point, ST_GeomFromText('POINT(" + lon + " " + lat + ")',4326)) as distance " + |
@@ -804,7 +853,12 @@ |
logger.info("centroidY=" + county.county_centroid_Y); |
return county; |
} |
+ |
|
+ public double findCmz(double lat, double lon) throws SQLException { |
+ return findDbl("select distinct g.co_cmz from cmz_geom as g " |
+ + "where ST_Within(ST_Point(" + lon + "," + lat + "), g.geometry); LIMIT 1;", lon, 1); |
+ } |
|
public List<FileQryResult> findManagements(double lat, double lon) throws SQLException { |
//Statement s = createStatement(getConnection()); |
@@ -60,7 +60,6 @@ |
static final String WIND_STATIONS_DIR = "windstations"; |
static final String WIND_STATION_FILE_EXT = ".wdb"; |
static final String DEFAULT_WIND_STATION_DB = "wind_gen_his_upper_US.wdb"; |
- static final String DUMMY_MGMT = "dummy.man"; |
static final String REPORT_JSON_FILENAME = "weps_report.json"; |
static final String WEPS_MGMT = "wepsmgmt.man"; |
static final int NRCS_CYCLE_COUNT = 50; |
@@ -139,10 +138,6 @@ |
sessionWorkDir = workDir.toString(); |
binDir = Config.getString("m.bin.dir", "/tmp/csip/bin"); |
|
- // Unpack the dummy mgmt |
- String dummyMgmt = Binaries.unpackResourceAbsolute("/bin/" + Binaries.getArch() + "/" + DUMMY_MGMT, sessionWorkDir + "/" + DUMMY_MGMT).toString(); |
- wmr.setMgmtFile(DUMMY_MGMT); // the default mgmt, if none provided |
- |
// check that required parameters exist. populate them in wmr data object |
loadRequiredParameters(); |
|
@@ -340,6 +335,7 @@ |
} |
try { |
error = translator.Translate(); |
+ LOG.log(Level.INFO, "OUTPUT FROM THE TRANSLATOR ='" + error + "'"); |
if(error != null) |
{ |
try{ |
@@ -365,11 +361,11 @@ |
throw new ServiceException("LMOD management translation error executing WEPS"); |
//return WEPS_ERROR_LMOD_TRANSLATION_ERROR; |
} |
- if(error != null){ |
- wmr.setRunCycle(Integer.toString(translator.getRotationYears())); |
- simulationYears = Integer.parseInt(wmr.getRunCycle()) * NRCS_CYCLE_COUNT; |
- wmr.setNumYears(Integer.toString(simulationYears)); |
- wmr.setMgmtFile(WEPS_MGMT); |
+ if (error != null) |
+ { |
+ wmr.setRunCycle(Integer.toString(translator.getRotationYears())); |
+ simulationYears = Integer.parseInt(wmr.getRunCycle()) * NRCS_CYCLE_COUNT; |
+ wmr.setNumYears(Integer.toString(simulationYears)); |
} |
} |
} catch (Exception e) { |
@@ -556,6 +552,14 @@ |
{ |
wmr.setElevation(cligenStation.elevation); |
} |
+ |
+ // populate cli gen station parameters in weps.run file |
+ wmr.setCliStationLong(cligenStation.stationX); |
+ wmr.setCliStationLat(cligenStation.stationY); |
+ wmr.setCliStationStateFips(cligenStation.state); |
+ wmr.setCliStationC1(cligenStation.stationId); |
+ wmr.setCliStationName(cligenStation.name); |
+ wmr.setCliStationEleM(cligenStation.elevation); |
|
ProcessComponent pcCliGen = new ProcessComponent(); |
pcCliGen.working_dir = sessionWorkDir; |
@@ -578,6 +582,9 @@ |
|
private void generateWindData() throws ServiceException { |
try { |
+ boolean bInterpolatedWind = false; |
+ PostGIS.County wepsCounty = null; |
+ PostGIS.StationResult windStationForWepsRunFile = null; |
sWindgenStation = null; |
// Always generate wind data for lat / long using wingen and possible interpolate program |
if (db != null) { |
@@ -597,6 +604,7 @@ |
else |
{ |
sWindgenStation = windStation.stationId.trim(); |
+ windStationForWepsRunFile = windStation; |
windDbPath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/" + DEFAULT_WIND_STATION_DB, new File(binDir)).toString(); |
} |
} |
@@ -624,7 +632,7 @@ |
String polygon = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/interpolation_boundary.pol", new File(binDir)).toString(); |
|
// Get the county centroid for wind interpolation |
- PostGIS.County wepsCounty = db.countyCentroid(latitude, longitude); |
+ wepsCounty = db.countyCentroid(latitude, longitude); |
|
// Generate shell script to invoke interpolate |
File interpolatesh = new File(sessionWorkDir + "/interpolate.sh"); |
@@ -650,6 +658,7 @@ |
// Added small delay because occasionally the stdout was incomplete upon parsing |
Thread.sleep(300); |
|
+ bInterpolatedWind = true; |
WeightsParser wp = new WeightsParser(); |
wp.weightsFile = pcInterpolate.stdout; |
wp.exitValue = pcInterpolate.exitValue; |
@@ -694,8 +703,14 @@ |
windDbPath = "test.wdb"; |
sWindgenStation = "999999"; // this is the magic number indicating its an interpolated wind station! |
} |
+ |
+ // for wind interpolation, report the nearest wind gen station in the weps.run file for now |
+ // check with Fred to verify if this is correct behavior for the weps gui |
+ windStationForWepsRunFile = db.findWindgenStation(Double.parseDouble(wmr.getLat()), Double.parseDouble(wmr.getLongitude())); |
} |
|
+ |
+ |
// otherwise, just use data from nearest wind station: |
// If this is not using an interpolated wind station, then use the default closest one... |
if (windDbPath.length() == 0) { |
@@ -708,10 +723,38 @@ |
PostGIS.StationResult windgenStation = db.findWindgenStation(Double.parseDouble(wmr.getLat()), Double.parseDouble(wmr.getLongitude())); |
LOG.info("windgen station is=" + windgenStation.stationId); |
sWindgenStation = windgenStation.stationId.trim(); |
+ windStationForWepsRunFile = windgenStation; |
|
windDbPath = Binaries.unpackResource("/bin/" + Binaries.getArch() + "/" + DEFAULT_WIND_STATION_DB, new File(binDir)).toString(); |
} |
} |
+ |
+ // populate wind gen station parameters in the weps.run file |
+ wmr.setWinWindLat(windStationForWepsRunFile.stationY); |
+ wmr.setWinWindLong(windStationForWepsRunFile.stationX); |
+ wmr.setWinWindStation(windStationForWepsRunFile.stationId); |
+ wmr.setWinWindCountry(windStationForWepsRunFile.country); |
+ wmr.setWinWindState(windStationForWepsRunFile.state); |
+ wmr.setWinWindStationName(windStationForWepsRunFile.name); |
+ wmr.setWinWindDescriptionString("|" + wmr.getWinWindStation() + "|" + wmr.getWinWindCountry() + "|" + wmr.getWinWindState() + "|" + wmr.getWinWindStationName()); |
+ |
+ // make adjustments if wind is interpolated in weps.run |
+ if (bInterpolatedWind) |
+ { |
+ wmr.setWinWindGenProgram("interpolated"); |
+ if (wepsCounty != null) |
+ { |
+ wmr.setWinWindLat(wepsCounty.county_centroid_Y); |
+ wmr.setWinWindLong(wepsCounty.county_centroid_X); |
+ } |
+ wmr.setWinWindDescriptionString(""); |
+ } |
+ |
+ // populate state and county code params in the weps.run file |
+ PostGIS.County cnty = db.findCounty(latitude, longitude); |
+ wmr.setStateSite(cnty.state_code); |
+ wmr.setCountySite(cnty.county_code); |
+ |
// 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(); |
@@ -18,8 +18,6 @@ |
// Fixed Values - these values are fixed in the weps.run, and typically do not change |
private final String runMode = "NRCS"; |
private final String rotationCycle = "50"; |
- private final String stateSite = "CO"; |
- private final String countySite = "069"; |
private final String simScale1 = "5.5"; |
private final String simScale2 = "5.5"; |
private final String avgSlope = "-1"; // value should come from soils file |
@@ -31,15 +29,30 @@ |
private final String radius = "1.00"; |
static final String UNSET_ELEVATION = "-9999.999"; |
// Dynamic Values - changable by the service |
+ private String stateSite = "XX"; |
+ private String countySite = "000"; |
private String cliFile = "cligen.cli"; // could change if provided by the client |
+ private String cliStationLat = "0.0"; |
+ private String cliStationLong = "0.0"; |
+ private String cliStationStateFips = "0"; |
+ private String cliStationc1 = "0000"; |
+ private String cliStationName = "CLI_STA_NAME"; |
+ private String cliStationEleM = "0"; |
private String winFile = "thewind.win"; // could change if provided by the client |
+ private String winWindGenProgram = "windgen"; |
+ private String winWindLat = "0.0"; |
+ private String winWindLong = "0.0"; |
+ private String winWindStation = "000000"; |
+ private String winWindCountry = "00"; |
+ private String winWindState = "00"; |
+ private String winWindDescriptionString = "wind station description"; |
+ private String winWindStationName = "WIN_STA_NAME"; |
private String runCycle = "3"; |
private String lat = "+66.56272"; |
private String longitude = "-105.00000"; |
private String elevation = UNSET_ELEVATION; // meters |
private String numYears = "150"; |
private String soilFile = "soil.ifc"; |
- private String mgmtFile = "management.man"; |
private String simRegionAngle = "0.00000"; |
private String simXLen = "1.00"; // meters |
private String simYLen = "1.00"; // meters |
@@ -51,16 +64,31 @@ |
{ |
barriers.add(new Barrier()); |
} |
- |
+ |
+ public void setStateSite(String stateSite) { this.stateSite = stateSite; } |
+ public void setCountySite(String countySite) { this.countySite = countySite; } |
public void setCliFile(String clifile) { this.cliFile = clifile; } |
+ public void setCliStationLat(String cliStationLat) { this.cliStationLat = cliStationLat; } |
+ public void setCliStationLong(String cliStationLong) { this.cliStationLong = cliStationLong; } |
+ public void setCliStationStateFips(String cliStationStateFips) { this.cliStationStateFips = cliStationStateFips; } |
+ public void setCliStationC1(String cliStationC1) { this.cliStationc1 = cliStationC1; } |
+ public void setCliStationName(String cliStationName) { this.cliStationName = cliStationName; } |
+ public void setCliStationEleM(String cliStationEleM) { this.cliStationEleM = cliStationEleM; } |
public void setWinFile(String windfile) { this.winFile = windfile; } |
+ public void setWinWindGenProgram(String winWindGenProgram) { this.winWindGenProgram = winWindGenProgram; } |
+ public void setWinWindLat(String winWindLat) { this.winWindLat = winWindLat; } |
+ public void setWinWindLong(String winWindLong) { this.winWindLong = winWindLong; } |
+ public void setWinWindStation(String winWindStation) { this.winWindStation = winWindStation; } |
+ public void setWinWindCountry(String winWindCountry) { this.winWindCountry = winWindCountry; } |
+ public void setWinWindState(String winWindState) { this.winWindState = winWindState; } |
+ public void setWinWindStationName(String winWindStationName) { this.winWindStationName = winWindStationName; } |
+ public void setWinWindDescriptionString(String winWindDescriptionString) { this.winWindDescriptionString = winWindDescriptionString; } |
public void setRunCycle(String runcycle) { this.runCycle = runcycle; } |
public void setLat(String latitude) { this.lat = latitude; } |
public void setLongitude(String longitude) { this.longitude = longitude; } |
public void setElevation(String ele) { this.elevation = ele; } |
public void setNumYears(String numYears) { this.numYears = numYears; } |
public void setSoilFile(String soilFile) { this.soilFile = soilFile; } |
- public void setMgmtFile(String mgmtFile) { this.mgmtFile = mgmtFile; } |
public void setSimRegionAngle(String simRegionAngle) { this.simRegionAngle = simRegionAngle; } |
public void setSimXLen(String X) { this.simXLen = X; } |
public void setSimYLen(String Y) { this.simYLen = Y; } |
@@ -71,8 +99,8 @@ |
public String getRunMode() { return runMode; } |
public String getRunCycle() { return runCycle; } |
public String getRotationCycle() { return rotationCycle; } |
- public String getStateSite() { return stateSite; } |
- public String getCountySite() { return countySite; } |
+ public String getStateSite() { return this.stateSite; } |
+ public String getCountySite() { return this.countySite; } |
public String getLat() { |
NumberFormat latlongFormat = new DecimalFormat("+0.00000;-0.00000"); |
return latlongFormat.format(Double.parseDouble(lat)); |
@@ -89,9 +117,25 @@ |
public String getNumYears () { return numYears; } |
public String getTimeSteps () { return timeSteps; } |
public String getCliFile() { return cliFile; } |
+ |
+ public String getCliStationLat() { return this.cliStationLat; } |
+ public String getCliStationLong() { return this.cliStationLong; } |
+ public String getCliStationStateFips() { return this.cliStationStateFips; } |
+ public String getCliStationC1() { return this.cliStationc1; } |
+ public String getCliStationName() { return this.cliStationName; } |
+ public String getCliStationEleM() { return this.cliStationEleM; } |
+ |
public String getWinFile() { return winFile; } |
+ public String getWinWindGenProgram() { return this.winWindGenProgram; } |
+ public String getWinWindLat() { return this.winWindLat; } |
+ public String getWinWindLong() { return this.winWindLong; } |
+ public String getWinWindStation() { return this.winWindStation; } |
+ public String getWinWindCountry() { return this.winWindCountry; } |
+ public String getWinWindState() { return this.winWindState; } |
+ public String getWinWindStationName() { return this.winWindStationName; } |
+ public String getWinWindDescriptionString() { return this.winWindDescriptionString; } |
+ |
public String getSoilFile() { return soilFile; } |
- public String getMgmtFile() { return mgmtFile; } |
public String getSimRegionAngle() { |
NumberFormat simRegionAngleFormat = new DecimalFormat("0.00000"); |
return simRegionAngleFormat.format(Double.parseDouble(simRegionAngle)); |