Index: trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- trunk/psLib/src/astronomy/psAstrometry.c	(revision 2222)
+++ trunk/psLib/src/astronomy/psAstrometry.c	(revision 2273)
@@ -8,6 +8,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 23:49:00 $
+ *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-04 01:04:57 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -25,4 +25,6 @@
 #include "psError.h"
 #include "psConstants.h"
+#include "psAstronomyErrors.h"
+
 #include "slalib.h"
 
@@ -868,5 +870,7 @@
     // generate an error if cell->toTP is not linear.
     if (0 == isProjectionLinear(cell->toTP)) {
-        psError(__func__, "the cell->toTP transfrom is not linear.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM,
+                "cell to tangent plane");
     }
 
Index: trunk/psLib/src/astronomy/psAstronomyErrors.dat
===================================================================
--- trunk/psLib/src/astronomy/psAstronomyErrors.dat	(revision 2222)
+++ trunk/psLib/src/astronomy/psAstronomyErrors.dat	(revision 2273)
@@ -7,2 +7,45 @@
 #  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
 ####################################################################
+psTime_FILE_NOT_FOUND                  Failed to open file %s.  No %s information is available.
+psTime_FILE_TOO_MANY_ROWS              Too many rows found in file %s. Max number of rows allowed is %d.
+psTime_TIME_POSTDATES_TABLE            Specified psTime postdates (%g) the table of %s information.
+psTime_TIME_PREDATES_TABLE             Specified psTime predates (%g) the table of %s information.
+psTime_TABLE_DUPLICATE_ROWS            The %s table was found to have two rows of the same time value.
+psTime_TYPE_UNKNOWN                    Specified type, %d, is not supported.
+psTime_TYPE_MISMATCH                   Specified psTime parameters must have same type.
+psTime_GET_TOD_FAILED                  Failed to determine the current time from gettimeofday function.
+psTime_CONVERT_TIME_TO_STRING_FAILED   Failed to convert a time via strftime function.
+psTime_APPEND_MSEC_FAILED              Failed to append millisecond to time string with snprintf function.
+psTime_USEC_INVALID                    The psTime usec attribute value, %u, is invalid.  Must be less than 1e6.
+psTime_ISOTIME_MALFORMED               Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format.
+#
+psCoord_PROJECTION_TYPE_UNDEFINED      The projection type, %s, is undefined.
+psCoord_PROJECTION_TYPE_UNKNOWN        The projection type, %d, is unknown.
+psCoord_UNITS_UNKNOWN                  Specified units, 0x%x, is not supported.
+psCoord_OFFSET_MODE_UNKNOWN            Specified offset mode, 0x%x, is not supported.
+#
+psAstrometry_NONLINEAR_TRANSFORM       The %s transfrom is not linear.  Only linear transforms are supported. 
+#
+psMetadata_METATYPE_INVALID            Specified psMetadataType, %d, is not supported.
+psMetadata_ADD_LIST_FAILED             Failed to add metadata item, %s, to items list.
+psMetadata_ADD_TABLE_FAILED            Failed to add metadata item, %s, to items table.
+psMetadata_REMOVE_LIST_FAILED          Failed to remove metadata item, %s, from metadata list.
+psMetadata_REMOVE_LIST_INDEX_FAILED    Failed to remove metadata item, at index %d, from metadata list.
+psMetadata_REMOVE_TABLE_FAILED         Failed to remove metadata item, %s, from metadata table.
+psMetadata_ADD_COLLECTION_FAILED       Failed to add metadata item, %s, to metadata collection list.
+psMetadata_ADD_FAILED                  Failed to add metadata item to metadata collection list.
+psMetadata_FIND_FAILED                 Could not find metadata item, %s.
+psMetadata_FIND_INDEX_FAILED           Could not find metadata item at index %d.
+#
+psMetadataIO_TYPE_INVALID              Specified type, %d, is not supported.
+psMetadataIO_EXTNUM_NOTPOSITIVE        Specified extension number, %d, is invalid.  Value must be positive if no extension name is given.
+psMetadataIO_FITS_METATYPE_INVALID     Specified FITS metadata type, %c, is not supported.
+psMetadataIO_ADD_FAILED                Failed to add metadata item, %s.
+psMetadataIO_FILE_OPEN_FAILED          Failed to open file '%s'.  Check if it exists and it has the proper permissions.
+psMetadataIO_FILE_MULTIPLE_CHAR        More than one '%c' character not allowed.  Found on line %d of %s.
+psMetadataIO_FILE_ELEMENT_NULL         Failed to read a metadata %s on line %d of %s.
+psMetadataIO_FILE_TYPE_INVALID         Metadata type '%s', found on line %d of %s, is not invalid.
+psMetadataIO_OVERWRITE_ITEM            Duplicate Metadata item, %s, found on line %d of %s.  Overwrite not allowed.
+psMetadataIO_PARSE_FAILED              Failed to parse the value '%s' of metadata item %s, type %s, on line %d of %s.
+
+
Index: trunk/psLib/src/astronomy/psAstronomyErrors.h
===================================================================
--- trunk/psLib/src/astronomy/psAstronomyErrors.h	(revision 2222)
+++ trunk/psLib/src/astronomy/psAstronomyErrors.h	(revision 2273)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 19:35:55 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-04 01:04:57 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,4 +30,41 @@
 
 //~Start #define PS_ERRORTEXT_$1 "$2"
