001    /**
002     * 
003     */
004    package org.wdssii.core;
005    
006    import java.io.FileReader;
007    import java.io.IOException;
008    
009    import ucar.units.StandardUnitFormat;
010    import ucar.units.Unit;
011    import ucar.units.UnitFormat;
012    
013    /**
014     * 
015     * Provides access to the ucar.units package
016     * Looks for, and loads, udunits.dat in w2config
017     * 
018     * @author lakshman
019     *
020     */
021    public class UdUnits {
022            private static StandardUnitFormat suf;
023            
024            public static UnitFormat getUnitFormat() throws ConfigurationException {
025                    if (suf == null){
026                            try {
027                                    suf = new StandardUnitFormat(new FileReader(W2Config.getFile("misc/udunits.dat")));
028                            } catch (IOException e){
029                                    throw new ConfigurationException(e);
030                            }
031                    }
032                    return suf;
033            }
034            
035            public static Unit parse(String unit){
036                    try {
037                            return getUnitFormat().parse(unit);
038                    } catch (Exception e){
039                            throw new RuntimeException(e);
040                    }
041            }
042    }