3 This file is part of a program that implements a Software-Defined Radio.
5 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 The authors can be reached by email at
29 The DTTS Microwave Society
41 sqr(double x) { return x * x; }
47 for (i = 1; i < 32; i++) c += (k >> i) & 01;
55 while (n > 0) n >>= 1, i++;
60 nblock2(int n) { return 1 << npoof2(n); }
63 in_blocks(int count, int block_size) {
65 fprintf(stderr, "block_size zero in in_blocks\n");
68 return (1 + ((count - 1) / block_size));
72 efopen(char *path, char *mode) {
73 FILE *iop = fopen(path, mode);
75 fprintf(stderr, "can't open \"%s\" in mode \"%s\"\n", path, mode);
82 efreopen(char *path, char *mode, FILE *strm) {
83 FILE *iop = freopen(path, mode, strm);
85 fprintf(stderr, "can't reopen \"%s\" in mode \"%s\"\n", path, mode);
92 filesize(char *path) {
94 if (stat(path, &sbuf) == -1) return -1;
101 if (fstat(fd, &sbuf) == -1) return -1;
105 #define MILLION (1000000)
111 gettimeofday(&tv, 0);
117 diff_tv(struct timeval *ta, struct timeval *tb) {
119 if (tb->tv_usec > ta->tv_usec) {
121 ta->tv_usec += MILLION;
123 tv.tv_sec = ta->tv_sec - tb->tv_sec;
124 if ((tv.tv_usec = ta->tv_usec - tb->tv_usec) >= MILLION) {
125 tv.tv_usec -= MILLION;
133 sum_tv(struct timeval *ta, struct timeval *tb) {
135 tv.tv_sec = ta->tv_sec + tb->tv_sec;
136 if ((tv.tv_usec = ta->tv_usec + tb->tv_usec) >= MILLION) {
137 tv.tv_usec -= MILLION;
144 fmt_tv(struct timeval *tv) {
145 static char buff[256];
146 snprintf(buff, sizeof(buff), "%ds%du", tv->tv_sec, tv->tv_usec);
151 since(struct timeval *tv) {
152 struct timeval nt = now_tv(),
153 dt = diff_tv(&nt, tv);
157 // linear integer interpolation:
158 // real vector v, n long, -> real vector u, m long
159 // *** n must divide m
160 // returns actual number of valid points in u
161 // (== n - m/n since v[n] is undefined)
164 hinterp_vec(REAL *u, int m, REAL *v, int n) {
165 if (!u || !v || (n < 2) || (m < n) || (m % n)) return 0;
167 int div = m / n, i, j = 0;
168 for (i = 1; i < n; i++) {
170 REAL vl = v[i - 1], del = (v[i] - vl) / div;
172 for (k = 1; k < div; k++) u[j++] = vl + k * del;
180 status_message(char *msg) { write(2, msg, strlen(msg)); }
183 find_rcfile(char *base) {
184 char path[MAXPATHLEN];
186 sprintf(path, "./%s", base);
187 if ((fp = fopen(path, "r"))) return fp;
189 char *home = getenv("HOME");
191 fprintf(stderr, "can't get HOME!\n"), exit(1);
192 sprintf(path, "%s/%s", home, base);
193 if ((fp = fopen(path, "r"))) return fp;
198 //------------------------------------------------------------------------