Index: /trunk/Ohana/src/addstar/Makefile
===================================================================
--- /trunk/Ohana/src/addstar/Makefile	(revision 5442)
+++ /trunk/Ohana/src/addstar/Makefile	(revision 5443)
@@ -44,8 +44,4 @@
 $(SRC)/greference.$(ARCH).o \
 $(SRC)/grefstars.$(ARCH).o \
-$(SRC)/gregion_image.$(ARCH).o \
-$(SRC)/gregion_match.$(ARCH).o \
-$(SRC)/gregion_patch.$(ARCH).o \
-$(SRC)/gregion_star.$(ARCH).o \
 $(SRC)/gstars.$(ARCH).o \
 $(SRC)/image-db.$(ARCH).o \
@@ -56,5 +52,4 @@
 $(SRC)/opening_angle.$(ARCH).o \
 $(SRC)/parse_time.$(ARCH).o \
-$(SRC)/RegionOps.$(ARCH).o \
 $(SRC)/replace_match.$(ARCH).o \
 $(SRC)/SetSignals.$(ARCH).o \
@@ -63,6 +58,15 @@
 $(SRC)/wcatalog.$(ARCH).o \
 $(SRC)/Shutdown.$(ARCH).o \
+$(SRC)/SkyRegionUtils.$(ARCH).o \
+$(SRC)/SkyListForStars.$(ARCH).o \
 $(SRC)/rfits.$(ARCH).o \
 $(SRC)/rtext.$(ARCH).o
+
+GSC-OPS = \
+$(SRC)/RegionOps.$(ARCH).o \
+$(SRC)/gregion_image.$(ARCH).o \
+$(SRC)/gregion_match.$(ARCH).o \
+$(SRC)/gregion_patch.$(ARCH).o \
+$(SRC)/gregion_star.$(ARCH).o
 
 MKACC-2MASS = \
Index: /trunk/Ohana/src/addstar/include/2mass.h
===================================================================
--- /trunk/Ohana/src/addstar/include/2mass.h	(revision 5442)
+++ /trunk/Ohana/src/addstar/include/2mass.h	(revision 5443)
@@ -9,5 +9,5 @@
 short TM_J, TM_H, TM_K;
 
-GSCRegion *get2mass_acc (GSCRegion *patch, int *nfiles, char *path, char *accel);
-Stars *get2mass_2DR_data (GSCRegion *region, GSCRegion *patch, int photcode, int *nstars);
-Stars *get2mass_AS_data (GSCRegion *region, GSCRegion *patch, int phocode, int *nstars);
+SkyTable *get2mass_acc (SkyRegion *patch, char *path, char *accel);
+Stars *get2mass_2DR_data (SkyRegion *region, SkyRegion *patch, int photcode, int *nstars);
+Stars *get2mass_AS_data (SkyRegion *region, SkyRegion *patch, int phocode, int *nstars);
Index: /trunk/Ohana/src/addstar/include/addstar.h
===================================================================
--- /trunk/Ohana/src/addstar/include/addstar.h	(revision 5442)
+++ /trunk/Ohana/src/addstar/include/addstar.h	(revision 5443)
@@ -11,6 +11,6 @@
 /* used in find_matches, find_matches_refstars */
 # define IN_CATALOG(R,D) ( \
-((D) >= region[0].DEC[0]) && ((D) < region[0].DEC[1]) && \
-((R) >= region[0].RA[0])  && ((R) < region[0].RA[1]))
+((D) >= region[0].Dmin) && ((D) < region[0].Dmax) && \
+((R) >= region[0].Rmin)  && ((R) < region[0].Rmax))
 
 /* grab named photcode */
@@ -39,4 +39,5 @@
 char   HOSTNAME[80];
 int    NVALID, *VALID_IP;
+int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
 
 /* used to select entries from header (gstars or parse_time) (KEEP) */
@@ -79,5 +80,5 @@
 /* these depend on HOW we implement the client/server interaction for CAT/REF modes */
 time_t    TIMEREF;    // used by MODE REF
-GSCRegion UserPatch;  // used by MODE CAT
+SkyRegion UserPatch;  // used by MODE CAT
 char     *SELECT_2MASS_QUALITY;  // used only by get2mass_as
 
@@ -86,11 +87,6 @@
 AddstarClientOptions ConfigInit   PROTO((int *argc, char **argv));
 void       FindCalibration        PROTO((Image *image));
-int        FindDecBand            PROTO((double dec, double *DEC0, double *DEC1));
-int        FindRegionByPoint      PROTO((GSCRegion *regions, double ra, double dec, GSCRegion *gsc, int Ngsc));
-int        FindRegionDecBandStart PROTO((GSCRegion *region, int Nregion, double dec));
-int        FindRegionDecBandStop  PROTO((GSCRegion *region, int Nregion, double dec));
 FILE      *GetDB                  PROTO((int *state));
 void       InitCalibration        PROTO(());
-GSCRegion *LoadRegions            PROTO((int *nregions));
 void       SaveCalibration        PROTO((float M, float dM, float Mr, float dMr, float Mc, float A, int N));
 void       SetProtect             PROTO((int mode));
