[Kst] kdeextragear-2/kst/plugins/syncbin
Barth Netterfield
netterfield at astro.utoronto.ca
Wed Jan 19 21:00:41 CET 2005
CVS commit by netterfield:
Fix error bars
M +28 -6 syncbin.cpp 1.3
--- kdeextragear-2/kst/plugins/syncbin/syncbin.cpp #1.2:1.3
@@ -99,11 +99,33 @@ int syncbin(const double *const inArrays
//bin the data
- int bin;
+ int bin, last_bin=-1;
+ int last_N=0;
+ double last_sY=0;
+
for ( int i=0; i<n_in; i++ ) {
bin = BIN( Xin[i] );
- if ( (bin>=0) && (bin<nbins) ) {
- Yout[bin]+=Yin[i];
- Yerr[bin]+=Yin[i] * Yin[i];
- N[bin]++;
+ if (bin == last_bin) {
+ last_sY += Yin[i];
+ last_N++;
+ } else { // new bin
+ if (last_N>0) {
+ last_sY/=last_N;
+ if ( (last_bin>=0) && (last_bin<nbins) ) {
+ Yout[last_bin]+=last_sY;
+ Yerr[last_bin]+=last_sY*last_sY;
+ N[last_bin]++;
+ }
+ }
+ last_sY = Yin[i];
+ last_N = 1;
+ last_bin = bin;
+ }
+ }
+ if (last_N>0) {
+ last_sY/=last_N;
+ if ( (last_bin>=0) && (last_bin<nbins) ) {
+ Yout[last_bin]+=last_sY;
+ Yerr[last_bin]+=last_sY*last_sY;
+ N[last_bin]++;
}
}
More information about the Kst
mailing list