Changeset 33963 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- May 30, 2012, 1:46:12 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
-
. (modified) (1 prop)
-
Ohana/src/opihi/cmd.data/dot.c (modified) (2 diffs)
-
Ohana/src/opihi/cmd.data/gridify.c (modified) (6 diffs)
-
Ohana/src/opihi/cmd.data/match2d.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.data/threshold.c (modified) (2 diffs)
-
Ohana/src/opihi/cmd.data/vgroup.c (modified) (4 diffs)
-
Ohana/src/opihi/cmd.data/vstats.c (modified) (1 diff)
-
Ohana/src/opihi/cmd.data/write_vectors.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
trunk/Ohana/src/opihi/cmd.data/dot.c
r14181 r33963 3 3 int dot (int argc, char **argv) { 4 4 5 int kapa ;5 int kapa, N; 6 6 Graphdata graphmode; 7 7 float x, y; 8 8 9 9 if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE; 10 11 /* FracPositions uses coordinates of 0-1 relative to axis range */ 12 int FracPositions = FALSE; 13 if ((N = get_argument (argc, argv, "-frac"))) { 14 remove_argument (N, &argc, argv); 15 FracPositions = TRUE; 16 } 10 17 11 18 if (argc != 3) { … … 15 22 x = atof(argv[1]); 16 23 y = atof(argv[2]); 24 25 if (FracPositions) { 26 x = x * (graphmode.xmax - graphmode.xmin) + graphmode.xmin; 27 y = y * (graphmode.ymax - graphmode.ymin) + graphmode.ymin; 28 } 17 29 18 30 /* set point style and errorbar mode (these are NOT sticky) */ -
trunk/Ohana/src/opihi/cmd.data/gridify.c
r31450 r33963 5 5 int i, Nx, Ny, Xb, Yb, Normalize, N; 6 6 float Xmin, Xmax, dX, Ymin, Ymax, dY, initValue; 7 float *buf, *val ;7 float *buf, *val, *cnt; 8 8 int *Nval; 9 Buffer *bf;10 9 Vector *vx, *vy, *vz; 11 10 opihi_flt *x, *y, *z; 11 12 Buffer *bf = NULL; 13 Buffer *ct = NULL; 12 14 13 15 Normalize = TRUE; … … 15 17 remove_argument (N, &argc, argv); 16 18 Normalize = FALSE; 19 if ((ct = SelectBuffer (argv[N], ANYBUFFER, TRUE)) == NULL) return (FALSE); 20 remove_argument (N, &argc, argv); 17 21 } 18 22 … … 24 28 } 25 29 26 if (argc != 11) { 27 gprint (GP_ERR, "USAGE: gridify x y z buffer Xmin Xmax dX Ymin Ymax dY\n"); 30 Xmin = Xmax = dX = NAN; 31 if ((N = get_argument (argc, argv, "-x"))) { 32 remove_argument (N, &argc, argv); 33 Xmin = atof (argv[N]); 34 remove_argument (N, &argc, argv); 35 Xmax = atof (argv[N]); 36 remove_argument (N, &argc, argv); 37 dX = atof (argv[N]); 38 remove_argument (N, &argc, argv); 39 } 40 41 Ymin = Ymax = dY = NAN; 42 if ((N = get_argument (argc, argv, "-y"))) { 43 remove_argument (N, &argc, argv); 44 Ymin = atof (argv[N]); 45 remove_argument (N, &argc, argv); 46 Ymax = atof (argv[N]); 47 remove_argument (N, &argc, argv); 48 dY = atof (argv[N]); 49 remove_argument (N, &argc, argv); 50 } 51 52 if (argc != 5) { 53 gprint (GP_ERR, "USAGE: gridify x y z buffer [-x Xmin Xmax dX] [-y Ymin Ymax dY] [-init-value value] [-raw]\n"); 28 54 return (FALSE); 29 55 } … … 41 67 REQUIRE_VECTOR_FLT (vz, FALSE); 42 68 43 Xmin = atof (argv[5]); 44 Xmax = atof (argv[6]); 45 dX = atof (argv[7]); 69 if (isnan(dX)) { 70 Xmin = 0; 71 Xmax = bf[0].matrix.Naxis[0]; 72 dX = 1; 73 } 46 74 47 Ymin = atof (argv[8]); 48 Ymax = atof (argv[9]); 49 dY = atof (argv[10]); 75 if (isnan(dY)) { 76 Ymin = 0; 77 Ymax = bf[0].matrix.Naxis[1]; 78 dY = 1; 79 } 50 80 51 Nx = (Xmax - Xmin) / dX + 1;52 Ny = (Ymax - Ymin) / dY + 1;81 Nx = (Xmax - Xmin) / dX; 82 Ny = (Ymax - Ymin) / dY; 53 83 54 gfits_free_matrix (&bf[0].matrix); 55 gfits_free_header (&bf[0].header); 56 CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0); 57 strcpy (bf[0].file, "(empty)"); 84 if ((Nx != bf[0].matrix.Naxis[0]) || (Ny != bf[0].matrix.Naxis[1])) { 85 gfits_free_matrix (&bf[0].matrix); 86 gfits_free_header (&bf[0].header); 87 CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0); 88 strcpy (bf[0].file, "(empty)"); 89 } 58 90 59 91 ALLOCATE (val, float, Nx*Ny); … … 68 100 Xb = (*x - Xmin) / dX; 69 101 Yb = (*y - Ymin) / dY; 102 if (Xb < 0) continue; 103 if (Yb < 0) continue; 70 104 if (Xb >= Nx) continue; 71 105 if (Yb >= Ny) continue; … … 74 108 } 75 109 110 if (!Normalize) { 111 gfits_free_matrix (&ct[0].matrix); 112 gfits_free_header (&ct[0].header); 113 CreateBuffer (ct, Nx, Ny, -32, 0.0, 1.0); 114 strcpy (ct[0].file, "(empty)"); 115 116 buf = (float *) bf[0].matrix.buffer; 117 cnt = (float *) ct[0].matrix.buffer; 118 for (i = 0; i < Nx*Ny; i++) { 119 if (Nval[i] == 0) continue; 120 buf[i] = val[i]; 121 cnt[i] = Nval[i]; 122 } 123 free (val); 124 free (Nval); 125 return TRUE; 126 } 127 76 128 buf = (float *) bf[0].matrix.buffer; 77 129 for (i = 0; i < Nx*Ny; i++) { 78 130 buf[i] = initValue; 79 if (Normalize) { 80 if (Nval[i] == 0) { 81 continue; 82 } 83 buf[i] = val[i] / Nval[i]; 84 } else { 85 buf[i] = val[i]; 86 } 131 if (Nval[i] == 0) continue; 132 buf[i] = val[i] / Nval[i]; 87 133 } 88 134 -
trunk/Ohana/src/opihi/cmd.data/match2d.c
r30610 r33963 167 167 NMATCH = X1->Nelements; 168 168 ResetVector (index, OPIHI_INT, NMATCH); 169 170 for (i = 0; i < index->Nelements; i++) { index->elements.Int[i] = -1; } 169 171 170 172 ALLOCATE (N1, off_t, X1->Nelements); -
trunk/Ohana/src/opihi/cmd.data/threshold.c
r33662 r33963 69 69 x0 = isFltX ? vecx[0].elements.Flt[Nhi] : vecy[0].elements.Int[Nhi]; 70 70 x1 = isFltX ? vecx[0].elements.Flt[Nhi+1] : vecy[0].elements.Int[Nhi+1]; 71 Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0; 71 if (y0 == y1) { 72 Xvalue = 0.5*(x0 + x1); 73 } else { 74 Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0; 75 } 72 76 } else { 73 77 // interpolate to value: … … 76 80 x0 = isFltX ? vecx[0].elements.Flt[Nhi-1] : vecy[0].elements.Int[Nhi-1]; 77 81 x1 = isFltX ? vecx[0].elements.Flt[Nhi] : vecy[0].elements.Int[Nhi]; 78 Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0; 82 if (y0 == y1) { 83 Xvalue = 0.5*(x0 + x1); 84 } else { 85 Xvalue = (value - y0) * (x1 - x0) / (y1 - y0) + x0; 86 } 79 87 } 80 88 -
trunk/Ohana/src/opihi/cmd.data/vgroup.c
r25757 r33963 1 1 # include "data.h" 2 3 enum {USE_MEDIAN, USE_COUNT, USE_SUM, USE_MEAN}; 2 4 3 5 int vgroup (int argc, char **argv) { … … 23 25 // } 24 26 27 int mode = USE_MEDIAN; 28 if ((N = get_argument (argc, argv, "-sum"))) { 29 remove_argument (N, &argc, argv); 30 mode = USE_SUM; 31 } 32 if ((N = get_argument (argc, argv, "-mean"))) { 33 remove_argument (N, &argc, argv); 34 mode = USE_MEAN; 35 } 36 37 float binsize = NAN; 38 if ((N = get_argument (argc, argv, "-binsize"))) { 39 remove_argument (N, &argc, argv); 40 binsize = atof(argv[N]); 41 remove_argument (N, &argc, argv); 42 } 43 25 44 if (argc != 5) { 26 gprint (GP_ERR, "USAGE: v bin<xin> <yin> <xout> <yout>\n");45 gprint (GP_ERR, "USAGE: vgroup <xin> <yin> <xout> <yout>\n"); 27 46 gprint (GP_ERR, " group x,y values in bins defined by <xout>\n"); 47 gprint (GP_ERR, " by default, yout has the median of the associated input values\n"); 48 gprint (GP_ERR, " use -sum to add values in the bin\n"); 49 gprint (GP_ERR, " use <yin> = histogram count matching values\n"); 50 gprint (GP_ERR, " use -binsize to specify a fixed bin width (<xout> will define the bin center)\n"); 28 51 return (FALSE); 29 52 } 30 53 31 54 if ((xin = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 32 if ((yin = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);33 55 if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 34 56 if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 57 yin = NULL; 58 59 // this should conflict with the -sum option... 60 if (!strcmp(argv[2], "histogram")) { 61 mode = USE_COUNT; 62 } else { 63 if ((yin = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE); 64 } 35 65 36 66 // re-binning creates a float vector … … 41 71 42 72 for (i = 0; i < xout[0].Nelements - 1; i++) { 43 xmin = xout[0].elements.Flt[i]; 44 xmax = xout[0].elements.Flt[i+1]; 73 if (isnan(binsize)) { 74 xmin = xout[0].elements.Flt[i]; 75 xmax = xout[0].elements.Flt[i+1]; 76 } else { 77 xmin = xout[0].elements.Flt[i] - 0.5*binsize; 78 xmax = xout[0].elements.Flt[i] + 0.5*binsize; 79 } 45 80 46 81 N = 0; … … 48 83 if (xin[0].elements.Flt[j] < xmin) continue; 49 84 if (xin[0].elements.Flt[j] > xmax) continue; 50 values[N] = yin[0].elements.Flt[j]; 85 if (yin) { 86 values[N] = yin[0].elements.Flt[j]; 87 } 51 88 N++; 52 89 } 53 90 54 dsort (values, N); 55 if (N > 1) { 56 sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]); 57 } else { 58 sum = values[0]; 91 sum = NAN; 92 switch (mode) { 93 case USE_MEDIAN: 94 dsort (values, N); 95 if (N > 1) { 96 sum = (N % 2) ? values[(int)(0.5*N)] : 0.5*(values[N/2] + values[N/2 + 1]); 97 } else { 98 sum = values[0]; 99 } 100 break; 101 102 case USE_SUM: 103 sum = 0.0; 104 for (j = 0; j < N; j++) { 105 sum += values[j]; 106 } 107 break; 108 109 case USE_COUNT: 110 sum = N; 111 break; 112 113 case USE_MEAN: 114 sum = 0.0; 115 for (j = 0; j < N; j++) { 116 sum += values[j]; 117 } 118 sum /= N; 119 break; 59 120 } 60 61 // measure the stat for this bin62 // sum = 0.0;63 // for (j = 0; j < N; j++) {64 // sum += values[j];65 // }66 // sum /= N;67 121 yout[0].elements.Flt[i] = sum; 68 122 } -
trunk/Ohana/src/opihi/cmd.data/vstats.c
r32632 r33963 144 144 } 145 145 } 146 stdev = sqrt (var / N);146 stdev = sqrt (var / (N - 1)); 147 147 148 148 Nmode = 0; -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r33662 r33963 21 21 FITS = NULL; 22 22 if ((N = get_argument (argc, argv, "-fits"))) { 23 if (format) { 24 gprint (GP_ERR, "ERROR: do not mix -fits and -format\n"); 25 free (format); 26 return (FALSE); 27 } 23 28 remove_argument (N, &argc, argv); 24 29 FITS = strcreate (argv[N]); 25 30 remove_argument (N, &argc, argv); 31 } 32 33 /* option generate a FITS output table */ 34 int CSV = FALSE; 35 if ((N = get_argument (argc, argv, "-csv"))) { 36 if (format) { 37 gprint (GP_ERR, "ERROR: do not mix -csv and -format\n"); 38 free (format); 39 return (FALSE); 40 } 41 if (FITS) { 42 gprint (GP_ERR, "ERROR: do not mix -csv and -fits\n"); 43 free (FITS); 44 return (FALSE); 45 } 46 remove_argument (N, &argc, argv); 47 CSV = TRUE; 26 48 } 27 49 … … 30 52 remove_argument (N, &argc, argv); 31 53 append = TRUE; 54 } 55 56 int ADD_HEADER = FALSE; 57 if ((N = get_argument (argc, argv, "-header"))) { 58 remove_argument (N, &argc, argv); 59 ADD_HEADER = TRUE; 32 60 } 33 61 … … 83 111 84 112 /* default output format */ 113 if (ADD_HEADER) { 114 for (j = 0; j < Nvec; j++) { 115 if (CSV) { 116 fprintf (f, "%s,", vec[j][0].name); 117 } else { 118 if (j == 0) fprintf (f, "# "); 119 fprintf (f, "%s ", vec[j][0].name); 120 } 121 } 122 fprintf (f, "\n"); 123 } 124 125 /* default output format */ 85 126 if (format == (char *) NULL) { 86 127 for (i = 0; i < vec[0][0].Nelements; i++) { 87 128 for (j = 0; j < Nvec; j++) { 88 129 if (vec[j][0].type == OPIHI_FLT) { 89 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 130 if (CSV) { 131 fprintf (f, "%.12g,", vec[j][0].elements.Flt[i]); 132 } else { 133 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 134 } 90 135 } else { 91 fprintf (f, "%d ", vec[j][0].elements.Int[i]); 136 if (CSV) { 137 fprintf (f, "%d,", vec[j][0].elements.Int[i]); 138 } else { 139 fprintf (f, "%d ", vec[j][0].elements.Int[i]); 140 } 92 141 } 93 142 }
Note:
See TracChangeset
for help on using the changeset viewer.