@@ -100,31 +96,24 @@
 float      airmass                PROTO((float secz_image, double ra, double dec, double st, double latitude));
 void       SetAirmassQuality      PROTO((int quality));
-void       aregion                PROTO((GSCRegion *region, FILE *f, double ra, double dec));
 AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
 void       check_permissions      PROTO((char *basefile));
 int        dump_rawstars          PROTO((Stars *stars, int Nstars));
 int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
-void       find_matches           PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options));
-void       find_matches_closest   PROTO((GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options));
-void       find_matches_refstars  PROTO((GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
-Stars    **find_subset            PROTO((GSCRegion *region, Stars *stars, int Nstars, int *NSTARS));
+void       find_matches           PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options));
+void       find_matches_closest   PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options));
+void       find_matches_refstars  PROTO((SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
+Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, int Nstars, int *NSTARS));
 int        gcatalog               PROTO((Catalog *catalog));
-Stars     *get2mass               PROTO((GSCRegion *patch, int photcode, int mode, int *NSTARS));
+Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, int *NSTARS));
 double     get_subpix             PROTO((double x, double y));
-Stars     *getgsc                 PROTO((GSCRegion *patch, int *NSTARS));
-Stars     *getusno                PROTO((GSCRegion *catstats, int photcode, int *Nstars));
+Stars     *getgsc                 PROTO((SkyRegion *patch, int *NSTARS));
+Stars     *getusno                PROTO((SkyRegion *catstats, int photcode, int *Nstars));
 Image     *gimages                PROTO((FITS_DB *db, Image *image, Coords *mosaic, int *Npimage));
-Stars     *grefcat                PROTO((char *Refcat, GSCRegion *catstats, int photcode, int *nstars));
+Stars     *grefcat                PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
 Stars     *grefstars              PROTO((char *file, int photcode, int *Nstars));
-GSCRegion *gregion_image          PROTO((Image *image, Coords *mosaic, int *Nregions));
-GSCRegion *gregion_match          PROTO((GSCRegion *regions, int *nregions));
-GSCRegion *gregion_patch          PROTO((GSCRegion *patch, int *nregions));
-void       gregion_star           PROTO((Stars *star, GSCRegion *region));
-GSCRegion *gregion_stars          PROTO((Stars *stars, int Nstars, int *Nregion));
-GSCRegion *gregions               PROTO((Image *image, int *Nregions));
 Stars     *gstars                 PROTO((char *file, int *NSTARS, int photcode, Image *image));
 void       help                   PROTO(());
 int        in_image               PROTO((double r, double d, Image *image));
-int        load_pt_catalog        PROTO((Catalog *catalog, GSCRegion *region));  /*** choose new name ***/
+int        load_pt_catalog        PROTO((Catalog *catalog, SkyRegion *region));  /*** choose new name ***/
 void       load_subpix            PROTO(());
 void       lock_image_db          PROTO((FITS_DB *db, char *filename));
@@ -132,5 +121,5 @@
 void       make_backup            PROTO((char *filename));
 int        match_refstars         PROTO((Stars *stars, int Nstars));
-void       mkcatalog              PROTO((GSCRegion *region, Catalog *catalog));
+void       mkcatalog              PROTO((SkyRegion *region, Catalog *catalog));
 double     opening_angle          PROTO((double x1, double y1, double x2, double y2, double x3, double y3));
 int        parse_time             PROTO((Header *header));
@@ -165,4 +154,17 @@
 Missing *sort_missing (Average *average, int Naverage, Missing *missing, int Nmissing, int *next_miss);
 
+GSCRegion *LoadRegions            PROTO((int *nregions));
+int        FindDecBand            PROTO((double dec, double *DEC0, double *DEC1));
+int        FindRegionByPoint      PROTO((GSCRegion *regions, double ra, double dec, GSCRegion *gsc, int Ngsc));
+int        FindRegionDecBandStart PROTO((GSCRegion *region, int Nregion, double dec));
+int        FindRegionDecBandStop  PROTO((GSCRegion *region, int Nregion, double dec));
+void       aregion                PROTO((GSCRegion *region, FILE *f, double ra, double dec));
+GSCRegion *gregion_image          PROTO((Image *image, Coords *mosaic, int *Nregions));
+GSCRegion *gregion_match          PROTO((GSCRegion *regions, int *nregions));
+GSCRegion *gregion_patch          PROTO((GSCRegion *patch, int *nregions));
+void       gregion_star           PROTO((Stars *star, GSCRegion *region));
+GSCRegion *gregion_stars          PROTO((Stars *stars, int Nstars, int *Nregion));
+GSCRegion *gregions               PROTO((Image *image, int *Nregions));
+
 /** 
   there is an inconsistency to be resolved: fixed structures (like Image)
@@ -192,2 +194,6 @@
 int UpdateDatabase_Reflist (AddstarClientOptions *options, Stars *stars, int Nstars);
 int UpdateDatabase_Refcat (AddstarClientOptions *options, GSCRegion *UserPatch, char *refcat);
+
+SkyList *SkyListForStars (SkyTable *table, int depth, Stars *stars, int Nstars);
+SkyList *SkyListExistingSubset (SkyList *input);
+int SkyListSetPath (SkyList *list, char *path);
Index: /trunk/Ohana/src/addstar/src/ConfigInit.c
===================================================================
--- /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/ConfigInit.c	(revision 5443)
@@ -56,4 +56,7 @@
   ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
   ScanConfig (config, "PHOTCODE_FILE",          "%s",  0, PhotCodeFile);
+  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
+    SKY_DEPTH = 2;
+  }
 
   /* used by client/server setup */