+#define PS_ERRORTEXT_psTime_FILE_NOT_FOUND "Failed to open file %s.  No %s information is available."
+#define PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS "Too many rows found in file %s. Max number of rows allowed is %d."
+#define PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE "Specified psTime postdates (%g) the table of %s information."
+#define PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE "Specified psTime predates (%g) the table of %s information."
+#define PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS "The %s table was found to have two rows of the same time value."
+#define PS_ERRORTEXT_psTime_TYPE_UNKNOWN "Specified type, %d, is not supported."
+#define PS_ERRORTEXT_psTime_TYPE_MISMATCH "Specified psTime parameters must have same type."
+#define PS_ERRORTEXT_psTime_GET_TOD_FAILED "Failed to determine the current time from gettimeofday function."
+#define PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED "Failed to convert a time via strftime function."
+#define PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED "Failed to append millisecond to time string with snprintf function."
+#define PS_ERRORTEXT_psTime_USEC_INVALID "The psTime usec attribute value, %u, is invalid.  Must be less than 1e6."
+#define PS_ERRORTEXT_psTime_ISOTIME_MALFORMED "Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format."
+#define PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED "The projection type, %s, is undefined."
+#define PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN "The projection type, %d, is unknown."
+#define PS_ERRORTEXT_psCoord_UNITS_UNKNOWN "Specified units, 0x%x, is not supported."
+#define PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN "Specified offset mode, 0x%x, is not supported."
+#define PS_ERRORTEXT_psAstrometry_NONLINEAR_TRANSFORM "The %s transfrom is not linear.  Only linear transforms are supported. "
+#define PS_ERRORTEXT_psMetadata_METATYPE_INVALID "Specified psMetadataType, %d, is not supported."
+#define PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED "Failed to add metadata item, %s, to items list."
+#define PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED "Failed to add metadata item, %s, to items table."
+#define PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED "Failed to remove metadata item, %s, from metadata list."
+#define PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED "Failed to remove metadata item, at index %d, from metadata list."
+#define PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED "Failed to remove metadata item, %s, from metadata table."
+#define PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED "Failed to add metadata item, %s, to metadata collection list."
+#define PS_ERRORTEXT_psMetadata_ADD_FAILED "Failed to add metadata item to metadata collection list."
+#define PS_ERRORTEXT_psMetadata_FIND_FAILED "Could not find metadata item, %s."
+#define PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED "Could not find metadata item at index %d."
+#define PS_ERRORTEXT_psMetadataIO_TYPE_INVALID "Specified type, %d, is not supported."
+#define PS_ERRORTEXT_psMetadataIO_EXTNUM_NOTPOSITIVE "Specified extension number, %d, is invalid.  Value must be positive if no extension name is given."
+#define PS_ERRORTEXT_psMetadataIO_FITS_METATYPE_INVALID "Specified FITS metadata type, %c, is not supported."
+#define PS_ERRORTEXT_psMetadataIO_ADD_FAILED "Failed to add metadata item, %s."
+#define PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED "Failed to open file '%s'.  Check if it exists and it has the proper permissions."
+#define PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR "More than one '%c' character not allowed.  Found on line %d of %s."
+#define PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL "Failed to read a metadata %s on line %d of %s."
+#define PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID "Metadata type '%s', found on line %d of %s, is not invalid."
+#define PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM "Duplicate Metadata item, %s, found on line %d of %s.  Overwrite not allowed."
+#define PS_ERRORTEXT_psMetadataIO_PARSE_FAILED "Failed to parse the value '%s' of metadata item %s, type %s, on line %d of %s."
 //~End
 
Index: trunk/psLib/src/astronomy/psCoord.c
===================================================================
--- trunk/psLib/src/astronomy/psCoord.c	(revision 2222)
+++ trunk/psLib/src/astronomy/psCoord.c	(revision 2273)
@@ -10,6 +10,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-27 23:31:43 $
+*  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-04 01:04:57 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,4 +27,5 @@
 #include "psConstants.h"
 #include "psError.h"
+#include "psAstronomyErrors.h"
 #include <math.h>
 #include <float.h>
@@ -278,10 +279,16 @@
 
     } else if (projection->type == PS_PROJ_PAR) {
-        psError(__func__, "The projection type PS_PROJ_PAR is undefined.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED,
+                "PS_PROJ_PAR");
 
     } else if (projection->type == PS_PROJ_GLS) {
-        psError(__func__, "The projection type PS_PROJ_GLS is undefined.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED,
+                "PS_PROJ_GLS");
     } else {
-        psError(__func__, "Unknown projection type.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN,
+                projection->type);
     }
 
@@ -333,10 +340,16 @@
 
     } else if (projection->type == PS_PROJ_PAR) {
-        psError(__func__, "The projection type PS_PROJ_PAR is undefined.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED,
+                "PS_PROJ_PAR");
 
     } else if (projection->type == PS_PROJ_GLS) {
-        psError(__func__, "The projection type PS_PROJ_GLG is undefined.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNDEFINED,
+                "PS_PROJ_GLS");
     } else {
-        psError(__func__, "Unknown projection type.\n");
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psCoord_PROJECTION_TYPE_UNKNOWN,
+                projection->type);
     }
 
