Index: /trunk/psLib/src/astro/psTime.c
===================================================================
--- /trunk/psLib/src/astro/psTime.c	(revision 2180)
+++ /trunk/psLib/src/astro/psTime.c	(revision 2181)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-20 20:05:51 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-20 21:21:58 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -72,30 +72,13 @@
                 #define LINESIZE 1024
 
-                /** Preprocessor macro to check for null psTime struct */
-                #define CHECK_NULL_TIME(TIME,RETURN) \
-                if(TIME == NULL) { \
-                    psError(__func__,"NULL value not allowed"); \
-                    return RETURN; \
-                }
-
-                /** Preprocessor macro to allocate psTime struct */
-                #define ALLOC_TIME(TIME) \
-                TIME = (psTime*)psAlloc(sizeof(psTime)); \
-if (TIME == NULL) { \
-    psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); \
-} \
-TIME->sec = 0; \
-TIME->usec = 0; \
-TIME->type = PS_TIME_TAI;
-
-/** Read TAI/UTC data file.
- *
- *  Reads TAI/UTC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-static psImage* readTaiUtcFile(
-    const char *fileName                      ///< Name of file to read.
-);
+                /** Read TAI/UTC data file.
+                 *
+                 *  Reads TAI/UTC data file.
+                 *
+                 *  @return  psImage*: Two-dimensional array with table data.
+                 */
+                static psImage* readTaiUtcFile(
+                    const char *fileName                      ///< Name of file to read.
+                );
 
 
@@ -488,4 +471,6 @@
     psTime *outTime = NULL;
 
+
+    // Error checks
     if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) {
         psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type);
@@ -512,5 +497,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(time);
+    time = psTimeAlloc(type);
 
     if (gettimeofday(&now, (struct timezone *)0) == -1) {
@@ -522,5 +507,4 @@
     time->sec = now.tv_sec;
     time->usec = now.tv_usec;
-    time->type = type;
 
     // Add most leapseconds to UTC time to get TAI time if necessary
@@ -537,6 +521,13 @@
 
 
-    if(time->type == type) {
-        psError(__func__, " : Line %d - Time is already in the correct psTime format. Time type: %d", __LINE__, type);
+    // 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;
     }
@@ -545,5 +536,5 @@
 
     if(type == PS_TIME_UTC) {
-        time->sec = time->sec - delta;    // User wants UTC time. Remove leapseconds.
+        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.
@@ -580,22 +571,28 @@
 
 
+    // 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;
+    }
+
     // Calculate TAI or UTC time based on type of time user passes
     if(time->type == PS_TIME_TAI) {
         taiTime = psMemIncrRefCounter(time);
-        ALLOC_TIME(utcTime);
+        utcTime = psTimeAlloc(PS_TIME_UTC);
         utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
         utcTime->usec = taiTime->usec;
-        utcTime->type = PS_TIME_UTC;
     } else if(time->type == PS_TIME_UTC) {
         utcTime = psMemIncrRefCounter(time);
-        ALLOC_TIME(taiTime);
+        taiTime = psTimeAlloc(PS_TIME_TAI);
         taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
         taiTime->usec = utcTime->usec;
-        taiTime->type = PS_TIME_TAI;
     }
 
     // Convert Universal Time (UTC) to  UT1
-    ALLOC_TIME(ut1UtcDelta);
-    ut1UtcDelta->type = PS_TIME_UTC;
+    ut1UtcDelta = psTimeAlloc(PS_TIME_UTC);
 
     ut1UtcDbl = psTimeGetUT1Delta(utcTime)*1e6;
@@ -614,5 +611,5 @@
 
     // Calculate Terrestial Dynamical Time (TDT)
-    ALLOC_TIME(tdtDelta);
+    tdtDelta = psTimeAlloc(PS_TIME_TAI);
     tdtDelta->sec = 32;
     tdtDelta->usec = 184000;
@@ -648,4 +645,14 @@
 double psTimeGetUT1Delta(const psTime *time)
 {
+
+    // 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;
+    }
+
     return lookupSer7Table(time, 6);
 }
