Changeset 42967 for trunk/Ohana/src/opihi/cmd.data/vweave.c
- Timestamp:
- Mar 9, 2026, 11:26:15 AM (4 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/vweave.c
r42946 r42967 6 6 7 7 int i, j, N; 8 Vector *xin, *yin, *xout, *yout; 8 Vector *xin, *yin, *yout; 9 Vector *xminV = NULL, *xmaxV = NULL, *xout = NULL; 9 10 opihi_flt xmin, xmax, Xmin, Xmax; 10 11 … … 22 23 } 23 24 24 if ( argc != 5) {25 if ((argc != 5) && (argc != 6)) { 25 26 gprint (GP_ERR, "USAGE: vweave <xin> <yin> <xout> <yout>\n"); 27 gprint (GP_ERR, " OR: vweave <xin> <yin> <xmin> <xmax> <yout>\n"); 26 28 gprint (GP_ERR, " fully interpolate input bin values into output bins, using fractional input bin contributions\n"); 27 29 gprint (GP_ERR, " by default, yout has the sum of the associated input values\n"); 28 30 gprint (GP_ERR, " use -count to find the fractional input bin contributions\n"); 29 gprint (GP_ERR, " output bin boundaries defined as midpoint of xout values\n"); 31 gprint (GP_ERR, " with a single <xout> vector, output bin boundaries defined as midpoint of xout values\n"); 32 gprint (GP_ERR, " with <xmin> and <xmax>, the output bin boundaries are explicitly provided\n"); 30 33 gprint (GP_ERR, " use -binsize to specify a fixed bin width (<xout> will define the bin center)\n"); 31 34 gprint (GP_ERR, " input values are treated as uniformly spread between midpoints of xin values\n"); … … 38 41 return FALSE; 39 42 } 40 if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 41 if (xout->Nelements < 2) { 42 gprint (GP_ERR, "output vector of length < 2 is invalid\n"); 43 return FALSE; 43 if ((yin = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE); 44 45 int Nout = -1; 46 if (argc == 5) { 47 if ((xout = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 48 if (xout->Nelements < 2) { 49 gprint (GP_ERR, "output vector of length < 2 is invalid\n"); 50 return FALSE; 51 } 52 Nout = xout->Nelements; 53 if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 54 } else { 55 if (!isnan(binsize)) { 56 gprint (GP_ERR, "-binsize is incompatible with <xmin>, <xmax>\n"); 57 return FALSE; 58 } 59 if ((xminV = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE); 60 if (xminV->Nelements < 2) { 61 gprint (GP_ERR, "output vector of length < 2 is invalid\n"); 62 return FALSE; 63 } 64 Nout = xminV->Nelements; 65 if ((xmaxV = SelectVector (argv[4], OLDVECTOR, TRUE)) == NULL) return (FALSE); 66 if (xmaxV->Nelements != Nout) { 67 gprint (GP_ERR, "<xmin> and <xmax> lengths must match\n"); 68 return FALSE; 69 } 70 if ((yout = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE); 44 71 } 45 72 46 if ((yin = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);47 if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);48 49 73 // re-binning creates a float vector 50 ResetVector (yout, OPIHI_FLT, xout[0].Nelements);74 ResetVector (yout, OPIHI_FLT, Nout); 51 75 52 76 // XXX this algorithm is not optimized: full scale of input vector for each output bin 53 77 // could speed up with sorting and pre-defined boundaries 54 for (i = 0; i < xout[0].Nelements; i++) {78 for (i = 0; i < Nout; i++) { 55 79 if (!isnan(binsize)) { 56 80 xmin = xout[0].elements.Flt[i] - 0.5*binsize; 57 81 xmax = xout[0].elements.Flt[i] + 0.5*binsize; 58 82 } else { 59 if (i > 0) { 60 xmin = 0.5*(xout[0].elements.Flt[i] + xout[0].elements.Flt[i-1]); 83 if (xout) { 84 if (i > 0) { 85 xmin = 0.5*(xout[0].elements.Flt[i] + xout[0].elements.Flt[i-1]); 86 } else { 87 xmin = 1.5*xout[0].elements.Flt[i] - 0.5*xout[0].elements.Flt[i+1]; 88 } 89 if (i < xout[0].Nelements - 1) { 90 xmax = 0.5*(xout[0].elements.Flt[i] + xout[0].elements.Flt[i+1]); 91 } else { 92 xmax = 1.5*xout[0].elements.Flt[i] - 0.5*xout[0].elements.Flt[i-1]; 93 } 61 94 } else { 62 xmin = 1.5*xout[0].elements.Flt[i] + 0.5*xout[0].elements.Flt[i+1]; 63 } 64 if (i < xout[0].Nelements - 1) { 65 xmax = 0.5*(xout[0].elements.Flt[i] + xout[0].elements.Flt[i+1]); 66 } else { 67 xmax = 1.5*xout[0].elements.Flt[i] - 0.5*xout[0].elements.Flt[i-1]; 95 xmin = xminV[0].elements.Flt[i]; 96 xmax = xmaxV[0].elements.Flt[i]; 68 97 } 69 98 }
Note:
See TracChangeset
for help on using the changeset viewer.