@@ -407,5 +420,7 @@
         } else if (unit == PS_RADIAN) {}
         else {
-            psError(__func__, "Unknown offset unit: 0x%x\n", unit);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psCoord_UNITS_UNKNOWN,
+                    unit);
         }
 
@@ -413,5 +428,7 @@
     }
 
-    psError(__func__, "Unrecognized offset mode\n");
+    psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+            PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
+            mode);
     return (NULL);
 }
@@ -469,5 +486,7 @@
             tmpD = offset->d;
         } else {
-            psError(__func__, "Unknown offset unit: 0x%x\n", unit);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psCoord_UNITS_UNKNOWN,
+                    unit);
         }
 
@@ -483,5 +502,8 @@
     }
 
-    psError(__func__, "Unrecognized offset mode\n");
+    psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+            PS_ERRORTEXT_psCoord_OFFSET_MODE_UNKNOWN,
+            mode);
+
     return (NULL);
 }
Index: trunk/psLib/src/astronomy/psMetadata.c
===================================================================
--- trunk/psLib/src/astronomy/psMetadata.c	(revision 2222)
+++ trunk/psLib/src/astronomy/psMetadata.c	(revision 2273)
@@ -12,6 +12,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-27 00:57:30 $
+*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-04 01:04:57 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,4 +35,6 @@
 #include "psMetadata.h"
 #include "psString.h"
+#include "psAstronomyErrors.h"
+#include "psConstants.h"
 
 /******************************************************************************/
@@ -123,8 +125,6 @@
 
 
-    if (name == NULL) {
-        psError(__func__, "Null value for name not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(name,NULL);
+
     // Allocate metadata item
     metadataItem = (psMetadataItem* ) psAlloc(sizeof(psMetadataItem));
@@ -147,9 +147,16 @@
     // Set metadata item type
     metadataItem->type = type;
+    metadataItem->data.V = NULL;
+
+    // Allocate metadata items with same name.
+    metadataItem->items = psListAlloc(NULL);
+
+    // Allocate and set metadata item name
+    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
+    vsprintf(metadataItem->name, name, argPtr);
 
     // Set metadata item value
     switch (type) {
     case PS_META_ITEM_SET:
-        metadataItem->data.V = NULL;
         break;
     case PS_META_BOOL:
@@ -180,13 +187,10 @@
     case PS_META_UNKNOWN:
     default:
-        psError(__func__, "Invalid psMetadataType: %d", type);
-    }
-
-    // Allocate and set metadata item name
-    metadataItem->name = (char *)psAlloc(sizeof(char) * MAX_STRING_LENGTH);
-    vsprintf(metadataItem->name, name, argPtr);
-
-    // Allocate metadata items with same name.
-    metadataItem->items = psListAlloc(NULL);
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psMetadata_METATYPE_INVALID,
+                type);
+        psFree(metadataItem);
+        metadataItem = NULL;
+    }
 
     return metadataItem;
@@ -224,33 +228,14 @@
     psMetadataType newType = PS_META_ITEM_SET;
 
-    if(md == NULL) {
-        psError( __func__, "Null metadata collection not allowed" );
-        return false;
-    }
-
-    if(metadataItem == NULL) {
-        psError( __func__, "Null metadata item not allowed" );
-        return false;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+    PS_PTR_CHECK_NULL(metadataItem,NULL);
+    PS_PTR_CHECK_NULL(metadataItem->name,NULL);
 
     newType = metadataItem->type;
-
     mdTable = md->table;
-    if(mdTable == NULL) {
-        psError( __func__, "Null metadata table not allowed" );
-        return false;
-    }
-
     mdList = md->list;
-    if(mdList == NULL) {
-        psError( __func__, "Null metadata list not allowed");
-        return false;
-    }
-
     key = metadataItem->name;
-    if(key == NULL) {
-        psError(__func__, "Null key item not allowed");
-        return false;
-    }
 
     // See if key is already in table
@@ -262,6 +247,7 @@
             // Add leaf node to existing folder node
             if(!psListAdd(existingEntry->items, PS_LIST_TAIL, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s",
-                         metadataItem->name );
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        metadataItem->name );
                 return false;
             }
