Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/LoadData.c	(revision 28723)
@@ -80,4 +80,9 @@
 	 
     inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
+    if (!inStars) {
+      // XXX need to free the data here or in ReadStarsFITS on error
+      continue;
+    }
+
     inStars = FilterStars (inStars, &images[0][Nvalid], Nvalid);
     *stars = MergeStars (*stars, Nstars, inStars, images[0][Nvalid].nstar);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsFITS.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/addstar/src/ReadStarsFITS.c	(revision 28723)
@@ -49,5 +49,5 @@
   if (stars == NULL) {
     fprintf (stderr, "ERROR: invalid table type %s\n", type);
-    exit (1);
+    return (NULL);
   }
   // Nstars is not necessarily == *nstars (The former is the number of detections, the
@@ -69,4 +69,8 @@
   swapped = FALSE;
   smpdata = gfits_table_get_SMPData (table, &Nstars, &swapped);
+  if (!smpdata) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
@@ -108,4 +112,8 @@
 
   ps1data = gfits_table_get_PS1_DEV_0 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
@@ -153,4 +161,8 @@
 
   ps1data = gfits_table_get_PS1_DEV_1 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
@@ -212,4 +224,8 @@
 
   ps1data = gfits_table_get_CMF_PS1_V1 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
@@ -284,4 +300,8 @@
 
   ps1data = gfits_table_get_CMF_PS1_V1_Alt (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
@@ -348,4 +368,8 @@
 
   ps1data = gfits_table_get_CMF_PS1_V2 (table, &Nstars, NULL);
+  if (!ps1data) {
+    fprintf (stderr, "skipping inconsistent entry\n");
+    return (NULL);
+  }
   ZeroPt = GetZeroPoint();
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_imagename.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_imagename.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_imagename.c	(revision 28723)
@@ -19,4 +19,8 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   /* find image in db by name */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_times.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_times.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/delete_times.c	(revision 28723)
@@ -26,4 +26,8 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   /* find images for time range, delete each image */ 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/find_image_db.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/find_image_db.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/delstar/src/find_image_db.c	(revision 28723)
@@ -17,4 +17,8 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   Nlist = 0;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c	(revision 28723)
@@ -13,4 +13,9 @@
  
   images = gfits_table_get_Image (&in[0].ftable, &Nimages, &in[0].swapped);
+  if (!images) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
+
   ALLOCATE (IDmap->old, off_t, Nimages);
   ALLOCATE (IDmap->new, off_t, Nimages);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoconvert.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoconvert.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoconvert.c	(revision 28723)
@@ -148,4 +148,8 @@
   // convert the raw image table to Image type (byteswap if needed)
   images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped);
+  if (!images) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   // update additional metadata
Index: /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoverify.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoverify.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/dvomerge/src/dvoverify.c	(revision 28723)
@@ -154,4 +154,8 @@
   // convert the raw image table to Image type (byteswap if needed)
   images = gfits_table_get_Image (&inDB.ftable, &Nimages, &inDB.swapped);
+  if (!images) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   // update additional metadata
Index: /branches/eam_branches/ipp-20100621/Ohana/src/gastro2/src/rfits.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/gastro2/src/rfits.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/gastro2/src/rfits.c	(revision 28723)
@@ -15,4 +15,8 @@
 
   stars = gfits_table_get_SMPData (&table, &Nstars, NULL);
+  if (!stars) {
+    fprintf (stderr, "ERROR: failed to read stars\n");
+    exit (2);
+  }
 
   ALLOCATE (stardata, StarData, Nstars);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageExtract.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageExtract.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageExtract.c	(revision 28723)
@@ -32,4 +32,8 @@
   // convert database table to internal structure
   images = gfits_table_get_Image (&db.ftable, &Nimages, &db.swapped);
+  if (!images) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
   
   matches = SelectImages (argv[1], images, Nimages, &Nmatches);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageOverlaps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImageOverlaps.c	(revision 28723)
@@ -35,4 +35,8 @@
   // convert database table to internal structure
   dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.swapped);
+  if (!dbImages) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
   
   // for (i = 1; i < 2; i++) {