@@ -653,9 +660,24 @@
 struct psSphere* psTimeGetPoleCoords(const psTime* time)
 {
-
-    double x = lookupSer7Table((psTime*)time, 4);
-    double y = lookupSer7Table((psTime*)time, 5);
-
-    struct psSphere* output = psAlloc(sizeof(psSphere));
+    double x = 0.0;
+    double y = 0.0;
+    struct psSphere* output = NULL;
+
+
+    // 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;
+    }
+
+    x = lookupSer7Table((psTime*)time, 4);
+    y = lookupSer7Table((psTime*)time, 5);
+
+    output = psAlloc(sizeof(psSphere));
     output->r = x * M_PI / 648000.0; // x in arcsec converted to radians, i.e., x/60/60*M_PI/180
     output->d = y * M_PI / 648000.0;
@@ -666,4 +688,14 @@
 double psTimeGetTAIDelta(const psTime *time)
 {
+
+    // 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;
+    }
+
     return lookupTaiUtcTable(time);
 }
@@ -673,7 +705,19 @@
     long diff = 0;
 
-    // NULL error checks
-    CHECK_NULL_TIME(time1,0);
-    CHECK_NULL_TIME(time2,0);
+
+    // 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;
+    }
 
     diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
@@ -687,6 +731,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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;
+    }
 
     // Julian date conversion
@@ -705,6 +755,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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;
+    }
 
     // Modified Julian date conversion
@@ -727,6 +783,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+    // 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;
+    }
 
     tempString = psAlloc(MAX_TIME_STRING_LENGTH);
@@ -757,6 +819,14 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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 = time->sec;
@@ -779,4 +849,15 @@
 
 
+    // 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;
+    }
+
     seconds = time->sec%60;
     minute = time->sec/60%60;
@@ -837,5 +918,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Julian date conversion courtesy of Eugene Magnier
@@ -849,4 +930,9 @@
     outTime->sec = seconds;
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -860,5 +946,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Modified Julian date conversion courtesy of Eugene Magnier
@@ -871,4 +957,9 @@
     }
     outTime->sec = seconds;
+
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
 
     return outTime;
@@ -947,4 +1038,9 @@
     outTime->usec = millisecond * 1000;
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -955,13 +1051,23 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+    // Error check
+    if(time == NULL)
+    {
+        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
+        return NULL;
+    }
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime)
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Convert to psTime
     outTime->sec = time->tv_sec;
     outTime->usec = time->tv_usec;
+
+    // Error check
+    if(outTime->usec >= 1e6)
+    {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
 
     return outTime;
@@ -979,9 +1085,14 @@
     psTime *outTime = NULL;
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+
+    // Error check
+    if(time == NULL)
+    {
+        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
+        return NULL;
+    }
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Extract data from TM struct
@@ -1020,4 +1131,10 @@
     outTime->usec = 0;
 
+    // Error check
+    if(outTime->usec >= 1e6)
+    {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -1030,10 +1147,17 @@
 
 
+    // Error checks
     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);
@@ -1041,6 +1165,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     outTime->sec = tai1->sec + tai2->sec;
     deltaUsec = tai1->usec + tai2->usec;
@@ -1058,4 +1181,9 @@
     }
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -1068,10 +1196,17 @@
 
 
+    // Error checks
     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);
@@ -1079,6 +1214,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     deltaSec = tai1->sec - tai2->sec;
     deltaUsec = (long)tai1->usec - (long)tai2->usec;
@@ -1108,10 +1242,17 @@
 
 
+    // Error checks
     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);
@@ -1119,6 +1260,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     deltaSec = tai1->sec - tai2->sec;
     deltaUsec = (long)tai1->usec - (long)tai2->usec;
Index: /trunk/psLib/src/astronomy/psTime.c
===================================================================
--- /trunk/psLib/src/astronomy/psTime.c	(revision 2180)
+++ /trunk/psLib/src/astronomy/psTime.c	(revision 2181)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-20 20:05:51 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-20 21:21:58 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -72,30 +72,13 @@
                 #define LINESIZE 1024
 
