Index: trunk/psLib/src/astronomy/psMetadataIO.c
===================================================================
--- trunk/psLib/src/astronomy/psMetadataIO.c	(revision 2204)
+++ trunk/psLib/src/astronomy/psMetadataIO.c	(revision 2273)
@@ -9,6 +9,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-27 00:57:30 $
+*  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-04 01:04:57 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,4 +29,6 @@
 #include "psMetadata.h"
 #include "psMetadataIO.h"
+#include "psConstants.h"
+#include "psAstronomyErrors.h"
 
 
@@ -38,10 +40,10 @@
 #define FITS_ERROR(STRING,PS_ERROR) \
 fits_get_errstatus(status, fitsErr); \
-psError(__func__, STRING, PS_ERROR, fitsErr); \
+psError(PS_ERR_IO,true, STRING, PS_ERROR, fitsErr); \
 status = 0; \
 fits_close_file(fd, &status); \
 if(status){ \
     fits_get_errstatus(status, fitsErr); \
-    psError(__func__, "Couldn't close FITS file. FITS error: %s", fitsErr); \
+    psError(PS_ERR_IO,true, "Couldn't close FITS file. FITS error: %s", fitsErr); \
 } \
 status = 0; \
@@ -281,5 +283,7 @@
             default:
                 *status = 1;
-                psError(__func__, "Invalid type: %d", elemType);
+                psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                        PS_ERRORTEXT_psMetadataIO_TYPE_INVALID,
+                        elemType);
             }
 
@@ -302,18 +306,7 @@
     psMetadataType type;
 
-    if (fd == NULL) {
-        psError(__func__, "Null file descriptor not allowed");
-        return;
-    }
-
-    if (format == NULL) {
-        psError(__func__, "Null format not allowed");
-        return;
-    }
-
-    if (metadataItem == NULL) {
-        psError(__func__, "Null metadata not allowed");
-        return;
-    }
+    PS_PTR_CHECK_NULL(fd,);
+    PS_PTR_CHECK_NULL(format,);
+    PS_PTR_CHECK_NULL(metadataItem,);
 
     type = metadataItem->type;
@@ -336,5 +329,7 @@
         break;
     default:
-        psError(__func__, " Invalid psMetadataType to print: %d", type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,true,
+                PS_ERRORTEXT_psMetadata_METATYPE_INVALID,
+                (int)type);
     }
 }
@@ -358,8 +353,5 @@
     fitsfile *fd = NULL;
 
-    if(fileName == NULL) {
-        psError(__func__, "Null fileName not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(fileName,NULL);
 
     fits_open_file(&fd, fileName, READONLY, &status);
@@ -369,9 +361,8 @@
     }
 
-    if (extName == NULL && extNum == 0) {
-        psError(__func__, "Null extName and extNum = 0 not allowed");
-        return NULL;
-    } else if (extName && (extNum != -1) ) {
-        psError(__func__, "If extName specified, extNum arguments should be -1.");
+    if (extName == NULL && extNum < 1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psMetadataIO_EXTNUM_NOTPOSITIVE,
+                extNum);
         return NULL;
     }
@@ -435,10 +426,14 @@
         case 'X':
         default:
-            psError(__func__, "Invalid psMetadataType: %c", keyType);
+            psError(PS_ERR_IO, true,
+                    PS_ERRORTEXT_psMetadataIO_FITS_METATYPE_INVALID,
+                    keyType);
             return output;
         }
 
         if (!success) {
-            psError(__func__, "Failed to add metadata item. Name: %s", keyName);
+            psError(PS_ERR_UNKNOWN, false,
+                    PS_ERRORTEXT_psMetadataIO_ADD_FAILED,
+                    keyName);
             return output;
         }
@@ -471,9 +466,9 @@
 
     // Check for nulls
