Index: /trunk/Ohana/src/opihi/dvo/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/dvo/Makefile	(revision 5441)
+++ /trunk/Ohana/src/opihi/dvo/Makefile	(revision 5442)
@@ -80,4 +80,5 @@
 $(SDIR)/procks.$(ARCH).o	  	\
 $(SDIR)/skycoverage.$(ARCH).o	  	\
+$(SDIR)/skycat.$(ARCH).o	  	\
 $(SDIR)/showtile.$(ARCH).o	  	\
 $(SDIR)/simage.$(ARCH).o	  	\
Index: /trunk/Ohana/src/opihi/dvo/find_regions.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 5441)
+++ /trunk/Ohana/src/opihi/dvo/find_regions.c	(revision 5442)
@@ -15,5 +15,5 @@
   int NLINES, done, NREGIONS, nregion;
   
-  VarConfig ("SKYFILE", "%s", filename);
+  VarConfig ("GSCFILE", "%s", filename);
   f = fopen (filename, "r");
   if (f == NULL) {
Index: /trunk/Ohana/src/opihi/dvo/init.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/init.c	(revision 5441)
+++ /trunk/Ohana/src/opihi/dvo/init.c	(revision 5442)
@@ -43,4 +43,5 @@
 int procks	    PROTO((int, char **));
 int showtile	    PROTO((int, char **));
+int skycat	    PROTO((int, char **));
 int skycoverage	    PROTO((int, char **));
 int simage	    PROTO((int, char **));
@@ -95,4 +96,5 @@
   {"procks",      procks,       "plot rocks"},
   {"showtile",    showtile,     "plot tile pattern"},
+  {"skycat",      skycat,       "show sky catalog boundaries"},
   {"skycoverage", skycoverage,  "measure image union on sky"},
   {"simage",      simage,       "plot stars in an image"},
Index: /trunk/Ohana/src/opihi/dvo/pcat.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/pcat.c	(revision 5441)
+++ /trunk/Ohana/src/opihi/dvo/pcat.c	(revision 5442)
@@ -1,8 +1,9 @@
 # include "dvo1.h"
+int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside);
 
 int pcat (int argc, char **argv) {
   
   double Radius;
-  int i, j, N, Nregions, ShowAll, NPTS, Npts;
+  int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside;
   RegionFile *regions;
   char filename[128];
@@ -10,9 +11,15 @@
   Vector Xvec, Yvec;
   Graphdata graphmode;
-  double X[4], Y[4];
+  double X[4], Y[4], Rmin, Rmax, Rmid;
   char catdir[256];
-  int Ngraph;
+  int Ngraph, VERBOSE;
 
   VarConfig ("CATDIR", "%s", catdir);
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    remove_argument (N, &argc, argv);
+    VERBOSE = TRUE;
+  }
 
   ShowAll = FALSE;
@@ -31,4 +38,8 @@
   regions = find_regions (graphmode.coords.crval1, graphmode.coords.crval2, Radius, &Nregions);
 
+  Rmin = graphmode.coords.crval1 - 180.0;
+  Rmax = graphmode.coords.crval1 + 180.0;
+  Rmid = 0.5*(Rmin + Rmax);
+
   NPTS = 200;
   ALLOCATE (Xvec.elements, float, NPTS);
