Index: /trunk/psastro/src/psastroLoadRefstars.c
===================================================================
--- /trunk/psastro/src/psastroLoadRefstars.c	(revision 16961)
+++ /trunk/psastro/src/psastroLoadRefstars.c	(revision 16962)
@@ -79,5 +79,5 @@
 
     // XXX use psPipe: catch stderr, stdout, allow for Nsec timeout...
-    // use fork to add timeout capability 
+    // use fork to add timeout capability
     status = system (getstarCommand);
     if (status) {
@@ -103,7 +103,13 @@
     if (refstars == NULL) {
         psError(PSASTRO_ERR_REFSTARS, true, "error reading reference data\n");
-        return NULL;
-    }
-    assert (refstars->n > 0);
+        psFitsClose (fits);
+        return NULL;
+    }
+    if (refstars->n == 0) {
+        psError(PSASTRO_ERR_REFSTARS, true, "no reference stars found");
+        psFitsClose (fits);
+        psFree(refstars);
+        return NULL;
+    }
 
     psLogMsg ("psastro", 3, "loaded %ld reference stars : %f sec\n", refstars->n, psTimerMark ("psastro"));
@@ -157,10 +163,10 @@
         }
 
-	// XXX VERY temporary hack to avoid M31 bulge
-	if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) {
-	  psFree (ref);
-	  psFree (row);
-	  continue;
-	}
+        // XXX VERY temporary hack to avoid M31 bulge
+        if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) {
+          psFree (ref);
+          psFree (row);
+          continue;
+        }
 
         psArrayAdd (refstars, 100, ref);
@@ -186,14 +192,14 @@
         psMetadata *row = psFitsReadTableRow(fits, i); // Table row
 
-	ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
-	ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
-	ref->Mag      = psMetadataLookupF32 (&status, row, "MAG");
-
-	// XXX VERY temporary hack to avoid M31 bulge
-	if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) { 
-	  psFree (ref);
-	  psFree (row);
-	  continue;
-	}
+        ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
+        ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
+        ref->Mag      = psMetadataLookupF32 (&status, row, "MAG");
+
+        // XXX VERY temporary hack to avoid M31 bulge
+        if ((fabs(ref->sky->r - 0.186438) < 0.002) && (fabs(ref->sky->d - 0.720270) < 0.002)) {
+          psFree (ref);
+          psFree (row);
+          continue;
+        }
 
         psArrayAdd (refstars, 100, ref);