@@ -272,5 +258,7 @@
 
             if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, existingEntry)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -278,5 +266,7 @@
 
             if(!psListAdd(newFolderEntry->items, PS_LIST_TAIL, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -284,5 +274,7 @@
 
             if(!psHashRemove(mdTable, key)) {
-                psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -290,5 +282,7 @@
 
             if(!psHashAdd(mdTable, key, newFolderEntry)) {
-                psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                        key);
                 psFree(newFolderEntry);
                 return false;
@@ -301,15 +295,21 @@
             // Folder node replaces leaf or folder node - Put old node into new folder and remove from table
             if(!psListAdd(metadataItem->items, PS_LIST_TAIL, existingEntry)) {
-                psError( __func__, "Couldn't add metadata item to items list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_LIST_FAILED,
+                        key);
                 return false;
             }
 
             if(!psHashRemove(mdTable, key)) {
-                psError( __func__, "Couldn't remove metadata item from metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                        key);
                 return false;
             }
 
             if(!psHashAdd(mdTable, key, metadataItem)) {
-                psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                        key);
                 return false;
             }
@@ -319,5 +319,7 @@
         // Node doesn't exist - Add new metadata item to metadata collection's hash
         if(!psHashAdd(mdTable, key, metadataItem)) {
-            psError( __func__, "Couldn't add metadata item to metadata table. Name: %s", key);
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_ADD_TABLE_FAILED,
+                    key);
             return false;
         }
@@ -328,6 +330,7 @@
     if(metadataItem->type != PS_META_ITEM_SET) {
         if(!psListAdd(mdList, location, metadataItem)) {
-            psError( __func__, "Couldn't add metadata item to metadata collection list. Name: %s",
-                     metadataItem->name );
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_ADD_COLLECTION_FAILED,
+                    key);
             return false;
         }
@@ -348,6 +351,6 @@
 
     if (!psMetadataAddItem(md, metadataItem, where)) {
-        psError(__func__, "Couldn't add metadata item to metadata collection list. Name: %s",
-                metadataItem->name);
+        psError(PS_ERR_UNKNOWN,false,
+                PS_ERRORTEXT_psMetadata_ADD_FAILED);
         psFree(metadataItem);
         return false;
@@ -368,20 +371,11 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return false;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return false;
-    }
-
     mdTable = md->table;
-    if (mdTable == NULL) {
-        psError(__func__, "Null metadata table not allowed");
-        return false;
-    }
+
     // Select removal by key or index
     if (key != NULL) {
@@ -390,5 +384,7 @@
         entry = (psMetadataItem* ) psHashLookup(mdTable, key);
         if (entry == NULL) {
-            psError(__func__, "Couldn't find metadata item. Name: %s", key);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_FIND_FAILED,
+                    key);
             return false;
         }
@@ -402,5 +398,7 @@
             while (entryChild != NULL) {
                 if (!psListRemove(mdList, PS_LIST_UNKNOWN, entryChild)) {
-                    psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
+                    psError(PS_ERR_UNKNOWN,false,
+                            PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
+                            key);
                     return false;
                 }
@@ -411,5 +409,7 @@
             // Table entry has no children. Remove entry from metadata collection's list
             if (!psListRemove(mdList, PS_LIST_UNKNOWN, entry)) {
-                psError(__func__, "Couldn't remove metadata item from list. Name: %s", key);
+                psError(PS_ERR_UNKNOWN,false,
+                        PS_ERRORTEXT_psMetadata_REMOVE_LIST_FAILED,
+                        key);
                 return false;
             }
@@ -417,5 +417,7 @@
         // Remove entry from metadata collection's table
         if (!psHashRemove(mdTable, key)) {
-            psError(__func__, "Couldn't remove metadata item from table. Name: %s", key);
+            psError(PS_ERR_UNKNOWN,false,
+                    PS_ERRORTEXT_psMetadata_REMOVE_TABLE_FAILED,
+                    key);
             return false;
         }
@@ -425,5 +427,7 @@
         entry = psListGet(mdList, where);
         if (entry == NULL) {
-            psError(__func__, "Couldn't find metadata item in list. Index: %d", where);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
+                    where);
             return false;
         }
@@ -431,5 +435,7 @@
         key = entry->name;
         if (key == NULL) {
-            psError(__func__, "Null key name not allowed. Index: %d", where);
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                    PS_ERRORTEXT_psMetadata_REMOVE_LIST_INDEX_FAILED,
+                    where);
             return false;
         }
@@ -447,19 +453,9 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->table,NULL);
+    PS_PTR_CHECK_NULL(key,NULL);
 
     mdTable = md->table;
-    if (mdTable == NULL) {
-        psError(__func__, "Null metadata table not allowed");
-        return NULL;
-    }
-
-    if (key == NULL) {
-        psError(__func__, "Null key name not allowed");
-        return NULL;
-    }
 
     entry = (psMetadataItem* ) psHashLookup(mdTable, key);
