Logo Search packages:      
Sourcecode: hamlib version File versions  Download package

float HAMLIB_API rig_raw2val ( int  rawval,
const cal_table_t cal 
)

Convert raw S-meter data to calibated value, according to table.

Parameters:
rawval input value
cal calibration table
Returns:
calibrated value
cal_table_t is a data type suited to hold linear calibration cal_table_t.size tell the number of plot cal_table_t.table contains If a value is below or equal to cal_table_t.table[0].raw, rig_raw2val() will return cal_table_t.table[0].val If a value is greater or equal to cal_table_t.table[cal_table_t.size-1].raw, rig_raw2val() will return cal_table_t.table[cal_table_t.size-1].val

Definition at line 57 of file cal.c.

References cal_table::raw, cal_table::size, cal_table::table, and cal_table::val.

Referenced by rig_get_level().

{
#ifdef WANT_CHEAP_WNO_FP
      int interpolation;
#else
      float interpolation;
#endif
      int i;

      /* ASSERT(cal != NULL) */
      /* ASSERT(cal->size <= MAX_CAL_LENGTH) */

      if (cal->size == 0)
                  return rawval;

      for (i=0; i<cal->size; i++)
            if (rawval < cal->table[i].raw)
                  break;

      if (i==0)
            return cal->table[0].val;

      if (i>=cal->size)
            return cal->table[i-1].val;

      if (cal->table[i].raw == cal->table[i-1].raw)   /* catch divide by 0 error */
            return cal->table[i].val;

#ifdef WANT_CHEAP_WNO_FP
      /* cheap, less accurate, but no fp needed */
      interpolation = ((cal->table[i].raw - rawval) * 
                   (cal->table[i].val - cal->table[i-1].val)) /
                    (cal->table[i].raw - cal->table[i-1].raw);

      return cal->table[i].val - interpolation;
#else
      interpolation = ((cal->table[i].raw - rawval) * 
                   (float)(cal->table[i].val - cal->table[i-1].val)) /
                    (float)(cal->table[i].raw - cal->table[i-1].raw);
#endif
      return cal->table[i].val - interpolation;
}


Generated by  Doxygen 1.6.0   Back to index