Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/LoadDataPMM.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/LoadDataPMM.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/LoadDataPMM.c	(revision 37386)
@@ -193,5 +193,5 @@
 
     // XXX for now, we define a totally fake coordinate system centered on the plate center
-    strcpy (image[0].coords.ctype, "DEC--TAN");
+    InitCoords (&image[0].coords, "DEC--TAN");
     
     image[0].coords.crval1  = pmm_get_ra (RA);
@@ -203,12 +203,4 @@
     image[0].coords.crpix2 = 0.5*PLATE_NY;
     image[0].coords.cdelt1 = image[0].coords.cdelt2 = 0.9 / 3600.0;
-
-    image[0].coords.pc1_1 = 0.0;
-    image[0].coords.pc1_2 = 1.0;
-    image[0].coords.pc2_1 = 1.0;
-    image[0].coords.pc2_2 = 0.0;
-
-    image[0].coords.Npolyterms = 0;
-    memset (image[0].coords.polyterms, 0, 2*7*sizeof(float));
 
     image[0].NX = PLATE_NX;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/ReadStarsSDSS.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/ReadStarsSDSS.c	(revision 37386)
@@ -201,20 +201,10 @@
     
     // XXX for now, we define a totally fake coordinate system centered on the first listed star
-    strcpy (images[N].coords.ctype, "DEC--TAN");
-    
+    InitCoords (&images[N].coords, "DEC--TAN");
     images[N].coords.crval1 = stars[0].average.R;
     images[N].coords.crval2 = stars[0].average.D;
-    
     images[N].coords.crpix1 = stars[0].measure.Xccd;
     images[N].coords.crpix2 = stars[0].measure.Yccd;
     images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
-
-    images[N].coords.pc1_1 = 0.0;
-    images[N].coords.pc1_2 = 1.0;
-    images[N].coords.pc2_1 = 1.0;
-    images[N].coords.pc2_2 = 0.0;
-
-    images[N].coords.Npolyterms = 0;
-    memset (images[N].coords.polyterms, 0, 2*7*sizeof(float));
 
     images[N].NX = 2048;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/fakeimage.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/fakeimage.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/fakeimage.c	(revision 37386)
@@ -3,5 +3,5 @@
 Image *fakeimage (char *rootname, off_t *Nimage, int photcode) {
 
-  int i, j, Nx, Ny, Nchips;
+  int i, Nx, Ny, Nchips;
   double pltscale, pixscale;
   double Rmin, Rmax, Dmin, Dmax;
@@ -33,9 +33,7 @@
 
   /* create a mosaic distortion structure */
-  strcpy (MOSAIC.ctype, "DEC--DIS");
+  InitCoords (&MOSAIC, "DEC--DIS");
   MOSAIC.crval1 = FAKE_RA;
   MOSAIC.crval2 = FAKE_DEC;
-  
-  MOSAIC.crpix1 = MOSAIC.crpix2 = 0.0;
   
   /* mosaic 'pixels' are millimeters */
@@ -49,8 +47,4 @@
 
   MOSAIC.Npolyterms = 3;
-  for (i = 0; i < 7; i++) {
-    MOSAIC.polyterms[i][0] = 0;
-    MOSAIC.polyterms[i][1] = 0;
-  }
   ScanConfig (config, "DPLATE_X",   "%lf", 0, &pltscale);
   MOSAIC.polyterms[3][0] = pltscale;  // L : X^3 Y^0
@@ -83,22 +77,11 @@
     strcpy (image[i+1].name, name);
 
-    strcpy (image[i+1].coords.ctype, "DEC--WRP");
+    InitCoords (&image[i+1].coords, "DEC--WRP");
     
     image[i+1].coords.crval1 = dX*pixscale;
     image[i+1].coords.crval2 = dY*pixscale;
-    
-    image[i+1].coords.crpix1 = image[i+1].coords.crpix2 = 0.0;
+
     image[i+1].coords.cdelt1 = image[i+1].coords.cdelt2 = pixscale;
 
-    image[i+1].coords.pc1_1 = 1.0;
-    image[i+1].coords.pc1_2 = 0.0;
-    image[i+1].coords.pc2_1 = 0.0;
-    image[i+1].coords.pc2_2 = 1.0;
-
-    image[i+1].coords.Npolyterms = 0;
-    for (j = 0; j < 7; j++) {
-      image[i+1].coords.polyterms[j][0] = 0;
-      image[i+1].coords.polyterms[j][1] = 0;
-    }
     image[i+1].coords.mosaic = &MOSAIC;
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches.c	(revision 37386)
@@ -53,4 +53,5 @@
    * coordops.update.c).  We use the center of the region (catalog) for crval1,2. 
    */
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -59,11 +60,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
   /* build spatial index (RA sort) referencing input array sequence */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest.c	(revision 37386)
@@ -53,4 +53,5 @@
    * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    */
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -59,11 +60,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
   /* build spatial index (RA sort) referencing input array sequence */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest_refstars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_closest_refstars.c	(revision 37386)
@@ -47,4 +47,5 @@
    * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    */
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -53,11 +54,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0.0;
-  tcoords.crpix2 = 0.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 = 0;
-  strcpy (tcoords.ctype, "DEC--ARC");
   
   /* build spatial index (RA sort) referencing input array sequence */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_refstars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_refstars.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/find_matches_refstars.c	(revision 37386)
@@ -51,12 +51,8 @@
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is catalog center */
+  InitCoords (&tcoords, "DEC--ZEA");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   tcoords.crval2 = 0.5*(region[0].Dmin + region[0].Dmax);
-  tcoords.crpix1 = tcoords.crpix2 = 0.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;
-  strcpy (tcoords.ctype, "DEC--ZEA");
-  tcoords.Npolyterms = 0;
   
   for (i = 0; i < Nstars; i++) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadsupercos_plates.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadsupercos_plates.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/loadsupercos_plates.c	(revision 37386)
@@ -118,5 +118,5 @@
 
     // for now, we define a fake coordinate system based on the boresite center
-    strcpy (image[Nimage].coords.ctype, "DEC--TAN");
+    InitCoords (&image[Nimage].coords, "DEC--TAN");
     
     image[Nimage].coords.crval1 = RAo;
@@ -126,12 +126,4 @@
     image[Nimage].coords.crpix2 = 0.5*image[Nimage].NY;
     image[Nimage].coords.cdelt1 = image[Nimage].coords.cdelt2 = scale;
-
-    image[Nimage].coords.pc1_1 = 0.0;
-    image[Nimage].coords.pc1_2 = 1.0;
-    image[Nimage].coords.pc2_1 = 1.0;
-    image[Nimage].coords.pc2_2 = 0.0;
-
-    image[Nimage].coords.Npolyterms = 0;
-    memset (image[Nimage].coords.polyterms, 0, 2*7*sizeof(float));
 
     Nimage ++;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/mkcmf.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/mkcmf.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/mkcmf.c	(revision 37386)
@@ -200,5 +200,5 @@
     
   /* bore site center guess */
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
   coords.crval1 = RA;
   coords.crval2 = DEC;
@@ -208,10 +208,4 @@
   coords.cdelt1 = 0.25/3600.0;
   coords.cdelt2 = 0.25/3600.0;
-
-  coords.pc1_1  = 1;
-  coords.pc2_2  = 1;
-  coords.pc1_2  = 0;
-  coords.pc2_1  = 0;
-  coords.Npolyterms = 1;
 
   // load stars and generate complete output fields
Index: /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/sky_tessalation.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/sky_tessalation.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/addstar/src/sky_tessalation.c	(revision 37386)
@@ -581,4 +581,7 @@
 
   memset (rectangle, 0, sizeof(SkyRectangle));
+
+  InitCoords (&rectangle[0].coords, "DEC--TAN");
+
   rectangle[0].coords.crval1 = CENTER_RA;
   rectangle[0].coords.crval2 = CENTER_DEC;
@@ -609,6 +612,4 @@
   rectangle[0].coords.cdelt2 = SCALE / 3600.0;
 
-  strcpy (rectangle[0].coords.ctype, "DEC--TAN");
-
   rectangle[0].NX = NX;
   rectangle[0].NY = NY;
