Changeset 42466
- Timestamp:
- May 24, 2023, 3:31:48 PM (3 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/box.c
r41379 r42466 305 305 gprint (GP_ERR, " -xfminor, -yfminor, +xfminor, +yfminor\n"); 306 306 gprint (GP_ERR, " \n"); 307 gprint (GP_ERR, " -dmajor : set the major ti xk spacing (all axes)\n");307 gprint (GP_ERR, " -dmajor : set the major tick spacing (all axes)\n"); 308 308 gprint (GP_ERR, " alternatively, set each axis independently with:\n"); 309 309 gprint (GP_ERR, " -xdmajor, -ydmajor, +xdmajor, +ydmajor\n"); … … 312 312 gprint (GP_ERR, " alternatively, set each axis independently with:\n"); 313 313 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"); 314 318 315 319 return (FALSE); -
trunk/Ohana/src/opihi/cmd.data/concat.c
r20936 r42466 32 32 if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 33 33 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 35 55 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) { 36 56 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); … … 38 58 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 39 59 } 60 goto done; 40 61 } 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 41 72 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) { 42 73 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); … … 44 75 ovec[0].elements.Flt[j] = ivec[0].elements.Int[i]; 45 76 } 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; 52 78 } 53 79 80 // the output vector is an int and input is a float: 54 81 // this case forces ovec to be raised to FLT 55 82 if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) { … … 64 91 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 65 92 } 93 goto done; 66 94 } 67 95 96 done: 68 97 ovec[0].Nelements += ivec[0].Nelements; 69 98 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/medacc.c
r42082 r42466 8 8 Vector *val, *key, *out; 9 9 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 10 21 if ((argc != 6) && (argc != 7)) { 11 22 gprint (GP_ERR, "USAGE: medacc <value> <vector> <key> start end [delta]\n"); 12 23 gprint (GP_ERR, " value and key are vectors of the same length\n"); 13 24 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"); 15 29 16 30 return (FALSE); … … 43 57 ResetVector (out, OPIHI_FLT, Nbins); 44 58 bzero (out[0].elements.Flt, sizeof(opihi_flt)*out[0].Nelements); 59 60 if (stdev) { 61 ResetVector (stdev, OPIHI_FLT, Nbins); 62 } 45 63 46 64 /* copy vec and key to temp vectors */ … … 80 98 } 81 99 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 } 82 108 } 83 109 -
trunk/Ohana/src/opihi/cmd.data/reindex.c
r42389 r42466 13 13 remove_argument (N, &argc, argv); 14 14 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); 15 23 } 16 24 … … 35 43 opihi_flt *vi = ivec[0].elements.Flt; 36 44 opihi_int *vx = xvec[0].elements.Int; 45 opihi_flt myBlank = (BLANKVAL == NULL) ? NAN : atof(BLANKVAL); 37 46 for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) { 38 47 if (Npts >= NPTS) { … … 42 51 if (*vx < 0) { 43 52 if (KEEP_UNMATCH) { 44 ovec[0].elements.Flt[Npts] = NAN;53 ovec[0].elements.Flt[Npts] = myBlank; 45 54 Npts++; 46 55 } … … 55 64 opihi_int *vi = ivec[0].elements.Int; 56 65 opihi_int *vx = xvec[0].elements.Int; 66 opihi_int myBlank = (BLANKVAL == NULL) ? -4096 : atoi(BLANKVAL); 57 67 for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) { 58 68 if (Npts >= NPTS) { … … 62 72 if (*vx < 0) { 63 73 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; 65 75 Npts++; 66 76 } … … 74 84 if (ivec->type == OPIHI_STR) { 75 85 opihi_int *vx = xvec[0].elements.Int; 86 char *myBlank = (BLANKVAL == NULL) ? strcreate ("") : strcreate(BLANKVAL); 76 87 for (Npts = i = 0; i < xvec[0].Nelements; i++, vx++) { 77 88 if (Npts >= NPTS) { … … 90 101 Npts++; 91 102 } 103 FREE (myBlank); 92 104 } 93 105 94 106 // free up unused memory 95 107 ResetVector (ovec, ivec->type, Npts); 108 FREE (BLANKVAL); 96 109 return (TRUE); 97 110 98 111 error: 99 112 DeleteVector (ovec); 113 FREE (BLANKVAL); 100 114 return (FALSE); 101 115 … … 104 118 gprint (GP_ERR, " Creates a new vector (out) from (in) based on sequence in (index)\n"); 105 119 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"); 107 121 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"); 108 123 gprint (GP_ERR, " The output vector has the type of the input vector and the length of the index (if -keep-unmatched).\n"); 109 124 gprint (GP_ERR, " The index vector may have duplicates\n"); 125 FREE (BLANKVAL); 110 126 return (FALSE); 111 127 }
Note:
See TracChangeset
for help on using the changeset viewer.
