FreeCalypso > hg > fc-rfcal-tools
comparison autocal/txcalconf.c @ 76:5c3574f8c8c1
fc-rfcal-txband: reading of basis & targets setting files implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 15 Jul 2017 20:08:55 +0000 |
parents | |
children | 1d3dd589a857 |
comparison
equal
deleted
inserted
replaced
75:93653fe9b4ef | 76:5c3574f8c8c1 |
---|---|
1 /* | |
2 * The code that reads and parses Tx calibration profiles lives here. | |
3 */ | |
4 | |
5 #include <sys/param.h> | |
6 #include <ctype.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <rvinterf/exitcodes.h> | |
12 #include "txband.h" | |
13 | |
14 char txlevels_directory[] = "/opt/freecalypso/rfcal/txlevels"; | |
15 | |
16 extern struct txcal_band *txcal_band; | |
17 extern char *txlevels_profile; | |
18 | |
19 extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS]; | |
20 extern unsigned num_basis_points; | |
21 | |
22 extern struct tx_level tx_levels[MAX_TX_LEVELS]; | |
23 | |
24 static basis_set, targets_set; | |
25 | |
26 static void | |
27 do_basis_line(cp, filename_for_errs, lineno) | |
28 char *cp, *filename_for_errs; | |
29 { | |
30 unsigned n; | |
31 | |
32 for (n = 0; ; n++) { | |
33 while (isspace(*cp)) | |
34 cp++; | |
35 if (*cp == '\0' || *cp == '#') | |
36 break; | |
37 if (!isdigit(*cp)) { | |
38 fprintf(stderr, | |
39 "%s line %d: non-numeric content not allowed\n", | |
40 filename_for_errs, lineno); | |
41 exit(ERROR_USAGE); | |
42 } | |
43 if (n >= MAX_BASIS_POINTS) { | |
44 fprintf(stderr, | |
45 "%s line %d: MAX_BASIS_POINTS exceeded\n", | |
46 filename_for_errs, lineno); | |
47 exit(ERROR_USAGE); | |
48 } | |
49 tx_basis[n].apc = atoi(cp); | |
50 while (isdigit(*cp)) | |
51 cp++; | |
52 } | |
53 if (n < 2) { | |
54 fprintf(stderr, | |
55 "%s line %d: a minimum of 2 basis points must be given\n", | |
56 filename_for_errs, lineno); | |
57 exit(ERROR_USAGE); | |
58 } | |
59 num_basis_points = n; | |
60 basis_set = 1; | |
61 } | |
62 | |
63 static void | |
64 do_targets_line(cp, filename_for_errs, lineno) | |
65 char *cp, *filename_for_errs; | |
66 { | |
67 unsigned expect_num, n; | |
68 | |
69 expect_num = txcal_band->end_plnum - txcal_band->start_plnum + 1; | |
70 for (n = 0; ; n++) { | |
71 while (isspace(*cp)) | |
72 cp++; | |
73 if (*cp == '\0' || *cp == '#') | |
74 break; | |
75 if (!isdigit(*cp)) { | |
76 fprintf(stderr, | |
77 "%s line %d: non-numeric content not allowed\n", | |
78 filename_for_errs, lineno); | |
79 exit(ERROR_USAGE); | |
80 } | |
81 if (n >= expect_num) { | |
82 wrong_num: fprintf(stderr, | |
83 "%s line %d: exactly %u target numbers expected\n", | |
84 filename_for_errs, lineno, expect_num); | |
85 exit(ERROR_USAGE); | |
86 } | |
87 tx_levels[txcal_band->start_plnum + n].target = atof(cp); | |
88 while (isdigit(*cp) || *cp == '.') | |
89 cp++; | |
90 } | |
91 if (n != expect_num) | |
92 goto wrong_num; | |
93 targets_set = 1; | |
94 } | |
95 | |
96 static void | |
97 process_line(linebuf, filename_for_errs, lineno) | |
98 char *linebuf, *filename_for_errs; | |
99 { | |
100 char *cp, *np; | |
101 | |
102 for (cp = linebuf; isspace(*cp); cp++) | |
103 ; | |
104 if (*cp == '\0' || *cp == '#') | |
105 return; | |
106 for (np = cp; *cp && !isspace(*cp); cp++) | |
107 ; | |
108 if (*cp) | |
109 *cp++ = '\0'; | |
110 if (!strcmp(np, "basis")) | |
111 do_basis_line(cp, filename_for_errs, lineno); | |
112 else if (!strcmp(np, "targets")) | |
113 do_targets_line(cp, filename_for_errs, lineno); | |
114 else { | |
115 fprintf(stderr, "%s line %d: unknown keyword \"%s\"\n", | |
116 filename_for_errs, lineno, np); | |
117 exit(ERROR_USAGE); | |
118 } | |
119 } | |
120 | |
121 read_tx_cal_profile() | |
122 { | |
123 char pathname[MAXPATHLEN]; | |
124 FILE *inf; | |
125 int lineno; | |
126 char linebuf[512]; | |
127 | |
128 sprintf(pathname, "%s/%s-%s", txlevels_directory, txlevels_profile, | |
129 txcal_band->name); | |
130 inf = fopen(pathname, "r"); | |
131 if (!inf) { | |
132 perror(pathname); | |
133 exit(ERROR_USAGE); | |
134 } | |
135 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) | |
136 process_line(linebuf, pathname, lineno); | |
137 fclose(inf); | |
138 if (!basis_set) { | |
139 fprintf(stderr, "error: basis not set in %s\n", pathname); | |
140 exit(ERROR_USAGE); | |
141 } | |
142 if (!targets_set) { | |
143 fprintf(stderr, "error: targets not set in %s\n", pathname); | |
144 exit(ERROR_USAGE); | |
145 } | |
146 } |