@@ -473,64 +469,40 @@
 psMetadataItem* psMetadataGet(psMetadata* restrict md, psS32 where)
 {
+    psMetadataItem* entry = NULL;
+
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+
+    entry = (psMetadataItem* ) psListGet(md->list, where);
+    if (entry == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psMetadata_FIND_INDEX_FAILED,
+                where);
+        return NULL;
+    }
+
+    return entry;
+}
+
+psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
+{
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
+
+    psListSetIterator(md->list, where);
+
+    return true;
+}
+
+psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
+{
     psList* mdList = NULL;
     psMetadataItem* entry = NULL;
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
-
-    entry = (psMetadataItem* ) psListGet(mdList, where);
-    if (entry == NULL) {
-        psError(__func__, "Couldn't find metadata item with given index. Index: %d", where);
-        return NULL;
-    }
-
-    return entry;
-}
-
-psBool psMetadataSetIterator(psMetadata* restrict md, psS32 where)
-{
-    psList* mdList = NULL;
-
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return false;
-    }
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return false;
-    }
-
-    psListSetIterator(mdList, where);
-
-    return true;
-}
-
-psMetadataItem* psMetadataGetNext(psMetadata* restrict md, const char *restrict match, psS32 which)
-{
-    psList* mdList = NULL;
-    psMetadataItem* entry = NULL;
-
-
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
-
-    mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
 
     psListSetIterator(mdList, which);
@@ -559,14 +531,8 @@
 
 
-    if (md == NULL) {
-        psError(__func__, "Null metadata collection not allowed");
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(md,NULL);
+    PS_PTR_CHECK_NULL(md->list,NULL);
 
     mdList = md->list;
-    if (mdList == NULL) {
-        psError(__func__, "Null metadata list not allowed");
-        return NULL;
-    }
 
     psListSetIterator(mdList, which);
Index: trunk/psLib/src/astronomy/psMetadataIO.c
===================================================================
--- trunk/psLib/src/astronomy/psMetadataIO.c	(revision 2222)
+++ 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
Index: trunk/psLib/src/astronomy/psTime.c
===================================================================
--- trunk/psLib/src/astronomy/psTime.c	(revision 2222)
+++ trunk/psLib/src/astronomy/psTime.c	(revision 2273)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-27 00:57:30 $
+ *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-04 01:04:57 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,5 @@
 #include "psMetadata.h"
 #include "psMetadataIO.h"
-
+#include "psConstants.h"
 #include "psAstronomyErrors.h"
 
@@ -151,5 +151,5 @@
     char line[LINESIZE];
     psS32 j = 0;
-    psS32 maxLines = 100;
+    psS32 maxLines = 1000;
     psF64 *ptr = NULL;
     psImage *table = NULL;
@@ -159,5 +159,7 @@
     fd=fopen(fileName, "r");
     if(fd==NULL) {
-        psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);
+        psError(PS_ERR_IO,true,
+                PS_ERRORTEXT_psTime_FILE_NOT_FOUND,
+                fileName,"Tai-Utc");
         return NULL;
     }
@@ -168,5 +170,7 @@
     while(fgets(line, LINESIZE, fd) != NULL) {
         if(j>=maxLines) {
-            psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);
+            psError(PS_ERR_IO,true,
+                    PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS,
+                    fileName,maxLines);
             return NULL;
             psFree(table);
@@ -201,5 +205,7 @@
     fd=fopen(fileName, "r");
     if(fd==NULL) {
-        psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);
+        psError(PS_ERR_IO,true,
+                PS_ERRORTEXT_psTime_FILE_NOT_FOUND,
+                fileName,"Ser7");
         return NULL ;
     }
@@ -218,5 +224,7 @@
 
             if(j>=maxLines) {
-                psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);
+                psError(PS_ERR_IO,true,
+                        PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS,
+                        fileName,maxLines);
                 return NULL;
                 psFree(table);
@@ -240,115 +248,4 @@
 }
 
-/* Not yet used...
-static psImage* readEopcFile(char *fileName)
-{
-    char line[LINESIZE];
-    psS32 i = 0;
-    psS32 j = 0;
-    psS32 maxLines = 2500;
-    psImage *table = NULL;
-    FILE *fd = NULL;
- 
- 
-    fd=fopen(fileName, "r");
-    if(fd==NULL) {
-        psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);
-        return NULL ;
-    }
- 
-    // Table shouldn't be larger than 2500 rows. All columns are read.
-    table  = psImageAlloc(11, maxLines, PS_TYPE_F64);
-    for(i=0; i<3; i++) {
-        if((fgets(line, LINESIZE, fd) != NULL)) {
-            psError(__func__, " : Line %d - Error reading %s", __LINE__, fileName);
-        }
-    }
- 
-    while(fgets(line, LINESIZE, fd) != NULL) {
-        if(j>=maxLines) {
-            psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);
-            return NULL;
-            psFree(table);
-        }
-        psF64 *ptr = table->data.F64[j++];
-        sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
-               ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);
-    }
- 
-    *(psU32 *)&table->numRows = j;
- 
-    return table;
-}
- 
-static psImage* readFinalsFile(char *fileName)
-{
-    char line[LINESIZE];
-    psS32 j = 0;
-    psS32 maxLines = 15000;
-    psImage *table = NULL;
-    FILE *fd = NULL;
- 
- 
-    fd=fopen(fileName, "r");
-    if(fd==NULL) {
-        psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);
-        return NULL ;
-    }
- 
-    // Table shouldn't be larger than 15000 rows. Select columns are read.
-    table  = psImageAlloc(6, maxLines, PS_TYPE_F64);
-    while(fgets(line, LINESIZE, fd) != NULL) {
-        if(j>=maxLines) {
-            psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);
-            return NULL;
-            psFree(table);
-        }
- 
-        psF64 *ptr = table->data.F64[j++];
-        ptr = table->data.F64[j++];
- 
-        // Sometimes there are blank entries in this table, so check for a space to determine if there is no entry
-        if(*(line+7) == ' ') {                   // MJD
-            *ptr = 0.0;
-        } else {
-            *ptr = atof(line+7);
-        }
- 
-        if(*(line+18) == ' ') {                  // Polar motion X
-            *(ptr+1) = 0.0;
-        } else {
-            *(ptr+1) = atof(line+18);
-        }
- 
-        if(*(line+27) == ' ') {                  // Polar motion X error
-            *(ptr+2) = 0.0;
-        } else {
-            *(ptr+2) = atof(line+27);
-        }
- 
-        if(*(line+37) == ' ') {                  // Polar motion Y
-            *(ptr+3) = 0.0;
-        } else {
-            *(ptr+3) = atof(line+37);
-        }
- 
-        if(*(line+46) == ' ') {                  // Polar motion Y error
-            *(ptr+4) = 0.0;
-        } else {
-            *(ptr+4) = atof(line+46);
-        }
- 
-        if(*(line+58) == ' ') {                  // UT1-UTC
-            *(ptr+5) = 0.0;
-        } else {
-            *(ptr+5) = atof(line+58);
-        }
-    }
- 
-    *(psU32 *)&table->numRows = j;
- 
-    return table;
-}
-*/
 
 static double lookupTaiUtcTable(const psTime *time)