Index: /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImagesAtCoords.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/getstar/src/dvoImagesAtCoords.c	(revision 28723)
@@ -55,4 +55,8 @@
     // convert database table to internal structure
     dbImages = gfits_table_get_Image (&db.ftable, &NdbImages, &db.swapped);
+    if (!dbImages) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+    }
   }
   
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/detsearch.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/detsearch.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/detsearch.c	(revision 28723)
@@ -36,4 +36,8 @@
   if (!output.Modify && !output.Delete && !output.Altpath) gfits_db_close (&db);
   detrend = gfits_table_get_DetReg (&db.ftable, &Ndetrend, &db.swapped);
+  if (!detrend) {
+    fprintf (stderr, "ERROR: failed to read detrend info\n");
+    exit (2);
+  }
   
   match = MatchCriteria (detrend, Ndetrend, &Nmatch);          /* match basic criteria */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imphotsearch.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imphotsearch.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imphotsearch.c	(revision 28723)
@@ -33,4 +33,8 @@
 
   image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   match = subset (image, Nimage, &Nmatch);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imregtable.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imregtable.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imregtable.c	(revision 28723)
@@ -34,4 +34,8 @@
 
   image = gfits_table_get_RegImage (&ftable, &Nimage, NULL);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   /* load database table */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imsearch.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imsearch.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imsearch.c	(revision 28723)
@@ -30,4 +30,8 @@
 
   image = gfits_table_get_RegImage (&db.ftable, &Nimage, &db.swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
   
   match = match_criteria (image, Nimage, &Nmatch);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imstatreg.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imstatreg.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/imstatreg.c	(revision 28723)
@@ -67,4 +67,8 @@
     }
     subset = gfits_table_get_RegImage (&temp_db.ftable, &Nsubset, &temp_db.swapped);
+    if (!subset) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+    }
     fprintf (stderr, "temporary database read\n");
 
@@ -93,4 +97,8 @@
     }
     image = gfits_table_get_RegImage (&image_db.ftable, &Nimage, &image_db.swapped);
+    if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+    }
     fprintf (stderr, "main database read\n");
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/photsearch.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/photsearch.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/photsearch.c	(revision 28723)
@@ -42,7 +42,15 @@
   if (output.convert) {
     photpars_old = gfits_table_get_PhotParsOld (&db.ftable, &Nphotpars, &db.swapped);
+    if (!photpars_old) {
+      fprintf (stderr, "ERROR: failed to read photometry parameters\n");
+      exit (2);
+    }
     photpars = PhotParsOld_to_PhotPars (photpars_old, Nphotpars);
   } else {
     photpars = gfits_table_get_PhotPars (&db.ftable, &Nphotpars, &db.swapped);
+    if (!photpars) {
+      fprintf (stderr, "ERROR: failed to read photometry parameters\n");
+      exit (2);
+    }
   }
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/spsearch.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/spsearch.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/imregister/src/spsearch.c	(revision 28723)
@@ -30,4 +30,8 @@
 
   spectrum = gfits_table_get_Spectrum (&db.ftable, &Nspectrum, &db.swapped);
+  if (!spectrum) {
+    fprintf (stderr, "ERROR: failed to read spectrum\n");
+    exit (2);
+  }
   
   match = match_criteria (spectrum, Nspectrum, &Nmatch);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/markstar/src/find_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/markstar/src/find_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/markstar/src/find_images.c	(revision 28723)
@@ -26,4 +26,8 @@
 
   timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
+  if (!timage) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
 
   /* set up buffers for images, temporary storage */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/mosastro/src/rfits.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/mosastro/src/rfits.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/mosastro/src/rfits.c	(revision 28723)
@@ -32,4 +32,9 @@
   off_t Nstars;
   stars = gfits_table_get_SMPData (&table, &Nstars, NULL);
+  if (!stars) {
+    fprintf (stderr, "ERROR: failed to read stars\n");
+    exit (2);
+  }
+
   mychip[0].Nstars = Nstars;
   gfits_scan (table.header, "NAXIS1", "%d", 1, &Nx);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/LoadImages.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/LoadImages.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/LoadImages.c	(revision 28723)
