Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 4537)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 4538)
@@ -102,4 +102,5 @@
 int MODE;
 char *DUMP;
+char *SELECT_2MASS_QUALITY;
 
 time_t TIMEREF;
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 4537)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 4538)
@@ -156,4 +156,11 @@
     remove_argument (N, &argc, argv);
   }
+  /* define 2MASS quality flags to keep */
+  SELECT_2MASS_QUALITY = NULL;
+  if ((N = get_argument (argc, argv, "-2massquality"))) {
+    remove_argument (N, &argc, argv);
+    SELECT_2MASS_QUALITY = strcreate (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
 
   /*** optional situations ***/
@@ -189,4 +196,5 @@
   }
 
+
   if (argc != 2) {
     fprintf (stderr, "USAGE: addstar (filename)\n");
Index: /trunk/Ohana/src/addstar/src/get2mass_as.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 4537)
+++ /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 4538)
@@ -16,7 +16,8 @@
   
   int FilterSkip, TimeSkip, Np;
-  int i, Nstars, NSTARS, Nbyte, Nline, Nextra, code;
+  int i, Nstars, NSTARS, Nbyte, Nline, Nextra, code, Qentry;
   Stars *stars;
   gzFile gf;
+  char qc;
   char *buffer, *filename;
   char *p, *q, *ptr, *end, *tmp;
@@ -38,12 +39,15 @@
       FilterSkip = 6;
       TimeSkip = 23;
+      Qentry   = 0;
   }
   if (thiscode[0].code == TM_H) {
       FilterSkip = 10;
       TimeSkip = 19;
+      Qentry   = 1;
   }
   if (thiscode[0].code == TM_K) {
       FilterSkip = 14;
       TimeSkip = 15;
+      Qentry   = 2;
   }
   if (!FilterSkip) Shutdown ("invalid photcode %d", thiscode[0].code);
@@ -76,5 +80,5 @@
       if (DEC > 90) Shutdown ("weird DEC value: something is wrong");
 
-      /* this test is now wrong */
+      /* skip stars which are outside desired region */
       if (DEC > DEC1) goto skip_star;
       if (DEC < DEC0) goto skip_star;
@@ -88,4 +92,11 @@
       dM = strtod (ptr, NULL);
       time = get2mass_time (ptr, buffer, TimeSkip, Nbyte);
+
+      /* filter on the ph_qual flag for this filter (field 19) */
+      if (SELECT_2MASS_QUALITY != NULL) {
+	ptr = skipNbounds (p, '|', 18, Nbyte - (p - buffer));
+	qc  = ptr[Qentry];
+	if (strchr (SELECT_2MASS_QUALITY, qc) == NULL) goto skip_star;
+      }
 
       stars[Nstars].R     = RA;
