SciEnergyParser.java [src/java/m/weps] Revision: Date:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package m.weps;
import java.util.LinkedList;
import java.util.logging.Logger;
import util.ErosionConst;
/**
*
* @author wlloyd
*/
public class SciEnergyParser {
public static final Logger LOG = Logger.getLogger(SciEnergyParser.class.getName());
// parse weps sci_energy.out file
public static WepsOutput parseSciEnergyFile(String text) {
String t2 = text.substring(1, text.length() - 1);
String delims = "[|\t\r\n ]";
String tokens[] = t2.split(delims);
LinkedList<String> lst = new LinkedList();
for (String token : tokens) {
if (token.trim().length() > 0) {
lst.add(token);
}
}
for (String item : lst) {
System.out.println(item);
}
// Grab tokens associated with the desired output values
WepsOutput wo = new WepsOutput();
wo.soilConditioningIndex = lst.get(2);
wo.sciOmFactor = lst.get(7);
wo.sciErFactor = lst.get(8);
wo.sciFoFactor = lst.get(9);
//wo.dieselEnergy = lst.get(3); This is wrong in the file
wo.averageBiomass = lst.get(22);
wo.windEros = lst.get(23);
wo.waterEros = lst.get(24);
wo.avgAllStir = lst.get(25);
wo.bNaN = ((lst.get(2).equals("NaN")
|| lst.get(7).equals("NaN")
|| lst.get(8).equals("NaN")
|| lst.get(9).equals("NaN")
|| lst.get(3).equals("NaN")
|| lst.get(22).equals("NaN")
|| lst.get(23).equals("NaN")
|| lst.get(24).equals("NaN")
|| lst.get(25).equals("NaN")) ? true : false);
// Work around to remove negative zero coming from sci_energy.out file
if (wo.windEros.equals("-0.0000")) {
wo.windEros = "0.0000";
}
// Work around to remove "NaN" from output(s)
if (wo.windEros.equals("NaN")) {
wo.windEros = "0.0000";
}
if (wo.soilConditioningIndex.equals("NaN")) {
wo.soilConditioningIndex = "0.000";
}
if (wo.sciOmFactor.equals("NaN")) {
wo.sciOmFactor = "0.0000";
}
if (wo.sciErFactor.equals("NaN")) {
wo.sciErFactor = "0.0000";
}
if (wo.sciFoFactor.equals("NaN")) {
wo.sciFoFactor = "0.0000";
}
// if (wo.dieselEnergy.equals("NaN")) {
// wo.dieselEnergy = "0.000";
// }
if (wo.averageBiomass.equals("NaN")) {
wo.averageBiomass = "0.0000";
}
if (wo.waterEros.equals("NaN")) {
wo.waterEros = "0.0000";
}
if (wo.avgAllStir.equals("NaN")) {
wo.avgAllStir = "0.0000";
}
// Unused tokens are:
// 14 = totalRennerOM
// 15 = totalRennerErosWater
// 16 = totalRennerErosWind
// 17 = rennerstir
// 27 = texturemult
if (wo.bNaN) {
LOG.warning(ErosionConst.WEPS_FOUND_NAN_IN_OUTPUT);
}
LOG.info("wo.soilConditioningIndex" + wo.soilConditioningIndex);
LOG.info("wo.sciOmFactor" + wo.sciOmFactor);
LOG.info("wo.sciErFactor" + wo.sciErFactor);
LOG.info("wo.sciFoFactor" + wo.sciFoFactor);
LOG.info("wo.dieselEnergy" + wo.dieselEnergy);
LOG.info("wo.averageBiomass" + wo.averageBiomass);
LOG.info("wo.windEros" + wo.windEros);
LOG.info("wo.waterEros" + wo.waterEros);
LOG.info("wo.avgAllStir" + wo.avgAllStir);
return wo;
}
}