@@ -389,5 +286,7 @@
             hiIdx++;
             if(hiIdx >= numRows) {
-                psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx);
+                psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                        PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE,
+                        jd, "TAI-UTC");
                 return 0.0;
             }
@@ -395,14 +294,18 @@
         loIdx = hiIdx--;
         if(loIdx < 0) {
-            psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx);
+            psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                    PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE,
+                    jd, "TAI-UTC");
             return 0.0;
         }
 
+        // since rows of table can not have same jd, this check is probably not needed.
         denom = table->data.F64[hiIdx][0]-table->data.F64[loIdx][0];
         if(fabs(denom) < FLT_EPSILON) {
-            psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__);
+            psError(PS_ERR_UNKNOWN,true,
+                    PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS
+                    "Ser7");
             return 0.0;
         } else {
-
             // Interpolate three constants required to calculate TAI-UTC
             const1 = table->data.F64[loIdx][1]+(table->data.F64[hiIdx][1]-table->data.F64[loIdx][1])
@@ -445,13 +348,19 @@
     mjdUtc = psTimeToMJD(time);
     if(mjdUtc < table->data.F64[0][3]) {                                    // MJD time before start of table
-        psError(__func__, " : Line %d - MJD too small. Value: %d", __LINE__, mjdUtc);
+        psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE,
+                mjdUtc, "Ser7");
 
     } else if(mjdUtc > table->data.F64[numRows-1][3]) {                     // MJD time after end of table
-        psError(__func__, " : Line %d - MJD too big. Value: %d", __LINE__, mjdUtc);
+        psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE,
+                mjdUtc, "Ser7");
     } else {                                                                // All other times..interpolate
         while(mjdUtc > table->data.F64[hiIdx][3]) {
             hiIdx++;
             if(hiIdx >= numRows) {
-                psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx);
+                psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                        PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE,
+                        mjdUtc, "Ser7");
                 return 0.0;
             }
@@ -460,10 +369,14 @@
         loIdx = hiIdx--;
         if(loIdx < 0) {
-            psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx);
+            psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+                    PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE,
+                    mjdUtc, "Ser7");
         }
 
         denom = table->data.F64[hiIdx][3] - table->data.F64[loIdx][3];
         if(fabs(denom) < FLT_EPSILON) {
-            psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__);
+            psError(PS_ERR_UNKNOWN,true,
+                    PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS,
+                    "Ser7");
         } else {
             out = table->data.F64[loIdx][col]+(table->data.F64[hiIdx][col]-table->data.F64[loIdx][col])
@@ -525,12 +438,11 @@
     // Error checks
     if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) {
-        psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type);
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psTime_TYPE_UNKNOWN,
+                type);
         return NULL;
     }
 
     outTime = (psTime*)psAlloc(sizeof(psTime));
-    if(outTime == NULL) {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
 
     outTime->sec = 0;
@@ -551,5 +463,6 @@
 
     if (gettimeofday(&now, (struct timezone *)0) == -1) {
-        psError(__func__, " : Line %d - Failed to get time", __LINE__);
+        psError(PS_ERR_OS_CALL_FAILED, true,
+                PS_ERRORTEXT_psTime_GET_TOD_FAILED);
         return NULL;
     }
@@ -573,23 +486,21 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return NULL;
-    } else if(time->type == type) {
-        psError(__func__, " : Line %d - Time already in correct psTime type. Time type: %d", __LINE__, type);
-        return NULL;
+    PS_PTR_CHECK_NULL(time,NULL);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
+
+    if (time->type == type) { // time already right type.  That was easy!
+        return time;
     }
 
     delta = psTimeGetTAIDelta(time);
 
-    if(type == PS_TIME_UTC) {
+    if (type == PS_TIME_UTC) {
         time->sec = time->sec - delta;    // User wants UTC time. Subtract leapseconds.
     } else if(type == PS_TIME_TAI) {
         time->sec = time->sec + delta;    // User wants TAI time. Add leapseconds.
     } else {
-        psError(__func__, " : Line %d - Invalid psTimeType: %d", __LINE__, type);
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psTime_TYPE_UNKNOWN,
+                type);
     }
 
@@ -623,11 +534,6 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return 0;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return 0;
-    }
+    PS_PTR_CHECK_NULL(time,NAN);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN);
 
     // Calculate TAI or UTC time based on type of time user passes
