Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/test/dvomerge.dvo
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/test/dvomerge.dvo	(revision 28673)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/test/dvomerge.dvo	(revision 28674)
@@ -95,5 +95,5 @@
     subset T = t if (id == imageID[$i])
     set dT = T - time[$i]
-    vstat -q dT 
+    vstat dT 
     tapOK {abs($MEAN)  < 0.00001} "time for measure ID $i (MEAN)"
     tapOK {abs($SIGMA) < 0.00001} "time for measure ID $i (SIGMA)"
Index: /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvomergeUpdate.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 28673)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvomergeUpdate.c	(revision 28674)
@@ -6,5 +6,5 @@
   off_t i, j, Ns, Ne;
   SkyTable *outsky, *insky;
-  SkyList *inlist;
+  SkyList *outlist;
   Catalog incatalog, outcatalog;
   char filename[256], *input, *output;
@@ -58,11 +58,17 @@
   depth = insky[0].regions[Ns].depth;
   
-  // loop over the populatable output regions
+  // loop over the populated input regions
   for (i = 0; i < outsky[0].Nregions; i++) {
-    if (!outsky[0].regions[i].table) continue;
-    if (VERBOSE) fprintf (stderr, "output: %s\n", outsky[0].regions[i].name);
+    if (!insky[0].regions[i].table) continue;
+    if (VERBOSE) fprintf (stderr, "input: %s\n", insky[0].regions[i].name);
 
     // load / create output catalog (if catalog does not exist, it will be created)
-    LoadCatalog (&outcatalog, &outsky[0].regions[i], outsky[0].filename[i], "w");
+    LoadCatalog (&incatalog, &insky[0].regions[i], insky[0].filename[i], "r");
+    // skip empty input catalogs
+    if (!incatalog.Naves_disk) {
+	dvo_catalog_unlock (&incatalog);
+	dvo_catalog_free (&incatalog);
+	continue;
+    }
 
     // combine only tables at equal or larger depth
@@ -72,30 +78,25 @@
     // compare to a slightly reduced footprint
     float dPos = 2.0/3600.0;
-    inlist = SkyListByBounds (insky, depth, outsky[0].regions[i].Rmin + dPos, outsky[0].regions[i].Rmax - dPos, outsky[0].regions[i].Dmin + dPos, outsky[0].regions[i].Dmax - dPos);
-    for (j = 0; j < inlist[0].Nregions; j++) {
-      if (VERBOSE) fprintf (stderr, "input : %s\n", inlist[0].regions[j][0].name);
+    outlist = SkyListByBounds (outsky, depth, insky[0].regions[i].Rmin + dPos, insky[0].regions[i].Rmax - dPos, insky[0].regions[i].Dmin + dPos, insky[0].regions[i].Dmax - dPos);
+    for (j = 0; j < outlist[0].Nregions; j++) {
+      if (VERBOSE) fprintf (stderr, "output : %s\n", outlist[0].regions[j][0].name);
 
       // load input catalog
-      LoadCatalog (&incatalog, inlist[0].regions[j], inlist[0].filename[j], "r");
+      LoadCatalog (&outcatalog, outlist[0].regions[j], outlist[0].filename[j], "w");
 
-      // skip empty input catalogs
-      if (!incatalog.Naves_disk) {
-	dvo_catalog_unlock (&incatalog);
-	dvo_catalog_free (&incatalog);
-	continue;
-      }
       dvo_update_image_IDs (&IDmap, &incatalog);
-      merge_catalogs_old (&outsky[0].regions[i], &outcatalog, &incatalog, RADIUS);
-      dvo_catalog_unlock (&incatalog);
-      dvo_catalog_free (&incatalog);
+      merge_catalogs_old (&outsky[0].regions[j], &outcatalog, &incatalog, RADIUS);
 
-      fprintf (stderr, "merged %s into %s\n", outsky[0].regions[i].name, inlist[0].regions[j][0].name);
+      outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
+      dvo_catalog_save (&outcatalog, VERBOSE);
+      dvo_catalog_unlock (&outcatalog);
+      dvo_catalog_free (&outcatalog);
+
+      fprintf (stderr, "merged %s into %s\n", insky[0].regions[i].name, outlist[0].regions[j][0].name);
     }
-    SkyListFree (inlist);
+    SkyListFree (outlist);
 
-    outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
-    dvo_catalog_save (&outcatalog, VERBOSE);
-    dvo_catalog_unlock (&outcatalog);
-    dvo_catalog_free (&outcatalog);
+    dvo_catalog_unlock (&incatalog);
+    dvo_catalog_free (&incatalog);
   }
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c	(revision 28673)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c	(revision 28674)
@@ -421,4 +421,6 @@
 }
 
