OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getmetrics.c
Go to the documentation of this file.
1 /* ---------------------------------------------------------------- */
2 /* Module getmetrics - computes seawifs L1A image metrics info */
3 /* */
4 /* B. A. Franz, GSC, 11/97 */
5 /* ---------------------------------------------------------------- */
6 
7 #include "swl0_proto.h"
8 
9 static l1met totmet; /* Total metrics */
10 static l1met avgmet; /* Mean metrics */
11 
12 /* ---------------------------------------------------------------- */
13 /* addL1Metrics() - adds metrics from one L1A scan to total */
14 
15 /* ---------------------------------------------------------------- */
16 void addL1Metrics(INT32 scanNum, swl1rec *l1rec) {
17  int ip, ib;
18 
19  if (scanNum <= 0)
20  memset(&totmet, 0, sizeof (totmet));
21 
22  for (ip = 0; ip < l1rec->npix; ip++) {
23 
24  for (ib = 0; ib < NBANDS; ib++) {
25 
26  if ((l1rec->data[ip][ib] - l1rec->darkpix[ib]) < 3)
27  totmet.zeropix[ib]++;
28 
29  if (l1rec->gain[ib] == 0) { /* Earth Gain 1 */
30 
31  if (l1rec->data[ip][ib] >= 1023)
32  totmet.gain1_satpix[ib]++;
33  else
34  totmet.gain1_nonsatpix[ib]++;
35 
36  totmet.gain1_mean_rad[ib] += l1rec->data[ip][ib];
37 
38  } else if (l1rec->gain[ib] == 2) { /* Earth Gain 2 */
39 
40  if (l1rec->data[ip][ib] >= 1023)
41  totmet.gain2_satpix[ib]++;
42  else
43  totmet.gain2_nonsatpix[ib]++;
44 
45  totmet.gain2_mean_rad[ib] += l1rec->data[ip][ib];
46 
47  }
48  }
49 
50  }
51  return;
52 }
53 
54 
55 
56 /* ---------------------------------------------------------------- */
57 /* getL1metrics() - returns pointer to mean metrics structure */
58 
59 /* ---------------------------------------------------------------- */
60 l1met *getL1Metrics(void) {
61  int ib;
62  INT32 gain1Cnt;
63  INT32 gain2Cnt;
64 
65  memcpy(&avgmet, &totmet, sizeof (l1met));
66 
67  for (ib = 0; ib < NBANDS; ib++) {
68 
69  gain1Cnt = totmet.gain1_satpix[ib]
70  + totmet.gain1_nonsatpix[ib];
71 
72  gain2Cnt = totmet.gain2_satpix[ib]
73  + totmet.gain2_nonsatpix[ib];
74 
75  if (gain1Cnt > 0)
76  avgmet.gain1_mean_rad[ib] /= gain1Cnt;
77 
78  if (gain2Cnt > 0)
79  avgmet.gain2_mean_rad[ib] /= gain2Cnt;
80  }
81 
82  /*
83  for (ib=0; ib<NBANDS; ib++)
84  printf("%2d %7d %7d %7d %7d %7d %10.2f %10.2f\n",ib,
85  avgmet.gain1_satpix[ib],
86  avgmet.gain2_satpix[ib],
87  avgmet.gain1_nonsatpix[ib],
88  avgmet.gain2_nonsatpix[ib],
89  avgmet.zeropix[ib],
90  avgmet.gain1_mean_rad[ib],
91  avgmet.gain2_mean_rad[ib]);
92  */
93 
94  return (&avgmet);
95 }
96 
97 
98 
l1met * getL1Metrics(void)
Definition: getmetrics.c:60
read l1rec
int32_t INT32
Definition: elements.h:6
void addL1Metrics(INT32 scanNum, swl1rec *l1rec)
Definition: getmetrics.c:16
@ NBANDS
Definition: make_L3_v1.1.c:53