3 This file is part of a program that implements a Software-Defined Radio.
\r
5 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
\r
7 This program is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 This program is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with this program; if not, write to the Free Software
\r
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 The authors can be reached by email at
\r
25 rwmcgwier@comcast.net
\r
29 The DTTS Microwave Society
\r
31 Bridgewater, NJ 08807
\r
34 #include <fromsys.h>
\r
38 in_blocks(int count, int block_size) {
\r
39 if (block_size < 1) {
\r
40 fprintf(stderr, "block_size zero in in_blocks\n");
\r
43 return (1 + ((count - 1) / block_size));
\r
47 efopen(char *path, char *mode) {
\r
48 FILE *iop = fopen(path, mode);
\r
50 fprintf(stderr, "can't open \"%s\" in mode \"%s\"\n", path, mode);
\r
57 efreopen(char *path, char *mode, FILE *strm) {
\r
58 FILE *iop = freopen(path, mode, strm);
\r
60 fprintf(stderr, "can't reopen \"%s\" in mode \"%s\"\n", path, mode);
\r
67 filesize(char *path) {
\r
69 if (stat(path, &sbuf) == -1) return -1;
\r
70 return sbuf.st_size;
\r
76 if (fstat(fd, &sbuf) == -1) return -1;
\r
77 return sbuf.st_size;
\r
80 #define MILLION (1000000)
\r
82 // return current tv
\r
86 gettimeofday(&tv, 0);
\r
92 diff_tv(struct timeval *ta, struct timeval *tb) {
\r
94 if (tb->tv_usec > ta->tv_usec) {
\r
96 ta->tv_usec += MILLION;
\r
98 tv.tv_sec = ta->tv_sec - tb->tv_sec;
\r
99 if ((tv.tv_usec = ta->tv_usec - tb->tv_usec) >= MILLION) {
\r
100 tv.tv_usec -= MILLION;
\r
108 sum_tv(struct timeval *ta, struct timeval *tb) {
\r
109 struct timeval tv;
\r
110 tv.tv_sec = ta->tv_sec + tb->tv_sec;
\r
111 if ((tv.tv_usec = ta->tv_usec + tb->tv_usec) >= MILLION) {
\r
112 tv.tv_usec -= MILLION;
\r
119 fmt_tv(struct timeval *tv) {
\r
121 static char buff[256];
\r
122 snprintf(buff, sizeof(buff), "%ds%du", tv->tv_sec, tv->tv_usec);
\r
124 static char buff[512];
\r
125 sprintf(buff, "%ds%du", tv->tv_sec, tv->tv_usec);
\r
131 since(struct timeval *tv) {
\r
132 struct timeval nt = now_tv(),
\r
133 dt = diff_tv(&nt, tv);
\r
134 return fmt_tv(&dt);
\r
139 hinterp_vec(REAL *u, int m, REAL *v, int n) {
\r
140 if (!u || !v || (n < 2) || (m < n) || (m % n)) return 0;
\r
142 int div = m / n, i, j = 0;
\r
143 for (i = 1; i < n; i++) {
\r
145 REAL vl = v[i - 1], del = (v[i] - vl) / div;
\r
147 for (k = 1; k < div; k++) u[j++] = vl + k * del;
\r