Index: /trunk/Ohana/src/addstar/src/SkyListForStars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 5443)
+++ /trunk/Ohana/src/addstar/src/SkyListForStars.c	(revision 5443)
@@ -0,0 +1,49 @@
+# include "addstar.h"
+
+SkyList *SkyListForStars (SkyTable *table, int depth, Stars *stars, int Nstars) {
+  
+  int i, j, Nr, NR;
+  SkyRegion *region;
+  SkyList *list;
+  
+  Nr = 0;
+  NR = 10;
+  ALLOCATE (list, SkyList, 1);
+  ALLOCATE (list[0].regions,  SkyRegion *, NR);
+  list[0].Nregions = Nr;
+
+  sort_stars (stars, Nstars); /* sort by RA */
+  for (i = 0; i < Nstars; i++) {
+    if (stars[i].found) continue;
+    region = SkyRegionByPoint (table, depth, stars[i].R, stars[i].D);
+    stars[i].found = TRUE;
+    /* search forward for all contained stars */
+    for (j = i; j < Nstars; j++) {
+      if (stars[j].R >= region[0].Rmax) break;
+      if (stars[j].D <  region[0].Dmin) continue;
+      if (stars[j].D >= region[0].Dmax) continue;
+      stars[j].found = TRUE;
+    }
+    list[0].regions[Nr] = region;
+    Nr ++;
+    CHECK_REALLOCATE (list[0].regions, SkyRegion *, NR, Nr, 100);
+    list[0].Nregions = Nr;
+  }
+
+  /* reset to -1 for all stars: required start for find_match_refstars */
+  for (i = 0; i < Nstars; i++) stars[i].found = -1; 
+  return (list);
+}
+
+/* given a list of stars, find all region files which contain them 
+
+   - sort by ra
+   - loop over stars
+     - find region file which contains star
+     - go forwards until ra > Rmax
+       - mark all stars in this region file
+     
+   - use DEC band information?
+   - would like to minimize the number of disk reads
+
+*/
Index: /trunk/Ohana/src/addstar/src/SkyRegionUtils.c
===================================================================
--- /trunk/Ohana/src/addstar/src/SkyRegionUtils.c	(revision 5443)
+++ /trunk/Ohana/src/addstar/src/SkyRegionUtils.c	(revision 5443)
@@ -0,0 +1,42 @@
+# include "addstar.h"
+
+SkyList *SkyListExistingSubset (SkyList *input) {
+  
+  int i, status, Nsubset, NSUBSET;
+  SkyList *subset;
+  struct stat filestats;
+  
+  Nsubset = 0;
+  NSUBSET = 100;
+  ALLOCATE (subset, SkyList, 1);
+  ALLOCATE (subset[0].regions, SkyRegion *, NSUBSET);
+
+  /* match the basename against the GSCRegion file names */
+  for (i = 0; i < input[0].Nregions; i++) {
+    status = stat (input[0].regions[i][0].name, &filestats);
+    if ((status == -1) && (errno == ENOENT)) continue;
+    /* give an error for other conditions? */
+
+    subset[0].regions[Nsubset] = input[0].regions[i];
+    Nsubset ++;
+    CHECK_REALLOCATE (subset[0].regions, SkyRegion *, NSUBSET, Nsubset, 100);
+    subset[0].Nregions = Nsubset;
+  }
+  return (subset);
+}
+
+int SkyListSetPath (SkyList *list, char *path) {
+
+  int i;
+  char line[256];
+
+  for (i = 0; i < list[0].Nregions; i++) {
+    fprintf (stderr, "region: %s\n", list[0].regions[i][0].name);
+    sprintf (line, "%s/%s", path, list[0].regions[i][0].name);
+    fprintf (stderr, "line: %s\n", line);
+    strcpy (list[0].regions[i][0].name, line);
+    fprintf (stderr, "catalog: %s\n", list[0].regions[i][0].name);
+  }
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/addstar/src/addstar.c
===================================================================
--- /trunk/Ohana/src/addstar/src/addstar.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/addstar.c	(revision 5443)
@@ -7,8 +7,11 @@
   Stars *stars, **subset;
   Image image, *overlap;
-  GSCRegion *regions;
   Catalog catalog;
   FITS_DB db;
   AddstarClientOptions options;
+
+  SkyTable *sky;
+  SkyList *skylist;
+  SkyRegion *regions;
 
   double dtime;
@@ -20,4 +23,6 @@
   options = ConfigInit (&argc, argv);
   options = args (argc, argv, options);
+
+  sky = SkyTableFromGSC (GSCFILE, SKY_DEPTH, VERBOSE);
 
   stars = NULL;
@@ -41,21 +46,23 @@
     stars = gstars (argv[1], &Nstars, options.photcode, &image);
     if ((DUMP != NULL) && !strcmp (DUMP, "rawstars")) dump_rawstars (stars, Nstars);
-    regions = gregion_image (&image, MOSAIC, &Nregions);
-    /* lock_image_db (&db, ImageCat); */
+    skylist = SkyListByImage (sky, -1, &image, MOSAIC);
     overlap = gimages (&db, &image, MOSAIC, &Noverlap);
-    /* unlock_image_db (&db); */
     break;
   case M_REFLIST:
     stars = grefstars (argv[1], options.photcode, &Nstars);
-    regions = gregion_stars (stars, Nstars, &Nregions);
+    skylist = SkyListForStars (sky, -1, stars, Nstars);
     break;
   case M_REFCAT:
-    regions = gregion_patch (&UserPatch, &Nregions);
+    skylist = SkyListByPatch (sky, -1, &UserPatch);
     break;
   }