@@ -699,12 +700,10 @@
   for (i = 0; i < nRA; i++) {
     memset (&ring[i], 0, sizeof(SkyRectangle));
-    memset (&ring[i].coords, 0, sizeof(Coords));
+
+    InitCoords (&ring[i].coords, "DEC--TAN");
     ring[i].coords.crval1 = i*dRA;
     ring[i].coords.crval2 = dec;
 
     ring[i].coords.pc1_1 = +1.0 * X_PARITY;
-    ring[i].coords.pc1_2 = +0.0;
-    ring[i].coords.pc2_1 = -0.0;
-    ring[i].coords.pc2_2 = +1.0;
   
     // range values are in projected degrees
@@ -718,6 +717,4 @@
     ring[i].coords.cdelt1 = SCALE / 3600.0;
     ring[i].coords.cdelt2 = SCALE / 3600.0;
-
-    strcpy (ring[i].coords.ctype, "DEC--TAN");
 
     ring[i].NX = NX*(1.0 + PADDING);
@@ -771,5 +768,5 @@
 
       memset (&ring[N], 0, sizeof(SkyRectangle));
-      memset (&ring[N].coords, 0, sizeof(Coords));
+      InitCoords (&ring[N].coords, "DEC--TAN");
 
       ring[N].coords.crval1 = ra / d2r;
@@ -779,7 +776,4 @@
 
       ring[N].coords.pc1_1 = +1.0 * X_PARITY;
-      ring[N].coords.pc1_2 = +0.0;
-      ring[N].coords.pc2_1 = -0.0;
-      ring[N].coords.pc2_2 = +1.0;
   
       // range values are in projected degrees
@@ -793,6 +787,4 @@
       ring[N].coords.cdelt1 = SCALE / 3600.0;
       ring[N].coords.cdelt2 = SCALE / 3600.0;
-
-      strcpy (ring[N].coords.ctype, "DEC--TAN");
 
       ring[N].NX = NX*(1.0 + PADDING);
@@ -1099,12 +1091,6 @@
 
   ALLOCATE (refcoords, Coords, 1);
-  refcoords[0].crval1 = refcoords[0].crval2 = 0.0;
-  refcoords[0].crpix1 = refcoords[0].crpix2 = 0.0;
+  InitCoords (refcoords, "DEC--TAN");
   refcoords[0].cdelt1 = refcoords[0].cdelt2 = scale / 3600;
-  refcoords[0].pc1_1 = refcoords[0].pc2_2 = 1.0;
-  refcoords[0].pc1_2 = refcoords[0].pc2_1 = 0.0;
-  refcoords[0].Npolyterms = 0;
-  memset (refcoords[0].polyterms, 0, 14*sizeof(float));
-  strcpy (refcoords[0].ctype, "DEC--TAN");
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20140904/Ohana/src/checkastro/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/checkastro/src/bcatalog.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/checkastro/src/bcatalog.c	(revision 37386)
@@ -191,13 +191,8 @@
   /* project coordinates to a plane centered on the object with units of arcsec */
   Coords coords;
+  InitCoords (&coords, "DEC--SIN");
   coords.crval1 = Rc;
   coords.crval2 = Dc;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   // convert all average R,D values to X,Y:
Index: /branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 37386)
@@ -64,4 +64,6 @@
    * coordops.update.c).  We use the center of the region (catalog) for crval1,2. 
    */
+
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -70,11 +72,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
   if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/fixcat/src/gcatstats.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/fixcat/src/gcatstats.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/fixcat/src/gcatstats.c	(revision 37386)
@@ -46,11 +46,8 @@
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is center of field  */
+  InitCoords (&catstats[0].coords, "DEC--TAN");
   catstats[0].coords.crval1 = RaCenter;
   catstats[0].coords.crval2 = DecCenter;
-  catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
   catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
-  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
-  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
-  strcpy (catstats[0].coords.ctype, "DEC--TAN");
 
   X1 = catstats[0].X;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gfitpoly.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gfitpoly.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gfitpoly.c	(revision 37386)
@@ -261,4 +261,6 @@
     det = 1.0 / (a1*b2 - a2*b1);
 
+    InitCoords (coords, "DEC--PLY");
+
     coords[0].pc1_1 = p11*a1 + p12*b1*(S2/S1);
     coords[0].pc2_1 = p21*a1 + p22*b1*(S2/S1);
@@ -273,5 +275,4 @@
 
     coords[0].Npolyterms = NORDER;
-    strcpy (coords[0].ctype, "DEC--PLY");
 
     /* generate higher order terms from vector */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gstars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gstars.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/gastro/src/gstars.c	(revision 37386)
@@ -79,9 +79,8 @@
   if (!strcasecmp (ROUGH_ASTROMETRY, "config")) {
     /* default values for coords */
-    strcpy (coords[0].ctype, "DEC--TAN");
+    InitCoords (coords, "DEC--TAN");
     coords[0].pc1_1 = CCD_PC1_1; coords[0].pc1_2 = CCD_PC1_2;
     coords[0].pc2_1 = CCD_PC2_1; coords[0].pc2_2 = CCD_PC2_2;
     coords[0].cdelt1 = coords[0].cdelt2 = ASEC_PIX / 3600.0;
-    coords[0].Npolyterms = 0;
     coords[0].crpix1 = 0.5*(*NX);
     coords[0].crpix2 = 0.5*(*NY);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gproject2.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gproject2.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gproject2.c	(revision 37386)
@@ -19,22 +19,10 @@
 
   /* create Tangent Plane to Sky transformation from input coords */
-  strcpy (TPtoSky.ctype, coords[0].ctype);
+  InitCoords (&TPtoSky, coords[0].ctype);
   TPtoSky.crval1 = coords[0].crval1;
   TPtoSky.crval2 = coords[0].crval2;
 
-  TPtoSky.cdelt1 = TPtoSky.cdelt2 = 1;
-  TPtoSky.crpix1 = TPtoSky.crpix2 = 0;
-  TPtoSky.pc1_1 = TPtoSky.pc2_2 = 1;
-  TPtoSky.pc1_2 = TPtoSky.pc2_1 = 0;
-  TPtoSky.Npolyterms = 0;
-  for (i = 0; i < 7; i++) {
-    TPtoSky.polyterms[i][0] = 0;
-    TPtoSky.polyterms[i][1] = 0;
-  }
-
   /* create Focal Plane to Tangent Plane transformation from input coords */
-  strcpy (FPtoTP.ctype, "FP---PLY");
-  FPtoTP.crval1 = FPtoTP.crval2 = 0;
-
+  InitCoords (&FPtoTP, "FP---PLY");
   FPtoTP.cdelt1 = coords[0].cdelt1;
   FPtoTP.cdelt2 = coords[0].cdelt2;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gstars2.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gstars2.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/gastro2/src/gstars2.c	(revision 37386)
@@ -28,9 +28,8 @@
 
   /* default values for coords */
-  strcpy (Target[0].coords.ctype, "DEC--TAN");
+  InitCoords (&Target[0].coords, "DEC--TAN");
   Target[0].coords.pc1_1 = CCD_PC1_1; Target[0].coords.pc1_2 = CCD_PC1_2;
   Target[0].coords.pc2_1 = CCD_PC2_1; Target[0].coords.pc2_2 = CCD_PC2_2;
   Target[0].coords.cdelt1 = Target[0].coords.cdelt2 = ASEC_PIX / 3600.0;
-  Target[0].coords.Npolyterms = 0;
   Target[0].coords.crpix1 = 0.5*NX;
   Target[0].coords.crpix2 = 0.5*NY;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/getstar/src/MatchImages.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/getstar/src/MatchImages.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/getstar/src/MatchImages.c	(revision 37386)
@@ -23,20 +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")) {
     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");
   }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Graphs.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Graphs.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Graphs.c	(revision 37386)
@@ -57,12 +57,5 @@
   graph[0].data.flipnorth = FALSE;	// +North = +Y by default
 
-  graph[0].data.coords.pc1_1 = graph[0].data.coords.pc2_2 = 1.0;
-  graph[0].data.coords.pc1_2 = graph[0].data.coords.pc2_1 = 0.0;
-  graph[0].data.coords.crval1 = 0.0;
-  graph[0].data.coords.crval2 = 0.0;
-  graph[0].data.coords.crpix1 = 0.0;
-  graph[0].data.coords.crpix2 = 0.0;
-  graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
-  strcpy (graph[0].data.coords.ctype, "DEC--LIN");
+  InitCoords (&graph[0].data.coords, "DEC--LIN");
   strcpy (graph[0].data.axis, "2222");
   strcpy (graph[0].data.ticks, "2222");
Index: /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Image.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Image.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/kapa2/src/Image.c	(revision 37386)
@@ -11,13 +11,5 @@
   channel->slope = 1;
 
-  channel->coords.pc1_1 = channel->coords.pc2_2 = 1.0;
-  channel->coords.pc1_2 = channel->coords.pc2_1 = 0.0;
-  channel->coords.crval1 = 0.0;
-  channel->coords.crval2 = 0.0;
-  channel->coords.crpix1 = 0.0;
-  channel->coords.crpix2 = 0.0;
-  channel->coords.cdelt1 = channel->coords.cdelt2 = 1.0;
-  strcpy (channel->coords.ctype, "DEC--LIN");
-  channel->coords.Npolyterms = 0;
+  InitCoords (&channel->coords, "DEC--LIN");
 
   channel->matrix.datasize = 0; /* a flag to show there is no data in the matrix */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/Makefile.Targets	(revision 37386)
@@ -1,4 +1,5 @@
 AOBJS = \
 $(ASRC)/coords-disk.$(ARCH).o \
+$(ASRC)/AstromOffsetMap_Disk.$(ARCH).o \
 $(ASRC)/average.$(ARCH).o \
 $(ASRC)/average-loneos.$(ARCH).o \
@@ -98,4 +99,5 @@
 AINCS = \
 $(AINC)/coords-disk.h \
