IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 4, 2023, 7:36:15 AM (3 years ago)
Author:
eugene
Message:

merge from trunk: spline improvements & string vector equate

Location:
branches/eam_branches/ipp-20220316/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/Ohana

  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.data/threshold.c

    r42156 r42361  
    11# include "data.h"
     2
     3int QUIET = FALSE;
     4
     5void _threshold_set_values (double value, int Nbin, double level, int thresherr) {
     6
     7  set_variable ("threshval", value);
     8  set_int_variable ("threshbin", Nbin);
     9  set_variable ("threshold", level);
     10  set_int_variable ("thresherr", thresherr);
     11
     12  if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n", level, Nbin, value);
     13  return;
     14}
    215
    316int threshold (int argc, char **argv) {
     
    619  Vector *vecx, *vecy;
    720
    8   int QUIET = FALSE;
    921  if ((N = get_argument (argc, argv, "-q"))) {
    1022    QUIET = TRUE;
     23    remove_argument (N, &argc, argv);
     24  }
     25
     26  int SATURATE = FALSE;
     27  if ((N = get_argument (argc, argv, "-saturate"))) {
     28    SATURATE = TRUE;
     29    remove_argument (N, &argc, argv);
     30  }
     31  if ((N = get_argument (argc, argv, "-sat"))) {
     32    SATURATE = TRUE;
    1133    remove_argument (N, &argc, argv);
    1234  }
     
    95117    // this algorithm assumes vecy[BinMax] > threshold, vecy[BinMin] < threshold
    96118    if (vecy[0].elements.Flt[BinMin] > value) {
    97       if (!QUIET) gprint (GP_ERR, "ERROR: all values above threshold\n");
    98       set_int_variable ("threshbin", BinMin);
    99       set_variable ("threshval", vecy[0].elements.Flt[BinMin]);
    100       set_variable ("threshold", vecx[0].elements.Flt[BinMin]);
    101       set_int_variable ("thresherr", 1);
    102       if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n",
    103                           vecx[0].elements.Flt[BinMin], BinMin,
    104                           vecy[0].elements.Flt[BinMin]);
    105       return TRUE;
     119      if (SATURATE) {
     120        _threshold_set_values (vecy[0].elements.Flt[BinMin], BinMin, vecx[0].elements.Flt[BinMin], 1);
     121        return TRUE;
     122      } else {
     123        gprint (GP_ERR, "ERROR: all values above threshold\n");
     124        _threshold_set_values (NAN, -1, NAN, 1);
     125        return FALSE;
     126      }
    106127    }
    107128    if (vecy[0].elements.Flt[BinMax] < value) {
    108       if (!QUIET) gprint (GP_ERR, "ERROR: all values below threshold\n");
    109       set_int_variable ("threshbin", BinMax);
    110       set_variable ("threshval", vecy[0].elements.Flt[BinMax]);
    111       set_variable ("threshold", vecx[0].elements.Flt[BinMax]);
    112       set_int_variable ("thresherr", 1);
    113       if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n",
    114                           vecx[0].elements.Flt[BinMax], BinMax,
    115                           vecy[0].elements.Flt[BinMax]);
    116       return TRUE;
     129      if (SATURATE) {
     130        _threshold_set_values (vecy[0].elements.Flt[BinMax], BinMax, vecx[0].elements.Flt[BinMax], 1);
     131        return TRUE;
     132      } else {
     133        gprint (GP_ERR, "ERROR: all values below threshold\n");
     134        _threshold_set_values (NAN, -1, NAN, 1);
     135        return FALSE;
     136      }
    117137    }
    118138    while (Nhi - Nlo > 10) {
     
    136156    // this algorithm assumes vecy[BinMin] > threshold, vecy[BinMax] < threshold
    137157    if (vecy[0].elements.Flt[BinMin] < value) {
    138       if (!QUIET) gprint (GP_ERR, "ERROR: all values below threshold\n");
    139       set_int_variable ("threshbin", BinMin);
    140       set_variable ("threshval", vecy[0].elements.Flt[BinMin]);
    141       set_variable ("threshold", vecx[0].elements.Flt[BinMin]);
    142       set_int_variable ("thresherr", 1);
    143       if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n",
    144                           vecx[0].elements.Flt[BinMin], BinMin,
    145                           vecy[0].elements.Flt[BinMin]);
    146       return TRUE;
     158      if (SATURATE) {
     159        _threshold_set_values (vecy[0].elements.Flt[BinMin], BinMin, vecx[0].elements.Flt[BinMin], 1);
     160        return TRUE;
     161      } else {
     162        gprint (GP_ERR, "ERROR: all values below threshold\n");
     163        _threshold_set_values (NAN, -1, NAN, 1);
     164        return FALSE;
     165      }
    147166    }
    148167    if (vecy[0].elements.Flt[BinMax] > value) {
    149       if (!QUIET) gprint (GP_ERR, "ERROR: all values above threshold\n");
    150       set_int_variable ("threshbin", BinMax);
    151       set_variable ("threshval", vecy[0].elements.Flt[BinMax]);
    152       set_variable ("threshold", vecx[0].elements.Flt[BinMax]);
    153       set_int_variable ("thresherr", 1);
    154       if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n",
    155                           vecx[0].elements.Flt[BinMax], BinMax,
    156                           vecy[0].elements.Flt[BinMax]);
    157       return TRUE;
     168      if (SATURATE) {
     169        _threshold_set_values (vecy[0].elements.Flt[BinMax], BinMax, vecx[0].elements.Flt[BinMax], 1);
     170        return TRUE;
     171      } else {
     172        gprint (GP_ERR, "ERROR: all values above threshold\n");
     173        _threshold_set_values (NAN, -1, NAN, 1);
     174        return FALSE;
     175      }
    158176    }
    159177    while (Nhi - Nlo > 10) {
     
    202220  }
    203221
    204   set_variable ("threshval", y1);
    205   set_variable ("threshold", Xvalue);
    206   set_int_variable ("threshbin", Nhi);
    207   set_int_variable ("thresherr", 0);
    208 
    209   if (!QUIET) gprint (GP_LOG, "theshold %f (bin %d is %f)\n", Xvalue, Nhi, y1);
    210 
     222  _threshold_set_values (y1, Nhi, Xvalue, 0);
    211223  return (TRUE);
    212224}
Note: See TracChangeset for help on using the changeset viewer.