IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 25, 2012, 6:39:11 AM (14 years ago)
Author:
eugene
Message:

add :char type to read vectors (very crude: sets vector to ascii value of first char); update reindex to handle duplicates; add mmatch function (equiv to avmatch)

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

Legend:

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

    r33662 r34461  
    2222
    2323// vector types
    24 enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME};
     24enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
    2525
    2626int read_vectors (int argc, char **argv) {
     
    101101      if (!strcasecmp(ptr, "float")) { coltype[i] = COLTYPE_FLT; }
    102102      if (!strcasecmp(ptr, "int"))   { coltype[i] = COLTYPE_INT; }
     103      if (!strcasecmp(ptr, "char"))  { coltype[i] = COLTYPE_CHAR; }
    103104      if (!strcasecmp(ptr, "time"))  { coltype[i] = COLTYPE_TIME; }
    104105      if (!coltype[i]) goto bad_colname;
     
    143144  NELEM = 1000;
    144145  for (i = 0; i < Nvec; i++) {
    145     if (coltype[i] == COLTYPE_INT) {
     146    if ((coltype[i] == COLTYPE_INT) || (coltype[i] == COLTYPE_CHAR)) {
    146147      ResetVector (vec[i], OPIHI_INT, NELEM);
    147148    } else {
     
    195196      for (i = 0; i < Nvec; i++) {
    196197        int ivalue;
     198        char cvalue;
    197199        double dvalue;
    198200        time_t tvalue;
     
    203205            readStatus = IsCSV ? iparse_csv (&ivalue, col[i], c0) : iparse (&ivalue, col[i], c0);
    204206            vec[i][0].elements.Int[Nelem] = readStatus ? ivalue : 0;
     207            break;
     208          case COLTYPE_CHAR:
     209            readStatus = IsCSV ? charparse_csv (&cvalue, col[i], c0) : charparse (&cvalue, col[i], c0);
     210            vec[i][0].elements.Int[Nelem] = readStatus ? cvalue : 0;
    205211            break;
    206212          case COLTYPE_FLT:
  • trunk/Ohana/src/opihi/cmd.data/reindex.c

    r33662 r34461  
    55int reindex (int argc, char **argv) {
    66 
    7   int  i, Npts, Nmax;
     7  int  i, Nmax, N;
    88  Vector *ivec, *ovec, *xvec;
    99
    1010  ivec = ovec = xvec = NULL;
    11   Npts = 0;
     11  int Npts = 0;
     12
     13  int KEEP_UNMATCH = FALSE;
     14  if ((N = get_argument (argc, argv, "-keep-unmatched"))) {
     15    remove_argument (N, &argc, argv);
     16    KEEP_UNMATCH = TRUE;
     17  }
    1218
    1319  if (argc != 6) goto usage;
     
    2228
    2329  // ovec matches ivec in type and xvec in size (xvec need not have all ivec elements, and may have duplicates
     30  int NPTS = xvec[0].Nelements;
    2431  ResetVector (ovec, ivec->type, xvec[0].Nelements);
    2532
     
    3138    opihi_int *vx = xvec[0].elements.Int;
    3239    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
    33       if (*vx == -1) continue;
    34       if (*vx < 0) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
     40      if (Npts >= NPTS) {
     41        NPTS += 2000;
     42        REALLOCATE (ovec[0].elements.Flt, opihi_flt, NPTS);
     43      }
     44      if (*vx < 0) {
     45        if (KEEP_UNMATCH) {
     46          ovec[0].elements.Flt[Npts] = NAN;
     47          Npts++;
     48        }
     49        continue;
     50      }
    3551      if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
    3652      ovec[0].elements.Flt[Npts] = vi[*vx];
     
    4258    opihi_int *vx = xvec[0].elements.Int;
    4359    for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) {
    44       if (*vx == -1) continue;
    45       if (*vx < 0) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
     60      if (Npts >= NPTS) {
     61        NPTS += 2000;
     62        REALLOCATE (ovec[0].elements.Int, opihi_int, NPTS);
     63      }
     64      if (*vx < 0) {
     65        if (KEEP_UNMATCH) {
     66          ovec[0].elements.Flt[Npts] = -1;
     67          Npts++;
     68        }
     69        continue;
     70      }
    4671      if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
    4772      ovec[0].elements.Int[Npts] = vi[*vx];
     
    6085usage:
    6186    gprint (GP_ERR, "USAGE: reindex (out) = (in) using (index)\n");
    62     gprint (GP_ERR, "  creates a new vectors (out) from (in) based on sequence in (index)\n");
     87    gprint (GP_ERR, "  Creates a new vector (out) from (in) based on sequence in (index)\n");
     88    gprint (GP_ERR, "  output[i] = input[index[i]]\n");
     89    gprint (GP_ERR, "  If -keep-unmatched is provided, elements of index with negative values will be set to NaN / -1,\n");
     90    gprint (GP_ERR, "    otherwise they will be skipped in the output.\n");
     91    gprint (GP_ERR, "  The output vector has the type of the input vector and the length of the index (if -keep-unmatched).\n");
     92    gprint (GP_ERR, "  The index vector may have duplicates\n");
    6393    return (FALSE);
    6494}
  • trunk/Ohana/src/opihi/cmd.data/subset.c

    r30610 r34461  
    1313  Npts = 0;
    1414
     15  if (argc < 6) {
     16    gprint (GP_ERR, "SYNTAX: subset vec = vec [if/where] (logic expression)\n");
     17    return (FALSE);
     18  }
     19
    1520  valid = TRUE;
    16   valid &= (argc >= 6);
    1721  valid &= !strcmp(argv[2], "=");
    1822  valid &= !strcmp(argv[4], "if") || !strcmp (argv[4], "where");
Note: See TracChangeset for help on using the changeset viewer.