Index: trunk/psLib/src/image/psImageIO.c
===================================================================
--- trunk/psLib/src/image/psImageIO.c	(revision 1440)
+++ trunk/psLib/src/image/psImageIO.c	(revision 1840)
@@ -1,3 +1,2 @@
-
 /** @file  psImageIO.c
  *
@@ -8,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-09 23:34:58 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-21 22:30:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,8 +21,15 @@
 #include "psMemory.h"
 
+#include "psImageErrors.h"
+
 psImage* psImageReadSection(psImage* output,
                             int col,
                             int row,
-                            int numCols, int numRows, int z, char *extname, int extnum, char *filename)
+                            int numCols,
+                            int numRows,
+                            int z,
+                            char *extname,
+                            int extnum,
+                            char *filename)
 {
     fitsfile *fptr = NULL;      /* Pointer to the FITS file */
@@ -42,5 +48,7 @@
 
     if (filename == NULL) {
-        psError(__func__, "Must specify filename; it can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImageIO_FILENAME_NULL);
         psFree(output);
         return NULL;
@@ -51,5 +59,8 @@
     if (fptr == NULL || status != 0) {
         fits_get_errstatus(status, fitsErr);
-        psError(__func__, "Could not open file '%s'. (%s)", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageIO_FILENAME_INVALID,
+                   filename, fitsErr);
         psFree(output);
         return NULL;
@@ -62,5 +73,8 @@
             status = 0;
             (void)fits_close_file(fptr, &status);
-            psError(__func__, "Could not index to '%s' HDU for file %s. (%s)", extname, filename, fitsErr);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                       PS_ERR_LOCATION_INVALID, true,
+                       PS_ERRORTEXT_psImageIO_EXTNAME_INVALID,
+                       extname, filename, fitsErr);
             psFree(output);
             return NULL;
@@ -71,5 +85,8 @@
             status = 0;
             (void)fits_close_file(fptr, &status);
-            psError(__func__, "Could not index to HDU #%d for file %s. (%s)", extnum, filename, fitsErr);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                       PS_ERR_LOCATION_INVALID, true,
+                       PS_ERRORTEXT_psImageIO_EXTNUM_INVALID,
+                       extnum, filename, fitsErr);
             psFree(output);
             return NULL;
@@ -82,5 +99,8 @@
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError("Could not determine image data type of '%s'. (%s)", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_DATATYPE_UNKNOWN,
+                   filename, fitsErr);
         psFree(output);
         return NULL;
@@ -92,5 +112,8 @@
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError("Could not determine dimensions of '%s'. (%s)", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_IMAGE_DIM_UNKNOWN,
+                   filename, fitsErr);
         psFree(output);
         return NULL;
@@ -101,5 +124,8 @@
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError("Dimensions of '%s' are not supported (NAXIS=%i).", filename, nAxis);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_IMAGE_DIMENSION_UNSUPPORTED,
+                   nAxis);
         psFree(output);
         return NULL;
@@ -111,5 +137,8 @@
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError("Could not determine image size of '%s'. (%s)", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_IMAGE_SIZE_UNKNOWN,
+                   filename, fitsErr);
         psFree(output);
         return NULL;
@@ -134,9 +163,4 @@
     increment[1] = 1;
     increment[2] = 1;
-
-    // turn off the BSCALE/BZERO processing in
-    // CFITSIO
-    // (void)fits_set_bscale(fptr,
-    // 1.0,0.0,&status);
 
     switch (bitPix) {
@@ -178,17 +202,22 @@
         break;
     default:
-        psError(__func__, "Unsupported bitpix value (%d) in FITS file %s.", bitPix, filename);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_FITS_TYPE_UNSUPPORTED,
+                   bitPix, filename);
         psFree(output);
         return NULL;
     }
     output = psImageRecycle(output, numCols, numRows, datatype);
-    if (fits_read_subset
-            (fptr, fitsDatatype, firstPixel,
-             lastPixel, increment, NULL, output->data.V[0], &anynull, &status) != 0) {
+    if (fits_read_subset(fptr, fitsDatatype, firstPixel, lastPixel, increment,
+                         NULL, output->data.V[0], &anynull, &status) != 0) {
         psFree(output);
         (void)fits_get_errstatus(status, fitsErr);
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError(__func__, "Failed to read image [%s]", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageReadSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_READ_FAILED,
+                   filename, fitsErr);
         return NULL;
     }
@@ -199,5 +228,10 @@
 }
 
