[Kst] kdeextragear-2/kst/plugins/syncbin

Barth Netterfield netterfield at astro.utoronto.ca
Mon Jan 10 19:16:10 CET 2005


CVS commit by netterfield: 

Make it work right....


  M +14 -10    syncbin.cpp   1.2
  M +7 -3      syncbin.xml   1.2


--- kdeextragear-2/kst/plugins/syncbin/syncbin.cpp  #1.1:1.2
@@ -15,4 +15,5 @@
  *                                                                         *
  ***************************************************************************/
+#include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -25,8 +26,6 @@ extern "C" int syncbin(const double *con
 // macros to find the top, bottom, and middle of a bin
 #define BINMID(x) XMin+(XMax-XMin)*(double(x)+0.5)/double(nbins)
-#define BINMIN(x) XMin+(XMax-XMin)*(double(x))/double(nbins)
-#define BINMAX(x) XMin+(XMax-XMin)*(double(x)+1.0)/double(nbins)
 
-#define BIN( x ) int( double( nbins )*( x-XMin )/( XMax-XMin ) )
+#define BIN( x ) int(double(nbins)*(x-XMin)/(XMax-XMin))
 
 /***************************************************************************/
@@ -56,5 +55,6 @@ int syncbin(const double *const inArrays
 
   //now set the outputs
-  outArrayLens[0] = outArrayLens[1] = outArrayLens[2] = nbins;
+  outArrayLens[0] = outArrayLens[1] = outArrayLens[2] = 
+    outArrayLens[3] = nbins;
 
   //resize the output arrays
@@ -62,5 +62,5 @@ int syncbin(const double *const inArrays
   outArrays[1]=(double*)realloc(outArrays[1], outArrayLens[1]*sizeof(double));
   outArrays[2]=(double*)realloc(outArrays[2], outArrayLens[2]*sizeof(double));
-  N = (double*)malloc( int( nbins )*sizeof(double));
+  outArrays[3]=(double*)realloc(outArrays[3], outArrayLens[3]*sizeof(double));
 
   // convenience definitions
@@ -71,4 +71,5 @@ int syncbin(const double *const inArrays
   Yout = outArrays[1];
   Yerr = outArrays[2];
+  N    = outArrays[3];
 
   // set/check XMax and XMin
@@ -79,5 +80,10 @@ int syncbin(const double *const inArrays
       if ( XMin<Xin[i] ) XMin = Xin[i];
     }
+    // make sure end points are included.
+    double d = (XMax - XMin)/double(nbins*100.0);
+    XMax+=d;
+    XMin-=d;
   }
+
   if ( XMax == XMin ) { // don't want divide by zero...
     XMax +=1;
@@ -95,6 +101,6 @@ int syncbin(const double *const inArrays
   int bin;
   for ( int i=0; i<n_in; i++ ) {
-    bin = BIN( i );
-    if ( bin>0 && bin<nbins ) {
+    bin = BIN( Xin[i] );
+    if ( (bin>=0) && (bin<nbins) ) {
       Yout[bin]+=Yin[i];
       Yerr[bin]+=Yin[i] * Yin[i];
@@ -111,6 +117,4 @@ int syncbin(const double *const inArrays
   }
 
-  free( N );
-
   return 0;
 }

--- kdeextragear-2/kst/plugins/syncbin/syncbin.xml  #1.1:1.2
@@ -3,5 +3,5 @@
 <module>
 <intro>
-<modulename name="sync"/>    <!-- The name of the module -->
+<modulename name="syncbin"/>    <!-- The name of the module -->
 <author name="Barth Netterfield"/> <!-- The name of the author -->
 <description text="Synchronously coadd vector Y into bins defined by vector X.  Like a 1D map."/>
@@ -14,9 +14,9 @@
 <!--inputs here-->
 <input>
-<table type="float" name="Y in" descr="The data to bin (eg, bolometer)." />
+<table type="float" name="X in" descr="The index data (eg, azimuth)." />
 </input>
 
 <input>
-<table type="float" name="X in" descr="The index data (eg, azimuth)." />
+<table type="float" name="Y in" descr="The data to bin (eg, bolometer)." />
 </input>
 
@@ -46,4 +46,8 @@
 </output>
 
+<output>
+<table type="float" name="N" descr="The number of samples in each bin" />
+</output>
+
 </interface>
 




More information about the Kst mailing list