Index: trunk/Ohana/src/getstar/src/getstar.c
===================================================================
--- trunk/Ohana/src/getstar/src/getstar.c	(revision 6239)
+++ trunk/Ohana/src/getstar/src/getstar.c	(revision 6812)
@@ -12,4 +12,10 @@
   set_db (&db);
 
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, SKY_DEPTH, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  /* choose elements to load based on options */
+  catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+
   Nstars = 0;
   stars = NULL;
@@ -20,14 +26,25 @@
     case BY_RADIUS:
 
-      /* load corresponding sky regions, associated images */
-      status = dvo_image_lock (&db, ImageCat, 60.0, LCK_SOFT);
-      if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
+      /* load corresponding sky regions */
+      skylist = SkyListByPatch (sky, -1, &REGION);
+      for (i = 0; i < skylist[0].Nregions; i++) {
+	catalog.filename = skylist[0].filename[i];
+	load_pt_catalog (&catalog, skylist[0].regions[i]);
+	unlock_catalog (&catalog);
 
-      skylist = SkyListByPatch (sky, -1, &REGION);
-      overlap = gimages (&db, &image, MOSAIC, &Noverlap);
-      dvo_image_unlock (&db);
+	/* skip empty catalogs */
+	if (catalog.Nave_disk == 0) continue;
+	select_by_region (&output, &catalog, &REGION, 0, 0);
+      }
+      break;
 
+    case BY_IMLIST:
+      /* load image list */
+    case BY_IMAGE:
+
+      # if (0)
+      /* load corresponding sky regions */
+      skylist = SkyListByImage (sky, -1, &image);
       for (i = 0; i < skylist[0].Nregions; i++) {
-	  
 	  catalog.filename = skylist[0].filename[i];
 	  load_pt_catalog (&catalog, skylist[0].regions[i]);
@@ -36,7 +53,7 @@
 	  /* skip empty catalogs */
 	  if (catalog.Nave_disk == 0) continue;
-
-	  stars = find_matches (&catalog, &image, 0, 0, stars, &Nstars);
-
+	  stars = select_by_image (&catalog, &image, 0, 0, stars, &Nstars);
+      }
+      # endif
       break;
 
@@ -45,46 +62,10 @@
       break;
 
-    case BY_IMAGE:
-
-      break;
-
-    case BY_IMLIST:
-
+      /* not implemented */
       break;
   }
 
-  image = gimages (argv[1]);
-
-  region = gregions (&image[0], &Nregions);
-
-  stars = (Stars *) NULL;
-  Nstars = 0;
-
-  for (i = 0; i < Nregions; i++) {
-    if (VERBOSE) fprintf (stderr, "extracting from %s\n", region[i].filename);
-    catalog.filename = region[i].filename;  /* don't free region before catalog! */
-    switch (lock_catalog (&catalog, LCK_SOFT)) {
-    case 0:
-      fprintf (stderr, "ERROR: can't lock file\n");
-      exit (1);
-    case 1:
-      gcatalog (&catalog);
-      break;
-    case 2:
-      fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
-      catalog.Naverage = 0;
-      catalog.Nmeasure = 0;
-      break;
-    default:
-      fprintf (stderr, "weird lock_catalog exit state\n");
-      exit (1);
-    }
-    unlock_catalog (&catalog);
-    stars = find_matches (&catalog, &image[0], 0, 0, stars, &Nstars);
-  }
-
   /* write out the selected stars */
-  clean_stars (stars, &Nstars, image);
-  wstars (argv[2], stars, Nstars, image);
+  wcatalog (argv[2], output);
   fprintf (stderr, "SUCCESS\n");
   exit (0);
