Index: trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- trunk/psLib/src/fits/psFitsImage.c	(revision 15920)
+++ trunk/psLib/src/fits/psFitsImage.c	(revision 16095)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-12-25 01:31:21 $
+ *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-01-16 20:10:35 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -243,14 +243,16 @@
 # if (0)
 // XXX this needs to be optional (eg, invalid for a mask)
-// Apply the BSCALE and BZERO for an image with a "fuzz"
+
+// Apply the BSCALE and BZERO for an image with a "fuzz", so that we get the image as it should be written to
+// disk.
 // The idea is that the "fuzz" (adding a random number between 0 and 1) preserves the expectation value of
 // the image (e.g., a value of 0.1 will get translated to zero 90% of the time, and unity 10% of the time),
 // though at the cost of adding an additional variance of 1/12 (a standard deviation of ~0.29).
-static psImage *scaleImageWrite(psImage *image, // Image to which to apply BSCALE and BZERO
-                                int bitpix, // Output BITPIX
-                                double bscale, // Scaling
-                                double bzero, // Zero point
-                                psRandom *rng // Random number generator (for the "fuzz"), or NULL
-    )
+static psImage *scaleImageForDisk(psImage *image, // Image to which to apply BSCALE and BZERO
+                                  int bitpix, // Output BITPIX
+                                  double bscale, // Scaling
+                                  double bzero, // Zero point
+                                  psRandom *rng // Random number generator (for the "fuzz"), or NULL
+                                  )
 {
     assert(image);
@@ -339,10 +341,10 @@
 // Determine BSCALE and BZERO for an image, and generate a new image with it applied
 // TRUE = BZERO + BSCALE * FITS
-static psImage *scaleImageDetermineWrite(double *bscale, // Scaling, to return
-                                         double *bzero, // Zero point, to return
-                                         psImage *image, // Image to scale
-                                         int bitpix, // Desired bits per pixel
-                                         psRandom *rng // Random number generator for scaleImageWrite
-    )
+static psImage *scaleImageDetermine(double *bscale, // Scaling, to return
+                                    double *bzero, // Zero point, to return
+                                    psImage *image, // Image to scale
+                                    int bitpix, // Desired bits per pixel
+                                    psRandom *rng // Random number generator for scaleImageForDisk
+                                    )
 {
     PS_ASSERT_PTR_NON_NULL(bscale, NULL);
@@ -412,5 +414,5 @@
     psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf\n", *bscale, *bzero);
 
-    return scaleImageWrite(image, bitpix, *bscale, *bzero, rng);
+    return scaleImageForDisk(image, bitpix, *bscale, *bzero, rng);
 }
 # endif
@@ -420,5 +422,5 @@
 // the present time, since cfitsio should apply the scaling itself in the process of reading.  However, we may
 // later desire it.
-static psImage *scaleImageRead(psFits *fits, psImage *image)
+static psImage *scaleImageFromDisk(psFits *fits, psImage *image)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
@@ -500,13 +502,13 @@
 #endif
 
-// Convert an image to the desired BITPIX
-static psImage *convertImageWrite(double *bscale, // Scaling applied
-                                  double *bzero, // Zero point applied
-                                  psFitsFloat *floatType, // Type of custom floating-point
-                                  psFits *fits, // FITS file pointer
-                                  const psImage *image, // Current type
-                                  psRandom *rng, // Random number generator
-                                  bool newScaleZero // Determine a new BSCALE and BZERO?
-    )
+// Convert an image to the desired BITPIX, i.e., the desired disk representation
+static psImage *imageToDiskRepresentation(double *bscale, // Scaling applied
+                                          double *bzero, // Zero point applied
+                                          psFitsFloat *floatType, // Type of custom floating-point
+                                          psFits *fits, // FITS file pointer
+                                          const psImage *image, // Current type
+                                          psRandom *rng, // Random number generator
+                                          bool newScaleZero // Determine a new BSCALE and BZERO?
+                                          )
 {
     assert(bscale);
@@ -524,5 +526,5 @@
         fits->floatType != PS_FITS_FLOAT_NONE) {
         *floatType = fits->floatType;
-        return psFitsFloatImageWrite(image, fits->floatType);
+        return psFitsFloatImageToDisk(image, fits->floatType);
     }
 
@@ -537,5 +539,5 @@
     if (PS_IS_PSELEMTYPE_REAL(image->type.type) && fits->bitpix > 0) {
         if (newScaleZero) {
-            return scaleImageDetermineWrite(bscale, bzero, (psImage*)image, fits->bitpix, rng);
+            return scaleImageDetermine(bscale, bzero, (psImage*)image, fits->bitpix, rng);
         }
         // Get the current BSCALE and BZERO
@@ -556,5 +558,5 @@
             return NULL;
         }
-        return scaleImageWrite((psImage*)image, fits->bitpix, *bscale, *bzero, rng);
+        return scaleImageForDisk((psImage*)image, fits->bitpix, *bscale, *bzero, rng);
     }
     # endif
@@ -655,5 +657,5 @@
 
     if (floatType != PS_FITS_FLOAT_NONE) {
-        outImage = psFitsFloatImageRead(outImage, inImage, floatType);
+        outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType);
     }
     psFree(inImage);
@@ -707,5 +709,5 @@
 
     if (floatType != PS_FITS_FLOAT_NONE) {
-        outImage = psFitsFloatImageRead(outImage, inImage, floatType);
+        outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType);
     }
     psFree(inImage);
@@ -742,6 +744,6 @@
     double bscale = 0.0, bzero = 0.0;   // Scale and zero point to put in header (*already* applied to data)
     psFitsFloat floatType;              // Custom floating-point convention type
-    psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, image,
-                                           NULL, true); // Image to write out
+    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, image,
+                                                   NULL, true); // Image to write out
     if (!diskImage) {
         psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format.");
@@ -758,5 +760,6 @@
     }
     if (cfitsioBzero != 0.0) {
-        assert(bzero == 0.0 && bscale == 1.0); // p_psFitsTypeToCfitsio and convertImageWrite must not clash
+        // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!
+        assert(bzero == 0.0 && bscale == 1.0);
         bscale = 1.0;
         bzero = cfitsioBzero;
@@ -871,6 +874,6 @@
     double bscale = 0.0, bzero = 0.0;   // Scale and zero point to put in header (*already* applied to data)
     psFitsFloat floatType;              // Custom floating-point convention type
-    psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, input,
-                                           NULL, false); // Image to write out
+    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, input,
+                                                   NULL, false); // Image to write out
     if (!diskImage) {
         psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format.");
@@ -882,10 +885,11 @@
     double cfitsioBzero = 0.0;          // Zero point for cfitsio to apply
     int dataType;                       // cfitsio data type
-    if (! p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) {
+    if (!p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) {
         psFree(diskImage);
         return false;
     }
     if (cfitsioBzero != 0.0) {
-        assert(bzero == 0.0 && bscale == 1.0); // p_psFitsTypeToCfitsio and convertImageWrite must not clash
+        // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!
+        assert(bzero == 0.0 && bscale == 1.0);
         bscale = 1.0;
         bzero = cfitsioBzero;
