Index: trunk/psModules/src/objects/pmSourceIO.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.c	(revision 16819)
+++ trunk/psModules/src/objects/pmSourceIO.c	(revision 17010)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-03-05 01:08:08 $
+ *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-03-17 22:04:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -278,4 +278,8 @@
         // a SPLIT format : only one header and object table per file
         hdu = pmFPAviewThisHDU (view, file->fpa);
+        if (!hdu) {
+            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
+            return false;
+        }
 
         // copy the header to an output header, add the output header data
@@ -310,15 +314,19 @@
         // get the current header
         hdu = pmFPAviewThisHDU (view, file->fpa);
-
-	// determine the output table format
-	psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
-	if (!status) {
-	  psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
-	  return false;
-	}
-
-	// if this is not TRUE, the output files only contain the psf measurements.
-	bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "SAVE.XSRC");
-	bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "SAVE.XFIT");
+        if (!hdu) {
+            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
+            return false;
+        }
+
+        // determine the output table format
+        psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
+        if (!status) {
+          psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
+          return false;
+        }
+
+        // if this is not TRUE, the output files only contain the psf measurements.
+        bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "SAVE.XSRC");
+        bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "SAVE.XFIT");
 
         // define the EXTNAME values for the different data segments:
@@ -350,22 +358,22 @@
             dataname = pmFPAfileNameFromRule (rule, file, view);
 
-	    if (XSRC_OUTPUT) {
-	      // EXTNAME for extended source data table
-	      rule = psMetadataLookupStr(&status, menu, "CMF.XSRC");
-	      if (!rule) {
+            if (XSRC_OUTPUT) {
+              // EXTNAME for extended source data table
+              rule = psMetadataLookupStr(&status, menu, "CMF.XSRC");
+              if (!rule) {
                 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XSRC in EXTNAME.RULES in camera.config");
                 return false;
-	      }
-	      xsrcname = pmFPAfileNameFromRule (rule, file, view);
-	    }
-	    if (XFIT_OUTPUT) {
-	      // EXTNAME for extended source data table
-	      rule = psMetadataLookupStr(&status, menu, "CMF.XFIT");
-	      if (!rule) {
+              }
+              xsrcname = pmFPAfileNameFromRule (rule, file, view);
+            }
+            if (XFIT_OUTPUT) {
+              // EXTNAME for extended source data table
+              rule = psMetadataLookupStr(&status, menu, "CMF.XFIT");
+              if (!rule) {
                 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XFIT in EXTNAME.RULES in camera.config");
                 return false;
-	      }
-	      xfitname = pmFPAfileNameFromRule (rule, file, view);
-	    }
+              }
+              xfitname = pmFPAfileNameFromRule (rule, file, view);
+            }
         }
 
@@ -416,11 +424,11 @@
             psFree (exttype);
 
-	    // if we request XSRC output, add the XSRC name to this header
-	    if (xsrcname) {
-	      psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
-	    }
-	    if (xfitname) {
-	      psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
-	    }
+            // if we request XSRC output, add the XSRC name to this header
+            if (xsrcname) {
+              psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
+            }
+            if (xfitname) {
+              psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
+            }
 
             // XXX these are case-sensitive since the EXTYPE is case-sensitive
@@ -435,14 +443,14 @@
                 status = pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname, xsrcname);
             }
-	    if (xsrcname) {
-	      if (!strcmp (exttype, "PS1_DEV_1")) {
+            if (xsrcname) {
+              if (!strcmp (exttype, "PS1_DEV_1")) {
                 status = pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname);
-	      }
-	    }
-	    if (xfitname) {
-	      if (!strcmp (exttype, "PS1_DEV_1")) {
+              }
+            }
+            if (xfitname) {
+              if (!strcmp (exttype, "PS1_DEV_1")) {
                 status = pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname);
-	      }
-	    }
+              }
+            }
             if (!status) {
                 psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