+$(AINC)/AstromOffsetMap_Disk.h \
 $(AINC)/average.h \
 $(AINC)/average-loneos.h \
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libautocode/def/common.h	(revision 37386)
@@ -34,80 +34,4 @@
 # define DVO_IMAGE_NAME_LEN 117
 
-typedef struct {
-  int Nx;
-  int Ny;
-  float *value;
-  float dX;
-  float dY;
-  float Xo;
-  float Yo;
-} ImageMap;
-
-/* Internal version of Coords (see CoordsDisk in libautocode/def/coords-disk.d) */
-typedef struct Coords {
-  double           crval1;               // coordinate at reference pixel
-  double           crval2;               // coordinate at reference pixel
-  float            crpix1;               // coordinate of reference pixel
-  float            crpix2;               // coordinate of reference pixel
-  float            cdelt1;               // degrees per pixel
-  float            cdelt2;               // degrees per pixel
-  float            pc1_1;                // rotation matrix
-  float            pc1_2;                // rotation matrix
-  float            pc2_1;                // rotation matrix
-  float            pc2_2;                // rotation matrix
-  float            polyterms[7][2];      // higher order warping terms
-  char             ctype[15];            // coordinate type
-  char             Npolyterms;           // order of polynomial
-  struct Coords   *mosaic;               // pointer to parent mosaic
-  ImageMap        *imageMap;		 // pointer to image map transformation
-} Coords;
-
-typedef struct Image {
-  Coords           coords;               // astrometric data
-  e_time           tzero;                // readout time (row 0)
-  unsigned int     nstar;                // number of stars on image
-  float            secz;                 // airmass (mag)
-  unsigned short   NX;                   // image width
-  unsigned short   NY;                   // image height
-  float            apmifit;              // aperture correction (mag)
-  float            dapmifit;             // apmifit error (mag)
-  float            Mcal;                 // calibration mag (mag)
-  float            dMcal;                // error on Mcal (mag)
-  short            Xm;                   // image chisq (10*log(value))
-  short            photcode;             // identifier for CCD,
-  float            exptime;              // exposure time (seconds)
-  float            sidtime;              // sidereal time of exposure
-  float            latitude;             // observatory latitude (degrees)
-  float            RAo;                  // image center (degrees)
-  float            DECo;                 // image center (degrees)
-  float            Radius;               // image radius (degrees)
-  float            refColorBlue;         // median astrometry ref color
-  float            refColorRed;          // median astrometry ref color
-  char             name[117];            // name of original image 
-  unsigned char    detection_limit;      // detection limit (10*mag)
-  unsigned char    saturation_limit;     // saturation limit (10*mag)
-  unsigned char    cerror;               // astrometric error (50*arcsec)
-  unsigned char    fwhm_x;               // PSF x width (25*arcsec)
-  unsigned char    fwhm_y;               // PSF y width (25*arcsec)
-  unsigned char    trate;                // scan rate (100 usec/pixel)
-  unsigned char    ccdnum;               // CCD ID number
-  unsigned int     flags;                // image quality flags
-  unsigned int     imageID;              // internal image ID
-  unsigned int     parentID;             // associated ref image
-  unsigned int     externID;             // external image ID
-  unsigned short   sourceID;             // analysis source ID
-  short            nLinkAstrom;          // mean number of matched measurements for astrometry
-  short            nLinkPhotom;          // mean number of matched measurements for astrometry
-  short            ubercalDist;          // distance to nearest ubercal image
-  float            dXpixSys;             // systematic astrometry error in X
-  float            dYpixSys;             // systematic astrometry error in Y
-  float            dMagSys;              // systematic photometry error
-  unsigned short   nFitAstrom;           // number of stars used for astrometry cal
-  unsigned short   nFitPhotom;           // number of stars used for photometry cal
-  unsigned int     photom_map_id;        // reference to 2D zero point map
-  unsigned int     astrom_map_id;        // reference to 2D astrometry map
-  struct Image    *parent;               // pointer to parent mosaic (not save to disk)
-} Image;
-
 /*** rawshort is used to handle the broken pre-autocode photreg tables
      fix the tables and remove this
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/Makefile	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/Makefile	(revision 37386)
@@ -86,4 +86,6 @@
 $(SRC)/skyregion_gsc.$(ARCH).o    \
 $(SRC)/skyregion_ops.$(ARCH).o \
+$(SRC)/AstromOffsetMapIO.$(ARCH).o    \
+$(SRC)/AstromOffsetMapOps.$(ARCH).o \
 $(SRC)/dvo_set_skyregion.$(ARCH).o \
 $(SRC)/dvo_set_catdir.$(ARCH).o \
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/dvo.h	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/dvo.h	(revision 37386)
@@ -36,29 +36,4 @@
 
 typedef enum {DVO_CAT_OPEN_FAIL, DVO_CAT_OPEN_OK, DVO_CAT_OPEN_EMPTY} DVOCatalogOpenModes;
-
-typedef enum {
-  PROJ_NONE, // undefined
-  PROJ_ZEA, // zenithal
-  PROJ_ZPL, // zenithal
-  PROJ_ARC, // zenithal
-  PROJ_STG, // zenithal
-  PROJ_SIN, // zenithal
-  PROJ_TAN, // zenithal
-  PROJ_TNX, // zenithal
-  PROJ_DIS, // zenithal (TAN + polyterms)
-  PROJ_LIN, // cartesian
-  PROJ_PLY, // cartesian
-  PROJ_WRP, // cartesian
-  PROJ_AIT, // pseudocyl
-  PROJ_GLS, // pseudocyl
-  PROJ_PAR, // pseudocyl
-} OhanaProjection;
-
-typedef enum {
-  PROJ_MODE_NONE,
-  PROJ_MODE_CARTESIAN,
-  PROJ_MODE_ZENITHAL,
-  PROJ_MODE_PSEUDOCYL,
-} OhanaProjectionMode;
 
 // these are used as NAN for types of int values
@@ -202,4 +177,22 @@
 } DVOSecfiltFlags;
 
+/* definitions for parallel dvo host information 
+   XXX : need better names (safer namespace)
+*/
+
+typedef enum {
+  DATA_ON_TGT  = 0x01,
+  DATA_ON_BCK  = 0x02,
+  DATA_USE_BCK = 0x04,
+
+  DATA_COPY_FAILURE = 0x80,
+} SkyTableDataFlags;
+
+typedef enum {
+  HOST_STDIN = 0,
+  HOST_STDOUT = 1,
+  HOST_STDERR = 2,
+} HostInfoIOfd;
+
 /*** general dvo structures (internal use only / not IO) ***/
 
@@ -252,22 +245,4 @@
   e_time *tstop;
 } FlatCorrectionTable;