-bool psImageWriteSection(psImage* input, int col0, int row0, int z, char *extname, int extnum,
+bool psImageWriteSection(psImage* input,
+                         int col0,
+                         int row0,
+                         int z,
+                         char *extname,
+                         int extnum,
                          char *filename)
 {
@@ -220,5 +254,7 @@
     /* need a valid image to write */
     if (input == NULL) {
-        psError(__func__, "Can not write %s.  Input psImage is NULL.", filename);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         return false;
     }
@@ -263,8 +299,13 @@
         datatype = TDOUBLE;
         break;
-    default:
-        psError(__func__,
-                "psImage datatype (%d) not supported.  File %s not written.", input->type.type, filename);
-        return false;
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,input->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImageIO_TYPE_UNSUPPORTED,
+                       typeStr);
+            return false;
+        }
     }
 
@@ -275,5 +316,8 @@
         if (fptr == NULL || status != 0) {
             fits_get_errstatus(status, fitsErr);
-            psError(__func__, "Could not open file '%s'. FITS error:%s", filename, fitsErr);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                       PS_ERR_BAD_PARAMETER_VALUE, true,
+                       PS_ERRORTEXT_psImageIO_FILENAME_INVALID,
+                       filename, fitsErr);
             return false;
         }
@@ -285,6 +329,8 @@
                 status = 0;
                 (void)fits_close_file(fptr, &status);
-                psError(__func__,
-                        "Could not index to '%s' HDU for file %s. (%s)", extname, filename, fitsErr);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                           PS_ERR_LOCATION_INVALID, true,
+                           PS_ERRORTEXT_psImageIO_EXTNAME_INVALID,
+                           extname, filename, fitsErr);
                 return false;
             }
@@ -296,6 +342,8 @@
                 status = 0;
                 (void)fits_close_file(fptr, &status);
-                psError(__func__,
-                        "extnum (%d) must not exceed number of HDUs (%d) by more than one.", extnum, numHDUs);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                           PS_ERR_LOCATION_INVALID, true,
+                           PS_ERRORTEXT_psImageIO_WRITE_EXTNUM_INVALID,
+                           extnum, numHDUs);
                 return false;
             } else if (numHDUs == extnum) {
@@ -305,5 +353,8 @@
                 status = 0;
                 (void)fits_close_file(fptr, &status);
-                psError(__func__, "Could not index to HDU #%d for file %s. (%s)", extnum, filename, fitsErr);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                           PS_ERR_LOCATION_INVALID, true,
+                           PS_ERRORTEXT_psImageIO_EXTNUM_INVALID,
+                           extnum, filename, fitsErr);
                 return false;
             }
@@ -318,5 +369,8 @@
         if (fptr == NULL || status != 0) {
             fits_get_errstatus(status, fitsErr);
-            psError(__func__, "Could not create file '%s'. (%s)", filename, fitsErr);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                       PS_ERR_IO, true,
+                       PS_ERRORTEXT_psImageIO_FILENAME_CREATE_FAILED,
+                       filename, fitsErr);
             return false;
         }
@@ -333,5 +387,8 @@
             status = 0;
             (void)fits_close_file(fptr, &status);
-            psError(__func__, "Could not create image HDU in FITS file '%s'. %s", filename, fitsErr);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                       PS_ERR_IO, true,
+                       PS_ERRORTEXT_psImageIO_CREATE_HDU_FAILED,
+                       filename, fitsErr);
             return false;
         }
@@ -347,6 +404,8 @@
                 status = 0;
                 (void)fits_close_file(fptr, &status);
-                psError(__func__,
-                        "Could not create EXTNAME keyword in FITS file '%s'. (%s)", filename, fitsErr);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                           PS_ERR_IO, true,
+                           PS_ERRORTEXT_psImageIO_CREATE_EXTENSION_FAILED,
+                           filename, fitsErr);
                 return false;
             }
@@ -366,5 +425,8 @@
         status = 0;
         (void)fits_close_file(fptr, &status);
-        psError(__func__, "Could not write image data to '%s'. (%s)", filename, fitsErr);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageWriteSection",
+                   PS_ERR_IO, true,
+                   PS_ERRORTEXT_psImageIO_WRITE_FAILED,
+                   filename, fitsErr);
         return false;
     }