@@ -38,4 +38,8 @@
 
   image = gfits_table_get_Image (&db.ftable, Nimage, &db.swapped);
+  if (!image) {
+    fprintf (stderr, "ERROR: failed to read images\n");
+    exit (2);
+  }
   return (image);
 }
Index: /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/cmpReadFile.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/cmpReadFile.c	(revision 28723)
@@ -20,4 +20,8 @@
 
   smpdata = gfits_table_get_SMPData (&table, &Nstars, NULL);
+  if (!smpdata) {
+    fprintf (stderr, "ERROR: failed to read stars\n");
+    exit (2);
+  }
 
   ALLOCATE (stars, CMPstars, Nstars);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/copy_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/copy_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/copy_images.c	(revision 28723)
@@ -46,4 +46,8 @@
     
   image = gfits_table_get_Image (&in.ftable, &Nimage, &in.swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
   dvo_image_addrows (&out, image, Nimage);
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/find_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/find_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/find_images.c	(revision 28723)
@@ -28,4 +28,8 @@
 
   timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
+  if (!timage) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   nimage = 0;
@@ -97,6 +101,6 @@
       if (found) {
 	image[nimage] = timage[i]; 
-	if (image[nimage].code == ID_IMAGE_NOCAL) {
-	  image[nimage].code &= ~ID_IMAGE_NOCAL;
+	if (image[nimage].code == ID_IMAGE_PHOTOM_NOCAL) {
+	  image[nimage].code &= ~ID_IMAGE_PHOTOM_NOCAL;
 	}	    
 	line_number[nimage] = i;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/flag_measures.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/flag_measures.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/photdbc/src/flag_measures.c	(revision 28723)
@@ -16,4 +16,8 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   PhotNsec = GetPhotcodeNsecfilt ();
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/ImageOps.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/ImageOps.c	(revision 28723)
@@ -323,5 +323,5 @@
     /* on PoorImages run, skip good images */
     if (PoorImages) {
-      bad = image[i].flags & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
+      bad = image[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);
       if (!bad) continue;
     }      
@@ -369,8 +369,8 @@
       mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
       if (mark) {
-	image[i].flags |= ID_IMAGE_FEW;
+	image[i].flags |= ID_IMAGE_PHOTOM_FEW;
 	Nfew ++;
       } else {
-	image[i].flags &= ~ID_IMAGE_FEW;
+	image[i].flags &= ~ID_IMAGE_PHOTOM_FEW;
       }      
     }
@@ -387,5 +387,5 @@
 
   if (PoorImages) {
-    IMAGE_BAD = ID_IMAGE_POOR | ID_IMAGE_FEW | ID_IMAGE_SKIP;
+    IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
     STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
@@ -429,11 +429,11 @@
   for (i = 0; i < Nimage; i++) {
     mark = FALSE;
-    image[i].flags &= ~ID_IMAGE_POOR;
+    image[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].Mcal - MedOffset) > MaxOffset);
     if (mark) { 
       Nmark ++;
-      image[i].flags |= ID_IMAGE_POOR;
+      image[i].flags |= ID_IMAGE_PHOTOM_POOR;
     } else {
-      image[i].flags &= ~ID_IMAGE_POOR;
+      image[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     }
   }
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/MosaicOps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/MosaicOps.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/MosaicOps.c	(revision 28723)
@@ -189,6 +189,6 @@
       image[im].dMcal = mosaic[i].dMcal;
       image[im].Xm = mosaic[i].Xm;
-      image[im].flags |= (mosaic[i].flags & ID_IMAGE_FEW);
-      image[im].flags |= (mosaic[i].flags & ID_IMAGE_POOR);
+      image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW);
+      image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR);
     }
   }      
@@ -351,5 +351,5 @@
     /* on PoorImages run, skip good images */
     if (PoorImages) {
-      bad = mosaic[i].flags & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
+      bad = mosaic[i].flags & (ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP);
       if (!bad) continue;
     }      
