Index: trunk/Ohana/src/getstar/include/dvoImageOverlaps.h
===================================================================
--- trunk/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 37772)
+++ trunk/Ohana/src/getstar/include/dvoImageOverlaps.h	(revision 37807)
@@ -37,2 +37,5 @@
 int edge_check (double *x1, double *y1, double *x2, double *y2);
 double opening_angle (double x1, double y1, double x2, double y2, double x3, double y3);
+
+void initMosaicCoords ();
+void saveMosaicCoords (Coords *input);
Index: trunk/Ohana/src/getstar/src/MatchCoords.c
===================================================================
--- trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 37772)
+++ trunk/Ohana/src/getstar/src/MatchCoords.c	(revision 37807)
@@ -29,7 +29,4 @@
     if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
     if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
-
-    /* if any of these images are WRP images, need to find matching DIS */
-    if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
 
     /* define image corners */
Index: trunk/Ohana/src/getstar/src/MatchImages.c
===================================================================
--- trunk/Ohana/src/getstar/src/MatchImages.c	(revision 37772)
+++ trunk/Ohana/src/getstar/src/MatchImages.c	(revision 37807)
@@ -23,26 +23,13 @@
   /* we keep the original crpix1,2 and crref1,2 */
   /* for mosaic astrometry, the grid should be w.r.t. the tangent-plane, not chip coords */
+  InitCoords (&tcoords, "DEC--TAN");
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
-    // if the input image is a mosaic, we need to register that mosaic for the calculations below
-    if (MOSAIC == NULL) {
-      fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
-      return NULL;
-    }
-    RegisterMosaic (MOSAIC);
-
-    tcoords = MOSAIC[0];
+    myAssert (image[0].coords.mosaic, "should already have tested this");
+    tcoords = image[0].coords.mosaic[0];
     tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
-    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
-    tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "DEC--TAN");
     /* register so image->sky conversions below have correct mosaic */
   } else {
     tcoords = image[0].coords;
     tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-    tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
-    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
-    tcoords.Npolyterms = 1;
-    strcpy (tcoords.ctype, "DEC--TAN");
   }
 
@@ -77,7 +64,4 @@
     if (!WITH_PHU && !strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
     if ( SOLO_PHU &&  strcmp (&dbImages[i].coords.ctype[4], "-DIS")) continue;
-
-    /* if any of these images are WRP images, need to find matching DIS */
-    if (!FindMosaicForImage (dbImages, NdbImages, i)) continue;
 
     /* define image corners */
Index: trunk/Ohana/src/getstar/src/ReadImageFiles.c
===================================================================
--- trunk/Ohana/src/getstar/src/ReadImageFiles.c	(revision 37772)
+++ trunk/Ohana/src/getstar/src/ReadImageFiles.c	(revision 37807)
@@ -42,4 +42,6 @@
 
   mode = GetFileMode (header);
+
+  initMosaicCoords ();
 
   /*** load data from a single PHU or a collection of PHU files ***/
Index: trunk/Ohana/src/getstar/src/ReadImageHeader.c
===================================================================
--- trunk/Ohana/src/getstar/src/ReadImageHeader.c	(revision 37772)
+++ trunk/Ohana/src/getstar/src/ReadImageHeader.c	(revision 37807)
@@ -1,3 +1,14 @@
 # include "dvoImageOverlaps.h"
+
+// for DIS/WRP sets, we need to save the DIS set and supply it to the WRP entries
+static Coords *mosaic = NULL;
+
+void initMosaicCoords () {
+  mosaic = NULL;
+}
+
+void saveMosaicCoords (Coords *input) {
+  mosaic = input;
+}
 
 /* read an image header corresponding to a CMF / CMP data block */
@@ -44,5 +55,5 @@
   /* only load astrometry, NAXIS1,2, and time if this is a MOSAIC_PHU (ctype is ....-DIS) */
   if (!strcmp (&image[0].coords.ctype[4], "-DIS")) {
-    MOSAIC = &image[0].coords;
+    saveMosaicCoords (&image[0].coords);
     return (TRUE);
   }
@@ -56,9 +67,9 @@
   }
   if (!strcmp (&image[0].coords.ctype[4], "-WRP")) {
-    if (MOSAIC == NULL) {
+    if (mosaic == NULL) {
       fprintf (stderr, "no mosaic for WRP image (use -mosaic)\n");
       return (FALSE);
     }
-    RegisterMosaic (MOSAIC);
+    image[0].coords.mosaic = mosaic;
   } else {
     /* force image to lie in 0-360 range */
Index: trunk/Ohana/src/getstar/src/WriteImages.c
===================================================================
--- trunk/Ohana/src/getstar/src/WriteImages.c	(revision 37772)
+++ trunk/Ohana/src/getstar/src/WriteImages.c	(revision 37807)
@@ -5,5 +5,5 @@
   
   int i, N;
-  int nWRP, newWRP, isWRP;
+  int isWRP;
   FILE *f;
 
@@ -16,21 +16,16 @@
   }
 
-  nWRP = -1;
+  Image *mosaic = NULL;
   isWRP = FALSE;
   for (i = 0; i < Nmatches; i++) {
-    if (!strcmp (&images[0].coords.ctype[4], "-WRP")) {
-      if (!FindMosaicForImage (images, Nimages, i)) {
-	fprintf (stderr, "failed to find matching mosaic\n");
-	exit (1);
-      }
+    N = matches[i];
+    if (!strcmp (&images[N].coords.ctype[4], "-WRP")) {
       if (isWRP) {
-	newWRP = GetRegisteredMosaic();
-	if (newWRP != nWRP) {
+	if (mosaic != images[N].parent) {
 	  fprintf (stderr, "only one mosaic allowed in an output file\n");
 	  exit (1);
 	}
       } else {
-	nWRP = GetRegisteredMosaic();
-	isWRP = TRUE;
+	mosaic = images[N].parent;
       }
     }      
@@ -38,5 +33,5 @@
 
   if (isWRP) {
-    WriteImageFITS (f, &images[nWRP]);
+    WriteImageFITS (f, mosaic);
   } else {
     // write a blank
