Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/include/dvo.h
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/include/dvo.h	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/include/dvo.h	(revision 28721)
@@ -85,29 +85,36 @@
 # define PHOT_MAG 0x06  /* generic magnitude; never stored */
 
-/* Image.code values.  these are codes to note bad images */
-# define ID_IMAGE_NEW   0x0000  /* no nrphot attempted */
-# define ID_IMAGE_NOCAL 0x0001  /* used within nrphot to mean "don't apply fit" */
-# define ID_IMAGE_POOR  0x0002  /* relphot says image is bad */
-# define ID_IMAGE_SKIP  0x0004  /* external information image is bad */
-# define ID_IMAGE_FEW   0x0008  /* currently too few measurements for good value */
+/* Image.code values -- these values are 32 bit (as of PS1_V1) */
+typedef enum {
+  ID_IMAGE_NEW          = 0x00000000,  /* no calibrations yet attempted */
+  ID_IMAGE_PHOTOM_NOCAL = 0x00000001,  /* user-set value used within relphot: ignore */
+  ID_IMAGE_PHOTOM_POOR  = 0x00000002,  /* relphot says image is bad (dMcal > limit) */
+  ID_IMAGE_PHOTOM_SKIP  = 0x00000004,  /* user-set value: assert that this image has bad photometry */
+  ID_IMAGE_PHOTOM_FEW   = 0x00000008,  /* currently too few measurements for photometry */
+  ID_IMAGE_ASTROM_NOCAL = 0x00000010,  /* user-set value used within relastro: ignore */
+  ID_IMAGE_ASTROM_POOR  = 0x00000020,  /* relastro says image is bad (dR,dD > limit) */
+  ID_IMAGE_ASTROM_FAIL  = 0x00000040,  /* relastro fit diverged, fit not applied */
+  ID_IMAGE_ASTROM_SKIP  = 0x00000080,  /* user-set value: assert that this image has bad astrometry */
+  ID_IMAGE_ASTROM_FEW   = 0x00000100,  /* currently too few measurements for astrometry */
+} DVOImageFlags;
 
 /* Measure.flags values -- these values are 32 bit (as of PS1_V1) */
 typedef enum {
-  ID_MEAS_NOCAL        = 0x0001,  // detection ignored for this analysis (photcode, time range) -- internal only 
-  ID_MEAS_POOR_PHOTOM  = 0x0002,  // detection is photometry outlier					     	  
-  ID_MEAS_SKIP_PHOTOM  = 0x0004,  // detection was ignored for photometry measurement			     	  
-  ID_MEAS_AREA         = 0x0008,  // detection near image edge						     
-  ID_MEAS_POOR_ASTROM  = 0x0010,  // detection is astrometry outlier					     	  
-  ID_MEAS_SKIP_ASTROM  = 0x0020,  // detection was ignored for astrometry measurement			     	  
-  ID_MEAS_USED_OBJ     = 0x0040,  // detection was used during opdate objects				     
-  ID_MEAS_USED_CHIP    = 0x0080,  // detection was used during update chips					     
-  ID_MEAS_BLEND_MEAS   = 0x0100,  // detection is within radius of multiple objects				     
-  ID_MEAS_BLEND_OBJ    = 0x0200,  // multiple detections within radius of object				     
-  ID_MEAS_UNDEF_3      = 0x0400,  // unused									     
-  ID_MEAS_UNDEF_4      = 0x0800,  // unused									     
-  ID_MEAS_BLEND_MEAS_X = 0x1000,  // detection is within radius of multiple objects across catalogs		     
-  ID_MEAS_ARTIFACT     = 0x2000,  // detection is thought to be non-astronomical				     
-  ID_MEAS_UNDEF_5      = 0x4000,  // unused									     
-  ID_MEAS_UNDEF_6      = 0x8000,  // unused									     
+  ID_MEAS_NOCAL        = 0x00000001,  // detection ignored for this analysis (photcode, time range) -- internal only 
+  ID_MEAS_POOR_PHOTOM  = 0x00000002,  // detection is photometry outlier					     	  
+  ID_MEAS_SKIP_PHOTOM  = 0x00000004,  // detection was ignored for photometry measurement			     	  
+  ID_MEAS_AREA         = 0x00000008,  // detection near image edge						     
+  ID_MEAS_POOR_ASTROM  = 0x00000010,  // detection is astrometry outlier					     	  
+  ID_MEAS_SKIP_ASTROM  = 0x00000020,  // detection was ignored for astrometry measurement			     	  
+  ID_MEAS_USED_OBJ     = 0x00000040,  // detection was used during opdate objects				     
+  ID_MEAS_USED_CHIP    = 0x00000080,  // detection was used during update chips					     
+  ID_MEAS_BLEND_MEAS   = 0x00000100,  // detection is within radius of multiple objects				     
+  ID_MEAS_BLEND_OBJ    = 0x00000200,  // multiple detections within radius of object				     
+  ID_MEAS_UNDEF_3      = 0x00000400,  // unused									     
+  ID_MEAS_UNDEF_4      = 0x00000800,  // unused									     
+  ID_MEAS_BLEND_MEAS_X = 0x00001000,  // detection is within radius of multiple objects across catalogs		     
+  ID_MEAS_ARTIFACT     = 0x00002000,  // detection is thought to be non-astronomical				     
+  ID_MEAS_UNDEF_5      = 0x00004000,  // unused									     
+  ID_MEAS_UNDEF_6      = 0x00008000,  // unused									     
 } DVOMeasureFlags;
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/LoadPhotcodesFITS.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/LoadPhotcodesFITS.c	(revision 28721)
@@ -43,4 +43,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE")) {
     PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_elixir) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
     free (photcode_elixir);
