73 int32_t nscans, int32_t nsamples, int32_t scan_no, int16_t gn,
74 float *
rads,
float *l1b_data, int32_t *sl_scan,
127 float32
delta, Ltyp_thresh, Ltypical_8 = 1.09;
128 float32 corr = 0, knee_val = 0, stray_thresh = 0;
130 int32 edge = 0, right_edge = -1, left_edge = -1;
131 static int32 scans_done,
scan, scan_p1, scan_p2, prev_scans, next_scans;
132 static int32 scan_m1, scan_m2, rt_edge_found =
FALSE;
135 float32 Ctyp_frac = 1.25, Ctyp_thresh;
145 if (*initial ==
TRUE) {
153 line_no[
scan - 1] = scan_no;
155 memcpy(l1b_buf[
i][
scan - 1], &l1b_data[
i * nsamples],
156 (
sizeof (
float)*nsamples));
157 for (
i = 0;
i < nsamples;
i++)
166 if (*initial ==
FALSE) {
171 line_no[scan_p1 - 1] = scan_no;
173 memcpy((
float *) l1b_buf[
i][scan_p1 - 1],
174 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
175 for (
i = 0;
i < nsamples;
i++)
176 flag_buf[scan_p1 - 1][
i] =
BLANK;
186 line_no[scan_p2 - 1] = scan_no;
188 memcpy((
float *) l1b_buf[
i][scan_p2 - 1],
189 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
190 for (
i = 0;
i < nsamples;
i++)
191 flag_buf[scan_p2 - 1][
i] =
BLANK;
198 if (scans_done == 1) {
205 line_no[scan_p2 - 1] = scan_no;
207 memcpy((
float *) l1b_buf[
i][scan_p2 - 1],
208 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
209 for (
i = 0;
i < nsamples;
i++)
210 flag_buf[scan_p2 - 1][
i] =
BLANK;
216 if (scans_done == 2) {
224 line_no[scan_p2 - 1] = scan_no;
226 memcpy((
float *) l1b_buf[
i][scan_p2 - 1],
227 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
228 for (
i = 0;
i < nsamples;
i++)
229 flag_buf[scan_p2 - 1][
i] =
BLANK;
234 if (scans_done > 2) {
235 scan_m2 = (scan_m2) % 5 + 1;
236 scan_m1 = (scan_m1) % 5 + 1;
238 scan_p1 = (scan_p1) % 5 + 1;
239 scan_p2 = (scan_p2) % 5 + 1;
243 if (scans_done < nscans - 2) {
244 line_no[scan_p2 - 1] = scan_no;
246 memcpy((
float *) l1b_buf[
i][scan_p2 - 1],
247 &l1b_data[
i * nsamples],
sizeof (
float)*nsamples);
248 for (
i = 0;
i < nsamples;
i++)
249 flag_buf[scan_p2 - 1][
i] =
BLANK;
254 next_scans = next_scans - 1;
255 if (next_scans < 0) {
256 *sl_scan = line_no[scan_m2 - 1];
258 memcpy((
float *) &l1b_data[
i * nsamples],
259 l1b_buf[
i][scan_m2 - 1],
sizeof (
float)*nsamples);
260 for (
i = 0;
i < nsamples;
i++)
261 sl_flag[
i] = flag_buf[scan_m2 - 1][
i];
269 if (*initial ==
TRUE) {
275 Ctyp_thresh = Ctyp_frac * Ltypical_8;
279 stray_thresh = Styp_frac * knee_val;
281 for (
p = 0;
p < nsamples;
p++) {
282 if (l1b_buf[7][
scan - 1][
p] > knee_val) {
285 if ((prev_scans >= 2) && (flag_buf[scan_m2 - 1][
p] !=
BT))
286 flag_buf[scan_m2 - 1][
p] =
AT;
287 if ((prev_scans >= 1) && (flag_buf[scan_m1 - 1][
p]) !=
BT)
288 flag_buf[scan_m1 - 1][
p] =
AT;
290 flag_buf[scan_p1 - 1][
p] =
AT;
292 flag_buf[scan_p2 - 1][
p] =
AT;
298 rt_edge_found =
FALSE;
300 while (n < nsamples - 1) {
303 if (n == 0 && flag_buf[
scan - 1][n] ==
BT) {
305 rt_edge_found =
FALSE;
308 while (edge ==
NO && (n < nsamples - 1)) {
309 if (flag_buf[
scan - 1][n] !=
BT || flag_buf[
scan - 1][n + 1] !=
BT) {
310 delta = l1b_buf[7][
scan - 1][n + 1] - l1b_buf[7][
scan - 1][n];
319 if (
delta > Ltyp_thresh && l1b_buf[7][
scan - 1][n + 1] > stray_thresh) {
321 rt_edge_found =
FALSE;
323 if (-1 *
delta > Ltyp_thresh && l1b_buf[7][
scan - 1][n] > stray_thresh) {
324 if (!(rt_edge_found)) {
326 rt_edge_found =
TRUE;
342 for (
i = n;
i >= 0;
i--)
if (l1b_buf[7][
scan - 1][
i] < Ctyp_thresh)
break;
346 farthest =
min((right_edge +
RRANGE), (nsamples - 1));
347 while (
p <= farthest) {
348 if (flag_buf[
scan - 1][
p] ==
BT)
352 flag_buf[
scan - 1][
p] =
p - right_edge;
360 while (
p >= farthest) {
361 if (flag_buf[
scan - 1][
p] ==
BT)
365 flag_buf[
scan - 1][
p] = left_edge -
p;
367 if (flag_buf[
scan - 1][
p] > 0)
368 flag_buf[
scan - 1][
p] =
369 flag_buf[
scan - 1][
p] + 1000 * (left_edge -
p);
375 right_edge = nsamples - 1;
377 while ((n < nsamples - 1) && (edge ==
LEFT)) {
378 if (flag_buf[
scan - 1][n] !=
BT || flag_buf[
scan - 1][n + 1] !=
BT) {
379 if (l1b_buf[7][
scan - 1][n + 1] < Ctyp_thresh)
goto R_found;
380 delta = l1b_buf[7][
scan - 1][n + 1] - l1b_buf[7][
scan - 1][n];
389 if (-1 *
delta > Ltyp_thresh &&
390 l1b_buf[7][
scan - 1][n] > stray_thresh) {
393 rt_edge_found =
TRUE;
399 rt_edge_found =
TRUE;
403 farthest =
min((right_edge +
RRANGE), (nsamples - 1));
404 while (
p <= farthest) {
405 if (flag_buf[
scan - 1][
p] ==
BT)
408 flag_buf[
scan - 1][
p] =
p - right_edge;
418 for (
p = left_edge;
p <= right_edge;
p++) {
420 if ((prev_scans >= 2) && (flag_buf[scan_m2 - 1][
p] !=
BT))
421 flag_buf[scan_m2 - 1][
p] =
AT;
422 if ((prev_scans >= 1) && (flag_buf[scan_m1 - 1][
p]) !=
BT)
423 flag_buf[scan_m1 - 1][
p] =
AT;
425 flag_buf[scan_p1 - 1][
p] =
AT;
427 flag_buf[scan_p2 - 1][
p] =
AT;
429 if (prev_scans >= 1) {
430 if ((flag_buf[scan_m1 - 1][left_edge - 1] !=
BT) && (left_edge > 1))
431 flag_buf[scan_m1 - 1][left_edge - 1] =
DIAG;
432 if ((flag_buf[scan_m1 - 1][right_edge + 1] !=
BT) &&
433 (right_edge < nsamples - 1))
434 flag_buf[scan_m1 - 1][right_edge + 1] =
DIAG;
436 if (next_scans >= 1) {
437 if ((flag_buf[scan_p1 - 1][left_edge - 1] !=
BT) && (left_edge > 1))
438 flag_buf[scan_p1 - 1][left_edge - 1] =
DIAG;
439 if ((flag_buf[scan_p1 - 1][right_edge + 1] !=
BT) &&
440 (right_edge < nsamples - 1))
441 flag_buf[scan_p1 - 1][right_edge + 1] =
DIAG;
444 if (rt_edge_found && n < nsamples - 1)
460 memcpy(&l1b_tmpbuf[
i * nsamples], l1b_buf[
i][
scan - 1],
461 (
sizeof (
float)*nsamples));
463 for (n = 0; n < nsamples; n++) {
464 if (flag_buf[
scan - 1][n] > 0) {
482 scans_done = scans_done + 1;
483 if (scans_done > 2) {
484 *sl_scan = line_no[scan_m2 - 1];
486 memcpy(&l1b_data[
i * nsamples],
487 l1b_buf[
i][scan_m2 - 1], (
sizeof (
float)*nsamples));
488 for (
i = 0;
i < nsamples;
i++)
489 sl_flag[
i] = flag_buf[scan_m2 - 1][
i];