+enum {COORD_TYPE_NONE, COORD_TYPE_PC, COORD_TYPE_ROT, COORD_TYPE_CD, COORD_TYPE_LIN};
+
 int GetCoords (Coords *coords, Header *header) {
   
@@ -427,4 +429,5 @@
   double equinox;
   char *ctype;
+  int mode;
   
   rotate = 0.0;
@@ -436,25 +439,45 @@
   strcpy (coords[0].ctype, "NONE");
   
-  status = FALSE; 
-  if (gfits_scan (header, "CTYPE2", "%s", 1, coords[0].ctype)) {
-    status  = gfits_scan (header, "CRVAL1", "%lf", 1, &coords[0].crval1);
-    status &= gfits_scan (header, "CRPIX1", "%f", 1, &coords[0].crpix1);
-    status &= gfits_scan (header, "CRVAL2", "%lf", 1, &coords[0].crval2);  
-    status &= gfits_scan (header, "CRPIX2", "%f", 1, &coords[0].crpix2);
-
-    if (gfits_scan (header, "CDELT1", "%f", 1, &coords[0].cdelt1)) {
-      status &= gfits_scan (header, "CDELT2", "%f", 1, &coords[0].cdelt2);
-      if (gfits_scan (header, "CROTA2", "%lf", 1, &rotate)) {
-	Lambda = coords[0].cdelt2 / coords[0].cdelt1;
-	coords[0].pc1_1 =  cos(rotate*RAD_DEG);
-	coords[0].pc1_2 = -sin(rotate*RAD_DEG) * Lambda;
-	coords[0].pc2_1 =  sin(rotate*RAD_DEG) / Lambda;
-	coords[0].pc2_2 =  cos(rotate*RAD_DEG);
-      }
-      if (gfits_scan (header, "PC001001", "%f", 1, &coords[0].pc1_1)) {
-	status &= gfits_scan (header, "PC001002", "%f", 1, &coords[0].pc1_2);
-	status &= gfits_scan (header, "PC002001", "%f", 1, &coords[0].pc2_1);
-	status &= gfits_scan (header, "PC002002", "%f", 1, &coords[0].pc2_2);
-      }
+  mode = COORD_TYPE_NONE;
+  {    
+    int haveCTYPE, haveCDELT, haveCROTA, haveCDij, havePCij, haveRAo;
+    float tmp;
+    char stmp[80];
+    
+    // there are a few different representations for scale and rotation.  choose an appropriate
+    // set: (CDELTi + CROTAi), (CDELTi + PCij), (CDij), 
+
+    haveCTYPE = gfits_scan (header, "CTYPE2",   "%s", 1, stmp);
+    haveCDELT = gfits_scan (header, "CDELT1",   "%f", 1, &tmp);
+    haveCROTA = gfits_scan (header, "CROTA1",   "%f", 1, &tmp);
+    haveCDij  = gfits_scan (header, "CD1_1",    "%f", 1, &tmp);
+    havePCij  = gfits_scan (header, "PC001001", "%f", 1, &tmp);
+    haveRAo   = gfits_scan (header, "RA_O",     "%f", 1, &tmp);
+    
+    if (haveCTYPE && havePCij  && haveCDELT) { mode = COORD_TYPE_PC;   goto gotit; }
+    if (haveCTYPE && haveCROTA && haveCDELT) { mode = COORD_TYPE_ROT;  goto gotit; }
+    if (haveCTYPE && haveCDij)               { mode = COORD_TYPE_CD;   goto gotit; }
+    if (haveRAo)                             { mode = COORD_TYPE_LIN;  goto gotit; }
+    // fprintf (stderr, "no valid WCS keywords\n");
+    return (FALSE);
+  }
+  
+gotit:
+
+  status = TRUE; 
+  switch (mode) {
+    case COORD_TYPE_PC:
+      status &= gfits_scan (header, "CTYPE2", 	"%s",  1, coords[0].ctype);
+      status &= gfits_scan (header, "CRVAL1", 	"%lf", 1, &coords[0].crval1);
+      status &= gfits_scan (header, "CRPIX1", 	"%f",  1, &coords[0].crpix1);
+      status &= gfits_scan (header, "CRVAL2", 	"%lf", 1, &coords[0].crval2);  
+      status &= gfits_scan (header, "CRPIX2", 	"%f",  1, &coords[0].crpix2);
+
+      status &= gfits_scan (header, "CDELT1", 	"%f",  1, &coords[0].cdelt1);
+      status &= gfits_scan (header, "CDELT2", 	"%f",  1, &coords[0].cdelt2);
+      status &= gfits_scan (header, "PC001001", "%f",  1, &coords[0].pc1_1);
+      status &= gfits_scan (header, "PC001002", "%f",  1, &coords[0].pc1_2);
+      status &= gfits_scan (header, "PC002001", "%f",  1, &coords[0].pc2_1);
+      status &= gfits_scan (header, "PC002002", "%f",  1, &coords[0].pc2_2);
 
       /* set NPLYTERM based on header.  if NPLYTERM is missing, it should have a 
@@ -490,24 +513,48 @@
 	  break;
       }
-    } else {
-      if (gfits_scan (header, "CD1_1", "%f", 1, &coords[0].pc1_1)) {
-	status &= gfits_scan (header, "CD1_2", "%f", 1, &coords[0].pc1_2);
-	status &= gfits_scan (header, "CD2_1", "%f", 1, &coords[0].pc2_1);
-	status &= gfits_scan (header, "CD2_2", "%f", 1, &coords[0].pc2_2);
-	/* renormalize */
-	scale = hypot (coords[0].pc1_1, coords[0].pc1_2);
-	coords[0].cdelt1 = coords[0].cdelt2 = scale;
-	coords[0].pc1_1 /= scale;
-	coords[0].pc1_2 /= scale;
-	coords[0].pc2_1 /= scale;
-	coords[0].pc2_2 /= scale;
-      } else {
-	status = FALSE;
-      }
-    }
-  } else {
-    /* some of my thesis data uses this simple linear model - convert on read? */
-    if (gfits_scan (header, "RA_O", "%lf", 1, &coords[0].crval1)) {
-      status  = gfits_scan (header, "RA_X", "%f", 1, &coords[0].pc1_1);
+      break;
+
+    case COORD_TYPE_ROT:
+      status &= gfits_scan (header, "CTYPE2", "%s",  1, coords[0].ctype);
+      status &= gfits_scan (header, "CRVAL1", "%lf", 1, &coords[0].crval1);
+      status &= gfits_scan (header, "CRPIX1", "%f",  1, &coords[0].crpix1);
+      status &= gfits_scan (header, "CRVAL2", "%lf", 1, &coords[0].crval2);  
+      status &= gfits_scan (header, "CRPIX2", "%f",  1, &coords[0].crpix2);
+
+      status &= gfits_scan (header, "CDELT1", "%f", 1, &coords[0].cdelt1);
+      status &= gfits_scan (header, "CDELT2", "%f", 1, &coords[0].cdelt2);
+
+      status &= gfits_scan (header, "CROTA2", "%lf", 1, &rotate);
+      Lambda = coords[0].cdelt2 / coords[0].cdelt1;
+      coords[0].pc1_1 =  cos(rotate*RAD_DEG);
+      coords[0].pc1_2 = -sin(rotate*RAD_DEG) * Lambda;
+      coords[0].pc2_1 =  sin(rotate*RAD_DEG) / Lambda;
+      coords[0].pc2_2 =  cos(rotate*RAD_DEG);
+      break;
+
+    case COORD_TYPE_CD:
+      status &= gfits_scan (header, "CTYPE2", "%s",  1, coords[0].ctype);
+      status &= gfits_scan (header, "CRVAL1", "%lf", 1, &coords[0].crval1);
+      status &= gfits_scan (header, "CRPIX1", "%f",  1, &coords[0].crpix1);
+      status &= gfits_scan (header, "CRVAL2", "%lf", 1, &coords[0].crval2);  
+      status &= gfits_scan (header, "CRPIX2", "%f",  1, &coords[0].crpix2);
+
+      status &= gfits_scan (header, "CD1_1", "%f", 1, &coords[0].pc1_1);
+      status &= gfits_scan (header, "CD1_2", "%f", 1, &coords[0].pc1_2);
+      status &= gfits_scan (header, "CD2_1", "%f", 1, &coords[0].pc2_1);
+      status &= gfits_scan (header, "CD2_2", "%f", 1, &coords[0].pc2_2);
+      /* renormalize */
+      scale = hypot (coords[0].pc1_1, coords[0].pc1_2);
+      coords[0].cdelt1 = coords[0].cdelt2 = scale;
+      coords[0].pc1_1 /= scale;
+      coords[0].pc1_2 /= scale;
+      coords[0].pc2_1 /= scale;
+      coords[0].pc2_2 /= scale;
+      break;
+
+    case COORD_TYPE_LIN:
+      /* some of my thesis data uses this simple linear model - convert on read? */
+      status &= gfits_scan (header, "RA_O", "%lf", 1, &coords[0].crval1);
+      status &= gfits_scan (header, "RA_X", "%f", 1, &coords[0].pc1_1);
       status &= gfits_scan (header, "RA_Y", "%f", 1, &coords[0].pc1_2);
       status &= gfits_scan (header, "DEC_O", "%lf", 1, &coords[0].crval2);  
@@ -517,6 +564,7 @@
       coords[0].cdelt1 = coords[0].cdelt2 = 1.0;
       strcpy (coords[0].ctype, "GENE");
-    }
-  }
+      break;
+  }
+
   if (status) {
     if (!gfits_scan (header, "EQUINOX", "%lf", 1, &equinox)) {
@@ -529,6 +577,7 @@
     } 
   }
+
   if (!status) {
-    fprintf (stderr, "error getting all elements for coordinate mode %s\n", coords[0].ctype);
+    // fprintf (stderr, "error getting all elements for coordinate mode %s\n", coords[0].ctype);
     coords[0].crval1 = coords[0].crpix1 = coords[0].cdelt1 = 0.0;
     coords[0].crval2 = coords[0].crpix2 = coords[0].cdelt2 = 0.0;