@@ -39,16 +50,19 @@
     sprintf (filename, "%s/%s", catdir, regions[i].name);
     if (ShowAll || (stat (filename, &filestat) != -1)) {
-      fprintf (stderr, "%3d %s\n", i, regions[i].name);
-      RD_to_XY (&X[0], &Y[0], regions[i].RA0, regions[i].DEC0, &graphmode.coords);
-      RD_to_XY (&X[1], &Y[1], regions[i].RA0, regions[i].DEC1, &graphmode.coords);
-      RD_to_XY (&X[2], &Y[2], regions[i].RA1, regions[i].DEC1, &graphmode.coords);
-      RD_to_XY (&X[3], &Y[3], regions[i].RA1, regions[i].DEC0, &graphmode.coords);
-      for (j = 0; j < 4; j++) {
-	Xvec.elements[Npts + j*2] = X[j];
-	Yvec.elements[Npts + j*2] = Y[j];
-	if (j > 0) {
-	  Xvec.elements[Npts+2*j - 1] = Xvec.elements[Npts+2*j];
-	  Yvec.elements[Npts+2*j - 1] = Yvec.elements[Npts+2*j];
-	}
+      if (VERBOSE) fprintf (stderr, "%3d %s\n", i, regions[i].name);
+
+      leftside = -1;
+      RD_to_XYpic (&X[0], &Y[0], regions[i].RA0, regions[i].DEC0, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[1], &Y[1], regions[i].RA0, regions[i].DEC1, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[2], &Y[2], regions[i].RA1, regions[i].DEC1, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[3], &Y[3], regions[i].RA1, regions[i].DEC0, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+
+      Xvec.elements[Npts] = X[0];
+      Yvec.elements[Npts] = Y[0];
+      for (j = 1; j < 4; j++) {
+	Xvec.elements[Npts + j*2 - 0] = X[j];
+	Yvec.elements[Npts + j*2 - 0] = Y[j];
+	Xvec.elements[Npts + j*2 - 1] = X[j];
+	Yvec.elements[Npts + j*2 - 1] = Y[j];
       }
       Xvec.elements[Npts+7] = Xvec.elements[Npts];
@@ -81,2 +95,19 @@
 
 }
+
+int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside) {
+
+  while (r < Rmin) { r += 360.0; }
+  while (r > Rmax) { r -= 360.0; }
+
+  if (*leftside == -1) {
+    *leftside = (r < Rmid);
+  } else {
+    if (  *leftside && (r > Rmid + 90)) { r -= 360.0; }
+    if (! *leftside && (r < Rmid - 90)) { r += 360.0; }
+  }
+
+  RD_to_XY (x, y, r, d, coords);
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/dvo/skycat.c
===================================================================
--- /trunk/Ohana/src/opihi/dvo/skycat.c	(revision 5442)
+++ /trunk/Ohana/src/opihi/dvo/skycat.c	(revision 5442)
@@ -0,0 +1,115 @@
+# include "dvo1.h"
+
+int skycat (int argc, char **argv) {
+  
+  double Radius;
+  int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside, Depth, TableDepth;
+  char filename[128];
+  struct stat filestat;
+  Vector Xvec, Yvec;
+  Graphdata graphmode;
+  double X[4], Y[4], Rmin, Rmax, Rmid;
+  char catdir[256], gscfile[256];
+  int Ngraph, VERBOSE;
+  SkyTable *sky;
+  SkyList *skylist;
+  SkyRegion **regions;
+
+  VarConfig ("CATDIR", "%s", catdir);
+  VarConfig ("GSCFILE", "%s", gscfile);
+
+  VERBOSE = FALSE;
+  if ((N = get_argument (argc, argv, "-v"))) {
+    remove_argument (N, &argc, argv);
+    VERBOSE = TRUE;
+  }
+  ShowAll = FALSE;
+  if ((N = get_argument (argc, argv, "-all"))) {
+    remove_argument (N, &argc, argv);
+    ShowAll = TRUE;
+  }
+  Depth = -1;
+  if ((N = get_argument (argc, argv, "-depth"))) {
+    remove_argument (N, &argc, argv);
+    Depth = atoi (argv[N]);
+    remove_argument (N, &argc, argv);    
+  }
+
+  if (argc != 1) {
+    fprintf (stderr, "USAGE: skycat [-all]\n");
+    return (FALSE);
+  }
+  TableDepth = (Depth == 3) ? 3 : 2;
+  Ngraph = 0;
+  if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
+
+  Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
+  sky = SkyTableFromGSC (gscfile, TableDepth, VERBOSE);
+  if (sky == NULL) return (FALSE);
+  skylist = SkyListByRadius (sky, Depth, graphmode.coords.crval1, graphmode.coords.crval2, Radius);
+  
+  if (VERBOSE) fprintf (stderr, "region: %6.2f - %6.2f, %6.2f - %6.2f\n", 
+			graphmode.coords.crval1 - Radius, graphmode.coords.crval1 + Radius, 
+			graphmode.coords.crval2 - Radius, graphmode.coords.crval2 + Radius);
+
+  Rmin = graphmode.coords.crval1 - 180.0;
+  Rmax = graphmode.coords.crval1 + 180.0;
+  Rmid = 0.5*(Rmin + Rmax);
+
+  NPTS = 200;
+  ALLOCATE (Xvec.elements, float, NPTS);
+  ALLOCATE (Yvec.elements, float, NPTS);
+  Npts = 0;
+   
+  regions = skylist[0].regions;
+  Nregions = skylist[0].Nregions;
+
+  for (i = 0; i < Nregions; i++) {
+    sprintf (filename, "%s/%s", catdir, regions[i][0].name);
+    if (ShowAll || (stat (filename, &filestat) != -1)) {
+      if (VERBOSE) fprintf (stderr, "%3d %s %6.2f - %6.2f, %6.2f - %6.2f\n", i, regions[i][0].name, 
+			    regions[i][0].Rmin, regions[i][0].Rmax, regions[i][0].Dmin, regions[i][0].Dmax);
+
+      leftside = -1;
+      RD_to_XYpic (&X[0], &Y[0], regions[i][0].Rmin, regions[i][0].Dmin, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[1], &Y[1], regions[i][0].Rmin, regions[i][0].Dmax, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[2], &Y[2], regions[i][0].Rmax, regions[i][0].Dmax, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+      RD_to_XYpic (&X[3], &Y[3], regions[i][0].Rmax, regions[i][0].Dmin, &graphmode.coords, Rmin, Rmax, Rmid, &leftside);
+
+      Xvec.elements[Npts] = X[0];
+      Yvec.elements[Npts] = Y[0];
+      for (j = 1; j < 4; j++) {
+	Xvec.elements[Npts + j*2 - 0] = X[j];
+	Yvec.elements[Npts + j*2 - 0] = Y[j];
+	Xvec.elements[Npts + j*2 - 1] = X[j];
+	Yvec.elements[Npts + j*2 - 1] = Y[j];
+      }
+      Xvec.elements[Npts+7] = Xvec.elements[Npts];
+      Yvec.elements[Npts+7] = Yvec.elements[Npts];
+      Npts += 8;
+      if (Npts > NPTS - 1) {  /* this is OK because NPTS is made always a multiple of 8 */
+	NPTS += 200;
+	REALLOCATE (Xvec.elements, float, NPTS);
+	REALLOCATE (Yvec.elements, float, NPTS);
+      }
+    }
+  }
+
+  fprintf (stderr, "plotting %d catalogs\n", Npts/8);
+  Xvec.Nelements = Xvec.Nelements = Npts;
+  if (Npts > 0) {
+    graphmode.style = 2; /* points */
+    graphmode.ptype = 100; /* connect pairs of points */
+    graphmode.etype = 0;
+    PrepPlotting (Npts, &graphmode);
+    PlotVector (Npts, Xvec.elements);
+    PlotVector (Npts, Yvec.elements);
+  }
+
+  free (Xvec.elements);
+  free (Yvec.elements);
+  free (regions);
+
+  return (TRUE);
+
+}
Index: /trunk/Ohana/src/opihi/include/dvo1.h
===================================================================
--- /trunk/Ohana/src/opihi/include/dvo1.h	(revision 5441)
+++ /trunk/Ohana/src/opihi/include/dvo1.h	(revision 5442)
@@ -90,4 +90,5 @@
 CMPstars *cmpReadFits (FILE *f, int *nstars);
 CMPstars *cmpReadText (FILE *f, int *nstars);
+int RD_to_XYpic (double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside);
 
 # endif
Index: /trunk/Ohana/src/opihi/include/dvo2.h
===================================================================
--- /trunk/Ohana/src/opihi/include/dvo2.h	(revision 5441)
+++ /trunk/Ohana/src/opihi/include/dvo2.h	(revision 5442)
@@ -11,10 +11,10 @@
   int Nregion;
   SkyRegion *region;
-} SkyRegionTable;
+} SkyTable;
 
 typedef struct {
   int Nregion;
   SkyRegion **region;
-} SkyRegionList;
+} SkyList;
 
 # if (0)
