75 int32_t nscans, int32_t nsamples, int32_t scan_no, int16_t gn,
76 float *
rads,
float *l1b_data, int32_t *sl_scan, int32_t *sl_flag) {
119 int32
i, n,
p, farthest,
status, pix;
120 float32
delta, Ltyp_thresh, Ltypical_8 = 1.09;
121 float32 knee_val = 0, stray_thresh = 0;
122 int32 edge = 0, right_edge = -1, left_edge = -1;
123 static int32 scans_done,
scan, scan_p1, prev_scans, next_scans;
124 static int32 scan_m1, rt_edge_found =
FALSE;
127 float32 Ctyp_frac = 1.25, Ctyp_thresh;
135 if (*initial ==
TRUE) {
141 line_no[
scan - 1] = scan_no;
143 memcpy(l1b_buf[
i][
scan - 1], &l1b_data[
i * nsamples],
144 (
sizeof (
float)*nsamples));
145 for (
i = 0;
i < nsamples;
i++)
154 if (*initial ==
FALSE) {
160 line_no[scan_p1 - 1] = scan_no;
162 memcpy((
float *) l1b_buf[
i][scan_p1 - 1],
163 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
164 for (
i = 0;
i < nsamples;
i++)
165 flag_buf[scan_p1 - 1][
i] =
BLANK;
172 if (scans_done == 1) {
178 line_no[scan_p1 - 1] = scan_no;
180 memcpy((
float *) l1b_buf[
i][scan_p1 - 1],
181 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
182 for (
i = 0;
i < nsamples;
i++)
183 flag_buf[scan_p1 - 1][
i] =
BLANK;
188 if (scans_done > 1) {
189 scan_m1 = (scan_m1) % 3 + 1;
191 scan_p1 = (scan_p1) % 3 + 1;
195 if (scans_done < nscans - 1) {
196 line_no[scan_p1 - 1] = scan_no;
198 memcpy((
float *) l1b_buf[
i][scan_p1 - 1],
199 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
200 for (
i = 0;
i < nsamples;
i++)
201 flag_buf[scan_p1 - 1][
i] =
BLANK;
206 next_scans = next_scans - 1;
207 if (next_scans < 0) {
208 *sl_scan = line_no[scan_m1 - 1];
210 memcpy((
float *) &l1b_data[
i * nsamples],
211 l1b_buf[
i][scan_m1 - 1],
sizeof (
float)*nsamples);
212 for (
i = 0;
i < nsamples;
i++)
213 sl_flag[
i] = flag_buf[scan_m1 - 1][
i];
221 if (*initial ==
TRUE) {
228 Ctyp_thresh = Ctyp_frac * Ltypical_8;
232 stray_thresh = Styp_frac * knee_val;
234 for (pix = 0; pix < nsamples; pix++) {
235 if (l1b_buf[7][
scan - 1][pix] > knee_val) {
236 flag_buf[
scan - 1][pix] =
BT;
237 if ((prev_scans >= 1) && (flag_buf[scan_m1 - 1][pix]) !=
BT)
238 flag_buf[scan_m1 - 1][pix] =
AT;
239 if ((next_scans >= 1) && (flag_buf[scan_p1 - 1][pix] !=
BT))
240 flag_buf[scan_p1 - 1][pix] =
AT;
247 rt_edge_found =
FALSE;
249 while (n < nsamples - 1) {
252 if (n == 0 && flag_buf[
scan - 1][n] ==
BT) {
254 rt_edge_found =
FALSE;
258 while (edge ==
NO && (n < nsamples - 1)) {
260 if (flag_buf[
scan - 1][n] !=
BT || flag_buf[
scan - 1][n + 1] !=
BT) {
261 delta = l1b_buf[7][
scan - 1][n + 1] - l1b_buf[7][
scan - 1][n];
270 if (
delta > Ltyp_thresh && l1b_buf[7][
scan - 1][n + 1] > stray_thresh) {
272 rt_edge_found =
FALSE;
274 if (-1 *
delta > Ltyp_thresh && l1b_buf[7][
scan - 1][n] > stray_thresh) {
275 if (!(rt_edge_found)) {
277 rt_edge_found =
TRUE;
298 for (
i = n;
i >= 0;
i--)
if (l1b_buf[7][
scan - 1][
i] < Ctyp_thresh)
break;
303 while (
p <= farthest) {
304 if (flag_buf[
scan - 1][
p] ==
BT)
308 flag_buf[
scan - 1][
p] =
p - right_edge;
311 l1b_buf[
i][
scan - 1][
p] +=
312 CF_right[
i][2] * l1b_buf[
i][
scan - 1][right_edge];
315 l1b_buf[
i][
scan - 1][
p] +=
316 CF_right[
i][1] * l1b_buf[
i][
scan - 1][right_edge];
334 while (
p >= farthest) {
335 if (flag_buf[
scan - 1][
p] ==
BT)
339 flag_buf[
scan - 1][
p] = left_edge -
p;
342 l1b_buf[
i][
scan - 1][
p] +=
343 (CF_left[
i][2] * l1b_buf[
i][
scan - 1][left_edge]);
346 l1b_buf[
i][
scan - 1][
p] +=
347 (CF_left[
i][1] * l1b_buf[
i][
scan - 1][left_edge]);
349 }
else if (flag_buf[
scan - 1][
p] > 0) {
350 flag_buf[
scan - 1][
p] += 1000 * (left_edge -
p);
353 l1b_buf[
i][
scan - 1][
p] +=
354 (CF_left[
i][2] * l1b_buf[
i][
scan - 1][left_edge]);
357 l1b_buf[
i][
scan - 1][
p] +=
358 (CF_left[
i][1] * l1b_buf[
i][
scan - 1][left_edge]);
366 right_edge = nsamples - 1;
368 while ((n < nsamples - 1) && (edge ==
LEFT)) {
369 if (flag_buf[
scan - 1][n] !=
BT || flag_buf[
scan - 1][n + 1] !=
BT) {
370 if (l1b_buf[7][
scan - 1][n + 1] < Ctyp_thresh)
goto R_found;
371 delta = l1b_buf[7][
scan - 1][n + 1] - l1b_buf[7][
scan - 1][n];
380 if (-1 *
delta > Ltyp_thresh &&
381 l1b_buf[7][
scan - 1][n] > stray_thresh) {
384 rt_edge_found =
TRUE;
391 rt_edge_found =
TRUE;
400 while (
p <= farthest) {
401 if (flag_buf[
scan - 1][
p] ==
BT)
405 (flag_buf[
scan - 1][
p] > 0)) {
406 flag_buf[
scan - 1][
p] =
p - right_edge;
409 l1b_buf[
i][
scan - 1][
p] +=
410 (CF_right[
i][2] * l1b_buf[
i][
scan - 1][right_edge]);
413 l1b_buf[
i][
scan - 1][
p] +=
414 (CF_right[
i][1] * l1b_buf[
i][
scan - 1][right_edge]);
426 for (
p = left_edge;
p <= right_edge;
p++) {
428 if ((prev_scans >= 1) && (flag_buf[scan_m1 - 1][
p]) !=
BT)
429 flag_buf[scan_m1 - 1][
p] =
AT;
430 if ((next_scans >= 1) && (flag_buf[scan_p1 - 1][
p] !=
BT))
431 flag_buf[scan_p1 - 1][
p] =
AT;
435 if (rt_edge_found && n < nsamples - 1)
444 scans_done = scans_done + 1;
445 if (scans_done > 1) {
446 *sl_scan = line_no[scan_m1 - 1];
449 memcpy(&l1b_data[
i * nsamples],
450 l1b_buf[
i][scan_m1 - 1], (
sizeof (
float)*nsamples));
451 for (
i = 0;
i < nsamples;
i++)
452 sl_flag[
i] = flag_buf[scan_m1 - 1][
i];