Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/include/addstar.h
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/include/addstar.h	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/include/addstar.h	(revision 28990)
@@ -209,5 +209,5 @@
 Stars     *ReadStarsSDSS          PROTO((FILE *f, char *name, Header *header, Header *in_theader, Image *images, off_t *nimages, unsigned int *nstars));
 int        ReadImageHeader        PROTO((Header *header, Image *image, int photcode));
-Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID));
+Stars     *FilterStars            PROTO((Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options));
 Stars     *MergeStars             PROTO((Stars *stars, unsigned int *Nstars, Stars *instars, unsigned int Ninstars));
 double     scat_subpix            PROTO((double x, double y));
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ConfigInit.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ConfigInit.c	(revision 28990)
@@ -212,4 +212,10 @@
   }
 
+  /* get detection filtering mask */
+  if(!ScanConfig (config, "DETECTIONFILTER", "%d", 0, &options.detectionFilter)) {
+      options.detectionFilter = 0;
+      fprintf (stderr, "Could not find 'DETECTIONFILTER' in config, using '%x'\n", options.detectionFilter);
+  }
+
   free (config);
   free (file);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/FilterStars.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/FilterStars.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/FilterStars.c	(revision 28990)
@@ -10,5 +10,5 @@
 // the imageID supplied here is the sequence **within this set**
 // this value is updated based on the image table later
-Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID) {
+Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID, const AddstarClientOptions *options) {
 
   int j, N;
@@ -28,4 +28,6 @@
   ALLOCATE (stars, Stars, image[0].nstar);
   for (N = j = 0; j < image[0].nstar; j++) {
+
+    if (instars[j].measure.photFlags & options->detectionFilter) continue;
 
     /* allow for some dynamic filtering of star list */
@@ -100,4 +102,7 @@
     N ++;
   }
+
+  // DEBUG printf("N stars orig = %d after filter = %d\n", image[0].nstar, N);
+  
   image[0].nstar = N;
   REALLOCATE (stars, Stars, image[0].nstar);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c	(revision 28990)
@@ -84,6 +84,5 @@
       continue;
     }
-
-    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid);
+    inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid, options);
     *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
     Nvalid++;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 28990)
@@ -11,4 +11,8 @@
   NAME = (TYPE *) gfits_get_bintable_column_data (table.header, &table, #NAME, type, &Nrow, &Ncol); \
   assert (NAME); assert (!strcmp (type, #TYPE)); assert (Nrow == Nstars); assert (Ncol == NFILTER);
+
+# define GET_COLUMN_5_NOASSERT(NAME,TYPE) \
+  TYPE *NAME; \
+  NAME = (TYPE *) gfits_get_bintable_column_data (table.header, &table, #NAME, type, &Nrow, &Ncol);
 
 # define GET_COLUMN_1(NAME,TYPE) \
@@ -123,5 +127,9 @@
   GET_COLUMN_5 (flags2, int);
 
+#ifdef notyet
   GET_COLUMN_5 (prob_psf, float);
+#else
+  GET_COLUMN_5_NOASSERT (prob_psf, float);
+#endif
 
   GET_COLUMN_1 (ra, double);
@@ -160,8 +168,12 @@
       stars[N].measure.FWx       = ShortPixels(seeing[j]); // reported in arcsec?
       stars[N].measure.FWy       = ShortPixels(seeing[j]);
-      stars[N].measure.psfChisq  = prob_psf[N]; // XXX not really the correct value...
+      if (prob_psf) {
+          stars[N].measure.psfChisq  = prob_psf[N]; // XXX not really the correct value...
+      } else {
+          stars[N].measure.psfChisq  = NAN;
+      }
       stars[N].measure.detID     = N;
       stars[N].measure.t         = tzero[j] + clockRate*rowc[N]; // time since row 0
-      stars[N].measure.dt        = 53.907456; // is this 2048*clockRate ?
+      stars[N].measure.dt        = 4.32912209; // 2.5 * log(53.907456) the sdss exposure time // old comment is 53907456 is this 2048*clockRate ?
 
       SetSDSSFlags (&stars[N], flags[N], flags2[N]);
@@ -182,4 +194,5 @@
       stars[N].measure.az        = az;
       stars[N].measure.photcode  = photcode[j];
+      stars[N].measure.imageID   = j + *nimages; // set imageID to entry for this filter
     }
   }    
@@ -254,4 +267,5 @@
     images[N].externID = 0;
     images[N].sourceID = 0;
+    images[N].parentID = UINT32_MAX; // UpdateImageIDs sets parentID = 0
 
     // save the filename
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches.c	(revision 28990)
@@ -247,10 +247,9 @@
     }
 
-    N = N1[i];
-    if (stars[N].found >= 0) continue;
-    if (!IN_REGION (stars[N].average.R, stars[N].average.D)) continue;
-
-    catalog[0].average[Nave].R         	   = stars[N].average.R;
-    catalog[0].average[Nave].D         	   = stars[N].average.D;
+    if (stars[i].found >= 0) continue;
+    if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
+
+    catalog[0].average[Nave].R         	   = stars[i].average.R;
+    catalog[0].average[Nave].D         	   = stars[i].average.D;
     catalog[0].average[Nave].dR        	   = 0;
     catalog[0].average[Nave].dD        	   = 0;
@@ -303,6 +302,5 @@
     for (j = 0; j < NSTAR_GROUP; j++) {
       // supply the measurments from this detection
-      catalog[0].measure[Nmeas]           = stars[N].measure;
-      N = N1[i + j];
+      catalog[0].measure[Nmeas]           = stars[i + j].measure;
 
       // the following measure elements cannot be set until here:
@@ -322,5 +320,5 @@
       /* next[Nmeas] should always be -1 in this context (it is always the only
          measurement for the star) */
-      stars[N].found = Nmeas;
+      stars[i].found = Nmeas;
       next_meas[Nmeas] = -1;  // initial value here update below
       Nmeas ++;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches_closest.c	(revision 28989)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/find_matches_closest.c	(revision 28990)
@@ -242,10 +242,9 @@
     }
 
-    N = N1[i];
-    if (stars[N].found >= 0) continue;
-    if (!IN_REGION (stars[N].average.R, stars[N].average.D)) continue;
-
-    catalog[0].average[Nave].R         	   = stars[N].average.R;
-    catalog[0].average[Nave].D         	   = stars[N].average.D;
+    if (stars[i].found >= 0) continue;
+    if (!IN_REGION (stars[i].average.R, stars[i].average.D)) continue;
+
+    catalog[0].average[Nave].R         	   = stars[i].average.R;
+    catalog[0].average[Nave].D         	   = stars[i].average.D;
     catalog[0].average[Nave].dR        	   = 0;
     catalog[0].average[Nave].dD        	   = 0;
@@ -297,6 +296,5 @@
     for (j = 0; j < NSTAR_GROUP; j++) {
         // supply the measurments from this detection
-        catalog[0].measure[Nmeas]           = stars[N].measure;
-        N = N1[i + j];
+        catalog[0].measure[Nmeas]           = stars[i + j].measure;
 
         // the following measure elements cannot be set until here:
@@ -316,5 +314,5 @@
         /* next[Nmeas] should always be -1 in this context (it is always the only
            measurement for the star) */
-        stars[N].found = Nmeas;
+        stars[i+j].found = Nmeas;
         next_meas[Nmeas] = -1;  // inital value here update below
         Nmeas ++;