@@ -49,4 +53,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
     PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_elixir) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
     free (photcode_elixir);
@@ -55,4 +63,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_1")) {
     PhotCode_PS1_DEV_1 *photcode_ps1_dev_1 = gfits_table_get_PhotCode_PS1_DEV_1 (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_dev_1) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_DEV_1_To_Internal (photcode_ps1_dev_1, Ncode);
     free (photcode_ps1_dev_1);
@@ -61,4 +73,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_2")) {
     PhotCode_PS1_DEV_2 *photcode_ps1_dev_2 = gfits_table_get_PhotCode_PS1_DEV_2 (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_dev_2) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_DEV_2_To_Internal (photcode_ps1_dev_2, Ncode);
     free (photcode_ps1_dev_2);
@@ -67,4 +83,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_DEV_3")) {
     PhotCode_PS1_DEV_3 *photcode_ps1_dev_3 = gfits_table_get_PhotCode_PS1_DEV_3 (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_dev_3) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_DEV_3_To_Internal (photcode_ps1_dev_3, Ncode);
     free (photcode_ps1_dev_3);
@@ -73,4 +93,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_V1")) {
     PhotCode_PS1_V1 *photcode_ps1_v1 = gfits_table_get_PhotCode_PS1_V1 (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_v1) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_V1_To_Internal (photcode_ps1_v1, Ncode);
     free (photcode_ps1_v1);
@@ -79,4 +103,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_V2")) {
     PhotCode_PS1_V2 *photcode_ps1_v2 = gfits_table_get_PhotCode_PS1_V2 (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_v2) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_V2_To_Internal (photcode_ps1_v2, Ncode);
     free (photcode_ps1_v2);
@@ -85,4 +113,8 @@
   if (!strcmp (extname, "DVO_PHOTCODE_PS1_REF")) {
     PhotCode_PS1_REF *photcode_ps1_ref = gfits_table_get_PhotCode_PS1_REF (&db.ftable, &Ncode, &db.swapped);
+    if (!photcode_ps1_ref) {
+      fprintf (stderr, "ERROR: failed to read photcodes\n");
+      exit (2);
+    }
     photcode = PhotCode_PS1_REF_To_Internal (photcode_ps1_ref, Ncode);
     free (photcode_ps1_ref);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/cmf-ps1-v1-alt.c	(revision 28721)
@@ -14,5 +14,5 @@
   if (ftable[0].header[0].Naxis[0] != 136) { 
     fprintf (stderr, "ERROR: wrong format for CMF_PS1_V1_Alt: "OFF_T_FMT" vs %d\n",  ftable[0].header[0].Naxis[0], 136);
-    exit (2);
+    return (NULL);
   }
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/coordops.c	(revision 28721)
@@ -20,5 +20,10 @@
 int XY_to_LM (double *L, double *M, double x, double y, Coords *coords) {
 
+  OhanaProjection proj;
+  OhanaProjectionMode mode;
   double X, Y, X2, XY, Y2, X3, Y3;
+
+  proj = GetProjection (coords[0].ctype);
+  mode = GetProjectionMode (proj);
 
   /** convert pixel coordinates to cartesian system **/
@@ -44,4 +49,9 @@
   }
 
+  if (mode == PROJ_MODE_CARTESIAN) {
+    *L += coords[0].crval1;
+    *M += coords[0].crval2;
+  }
+
   return (TRUE);
 }
