10 #include <sys/types.h>
42 "-E- %s line %d: unable to open %s for reading\n",
50 if (fread(&hdr,
sizeof (hdr), 1, fp) != 1) {
52 "-E- %s line %d: error reading %s\n",
65 if (strncmp((
char *) hdr.id,
"CWIF", 4) != 0) {
67 "-E- %s line %d: error in header format of %s\n",
69 fprintf(
stderr,
" Header should start with CWIF string.\n");
70 fprintf(
stderr,
" This may not be level-0 format.\n");
74 if (l0ctl->fileType >= 0)
75 hdr.type = l0ctl->fileType;
78 if (hdr.stopTime <= hdr.startTime || hdr.startTime < 873072000) {
79 if (hdr.type !=
HRPT) {
81 "-E- %s line %d: error in header format of %s\n",
83 fprintf(
stderr,
" AOS and/or LOS times make no sense.\n");
85 hdr.startTime = 873072000;
90 if (hdr.type !=
HRPT && hdr.type !=
GAC) {
92 "-E- %s line %d: error in header format of %s\n",
94 fprintf(
stderr,
" HRPT/Stored-GAC flag invalid, assuming HRPT.\n");
104 "-E- %s line %d: input file %s is empty\n",
108 if ((indx->rec = (frameqc *) calloc(nrecs,
sizeof (frameqc))) ==
NULL) {
110 "-E- %s line %d: error allocating memory for index array\n",
119 indx->timeAOS = hdr.startTime;
120 indx->timeLOS = hdr.stopTime;
121 indx->type = hdr.type;
133 indx->bitRateRep = ((
double) hdr.errbits) /
MAX(hdr.numbits, 1);
143 if (hdr.type ==
HRPT) {
144 startSec = hdr.startTime;
145 stopSec = hdr.stopTime;
147 startSec = hdr.startTime - 86400.;
148 stopSec = hdr.stopTime + 60.;
155 printf(
"\nChecking telemetry for general corruption.\n");
156 for (irec = 0; irec < nrecs; irec++) {
158 if (fread(mnf,
L0LEN, 1, fp) != 1) {
160 "-E- %s line %d: error reading %s at rec %d\n",
161 __FILE__, __LINE__, indx->l0file, irec);
168 indx->rec[irec].bitError = 0;
169 indx->rec[irec].scidError = 0;
170 indx->rec[irec].tRanError = 0;
171 indx->rec[irec].tSeqError = 0;
172 indx->rec[irec].tDifError = 0;
173 indx->rec[irec].sgaError = 0;
174 indx->rec[irec].sacError = 0;
175 indx->rec[irec].saaError = 0;
180 memcpy(scid, &mnf[
O_SCID],
sizeof (scid));
181 memcpy(ttag, &mnf[
O_TIME],
sizeof (ttag));
190 indx->rec[irec].time = utime;
191 indx->rec[irec].mnfnum = mnfnum;
192 indx->rec[irec].mnftype = mnftype;
195 if (scid[0] != 403 && scid[0] != 147 && scid[0] != 275) {
196 indx->rec[irec].scidError = 1;
197 printf(
"Invalid S/C ID, %d, at frame %d.\n", scid[0], irec);
199 if (hdr.type ==
HRPT && mnftype != 0) {
200 indx->rec[irec].scidError = 1;
201 printf(
"Invalid frame type for HRPT at frame %d.\n", irec);
203 if (hdr.type ==
GAC && ((mnftype > 4 && mnftype < 15) || mnftype > 15)) {
204 indx->rec[irec].scidError = 1;
205 printf(
"Invalid frame type for GAC/LAC at frame %d.\n", irec);
211 indx->rec[irec].bitError =
bitError(mnf, &numbits, &numerrs);
212 indx->rec[irec].numBits = numbits;
213 indx->rec[irec].errBits = numerrs;
214 totnumbits += numbits;
215 totnumerrs += numerrs;
217 indx->rec[irec].bitError = 1;
218 if (indx->rec[irec].bitError == 1)
219 printf(
"Frame %5d, FF bit errors: %d, L0 bit errors: %d\n",
220 irec, mnf[2], numerrs);
221 if (indx->rec[irec].errBits > l0ctl->maxBitErrors) {
222 printf(
"Max number of bit errors exceeded for this frame.\n");
223 indx->rec[irec].maxErrBits = 1;
231 indx->rec[irec].sgaError = 1;
233 indx->rec[irec].sacError = 1;
235 indx->rec[irec].saaError = 1;
249 if (hdr.type ==
HRPT) {
251 printf(
"\nComputing AOS and LOS from frame timetags.\n");
259 if (timeValid == 1) {
260 srec =
MAX(irec - 1, 0);
261 startSec = indx->rec[srec].time;
262 indx->timeAOS = startSec;
263 printf(
"Contiguous timetags at frame %d\n", srec);
264 for (irec = srec - 1; irec >= 0; irec--)
265 indx->rec[irec].tRanError = 1;
268 "-E- %s line %d: no contiguous timetags found in %s\n",
279 indx->rec[irec].time > startSec + l0ctl->stopTimeDelta)) ||
280 indx->rec[irec].time < startSec)
284 erec =
MIN(irec + 1, nrecs - 1);
285 stopSec = indx->rec[erec].time;
286 indx->timeLOS = stopSec;
287 printf(
"Contiguous timetags at frame %d\n", erec);
288 for (irec = erec + 1; irec < nrecs; irec++)
289 indx->rec[irec].tRanError = 1;
292 "-E- %s line %d: no contiguous timetags found in %s\n",
306 if (hdr.type ==
GAC && l0ctl->timerangeFactor > 0) {
308 printf(
"\nComputing valid timerange from frame timetags.\n\n");
313 while (irec < nrecs && (timeValid =
timeContiguous(indx, irec)) == 0)
315 if (timeValid == 1) {
316 startSec = indx->rec[irec].time;
317 printf(
"Contiguous timetags at frame %d\n", irec);
320 "-E- %s line %d: no contiguous timetags found in %s\n",
325 stopSec = startSec + l0ctl->timerangeFactor * 86400.0;
326 startSec = startSec - l0ctl->timerangeFactor * 86400.0;
327 indx->timeAOS = startSec;
328 indx->timeLOS = stopSec;
335 printf(
"\nChecking timetag differences, limits, and sequence.\n");
336 for (irec = srec; irec <= erec; irec++) {
338 mnfnum = indx->rec[irec].mnfnum;
339 mnftype = indx->rec[irec].mnftype;
342 if (indx->rec[irec].time < startSec ||
343 indx->rec[irec].time > stopSec) {
344 printf(
"Time Range Error at Frame %d\n", irec);
345 indx->rec[irec].tRanError = 1;
350 indx->rec[irec].tDifError = 1;
355 if (indx->rec[irec].tSeqError == 1)
356 printf(
"Time Sequence Error at Frame %d\n", irec);
360 indx->rec[irec].tShfError =
361 timeShifted(indx, irec, &(indx->rec[irec].timeShift));
363 indx->rec[irec].tShfError = 0;
364 indx->rec[irec].timeShift = 0.0;
383 default: indx->nund += 1;
386 indx->scidError += indx->rec[irec].scidError;
387 indx->sohError += indx->rec[irec].sgaError ||
388 indx->rec[irec].sacError ||
389 indx->rec[irec].saaError;
390 indx->timeError += indx->rec[irec].tRanError ||
391 indx->rec[irec].tSeqError ||
392 indx->rec[irec].tDifError;
398 indx->bitRateComp = (
float) totnumerrs / (
float) totnumbits;
406 printf(
"\nPerforming pass 2 time sequence test.\n");
408 for (irec = srec; irec <= erec; irec++) {
413 if (indx->rec[irec].tSeqError == 1) {
414 printf(
"Time Sequence Error at Frame %d\n", irec);
415 indx->rec[irec].tSeqError = 1;
422 if (indx->rec[irec].time < lastTime) {
423 printf(
"Decreasing timetag at frame %d\n", irec);
424 indx->rec[irec].tSeqError = 1;
427 lastTime = indx->rec[irec].time;
433 indx->timeFirst = (
double) indx->timeLOS;
434 indx->timeLast = (
double) indx->timeAOS;
436 for (irec = srec; irec <= erec; irec++) {
438 indx->timeFirst =
MIN(indx->rec[irec].time, indx->timeFirst);
439 indx->timeLast =
MAX(indx->rec[irec].time, indx->timeLast);