/// <summary> /// Gets the name of the SI unit associated with the unit category, e.g. Pascals for pressure. /// </summary> /// <remarks> /// <para>The SI unit is the basis for conversions between any two units of the same category, either SI or /// customary. /// </para> /// </remarks> /// <returns>The Aspen(TM) display unit that corresponds to the current unit.</returns> /// <param name="unit">The unit to get the Aspen (TM) unit for.</param> public static String AspenUnit(String unit) { String retVal = String.Empty; String category = String.Empty; bool found = false; for (int i = 0; i < units.Count; i++) { CapeOpen.unit current = (CapeOpen.unit)units[i]; if (current.Name == unit) { category = current.Category; found = true; } } for (int i = 0; i < unitCategories.Count; i++) { CapeOpen.unitCategory current = (CapeOpen.unitCategory)unitCategories[i]; if (current.Name == category) { retVal = current.AspenUnit; found = true; } } if (!found) { throw new CapeOpen.CapeBadArgumentException(String.Concat("Unit: ", unit, " was not found"), 1); } return(retVal); }
///// <summary> ///// Changes the description of the unit of measure ///// </summary> ///// <remarks>Changes the description of the unit of measure.</remarks> //public static void ChangeUnitDescription(String unit, String newDescription) //{ // bool found = false; // for (int i = 0; i < units.Count; i++) // { // CapeOpen.unit current = (CapeOpen.unit)units[i]; // if (current.Name == unit) // { // current.Description = newDescription; // found = true; // } // } // if (!found) throw new CapeOpen.CapeBadArgumentException(String.Concat("Unit: ", unit, " was not found"), 1); //} /// <summary> /// Returns all units matching the unit category. /// </summary> /// <remarks>A unit category represents a specific combination of dimsionality values. Examples would be /// pressure or temperature. This method would return all units that are in the category, such as Celius, /// Kelvin, Farehnheit, and Rankine for temperature.</remarks> /// <param name="category">The catgeory of the desired units.</param> /// <returns>All units that represent the categoery.</returns> public static String[] UnitsMatchingCategory(String category) { System.Collections.ArrayList unitNames = new System.Collections.ArrayList(); for (int i = 0; i < units.Count; i++) { CapeOpen.unit current = (CapeOpen.unit)units[i]; if (current.Category == category) { unitNames.Add(current.Name); } } String[] retVal = new String[unitNames.Count]; for (int i = 0; i < unitNames.Count; i++) { retVal[i] = unitNames[i].ToString(); } return(retVal); }
/// <summary> /// A description of the unit of measure /// </summary> /// <remarks>The description of the unit of measure.</remarks> /// <param name="unit">The unit to get the conversion factor for.</param> /// <returns>The description of the unit of measure.</returns> public static String UnitDescription(String unit) { String retVal = String.Empty; bool found = false; for (int i = 0; i < units.Count; i++) { CapeOpen.unit current = (CapeOpen.unit)units[i]; if (current.Name == unit) { retVal = current.Description; found = true; } } if (!found) { throw new CapeOpen.CapeBadArgumentException(String.Concat("Unit: ", unit, " was not found"), 1); } return(retVal); }
/// <summary> /// An offset factor used in converting the value of the measurement to its SI equivalent. /// </summary> /// <remarks> /// <para>Units are converted to and from the SI equivalent for the unit category. Unit conversions are /// accomplished by first adding any offset, stored in <see cref = "ConverionsPlus"/> to the value of the unit. /// The sum is then multiplied by the value of the <see cref = "ConverionsTimes"/> for the unit to get the /// measured value in SI units.</para> /// </remarks> /// <param name="unit">The unit to get the conversion factor for.</param> /// <returns>The additive part of the conversion factor.</returns> public static double ConverionsPlus(String unit) { double retVal = 0; bool found = false; for (int i = 0; i < units.Count; i++) { CapeOpen.unit current = (CapeOpen.unit)units[i]; if (current.Name == unit) { retVal = current.ConversionPlus; found = true; } } if (!found) { throw new CapeOpen.CapeBadArgumentException(String.Concat("Unit: ", unit, " was not found"), 1); } return(retVal); }