OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
st_lt.c
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  Function: stray_light_corr
3 
4  Returns: int32 (status)
5  Returns as 0, "not done", to indicate that the routine did not
6  return any useful information for the last call, but was filling
7  its buffers with scan line data; and 1, "done", to indicate that
8  the l1b_data and sl_flag arrays for scan line sl_scan have been
9  set.
10 
11  Description:
12  The function stray_light_corr calls stray_light_lac or stray_light_gac
13  depending upon input data type. If the processed scan line is
14  returned (status = DONE) checks sl_flag arry for stray light flags
15  and sets corresponding l2_flag bits.
16 
17  Parameters: (in calling order)
18  Type Name I/O Description
19  ---- ---- --- -----------
20  int32 *initial I Flag, should be set to "true" (a value
21  of 1) if it is the fst call for a scene
22  float32 Ltyp_frac I fraction of Ltypical for band 8
23  float32 Styp_frac I fraction value that will be applied
24  to knee value to calculate straylight
25  threshold
26  int32 nscans I the number of scan lines in the scene
27  (to be processed). Must be set to <5
28  to process only in the along scan
29  int32 nsamples I number of pixel data values in
30  l1b_data and sl_flag
31  int32 scan_no I scan line number of l1b_data input
32  char *dtype I l1b_data data type
33  float32 *l1b_data I/O array of nsamples long containing
34  l1b_data of scan line scan_no
35  int32 *sl_scan O scan line number for which the
36  returned l1b_data apply
37  int16 *l2_flags O an array of nsamples long containing
38  level2 flags of scan line scan_no. The
39  corresponding pixel flags will be set
40  for affected pixels
41  int32 *AS_pixels I Along Scan pixels (constant set to 12)
42 
43  Notes:
44 
45  Modification history:
46  Programmer Organization Date Description of change
47  -------------- ------------ -------- ---------------------
48  Lakshmi Kumar Hughes STX 02/10/97 Added input argument
49  Styp_frac & is passed to
50  stlt lac and gac routines
51  Lakshmi Kumar Hughes STX 03/21/96 Fixed code for
52  non ANSI compile options
53  Lakshmi Kumar Hughes STX 10/12/95 Original development
54  W. Robinson, GSC 4 Nov 97 remove hard coding of
55  range and fix problem
56  with sl_flag of > 1000
57 ------------------------------------------------------------------------------*/
58 
59 #include "st_lt.h"
60 #include "st_proto.h"
61 #include <mfhdf.h>
62 
63 
64 int32_t
65 stray_light_corr(int32_t *initial, float Ltyp_frac, float Styp_frac,
66  int32_t nscans, int32_t nsamples, int32_t scan_no, char *dtype,
67  int16_t gn, float *rads, float *l1b_data, int32_t *sl_scan,
68  int16_t *l2_flags, int32_t *AS_pixels) {
69  int32 status; /* Function returned value */
70  int32 sl_flag[MAXSAMPS]; /* Flag list identifying BTs */
71  int32 range; /* Range of pixels flagged bad */
72  int32 i, left, right;
73  static float tsum = 0;
74  static float t1, t2;
75  div_t quot1;
76 
77  /* call appropriate correction routine according to data type */
78  for (i = 0; i < nsamples; i++)
79  l2_flags[i] = 0;
80 
81  t1 = (float) clock() / CLOCKS_PER_SEC;
82 
83  if ((strcmp(dtype, "GAC")) == 0)
84  status = stray_light_gac(initial, Ltyp_frac, Styp_frac, nscans, nsamples,
85  scan_no, gn, rads, l1b_data, sl_scan, sl_flag);
86  else
87  status = stray_light_lac(initial, Ltyp_frac, Styp_frac, nscans, nsamples,
88  scan_no, gn, rads, l1b_data, sl_scan, sl_flag);
89 
90  t2 = (float) clock() / CLOCKS_PER_SEC;
91  tsum += t2 - t1;
92 
93  /*
94  if (scan_no == nscans)
95  printf("\n%d\t%f\n", nscans, tsum);
96  */
97 
98 
99  /* if status = done do the following loop */
100  if (status == DONE) {
101  range = *AS_pixels;
102  /* WDR keep the variable above range = 14; */
103  if ((strcmp(dtype, "GAC")) == 0) {
104  quot1 = div(range, 4);
105  if (quot1.rem > 0)
106  range = quot1.quot + 1;
107  else
108  range = quot1.quot;
109  }
110  for (i = 0; i < nsamples; i++) {
111  if (sl_flag[i] < 1000) {
112  if ((sl_flag[i] > -10) && (sl_flag[i] <= range))
113  l2_flags[i] = l2_flags[i] + 256;
114  } else {
115  left = sl_flag[i] / 1000;
116  /* WDR as was:right = sl_flag[i] - 1000; */
117  right = sl_flag[i] % 1000;
118  if ((left <= range) || (right <= range))
119  l2_flags[i] = l2_flags[i] + 256;
120  } /* end else */
121  } /* end for */
122  } /* end if */
123  return status;
124 }
float rads[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: l1a_seawifs.c:47
int status
Definition: l1_czcs_hdf.c:32
int32_t stray_light_gac(int32_t *initial, float Ltyp_frac, float Styp_frac, int32_t nscans, int32_t nsamples, int32_t scan_no, int16_t gn, float *rads, float *l1b_data, int32_t *sl_scan, int32_t *sl_flag)
Definition: gac_st.c:74
float Ltyp_frac
Definition: l1a_seawifs.c:101
#define MAXSAMPS
Definition: st_lt.h:28
dtype
Definition: DDataset.hpp:31
int32_t stray_light_corr(int32_t *initial, float Ltyp_frac, float Styp_frac, int32_t nscans, int32_t nsamples, int32_t scan_no, char *dtype, int16_t gn, float *rads, float *l1b_data, int32_t *sl_scan, int16_t *l2_flags, int32_t *AS_pixels)
Definition: st_lt.c:65
int i
Definition: decode_rs.h:71
#define DONE
Definition: st_lt.h:24
int32_t stray_light_lac(int32_t *initial, float Ltyp_frac, float Styp_frac, int32_t nscans, int32_t nsamples, int32_t scan_no, int16_t gn, float *rads, float *l1b_data, int32_t *sl_scan, int32_t *sl_flag)
Definition: lac_st.c:72