From 1e3a084d31baf615fb2c154484481f7934f3a878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sun, 4 Mar 2001 12:54:12 +0000 Subject: [PATCH] * Initial release git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@436 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/cal.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cal.h | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/cal.c create mode 100644 src/cal.h diff --git a/src/cal.c b/src/cal.c new file mode 100644 index 000000000..426c84646 --- /dev/null +++ b/src/cal.c @@ -0,0 +1,84 @@ +/* + * hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * + * cal.c - Copyright (C) 2001 Stephane Fillod + * + * + * $Id: cal.c,v 1.1 2001-03-04 12:54:12 f4cfe Exp $ + * + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "cal.h" + +/* add rig_set_cal(cal_table), rig_get_calstat(rawmin,rawmax,cal_table), */ + +/* + * 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 + */ + + +float rig_raw2val(int rawval, const cal_table_t *cal) +{ +#ifdef WANT_CHEAP_WNO_FP + float interpolation; +#else + int interpolation; +#endif + int i; + + /* ASSERT(cal != NULL) */ + /* ASSERT(cal->size <= MAX_CAL_LENGTH) */ + + if (cal->size == 0) + return rawval; + + for (i=0; isize; 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) * + (cal->table[i].val - cal->table[i-1].val)) / + (cal->table[i].raw - cal->table[i-1].raw); +#endif + + return cal->table[i].val - interpolation; +} + diff --git a/src/cal.h b/src/cal.h new file mode 100644 index 000000000..ec5afbc3b --- /dev/null +++ b/src/cal.h @@ -0,0 +1,57 @@ +/* + * hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com) + * + * cal.h - Copyright (C) 2001 Stephane Fillod + * + * + * $Id: cal.h,v 1.1 2001-03-04 12:54:12 f4cfe Exp $ + * + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _CAL_H +#define _CAL_H 1 + +/* add rig_set_cal(cal_table), rig_get_calstat(rawmin,rawmax,cal_table), */ + +#define MAX_CAL_LENGTH 32 + +/* + * 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 + */ +struct cal_cell { + int raw; + int val; +}; +struct cal_table { + int size; + struct cal_cell table[MAX_CAL_LENGTH]; +}; + +typedef struct cal_table cal_table_t; + +#define EMPTY_STR_CAL { 0, { { 0, 0 }, } } + +float rig_raw2val(int rawval, const cal_table_t *cal); + +#endif /* _CAL_H */