Exemple #1
0
 public string PressureUnitToString(PressureUnit unit)
 {
     return
         (_appContext.GetString(_appContext.Resources.GetIdentifier(
                                    unit.ToString(), ResourceType.String,
                                    _appContext.PackageName)));
 }
Exemple #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="tempUnit">Unit for temperature, default = celcius</param>
 /// <param name="pUnit">Unit for pressure, default = torr</param>
 /// <param name="speedUnit">Unit for speed (wind), default = knots</param>
 /// <param name="distanceUnit">Unit for distance (visibility), default = kilometer</param>
 public Units(TemperatureUnit tempUnit, PressureUnit pUnit, SpeedUnit speedUnit, LengthUnit distanceUnit)
 {
     PressureUnit    = pUnit;
     TemperatureUnit = tempUnit;
     WindSpeedUnit   = speedUnit;
     VisibilityUnit  = distanceUnit;
 }
Exemple #3
0
 public UnitSystem()
 {
     this.temperature        = TemperatureUnit.Celsius;
     this.pressure           = PressureUnit.Pascal;
     this.massFlowRate       = MassFlowRateUnit.KgPerSec;
     this.volumeFlowRate     = VolumeFlowRateUnit.CubicMeterPerSec;
     this.moistureContent    = MoistureContentUnit.KgPerKg;
     this.relativeHumidity   = RatioUnit.Percent;
     this.enthalpy           = SpecificEnergyUnit.JoulePerKg;
     this.specificHeat       = SpecificHeatUnit.JoulePerKgKelvin;
     this.energy             = EnergyUnit.Joule;
     this.power              = PowerUnit.JoulePerSec;
     this.density            = DensityUnit.KgPerCubicMeter;
     this.dynamicViscosity   = DynamicViscosityUnit.PascalSecond;
     this.kinematicViscosity = KinematicViscosityUnit.SquareMeterPerSec;
     this.conductivity       = ThermalConductivityUnit.WattPerMeterKelvin;
     this.diffusivity        = DiffusivityUnit.SquareMeterPerSec;
     this.mass     = MassUnit.Kilogram;
     this.length   = LengthUnit.Meter;
     this.area     = AreaUnit.SquareMeter;
     this.volume   = VolumeUnit.CubicMeter;
     this.time     = TimeUnit.Second;
     this.Name     = "SI"; //ep
     this.readOnly = true;
 }
        public static string GetAbbreviation(PressureUnit unit, [CanBeNull] string cultureName)
        {
            // Windows Runtime Component does not support CultureInfo and IFormatProvider types, so we use culture name for public methods: https://msdn.microsoft.com/en-us/library/br230301.aspx
            IFormatProvider provider = cultureName == null ? UnitSystem.DefaultCulture : new CultureInfo(cultureName);

            return(UnitSystem.GetCached(provider).GetDefaultAbbreviation(unit));
        }
Exemple #5
0
 public UserUnits(string unit, string windunit, string pressureunit)
 {
     Temperature = unit.ConvertToIntFromNetatmo().GetTemperatureUnit();
     Rain        = unit.ConvertToIntFromNetatmo().GetRainUnit();
     Wind        = windunit.ConvertToIntFromNetatmo().GetWindUnit();
     Pressure    = pressureunit.ConvertToIntFromNetatmo().GetPressureUnit();
 }
Exemple #6
0
        //HeatFluxDensityUnit heatTransferCoefficient;
        //ForceUnit force;
        //SurfaceTensionUnit surfaceTension;

        public UnitSystem(TemperatureUnit temperature, PressureUnit pressure, MassFlowRateUnit massFlowRate,
                          VolumeFlowRateUnit volumeFlowRate, MoistureContentUnit moistureContent,
                          RatioUnit relativeHumidity, SpecificEnergyUnit enthalpy,
                          SpecificHeatUnit specificHeat, EnergyUnit energy, PowerUnit power, DensityUnit density,
                          DynamicViscosityUnit dynamicViscosity, KinematicViscosityUnit kinematicViscosity,
                          ThermalConductivityUnit conductivity, DiffusivityUnit diffusivity, MassUnit mass,
                          LengthUnit length, AreaUnit area, VolumeUnit volume, TimeUnit Time, string name) //ep
        {
            this.temperature        = temperature;
            this.pressure           = pressure;
            this.massFlowRate       = massFlowRate;
            this.volumeFlowRate     = volumeFlowRate;
            this.moistureContent    = moistureContent;
            this.relativeHumidity   = relativeHumidity;
            this.enthalpy           = enthalpy;
            this.specificHeat       = specificHeat;
            this.energy             = energy;
            this.power              = power;
            this.density            = density;
            this.dynamicViscosity   = dynamicViscosity;
            this.kinematicViscosity = kinematicViscosity;
            this.conductivity       = conductivity;
            this.diffusivity        = diffusivity;
            this.mass     = mass;
            this.length   = length;
            this.area     = area;
            this.volume   = volume;
            this.time     = time;
            this.Name     = name;  //ep
            this.readOnly = false; //ep
        }