@@ -401,8 +401,8 @@
       if (mark) {
 	fprintf (stderr, "marked mosaic %s ("OFF_T_FMT"), ("OFF_T_FMT" < %d) || ("OFF_T_FMT" < %f*"OFF_T_FMT")\n", image[imlist[i][0]].name,  i,  N, IMAGE_TOOFEW,  N, IMAGE_GOOD_FRACTION,  Nlist[i]);
-	mosaic[i].flags |= ID_IMAGE_FEW;
+	mosaic[i].flags |= ID_IMAGE_PHOTOM_FEW;
 	Nfew ++;
       } else {
-	mosaic[i].flags &= ~ID_IMAGE_FEW;
+	mosaic[i].flags &= ~ID_IMAGE_PHOTOM_FEW;
       }
     }
@@ -421,5 +421,5 @@
 
   if (PoorImages) {
-    IMAGE_BAD = ID_IMAGE_POOR | ID_IMAGE_FEW | ID_IMAGE_SKIP;
+    IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
     STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
     MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
@@ -593,7 +593,7 @@
     if (mark) { 
       Nmark ++;
-      mosaic[i].flags |= ID_IMAGE_POOR;
+      mosaic[i].flags |= ID_IMAGE_PHOTOM_POOR;
     } else {
-      mosaic[i].flags &= ~ID_IMAGE_POOR;
+      mosaic[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     }
   }
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/StarOps.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/StarOps.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/StarOps.c	(revision 28723)
@@ -302,5 +302,5 @@
 }
 
