comparison librftab/readfir.c @ 315:9178594bc283

librftab: implemented reading of FIR coefficient tables
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 22 Nov 2017 18:52:47 +0000
parents
children
comparison
equal deleted inserted replaced
314:a0f79bba0ad8 315:9178594bc283
1 /*
2 * Reading FIR coefficient tables from formatted ASCII files, used for the
3 * auw-fir command in fc-tmsh.
4 */
5
6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <strings.h>
11 #include <stdlib.h>
12 #include "../rvinterf/include/exitcodes.h"
13
14 #include "rdcommon.c"
15
16 static u_char *writeptr;
17
18 static
19 process_number()
20 {
21 char *field;
22 int rc;
23 long number;
24
25 rc = get_field(&field);
26 if (rc < 0)
27 return(ERROR_USAGE);
28 if (!rc) {
29 printf("error: %s is too short for a FIR coefficient table\n",
30 filename);
31 return(ERROR_USAGE);
32 }
33 number = strtol(field, 0, 0);
34 *writeptr++ = number;
35 *writeptr++ = number >> 8;
36 return(0);
37 }
38
39 read_fir_coeff_table(filename_arg, rdbuf)
40 char *filename_arg;
41 u_char *rdbuf;
42 {
43 char *field;
44 int rc, i;
45
46 filename = filename_arg;
47 rdfile = fopen(filename, "r");
48 if (!rdfile) {
49 perror(filename);
50 return(ERROR_UNIX);
51 }
52 lineno = 0;
53 line_nfields = 0;
54 rc = get_field(&field);
55 if (rc <= 0) {
56 not_valid_fir_table:
57 printf("error: %s is not a valid FIR coefficient table file\n",
58 filename);
59 fclose(rdfile);
60 return(ERROR_USAGE);
61 }
62 if (strcmp(field, "fir-coeff-table"))
63 goto not_valid_fir_table;
64 writeptr = rdbuf;
65 for (i = 0; i < 31; i++) {
66 rc = process_number();
67 if (rc) {
68 fclose(rdfile);
69 return(rc);
70 }
71 }
72 rc = get_field(&field);
73 fclose(rdfile);
74 if (rc < 0)
75 return(ERROR_USAGE);
76 if (rc) {
77 printf("error: %s is too long for a FIR coefficient table\n",
78 filename);
79 return(ERROR_USAGE);
80 }
81 return(0);
82 }