-    if(fileName == NULL) {
-        psError(__func__, "Null fileName not allowed");
-        return -1;
-    } else if((fp=fopen(fileName, "r")) == NULL) {
-        psError(__func__, "Couldn't open file. Name: %s", fileName);
+    PS_PTR_CHECK_NULL(fileName,-1);
+    if((fp=fopen(fileName, "r")) == NULL) {
+        psError(PS_ERR_IO, true,
+                PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED,
+                fileName);
         return -1;
     }
@@ -486,7 +481,4 @@
     // Create reusable line for continuous read
     line = (char*)psAlloc(MAX_STRING_LENGTH*sizeof(char));
-    if (line == NULL) {
-        psAbort(__func__, "Failed to allocate reusable line");
-    }
 
     // While loop to parse the file
@@ -504,13 +496,19 @@
             if(repeatedChars(linePtr, '@') > 1) {
                 failedLines++;
-                psError(__func__, "More than one @ charecter not allowed. Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR,
+                        '@', lineCount, fileName);
                 continue;
             } else if(repeatedChars(linePtr, '*') > 1) {
                 failedLines++;
-                psError(__func__, "More than one * charecter not allowed. Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR,
+                        '*', lineCount, fileName);
                 continue;
             } else if(repeatedChars(linePtr, '~') > 0) {
                 failedLines++;
-                psError(__func__, "Illegal character. Character:~ Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR,
+                        '~', lineCount, fileName);
                 continue;
             }
@@ -521,5 +519,7 @@
                 failedLines++;
                 status = 0;
-                psError(__func__, "Null name not allowed. Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,
+                        "name",lineCount, fileName);
                 continue;
             }
@@ -530,5 +530,7 @@
                 failedLines++;
                 status = 0;
-                psError(__func__, "Null type not allowed. Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,
+                        "type",lineCount, fileName);
                 continue;
             } else if(!strncmp(strType, "*", 1)) {
@@ -551,5 +553,7 @@
             } else {
                 failedLines++;
-                psError(__func__, "Invalid psMetadataType. Type: %s Line %d: %s", strType, lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID,
+                        strType, lineCount, fileName);
                 continue;
             }
@@ -565,5 +569,7 @@
                     failedLines++;
                     status = 0;
-                    psError(__func__, "Null value not allowed. Line %d: %s", lineCount, line);
+                    psError(PS_ERR_IO, true,
+                            PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,
+                            "value",lineCount, fileName);
                     continue;
                 }
@@ -575,5 +581,7 @@
                 failedLines++;
                 status = 0;
-                psError(__func__, "Failed to parse comment. Line %d: %s", lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,
+                        "comment",lineCount, fileName);
                 continue;
             }
@@ -589,6 +597,7 @@
                     } else {
                         failedLines++;
-                        psError(__func__, "Overwrite for name not allowed. Name: %s. Line %d: %s", strName,
-                                lineCount, line);
+                        psError(PS_ERR_IO, true,
+                                PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM,
+                                strName, lineCount, fileName);
                         continue;
                     }
@@ -608,5 +617,7 @@
                     status = 0;
                     failedLines++;
-                    psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line);
+                    psError(PS_ERR_IO, true,
+                            PS_ERRORTEXT_psMetadataIO_PARSE_FAILED,
+                            strValue, strName, strType, lineCount, fileName);
                     continue;
                 }
@@ -619,5 +630,7 @@
                     status = 0;
                     failedLines++;
-                    psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line);
+                    psError(PS_ERR_IO, true,
+                            PS_ERRORTEXT_psMetadataIO_PARSE_FAILED,
+                            strValue, strName, strType, lineCount, fileName);
                     continue;
                 }
@@ -631,5 +644,7 @@
                     status = 0;
                     failedLines++;
-                    psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line);
+                    psError(PS_ERR_IO, true,
+                            PS_ERRORTEXT_psMetadataIO_PARSE_FAILED,
+                            strValue, strName, strType, lineCount, fileName);
                     continue;
                 }
@@ -645,5 +660,7 @@
                     status = 0;
                     failedLines++;
-                    psError(__func__, "Failed to parse value. Value: %s Line %d: %s", strValue, lineCount, line);
+                    psError(PS_ERR_IO, true,
+                            PS_ERRORTEXT_psMetadataIO_PARSE_FAILED,
+                            strValue, strName, strType, lineCount, fileName);
                     continue;
                 }
@@ -651,5 +668,7 @@
             default:
                 failedLines++;
-                psError(__func__, "Invalid psMetadataType. Type: %d Line %d: %s", mdType, lineCount, line);
+                psError(PS_ERR_IO, true,
+                        PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID,
+                        mdType, lineCount, fileName);
                 continue;
             } // switch