-                /** Preprocessor macro to check for null psTime struct */
-                #define CHECK_NULL_TIME(TIME,RETURN) \
-                if(TIME == NULL) { \
-                    psError(__func__,"NULL value not allowed"); \
-                    return RETURN; \
-                }
-
-                /** Preprocessor macro to allocate psTime struct */
-                #define ALLOC_TIME(TIME) \
-                TIME = (psTime*)psAlloc(sizeof(psTime)); \
-if (TIME == NULL) { \
-    psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); \
-} \
-TIME->sec = 0; \
-TIME->usec = 0; \
-TIME->type = PS_TIME_TAI;
-
-/** Read TAI/UTC data file.
- *
- *  Reads TAI/UTC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-static psImage* readTaiUtcFile(
-    const char *fileName                      ///< Name of file to read.
-);
+                /** Read TAI/UTC data file.
+                 *
+                 *  Reads TAI/UTC data file.
+                 *
+                 *  @return  psImage*: Two-dimensional array with table data.
+                 */
+                static psImage* readTaiUtcFile(
+                    const char *fileName                      ///< Name of file to read.
+                );
 
 
@@ -488,4 +471,6 @@
     psTime *outTime = NULL;
 
+
+    // Error checks
     if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) {
         psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type);
@@ -512,5 +497,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(time);
+    time = psTimeAlloc(type);
 
     if (gettimeofday(&now, (struct timezone *)0) == -1) {
@@ -522,5 +507,4 @@
     time->sec = now.tv_sec;
     time->usec = now.tv_usec;
-    time->type = type;
 
     // Add most leapseconds to UTC time to get TAI time if necessary
@@ -537,6 +521,13 @@
 
 
-    if(time->type == type) {
-        psError(__func__, " : Line %d - Time is already in the correct psTime format. Time type: %d", __LINE__, type);
+    // 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;
     }
@@ -545,5 +536,5 @@
 
     if(type == PS_TIME_UTC) {
-        time->sec = time->sec - delta;    // User wants UTC time. Remove leapseconds.
+        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.
@@ -580,22 +571,28 @@
 
 
+    // 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;
+    }
+
     // Calculate TAI or UTC time based on type of time user passes
     if(time->type == PS_TIME_TAI) {
         taiTime = psMemIncrRefCounter(time);
-        ALLOC_TIME(utcTime);
+        utcTime = psTimeAlloc(PS_TIME_UTC);
         utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
         utcTime->usec = taiTime->usec;
-        utcTime->type = PS_TIME_UTC;
     } else if(time->type == PS_TIME_UTC) {
         utcTime = psMemIncrRefCounter(time);
-        ALLOC_TIME(taiTime);
+        taiTime = psTimeAlloc(PS_TIME_TAI);
         taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
         taiTime->usec = utcTime->usec;
-        taiTime->type = PS_TIME_TAI;
     }
 
     // Convert Universal Time (UTC) to  UT1
-    ALLOC_TIME(ut1UtcDelta);
-    ut1UtcDelta->type = PS_TIME_UTC;
+    ut1UtcDelta = psTimeAlloc(PS_TIME_UTC);
 
     ut1UtcDbl = psTimeGetUT1Delta(utcTime)*1e6;
@@ -614,5 +611,5 @@
 
     // Calculate Terrestial Dynamical Time (TDT)
-    ALLOC_TIME(tdtDelta);
+    tdtDelta = psTimeAlloc(PS_TIME_TAI);
     tdtDelta->sec = 32;
     tdtDelta->usec = 184000;
@@ -648,4 +645,14 @@
 double psTimeGetUT1Delta(const psTime *time)
 {
+
+    // 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;
+    }
+
     return lookupSer7Table(time, 6);
 }
