Example #1
0
        private void ReadBaseUnits(SystemOfUnits system)
        {
            foreach (XPathNavigator n in navigator.Select("u:root/base-unit", ns))
            {
                string name = n.SelectSingleNode("name").ToString();
                string dimension = n.SelectSingleNode("property").ToString();
                string symbol = n.SelectSingleNode("@Code").ToString();

                system.AddUnit(name, symbol, dimension);
            }
        }
Example #2
0
        private void ReadBaseUnits(SystemOfUnits system)
        {
            foreach (XPathNavigator n in navigator.Select("u:root/base-unit", ns))
            {
                string name      = n.SelectSingleNode("name").ToString();
                string dimension = n.SelectSingleNode("property").ToString();
                string symbol    = n.SelectSingleNode("@Code").ToString();

                system.AddUnit(name, symbol, dimension);
            }
        }
Example #3
0
        public SystemOfUnits Read()
        {
            SystemOfUnits system = new SystemOfUnits();

            //ReadConstants(system);
            ReadPrefixes(system);
            ReadBaseUnits(system);
            ReadUnits(system);
            ReadConversions(system);
            return(system);
        }
Example #4
0
        public void AddConversion(SystemOfUnits system, string from, string formula, Exponential number)
        {
            Metric metricfrom = system.Metrics.ParseMetric(from);
            Metric metricto   = system.Metrics.ParseMetric(Parser.ToUnaryTokens(formula).NonNumerics());

            if ((metricfrom != null) && (metricto != null))
            {
                ConversionMethod method = BuildConversion(formula, number);
                system.Conversions.Add(metricfrom, metricto, method);
            }
        }
Example #5
0
        private void ReadPrefixes(SystemOfUnits system)
        {
            foreach (XPathNavigator n in navigator.Select("u:root/prefix", ns))
            {
                string      name   = n.SelectSingleNode("name").ToString();
                string      s      = n.SelectSingleNode("value/@value").ToString();
                Exponential factor = Exponential.Exact(s);

                //string symbol = n.SelectSingleNode("printSymbol").ToString();
                string symbol = n.SelectSingleNode("@Code").ToString();
                system.AddPrefix(name, symbol, factor);
            }
        }
Example #6
0
        private void ReadPrefixes(SystemOfUnits system)
        {
            foreach(XPathNavigator n in navigator.Select("u:root/prefix", ns))
            {
                string name = n.SelectSingleNode("name").ToString();
                string s = n.SelectSingleNode("value/@value").ToString();
                Exponential factor = Exponential.Exact(s);

                //string symbol = n.SelectSingleNode("printSymbol").ToString();
                string symbol = n.SelectSingleNode("@Code").ToString();
                system.AddPrefix(name, symbol, factor);
            }
        }
Example #7
0
        private void ReadUnits(SystemOfUnits system)
        {
            foreach (XPathNavigator n in navigator.Select("u:root/unit", ns))
            {
                string name           = n.SelectSingleNode("name").ToString();
                string classification = n.SelectSingleNode("@class", ns).ToString();

                string symbol = n.SelectSingleNode("@Code").ToString();
                //if (classification != "dimless")
                {
                    system.AddUnit(name, symbol);
                }
            }
        }
Example #8
0
 private void ReadUnits(SystemOfUnits system)
 {
     foreach (XPathNavigator n in navigator.Select("u:root/unit", ns))
     {
         string name = n.SelectSingleNode("name").ToString();
         string classification = n.SelectSingleNode("@class", ns).ToString();
         
         string symbol = n.SelectSingleNode("@Code").ToString();
         //if (classification != "dimless")
         {
             system.AddUnit(name, symbol);
         }
     }
 }
Example #9
0
 public void ReadConversions(SystemOfUnits system)
 {
     foreach (XPathNavigator n in navigator.Select("u:root/unit", ns))
     {
         string from    = n.SelectSingleNode("@Code").ToString();
         string formula = n.SelectSingleNode("value/@Unit").ToString();
         try
         {
             string value = n.SelectSingleNode("value/@value").ToString();
             if (value.Length > 16)
             {
                 value = value.Substring(0, 16);
             }
             Exponential number = Exponential.Exact(value);
             AddConversion(system, from, formula, number);
         }
         catch
         {
         }
     }
 }
 public static void Init(TestContext context)
 {
     system = UCUM.Load();
 }
Example #11
0
 public SystemOfUnits Read()
 {
     SystemOfUnits system = new SystemOfUnits();
     //ReadConstants(system);
     ReadPrefixes(system);
     ReadBaseUnits(system);
     ReadUnits(system);
     ReadConversions(system);
     return system;
 }
Example #12
0
        public void ReadConversions(SystemOfUnits system)
        {
            foreach (XPathNavigator n in navigator.Select("u:root/unit", ns))
            {
                string from = n.SelectSingleNode("@Code").ToString();
                string formula = n.SelectSingleNode("value/@Unit").ToString();
                try
                {
                    string value = n.SelectSingleNode("value/@value").ToString();
                    if (value.Length > 16)
                        value = value.Substring(0, 16);
                    Exponential number = Exponential.Exact(value);
                    AddConversion(system, from, formula, number);
                }
                catch
                {

                }
                
            }
        }
Example #13
0
        public void AddConversion(SystemOfUnits system, string from, string formula, Exponential number)
        {
            Metric metricfrom = system.Metrics.ParseMetric(from);
            Metric metricto = system.Metrics.ParseMetric(Parser.ToUnaryTokens(formula).NonNumerics());

            if ( (metricfrom != null) && (metricto != null) )
            {
                ConversionMethod method = BuildConversion(formula, number);
                system.Conversions.Add(metricfrom, metricto, method);
            }

        }