Beispiel #1
0
/* Returns a named property value.  Depending on the source and
   destination unit the actual value is converted. */
double transline::getProperty (const char * prop, int type, int dstunit) {
  int srcunit = translateUnit (getUnit (prop));
  double value = getProperty (prop);
  if (type == UNIT_LENGTH)
    return value * conv_length[srcunit][dstunit];
  else if (type == UNIT_RES)
    return value * conv_res[srcunit][dstunit];
  else if (type == UNIT_ANG)
    return value * conv_ang[srcunit][dstunit];
  else if (type == UNIT_FREQ)
    return value * conv_freq[srcunit][dstunit];
  return value;
}
Beispiel #2
0
/* Sets a named property to a given value.  Depending on the source
   and destination unit the value gets previously converted. */
void transline::setProperty (const char * prop, double value, int type,
			     int srcunit) {
  int dstunit = translateUnit (getUnit (prop));
  if (type == UNIT_LENGTH)
    value *= conv_length[srcunit][dstunit];
  else if (type == UNIT_RES)
    value *= conv_res[srcunit][dstunit];
  else if (type == UNIT_ANG)
    value *= conv_ang[srcunit][dstunit];
  else if (type == UNIT_FREQ)
    value *= conv_freq[srcunit][dstunit];
  setProperty (prop, value);
}
Beispiel #3
0
/**
 * Transform number to base units
 * @param context
 * @param unit text representation of unit
 * @param len length of text representation
 * @param value preparsed numeric value
 * @return TRUE if value parameter was converted to base units
 */
scpi_bool_t SCPIParser::transformNumber(const char * unit, size_t len, scpi_number_t * value) {
    size_t s;
    const scpi_unit_def_t * unitDef;
    s = skipWhitespace(unit, len);

    if (s == len) {
        value->unit = SCPI_UNIT_NONE;
        return TRUE;
    }

    unitDef = translateUnit(context.units, unit + s, len - s);

    if (unitDef == NULL) {
        SCPI_ErrorPush(SCPI_ERROR_INVALID_SUFFIX);
        return FALSE;
    }

    value->value *= unitDef->mult;
    value->unit = unitDef->unit;

    return TRUE;
}