Index: trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c
===================================================================
--- trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 17196)
+++ trunk/Ohana/src/addstar/src/load2mass_as_rawdata.c	(revision 17197)
@@ -95,4 +95,6 @@
     if (VERBOSE) fprintf (stderr, "scan %d stars (%10.6f - %10.6f, %10.6f - %10.6f) .. ", Ntstars, Rmin, Rmax, Dmin, Dmax);
 
+    // sort the tstars by RA
+    get2mass_sortStars (tstars, Ntstars);
 
     // scan through the stars, loading the containing catalogs
@@ -101,9 +103,15 @@
       if (tstars[i].flag) continue;
 
+      // scan forward until we read the UserPatch
+      if (tstars[i].R < UserPatch.Rmin) continue;
+      if (tstars[i].R > UserPatch.Rmax) break;
+      if (tstars[i].D < UserPatch.Dmin) continue;
+      if (tstars[i].D > UserPatch.Dmax) continue;
+
       // collect stars in a new output catalog
       Nstars = 0;
       NSTARS = 3000;
       ALLOCATE (stars, Stars, NSTARS);
-	
+
       // identify the relevant catalog
       skylist = SkyRegionByPoint (skytable, -1, tstars[i].R, tstars[i].D);
@@ -116,5 +124,5 @@
 	// check if in skyregion
 	if (tstars[j].R < region[0].Rmin) continue;
-	if (tstars[j].R > region[0].Rmax) continue;
+	if (tstars[j].R > region[0].Rmax) break;
 	if (tstars[j].D < region[0].Dmin) continue;
 	if (tstars[j].D > region[0].Dmax) continue;
@@ -122,5 +130,5 @@
 	// check if in UserPatch
 	if (tstars[j].R < UserPatch.Rmin) continue;
-	if (tstars[j].R > UserPatch.Rmax) continue;
+	if (tstars[j].R > UserPatch.Rmax) break;
 	if (tstars[j].D < UserPatch.Dmin) continue;
 	if (tstars[j].D > UserPatch.Dmax) continue;
