13 int main(
int argc,
char *argv[])
49 int16 tilt_ranges[20][2], tilt_flags[20], dtynum, rpt_negtim;
51 int32
i, nsamp, nscans, ntilts;
52 float32 nav_thresh1 = -999, nav_thresh2 = -999, l1tilt_thresh = -999,
53 pct_noise_thresh, pct_encrypt_thresh;
55 cntl1_str gn1[8], gn2[8], zero[8];
56 cntl2_str l1hicnt[8], l1locnt[8];
68 printf(
"\n******* Usage: l1stat_chk <hdf file> <control file> \n");
69 printf(
"\t\t<hdf file> is level 1 data file\n");
70 printf(
"\t\t<control file> is the file specifying thresholds\n");
71 printf(
"\nOn exit, $status will be set to: \n\t0 - no problems,"
72 "\n\t1 - program error, ");
73 printf(
"\n\t2 - data problem, \n\t3 - both program and data problem\n");
78 printf(
"\n\n# Statistical Check of Dataset '%s'\n\n", argv[1]);
84 for (
i = 0;
i < 8;
i++) {
85 gn1[
i].band = gn2[
i].band = zero[
i].band = 0;
86 gn1[
i].threshold = gn2[
i].threshold = zero[
i].threshold = 0;
87 l1hicnt[
i].band = l1locnt[
i].band = 0;
88 l1hicnt[
i].err_thresh = l1hicnt[
i].cnt_thresh = 0;
89 l1locnt[
i].err_thresh = l1locnt[
i].cnt_thresh = 0;
97 if ((fid = Hopen(argv[1], DFACC_RDONLY, 0)) < 0) {
98 printf(
"****** L1stat_chk: Failed on the Hopen of \n\t'%s'\n", argv[1]);
107 if ((sdfid = SDstart(argv[1], DFACC_RDONLY)) < 0) {
108 printf(
"******* L1stat_chk: Failure at SDstart of \n'%s'\n", argv[1]);
126 l1locnt, &nav_thresh1, &nav_thresh2,
127 &l1tilt_thresh, &pct_noise_thresh,
128 &pct_encrypt_thresh, &thr_ctl, &rpt_negtim)) < 0) {
137 if ((
l1file(sdfid, &nsamp, &nscans, &dtynum)) < 0) {
146 if ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT)) {
147 if ((
chk_gn(sdfid, gn1, gn2, dtynum, nsamp, nscans)) < 0)
148 printf(
"\n******* %s",
err_msg);
154 if ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT)) {
155 if ((
chk_zero(sdfid, zero, nscans, nsamp)) < 0)
156 printf(
"\n******* %s",
err_msg);
162 if ((spike_cnt = (
int *) calloc(8 * nscans,
sizeof (
int))) ==
NULL) {
163 printf(
"\n******** l1stat_chk: failure to allocate spike_cnt storage\n");
168 if ((line_sd = (
float *) malloc(8 * nscans *
sizeof (
float))) ==
NULL) {
169 printf(
"\n******** l1stat_chk: failure to allocate line_sd storage\n");
174 if ((
chk_count(sdfid, nscans, nsamp, dtynum, l1hicnt, l1locnt, spike_cnt, line_sd)) < 0)
175 printf(
"\n******** %s",
err_msg);
180 if ((l1tilt_thresh != -999) &&
181 ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT))) {
182 if ((
chk_tilt(sdfid, dtynum, l1tilt_thresh, &ntilts, tilt_ranges,
184 printf(
"\n******** %s",
err_msg);
190 if ((nav_thresh1 != -999 && nav_thresh2 != -999) &&
191 ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT))) {
192 if ((
chk_nav(sdfid, nscans, nav_thresh1, nav_thresh2, ntilts,
193 tilt_ranges, tilt_flags, dtynum, rpt_negtim)) < 0)
194 printf(
"\n********* %s",
err_msg);
200 if ((thr_ctl.trng_chk_do == 1) &&
201 ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT)))
207 rpt_noise(sdfid, dtynum, nscans, nsamp, spike_cnt, line_sd,
208 pct_noise_thresh, pct_encrypt_thresh);
216 chk_gainv(sdfid, dtynum, nscans, thr_ctl);
220 chk_tdiv(sdfid, dtynum, nscans, thr_ctl);
277 cntl1_str *gn2, cntl1_str *zero, cntl2_str *l1hicnt,
278 cntl2_str *l1locnt, float32 *nav_thresh1,
279 float32 *nav_thresh2, float32 *l1tilt_thresh,
280 float32 *pct_noise_thresh, float32 *pct_encrypt_thresh,
281 thr_ctl_def *thr_ctl,
int16 *rpt_negtim) {
283 char line[501],
str[25], bnd[2], tstr[14];
284 int32
i,
band, nflds = 0, ival;
285 float32 threshold, cnt_thresh, err_thresh,
f1,
f2,
f3;
287 printf(
"\n# Reading control file '%s'\n\n", cntl_file);
292 if ((fid = fopen(cntl_file,
"r")) ==
NULL) {
293 printf(
"********read_cntldata: Unable to open control file:\n\t'%s'\n",
302 thr_ctl->trng_chk_do = 0;
303 for (
i = 0;
i < 8;
i++) {
304 gn1[
i].band = gn2[
i].band = 0;
305 gn1[
i].threshold = gn2[
i].threshold = 0;
306 thr_ctl->gainv_chk_do[
i] = 0;
308 for (
i = 0;
i < 32;
i++)
309 thr_ctl->inst_ana_do[
i] = 0;
311 thr_ctl->rpt_tdi_vchk = 1;
312 thr_ctl->rpt_gainv_chk = 1;
313 thr_ctl->rpt_inst_ana = 1;
318 for (
i = 0;
i < 500 && (
line[
i] ==
' ' ||
line[
i] ==
'\t');
i++);
321 if (
i < 500 &&
line[
i] ==
'#') {
328 if (strncmp(&
line[
i],
"L1GAIN", 6) == 0) {
329 if ((nflds = sscanf(
line,
"%s %f",
str, &threshold)) != 2) {
330 printf(
"\n*********read_cntldata: expecting 2 fields");
331 printf(
" but read %d field(s)", nflds);
338 if (band < 1 || band > 8) {
339 printf(
"********read_cntldata: Error in band number.");
340 printf(
" Band # read = %d",
band);
345 gn1[
band - 1].band = 1;
346 gn1[
band - 1].threshold = threshold;
347 }
else if (
str[6] ==
'2') {
348 gn2[
band - 1].band = 1;
349 gn2[
band - 1].threshold = threshold;
351 }
else if (strncmp(&
line[
i],
"L1ZERO", 6) == 0) {
352 if ((nflds = sscanf(
line,
"%s %f",
str, &threshold)) != 2) {
353 printf(
"*********read_cntldata: expecting 2 fields");
354 printf(
" but read %d field(s)", nflds);
360 if (band < 1 || band > 8) {
361 printf(
"********read_cntldata: Error in band number.");
362 printf(
" Band # read = %d",
band);
366 zero[
band - 1].band = 1;
367 zero[
band - 1].threshold = threshold;
368 }
else if (strncmp(&
line[
i],
"L1HICOUNT", 9) == 0) {
369 if ((nflds = sscanf(
line,
"%s %f %f",
str, &err_thresh, &cnt_thresh))
371 printf(
"*********read_cntldata: expecting 3 fields");
372 printf(
" but read %d field(s)", nflds);
378 if (band < 1 || band > 8) {
379 printf(
"*********read_cntldata: Error in band number.");
380 printf(
" Band # read = %d",
band);
384 l1hicnt[
band - 1].band = 1;
385 l1hicnt[
band - 1].err_thresh = err_thresh;
386 l1hicnt[
band - 1].cnt_thresh = cnt_thresh;
387 }
else if (strncmp(&
line[
i],
"L1LOWCOUNT", 10) == 0) {
388 if ((nflds = sscanf(
line,
"%s %f %f",
str, &err_thresh, &cnt_thresh))
390 printf(
"*********read_cntldata: expecting 3 fields");
391 printf(
" but read %d field(s)", nflds);
397 if (band < 1 || band > 8) {
398 printf(
"*********read_cntldata: Error in band number.");
399 printf(
" Band # read = %d",
band);
403 l1locnt[
band - 1].band = 1;
404 l1locnt[
band - 1].err_thresh = err_thresh;
405 l1locnt[
band - 1].cnt_thresh = cnt_thresh;
406 }
else if (strncmp(&
line[
i],
"L1TILT", 6) == 0) {
407 if ((nflds = sscanf(
line,
"%s %f",
str, l1tilt_thresh)) != 2) {
408 printf(
"*********read_cntldata: expecting 2 fields");
409 printf(
" but read %d field(s)", nflds);
416 else if (strncmp(&
line[
i],
"TLIM_NEGTIM", 11) == 0) {
417 if ((nflds = sscanf(
line,
"%s %s",
str, tstr)) != 2) {
418 printf(
"***** read_cntldata: expecting 2 fields for TLIM_NEGTIM\n");
419 printf(
" but read %d field(s)", nflds);
424 if (strncmp(fsttim, tstr, 13) < 0) *rpt_negtim = 0;
425 }
else if (strncmp(&
line[
i],
"L1NAVDISC", 9) == 0) {
426 if ((nflds = sscanf(
line,
"%s %f %f",
str, nav_thresh1, nav_thresh2))
428 printf(
"*********read_cntldata: expecting 3 fields");
429 printf(
" but read %d field(s)", nflds);
433 }
else if (strncmp(&
line[
i],
"NOISE", 5) == 0) {
434 if ((nflds = sscanf(
line,
"%s %f",
str, pct_noise_thresh)) != 2) {
435 printf(
"*********read_cntldata: NOISE: expecting 2 fields");
436 printf(
" but read %d field(s)", nflds);
440 }
else if (strncmp(&
line[
i],
"ENCRYPT", 7) == 0) {
441 if ((nflds = sscanf(
line,
"%s %f",
str, pct_encrypt_thresh)) != 2) {
442 printf(
"*********read_cntldata: ENCRYPT: expecting 2 fields");
443 printf(
" but read %d field(s)", nflds);
447 }
else if (strncmp(&
line[
i],
"TRNG_CHK", 8) == 0) {
448 if ((nflds = sscanf(
line,
"%s",
str)) != 1) {
449 printf(
"*********read_cntldata: TRNG_CHK: expecting 1 field");
450 printf(
" but read %d field(s)", nflds);
454 thr_ctl->trng_chk_do = 1;
458 else if (strncmp(&
line[
i],
"TLIM_INST_ANA", 13) == 0) {
459 if ((nflds = sscanf(
line,
"%s %s",
str, tstr)) != 2) {
460 printf(
"***** read_cntldata: expecting 2 fields for TLIM_INST_ANA\n");
461 printf(
" but read %d field(s)", nflds);
465 thr_ctl->rpt_inst_ana = 1;
466 if (strncmp(fsttim, tstr, 13) < 0) thr_ctl->rpt_inst_ana = 0;
467 }
else if (strncmp(&
line[
i],
"INST_ANA", 8) == 0) {
468 if ((nflds = sscanf(
line,
469 "INST_ANA%2d %f %f %f", &ival, &
f1, &
f2, &
f3)) != 4) {
470 printf(
"********read_cntldata: Error in INST_ANA line decode\n");
471 printf(
"# fields read: %d\n", nflds);
472 printf(
"Line is:\n%s\n\n",
line);
479 if ((ival < 1) || (ival > 32)) {
480 printf(
"********read_cntldata: Error in INST_ANA item #\n");
481 printf(
"It must be from 1 - 32 and the entered value was %d\n",
486 thr_ctl->inst_ana_do[ ival - 1 ] = 1;
487 thr_ctl->inst_ana_lo[ ival - 1 ] =
f1;
488 thr_ctl->inst_ana_hi[ ival - 1 ] =
f2;
489 thr_ctl->inst_ana_pct[ ival - 1 ] =
f3;
493 else if (strncmp(&
line[
i],
"TLIM_GAINV_CHK", 14) == 0) {
494 if ((nflds = sscanf(
line,
"%s %s",
str, tstr)) != 2) {
495 printf(
"***** read_cntldata: expecting 2 fields for TLIM_GAINV_CHK\n");
496 printf(
" but read %d field(s)", nflds);
500 thr_ctl->rpt_gainv_chk = 1;
501 if (strncmp(fsttim, tstr, 13) < 0) thr_ctl->rpt_gainv_chk = 0;
502 }
else if (strncmp(&
line[
i],
"GAINV_CHK", 9) == 0) {
503 if ((nflds = sscanf(
line,
"GAINV_CHK%1d %f", &ival, &
f1)) != 2) {
504 printf(
"********read_cntldata: Error in GAINV_CHK line decode\n");
505 printf(
"# fields read: %d\n", nflds);
506 printf(
"Line is:\n%s\n\n",
line);
513 if ((ival < 1) || (ival > 8)) {
514 printf(
"********read_cntldata: Error in GAINV_CHK item #\n");
515 printf(
"It must be from 1 - 8 and the entered value was %d\n",
520 thr_ctl->gainv_chk_do[ ival - 1 ] = 1;
521 thr_ctl->gainv_chk_pct[ ival - 1 ] =
f1;
525 else if (strncmp(&
line[
i],
"TLIM_TDIV_CHK", 13) == 0) {
526 if ((nflds = sscanf(
line,
"%s %s",
str, tstr)) != 2) {
527 printf(
"***** read_cntldata: expecting 2 fields for TLIM_TDIV_CHK\n");
528 printf(
" but read %d field(s)", nflds);
532 thr_ctl->rpt_tdi_vchk = 1;
533 if (strncmp(fsttim, tstr, 13) < 0) thr_ctl->rpt_tdi_vchk = 0;
534 }
else if (strncmp(&
line[
i],
"TDIV_CHK", 8) == 0) {
535 if ((nflds = sscanf(
line,
"TDIV_CHK%1d %f", &ival, &
f1)) != 2) {
536 printf(
"********read_cntldata: Error in TDIV_CHK line decode\n");
537 printf(
"# fields read: %d\n", nflds);
538 printf(
"Line is:\n%s\n\n",
line);
545 if ((ival < 1) || (ival > 8)) {
546 printf(
"********read_cntldata: Error in TDIV_CHK item #\n");
547 printf(
"It must be from 1 - 8 and the entered value was %d\n",
552 thr_ctl->tdiv_chk_do[ ival - 1 ] = 1;
553 thr_ctl->tdiv_chk_pct[ ival - 1 ] =
f1;
555 printf(
"*********read_cntldata: Cannot recognize the mnemonic read");
586 int32
l1file(int32 sdfid, int32 *nsamp, int32 *nscans,
int16 *dtynum) {
597 if (strcmp(
title,
"SeaWiFS Level-1A Data") != 0) {
598 sprintf(
err_msg,
"l1file: Data file is not level 1A file");
611 if (strncmp(
dtype,
"GAC", 3) == 0) {
613 }
else if (strncmp(
dtype,
"LAC", 3) == 0) {
615 }
else if (strncmp(
dtype,
"HRPT", 4) == 0) {
617 }
else if (strncmp(
dtype,
"LUN", 3) == 0) {
619 }
else if (strncmp(
dtype,
"SOL", 3) == 0) {
621 }
else if (strncmp(
dtype,
"IGC", 3) == 0) {
623 }
else if (strncmp(
dtype,
"TDI", 3) == 0) {
626 printf(
"Data type of '%s' is unknown. Exiting\n",
dtype);
661 int32
chk_gn(int32 sdfid, cntl1_str *gn1, cntl1_str *gn2,
int16 dtynum,
662 int32 nsamp, int32 nscans) {
663 int32
i, gn1sat[8], gn2sat[8], gn1unsat[8], gn2unsat[8];
665 float64 gn1_val[8], gn2_val[8];
669 printf(
"\n#Checking Level 1 and Level 2 gains ....");
676 for (
i = 0;
i < 8;
i++)
677 gn1_val[
i] = gn2_val[
i] = 0;
696 for (
i = 0;
i < 8;
i++) {
697 if ((gn1sat[
i] + gn1unsat[
i]) > 0)
698 gn1_val[
i] = ((float64) gn1sat[
i] / (gn1sat[
i] + gn1unsat[
i])) * 100;
702 if ((gn2sat[
i] + gn2unsat[
i]) > 0)
703 gn2_val[
i] = ((float64) gn2sat[
i] / (gn2sat[
i] + gn2unsat[
i]))*100;
712 if ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT))
713 for (
i = 0;
i < 8;
i++) {
715 (
float) (gn1sat[
i] + gn1unsat[
i] + gn2sat[
i] + gn2unsat[
i]) /
716 (
float) (nsamp * nscans) * 100.;
717 if (pct_good_gain < 100.) {
718 if (pct_good_gain >= 90.) {
719 printf(
"\nNote that percentage of good gains (%f) for band %d is < 100%%", pct_good_gain,
i);
721 printf(
"\n********chk_gn: Percentage of good gains (%f) for band %d is < 90 %%, an ERROR condition", pct_good_gain,
i);
723 sprintf(
str,
"L1GAIN%1d ", (
i + 1));
734 printf(
"\n\n#Mnemonic Code\t Value\t --\tError_threshold");
735 printf(
"\n#-----------------------------------------------\n");
740 for (
i = 0;
i < 8;
i++) {
742 if (gn1[
i].
band == 1) {
743 if (gn1_val[
i] != -1 && gn1_val[
i] > gn1[
i].threshold) {
746 sprintf(
str,
"L1GAIN1%1d ", (
i + 1));
750 printf(
"\nL1GAIN1%d %d\t%f --\t%f",
i + 1, failcode, gn1_val[
i],
756 for (
i = 0;
i < 8;
i++) {
758 if (gn2[
i].
band == 1) {
759 if (gn2_val[
i] != -1 && gn2_val[
i] > gn2[
i].threshold) {
762 sprintf(
str,
"L1GAIN2%1d ", (
i + 1));
766 printf(
"\nL1GAIN2%d %d\t%f --\t%f",
i + 1, failcode, gn2_val[
i],
772 for (
i = 0;
i < 8;
i++)
773 printf(
"\n gn1sat = %d\t gn1unsat = %d\t gn1_val = %f\n", gn1sat[
i],
774 gn1unsat[
i], gn1_val[
i]);
775 for (
i = 0;
i < 8;
i++)
776 printf(
"\n gn2sat = %d\t gn2unsat = %d\t gn2_val = %f\n", gn2sat[
i],
777 gn2unsat[
i], gn2_val[
i]);
807 int32
chk_zero(int32 sdfid, cntl1_str *zero_str, int32 nscans, int32 nsamp) {
808 int32
i, zero_pix[8];
813 printf(
"\n\n#Checking Zero pixels percentage ....");
820 for (
i = 0;
i < 8;
i++)
826 for (
i = 0;
i < 8;
i++)
827 zero_val[
i] = ((float64) zero_pix[
i] / (nscans * nsamp)) * 100.0;
833 printf(
"\n\n#Mnemonic Code\t Value\t --\tError_threshold");
834 printf(
"\n#-----------------------------------------------\n");
836 for (
i = 0;
i < 8;
i++) {
838 if (zero_str[
i].
band == 1) {
839 if (zero_val[
i] > zero_str[
i].threshold) {
842 sprintf(
str,
"L1ZERO%1d ", (
i + 1));
846 printf(
"\nL1ZERO%d %d\t%f --\t%f",
i + 1, failcode, zero_val[
i],
847 zero_str[
i].threshold);
852 for (
i = 0;
i < 8;
i++)
853 printf(
"\n zero_pix = %d\t zero_val = %f\n", zero_pix[
i], zero_val[
i]);
895 cntl2_str *l1hicnt, cntl2_str *l1locnt,
int *spike_cnt,
float *line_sd) {
897 int32
i, rec, bnd, failcode = 0;
898 int32
nbands = 8, nrec, rdrecs = 256, recsleft;
899 int32
start[3], edge[3];
900 int32 hicnt[8] = {0, 0, 0, 0, 0, 0, 0, 0};
901 int32 lowcnt[8] = {0, 0, 0, 0, 0, 0, 0, 0};
902 float32
value[8] = {0, 0, 0, 0, 0, 0, 0, 0};
903 int32_t cnt_coin_jmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
904 int32_t jmp_hist[1024];
909 for (
i = 0;
i < 1024;
i++)
913 printf(
"\n\n#Checking Low and High count percentages ....");
920 "chk_count: cannot allocate memory for reading l1a_data");
940 for (rec = 0; rec < nscans; rec += rdrecs) {
941 if ((recsleft = nscans - rec) < rdrecs)
955 anal_noise(rec, nrec, nscans, nsamp,
nbands, i16buf, spike_cnt, line_sd, cnt_coin_jmp, jmp_hist);
963 printf(
"Grand total of co-incident jumps\n");
964 printf(
"Total # pixels: %d\n", nscans * nsamp);
965 for (rec = 0; rec < 8; rec++)
966 printf(
"#co-incidences: %d, count: %d\n",
967 (rec + 1), *(cnt_coin_jmp + rec));
969 printf(
"\nhistogram (size 1024) of jump frequency");
970 for (rec = 0; rec < 1024; rec++) {
971 printf(
"%10d", *(jmp_hist + rec));
972 if (rec % 8 == 7) printf(
"\n");
979 printf(
"\n\nline-by-line jump count Standard deviation\n");
980 printf(
"line 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8\n");
981 for (rec = 0; rec < nscans; rec++) {
983 for (bnd = 0; bnd <
nbands; bnd++) {
984 printf(
" %4d", *(spike_cnt + bnd +
nbands * rec));
986 for (bnd = 0; bnd <
nbands; bnd++) {
987 printf(
" %7.2f", *(line_sd + bnd +
nbands * rec));
999 printf(
"\n\n#Mnemonic Code\t Value\t --\tErr_thresh\tCount_thresh");
1000 printf(
"\n#-----------------------------------------------------------\n");
1004 if (l1hicnt[
i].
band == 1) {
1005 value[
i] = (hicnt[
i] / (nscans * nsamp * 1.0)) * 100.0;
1006 if (
value[
i] > l1hicnt[
i].err_thresh) {
1009 sprintf(
str,
"L1HICOUNT%1d ", (
i + 1));
1013 printf(
"\nL1HICOUNT%d %d\t%f --\t%f\t%f",
1014 i + 1, failcode,
value[
i], l1hicnt[
i].err_thresh,
1015 l1hicnt[
i].cnt_thresh);
1021 if (l1locnt[
i].
band == 1) {
1022 value[
i] = (lowcnt[
i] / (nscans * nsamp * 1.0))*100.00;
1024 if (((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT)) &&
1025 (
value[
i] > l1locnt[
i].err_thresh)) {
1028 sprintf(
str,
"L1LOWCOUNT%1d ", (
i + 1));
1032 if ((dtynum ==
GAC) || (dtynum ==
LAC) || (dtynum ==
HRPT)) {
1033 printf(
"\nL1LOWCOUNT%d %d\t%f --\t%f\t%f",
1034 i + 1, failcode,
value[
i], l1locnt[
i].err_thresh,
1035 l1locnt[
i].cnt_thresh);
1037 printf(
"\nL1LOWCOUNT%d N/A\t%f --\t%f\t%f",
1038 i + 1,
value[
i], l1locnt[
i].err_thresh,
1039 l1locnt[
i].cnt_thresh);
1079 cntl2_str *l1hicnt, int32 *hicnt)
1082 int32 nrec, nsamp,
nbands, *hicnt;
1090 for (
i = 0;
i < nrec * nsamp *
nbands;
i += 8)
1091 if (databuf[
i] > l1hicnt[
BAND1].cnt_thresh)
1095 for (
i = 1;
i < nrec * nsamp *
nbands;
i += 8)
1096 if (databuf[
i] > l1hicnt[
BAND2].cnt_thresh)
1100 for (
i = 2;
i < nrec * nsamp *
nbands;
i += 8)
1101 if (databuf[
i] > l1hicnt[
BAND3].cnt_thresh)
1105 for (
i = 3;
i < nrec * nsamp *
nbands;
i += 8)
1106 if (databuf[
i] > l1hicnt[
BAND4].cnt_thresh)
1110 for (
i = 4;
i < nrec * nsamp *
nbands;
i += 8)
1111 if (databuf[
i] > l1hicnt[
BAND5].cnt_thresh)
1115 for (
i = 5;
i < nrec * nsamp *
nbands;
i += 8)
1116 if (databuf[
i] > l1hicnt[
BAND6].cnt_thresh)
1120 for (
i = 6;
i < nrec * nsamp *
nbands;
i += 8)
1121 if (databuf[
i] > l1hicnt[
BAND7].cnt_thresh)
1125 for (
i = 7;
i < nrec * nsamp *
nbands;
i += 8)
1126 if (databuf[
i] > l1hicnt[
BAND8].cnt_thresh)
1160 cntl2_str *l1locnt, int32 *lowcnt)
1163 int32 nrec, nsamp,
nbands, *lowcnt;
1171 for (
i = 0;
i < nrec * nsamp *
nbands;
i += 8)
1172 if (databuf[
i] < l1locnt[
BAND1].cnt_thresh)
1176 for (
i = 1;
i < nrec * nsamp *
nbands;
i += 8)
1177 if (databuf[
i] < l1locnt[
BAND2].cnt_thresh)
1181 for (
i = 2;
i < nrec * nsamp *
nbands;
i += 8)
1182 if (databuf[
i] < l1locnt[
BAND3].cnt_thresh)
1186 for (
i = 3;
i < nrec * nsamp *
nbands;
i += 8)
1187 if (databuf[
i] < l1locnt[
BAND4].cnt_thresh)
1191 for (
i = 4;
i < nrec * nsamp *
nbands;
i += 8)
1192 if (databuf[
i] < l1locnt[
BAND5].cnt_thresh)
1196 for (
i = 5;
i < nrec * nsamp *
nbands;
i += 8)
1197 if (databuf[
i] < l1locnt[
BAND6].cnt_thresh)
1201 for (
i = 6;
i < nrec * nsamp *
nbands;
i += 8)
1202 if (databuf[
i] < l1locnt[
BAND7].cnt_thresh)
1206 for (
i = 7;
i < nrec * nsamp *
nbands;
i += 8)
1207 if (databuf[
i] < l1locnt[
BAND8].cnt_thresh)
1269 int32
chk_nav(int32 sdfid, int32 nscans, float32 nav_thresh1,
1270 float32 nav_thresh2, int32 ntilts,
int16 tilt_ranges[20][2],
1272 int16 good_scans[20][2];
1273 int32
scan,
start[3], edge[3], failcode = 0;
1274 int32 err_thresh = 0, err_thresh1 = 0, err_thresh2 = 0;
1275 int32
i, fst, t_cnt = 0;
1277 int32 suncounter = 0, tiltcounter = 0, telcounter = 0;
1278 int32 timecounter = 0, earthcounter = 0, failcounter = 0;
1279 int32 fixtimecount = 0, interpcount = 0, warncount = 0;
1280 int32 tiltchgcount = 0;
1281 float32 *orb_vec, *sun_ref, *sen_mat, *
scan_ell;
1282 float32
value, v0[3], v1[3];
1283 int32_t t0, t1, tstart, delt, trend_dev, *
msec;
1284 double v0abs, v1abs, delang, d_value;
1285 float lo_nav_rate, hi_nav_rate, lo_nav_rate_delang,
1286 hi_nav_rate_delang, lo_nav_rate_delt, hi_nav_rate_delt;
1287 int lo_nav_rate_loc, hi_nav_rate_loc;
1290 printf(
"\n\n#Checking for Navigation discontinuity ....");
1292 for (
i = 0;
i < 20;
i++)
1293 good_scans[
i][0] = good_scans[
i][1] = 0;
1299 if ((orb_vec = (float32 *) calloc(nscans * 3,
sizeof (float32))) ==
NULL) {
1300 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading orb_vec");
1304 if ((sun_ref = (float32 *) calloc(nscans * 3,
sizeof (float32))) ==
NULL) {
1305 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading sun_ref");
1309 if ((sen_mat = (float32 *) calloc(nscans * 3 * 3,
sizeof (float32))) ==
NULL) {
1310 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading sen_mat");
1314 if ((
scan_ell = (float32 *) calloc(nscans * 6,
sizeof (float32))) ==
NULL) {
1315 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading scan_ell");
1319 if ((
msec = (int32_t *) calloc(nscans,
sizeof (int32_t))) ==
NULL) {
1320 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading msec");
1323 if ((nflag = (int32 *) calloc(nscans * 8,
sizeof (int32))) ==
NULL) {
1324 sprintf(
err_msg,
"chk_nav: cannot allocate memory for reading nflag");
1406 for (t_cnt = 0,
i = 0;
i < ntilts;
i++) {
1407 if (tilt_flags[
i] == 1 || tilt_flags[
i] == 2) {
1408 good_scans[t_cnt][0] = tilt_ranges[
i][0] - 1;
1409 good_scans[t_cnt][1] = tilt_ranges[
i][1] - 1;
1428 lo_nav_rate = 9999.;
1429 hi_nav_rate = -9999.;
1430 lo_nav_rate_loc = hi_nav_rate_loc = -1;
1431 lo_nav_rate_delang = lo_nav_rate_delt = 0;
1432 hi_nav_rate_delang = hi_nav_rate_delt = 0;
1434 for (
i = 0;
i < t_cnt;
i++) {
1436 for (fst = 0,
scan = good_scans[
i][0];
scan <= good_scans[
i][1];
scan++) {
1442 if ((*(nflag +
scan * 8) == 0) && (*(nflag +
scan * 8 + 7) == 0)) {
1452 if (t0 < tstart) t0 = t0 + 86400000;
1463 if ((dtynum ==
GAC) &&
1464 (((delt <= 0) && (delt > -2340)) ||
1465 ((delt >= 686) && (delt <= 2666)))) {
1466 trend_dev = delt - 666;
1467 if (rpt_negtim == 1)failcode = 1;
1468 printf(
"\n\n\nTIME_ERROR scan # [%d-%d] ",
scan,
scan + 1);
1469 printf(
"Delta time = %d, Trend deviation = %d\n\n\n", delt, trend_dev);
1470 printf(
"NOTE that if this time is not in a mandatory product\n");
1471 printf(
"failure time range, it may need to be put in one.\n");
1472 printf(
"For post-repro 3 data this denotes a 30 second time\n");
1473 printf(
"shift that wasn't detected or a GPS reset\n");
1474 printf(
"Check around this time period for navigation offsets\n");
1475 printf(
"using GAC, LAC and HRPT stations.\n");
1476 printf(
"Also, inform QC and navigation manager of this problem\n");
1477 printf(
"(This may require an update to l1stat_chk)\n\n\n");
1479 v0abs = sqrt(v0[0] * v0[0] + v0[1] * v0[1] + v0[2] * v0[2]);
1480 v1abs = sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
1489 d_value = sqrt(pow((v0[0] / v0abs - v1[0] / v1abs), 2) +
1490 pow((v0[1] / v0abs - v1[1] / v1abs), 2) +
1491 pow((v0[2] / v0abs - v1[2] / v1abs), 2));
1493 delang = 2. * asin(d_value / 2.);
1495 value = (delang * 1.e6) / (
float) delt;
1500 if (
value < lo_nav_rate) {
1501 lo_nav_rate =
value;
1502 lo_nav_rate_loc =
scan;
1503 lo_nav_rate_delang = delang;
1504 lo_nav_rate_delt = delt;
1506 if (
value > hi_nav_rate) {
1507 hi_nav_rate =
value;
1508 hi_nav_rate_loc =
scan;
1509 hi_nav_rate_delang = delang;
1510 hi_nav_rate_delt = delt;
1513 if (
value < nav_thresh1) {
1517 printf(
"\nNAVERR scan # [%d-%d] ",
scan,
scan + 1);
1518 printf(
"value = %f, threshold = %f",
value, nav_thresh1);
1519 printf(
" Kdelang: %f, delt: %d", 1000. * delang, delt);
1520 }
else if (
value > nav_thresh2) {
1524 printf(
"\nNAVERR scan # [%d-%d] ",
scan,
scan + 1);
1525 printf(
"value = %f, threshold = %f",
value, nav_thresh2);
1526 printf(
" Kdelang: %f, delt: %d", 1000. * delang, delt);
1537 if (*(nflag +
scan * 8) == 1) failcounter++;
1538 if (*(nflag +
scan * 8 + 1) == 1) interpcount++;
1539 if (*(nflag +
scan * 8 + 2) == 1) suncounter++;
1540 if (*(nflag +
scan * 8 + 3) == 1) earthcounter++;
1541 if (*(nflag +
scan * 8 + 4) == 1) telcounter++;
1542 if (*(nflag +
scan * 8 + 5) == 1) timecounter++;
1543 if (*(nflag +
scan * 8 + 5) == 2) fixtimecount++;
1544 if (*(nflag +
scan * 8 + 6) == 1) tiltcounter++;
1545 if (*(nflag +
scan * 8 + 6) == 2) tiltchgcount++;
1546 if (*(nflag +
scan * 8 + 7) == 1) warncount++;
1550 printf(
"\n\n# --- Cumulative navigation flag (nflag) settings ---\n");
1551 printf(
"Description # of occurences\n");
1552 printf(
"-------------------------------------- ---------------\n");
1553 printf(
"navigation failure (nflag(1) = 1) %d\n", failcounter);
1554 printf(
"nav interp problem (nflag(2) = 1) %d\n", interpcount);
1555 printf(
"sun sensor out (nflag(3) = 1) %d\n", suncounter);
1556 printf(
"earth sensor out (nflag(4) = 1) %d\n", earthcounter);
1557 printf(
"attitude uncertainty (nflag(5) = 1) %d\n", telcounter);
1558 printf(
"time code problem (nflag(6) = 1) %d\n", timecounter);
1559 printf(
"time code problem fixed (nflag(6) = 2) %d\n", fixtimecount);
1560 printf(
"tilt info bad (nflag(7) = 1) %d\n", tiltcounter);
1561 printf(
"tilt changing (nflag(7) = 2) %d\n", tiltchgcount);
1562 printf(
"navigation warning (nflag(8) = 1) %d\n\n", warncount);
1564 printf(
"\n\n\n#Mnemonic Code tot # outside\tthresh_1 thresh_2 # below 1 # below 2");
1565 printf(
"\n thresholds ");
1566 printf(
"\n#--------------------------------------------------------------------------\n");
1568 printf(
"\nL1NAVDISC %d\t %d\t %f\t %f\t%d\t %d", failcode,
1569 err_thresh, nav_thresh1, nav_thresh2, err_thresh1, err_thresh2);
1574 printf(
"\n\nRecord of lowest, highest rates found ( ideal rate: 1.059)\n");
1575 printf(
" rate (mrad / sec) line location delang (mrad) delt (msec)\n");
1576 printf(
"LOWRATE:%-12.4f %-10d %-12.4f %-12.4f\n", lo_nav_rate, lo_nav_rate_loc, lo_nav_rate_delang * 1000., lo_nav_rate_delt);
1577 printf(
"HIRATE: %-12.4f %-10d %-12.4f %-12.4f\n", hi_nav_rate, hi_nav_rate_loc, hi_nav_rate_delang * 1000., hi_nav_rate_delt);
1582 sprintf(
str,
"L1NAVDISC ");
1623 int16 tilt_ranges[20][2],
int16 *tilt_flags) {
1624 int32
i, failcode = 0,
start[3], edge[3];
1625 float32 tilt_value = 0;
1628 printf(
"\n\n#Checking Tilt behavior....");
1635 edge[1] = edge[2] = 0;
1645 edge[1] = edge[2] = 0;
1662 printf(
"\n\n#Mnemonic Code\t Value\t --\tError_threshold");
1663 printf(
"\n#-----------------------------------------------\n");
1665 for (
i = 0;
i < *ntilts;
i++) {
1666 if (tilt_flags[
i] == 3) {
1668 tilt_value = (tilt_ranges[
i][1] - tilt_ranges[
i][0] + 1);
1670 tilt_value = (tilt_value * 2.0 / 3.0);
1672 tilt_value = (tilt_value / 6.0);
1673 if (tilt_value > l1tilt_thresh)
1677 printf(
"\nL1TILT %d\t%f\t%f", failcode, tilt_value, l1tilt_thresh);
1680 sprintf(
str,
"L1TILT ");
1710 printf(
"\n\nSuccessful check, no statistical errors\n");
1713 printf(
"\n\nFailure of statistical check due to program error\n");
1715 printf(
"\n\nFailure of statistical check due to data error\n\n");
1716 printf(
"Summary of mnemonics with bad status:\n");