@@ -698,11 +604,6 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return 0.0;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return 0.0;
-    }
+    PS_PTR_CHECK_NULL(time,NAN);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN);
 
     return lookupSer7Table(time, 6);
@@ -717,13 +618,6 @@
 
     // Error checks
-    if(time == NULL)
-    {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    } else if(time->usec >= 1e6)
-    {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(time,NULL);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
 
     x = lookupSer7Table((psTime*)time, 4);
@@ -741,11 +635,6 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return 0.0;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return 0.0;
-    }
+    PS_PTR_CHECK_NULL(time,NAN);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN);
 
     return lookupTaiUtcTable(time);
@@ -758,17 +647,8 @@
 
     // Error checks
-    if(time1 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__);
-        return 0;
-    } else if(time1->usec >= 1e6) {
-        psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time1->usec);
-        return 0;
-    } else if(time2 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__);
-        return 0;
-    } else if(time2->usec >= 1e6) {
-        psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time2->usec);
-        return 0;
-    }
+    PS_PTR_CHECK_NULL(time1,0);
+    PS_PTR_CHECK_NULL(time2,0);
+    PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0);
+    PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0);
 
     diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
@@ -781,13 +661,7 @@
     double jd = 0.0;
 
-
-    // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return 0.0;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return 0.0;
-    }
+    // Error checks
+    PS_PTR_CHECK_NULL(time,NAN);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN);
 
     // Julian date conversion
@@ -807,11 +681,6 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return 0.0;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return 0.0;
-    }
+    PS_PTR_CHECK_NULL(time,NAN);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN);
 
     // Modified Julian date conversion
@@ -835,11 +704,6 @@
 
     // Error checks
-    if(time == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    } else if(time->usec >= 1e6) {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(time,NULL);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
 
     tempString = psAlloc(MAX_TIME_STRING_LENGTH);
@@ -854,9 +718,11 @@
     // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form
     if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) {
-        psError(__func__, " : Line %d - Failed strftime conversion", __LINE__);
+        psError(PS_ERR_OS_CALL_FAILED, true,
+                PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED);
     }
 
     if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3dZ", tempString, ms) < 0) {
-        psError(__func__, " : Line %d - Failed snprintf conversion", __LINE__);
+        psError(PS_ERR_OS_CALL_FAILED, true,
+                PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED);
     }
     psFree(tempString);
@@ -869,15 +735,10 @@
     struct timeval timevalTime;
 
-
-    // Error checks
-    if(time == NULL)
-    {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return timevalTime;
-    } else if(time->usec >= 1e6)
-    {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return timevalTime;
-    }
+    timevalTime.tv_sec = 0;
+    timevalTime.tv_usec = 0;
+
+    // Error checks
+    PS_PTR_CHECK_NULL(time,timevalTime);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,timevalTime);
 
     timevalTime.tv_sec = time->sec;
@@ -901,13 +762,6 @@
 
     // Error checks
-    if(time == NULL)
-    {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    } else if(time->usec >= 1e6)
-    {
-        psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec);
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(time,NULL);
+    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
 
     seconds = time->sec%60;
@@ -945,8 +799,4 @@
     // Allocate output
     tmTime = (struct tm*)psAlloc(sizeof(struct tm));
-    if (tmTime == NULL)
-    {
-        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
-    }
 
     tmTime->tm_year = year - 1900;
@@ -982,7 +832,5 @@
 
     // Error check
