# HG changeset patch # User Mychaela Falconia # Date 1500149335 0 # Node ID 5c3574f8c8c1cba9ab47cff03a53ec8ce06c03e9 # Parent 93653fe9b4efecbd2fff752d3e37f25b832f7a30 fc-rfcal-txband: reading of basis & targets setting files implemented diff -r 93653fe9b4ef -r 5c3574f8c8c1 autocal/Makefile --- a/autocal/Makefile Sat Jul 15 19:22:30 2017 +0000 +++ b/autocal/Makefile Sat Jul 15 20:08:55 2017 +0000 @@ -11,7 +11,7 @@ rxupload.o sockopts.o tsidsock.o TXBAND_OBJS= l1tmops.o rvinterf.o sockopts.o tsidsock.o txbandmain.o \ - txpwrmeas.o + txcalconf.o txpwrmeas.o TXBASIS_OBJS= l1tmops.o rvinterf.o tsidsock.o txpwrmeas.o txstandbas.o diff -r 93653fe9b4ef -r 5c3574f8c8c1 autocal/txbandmain.c --- a/autocal/txbandmain.c Sat Jul 15 19:22:30 2017 +0000 +++ b/autocal/txbandmain.c Sat Jul 15 20:08:55 2017 +0000 @@ -100,6 +100,7 @@ { socket_pathname_options(argc, argv); finish_cmdline(argc, argv); + read_tx_cal_profile(); connect_rvinterf_socket(); connect_tsid_socket(); setlinebuf(stdout); /* to allow logging with tee */ diff -r 93653fe9b4ef -r 5c3574f8c8c1 autocal/txcalconf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/autocal/txcalconf.c Sat Jul 15 20:08:55 2017 +0000 @@ -0,0 +1,146 @@ +/* + * The code that reads and parses Tx calibration profiles lives here. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "txband.h" + +char txlevels_directory[] = "/opt/freecalypso/rfcal/txlevels"; + +extern struct txcal_band *txcal_band; +extern char *txlevels_profile; + +extern struct tx_basis_point tx_basis[MAX_BASIS_POINTS]; +extern unsigned num_basis_points; + +extern struct tx_level tx_levels[MAX_TX_LEVELS]; + +static basis_set, targets_set; + +static void +do_basis_line(cp, filename_for_errs, lineno) + char *cp, *filename_for_errs; +{ + unsigned n; + + for (n = 0; ; n++) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + if (!isdigit(*cp)) { + fprintf(stderr, + "%s line %d: non-numeric content not allowed\n", + filename_for_errs, lineno); + exit(ERROR_USAGE); + } + if (n >= MAX_BASIS_POINTS) { + fprintf(stderr, + "%s line %d: MAX_BASIS_POINTS exceeded\n", + filename_for_errs, lineno); + exit(ERROR_USAGE); + } + tx_basis[n].apc = atoi(cp); + while (isdigit(*cp)) + cp++; + } + if (n < 2) { + fprintf(stderr, + "%s line %d: a minimum of 2 basis points must be given\n", + filename_for_errs, lineno); + exit(ERROR_USAGE); + } + num_basis_points = n; + basis_set = 1; +} + +static void +do_targets_line(cp, filename_for_errs, lineno) + char *cp, *filename_for_errs; +{ + unsigned expect_num, n; + + expect_num = txcal_band->end_plnum - txcal_band->start_plnum + 1; + for (n = 0; ; n++) { + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + break; + if (!isdigit(*cp)) { + fprintf(stderr, + "%s line %d: non-numeric content not allowed\n", + filename_for_errs, lineno); + exit(ERROR_USAGE); + } + if (n >= expect_num) { +wrong_num: fprintf(stderr, + "%s line %d: exactly %u target numbers expected\n", + filename_for_errs, lineno, expect_num); + exit(ERROR_USAGE); + } + tx_levels[txcal_band->start_plnum + n].target = atof(cp); + while (isdigit(*cp) || *cp == '.') + cp++; + } + if (n != expect_num) + goto wrong_num; + targets_set = 1; +} + +static void +process_line(linebuf, filename_for_errs, lineno) + char *linebuf, *filename_for_errs; +{ + char *cp, *np; + + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + return; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (*cp) + *cp++ = '\0'; + if (!strcmp(np, "basis")) + do_basis_line(cp, filename_for_errs, lineno); + else if (!strcmp(np, "targets")) + do_targets_line(cp, filename_for_errs, lineno); + else { + fprintf(stderr, "%s line %d: unknown keyword \"%s\"\n", + filename_for_errs, lineno, np); + exit(ERROR_USAGE); + } +} + +read_tx_cal_profile() +{ + char pathname[MAXPATHLEN]; + FILE *inf; + int lineno; + char linebuf[512]; + + sprintf(pathname, "%s/%s-%s", txlevels_directory, txlevels_profile, + txcal_band->name); + inf = fopen(pathname, "r"); + if (!inf) { + perror(pathname); + exit(ERROR_USAGE); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) + process_line(linebuf, pathname, lineno); + fclose(inf); + if (!basis_set) { + fprintf(stderr, "error: basis not set in %s\n", pathname); + exit(ERROR_USAGE); + } + if (!targets_set) { + fprintf(stderr, "error: targets not set in %s\n", pathname); + exit(ERROR_USAGE); + } +}