Index: trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- trunk/psLib/src/fits/psFitsImage.c	(revision 38535)
+++ trunk/psLib/src/fits/psFitsImage.c	(revision 38538)
@@ -751,35 +751,35 @@
 
     // Remove any BOFFSET values that exist in the header if we are not using that scaling anymore
-    if (options&&(!((options->scaling == PS_FITS_SCALE_LOG_RANGE)||
-		    (options->scaling == PS_FITS_SCALE_LOG_MANUAL)||
-		    (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
-		    (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
-		    (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
-      if (psMetadataLookup(header,"BOFFSET")) {
+    if (options && (!((options->scaling == PS_FITS_SCALE_LOG_RANGE)||
+		      (options->scaling == PS_FITS_SCALE_LOG_MANUAL)||
+		      (options->scaling == PS_FITS_SCALE_LOG_STDEV_POSITIVE)||
+		      (options->scaling == PS_FITS_SCALE_LOG_STDEV_NEGATIVE)||
+		      (options->scaling == PS_FITS_SCALE_LOG_STDEV_BOTH)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
+      if (header && psMetadataLookup(header,"BOFFSET")) {
 	psMetadataRemoveKey(header,"BOFFSET");
       }
     }	
     // Remove any BSOFTENvalues that exist in the header if we are not using that scaling anymore
-    if (options&&(!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
-		    (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
-      if (psMetadataLookup(header,"BSOFTEN")) {
+    if (options && (!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_POSITIVE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_NEGATIVE)||
+		      (options->scaling == PS_FITS_SCALE_ASINH_STDEV_BOTH)))) {
+      if (header && psMetadataLookup(header,"BSOFTEN")) {
 	psMetadataRemoveKey(header,"BSOFTEN");
       }
     }	
 
-    // If there is no options set, remove all our non-standard keywords, because no one asked for them.
+    // If there are no options set, remove all our non-standard keywords, because no one asked for them.
     if (!options) {
-      if (psMetadataLookup(header,"BOFFSET")) {
+      if (header && psMetadataLookup(header,"BOFFSET")) {
 	psMetadataRemoveKey(header,"BOFFSET");
       }
-      if (psMetadataLookup(header,"BSOFTEN")) {
+      if (header && psMetadataLookup(header,"BSOFTEN")) {
 	psMetadataRemoveKey(header,"BSOFTEN");
       }