@@ -63,7 +73,4 @@
   /** Locally Cartesian Projections **/
   if (mode == PROJ_MODE_CARTESIAN) {
-    *ra  = L + coords[0].crval1;
-    *dec = M + coords[0].crval2;
-
     /* mosaic astrometry : WRP is chip astrometry; apply mosaic (DIS) term */
     if (proj == PROJ_WRP) {
@@ -182,5 +189,4 @@
 
   double phi, theta;
-  double Lo, Mo;
   double sphi, cphi, stht, ctht;
   double salp, calp, sdel, cdel, sdp, cdp;
@@ -200,11 +206,9 @@
     if (proj == PROJ_WRP) {
       if (!gotMosaic) return (FALSE);
-      RD_to_XY (&Lo, &Mo, ra, dec, &mosaic);
-      *L = (Lo - coords[0].crval1);
-      *M = (Mo - coords[0].crval2);
+      RD_to_XY (L, M, ra, dec, &mosaic);
       return (TRUE);
     }
-    *L = (ra  - coords[0].crval1);
-    *M = (dec - coords[0].crval2);
+    *L = ra;
+    *M = dec;
     return (TRUE);
   }
@@ -309,7 +313,17 @@
   double dX, dY, Lo, Mo, dL, dM;
   double dLdX, dLdY, dMdX, dMdY, Do;
+  OhanaProjection proj;
+  OhanaProjectionMode mode;
+
+  proj = GetProjection (coords[0].ctype);
+  mode = GetProjectionMode (proj);
 
   *x = 0;
   *y = 0;
+
+  if (mode == PROJ_MODE_CARTESIAN) {
+    L -= coords[0].crval1;
+    M -= coords[0].crval2;
+  }
 
   /* start with linear solution for X,Y */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_mef.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_mef.c	(revision 28721)
@@ -125,4 +125,8 @@
     /* no conversions currently defined */
     catalog[0].missing = gfits_table_get_Missing (&ftable, &catalog[0].Nmissing, NULL);
+    if (!catalog[0].missing) {
+      fprintf (stderr, "ERROR: failed to read missing\n");
+      exit (2);
+    }
     if (Nmissing != catalog[0].Nmiss_disk) {
       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  catalog[0].Nmiss_disk);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_split.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_catalog_split.c	(revision 28721)
@@ -285,4 +285,8 @@
     /* no conversions currently defined : this just does the byte swap */
     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
+    if (!catalog[0].missing) {
+      fprintf (stderr, "ERROR: failed to read missing\n");
+      exit (2);
+    }
     if (Nmissing != catalog[0].Nmiss_disk) {
       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  catalog[0].Nmiss_disk);
@@ -473,4 +477,8 @@
     /* no conversions currently defined : this just does the byte swap */
     catalog[0].missing = gfits_table_get_Missing (&ftable, &Nmissing, NULL);
+    if (!catalog[0].missing) {
+      fprintf (stderr, "ERROR: failed to read missing\n");
+      exit (2);
+    }
     if (Nmissing != Nrows) {
       fprintf (stderr, "Warning: mismatch between Nmissing in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmissing,  Nrows);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_convert.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_convert.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/dvo_convert.c	(revision 28721)
@@ -32,4 +32,8 @@
     Average_##TYPE *tmpAverage; \
     tmpAverage = gfits_table_get_Average_##TYPE (ftable, Naverage, NULL); \
+    if (!tmpAverage) { \
+      fprintf (stderr, "ERROR: failed to read averages\n"); \
+      exit (2); \
+    } \
     average = Average_##TYPE##_ToInternal (tmpAverage, *Naverage, primary); \
     free (tmpAverage); \
@@ -39,4 +43,8 @@
   if (!strcmp (extname, "DVO_AVERAGE")) {
     average = gfits_table_get_Average (ftable, Naverage, NULL);
+    if (!average) {
+      fprintf (stderr, "ERROR: failed to read averages\n");
+      exit (2);
+    }
     *format = DVO_FORMAT_INTERNAL;
     return (average);
@@ -111,4 +119,8 @@
     Measure_##TYPE *tmpMeasure; \
     tmpMeasure = gfits_table_get_Measure_##TYPE (ftable, Nmeasure, NULL); \
+    if (!tmpMeasure) { \
+      fprintf (stderr, "ERROR: failed to read measures\n"); \
+      exit (2); \
+    } \
     measure = Measure_##TYPE##_ToInternal (tmpMeasure, *Nmeasure); \
     free (tmpMeasure); \
@@ -118,4 +130,8 @@
   if (!strcmp (extname, "DVO_MEASURE")) {
     measure = gfits_table_get_Measure (ftable, Nmeasure, NULL);
+    if (!measure) {
+      fprintf (stderr, "ERROR: failed to read measures\n");
+      exit (2);
+    }
     *format = DVO_FORMAT_INTERNAL;
     return (measure);
@@ -190,4 +206,8 @@
     SecFilt_##TYPE *tmpSecFilt; \
     tmpSecFilt = gfits_table_get_SecFilt_##TYPE (ftable, Nsecfilt, NULL); \
+    if (!tmpSecFilt) { \
+      fprintf (stderr, "ERROR: failed to read secfilts\n"); \
+      exit (2); \
+    } \
     secfilt = SecFilt_##TYPE##_ToInternal (tmpSecFilt, *Nsecfilt); \
     free (tmpSecFilt); \
@@ -197,4 +217,8 @@
   if (!strcmp (extname, "DVO_SECFILT")) {
     secfilt = gfits_table_get_SecFilt (ftable, Nsecfilt, NULL);
+    if (!secfilt) {
+      fprintf (stderr, "ERROR: failed to read secfilts\n");
+      exit (2);
+    }
     *format = DVO_FORMAT_INTERNAL;
     return (secfilt);
@@ -263,4 +287,8 @@
     Image_Elixir *tmpimage;
     tmpimage = gfits_table_get_Image_Elixir (ftable, &Nimage, NULL);
+    if (!tmpimage) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+    }
     ftable[0].buffer = (char *) Image_Elixir_ToInternal (tmpimage, Nimage);
     free (tmpimage);
@@ -284,4 +312,8 @@
     *format = DVO_FORMAT_##FORMAT; \
     tmpimage = gfits_table_get_Image_##TYPE (ftable, &Nimage, NULL); \
+    if (!tmpimage) { \
+      fprintf (stderr, "ERROR: failed to read images\n"); \
+      exit (2); \
+    } \
     ftable[0].buffer = (char *) Image_##TYPE##_ToInternal (tmpimage, Nimage); \
     free (tmpimage); \
@@ -296,4 +328,8 @@
     Image *image;
     image = gfits_table_get_Image (ftable, &Nimage, NULL);
+    if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+    }
     *format = DVO_FORMAT_INTERNAL;
     return (TRUE);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/skyregion_io.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/skyregion_io.c	(revision 28720)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/libdvo/src/skyregion_io.c	(revision 28721)
@@ -40,4 +40,9 @@
   ALLOCATE (skytable, SkyTable, 1);
   skytable[0].regions = gfits_table_get_SkyRegion (&ftable, &skytable[0].Nregions, NULL);
+  if (!skytable[0].regions) {
+    fprintf (stderr, "ERROR: failed to read sky regions\n");
+    exit (2);
+  }
+
   ALLOCATE (skytable[0].filename, char *, skytable[0].Nregions);
   for (i = 0; i < skytable[0].Nregions; i++) {