-
-/* definitions for parallel dvo host information 
-   XXX : need better names (safer namespace)
-*/
-
-typedef enum {
-  DATA_ON_TGT  = 0x01,
-  DATA_ON_BCK  = 0x02,
-  DATA_USE_BCK = 0x04,
-
-  DATA_COPY_FAILURE = 0x80,
-} SkyTableDataFlags;
-
-typedef enum {
-  HOST_STDIN = 0,
-  HOST_STDOUT = 1,
-  HOST_STDERR = 2,
-} HostInfoIOfd;
 
 typedef struct {
@@ -738,21 +713,4 @@
 int   gfits_db_free                PROTO((FITS_DB *db));
 
-/* in coords.c, using libautocode/def/coords.d */
-int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
-int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
-int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
-int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
-int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
-int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
-int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
-int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
-int  GetCoords (Coords *coords, Header *header);
-int  PutCoords (Coords *coords, Header *header);
-void RegisterMosaic (Coords *coords);
-void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
-OhanaProjection GetProjection (char *ctype);
-int SetProjection (char *ctype, OhanaProjection proj);
-OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
-
 char *libdvo_version (void);
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/include/libdvo_astro.h	(revision 37386)
@@ -1,16 +1,36 @@
-#ifdef notdef
-# include "external.h"
-# include "shell.h"
-# include "dvomath.h"
-# include "convert.h"
-# include "display.h"
-# include "data.h"
-#endif
+# ifndef LIBDVO_ASTRO_H
+# define LIBDVO_ASTRO_H
 
-# ifndef ASTRO_H
-# define ASTRO_H
+typedef enum {
+  COORD_NONE, 
+  COORD_CELESTIAL, 
+  COORD_GALACTIC, 
+  COORD_ECLIPTIC
+} CoordTransformSystem;
 
-void InitAstro (void);
-void FreeAstro (void);
+typedef enum {
+  PROJ_NONE, // undefined
+  PROJ_ZEA, // zenithal
+  PROJ_ZPL, // zenithal
+  PROJ_ARC, // zenithal
+  PROJ_STG, // zenithal
+  PROJ_SIN, // zenithal
+  PROJ_TAN, // zenithal
+  PROJ_TNX, // zenithal
+  PROJ_DIS, // zenithal (TAN + polyterms)
+  PROJ_LIN, // cartesian
+  PROJ_PLY, // cartesian (allow polyterms)
+  PROJ_WRP, // cartesian (allow polyterms, require mosaic)
+  PROJ_AIT, // pseudocyl
+  PROJ_GLS, // pseudocyl
+  PROJ_PAR, // pseudocyl
+} OhanaProjection;
+
+typedef enum {
+  PROJ_MODE_NONE,
+  PROJ_MODE_CARTESIAN,
+  PROJ_MODE_ZENITHAL,
+  PROJ_MODE_PSEUDOCYL,
+} OhanaProjectionMode;
 
 typedef struct {
@@ -29,8 +49,117 @@
 } CoordTransform;
 
-typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
+typedef struct {
+  int Nx;
+  int Ny;
+  float dX;
+  float dY;
+  float **dXv;
+  float **dYv;
+  unsigned int ID;
+  unsigned int imageID;
+} AstromOffsetMap;
+
+typedef struct {
+  int Nmap;
+  AstromOffsetMap *map;
+  int *IDtoSeq;
+  int MaxID;
+} AstromOffsetTable;
+
+/* Internal version of Coords (see CoordsDisk in libautocode/def/coords-disk.d) */
+typedef struct Coords {
+  double           crval1;               // coordinate at reference pixel
+  double           crval2;               // coordinate at reference pixel
+  float            crpix1;               // coordinate of reference pixel
+  float            crpix2;               // coordinate of reference pixel
+  float            cdelt1;               // degrees per pixel
+  float            cdelt2;               // degrees per pixel
+  float            pc1_1;                // rotation matrix
+  float            pc1_2;                // rotation matrix
+  float            pc2_1;                // rotation matrix
+  float            pc2_2;                // rotation matrix
+  float            polyterms[7][2];      // higher order warping terms
+  char             ctype[15];            // coordinate type
+  char             Npolyterms;           // order of polynomial
+  struct Coords   *mosaic;               // pointer to parent mosaic
+  AstromOffsetMap *offsetMap;		 // pointer to offset map transformation
+} Coords;
+
+typedef struct Image {
+  Coords           coords;               // astrometric data
+  e_time           tzero;                // readout time (row 0)
+  unsigned int     nstar;                // number of stars on image
+  float            secz;                 // airmass (mag)
+  unsigned short   NX;                   // image width
+  unsigned short   NY;                   // image height
+  float            apmifit;              // aperture correction (mag)
+  float            dapmifit;             // apmifit error (mag)
+  float            Mcal;                 // calibration mag (mag)
+  float            dMcal;                // error on Mcal (mag)
+  short            Xm;                   // image chisq (10*log(value))
+  short            photcode;             // identifier for CCD,
+  float            exptime;              // exposure time (seconds)
+  float            sidtime;              // sidereal time of exposure
+  float            latitude;             // observatory latitude (degrees)
+  float            RAo;                  // image center (degrees)
+  float            DECo;                 // image center (degrees)
+  float            Radius;               // image radius (degrees)
+  float            refColorBlue;         // median astrometry ref color
+  float            refColorRed;          // median astrometry ref color
+  char             name[117];            // name of original image 
+  unsigned char    detection_limit;      // detection limit (10*mag)
+  unsigned char    saturation_limit;     // saturation limit (10*mag)
+  unsigned char    cerror;               // astrometric error (50*arcsec)
+  unsigned char    fwhm_x;               // PSF x width (25*arcsec)
+  unsigned char    fwhm_y;               // PSF y width (25*arcsec)
+  unsigned char    trate;                // scan rate (100 usec/pixel)
+  unsigned char    ccdnum;               // CCD ID number
+  unsigned int     flags;                // image quality flags
+  unsigned int     imageID;              // internal image ID
+  unsigned int     parentID;             // associated ref image
+  unsigned int     externID;             // external image ID
+  unsigned short   sourceID;             // analysis source ID
+  short            nLinkAstrom;          // mean number of matched measurements for astrometry
+  short            nLinkPhotom;          // mean number of matched measurements for astrometry
+  short            ubercalDist;          // distance to nearest ubercal image
+  float            dXpixSys;             // systematic astrometry error in X
+  float            dYpixSys;             // systematic astrometry error in Y
+  float            dMagSys;              // systematic photometry error
+  unsigned short   nFitAstrom;           // number of stars used for astrometry cal
+  unsigned short   nFitPhotom;           // number of stars used for photometry cal
+  unsigned int     photom_map_id;        // reference to 2D zero point map
+  unsigned int     astrom_map_id;        // reference to 2D astrometry map
+  struct Image    *parent;               // pointer to parent mosaic (not save to disk)
+} Image;
 
 CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
 int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
 
+/* in coords.c */
+void InitCoords (Coords *coords, char *projection);
+int  XY_to_LM (double *L, double *M, double x,  double y,   Coords *coords);
+int  LM_to_XY (double *x,  double *y,   double L, double M, Coords *coords);
+int  RD_to_LM (double *L, double *M, double ra,  double dec,   Coords *coords);
+int  LM_to_RD (double *ra, double *dec,   double L, double M, Coords *coords);
+int  XY_to_RD (double *ra, double *dec, double x,  double y,   Coords *coords);
+int  RD_to_XY (double *x,  double *y,   double ra, double dec, Coords *coords);
+int  fXY_to_RD (float *ra, float *dec, double x,  double y,   Coords *coords);
+int  fRD_to_XY (float *x,  float *y,   double ra, double dec, Coords *coords);
+int  GetCoords (Coords *coords, Header *header);
+int  PutCoords (Coords *coords, Header *header);
+void coords_precess (double *ra, double *dec, double in_epoch, double out_epoch);
+OhanaProjection GetProjection (char *ctype);
+int SetProjection (char *ctype, OhanaProjection proj);
+OhanaProjectionMode GetProjectionMode (OhanaProjection proj);
+
+/* in AstromOffsetMapIO.c */
+AstromOffsetTable *AstromOffsetMapLoad (char *filename, int VERBOSE);
+int AstromOffsetMapSave (AstromOffsetTable *table, char *filename);
+AstromOffsetTable *AstromOffsetMapToTable(AstromOffsetMap_Disk_6x6 *map_disk, off_t Nmap);
+AstromOffsetMap_Disk_6x6 *AstromOffsetTableToMap(AstromOffsetTable *table, off_t *Nmap);
+
+/* in AstromOffsetMapOps.c */
+float AstromOffsetMapValue (AstromOffsetMap *map, float x, float y, int xdir);
+int AstromOffsetMapFit (AstromOffsetMap *map, float *x, float *y, float *f, int Npts, int xdir);
+
 # endif
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageMetadataSelection.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageMetadataSelection.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageMetadataSelection.c	(revision 37386)
@@ -13,18 +13,10 @@
   
   /* field defines a frame with 0,0 at the field center, and 1 arcsec / pixel */
-  field.crpix1 = field.crpix2 = 0.0;
+  InitCoords (&field, "DEC--SIN");
   field.cdelt1 = field.cdelt2 = 1.0 / 3600;
-  field.pc1_1  = field.pc2_2  = 1.0;
-  field.pc1_2  = field.pc2_1  = 0.0;
-  field.Npolyterms = 0;
-  strcpy (field.ctype, "DEC--SIN");
 
   /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
-  mosaic.crpix1 = mosaic.crpix2 = 0.0;
+  InitCoords (&mosaic, "DEC--SIN");
   mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
-  mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
-  mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
-  mosaic.Npolyterms = 0;
-  strcpy (mosaic.ctype, "DEC--SIN");
 
   if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageSelection.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageSelection.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/ImageSelection.c	(revision 37386)
@@ -22,11 +22,7 @@
 
   if (mosaicMode) {
-      /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
-      mosaic.crpix1 = mosaic.crpix2 = 0.0;
-      mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
-      mosaic.pc1_1  = mosaic.pc2_2  = 1.0;
-      mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
-      mosaic.Npolyterms = 0;
-      strcpy (mosaic.ctype, "DEC--SIN");
+    /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
+    InitCoords (&mosaic, "DEC--SIN");
+    mosaic.cdelt1 = mosaic.cdelt2 = 1.0 / 3600;
   }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coord_systems.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coord_systems.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coord_systems.c	(revision 37386)
@@ -1,4 +1,3 @@
 # include "dvo.h"
-# include "libdvo_astro.h"
     
 CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/coordops.c	(revision 37386)
@@ -3,23 +3,31 @@
 /* note that Coords.ctype carries the DEC (ctype2) value */
 
-// this was previously coded not-thread-safe: I've added the mosaic link directly to the Coords structure
-# if (0)
-static Coords mosaic;
-static int gotMosaic = FALSE;
-
-void RegisterMosaic (Coords *coords) {
-  mosaic = *coords;
-  gotMosaic = TRUE;
-}
-
-int isRegisteredMosaic () {
-  return (gotMosaic);
-}
-
-int GetMosaicCoords (Coords *coords) {
-  *coords = mosaic;
-  return (TRUE);
-}
-# endif
+// default coordinates have unit scale and no rotation
+void InitCoords (Coords *coords, char *projection) {
+  coords->crval1 = 0.0;
+  coords->crval2 = 0.0;
+  coords->crpix1 = 0.0;
+  coords->crpix2 = 0.0;
+
+  coords->cdelt1 = 1.0;
+  coords->cdelt2 = 1.0;
+
+  coords->pc1_1 = 1.0; // EW is flipped relative to sky parity (dRA/dX > 0)
+  coords->pc2_2 = 1.0;
+  coords->pc2_1 = 0.0;
+  coords->pc1_2 = 0.0;
+
+  coords->Npolyterms = 1;
+  coords->mosaic = NULL;
+  coords->offsetMap = NULL;
+
+  memset (coords->polyterms, 0, 7*2*sizeof(float));
+
+  if (projection) {
+    strcpy (coords->ctype, projection);
+  } else {
+    strcpy (coords->ctype, "NONE");
+  }
+} 
 
 int XY_to_LM (double *L, double *M, double x, double y, Coords *coords) {
@@ -31,4 +39,15 @@
   proj = GetProjection (coords[0].ctype);
   mode = GetProjectionMode (proj);
+
+  // if we have an image map, it should be applied to the pixel coordinates 
+  // before anything else is done.  It is easier to invert the map if it is 
+  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
+  if (coords[0].Npolyterms == -1) {
+    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
+    float dX = AstromOffsetMapValue (coords->offsetMap, x, y, TRUE);
+    float dY = AstromOffsetMapValue (coords->offsetMap, x, y, FALSE);
+    x += dX;
+    y += dY;
+  }
 
   /** convert pixel coordinates to cartesian system **/
@@ -390,4 +409,40 @@
   *y = Yo / coords[0].cdelt2 + coords[0].crpix2;
 
+  // if we have an image map, it should be applied to the pixel coordinates 
+  // after anything else is done.  It is easier to invert the map if it is 
+  // of the form (dX,dY) = f(X,Y), then if (dL,dM) = f(X,Y).
+  if (coords[0].Npolyterms == -1) {
+    myAssert (coords[0].offsetMap, "offsetMap is requested by not defined");
+
+    double xraw = *x;
+    double yraw = *y;
+
+    double dXo = 0.0;
+    double dYo = 0.0;
+
+    int i;
+    for (i = 0; i < 4; i++) {
+      double dX = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, TRUE);
+      double dY = AstromOffsetMapValue (coords->offsetMap, xraw, yraw, FALSE);
+
+      dX -= dXo;
+      dY -= dYo;
+
+      xraw -= dX;
+      yraw -= dY;
+
+      dXo += dX;
+      dYo += dY;
+    }
+
+    *x = xraw;
+    *y = yraw;
+
+    // I need to iterate since the position at which I have first made the correction is
+    // not the true position.  but if dX,dY is small and the gradient of dX,dY is also
+    // small, then even a single pass gets us close.
+
+    // XXX test this and use a while (hypot(dX,dY) > XXX) condition 
+  }
   return (TRUE);
 }