Exemple #7
0
        private void WriteImpulse(PressureUnit unit, double[] values)
        {
            var valueObj = new NdConvertibleValue(StockConverters.PressureConverter, unit, values);

            QraStateContainer.SetValue("impulse", valueObj);
            //QraStateContainer.Instance.Parameters["impulse"] = ValueObj;
        }
Exemple #8
0
        private async void OnUnitChanged(object sender, SelectionChangedEventArgs e)
        {
            selectedUnit = (PressureUnit)UnitCombo.SelectedIndex;

            // remember this setting.
            Settings.Instance.PressureUnit = (int)selectedUnit;
            await Settings.Instance.SaveAsync();
        }
Exemple #9
0
 public static string DspString(double Value, PressureUnit Unit)
 {
     if (double.IsNaN(Value))
     {
         return("");
     }
     return(Value.ToString(mDspFmt[(int)Unit], CultureInfo.CurrentCulture));
 }
Exemple #10
0
 public static string LogString(double Value, PressureUnit Unit, CultureInfo Culture)
 {
     if (double.IsNaN(Value))
     {
         return("");
     }
     return(Value.ToString(mLogFmt[(int)Unit], Culture));
 }
Exemple #11
0
 public SensorStorage(string name, SpeedUnit speedUnit, TemperatureUnit tempUnit, PressureUnit presUnit, IEnumerable <Reading> readings)
     : base(readings ?? new Reading[0])
 {
     _name      = name;
     _speedUnit = speedUnit;
     _tempUnit  = tempUnit;
     _presUnit  = presUnit;
 }
 public void PressureConversions(double value1, PressureUnit units1, double value2, PressureUnit units2)
 {
     new Pressure(value1, units1) {
         Units = units2
     }.Value.ShouldBeWithinEpsilonOf(value2);
     new Pressure(value2, units2) {
         Units = units1
     }.Value.ShouldBeWithinEpsilonOf(value1);
 }
Exemple #13
0
        public string ToString(PressureUnit unit, CultureInfo culture, string format, params object[] args)
        {
            string abbreviation = UnitSystem.GetCached(culture).GetDefaultAbbreviation(unit);

            object[] finalArgs = new object[] { As(unit), abbreviation }
            .Concat(args)
            .ToArray();

            return(string.Format(culture, format, finalArgs));
        }
Exemple #14
0
        public SensorInfo(
			string name,
			SpeedUnit speedUnit,
			TemperatureUnit tempUnit,
			PressureUnit pressureUnit
		)
        {
            Name = name;
            SpeedUnit = speedUnit;
            TemperatureUnit = tempUnit;
            PressureUnit = pressureUnit;
        }
Exemple #15
0
        private void AddCfdInputRow(string variableName, double[] variableValues, PressureUnit unit)
        {
            var input = new object[variableValues.Length + 1];

            input[0] = variableName;
            for (var index = 0; index < variableValues.Length; index++)
            {
                input[index + 1] = variableValues[index].ToString("F4");
            }

            dgCFDInput.Rows.Add(input);
        }
Exemple #16
0
        public static double Convert(double Value, PressureUnit FromUnit, PressureUnit ToUnit)
        {
            // it would be faster to create a 5-by-5 table with each conversion constant,
            // but this is much easier.
            if (FromUnit == ToUnit || double.IsNaN(Value))
            {
                return(Value);
            }
            // first, convert the unit to meters-per-sec
            double mb = Value / mRatios[(int)FromUnit];

            // now, convert to the desired unit
            return(mb * mRatios[(int)ToUnit]);
        }
Exemple #17
0
        private void SetCfdUnit(PressureUnit unitToSet)
        {
            var unitToFind = unitToSet.ToString();

            for (var index = 0; index < cbCFDUnits.Items.Count; index++)
            {
                var unitFound = cbCFDUnits.Items[index].ToString();
                if (unitFound == unitToFind)
                {
                    cbCFDUnits.SelectedIndex = index;
                    break;
                }
            }
        }
