Index: /branches/sj_branches/sj_SDSSaddstar_branch_r23928_20090420/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /branches/sj_branches/sj_SDSSaddstar_branch_r23928_20090420/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 23941)
+++ /branches/sj_branches/sj_SDSSaddstar_branch_r23928_20090420/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 23942)
@@ -4,4 +4,5 @@
 
 # define NFILTER 5
+# define AR_OBJECT_STATUS_OK_RUN 0x10
 # define dCOS(A)   ((double) cos ((double)RAD_DEG*A))
 # define dSIN(A)   ((double) sin ((double)RAD_DEG*A))
@@ -33,5 +34,5 @@
 Stars *ReadStarsSDSS (FILE *f, char *name, Header *header, Header *in_theader, Image *images, int *nimages, unsigned int *nstars) {
 
-  int i, j, N, Nskip, Nstars, camcol;
+  int i, j, N, Nskip, Nstars, Nstars_used, camcol;
   char type[80];
   Header theader;
@@ -146,5 +147,11 @@
   // compensate for the difference.
 
+  Nstars_used = Nstars;
   for (i = 0; i < Nstars; i++) {
+    // Skip objects that are not OK_RUN
+    if ( ((status[i]) & AR_OBJECT_STATUS_OK_RUN) != 0) {
+      Nstars_used--;
+      continue;
+    }
     for (j = 0; j < NFILTER; j++) {
       N = NFILTER*i + j;
@@ -199,4 +206,7 @@
   }
 
+  // Throw away unneeded trailing (I hope) part of Stars
+  REALLOCATE (stars, Stars, NFILTER*Nstars_used);
+
   for (i = 0; i < NFILTER; i++) {
 
@@ -292,5 +302,5 @@
     images[N].flags = 0;
 
-    images[N].nstar = Nstars;
+    images[N].nstar = Nstars_used;
 
     images[N].imageID = N;
@@ -303,5 +313,5 @@
 
   *nimages += NFILTER;
-  *nstars = Nstars*NFILTER;
+  *nstars = Nstars_used*NFILTER;
   return (stars);
 }