@@ -458,10 +513,6 @@
   
   rotate = 0.0;
-  coords[0].crval1 = coords[0].crpix1 = coords[0].cdelt1 = 0.0;
-  coords[0].crval2 = coords[0].crpix2 = coords[0].cdelt2 = 0.0;
-  coords[0].pc1_1 = coords[0].pc2_2 = 1.0;
-  coords[0].pc2_1 = coords[0].pc1_2 = 0.0;
-  coords[0].Npolyterms = 1;
-  strcpy (coords[0].ctype, "NONE");
+
+  InitCoords (coords, NULL);
   
   mode = COORD_TYPE_NONE;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c	(revision 37386)
@@ -222,5 +222,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c	(revision 37386)
@@ -217,5 +217,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c	(revision 37386)
@@ -21,5 +21,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c	(revision 37386)
@@ -148,5 +148,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c	(revision 37386)
@@ -241,5 +241,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c	(revision 37386)
@@ -252,5 +252,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c	(revision 37386)
@@ -262,5 +262,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c	(revision 37386)
@@ -301,6 +301,6 @@
     // this is only save because the initial 120 bytes in Coords match CoordsDisk
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
-    out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.mosaic    = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN > DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c	(revision 37386)
@@ -679,5 +679,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN == DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_elixir.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_elixir.c	(revision 37386)
@@ -213,5 +213,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_loneos.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_loneos.c	(revision 37386)
@@ -191,5 +191,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c	(revision 37386)
@@ -230,5 +230,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c	(revision 37386)
@@ -230,5 +230,5 @@
     memcpy (&out[i].coords, &in[i].coords, sizeof(CoordsDisk));
     out[i].coords.mosaic   = NULL;
-    out[i].coords.imageMap = NULL;
+    out[i].coords.offsetMap = NULL;
 
     // RAW_IMAGE_NAME_LEN < DVO_IMAGE_NAME_LEN
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libkapa/src/KapaWindow.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libkapa/src/KapaWindow.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libkapa/src/KapaWindow.c	(revision 37386)
@@ -98,13 +98,6 @@
   graphdata[0].lweight = graphdata[0].size = 1.0;
     
-  graphdata[0].coords.pc1_1 = graphdata[0].coords.pc2_2 = 1.0;
-  graphdata[0].coords.pc1_2 = graphdata[0].coords.pc2_1 = 0.0;
-  strcpy (graphdata[0].coords.ctype, "DEC--LIN");
-  graphdata[0].coords.crval1 = 0.0;
-  graphdata[0].coords.crval2 = 0.0;
-  graphdata[0].coords.crpix1 = 0.0;
-  graphdata[0].coords.crpix2 = 0.0;
-  graphdata[0].coords.cdelt1 = graphdata[0].coords.cdelt2 = 1.0;
-  graphdata[0].flipeast = TRUE;
+  InitCoords (&graphdata[0].coords, "DEC--LIN");
+  graphdata[0].flipeast = TRUE; // default coords has EW flipped relative to sky
   graphdata[0].flipnorth = FALSE;
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libohana/Makefile
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libohana/Makefile	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libohana/Makefile	(revision 37386)
@@ -35,4 +35,5 @@
 $(SRC)/time.$(ARCH).o		 \
 $(SRC)/gaussj.$(ARCH).o		 \
+$(SRC)/vstats.$(ARCH).o		 \
 $(SRC)/config.$(ARCH).o		 \
 $(SRC)/Fread.$(ARCH).o		 \
Index: /branches/eam_branches/ipp-20140904/Ohana/src/libohana/include/ohana.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/libohana/include/ohana.h	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/libohana/include/ohana.h	(revision 37386)
@@ -242,4 +242,31 @@
 // sorting is now defined as a macro call
 # include <ohana_sort.h>
+
+// vector statistics options
+typedef enum {
+  VSTATS_NONE, 
+  VSTATS_MEAN, 
+  VSTATS_MEDIAN, 
+  VSTATS_WT_MEAN, 
+  VSTATS_INNER_MEAN, 
+  VSTATS_INNER_WTMEAN, 
+  VSTATS_CHI_INNER_MEAN, 
+  VSTATS_CHI_INNER_WTMEAN
+} VStatsMode;
+
+typedef struct {
+  double median;
+  double mean;
+  double sigma;
+  double error;
+  double chisq;
+  double min;
+  double max;
+  double Upper80;
+  double Lower20;
+  double total;
+  int    Nmeas;
+  VStatsMode statmode;
+} VStatsType;
 
 /* socket / pipe communication buffer */
@@ -388,4 +415,8 @@
 int rconnect (char *command, char *hostname, char *shell, int *stdio, int *errorInfo, int doHandshake);
 
+int vstats_setmode (VStatsType *stats, char *mode);
+int vstats_getstats (double *value, double *dvalue, double *weight, int N, VStatsType *stats);
+int vstats_getstats_f (float *value, float *dvalue, float *weight, int N, VStatsType *stats);
+
 /*
 #   define F_SETFL         4   
Index: /branches/eam_branches/ipp-20140904/Ohana/src/markrock/src/gcatstats.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/markrock/src/gcatstats.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/markrock/src/gcatstats.c	(revision 37386)
@@ -34,12 +34,9 @@
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is center of field  */
+  InitCoords (&catstats[0].coords, "DEC--TAN");
   catstats[0].coords.crval1 = RaCenter;
   catstats[0].coords.crval2 = DecCenter;
-  catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
   catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
-  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
-  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
-  strcpy (catstats[0].coords.ctype, "DEC--TAN");
-
+  
   X1 = catstats[0].X;
   Y1 = catstats[0].Y;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/markstar/src/gcatstats.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/markstar/src/gcatstats.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/markstar/src/gcatstats.c	(revision 37386)
@@ -44,11 +44,8 @@
   /* project onto rectilinear grid with 1 arcsec pixels, sort by X */
   /* reference for coords is center of field  */
+  InitCoords (&catstats[0].coords, "DEC--TAN");
   catstats[0].coords.crval1 = RaCenter;
   catstats[0].coords.crval2 = DecCenter;
