use of ucar.units_vcell.ParseException in project vcell by virtualcell.
the class InternalUnitDefinition method getInstance.
/**
* Creation date: (4/15/2004 1:39:26 PM)
* @return cbit.vcell.units.InternalUnitDefinition
* @param InternalUnitDefinition cbit.vcell.units.InternalUnitDefinition
* @deprecated please don't use, we should hide the underlying implementation (CellML translator needs it now)
*/
static InternalUnitDefinition getInstance(Unit ucarUnit) {
//
for (int i = 0; i < defs.size(); i++) {
InternalUnitDefinition temp = (InternalUnitDefinition) defs.get(i);
if (equivalent(ucarUnit, temp.getUcarUnit())) {
return temp;
}
}
//
try {
if (ucarUnit instanceof ScaledUnit) {
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(ucarUnit.toString(), " ");
double scale = 1;
int cnt = 0;
String nonNum = null;
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
try {
scale *= Double.parseDouble(token);
cnt++;
} catch (NumberFormatException e) {
nonNum = token;
break;
}
}
double roundedScale = round(scale);
if (roundedScale != scale || cnt > 1) {
String newSymbol = String.valueOf(roundedScale);
if (nonNum != null) {
newSymbol += " " + nonNum;
}
StandardUnitFormat standardUnitFormat = new StandardUnitFormat(new java.io.ByteArrayInputStream(newSymbol.trim().getBytes()));
ucar.units_vcell.UnitDB unitDB = ucar.units_vcell.UnitSystemManager.instance().getUnitDB();
ucarUnit = standardUnitFormat.unitSpec(unitDB);
}
}
} catch (ParseException e) {
e.printStackTrace();
throw new VCUnitException("Unable to get unit: " + ucarUnit.toString() + ": " + e.getMessage());
} catch (UnitException e) {
e.printStackTrace();
throw new VCUnitException("Unable to get unit: " + ucarUnit.toString() + ": " + e.getMessage());
}
//
return new InternalUnitDefinition(ucarUnit);
}
Aggregations