IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42466


Ignore:
Timestamp:
May 24, 2023, 3:31:48 PM (3 years ago)
Author:
eugene
Message:

better usage message for box; allow string vector concat, concat int vector into new vector yields an int vector; option to calculate stdev in medacc; option to set specified blank value for unmatched entries in reindex

Location:
trunk/Ohana/src/opihi/cmd.data
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/box.c

    r41379 r42466  
    305305  gprint (GP_ERR, "        -xfminor, -yfminor, +xfminor, +yfminor\n");
    306306  gprint (GP_ERR, "  \n");
    307   gprint (GP_ERR, "  -dmajor : set the major tixk spacing (all axes)\n");
     307  gprint (GP_ERR, "  -dmajor : set the major tick spacing (all axes)\n");
    308308  gprint (GP_ERR, "         alternatively, set each axis independently with:\n");
    309309  gprint (GP_ERR, "        -xdmajor, -ydmajor, +xdmajor, +ydmajor\n");
     
    312312  gprint (GP_ERR, "         alternatively, set each axis independently with:\n");
    313313  gprint (GP_ERR, "        -xflabel, -yflabel, +xflabel, +yflabel\n");
     314  gprint (GP_ERR, "  \n");
     315  gprint (GP_ERR, "  -format : set the format (C-style) for the tick labels (all axes)\n");
     316  gprint (GP_ERR, "         alternatively, set each axis independently with:\n");
     317  gprint (GP_ERR, "        -xformat, -yformat, +xformat, +yformat\n");
    314318
    315319  return (FALSE);
  • trunk/Ohana/src/opihi/cmd.data/concat.c

    r20936 r42466  
    3232  if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    3333 
    34   // we have 4 cases: (ivec == flt or int) and (ovec == flt or int)
     34  // if the output vector is empty, inherit the type of the input vector
     35  if (!ovec->Nelements) { ResetVector (ovec, ivec->type, ovec->Nelements); }
     36
     37  // we have 3 input and 3 output types : INT, FLT, STR
     38
     39  // both are strings
     40  if ((ovec[0].type == OPIHI_STR) && (ivec[0].type == OPIHI_STR)) {
     41    REALLOCATE (ovec->elements.Str, char *, MAX(1, ovec->Nelements + ivec->Nelements));
     42    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     43      ovec[0].elements.Str[j] = strcreate(ivec[0].elements.Str[i]);
     44    }
     45    goto done;
     46  }
     47
     48  // if only one is a string, raise an error
     49  if ((ovec[0].type == OPIHI_STR) || (ivec[0].type == OPIHI_STR)) {
     50    gprint (GP_ERR, "ERROR: cannot mix string and numerical vectors\n");
     51    return FALSE;
     52  }
     53
     54  // both vectors are floats
    3555  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) {
    3656    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     
    3858      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
    3959    }
     60    goto done;
    4061  }
     62  // both vectors are ints
     63  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) {
     64    REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements);
     65    for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
     66      ovec[0].elements.Int[j] = ivec[0].elements.Int[i];
     67    }
     68    goto done;
     69  }
     70
     71  // if output vector is a float and input is an int, cast the int values to the float
    4172  if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) {
    4273    REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements);
     
    4475      ovec[0].elements.Flt[j] = ivec[0].elements.Int[i];
    4576    }
    46   }
    47   if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) {
    48     REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements);
    49     for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) {
    50       ovec[0].elements.Int[j] = ivec[0].elements.Int[i];
    51     }
     77    goto done;
    5278  }
    5379
     80  // the output vector is an int and input is a float:
    5481  // this case forces ovec to be raised to FLT
    5582  if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) {
     
    6491      ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i];
    6592    }
     93    goto done;
    6694  }
    6795
     96done:
    6897  ovec[0].Nelements += ivec[0].Nelements;
    6998  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/medacc.c

    r42082 r42466  
    88  Vector *val, *key, *out;
    99
     10  Vector *stdev = NULL;
     11  if ((N = get_argument (argc, argv, "-stdev"))) {
     12    remove_argument (N, &argc, argv);
     13    stdev = SelectVector (argv[N], ANYVECTOR, TRUE);
     14    remove_argument (N, &argc, argv);
     15    if (!stdev) {
     16      gprint (GP_ERR, "output vector for standard deviation not found\n");
     17      return (FALSE);
     18    }
     19  }
     20
    1021  if ((argc != 6) && (argc != 7)) {
    1122    gprint (GP_ERR, "USAGE: medacc <value> <vector> <key> start end [delta]\n");
    1223    gprint (GP_ERR, "  value and key are vectors of the same length\n");
    1324    gprint (GP_ERR, "  the output vector bins correspond to values ranging from start to end in steps of delta (default 1)\n");
    14     gprint (GP_ERR, "  for a given output bin, all input values for which the key matches the output bin are averaged\n");
     25    gprint (GP_ERR, "  for a given output bin, all input values for which the key matches the output bin are used to calculate the statistic\n");
     26
     27    gprint (GP_ERR, "  the output is the average of the inner 25%% of data values\n");
     28    gprint (GP_ERR, "  -stdev (outvec) : optionally return the standard deviation, calculated based on the 68%%-ile range\n");
    1529
    1630    return (FALSE);
     
    4357  ResetVector (out, OPIHI_FLT, Nbins);
    4458  bzero (out[0].elements.Flt, sizeof(opihi_flt)*out[0].Nelements);
     59
     60  if (stdev) {
     61    ResetVector (stdev, OPIHI_FLT, Nbins);
     62  }
    4563
    4664  /* copy vec and key to temp vectors */
     
    8098    }
    8199    if (fn > 0) O[i] /= fn;
     100
     101    if (stdev) {
     102      int Nmin = 0.16*N;
     103      int Nmax = 0.84*N;
     104      float Smin = tmpvec[N0 + Nmin];
     105      float Smax = tmpvec[N0 + Nmax];
     106      stdev[0].elements.Flt[i] = 0.5*(Smax - Smin);
     107    }
    82108  }     
    83109 
  • trunk/Ohana/src/opihi/cmd.data/reindex.c

    r42389 r42466  
    1313    remove_argument (N, &argc, argv);
    1414    KEEP_UNMATCH = TRUE;
     15  }
     16
     17  // BLANKVAL is the name of the value to use for unmatched elements
     18  char *BLANKVAL = NULL;
     19  if ((N = get_argument (argc, argv, "-blank")) || (N = get_argument (argc, argv, "-blank-value"))) {
     20    remove_argument (N, &argc, argv);
     21    BLANKVAL = strcreate (argv[N]);
     22    remove_argument (N, &argc, argv);
    1523  }
    1624
     
    3543    opihi_flt *vi = ivec[0].elements.Flt;
    3644    opihi_int *vx = xvec[0].elements.Int;
     45    opihi_flt myBlank = (BLANKVAL == NULL) ? NAN : atof(BLANKVAL);
    3746    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
    3847      if (Npts >= NPTS) {
     
    4251      if (*vx < 0) {
    4352        if (KEEP_UNMATCH) {
    44           ovec[0].elements.Flt[Npts] = NAN;
     53          ovec[0].elements.Flt[Npts] = myBlank;
    4554          Npts++;
    4655        }
     
    5564    opihi_int *vi = ivec[0].elements.Int;
    5665    opihi_int *vx = xvec[0].elements.Int;
     66    opihi_int myBlank = (BLANKVAL == NULL) ? -4096 : atoi(BLANKVAL);
    5767    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
    5868      if (Npts >= NPTS) {
     
    6272      if (*vx < 0) {
    6373        if (KEEP_UNMATCH) {
    64           ovec[0].elements.Int[Npts] = -4096; // XXX use a different or a specified value?
     74          ovec[0].elements.Int[Npts] = myBlank;
    6575          Npts++;
    6676        }
     
    7484  if (ivec->type == OPIHI_STR) {
    7585    opihi_int *vx = xvec[0].elements.Int;
     86    char *myBlank = (BLANKVAL == NULL) ? strcreate ("") : strcreate(BLANKVAL);
    7687    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
    7788      if (Npts >= NPTS) {
     
    90101      Npts++;
    91102    }
     103    FREE (myBlank);
    92104  }
    93105
    94106  // free up unused memory
    95107  ResetVector (ovec, ivec->type, Npts);
     108  FREE (BLANKVAL);
    96109  return (TRUE);
    97110
    98111error:
    99112  DeleteVector (ovec);
     113  FREE (BLANKVAL);
    100114  return (FALSE);
    101115
     
    104118    gprint (GP_ERR, "  Creates a new vector (out) from (in) based on sequence in (index)\n");
    105119    gprint (GP_ERR, "  output[i] = input[index[i]]\n");
    106     gprint (GP_ERR, "  If -keep-unmatched is provided, elements of index with negative values will be set to NaN / -1,\n");
     120    gprint (GP_ERR, "  If -keep-unmatched is provided, elements of index with negative values will be set to NaN / -4096 (or specific value)\n");
    107121    gprint (GP_ERR, "    otherwise they will be skipped in the output.\n");
     122    gprint (GP_ERR, "  If -blank-value is provided, this supplied value will be used for unmatched elements\n");
    108123    gprint (GP_ERR, "  The output vector has the type of the input vector and the length of the index (if -keep-unmatched).\n");
    109124    gprint (GP_ERR, "  The index vector may have duplicates\n");
     125    FREE (BLANKVAL);
    110126    return (FALSE);
    111127}
Note: See TracChangeset for help on using the changeset viewer.