-  catstats[0].coords.crpix1 = catstats[0].coords.crpix2 = 0.0;
   catstats[0].coords.cdelt1 = catstats[0].coords.cdelt2 = 1.0 / 3600.0;
-  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
-  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
-  strcpy (catstats[0].coords.ctype, "DEC--TAN");
 
   X1 = catstats[0].X;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/chips.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/chips.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/chips.c	(revision 37386)
@@ -21,9 +21,5 @@
 
     /* bore site center guess */
-    strcpy (chip[i].map.ctype, "DEC--PLY");
-    chip[i].map.crpix1 = 0.0;
-    chip[i].map.crpix2 = 0.0;
-    chip[i].map.cdelt1 = 1.0;
-    chip[i].map.cdelt2 = 1.0;
+    InitCoords (&chip[i].map, "DEC--PLY");
 
     /* find (L,M) coords of reference pixel (0,0) */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fakefield.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fakefield.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fakefield.c	(revision 37386)
@@ -22,7 +22,5 @@
 
   /* bore site center guess */
-  strcpy (field.project.ctype, "DEC--TAN");
-  field.project.crpix1 = 0;
-  field.project.crpix2 = 0;
+  InitCoords (&field.project, "DEC--TAN");
   
   /* set TP plate scale */
@@ -30,31 +28,6 @@
   field.project.cdelt2 = 1.0/3600.0;
 
-  /** allow guess at field rotation?? **/
-  field.project.pc1_1  = 1;
-  field.project.pc2_2  = 1;
-  field.project.pc1_2  = 0;
-  field.project.pc2_1  = 0;
-  field.project.Npolyterms = 1;
-
   /** distort only has power in polyterms **/
-  strcpy (field.distort.ctype, "DEC--PLY");
-  field.distort.crval1 = 0.0;
-  field.distort.crval2 = 0.0;
-  field.distort.crpix1 = 0.0;
-  field.distort.crpix2 = 0.0;
-  field.distort.cdelt1 = 1.0;
-  field.distort.cdelt2 = 1.0;
-  
-  field.distort.pc1_1  = 1;
-  field.distort.pc2_2  = 1;
-  field.distort.pc1_2  = 0;
-  field.distort.pc2_1  = 0;
-
-  /* how do we handle renormalization? (fixed at 1000 pixels??) */
-  field.distort.Npolyterms = 3;
-  for (i = 0; i < 7; i++) {
-    field.distort.polyterms[i][0] = 0;
-    field.distort.polyterms[i][1] = 0;
-  }
+  InitCoords (&field.distort, "DEC--PLY");
 
   return (1);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/field.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/field.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/field.c	(revision 37386)
@@ -12,5 +12,5 @@
 
   /* bore site center guess */
-  strcpy (field.project.ctype, "DEC--TAN");
+  InitCoords (&field.project, "DEC--TAN");
 
   # if (PSASTRO_MODE)
@@ -23,7 +23,4 @@
   # endif
 
-  field.project.crpix1 = 0;
-  field.project.crpix2 = 0;
-  
   /* measure average plate scale - would be better using parabolic min... */
   field.project.cdelt1 = 0;
@@ -47,33 +44,6 @@
 	   3600*field.project.cdelt1, 3600*field.project.cdelt2);
 
-  /** allow guess at field rotation?? **/
-  field.project.pc1_1  = 1;
-  field.project.pc2_2  = 1;
-  field.project.pc1_2  = 0;
-  field.project.pc2_1  = 0;
-  field.project.Npolyterms = 1;
-
   /* bore site center guess */
-  strcpy (field.distort.ctype, "DEC--PLY");
-  field.distort.crval1 = 0.0;
-  field.distort.crval2 = 0.0;
-  field.distort.crpix1 = 0.0;
-  field.distort.crpix2 = 0.0;
-  field.distort.cdelt1 = 1.0;
-  field.distort.cdelt2 = 1.0;
-  
-  /** allow guess at field rotation?? **/
-  field.distort.pc1_1  = 1;
-  field.distort.pc2_2  = 1;
-  field.distort.pc1_2  = 0;
-  field.distort.pc2_1  = 0;
-
-  /* allow 2nd and 3rd order? */
-  /* how do we handle renormalization? (fixed at 1000 pixels??) */
-  field.distort.Npolyterms = 1;
-  for (i = 0; i < 7; i++) {
-    field.distort.polyterms[i][0] = 0;
-    field.distort.polyterms[i][1] = 0;
-  }
+  InitCoords (&field.distort, "DEC--PLY");
   return (TRUE);
 }
@@ -138,5 +108,4 @@
 int load_field (char *filename) {
 
-  int i;
   Coords coords;
   Header header;
@@ -156,9 +125,7 @@
 
   /* bore site center guess */
-  strcpy (field.project.ctype, "DEC--TAN");
+  InitCoords (&field.project, "DEC--TAN");
   field.project.crval1 = 0.5*(field.Rmin + field.Rmax);
   field.project.crval2 = 0.5*(field.Dmin + field.Dmax);
-  field.project.crpix1 = 0;
-  field.project.crpix2 = 0;
   
   /* measure average plate scale - would be better using parabolic min... */
@@ -174,25 +141,6 @@
 
   /* bore site center guess */
-  strcpy (field.distort.ctype, "DEC--PLY");
-  field.distort.crval1 = 0.0;
-  field.distort.crval2 = 0.0;
-  field.distort.crpix1 = 0.0;
-  field.distort.crpix2 = 0.0;
-  field.distort.cdelt1 = 1.0;
-  field.distort.cdelt2 = 1.0;
-  
-  /** allow guess at field rotation?? **/
-  field.distort.pc1_1  = 1;
-  field.distort.pc2_2  = 1;
-  field.distort.pc1_2  = 0;
-  field.distort.pc2_1  = 0;
+  InitCoords (&field.distort, "DEC--PLY");
 
-  /* allow 2nd and 3rd order? */
-  /* how do we handle renormalization? (fixed at 1000 pixels??) */
-  field.distort.Npolyterms = coords.Npolyterms;
-  for (i = 0; i < 7; i++) {
-    field.distort.polyterms[i][0] = coords.polyterms[i][0];
-    field.distort.polyterms[i][1] = coords.polyterms[i][1];
-  }
   return (TRUE);
 }
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fitpoly.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fitpoly.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/fitpoly.c	(revision 37386)
@@ -130,4 +130,6 @@
   double R;
 
+  InitCoords (coords, "DEC--PLY");
+
   /* update the higher order terms */
   if (NORDER > 1) {
@@ -166,5 +168,4 @@
 
   coords[0].Npolyterms = NORDER;
-  strcpy (coords[0].ctype, "DEC--PLY");
 }
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkobs.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkobs.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkobs.c	(revision 37386)
@@ -104,5 +104,5 @@
 
       /* Chip-Sky terms */
-      strcpy (coords.ctype, "DEC--WRP");
+      InitCoords (&coords, "DEC--WRP");
       coords.crval1 = Ro;
       coords.crval2 = Do;
@@ -124,10 +124,4 @@
       }
 
-      coords.pc1_1  = 1;
-      coords.pc2_2  = 1;
-      coords.pc1_2  = 0;
-      coords.pc2_1  = 0;
-      coords.Npolyterms = 1;
-
       header = mkheader (2*dX, 2*dY, Nstars, &coords);
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkstandards.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkstandards.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/mosastro/src/mkstandards.c	(revision 37386)
@@ -32,18 +32,11 @@
 
   /* bore site center guess */
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
   coords.crval1 = atof(argv[1]);
   coords.crval2 = atof(argv[2]);
   coords.crpix1 = dX;
   coords.crpix2 = dX;
-  
   coords.cdelt1 = 1/3600.0;
   coords.cdelt2 = 1/3600.0;
-
-  coords.pc1_1  = 1;
-  coords.pc2_2  = 1;
-  coords.pc1_2  = 0;
-  coords.pc2_1  = 0;
-  coords.Npolyterms = 1;
 
   if (Random) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/cdensify.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/cdensify.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/cdensify.c	(revision 37386)
@@ -97,11 +97,5 @@
   // generate the PSF in a local tangent plane
   Coords coords;
-  coords.crpix1 = coords.crpix2 = 0.0;
-  coords.crval1 = coords.crval2 = 0.0;
-  coords.cdelt1 = coords.cdelt2 = 1.0;
-  coords.pc1_1  = coords.pc2_2  = 1.0;
-  coords.pc1_2  = coords.pc2_1  = 0.0;
-  coords.Npolyterms = 0;
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
 
   r = vr[0].elements.Flt;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitplx.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitplx.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitplx.c	(revision 37386)
@@ -104,13 +104,8 @@
   /* project coordinates to a plane centered on the object with units of arcsec */
   Coords coords;
+  InitCoords (&coords, "DEC--SIN");
   coords.crval1 = Rmean;
   coords.crval2 = Dmean;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   double *X, *Y, *t, *pX, *pY, *dX, *dY;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitpm.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitpm.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/fitpm.c	(revision 37386)
