Index: trunk/Ohana/src/opihi/dvo/imdata.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/imdata.c	(revision 5320)
+++ trunk/Ohana/src/opihi/dvo/imdata.c	(revision 5448)
@@ -1,4 +1,3 @@
 # include "dvo1.h"
-void copy_region (GSCRegion *in, GSCRegion *out);
 
 int imdata (int argc, char **argv) {
@@ -13,5 +12,6 @@
   Image *image;
   Catalog catalog;
-  GSCRegion *region, *tregion;
+  SkyTable *sky;
+  SkyList *skylist, *skyset;
   Vector *vec;
 
@@ -80,27 +80,35 @@
   GetTimeFormat (&TimeReference, &TimeFormat);
 
+  /* load sky from correct table */
+  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, -1, VERBOSE);
+  SkyTableSetFilenames (sky, CATDIR, "cpt");
+
+  Nregions = 0;
+  NREGIONS = 10;
+  ALLOCATE (skylist, SkyList, 1);
+  ALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS);
+
   /* for each image of interest, find the appropriate region files */
-  Nregion = 0;
-  ALLOCATE (region, GSCRegion, 1);
   for (i = 0; i < Nsubset; i++) {
     I = subset[i];
+
     if (!FindMosaicForImage (image, Nimage, I)) continue;
-    tregion = get_regions (&image[I], &Ntregion);
-    REALLOCATE (region, GSCRegion, MAX (1, Nregion + Ntregion));
-    for (j = 0; j < Ntregion; j++) {
-      skip = FALSE;
-      for (k = 0; (k < Nregion) && !skip; k++) {
-	if (!strcmp (region[k].filename, tregion[j].filename)) skip = TRUE;
-      }
-      if (!skip) {
-	copy_region (&tregion[j], &region[Nregion]);
-	Nregion ++;
-      }
-    }
-    free (tregion);
+    skyset = SkyListByImage (table, -1, &image[I]);
+
+    for (j = 0; j < skyset[0].Nregions; j++) {
+      found = FALSE;
+      for (k = 0; (k < skylist[0].Nregion) && !found; k++) {
+	found = !strcmp (skylist[0].regions[k].name, skyset[0].regions[j].name);
+      }
+      if (found) continue;
+      skylist[0].regions[Nregions] = skyset[0].regions[j];
+      Nregions ++;
+      CHECK_REALLOCATE (skylist[0].regions, SkyRegions *, NREGIONS, Nregions, 10);
+    }
+    SkyListFree (skyset);
   }	
   free (subset);
-  for (i = 0; i < Nregion; i++) {
-    fprintf (stderr, "try %s\n", region[i].filename);
+  for (i = 0; i < skylist[0].Nregions; i++) {
+    fprintf (stderr, "try %s\n", skylist[0].regions[i][0].name);
   } 
   
@@ -111,9 +119,8 @@
 
   /* for each region file, extract the data of interest in the right time range */
-  for (j = 0; j < Nregion; j++) {
+  for (j = 0; j < skylist[0].Nregions; j++) {
 
     /* get file name and open */
-    strcpy (filename, region[j].filename);
-    catalog.filename = filename;
+    catalog.filename = skylist[0].regions[j][0].filename;
     switch (lock_catalog (&catalog, LCK_SOFT)) {
     case 2:
@@ -210,13 +217,2 @@
   return (TRUE);
 }
-
-
-void copy_region (GSCRegion *in, GSCRegion *out) {
-    
-  out[0].RA[0]  = in[0].RA[0];
-  out[0].RA[1]  = in[0].RA[1];
-  out[0].DEC[0] = in[0].DEC[0];
-  out[0].DEC[1] = in[0].DEC[1];
-  strcpy (out[0].filename, in[0].filename);
-}
-
