comparison rfcal/vcxo-manual/readmeas.c @ 181:dcab0be3f67a

started manual VCXO calibration code: fc-vcxo-linear utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Apr 2017 06:45:45 +0000
parents
children
comparison
equal deleted inserted replaced
180:e50c3aa1152a 181:dcab0be3f67a
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "meas.h"
5
6 read_meas_file(filename, meas_table, nmeas)
7 char *filename;
8 struct meas *meas_table;
9 {
10 FILE *f;
11 char linebuf[256], *cp, *np;
12 int lineno;
13 struct meas *mtp;
14 int got_meas;
15
16 f = fopen(filename, "r");
17 if (!f) {
18 perror(filename);
19 exit(1);
20 }
21 mtp = meas_table;
22 got_meas = 0;
23 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
24 for (cp = linebuf; isspace(*cp); cp++)
25 ;
26 if (*cp == '\0' || *cp == '#')
27 continue;
28 if (!isdigit(*cp) && *cp != '-' && *cp != '+') {
29 inv: fprintf(stderr, "%s line %d: invalid syntax\n",
30 filename, lineno);
31 exit(1);
32 }
33 np = cp++;
34 while (isdigit(*cp))
35 cp++;
36 if (!isspace(*cp))
37 goto inv;
38 mtp->dac_value = atoi(np);
39 while (isspace(*cp))
40 cp++;
41 if (!isdigit(*cp) && *cp != '-' && *cp != '+')
42 goto inv;
43 np = cp++;
44 while (isdigit(*cp))
45 cp++;
46 if (*cp && !isspace(*cp))
47 goto inv;
48 mtp->freq_offset = atoi(np);
49 mtp++;
50 got_meas++;
51 if (got_meas >= nmeas)
52 break;
53 }
54 fclose(f);
55 if (got_meas < nmeas) {
56 fprintf(stderr, "error: need %d measurements, got %d in %s\n",
57 nmeas, got_meas, filename);
58 exit(1);
59 }
60 return 0;
61 }