@@ -100,13 +100,8 @@
   /* project coordinates to a plane centered on the object with units of arcsec */
   Coords coords;
+  InitCoords (&coords, "DEC--SIN");
   coords.crval1 = Rmean;
   coords.crval2 = Dmean;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   double *X, *Y, *t, *dX, *dY;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/region.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/region.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/cmd.astro/region.c	(revision 37386)
@@ -80,5 +80,6 @@
   if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
   Radius = atof (argv[3]);
-  strcpy (graphmode.coords.ctype, "DEC--TAN");
+  InitCoords (&graphmode.coords, "DEC--TAN");
+
   if (argc == 5) {
     if (!strcasecmp (argv[4], "TAN")) 
@@ -99,6 +100,11 @@
       strcpy (graphmode.coords.ctype, "DEC--PAR");
   }
+  
+  graphmode.coords.crval1 = Ra;
+  graphmode.coords.crval2 = Dec;
 
-  
+  graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
+  graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
+
   /* ask kapa for coordinate limits, to get the right aspect ratio */
   KapaGetLimits (kapa, &dx, &dy);
@@ -132,14 +138,4 @@
   set_int_variable ("NORTH_UP", !graphmode.flipnorth);
 
-  graphmode.coords.pc1_1 = (graphmode.flipeast) ? -1 : 1;
-  graphmode.coords.pc2_2 = (graphmode.flipnorth) ? -1 : 1;
-
-  graphmode.coords.pc1_2 = graphmode.coords.pc2_1 = 0.0;
-  graphmode.coords.crval1 = Ra;
-  graphmode.coords.crval2 = Dec;
-  graphmode.coords.crpix1 = 0.0;
-  graphmode.coords.crpix2 = 0.0;
-  graphmode.coords.cdelt1 = graphmode.coords.cdelt2 = 1.0;
-
   if (!NoClear) KapaClearSections (kapa);
   KapaSetLimits (kapa, &graphmode);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/find_matches.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/find_matches.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/find_matches.c	(revision 37386)
@@ -38,4 +38,5 @@
    * far from the projection pole. We use the center of the region (catalog) for crval1,2.
    */
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -44,11 +45,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
   // this region includes a boundary layer of size RADIUS
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/gimages.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/gimages.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/gimages.c	(revision 37386)
@@ -128,12 +128,8 @@
       if (fabs(Ro - Ra) > 120.0) continue;
 
+      InitCoords (&local, "DEC--TAN");
       local.crval1 = Ro;
       local.crval2 = Do;
-      local.crpix1 = local.crpix2 = 0.0;
       local.cdelt1 = local.cdelt2 = 1.0/3600.0;
-      local.pc1_1 = local.pc2_2 = 1.0;
-      local.pc2_1 = local.pc1_2 = 0.0;
-      local.Npolyterms = 1;
-      strcpy (local.ctype, "DEC--TAN");
 
       if (typehash == DistortImage) {
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/objectcoverage.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/objectcoverage.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/objectcoverage.c	(revision 37386)
@@ -147,15 +147,12 @@
   strcpy (buf[0].file, "(empty)");
 
+  InitCoords (&coords, projection);
   coords.crval1 = RaCenter;
   coords.crval2 = DecCenter;
   coords.crpix1 = 0.5*Nx;
   coords.crpix2 = 0.5*Ny;
-  strcpy (coords.ctype, projection);
-  coords.pc1_1 = -1.0;
+  coords.pc1_1 = -1.0; // sky parity
   coords.pc2_2 = +1.0;
-  coords.pc1_2 =  0.0;
-  coords.pc2_1 =  0.0;
   coords.cdelt1 = coords.cdelt2 = pixscale;
-  coords.Npolyterms = 0;
 
   PutCoords (&coords, &buf[0].header);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/showtile.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/showtile.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/showtile.c	(revision 37386)
@@ -28,11 +28,5 @@
 
   /* reference for coords is this image */
-  coords.crpix1 = coords.crpix2 = 0.0;
-  coords.crval1 = coords.crval2 = 0.0;
-  coords.cdelt1 = coords.cdelt2 = 1.0;
-  coords.pc1_1  = coords.pc2_2  = 1.0;
-  coords.pc1_2  = coords.pc2_1  = 0.0;
-  coords.Npolyterms = 0;
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
   
   /* fill in top-left region */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/simage.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/simage.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/simage.c	(revision 37386)
@@ -42,37 +42,8 @@
   }
   /* get astrometry information */