-/* set measure.Mcal for all measures except ID_MEAS_NOCAL and ID_IMAGE_NOCAL */
+/* set measure.Mcal for all measures except ID_MEAS_NOCAL and ID_IMAGE_PHOTOM_NOCAL */
 int setMcalOutput (Catalog *catalog, int Ncatalog) {
 
@@ -310,5 +310,5 @@
 
   MEAS_BAD = ID_MEAS_NOCAL;
-  IMAGE_BAD = ID_IMAGE_NOCAL;
+  IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
 
   for (i = 0; i < Ncatalog; i++) {
@@ -470,5 +470,5 @@
       /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */
       image_bad = IMAGE_BAD;
-      IMAGE_BAD = ID_IMAGE_NOCAL;
+      IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
       m = catalog[i].average[j].measureOffset;
       N = 0;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/initialize.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/initialize.c	(revision 28723)
@@ -27,5 +27,5 @@
   initstats (STATMODE);
 
-  IMAGE_BAD = ID_IMAGE_POOR | ID_IMAGE_FEW | ID_IMAGE_SKIP;
+  IMAGE_BAD = ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_SKIP;
   STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
   MEAS_BAD  = ID_MEAS_NOCAL | ID_MEAS_POOR_PHOTOM | ID_MEAS_SKIP_PHOTOM | ID_MEAS_AREA;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/load_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/load_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/load_images.c	(revision 28723)
@@ -25,4 +25,8 @@
   // convert database table to internal structure
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   // select the images which overlap the selected sky regions
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/select_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/select_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/select_images.c	(revision 28723)
@@ -157,11 +157,11 @@
       image[nimage] = timage[i]; 
       /* always allow 'few' images to succeed, if possible */
-      if (image[nimage].flags & ID_IMAGE_FEW) { 
-	image[nimage].flags &= ~(ID_IMAGE_FEW | ID_IMAGE_POOR);
+      if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) { 
+	image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
       }
       if (RESET) {
 	assignMcal (&image[nimage], (double *) NULL, -1);
 	image[nimage].dMcal = NAN;
-	image[nimage].flags &= ~ID_IMAGE_POOR;
+	image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR;
       }
       line_number[nimage] = i;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/setMrelFinal.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/setMrelFinal.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/relphot/src/setMrelFinal.c	(revision 28723)
@@ -75,5 +75,5 @@
 
   /* allow measures from images marked POOR and FEW */
-  if (pass >= 3) IMAGE_BAD = ID_IMAGE_NOCAL;
+  if (pass >= 3) IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
   
   /* allow measures marked as outliers (POOR) and off image region (AREA) */
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_sgroups.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_sgroups.c	(revision 28723)
@@ -13,4 +13,8 @@
   imlink = *Imlink;
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   coords.crpix1 = coords.crpix2 = 0.0;
@@ -28,5 +32,5 @@
   for (i = 0; i < Nimage; i++) {
     if (imlink[i].sgroup != NULL) continue;
-    if (image[i].flags & ID_IMAGE_NOCAL) continue;
+    if (image[i].flags & ID_IMAGE_PHOTOM_NOCAL) continue;
 
     /* new sgroup, set ref coords */
@@ -53,5 +57,5 @@
 
     for (j = 0; j < Nimage; j++) {
-      if (image[j].flags & ID_IMAGE_NOCAL) continue;
+      if (image[j].flags & ID_IMAGE_PHOTOM_NOCAL) continue;
       if (imlink[j].sgroup != NULL) continue;
 
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_tgroups.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_tgroups.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/find_image_tgroups.c	(revision 28723)
@@ -12,4 +12,9 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
+
   ALLOCATE (imlink, ImageLink, Nimage);
 
@@ -64,5 +69,5 @@
       if (image[j].tzero < tmin[i]) continue;
       if (image[j].tzero > tmax[i]) continue;
-      if (image[j].flags & ID_IMAGE_NOCAL) continue;
+      if (image[j].flags & ID_IMAGE_PHOTOM_NOCAL) continue;
       
       group[i].image[Nentry] = &image[j];
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/initialize.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/initialize.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/initialize.c	(revision 28723)
@@ -16,5 +16,5 @@
   }
 
-  IMAGE_BAD = ID_IMAGE_NOCAL | ID_IMAGE_POOR | ID_IMAGE_SKIP | ID_IMAGE_FEW;
+  IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL | ID_IMAGE_PHOTOM_POOR | ID_IMAGE_PHOTOM_SKIP | ID_IMAGE_PHOTOM_FEW;
 
   initstats (STATMODE);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/load_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/load_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/load_images.c	(revision 28723)
@@ -22,4 +22,8 @@
   /* use a vtable to keep the images to be calibrated */
   image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   fprintf (stderr, "loaded "OFF_T_FMT" images\n", *Nimage);
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/match_zpts_to_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/match_zpts_to_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/match_zpts_to_images.c	(revision 28723)
@@ -70,5 +70,5 @@
     // we have a match: set zpt and record the match
     image[Ni].Mcal = SCALE*code[0].C - zpts[Nz].zpt;
-    image[Ni].flags &= ~ID_IMAGE_NOCAL; // clear the NOCAL flag
+    image[Ni].flags &= ~ID_IMAGE_PHOTOM_NOCAL; // clear the NOCAL flag
     zpts[Nz].found = TRUE;
     NImatch ++;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/subset_images.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/subset_images.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/subset_images.c	(revision 28723)
@@ -9,4 +9,8 @@
   /* use a vtable to keep the images to be calibrated */
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   Nkeep = 0;
@@ -16,5 +20,5 @@
   for (i = 0; i < Nimage; i++) {
       
-    image[i].flags |= ID_IMAGE_NOCAL;
+    image[i].flags |= ID_IMAGE_PHOTOM_NOCAL;
 
     /* select images by photcode */
@@ -27,5 +31,5 @@
       if (image[i].tzero > TSTOP) continue;
     }
-    image[i].flags &= ~ID_IMAGE_NOCAL;
+    image[i].flags &= ~ID_IMAGE_PHOTOM_NOCAL;
     keep[Nkeep] = i;
     Nkeep ++;
Index: /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/update.c
===================================================================
--- /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/update.c	(revision 28722)
+++ /branches/eam_branches/ipp-20100621/Ohana/src/uniphot/src/update.c	(revision 28723)
@@ -14,8 +14,12 @@
 
   image = gfits_table_get_Image (&db[0].ftable, &Nimage, &db[0].swapped);
+  if (!image) {
+      fprintf (stderr, "ERROR: failed to read images\n");
+      exit (2);
+  }
 
   /* clear the NOCAL flags */
   for (i = 0; i < Nimage; i++) {
-    image[i].flags &= ~ID_IMAGE_NOCAL;
+    image[i].flags &= ~ID_IMAGE_PHOTOM_NOCAL;
   }
 
