static protected Unit makeUnit(String name) throws UnitException { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
static protected Unit makeUnit(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
static protected Unit makeUnit(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); return format.parse(name); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is compatible to unitString2, meaning one can be converted to the other. * If either unit string is illegal, return false. * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible */ static public boolean isCompatible(String unitString1, String unitString2) { Unit uu1, uu2; try { UnitFormat format = UnitFormatManager.instance(); uu1 = format.parse(unitString1); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString1 + " got Exception1 " + e); return false; } try { UnitFormat format = UnitFormatManager.instance(); uu2 = format.parse(unitString2); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString2 + " got Exception2 " + e); return false; } //System.out.println("udunits isCompatible "+ uu1+ " "+ uu2); return uu1.isCompatible(uu2); }
public void testException() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu = format.parse("barf"); logger.debug("Parse ok = {}", uu); } }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws UnitException if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date( (long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date( (long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date( (long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date( (long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
public static void main(String[] args) throws Exception { UnitFormat udunit = UnitFormatManager.instance(); //String text = "days since 2009-06-14 04:00:00"; String text2 = "days since 2009-06-14 04:00:00 +00:00"; Unit uu2 = udunit.parse(text2); System.out.printf("%s == %s %n", text2, uu2); String text = "days since 2009-06-14 04:00:00"; Unit uu = udunit.parse(text); System.out.printf("%s == %s %n", text, uu); Unit ref = udunit.parse("ms since 1970-01-01"); Converter converter = uu.getConverterTo(ref); DateFormatter formatter = new DateFormatter(); double val = converter.convert(1.0); Date d = new Date((long) val); System.out.printf(" val=%f date=%s (%s)%n", 1.0, d, formatter.toDateTimeStringISO(d)); double val2 = converter.convert(2.0); Date d2 = new Date((long) val2); System.out.printf(" val=%f date=%s (%s)%n", 2.0, d, formatter.toDateTimeStringISO(d2)); }
/** * Create a SimpleUnit from the given name, allow Exceptions. * * @param name parse this name to create a unit. * @return SimpleUnit, DateUnit, or TimeUnit * @throws Exception when date parser fails * @see ucar.units.UnitFormat#parse */ static public SimpleUnit factoryWithExceptions(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu = format.parse(name); //if (isDateUnit(uu)) return new DateUnit(name); if (isTimeUnit(uu)) return new TimeUnit(name); return new SimpleUnit(uu); }
/** * Create a SimpleUnit from the given name, allow Exceptions. * * @param name parse this name to create a unit. * @return SimpleUnit, DateUnit, or TimeUnit * @throws Exception when date parser fails * @see ucar.units.UnitFormat#parse */ static public SimpleUnit factoryWithExceptions(String name) throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu = format.parse(name); //if (isDateUnit(uu)) return new DateUnit(name); if (isTimeUnit(uu)) return new TimeUnit(name); return new SimpleUnit(uu); }
/** * Create a SimpleUnit from the given name, allow Exceptions. * * @param name parse this name to create a unit. * @return SimpleUnit, DateUnit, or TimeUnit * @throws Exception when date parser fails * @see ucar.units.UnitFormat#parse */ static public SimpleUnit factoryWithExceptions(String name) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu = format.parse(name); //if (isDateUnit(uu)) return new DateUnit(name); if (isTimeUnit(uu)) return new TimeUnit(name); return new SimpleUnit(uu); }
void doTime2(double value, String name, boolean ok) { ucar.units.UnitFormat format = UnitFormatManager.instance(); ucar.units.Unit timeUnit; try { timeUnit = format.parse("secs since 1970-01-01 00:00:00"); } catch (Exception e) { System.out.println("SimpleUnit initialization failed " + e); return; } ucar.units.Unit uu; try { uu = format.parse(name); } catch (Exception e) { System.out.println("Parse " + name + " got Exception " + e); return; } System.out.println("isCompatible=" + uu.isCompatible(timeUnit)); try { System.out.println("convert " + uu.convertTo(value, timeUnit)); } catch (Exception e) { System.out.println("convert " + name + " got Exception " + e); return; } }