diff vcxo-manual/readmeas.c @ 0:bd62be88259d

initial import of rfcal code and docs from freecalypso-tools repository
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 May 2017 18:49:35 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vcxo-manual/readmeas.c	Sat May 20 18:49:35 2017 +0000
@@ -0,0 +1,61 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "meas.h"
+
+read_meas_file(filename, meas_table, nmeas)
+	char *filename;
+	struct meas *meas_table;
+{
+	FILE *f;
+	char linebuf[256], *cp, *np;
+	int lineno;
+	struct meas *mtp;
+	int got_meas;
+
+	f = fopen(filename, "r");
+	if (!f) {
+		perror(filename);
+		exit(1);
+	}
+	mtp = meas_table;
+	got_meas = 0;
+	for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
+		for (cp = linebuf; isspace(*cp); cp++)
+			;
+		if (*cp == '\0' || *cp == '#')
+			continue;
+		if (!isdigit(*cp) && *cp != '-' && *cp != '+') {
+inv:			fprintf(stderr, "%s line %d: invalid syntax\n",
+				filename, lineno);
+			exit(1);
+		}
+		np = cp++;
+		while (isdigit(*cp))
+			cp++;
+		if (!isspace(*cp))
+			goto inv;
+		mtp->dac_value = atoi(np);
+		while (isspace(*cp))
+			cp++;
+		if (!isdigit(*cp) && *cp != '-' && *cp != '+')
+			goto inv;
+		np = cp++;
+		while (isdigit(*cp))
+			cp++;
+		if (*cp && !isspace(*cp))
+			goto inv;
+		mtp->freq_offset = atoi(np);
+		mtp++;
+		got_meas++;
+		if (got_meas >= nmeas)
+			break;
+	}
+	fclose(f);
+	if (got_meas < nmeas) {
+		fprintf(stderr, "error: need %d measurements, got %d in %s\n",
+			nmeas, got_meas, filename);
+		exit(1);
+	}
+	return 0;
+}