@@ -653,9 +660,24 @@
 struct psSphere* psTimeGetPoleCoords(const psTime* time)
 {
-
-    double x = lookupSer7Table((psTime*)time, 4);
-    double y = lookupSer7Table((psTime*)time, 5);
-
-    struct psSphere* output = psAlloc(sizeof(psSphere));
+    double x = 0.0;
+    double y = 0.0;
+    struct psSphere* output = NULL;
+
+
+    // 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;
+    }
+
+    x = lookupSer7Table((psTime*)time, 4);
+    y = lookupSer7Table((psTime*)time, 5);
+
+    output = psAlloc(sizeof(psSphere));
     output->r = x * M_PI / 648000.0; // x in arcsec converted to radians, i.e., x/60/60*M_PI/180
     output->d = y * M_PI / 648000.0;
@@ -666,4 +688,14 @@
 double psTimeGetTAIDelta(const psTime *time)
 {
+
+    // 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;
+    }
+
     return lookupTaiUtcTable(time);
 }
@@ -673,7 +705,19 @@
     long diff = 0;
 
-    // NULL error checks
-    CHECK_NULL_TIME(time1,0);
-    CHECK_NULL_TIME(time2,0);
+
+    // 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;
+    }
 
     diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
@@ -687,6 +731,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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;
+    }
 
     // Julian date conversion
@@ -705,6 +755,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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;
+    }
 
     // Modified Julian date conversion
@@ -727,6 +783,12 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+    // 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;
+    }
 
     tempString = psAlloc(MAX_TIME_STRING_LENGTH);
@@ -757,6 +819,14 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,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 = time->sec;
@@ -779,4 +849,15 @@
 
 
+    // 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;
+    }
+
     seconds = time->sec%60;
     minute = time->sec/60%60;
@@ -837,5 +918,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Julian date conversion courtesy of Eugene Magnier
@@ -849,4 +930,9 @@
     outTime->sec = seconds;
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -860,5 +946,5 @@
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Modified Julian date conversion courtesy of Eugene Magnier
@@ -871,4 +957,9 @@
     }
     outTime->sec = seconds;
+
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
 
     return outTime;
@@ -947,4 +1038,9 @@
     outTime->usec = millisecond * 1000;
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -955,13 +1051,23 @@
 
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+    // Error check
+    if(time == NULL)
+    {
+        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
+        return NULL;
+    }
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime)
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Convert to psTime
     outTime->sec = time->tv_sec;
     outTime->usec = time->tv_usec;
+
+    // Error check
+    if(outTime->usec >= 1e6)
+    {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
 
     return outTime;
@@ -979,9 +1085,14 @@
     psTime *outTime = NULL;
 
-    // NULL error check
-    CHECK_NULL_TIME(time,NULL);
+
+    // Error check
+    if(time == NULL)
+    {
+        psError(__func__, " : Line %d - NULL value not allowed", __LINE__);
+        return NULL;
+    }
 
     // Allocate psTime struct
-    ALLOC_TIME(outTime);
+    outTime = psTimeAlloc(PS_TIME_TAI);
 
     // Extract data from TM struct
@@ -1020,4 +1131,10 @@
     outTime->usec = 0;
 
+    // Error check
+    if(outTime->usec >= 1e6)
+    {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -1030,10 +1147,17 @@
 
 
+    // Error checks
     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);
@@ -1041,6 +1165,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     outTime->sec = tai1->sec + tai2->sec;
     deltaUsec = tai1->usec + tai2->usec;
@@ -1058,4 +1181,9 @@
     }
 
+    // Error check
+    if(outTime->usec >= 1e6) {
+        psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec);
+    }
+
     return outTime;
 }
@@ -1068,10 +1196,17 @@
 
 
+    // Error checks
     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);
@@ -1079,6 +1214,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     deltaSec = tai1->sec - tai2->sec;
     deltaUsec = (long)tai1->usec - (long)tai2->usec;
@@ -1108,10 +1242,17 @@
 
 
+    // Error checks
     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);
@@ -1119,6 +1260,5 @@
     }
 
-    ALLOC_TIME(outTime);
-    outTime->type = tai1->type;
+    outTime = psTimeAlloc(tai1->type);
     deltaSec = tai1->sec - tai2->sec;
     deltaUsec = (long)tai1->usec - (long)tai2->usec;
