set_ch

set_ch sets the new channel data.

The function can only be used inside a formula function. The function uses the globale variable _fi_ncid.

bool = set_ch(ssChannelName, values)
bool = set_ch(ssChannelName, values, ssDepChannels)
bool = set_ch(ssChannelName, values, ssDepChannels, bSIUnits)

Return Value

bool is TRUE (1), if the function was successful an otherwise FALSE (0).

Parameters

ssChannelName

ssChannelName is a channel name.

values

values is a vector with values.

ssDepChannels

ssDepChannels is a string with the channelnames separated by a comma. If ssDepChannels is set to an empty string (“”), the values are not set to missing, if one of the input channels contain missing values. The ch function returns the value infinite (1.#inf) for missing values. The finite function can be used to find the infinite values. See example.

bSIUnits

bSIUnits must be TRUE (1), if values are in SI units and the units attribute is not in SI units. Teh units will be converted. If bSIUnits is FALSE (0) or the parameter is not specified, the units are not converted.

Example

Beispiel

// Leistung in kW
// M*2*PI*n
// Drehzahl n in 1/min
// Moment m in Nm
def _fi_Power(bInfo)
{
    ssChannels = "n_Motor, Md_Motor";
    if (bInfo) {
        return ["Power"; ..
            "kW"; ..
            "Leistung"; ..
            ssChannels;
            "0"];
    }
    n_Motor = ch("n_Motor");
    Md_Motor = ch("Md_Motor");
    Power = (n_Motor .* Md_Motor) ./ 9549.3;
    set_ch("Power", Power, ssChannels);
}
// Leistung in kW
// M*2*PI*n
// Drehzahl n in 1/s
// Moment m in Nm
def _fi_Power(bInfo)
{
    bSIUnits = 1;
    ssUnit = "kW";
    ssChannels = "n_Motor, Md_Motor";
    if (bInfo) {
        return ["Power"; ..
            ssUnit; ..
            "Leistung"; ..
            ssChannels;
            "1"];
    }
    n_Motor = ch("n_Motor", "", bSIUnits);
    Md_Motor = ch("Md_Motor", "", bSIUnits);
    Power = (n_Motor .* Md_Motor) .* (2*PI);
    set_ch("Power", Power, ssChannels, bSIUnits);
}

Example for an integral calculation, where the missings are set to 0:

def _fi_qm(bInfo)
{
    ssChannels = "time, m_flow";
    if (bInfo) {
        return ["qm"; ..
            "kg"; ..
            "Leistung"; ..
            ssChannels;
            "1"];
    }
    rvTime = ch("time");
    rvMFlow = ch("m_flow");

    idx = find(finite(rvMFlow) == FALSE);
    if (idx[1] != 0) {
          rvMFlow[idx] = 0;
    }
    // we ignore the error that the triangle before and after
    // the missing values is added to the integral value.

    rvQm = integral(rvTime, rvMFlow);
    // Third parameter = "": missings will not set set:
    // Only the second column is the integral
    set_ch("qm", rvQm[;2], "", FALSE);
}

History

Version Description
R2013.11 Unit Conversion.
R2012.0 New documentation.
5.7 New.

id-875561