Exemple #18
0
        /// <summary>
        ///     Parse a string given a particular regular expression.
        /// </summary>
        /// <exception cref="UnitsNetException">Error parsing string.</exception>
        private static List <Pressure> ParseWithRegex(string regexString, string str, IFormatProvider formatProvider = null)
        {
            var             regex     = new Regex(regexString);
            MatchCollection matches   = regex.Matches(str.Trim());
            var             converted = new List <Pressure>();

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                var valueString = groups["value"].Value;
                var unitString  = groups["unit"].Value;
                if (groups["invalid"].Value != "")
                {
                    var newEx = new UnitsNetException("Invalid string detected: " + groups["invalid"].Value);
                    newEx.Data["input"]          = str;
                    newEx.Data["matched value"]  = valueString;
                    newEx.Data["matched unit"]   = unitString;
                    newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                    throw newEx;
                }
                if (valueString == "" && unitString == "")
                {
                    continue;
                }

                try
                {
                    PressureUnit unit  = ParseUnit(unitString, formatProvider);
                    double       value = double.Parse(valueString, formatProvider);

                    converted.Add(From(value, unit));
                }
                catch (AmbiguousUnitParseException ambiguousException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    var newEx = new UnitsNetException("Error parsing string.", ex);
                    newEx.Data["input"]          = str;
                    newEx.Data["matched value"]  = valueString;
                    newEx.Data["matched unit"]   = unitString;
                    newEx.Data["formatprovider"] = formatProvider == null ? null : formatProvider.ToString();
                    throw newEx;
                }
            }
            return(converted);
        }
        protected SensorInfo AddSensor(
			Data.DbDataStore store = null,
			string name = "Sensor",
			SpeedUnit speedUnit = SpeedUnit.MetersPerSec,
			TemperatureUnit tempUnit = TemperatureUnit.Celsius,
			PressureUnit pressUnit = PressureUnit.KiloPascals
		)
        {
            if (null == store)
                store = Store;
            Assert.IsNotNull(store, "no store");
            var sensor = new SensorInfo(name, speedUnit, tempUnit, pressUnit);
            var sensorAdded = store.AddSensor(sensor);
            Assert.IsTrue(sensorAdded, "sensor add failed");
            return sensor;
        }
 protected override PressureUnit __DoSubstraction(PressureUnit right)
 {
     return new Pascal(ConvertToBase().Value - right.ConvertToBase().Value);
 }
Exemple #21
0
        public static double ConvertUnit(double value, PressureUnit from, PressureUnit to)
        {
            if (from == to) {
                return value;
            }

            switch (from) {
                case PressureUnit.InchOfMercury:
                    switch (to) {
                        case PressureUnit.KiloPascals:
                            return value * 3.38600;
                        case PressureUnit.Pascals:
                            return value * (3.38600 * 1000.0);
                        case PressureUnit.Millibar:
                            return value * 33.86;
                        default:
                            throw new ArgumentOutOfRangeException("to");
                    }
                case PressureUnit.KiloPascals:
                    switch (to) {
                        case PressureUnit.InchOfMercury:
                            return 0.295333727 * value;
                        case PressureUnit.Pascals:
                            return value * 1000.0;
                        case PressureUnit.Millibar:
                            return 10.0 * value;
                        default:
                            throw new ArgumentOutOfRangeException("to");
                    }
                case PressureUnit.Pascals:
                    switch (to) {
                        case PressureUnit.InchOfMercury:
                            return (0.295333727 / 1000.0) * value;
                        case PressureUnit.KiloPascals:
                            return value / 1000.0;
                        case PressureUnit.Millibar:
                            return (10.0 / 1000.0) * value;
                        default:
                            throw new ArgumentOutOfRangeException("to");
                    }
                case PressureUnit.Millibar:
                    switch (to) {
                        case PressureUnit.InchOfMercury:
                            return value * 0.0295333727;
                        case PressureUnit.Pascals:
                            return value * (0.1 * 1000.0);
                        case PressureUnit.KiloPascals:
                            return value * 0.1;
                        default:
                            throw new ArgumentOutOfRangeException("to");
                    }
                default:
                    throw new ArgumentOutOfRangeException("from");
            }
        }
Exemple #22
0
 public static string GetFriendlyName(PressureUnit unit)
 {
     switch (unit) {
     case PressureUnit.InchOfMercury: return "inHg";
     case PressureUnit.KiloPascals: return "kPa";
     case PressureUnit.Pascals: return "Pa";
     case PressureUnit.Millibar: return "hPa";//"mBar";
     default: return unit.ToString();
     }
 }
 protected override PressureUnit __DoAddition(PressureUnit right)
 {
     return new Pascal(ConvertToBase().Value + right.ConvertToBase().Value);
 }
 protected static string CreateSuffix(SymbolFormat format, PressureUnit unit)
 {
     return default(Pressure).ToString(unit, format).Trim('0');
 }
Exemple #25
0
        /// <summary>Convert the previous pressure to the new unit.</summary>
        /// <summary>PressureUnitConverter(Pressure.ParseUnit(string unit), Convert.ToDouble(value), Pressure.ParseUnit(string unit));</summary>
        public double PressureUnitConverter(PressureUnit prevUnit, double prevValue, PressureUnit newUnit)
        {
            // Construct from dynamic unit and value
            var prevPressure = Pressure.From(prevValue, prevUnit);

            // Convert to the new unit
            double newPressureValue = prevPressure.As(newUnit);
            return newPressureValue;
        }