annotate fir/readfir.c @ 389:623316d1ece7

compal/iMelody: capturing initial observations
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Mar 2022 20:56:56 +0000
parents 9b3e5be96bab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
376
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Reading FIR coefficient tables from formatted ASCII files,
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * modified version for host processing.
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "rdcommon.c"
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 static int *writeptr;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 process_number()
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *field;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int rc, number;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 rc = get_field(&field);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (rc < 0)
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(rc);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (!rc) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 printf("error: %s is too short for a FIR coefficient table\n",
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 filename);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(-1);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 number = strtol(field, 0, 0);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (number >= 32768)
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 number -= 65536;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *writeptr++ = number;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(0);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 read_fir_coeff_table_int(filename_arg, rdbuf)
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 char *filename_arg;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 int *rdbuf;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char *field;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 int rc, i;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 filename = filename_arg;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 rdfile = fopen(filename, "r");
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!rdfile) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 perror(filename);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-1);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 lineno = 0;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 line_nfields = 0;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 rc = get_field(&field);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (rc <= 0) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 not_valid_fir_table:
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 fprintf(stderr,
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 "error: %s is not a valid FIR coefficient table file\n",
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 filename);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fclose(rdfile);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (strcmp(field, "fir-coeff-table"))
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 goto not_valid_fir_table;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 writeptr = rdbuf;
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 for (i = 0; i < 31; i++) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 rc = process_number();
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (rc < 0) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fclose(rdfile);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(rc);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 rc = get_field(&field);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 fclose(rdfile);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (rc < 0)
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return(rc);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (rc) {
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr,
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 "error: %s is too long for a FIR coefficient table\n",
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 filename);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(-1);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return(0);
9b3e5be96bab fir2freq: a tool for analyzing captured FIR coefficient sets
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }