Changeset 34461 for trunk/Ohana/src/opihi/cmd.data/reindex.c
- Timestamp:
- Sep 25, 2012, 6:39:11 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/reindex.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/reindex.c
r33662 r34461 5 5 int reindex (int argc, char **argv) { 6 6 7 int i, N pts, Nmax;7 int i, Nmax, N; 8 8 Vector *ivec, *ovec, *xvec; 9 9 10 10 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 } 12 18 13 19 if (argc != 6) goto usage; … … 22 28 23 29 // 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; 24 31 ResetVector (ovec, ivec->type, xvec[0].Nelements); 25 32 … … 31 38 opihi_int *vx = xvec[0].elements.Int; 32 39 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 } 35 51 if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i); 36 52 ovec[0].elements.Flt[Npts] = vi[*vx]; … … 42 58 opihi_int *vx = xvec[0].elements.Int; 43 59 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 } 46 71 if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i); 47 72 ovec[0].elements.Int[Npts] = vi[*vx]; … … 60 85 usage: 61 86 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"); 63 93 return (FALSE); 64 94 }
Note:
See TracChangeset
for help on using the changeset viewer.
