Index: trunk/Ohana/src/opihi/dvo/skycoverage.c
===================================================================
--- trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 19823)
+++ trunk/Ohana/src/opihi/dvo/skycoverage.c	(revision 21153)
@@ -1,9 +1,12 @@
 # include "dvoshell.h"
+
+int wordhash (char *word);
 
 int skycoverage (int argc, char **argv) {
 
+  int WITH_MOSAIC, SOLO_MOSAIC;
   int i, N, Nimage, status, TimeSelect, ByName, xs, ys;
   time_t tzero, tend;
-  double pixscale, dPix, r, d, Xi, Yi, Xs, Ys, x[2], y[2], trange;
+  double pixscale, dX, dY, Npts, r, d, Xi, Yi, Xs, Ys, x[2], y[2], trange, RaCenter;
   Image *image;
   char name[256];
@@ -12,4 +15,25 @@
   Buffer *buf;
   Coords coords;
+  int typehash;
+
+  WITH_MOSAIC = FALSE;
+  if ((N = get_argument (argc, argv, "+mosaic"))) {
+    remove_argument (N, &argc, argv);
+    WITH_MOSAIC = TRUE;
+  }
+
+  SOLO_MOSAIC = FALSE;
+  if ((N = get_argument (argc, argv, "-mosaic"))) {
+    remove_argument (N, &argc, argv);
+    SOLO_MOSAIC = TRUE;
+    WITH_MOSAIC = TRUE;
+  }
+
+  RaCenter = 0.0;
+  if ((N = get_argument (argc, argv, "-ra-center"))) {
+    remove_argument (N, &argc, argv);
+    RaCenter = atof (argv[N]);
+    remove_argument (N, &argc, argv);
+  }
 
   ByName = FALSE;
@@ -61,7 +85,8 @@
  
   if (argc != 4) {
-    gprint (GP_ERR, "USAGE: skycoverage (buffer) (pixscale) (dPix) [-time start range] [-name name]\n");
+    gprint (GP_ERR, "USAGE: skycoverage (buffer) (pixscale) (Npts) [-time start range] [-name name]\n");
     gprint (GP_ERR, "       (buffer) saves bitmapped AIT plot\n");
     gprint (GP_ERR, "       (pixscale) specifies the pixel size in degrees\n");
+    gprint (GP_ERR, "       (Npts) gives the number of test points per image in each dimension\n");
     gprint (GP_ERR, "       note: we need 64800 / (pixscale)^2 pixels to represent the sky\n");
     return (FALSE);
@@ -70,5 +95,5 @@
   if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE);
   pixscale = atof(argv[2]);
-  dPix     = atof(argv[3]);
+  Npts     = atof(argv[3]);
 
   Nx = 360/pixscale;
@@ -80,11 +105,13 @@
   strcpy (buf[0].file, "(empty)");
 
-  coords.crval1 = 180;
+  coords.crval1 = RaCenter;
   coords.crval2 = 0;
   coords.crpix1 = 0.5*Nx;
   coords.crpix2 = 0.5*Ny;
   strcpy (coords.ctype, "DEC--AIT");
-  coords.pc1_1 = coords.pc2_2 = 1;
-  coords.pc1_2 = coords.pc2_1 = 0;
+  coords.pc1_1 = -1.0;
+  coords.pc2_2 = +1.0;
+  coords.pc1_2 =  0.0;
+  coords.pc2_1 =  0.0;
   coords.cdelt1 = coords.cdelt2 = pixscale;
   coords.Npolyterms = 0;
@@ -109,8 +136,16 @@
   }
 
+  int DistortImage = wordhash ("-DIS");
+
   for (i = 0; i < Nimage; i++) {
     if (ByName && strcmp (name, image[i].name)) continue;
     if (TimeSelect && ((image[i].tzero < tzero) || (image[i].tzero+image[i].trate*image[i].NY > tzero + trange))) continue;
     if (!FindMosaicForImage (image, Nimage, i)) continue;
+
+    typehash = wordhash (&image[i].coords.ctype[4]);
+
+    /* DIS images represent a field, not a chip */
+    if ((typehash == DistortImage) && !WITH_MOSAIC) continue;
+    if ((typehash != DistortImage) &&  SOLO_MOSAIC) continue;
 
     /* project this image to screen display coords */
@@ -125,9 +160,16 @@
     status = FALSE;
     
-    for (Yi = y[0] + 0.5*dPix; Yi < y[1]; Yi += dPix) {
-      for (Xi = x[0] + 0.5*dPix; Xi < x[1]; Xi += dPix) {
+    dX = (x[1] - x[0]) / Npts;
+    dY = (y[1] - y[0]) / Npts;
+    
+    for (Yi = y[0] + 0.5*dY; Yi < y[1]; Yi += dY) {
+      for (Xi = x[0] + 0.5*dX; Xi < x[1]; Xi += dX) {
 	XY_to_RD (&r, &d, Xi, Yi, &image[i].coords);
 	r = ohana_normalize_angle (r);
 	status = RD_to_XY (&Xs, &Ys, r, d, &coords);
+	if (Xs < 0) continue;
+	if (Ys < 0) continue;
+	if (Xs >= Nx) continue;
+	if (Ys >= Ny) continue;
 	if (status) {
 	  xs = (int)Xs;
