Analyte Formulae Scripts

Analyte formulae are C# scripts used to calculate the final result of an analyte when quality is monitored for material being transferred across process flows and discrete unit movements.

The following example script calculates the ratio of iron to magnesium oxide. The script presumes that the Fe and MgO analytes are already configured.

Copy
public class FeMgO_Calc : IAnalyteFormula
{
    /// <summary>
    /// Gets the name that will appear in the UI for this formula script.
    /// </summary>
    public string FormulaName
    {
        get
        {
            return "Fe:MgO Calc";
        }
    }
    public NullableDouble CalculateValue(CalcStockBalanceAnalyteList analytes)
    {
        // Get the value of the analyte based on the analyte's Alias1 value.
        // If the boolean parameter is false or not specified, the analyte 
        // look-up is by name, which is not recommended.
        NullableDouble feValue = analytes["Fe", true];
        NullableDouble mgoValue = analytes["MgO", true];

        // Check to make sure that none of the analyte values are null.
        if (!feValue.IsNull && !mgoValue.IsNull)
        {
            // Perform the calculation.
            return feValue.Value / mgoValue.Value;
        }
        else
        {
            // If any of the analyte values were null then return 
            // NullableDouble.Null.
            return NullableDouble.Null;
        }
    }
}