+  SkyListSetPath (skylist, CATDIR);
   if (options.only_match || options.existing_regions) {
-    regions = gregion_match (regions, &Nregions);
+    SkyList *tmp;
+    tmp = SkyListExistingSubset (skylist);
+    SkyListFree (skylist);
+    skylist = tmp;
   }
-  if (VERBOSE) fprintf (stderr, "writing to %d regions\n", Nregions);
+  if (VERBOSE) fprintf (stderr, "writing to %d regions\n", skylist[0].Nregions);
 
   gettimeofday (&stop, NULL);
@@ -64,9 +71,9 @@
 
   Naverage = Nmeasure = 0;
-  for (i = 0; i < Nregions; i++) {
+  for (i = 0; i < skylist[0].Nregions; i++) {
 
     gettimeofday (&t1, NULL);
 
-    load_pt_catalog (&catalog, &regions[i]);
+    load_pt_catalog (&catalog, skylist[0].regions[i]);
 
     /* for only_match, skip empty catalogs XXX EAM : this leaves behind empty files */
@@ -93,14 +100,14 @@
       Nsubset = Nstars;
       if (options.closest) {
-	find_matches_closest (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, MOSAIC, options);
+	find_matches_closest (skylist[0].regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, MOSAIC, options);
       } else {
-	find_matches (&regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, MOSAIC, options);
+	find_matches (skylist[0].regions[i], stars, Nstars, &catalog, &image, overlap, Noverlap, MOSAIC, options);
       }
       break;
     case M_REFCAT:
-      stars = grefcat (argv[1], &regions[i], options.photcode, &Nstars);
+      stars = grefcat (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
     case M_REFLIST:
-      subset = find_subset (&regions[i], stars, Nstars, &Nsubset);
-      find_matches_refstars (&regions[i], subset, Nsubset, &catalog, options);
+      subset = find_subset (skylist[0].regions[i], stars, Nstars, &Nsubset);
+      find_matches_refstars (skylist[0].regions[i], subset, Nsubset, &catalog, options);
       if (Nsubset) free (subset);
       break;
Index: /trunk/Ohana/src/addstar/src/args.c
===================================================================
--- /trunk/Ohana/src/addstar/src/args.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/args.c	(revision 5443)
@@ -28,17 +28,17 @@
   /*** provide additional data ***/ 
   /* restrict to a portion of the sky? (REFCAT only) */
-  UserPatch.RA[0] = 0;
-  UserPatch.RA[1] = 360;
-  UserPatch.DEC[0] = -90;
-  UserPatch.DEC[1] = +90;
+  UserPatch.Rmin = 0;
+  UserPatch.Rmax = 360;
+  UserPatch.Dmin = -90;
+  UserPatch.Dmax = +90;
   if ((N = get_argument (argc, argv, "-region"))) {
     remove_argument (N, &argc, argv);
-    UserPatch.RA[0] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.RA[1] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.DEC[0] = atof (argv[N]);
-    remove_argument (N, &argc, argv);
-    UserPatch.DEC[1] = atof (argv[N]);
+    UserPatch.Rmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Rmax = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmin = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+    UserPatch.Dmax = atof (argv[N]);
     remove_argument (N, &argc, argv);
   }
Index: /trunk/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/find_matches.c	(revision 5443)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
+void find_matches (SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
 
   int i, j, n, N, J;
Index: /trunk/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/find_matches_closest.c	(revision 5443)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_closest (GSCRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
+void find_matches_closest (SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, Image *image, Image *overlap, int Noverlap, Coords *mosaic, AddstarClientOptions options) {
 
   int i, j, n, N, J, Jmin;
Index: /trunk/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/find_matches_refstars.c	(revision 5443)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void find_matches_refstars (GSCRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
+void find_matches_refstars (SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options) {
 
   int i, j, k, n, m, N, J;
@@ -46,6 +46,6 @@
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is catalog center */
-  tcoords.crval1 = 0.5*(region[0].RA[0] + region[0].RA[1]);
-  tcoords.crval2 = 0.5*(region[0].DEC[0] + region[0].DEC[1]);
+  tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
+  tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
   tcoords.crpix1 = tcoords.crpix2 = 0.0;
   tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
Index: /trunk/Ohana/src/addstar/src/find_subset.c
===================================================================
--- /trunk/Ohana/src/addstar/src/find_subset.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/find_subset.c	(revision 5443)
@@ -2,5 +2,5 @@
 
 /* find stars within this region */
-Stars **find_subset (GSCRegion *region, Stars *stars, int Nstars, int *Nsubset) {
+Stars **find_subset (SkyRegion *region, Stars *stars, int Nstars, int *Nsubset) {
 
   int i, N, NSUBSET;
@@ -11,8 +11,8 @@
   ALLOCATE (subset, Stars *, NSUBSET);
 
-  RA0  = region[0].RA[0];
-  RA1  = region[0].RA[1];
-  DEC0 = region[0].DEC[0];
-  DEC1 = region[0].DEC[1];
+  RA0  = region[0].Rmin;
+  RA1  = region[0].Rmax;
+  DEC0 = region[0].Dmin;
+  DEC1 = region[0].Dmax;
 
   if (VERBOSE) fprintf (stderr, "subset for %f - %f, %f - %f\n", RA0, RA1, DEC0, DEC1);
Index: /trunk/Ohana/src/addstar/src/get2mass.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/get2mass.c	(revision 5443)
@@ -2,11 +2,11 @@
 # include "2mass.h"
 
-Stars *get2mass (GSCRegion *patch, int photcode, int mode, int *NSTARS) {
+Stars *get2mass (SkyRegion *patch, int photcode, int mode, int *NSTARS) {
   
   char *path;
-  int i, Nstars, Nrefcat, Nregions; 
-  Stars     *stars;
-  Stars     *refcat;
-  GSCRegion *regions;
+  int i, Nstars, Nrefcat; 
+  Stars    *stars;
+  Stars    *refcat;
+  SkyTable *sky;
 
   NAMED_PHOTCODE (TM_J, "2MASS_J");
@@ -22,18 +22,18 @@
   if (mode == 1) path = TWO_MASS_DIR_DR2;
 
-  regions = get2mass_acc (patch, &Nregions, path, "accel.dat");
+  sky = get2mass_acc (patch, path, "accel.dat");
   
   Nstars = 0;
   ALLOCATE (stars, Stars, 1);
 
-  for (i = 0; i < Nregions; i++) {
+  for (i = 0; i < sky[0].Nregions; i++) {
     refcat = NULL;
     switch (mode) {
       case 0:
-	refcat = get2mass_AS_data (&regions[i], patch, photcode, &Nrefcat);
+	refcat = get2mass_AS_data (&sky[0].regions[i], patch, photcode, &Nrefcat);
 	if (VERBOSE) fprintf (stderr, "loaded %d stars from 2MASS (allsky)\n", Nrefcat);
 	break;
       case 1:
-	refcat = get2mass_2DR_data (&regions[i], patch, photcode, &Nrefcat);
+	refcat = get2mass_2DR_data (&sky[0].regions[i], patch, photcode, &Nrefcat);
 	if (VERBOSE) fprintf (stderr, "loaded %d stars from 2MASS (dr2)\n", Nrefcat);
 	break;
@@ -53,11 +53,13 @@
 
 /* watch for patch which cross 0,360 boundary */
-GSCRegion *get2mass_acc (GSCRegion *patch, int *nregions, char *path, char *accel) {
+SkyTable *get2mass_acc (SkyRegion *patch, char *path, char *accel) {
 
   int Nregions, NREGIONS;
-  GSCRegion *regions;
   char accelfile[1024], line[256], filename[128];
   FILE *f;
   double Rs, Re, Ds, De;
+
+  SkyTable *sky;
+  SkyRegion *regions;
 
   sprintf (accelfile, "%s/%s", path, accel);
@@ -67,5 +69,5 @@
   Nregions = 0;
   NREGIONS = 200;
-  ALLOCATE (regions, GSCRegion, NREGIONS);
+  ALLOCATE (regions, SkyRegion, NREGIONS);
 
   /* read in stars line-by-line */
@@ -77,19 +79,21 @@
     Rs *= 15.0;
     Re *= 15.0;
-    if (Rs > patch[0].RA[1]) continue;
-    if (Re < patch[0].RA[0]) continue;
-    if (Ds > patch[0].DEC[1]) continue;
-    if (De < patch[0].DEC[0]) continue;
-    sprintf (regions[Nregions].filename, "%s/%s", path, filename);
-    regions[Nregions].RA[0] = Rs;
-    regions[Nregions].RA[1] = Re;
-    regions[Nregions].DEC[0] = Ds;
-    regions[Nregions].DEC[1] = De;
+    if (Rs > patch[0].Rmax) continue;
+    if (Re < patch[0].Rmin) continue;
+    if (Ds > patch[0].Dmax) continue;
+    if (De < patch[0].Dmin) continue;
+    sprintf (regions[Nregions].name, "%s/%s", path, filename);
+    regions[Nregions].Rmin = Rs;
+    regions[Nregions].Rmax = Re;
+    regions[Nregions].Dmin = Ds;
+    regions[Nregions].Dmax = De;
     Nregions ++;
-    CHECK_REALLOCATE (regions, GSCRegion, NREGIONS, Nregions, 20);
+    CHECK_REALLOCATE (regions, SkyRegion, NREGIONS, Nregions, 20);
   }    
   fclose (f);
 
-  *nregions = Nregions;
-  return (regions);
+  ALLOCATE (sky, SkyTable, 1);
+  sky[0].regions = regions;
+  sky[0].Nregions = Nregions;
+  return (sky);
 }
Index: /trunk/Ohana/src/addstar/src/get2mass_as.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/get2mass_as.c	(revision 5443)
@@ -13,5 +13,5 @@
 e_time get2mass_time (char *ptr, char *buffer, int Nbound, int Nbyte);
 
-Stars *get2mass_AS_data (GSCRegion *region, GSCRegion *patch, int photcode, int *nstars) {
+Stars *get2mass_AS_data (SkyRegion *region, SkyRegion *patch, int photcode, int *nstars) {
   
   int FilterSkip, TimeSkip;
@@ -28,8 +28,8 @@
   ALLOCATE (buffer, char, NBYTE);
 
-  RA0  = MAX (patch[0].RA[0],  UserPatch.RA[0]);
-  RA1  = MIN (patch[0].RA[1],  UserPatch.RA[1]);
-  DEC0 = MAX (patch[0].DEC[0], UserPatch.DEC[0]);
-  DEC1 = MIN (patch[0].DEC[1], UserPatch.DEC[1]);
+  RA0  = MAX (patch[0].Rmin, UserPatch.Rmin);
+  RA1  = MIN (patch[0].Rmax, UserPatch.Rmax);
+  DEC0 = MAX (patch[0].Dmin, UserPatch.Dmin);
+  DEC1 = MIN (patch[0].Dmax, UserPatch.Dmax);
 
   FilterSkip = TimeSkip = Qentry = 0;
@@ -51,5 +51,5 @@
   if (!FilterSkip) Shutdown ("invalid photcode %s", GetPhotcodeNamebyCode(photcode));
 
-  filename = region[0].filename;
+  filename = region[0].name;
   gf = gzopen (filename, "rb");
   if (gf == NULL) Shutdown ("can't read 2mass data file: %s", filename);
@@ -136,5 +136,5 @@
 /* this just scans along in the file.  file is sorted by dec, so we 
    should be skipping large chunks - but we would need to have
-   the size from the accel file (won't fit in GSCRegion) and need
+   the size from the accel file (won't fit in SkyRegion) and need
    to use gzseek, if it exists.
 */
Index: /trunk/Ohana/src/addstar/src/get2mass_dr2.c
===================================================================
--- /trunk/Ohana/src/addstar/src/get2mass_dr2.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/get2mass_dr2.c	(revision 5443)
@@ -5,5 +5,5 @@
 # define NLINE 30000
 
-Stars *get2mass_2DR_data (GSCRegion *region, GSCRegion *patch, int photcode, int *nstars) {
+Stars *get2mass_2DR_data (SkyRegion *region, SkyRegion *patch, int photcode, int *nstars) {
   
   int i, Nstars, NSTARS, Nbyte, Nline;
@@ -20,12 +20,12 @@
   if (patch == NULL) exit (3);
 
-  RA0  = MAX (patch[0].RA[0],  UserPatch.RA[0]);
-  RA1  = MIN (patch[0].RA[1],  UserPatch.RA[1]);
-  DEC0 = MAX (patch[0].DEC[0], UserPatch.DEC[0]);
-  DEC1 = MIN (patch[0].DEC[1], UserPatch.DEC[1]);
+  RA0  = MAX (patch[0].Rmin, UserPatch.Rmin);
+  RA1  = MIN (patch[0].Rmax, UserPatch.Rmax);
+  DEC0 = MAX (patch[0].Dmin, UserPatch.Dmin);
+  DEC1 = MIN (patch[0].Dmax, UserPatch.Dmax);
 
   fprintf (stderr, "overlap: %f - %f, %f - %f\n", RA0, RA1, DEC0, DEC1);
 
-  filename = region[0].filename;
+  filename = region[0].name;
   gf = gzopen (filename, "rb");
   if (gf == NULL) Shutdown ("can't read 2mass data file: %s", filename);
@@ -105,5 +105,5 @@
    and gzseek is as expensive as gzread */
 /* 
-   Noffset = region[0].Nrec * (patch[0].DEC[0] + 90) / 180.0;
+   Noffset = region[0].Nrec * (patch[0].Dmin + 90) / 180.0;
    gzseek (gf, Noffset * NBYTE, SEEK_SET);
    Nbyte = gzread (gf, buffer, NLINE*NBYTE);
Index: /trunk/Ohana/src/addstar/src/getgsc.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getgsc.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/getgsc.c	(revision 5443)
@@ -6,26 +6,25 @@
 static short GSC_M;
 
-Stars *getgsc (GSCRegion *patch, int *NSTARS) {
+Stars *getgsc (SkyRegion *patch, int *NSTARS) {
   
   int i, Ngsc, Nregions, Nstars; 
   Stars *gsc;
   Stars *stars;
-  GSCRegion *regions;
+  SkyList *skylist;
+  SkyTable *sky;
   char *tmp;
 
   NAMED_PHOTCODE (GSC_M, "GSC_M");
 
-  /* sort of sleaze way to get the right GSC files */
-  tmp = strcreate (CATDIR);
-  strcpy (CATDIR, GSCDIR);
-  regions = gregion_patch (patch, &Nregions);
-  strcpy (CATDIR, tmp);
-  free (tmp);
+  /* load regions from GSC table, restrict to patch */
+  sky = SkyTableFromGSC (GSCFILE, 2, VERBOSE);
+  skylist = SkyListByPatch (sky, -1, patch);
+  SkyListSetPath (skylist, GSCDIR);
   
   Nstars = 0;
   ALLOCATE (stars, Stars, 1);
   
-  for (i = 0; i < Nregions; i++) {
-    gsc = rd_gsc (regions[i].filename, &Ngsc);
+  for (i = 0; i < skylist[0].Nregions; i++) {
+    gsc = rd_gsc (skylist[0].regions[i][0].name, &Ngsc);
 
     REALLOCATE (stars, Stars, MAX (1, Nstars + Ngsc));
@@ -67,8 +66,8 @@
       dparse (&stars[Nstars].R, 1, &buffer[Nbyte]);
       dparse (&stars[Nstars].D, 2, &buffer[Nbyte]);
-      if (stars[Nstars].R < UserPatch.RA[0]) continue;
-      if (stars[Nstars].R > UserPatch.RA[1]) continue;
-      if (stars[Nstars].D < UserPatch.DEC[0]) continue;
-      if (stars[Nstars].D > UserPatch.DEC[1]) continue;
+      if (stars[Nstars].R < UserPatch.Rmin) continue;
+      if (stars[Nstars].R > UserPatch.Rmax) continue;
+      if (stars[Nstars].D < UserPatch.Dmin) continue;
+      if (stars[Nstars].D > UserPatch.Dmax) continue;
 
       dparse (&stars[Nstars].M, 3, &buffer[Nbyte]);
Index: /trunk/Ohana/src/addstar/src/getusno.c
===================================================================
--- /trunk/Ohana/src/addstar/src/getusno.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/getusno.c	(revision 5443)
@@ -9,5 +9,5 @@
   1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10};
 
-Stars *getusno (GSCRegion *catstats, int photcode, int *Nstars) {
+Stars *getusno (SkyRegion *catstats, int photcode, int *Nstars) {
 
   long int offset;
@@ -34,16 +34,16 @@
   /* identify ra & dec range of interest */
   /* note: the use of UserPatch to restrict here limits general utility of function */
-  iRA0  =  MAX (catstats[0].RA[0], UserPatch.RA[0]) * 360000.0;
-  iRA1  =  MIN (catstats[0].RA[1], UserPatch.RA[1]) * 360000.0;
-  iDEC0 = (MAX (catstats[0].DEC[0], UserPatch.DEC[0]) + 90.0) * 360000.0;
-  iDEC1 = (MIN (catstats[0].DEC[1], UserPatch.DEC[1]) + 90.0) * 360000.0;
+  iRA0  =  MAX (catstats[0].Rmin, UserPatch.Rmin) * 360000.0;
+  iRA1  =  MIN (catstats[0].Rmax, UserPatch.Rmax) * 360000.0;
+  iDEC0 = (MAX (catstats[0].Dmin, UserPatch.Dmin) + 90.0) * 360000.0;
+  iDEC1 = (MIN (catstats[0].Dmax, UserPatch.Dmax) + 90.0) * 360000.0;
   
   /* data is organized in south-pole distance zones */
-  spd_start = (int)((catstats[0].DEC[0] + 90) / 7.5) * 75.0;
-  dec = (catstats[0].DEC[1] + 90) / 7.5;
+  spd_start = (int)((catstats[0].Dmin + 90) / 7.5) * 75.0;
+  dec = (catstats[0].Dmax + 90) / 7.5;
   if (dec > (int)(dec)) {
-    spd_end =   (int)(1 + (catstats[0].DEC[1] + 90) / 7.5) * 75.0;
+    spd_end =   (int)(1 + (catstats[0].Dmax + 90) / 7.5) * 75.0;
   } else {
-    spd_end =   (int)(0 + (catstats[0].DEC[1] + 90) / 7.5) * 75.0;
+    spd_end =   (int)(0 + (catstats[0].Dmax + 90) / 7.5) * 75.0;
   }
 
@@ -82,9 +82,9 @@
     fclose (f);
     
-    first = catstats[0].RA[0] / 3.75;
-    if ((catstats[0].RA[1] / 3.75) == (int) (catstats[0].RA[1] / 3.75)) 
-      last  = catstats[0].RA[1] / 3.75;
+    first = catstats[0].Rmin / 3.75;
+    if ((catstats[0].Rmax / 3.75) == (int) (catstats[0].Rmax / 3.75)) 
+      last  = catstats[0].Rmax / 3.75;
     else 
-      last  = 1 + catstats[0].RA[1] / 3.75;
+      last  = 1 + catstats[0].Rmax / 3.75;
 
     if ((first > Nbins) || (last > Nbins)) {
Index: /trunk/Ohana/src/addstar/src/gimages.c
===================================================================
--- /trunk/Ohana/src/addstar/src/gimages.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/gimages.c	(revision 5443)
@@ -153,4 +153,5 @@
 */
 
+# if (0)
 void SetImageCorners (double *X, double *Y, Image *image) {
 
@@ -167,2 +168,3 @@
   }
 }
+# endif
Index: /trunk/Ohana/src/addstar/src/greference.c
===================================================================
--- /trunk/Ohana/src/addstar/src/greference.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/greference.c	(revision 5443)
@@ -3,5 +3,5 @@
 # define LOAD_DR2    1
 
-Stars *grefcat (char *Refcat, GSCRegion *catstats, int photcode, int *nstars) {
+Stars *grefcat (char *Refcat, SkyRegion *region, int photcode, int *nstars) {
 
   int Nstars;
@@ -9,5 +9,5 @@
 
   if (VERBOSE) fprintf (stderr, "loading reference catalog data from %s\n", Refcat); 
-  if (VERBOSE) fprintf (stderr, "full region: %f - %f, %f - %f\n", catstats[0].RA[0], catstats[0].RA[1], catstats[0].DEC[0], catstats[0].DEC[1]);
+  if (VERBOSE) fprintf (stderr, "full region: %f - %f, %f - %f\n", region[0].Rmin, region[0].Rmax, region[0].Dmin, region[0].Dmax);
 
   Nstars = 0;
@@ -16,28 +16,28 @@
   /* get stars from USNO for the given region */
   if (!strcasecmp (Refcat, "USNO")) {
-    stars = getusno (catstats, photcode, &Nstars);
+    stars = getusno (region, photcode, &Nstars);
   }
 
   /* get stars from HST GSC for the given region */
   if (!strcasecmp (Refcat, "GSC")) {
-    stars = getgsc (catstats, &Nstars);
+    stars = getgsc (region, &Nstars);
   }
   
   /* get stars from 2MASS for the given region */
   if (!strcasecmp (Refcat, "2MASS")) {
-    stars = get2mass (catstats, photcode, LOAD_ALLSKY, &Nstars);
+    stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
   }
   
   /* get stars from 2MASS for the given region */
   if (!strcasecmp (Refcat, "2MASS-ALLSKY")) {
-    stars = get2mass (catstats, photcode, LOAD_ALLSKY, &Nstars);
+    stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
   }
   
   /* get stars from 2MASS for the given region */
   if (!strcasecmp (Refcat, "2MASS-DR2")) {
-    stars = get2mass (catstats, photcode, LOAD_DR2, &Nstars);
+    stars = get2mass (region, photcode, LOAD_DR2, &Nstars);
   }
   
-  if (VERBOSE && (Nstars == 0)) fprintf (stderr, "no ref objects in region %s\n", catstats[0].filename);
+  if (VERBOSE && (Nstars == 0)) fprintf (stderr, "no ref objects in region %s\n", region[0].name);
 
   *nstars = Nstars;
Index: /trunk/Ohana/src/addstar/src/load_pt_catalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/load_pt_catalog.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/load_pt_catalog.c	(revision 5443)
@@ -1,11 +1,11 @@
 # include "addstar.h"
 
-int load_pt_catalog (Catalog *catalog, GSCRegion *region) {
+int load_pt_catalog (Catalog *catalog, SkyRegion *region) {
   
-  check_permissions (region[0].filename);
+  check_permissions (region[0].name);
 
   /* don't free region before catalog! */
-  catalog[0].filename = region[0].filename;
-  if (VERBOSE) fprintf (stderr, "adding to %s\n", region[0].filename);
+  catalog[0].filename = region[0].name;
+  if (VERBOSE) fprintf (stderr, "adding to %s\n", region[0].name);
     
   switch (lock_catalog (catalog, LCK_XCLD)) {
Index: /trunk/Ohana/src/addstar/src/mkcatalog.c
===================================================================
--- /trunk/Ohana/src/addstar/src/mkcatalog.c	(revision 5442)
+++ /trunk/Ohana/src/addstar/src/mkcatalog.c	(revision 5443)
@@ -1,5 +1,5 @@
 # include "addstar.h"
 
-void mkcatalog (GSCRegion *region, Catalog *catalog) {
+void mkcatalog (SkyRegion *region, Catalog *catalog) {
   
   int length, status;
@@ -7,5 +7,5 @@
   time_t now;
 
-  if (VERBOSE) fprintf (stderr, "new catalog file: %s\n", region[0].filename);
+  if (VERBOSE) fprintf (stderr, "new catalog file: %s\n", region[0].name);
 
   /* set the recommended CATFORMAT */
@@ -94,8 +94,8 @@
 
   /* write RA,DEC range in header */
-  fits_modify (&catalog[0].header, "RA0",  "%lf", 1, region[0].RA[0]);
-  fits_modify (&catalog[0].header, "DEC0", "%lf", 1, region[0].DEC[0]);
-  fits_modify (&catalog[0].header, "RA1",  "%lf", 1, region[0].RA[1]);
-  fits_modify (&catalog[0].header, "DEC1", "%lf", 1, region[0].DEC[1]);
+  fits_modify (&catalog[0].header, "RA0",  "%lf", 1, region[0].Rmin);
+  fits_modify (&catalog[0].header, "DEC0", "%lf", 1, region[0].Dmin);
+  fits_modify (&catalog[0].header, "RA1",  "%lf", 1, region[0].Rmax);
+  fits_modify (&catalog[0].header, "DEC1", "%lf", 1, region[0].Dmax);
 
   /* write creation date in header */
