IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42516


Ignore:
Timestamp:
Aug 17, 2023, 4:28:02 PM (3 years ago)
Author:
eugene
Message:

merging from trunk: user-specified blank value in reindex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/Ohana/src/opihi/cmd.data/reindex.c

    r42389 r42516  
    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.