-    if(outTime->usec >= 1e6) {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
+    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
 
     return outTime;
@@ -1010,7 +858,5 @@
 
     // Error check
-    if(outTime->usec >= 1e6) {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
+    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
 
     return outTime;
@@ -1020,67 +866,28 @@
 {
     char tempString[MAX_TIME_STRING_LENGTH];
-    psS32 month;
-    psS32 day;
-    psS32 year;
-    psS32 hour;
-    psS32 minute;
-    psS32 second;
     psS32 millisecond;
     struct tm tmTime;
     psTime *outTime = NULL;
 
-
-    // Preserve input string by creating duplicate
-    strncpy(tempString, time, MAX_TIME_STRING_LENGTH);
-
     // Convert YYYY-MM-DDThh:mm:ss.sss in string form to tm time
-    year = atoi(strtok(tempString, "-"));
-    if (year < 0) {
-        psError(__func__, "Years less than 0 not allowed. Value: %d", year);
-        return outTime;
-    }
-
-    month = atoi(strtok(NULL, "-"));
-    if (month < 1 || month > 12) {
-        psError(__func__, "Month must have a value from 1 to 12. Value: %d", month);
-        return outTime;
-    }
-
-    day = atoi(strtok(NULL, "T"));
-    if (day < 1 || day > 31) {
-        psError(__func__, "Day must have a value from 1 to 31. Value: %d", day);
-        return outTime;
-    }
-
-    hour = atoi(strtok(NULL, ":"));
-    if (hour < 0 || hour > 23) {
-        psError(__func__, "Hour must have a value from 0 to 23. Value: %d", hour);
-        return outTime;
-    }
-
-    minute = atoi(strtok(NULL, ":"));
-    if (minute < 0 || minute > 59) {
-        psError(__func__, "Minute must have a value from 0 to 59. Value: %d", minute);
-        return outTime;
-    }
-
-    second = atoi(strtok(NULL, "."));
-    if (second < 0 || second > 59) {
-        psError(__func__, "Second must have a value from 0 to 59. Value: %d", second);
-        return outTime;
-    }
-
-    millisecond = atoi(strtok(NULL, "Z"));
-    if (millisecond < 0 || millisecond > 1000) {
-        psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond);
-        return outTime;
-    }
-
-    tmTime.tm_year = year - 1900;
-    tmTime.tm_mon = month - 1;
-    tmTime.tm_mday = day;
-    tmTime.tm_hour = hour;
-    tmTime.tm_min = minute;
-    tmTime.tm_sec = second;
+    if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d",
+               &tmTime.tm_year,&tmTime.tm_mon,&tmTime.tm_mday,
+               &tmTime.tm_hour,&tmTime.tm_min,&tmTime.tm_sec,&millisecond) < 7) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psTime_ISOTIME_MALFORMED,
+                time);
+        return NULL;
+    }
+
+    PS_INT_CHECK_NON_NEGATIVE(tmTime.tm_year, outTime);
+    PS_INT_CHECK_RANGE(tmTime.tm_mon,1,12,outTime);
+    PS_INT_CHECK_RANGE(tmTime.tm_mday,1,31,outTime);
+    PS_INT_CHECK_RANGE(tmTime.tm_hour,0,23,outTime);
+    PS_INT_CHECK_RANGE(tmTime.tm_min,0,59,outTime);
+    PS_INT_CHECK_RANGE(tmTime.tm_sec,0,59,outTime);
+    PS_INT_CHECK_RANGE(millisecond,0,999,outTime);
+
+    tmTime.tm_year -= 1900;
+    tmTime.tm_mon--;
     tmTime.tm_isdst = -1;
 
@@ -1089,23 +896,14 @@
     outTime->usec = millisecond * 1000;
 
+    return outTime;
+}
+
+psTime* psTimeFromTimeval(const struct timeval *time)
+{
+    psTime *outTime = NULL;
+
+
     // Error check
-    if(outTime->usec >= 1e6) {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
-
-    return outTime;
-}
-
-psTime* psTimeFromTimeval(const struct timeval *time)
-{
-    psTime *outTime = NULL;
-
-
-    // Error check
-    if(time == NULL)
-    {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(time,NULL);
 
     // Allocate psTime struct
@@ -1117,8 +915,5 @@
 
     // Error check
-    if(outTime->usec >= 1e6)
-    {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
+    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
 
     return outTime;
@@ -1138,9 +933,5 @@
 
     // Error check
-    if(time == NULL)
-    {
-        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
-        return NULL;
-    }
+    PS_PTR_CHECK_NULL(time,NULL);
 
     // Allocate psTime struct
@@ -1183,8 +974,5 @@
 
     // Error check
-    if(outTime->usec >= 1e6)
-    {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
+    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
 
     return outTime;
@@ -1199,18 +987,12 @@
 
     // Error checks
+    PS_PTR_CHECK_NULL(tai1,NULL);
+    PS_PTR_CHECK_NULL(tai2,NULL);
+    PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
+    PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
+
     if(tai1->type != tai2->type) {
-        psError(__func__, " : Line %d - Argument types inconsistent for time addition", __LINE__);
-        return NULL;
-    } else if(tai1 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__);
-        return NULL;
-    } else if(tai1->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec);
-        return NULL;
-    } else if(tai2 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__);
-        return NULL;
-    } else if(tai2->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec);
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psTime_TYPE_MISMATCH);
         return NULL;
     }
@@ -1233,7 +1015,5 @@
 
     // Error check
-    if(outTime->usec >= 1e6) {
-        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
-    }
+    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
 
     return outTime;
@@ -1248,18 +1028,11 @@
 
     // Error checks
+    PS_PTR_CHECK_NULL(tai1,NULL);
+    PS_PTR_CHECK_NULL(tai2,NULL);
+    PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
+    PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
     if(tai1->type != tai2->type) {
-        psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__);
-        return NULL;
-    } else if(tai1 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__);
-        return NULL;
-    } else if(tai1->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec);
-        return NULL;
-    } else if(tai2 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__);
-        return NULL;
-    } else if(tai2->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec);
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psTime_TYPE_MISMATCH);
         return NULL;
     }
@@ -1294,18 +1067,12 @@
 
     // Error checks
+    // Error checks
+    PS_PTR_CHECK_NULL(tai1,NULL);
+    PS_PTR_CHECK_NULL(tai2,NULL);
+    PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
+    PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
     if(tai1->type != tai2->type) {
-        psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__);
-        return NULL;
-    } else if(tai1 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__);
-        return NULL;
-    } else if(tai1->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec);
-        return NULL;
-    } else if(tai2 == NULL) {
-        psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__);
-        return NULL;
-    } else if(tai2->usec >= 1e6) {
-        psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec);
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psTime_TYPE_MISMATCH);
         return NULL;
     }