-  strcpy (coords.ctype, "NONE");
-  gfits_scan (&header, "CTYPE2",   "%s",  1, coords.ctype);
-  if (strcmp (coords.ctype, "DEC--PLY")) {
-    gprint (GP_ERR, "ERROR: wrong astrometric info in header\n");
+  if (!GetCoords (&coords, &header)) {
+    gprint (GP_ERR, "ERROR: can't get coord info from header\n");
     return (FALSE);
   }
-  gfits_scan (&header, "CDELT1",   "%f", 1, &coords.cdelt1); 
-  gfits_scan (&header, "CDELT2",   "%f", 1, &coords.cdelt2);
-  gfits_scan (&header, "CRVAL1",   "%lf", 1, &coords.crval1);
-  gfits_scan (&header, "CRVAL2",   "%lf", 1, &coords.crval2);  
-  gfits_scan (&header, "CRPIX1",   "%f", 1, &coords.crpix1);
-  gfits_scan (&header, "CRPIX2",   "%f", 1, &coords.crpix2);
-  gfits_scan (&header, "PC001001", "%f", 1, &coords.pc1_1);
-  gfits_scan (&header, "PC001002", "%f", 1, &coords.pc1_2);
-  gfits_scan (&header, "PC002001", "%f", 1, &coords.pc2_1);
-  gfits_scan (&header, "PC002002", "%f", 1, &coords.pc2_2);
-  /* RA Terms */
-  gfits_scan (&header, "PCA1X2Y0", "%f", 1, &coords.polyterms[0][0]);
-  gfits_scan (&header, "PCA1X1Y1", "%f", 1, &coords.polyterms[1][0]);
-  gfits_scan (&header, "PCA1X0Y2", "%f", 1, &coords.polyterms[2][0]);
-  gfits_scan (&header, "PCA1X3Y0", "%f", 1, &coords.polyterms[3][0]);
-  gfits_scan (&header, "PCA1X2Y1", "%f", 1, &coords.polyterms[4][0]);
-  gfits_scan (&header, "PCA1X1Y2", "%f", 1, &coords.polyterms[5][0]);
-  gfits_scan (&header, "PCA1X0Y3", "%f", 1, &coords.polyterms[6][0]);
-  /* Dec Terms */			    
-  gfits_scan (&header, "PCA2X2Y0", "%f", 1, &coords.polyterms[0][1]);
-  gfits_scan (&header, "PCA2X1Y1", "%f", 1, &coords.polyterms[1][1]);
-  gfits_scan (&header, "PCA2X0Y2", "%f", 1, &coords.polyterms[2][1]);
-  gfits_scan (&header, "PCA2X3Y0", "%f", 1, &coords.polyterms[3][1]);
-  gfits_scan (&header, "PCA2X2Y1", "%f", 1, &coords.polyterms[4][1]);
-  gfits_scan (&header, "PCA2X1Y2", "%f", 1, &coords.polyterms[5][1]);
-  gfits_scan (&header, "PCA2X0Y3", "%f", 1, &coords.polyterms[6][1]);
-  coords.Npolyterms = 2; /* how many do we use? */
 
   /* find number of stars */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/skycoverage.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/skycoverage.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/dvo/skycoverage.c	(revision 37386)
@@ -204,15 +204,12 @@
   strcpy (buf[0].file, "(empty)");
 
+  InitCoords (&coords, projection);
   coords.crval1 = RaCenter;
   coords.crval2 = DecCenter;
   coords.crpix1 = 0.5*Nx;
   coords.crpix2 = 0.5*Ny;
-  strcpy (coords.ctype, projection);
-  coords.pc1_1 = -1.0;
+  coords.pc1_1 = -1.0; // sky parity
   coords.pc2_2 = +1.0;
-  coords.pc1_2 =  0.0;
-  coords.pc2_1 =  0.0;
   coords.cdelt1 = coords.cdelt2 = pixscale;
-  coords.Npolyterms = 0;
 
   PutCoords (&coords, &buf[0].header);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/opihi/include/astro.h
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/opihi/include/astro.h	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/opihi/include/astro.h	(revision 37386)
@@ -12,25 +12,3 @@
 void FreeAstro (void);
 
-typedef struct {
-  int    isIdentity;	      // identity transformation 
-  double phi;		      // saved in radians
-  double Xo;		      // saved in radians
-  double xo;		      // saved in degrees
-  double sin_phi_cos_Xo;      // pre-computed values
-  double sin_phi_sin_Xo;      // pre-computed values
-  double cos_phi_cos_Xo;      // pre-computed values
-  double cos_phi_sin_Xo;      // pre-computed values
-  double cos_phi;	      // pre-computed values
-  double sin_phi;	      // pre-computed values
-  double cos_Xo;	      // pre-computed values
-  double sin_Xo;	      // pre-computed values
-} CoordTransform;
-
-#ifndef MOVED_TO_LIBDVO
-typedef enum {COORD_NONE, COORD_CELESTIAL, COORD_GALACTIC, COORD_ECLIPTIC} CoordTransformSystem;
-#endif
-
-CoordTransform *InitTransform (CoordTransformSystem input, CoordTransformSystem output);
-int ApplyTransform (double *x, double *y, double X, double Y, CoordTransform *transform);
-
 # endif
Index: /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/find_images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/find_images.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/find_images.c	(revision 37386)
@@ -19,11 +19,8 @@
 
   /* we make positional comparisons in the projection of catalog */
+  InitCoords (&tcoords, "DEC--TAN");
   tcoords.crval1 = 0.5*(region[0].RA[0]  + region[0].RA[1]);
   tcoords.crval2 = 0.5*(region[0].DEC[0] + region[0].DEC[1]);
-  tcoords.crpix1 = tcoords.crpix2 = 0.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;
-  strcpy (tcoords.ctype, "DEC--TAN");
 
   timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/join_stars.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/join_stars.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/join_stars.c	(revision 37386)
@@ -50,12 +50,8 @@
 
   /* coordinate system for projection */
+  InitCoords (&tcoords, "DEC--TAN");
   tcoords.crval1 = Rmid;
   tcoords.crval2 = Dmid;
-  tcoords.crpix1 = tcoords.crpix2 = 0.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 = 0;
-  strcpy (tcoords.ctype, "DEC--TAN");
   
   /* project & sort coordinates in local linear frame */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/select_images.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/photdbc/src/select_images.c	(revision 37386)
@@ -34,9 +34,6 @@
 
   // the comparison is made in the catalog local projection. below we set crval1,2
-  tcoords.crpix1 = tcoords.crpix2 = 0.0;
+  InitCoords (&tcoords, "DEC--TAN");
   tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
-  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
-  strcpy (tcoords.ctype, "DEC--TAN");
 
   ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateObjects.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateObjects.c	(revision 37386)
@@ -69,13 +69,6 @@
 
   /* project coordinates to a plane centered on the object with units of arcsec */
-  coords.crval1 = 0;
-  coords.crval2 = 0;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
+  InitCoords (&coords, "DEC--SIN");
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   // use J2000 as a reference time
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/bcatalog.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/bcatalog.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/bcatalog.c	(revision 37386)
@@ -27,13 +27,6 @@
 
   /* for outlier rejection, project coordinates to a plane centered on the object with units of arcsec */
-  coords.crval1 = 0;
-  coords.crval2 = 0;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
+  InitCoords (&coords, "DEC--SIN");
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   // XXX in the future, use catalog[0].Nsecfilt only?  allow catalogs to have variable Nsecfilt?
@@ -269,13 +262,8 @@
   /* project coordinates to a plane centered on the object with units of arcsec */
   Coords coords;
+  InitCoords (&coords, "DEC--SIN");
   coords.crval1 = Rc;
   coords.crval2 = Dc;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   // convert all average R,D values to X,Y:
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/high_speed_objects.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/high_speed_objects.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/high_speed_objects.c	(revision 37386)
@@ -149,4 +149,5 @@
 
   // define a local projection
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -155,11 +156,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
   /* build spatial index (RA sort) referencing input array sequence */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/hpm_objects.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/hpm_objects.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/hpm_objects.c	(revision 37386)
@@ -126,4 +126,5 @@
 
   // define a local projection
+  InitCoords (&tcoords, "DEC--ARC");
   tcoords.crval1 = 0.5*(region[0].Rmin + region[0].Rmax);
   if (region[0].Dmax < 90) {
@@ -132,10 +133,5 @@
     tcoords.crval2 = 90.0;
   }
-  tcoords.crpix1 = 0;
-  tcoords.crpix2 = 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--ARC");
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/select_images.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/select_images.c	(revision 37386)
@@ -23,5 +23,4 @@
   int InRange, found;
   double Ri[5], Di[5], Xi[5], Yi[5], dx, dy;
-  Coords tcoords;
   SkyRegionCoords *skycoords;
   
@@ -46,9 +45,7 @@
 
   // the comparison is made in the catalog local projection. below we set crval1,2
-  tcoords.crpix1 = tcoords.crpix2 = 0.0;
+  Coords tcoords;
+  InitCoords (&tcoords, "DEC--TAN");
   tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
-  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
-  strcpy (tcoords.ctype, "DEC--TAN");
 
   ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/testparallax.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/testparallax.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/testparallax.c	(revision 37386)
@@ -49,13 +49,6 @@
 
   /* project coordinates to a plane centered on the object with units of arcsec */
-  coords.crval1 = 0;
-  coords.crval2 = 0;
-  coords.crpix1 = 0;
-  coords.crpix2 = 0;
+  InitCoords (&coords, "DEC--SIN");
   coords.cdelt1 = coords.cdelt2 = 1.0 / 3600.0;
-  coords.pc1_1  = coords.pc2_2 = 1.0;
-  coords.pc1_2  = coords.pc2_1 = 0.0;
-  coords.Npolyterms = 1;
-  strcpy (coords.ctype, "DEC--SIN");
 
   // use one point as a local reference
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/MosaicOps.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/MosaicOps.c	(revision 37386)
@@ -582,15 +582,9 @@
     }
 
-    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
+    InitCoords (&mosaic[i].coords, "DEC--TAN");
     mosaic[i].coords.crval1 = Rmid;
     mosaic[i].coords.crval2 = Dmid;
-    mosaic[i].coords.crpix1 = 0.0;
-    mosaic[i].coords.crpix2 = 0.0;
     mosaic[i].coords.cdelt1 = 1.0 / 3600.0;
     mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
-    mosaic[i].coords.pc1_1  = 1.0;
-    mosaic[i].coords.pc2_2  = 1.0;
-    mosaic[i].coords.pc1_2  = 0.0;
-    mosaic[i].coords.pc2_1  = 0.0;
 
     mosaic[i].Mcal   = 0.0;
@@ -663,15 +657,11 @@
     }
     dS /= MosaicN_Image[i];
-    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
+
+    InitCoords (&mosaic[i].coords, "DEC--TAN");
     mosaic[i].coords.crval1 = Rmin;
     mosaic[i].coords.crval2 = Dmin;
-    mosaic[i].coords.crpix1 = 0.0;
-    mosaic[i].coords.crpix2 = 0.0;
     mosaic[i].coords.cdelt1 = dS;
     mosaic[i].coords.cdelt2 = dS;
-    mosaic[i].coords.pc1_1  = 1.0;
-    mosaic[i].coords.pc2_2  = 1.0;
-    mosaic[i].coords.pc1_2  = 0.0;
-    mosaic[i].coords.pc2_1  = 0.0;
+
     RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
 
Index: /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/select_images.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/relphot/src/select_images.c	(revision 37386)
@@ -36,9 +36,6 @@
 
   // the comparison is made in the catalog local projection. below we set crval1,2
-  tcoords.crpix1 = tcoords.crpix2 = 0.0;
+  InitCoords (&tcoords, "DEC--TAN");
   tcoords.cdelt1 = tcoords.cdelt2 = 1.0 / 3600.0;
-  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
-  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
-  strcpy (tcoords.ctype, "DEC--TAN");
 
   double RminSkyRegion = region[0].Rmin;
@@ -397,12 +394,6 @@
 
   // the comparison is made in the catalog local projection. below we set crval1,2
-  tcoords.crpix1 = tcoords.crpix2 = 0.0;
+  InitCoords (&tcoords, "DEC--TAN");
   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 = 0;
-  memset (tcoords.polyterms, 0, 14*sizeof(float));
-  strcpy (tcoords.ctype, "DEC--TAN");
 
   /* compare with each region file */
Index: /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/find_image_sgroups.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 37386)
@@ -18,9 +18,5 @@
   }
 
-  coords.crpix1 = coords.crpix2 = 0.0;
-  coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
-  coords.pc1_1 = coords.pc2_2 = 1.0;
-  coords.pc1_2 = coords.pc2_1 = 0.0;
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
   
   Ngroup = 0;
Index: /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/update_dvo_uniphot.c
===================================================================
--- /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/update_dvo_uniphot.c	(revision 37385)
+++ /branches/eam_branches/ipp-20140904/Ohana/src/uniphot/src/update_dvo_uniphot.c	(revision 37386)
@@ -57,9 +57,5 @@
   glob (line, 0, NULL, &pglob);
 
-  coords.crpix1 = coords.crpix2 = 0.0;
-  coords.cdelt1 = coords.cdelt2 = 1.0; /* scale is degrees, radius in degrees */
-  coords.pc1_1 = coords.pc2_2 = 1.0;
-  coords.pc1_2 = coords.pc2_1 = 0.0;
-  strcpy (coords.ctype, "DEC--TAN");
+  InitCoords (&coords, "DEC--TAN");
   
   for (i = 0; i < pglob.gl_pathc; i++) {
