Index: /trunk/psLib/test/astronomy/tst_psTime_02.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psTime_02.c	(revision 4057)
+++ /trunk/psLib/test/astronomy/tst_psTime_02.c	(revision 4058)
@@ -4,12 +4,14 @@
  *
  *  This test driver contains the following tests for psTime:
- *     A) Incorrect ISO time data
- *     B) Attempt to use null timeval
- *     C) Free data
+ *     1) Convert psTime to Local Mean Sidereal Time (LMST)
+ *     2) Calculate leap second delta between times
+ *     3) Creation of psTime of type TT
+ *     4) Creation of psTime of type UTC
  *
  *  @author  Ross Harman, MHPCC
- *
- *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2005-04-18 23:30:54 $
+ *  @author  Eric Van Alst, MHPCC
+ *
+ *  @version $Revision: 1.12 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2005-05-31 21:57:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,37 +22,347 @@
 #include "psTest.h"
 
+#define ERROR_TOL  0.001
+
+static psS32 testTimeLMST(void);
+static psS32 testTimeLeapSecondDelta(void);
+static psS32 testTimeIsLeapSecond(void);
+static psS32 testTimeFromTT(void);
+static psS32 testTimeFromUTC(void);
+
+// Test Time 1 : May 9, 2005  00:00:00,0
+//               MJD = 53499.000
+//               JD = 2453499.5
+// UTC Test Time 1
+const psS64 testTime1SecondsUTC     = 1115596900;
+const psU32 testTime1NanosecondsUTC = 0;
+// Expected LMST  15:09:18
+const psF64 testTime1LMST0          = 3.967604;
+
+// Test Time 2 : May 9, 1995 00:00:00,0
+//               MJD = 49846.00
+//               JD = 2449846.5
+// UTC Test Time 2
+const psS64 testTime2SecondsUTC     = 799977600;
+const psU32 testTime2NanosecondsUTC = 0;
+// Expected leap second delta
+const psS64 testTimeLeapSecondDelta1 = 3;
+
+// Test Time 3: Jan 1, 1999 00:00:00,0
+//              MJD = 51179
+//              JD = 2451179.5
+const psS64 testTime3SecondsUTC     = 915148800;
+const psU32 testTime3NanosecondsUTC = 0;
+
+testDescription tests[] = {
+                              {testTimeLMST,000,"psTimeToLMST",0,false},
+                              {testTimeLeapSecondDelta,000,"psTimeLeapSecondDelta",0,false},
+                              {testTimeIsLeapSecond,000,"psTimeIsLeapSecond",0,false},
+                              {testTimeFromTT,000,"psTimeFromTT",0,false},
+                              {testTimeFromUTC,000,"psTimeFromUTC",0,false},
+                              {NULL}
+                          };
 psS32 main(psS32 argc, char* argv[])
 {
-
-    // Test A - Incorrect ISO time data
-    printNegativeTestHeader(stdout,"psTime", "Incorrect ISO time data", "Time not allowed", 0);
-    psTimeFromISO("2004-99-21T18:22:24.272Z");
-    psTimeFromISO("2004-07-99T18:22:24.272Z");
-    psTimeFromISO("2004-07-21T99:22:24.272Z");
-    psTimeFromISO("2004-07-21T18:99:24.272Z");
-    psTimeFromISO("2004-07-21T18:22:99.272Z");
-    psTimeFromISO("2004-07-21T18:22:24.-999Z");
-    printFooter(stdout, "psTime", "Incorrect ISO time data", true);
-
-
-    // Test B - Attempt to use null timeval
-    printNegativeTestHeader(stdout,"psTime", "Attempt to use null timeval", "Null value for timeval arg not allowed", 0);
-    psTimeFromTimeval(NULL);
-    printFooter(stdout, "psTime", "Attempt to use null timeval", true);
-
-
-    // Test C - Free data
-    printPositiveTestHeader(stdout, "psTime", "Test C - Free data");
-    if ( psMemCheckLeaks(0, NULL, stdout,false) != 0) {
-        psError(PS_ERR_UNKNOWN,true,"Memory leaks detected");
-        return 10;
-    }
-    psMemCheckCorruption(0);
-    psS32 nBad = psMemCheckCorruption(0);
-    if(nBad) {
-        printf("ERROR: Found %d bad memory blocks\n", nBad);
-    }
-    printFooter(stdout, "psTime", "Test C - Free data", true);
-
-    return 0;
-}
+    psLogSetLevel(PS_LOG_INFO);
+
+    // Initialize library internal structures
+    psLibInit(true,"psTime.config");
+
+    if( !runTestSuite(stderr,"psTime",tests,argc,argv)) {
+        return 1;
+    }
+
+    // Clean up library
+    psLibFinalize();
+
+    return 0;
+}
+
+psS32 testTimeLMST(void)
+{
+    psTime*       time      = NULL;
+    psF64         lmst      = 0.0;
+
+    // Attempt to get LMST with NULL time
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time");
+    lmst = psTimeToLMST(time,0);
+    if(!isnan(lmst)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NaN as expected %lf",lmst);
+        return 1;
+    }
+
+    // Attempt to get LMST with valid test time
+    // Allocate test time
+    time = psTimeAlloc(PS_TIME_UTC);
+    time->sec = testTime1SecondsUTC;
+    time->nsec = testTime1NanosecondsUTC;
+    time->leapsecond = false;
+    lmst = psTimeToLMST(time,0.0);
+    if(fabs(lmst-testTime1LMST0) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"LMST %lf not as expected %lf",lmst,testTime1LMST0);
+        return 2;
+    }
+
+    // Attempt to get LMST with invalid input time UT1
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for incorrect type");
+    time->type = PS_TIME_UT1;
+    lmst = psTimeToLMST(time,0.0);
+    if(!isnan(lmst)) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NaN as expected %lf",lmst);
+        return 3;
+    }
+    psFree(time);
+
+    return 0;
+}
+
+psS32 testTimeLeapSecondDelta(void)
+{
+    psTime*       time1   = NULL;
+    psTime*       time2   = NULL;
+    psS64         delta   = 0;
+
+    // Attempt to get delta with NULL time1 argument
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time");
+    delta = psTimeLeapSecondDelta(time1,time2);
+    if(delta != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta);
+        return 1;
+    }
+
+    // Set test time 1
+    time1 = psTimeAlloc(PS_TIME_UTC);
+    time1->sec = testTime1SecondsUTC;
+    time1->nsec = testTime1NanosecondsUTC;
+    time1->leapsecond = false;
+
+    // Attempt to get delta with NULL time2 argument
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time");
+    delta = psTimeLeapSecondDelta(time1,time2);
+    if(delta != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta);
+        return 2;
+    }
+
+    // Set test time 2 with invalid time
+    time2 = psTimeAlloc(PS_TIME_UTC);
+    time2->sec = 0;
+    time2->nsec = 2e9;
+    time2->leapsecond = false;
+
+    // Attempt to get delta with invalid time2
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time");
+    delta = psTimeLeapSecondDelta(time1,time2);
+    if(delta != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta);
+        return 3;
+    }
+
+    // Set test time 2 valid
+    time2->sec = testTime2SecondsUTC;
+    time2->nsec = testTime2NanosecondsUTC;
+
+    // Set test time 1 invalid
+    time1->sec = 0;
+    time1->nsec = 2e9;
+
+    // Attempt to get delta with invalid time1
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time");
+    delta = psTimeLeapSecondDelta(time1,time2);
+    if(delta != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta);
+        return 4;
+    }
+
+    // Set test time 1 to greater time
+    time1->sec = testTime1SecondsUTC;
+    time1->nsec = testTime1NanosecondsUTC;
+    delta = psTimeLeapSecondDelta(time1,time2);
+    if(delta != testTimeLeapSecondDelta1) {
+        psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected %ld",
+                (long int)delta,(long int)testTimeLeapSecondDelta1);
+        return 5;
+    }
+
+    // Set test time 1 to lesser time
+    delta = psTimeLeapSecondDelta(time2,time1);
+    if(delta != testTimeLeapSecondDelta1) {
+        psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected %ld",
+                (long int)delta,(long int)testTimeLeapSecondDelta1);
+        return 6;
+    }
+
+    // Attempt to get delta with times equal
+    delta = psTimeLeapSecondDelta(time1,time1);
+    if(delta != 0) {
+        psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected 0",(long int)delta);
+        return 7;
+    }
+
+    psFree(time2);
+    psFree(time1);
+
+    return 0;
+}
+
+psS32 testTimeIsLeapSecond(void)
+{
+    psTime*     time        = NULL;
+    psBool      leapsecond  = false;
+
+    // Attempt to determine if leap second with NULL time
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time");
+    leapsecond = psTimeIsLeapSecond(time);
+    if(leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond);
+        return 1;
+    }
+
+    // Set time
+    time = psTimeAlloc(PS_TIME_TAI);
+    time->sec = testTime1SecondsUTC;
+    time->nsec = testTime1NanosecondsUTC;
+    time->leapsecond = false;
+
+    // Attempt to determine if leap second with non-UTC time
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type");
+    leapsecond = psTimeIsLeapSecond(time);
+    if(leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond);
+        return 2;
+    }
+
+    // Set time to UTC
+    time->type = PS_TIME_UTC;
+
+    // Attempt to determine if leap second with valid time
+    leapsecond = psTimeIsLeapSecond(time);
+    if(leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not a expected 0",leapsecond);
+        return 3;
+    }
+
+    // Set time to UTC with leap second
+    time->sec = testTime3SecondsUTC;
+    time->nsec = testTime3NanosecondsUTC;
+    leapsecond = psTimeIsLeapSecond(time);
+    if(!leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not a expected 1",leapsecond);
+        return 4;
+    }
+
+    // Set time to 1 second before a known leap second
+    time->sec--;
+    leapsecond = psTimeIsLeapSecond(time);
+    if(leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond);
+        return 5;
+    }
+
+    // Set time to 1 second after a known leap second
+    time->sec +=2;
+    leapsecond = psTimeIsLeapSecond(time);
+    if(leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond);
+        return 6;
+    }
+
+    psFree(time);
+
+    return 0;
+}
+
+psS32 testTimeFromTT(void)
+{
+    psTime*       time = NULL;
+
+    // Attempt to create psTime with invalid time
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time");
+    time = psTimeFromTT(0,2e9);
+    if(time != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected");
+        return 1;
+    }
+
+    // Attempt to create psTime with valid time
+    time = psTimeFromTT(testTime1SecondsUTC,testTime1NanosecondsUTC);
+    if(time == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected");
+        return 2;
+    }
+    if(time->type != PS_TIME_TT) {
+        psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d",
+                time->type,PS_TIME_TT);
+        return 3;
+    }
+    if((time->sec != testTime1SecondsUTC) || (time->nsec != testTime1NanosecondsUTC)) {
+        psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d",
+                (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC);
+        return 4;
+    }
+    psFree(time);
+
+    return 0;
+}
+
+psS32 testTimeFromUTC(void)
+{
+    psTime*       time = NULL;
+
+    // Attempt to create psTime with invalid time
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time");
+    time = psTimeFromUTC(0,2e9,true);
+    if(time != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected");
+        return 1;
+    }
+
+    // Attempt to create psTime with valid non-leapsecond time and leapsecond flag true
+    time = psTimeFromUTC(testTime1SecondsUTC,testTime1NanosecondsUTC,true);
+    if(time == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected");
+        return 2;
+    }
+    if(time->type != PS_TIME_UTC) {
+        psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d",
+                time->type,PS_TIME_UTC);
+        return 3;
+    }
+    if((time->sec != testTime1SecondsUTC) || (time->nsec != testTime1NanosecondsUTC)) {
+        psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d",
+                (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC);
+        return 4;
+    }
+    if(time->leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",time->leapsecond);
+        return 5;
+    }
+    psFree(time);
+
+    // Attempt to create psTime with valid leapsecond time but leapsecond flag false
+    time = psTimeFromUTC(testTime3SecondsUTC,testTime3NanosecondsUTC,false);
+    if(time == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected");
+        return 6;
+    }
+    if(time->type != PS_TIME_UTC) {
+        psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d",
+                time->type,PS_TIME_UTC);
+        return 7;
+    }
+    if((time->sec != testTime3SecondsUTC) || (time->nsec != testTime3NanosecondsUTC)) {
+        psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d",
+                (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC);
+        return 8;
+    }
+    if(!time->leapsecond) {
+        psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 1",time->leapsecond);
+        return 9;
+    }
+
+
+    psFree(time);
+
+    return 0;
+}
+
Index: /trunk/psLib/test/astronomy/verified/tst_psTime_02.stderr
===================================================================
--- /trunk/psLib/test/astronomy/verified/tst_psTime_02.stderr	(revision 4057)
+++ /trunk/psLib/test/astronomy/verified/tst_psTime_02.stderr	(revision 4058)
@@ -1,14 +1,85 @@
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: tmTime.tm_mon, 99, is out of range.  Must be between 1 and 12.
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: tmTime.tm_mday, 99, is out of range.  Must be between 1 and 31.
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: tmTime.tm_hour, 99, is out of range.  Must be between 0 and 23.
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: tmTime.tm_min, 99, is out of range.  Must be between 0 and 59.
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: tmTime.tm_sec, 99, is out of range.  Must be between 0 and 59.
-<DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO)
-    Error: millisecond, -999, is out of range.  Must be between 0 and 999.
-<DATE><TIME>|<HOST>|E|psTimeFromTimeval (FILE:LINENO)
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psTime_02.c                                            *
+*            TestPoint: psTime{psTimeToLMST}                                       *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testTimeLMST
+    Following should generate an error message for NULL time
+<DATE><TIME>|<HOST>|E|psTimeToLMST (FILE:LINENO)
     Unallowable operation: time is NULL.
+<DATE><TIME>|<HOST>|I|testTimeLMST
+    Following should generate error message for incorrect type
+<DATE><TIME>|<HOST>|E|psTimeToLMST (FILE:LINENO)
+    Specified type, 2, is incorrect.
+
+---> TESTPOINT PASSED (psTime{psTimeToLMST} | tst_psTime_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psTime_02.c                                            *
+*            TestPoint: psTime{psTimeLeapSecondDelta}                              *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta
+    Following should generate an error message for NULL time
+<DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO)
+    Unallowable operation: time1 is NULL.
+<DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta
+    Following should generate an error message for NULL time
+<DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO)
+    Unallowable operation: time2 is NULL.
+<DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta
+    Following should generate an error message for invalid time
+<DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO)
+    Error: time2->nsec, 2000000000, is out of range.  Must be between 0 and 999999999.
+<DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta
+    Following should generate an error message for invalid time
+<DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO)
+    Error: time1->nsec, 2000000000, is out of range.  Must be between 0 and 999999999.
+
+---> TESTPOINT PASSED (psTime{psTimeLeapSecondDelta} | tst_psTime_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psTime_02.c                                            *
+*            TestPoint: psTime{psTimeIsLeapSecond}                                 *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testTimeIsLeapSecond
+    Following should generate an error message for NULL time
+<DATE><TIME>|<HOST>|E|psTimeIsLeapSecond (FILE:LINENO)
+    Unallowable operation: utc is NULL.
+<DATE><TIME>|<HOST>|I|testTimeIsLeapSecond
+    Following should generate an error message for invalid type
+<DATE><TIME>|<HOST>|E|psTimeIsLeapSecond (FILE:LINENO)
+    Specified type, 0, is incorrect.
+
+---> TESTPOINT PASSED (psTime{psTimeIsLeapSecond} | tst_psTime_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psTime_02.c                                            *
+*            TestPoint: psTime{psTimeFromTT}                                       *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testTimeFromTT
+    Following should generate an error message for invalid time
+<DATE><TIME>|<HOST>|E|psTimeFromTT (FILE:LINENO)
+    Error: nsec, 2000000000, is out of range.  Must be between 0 and 999999999.
+
+---> TESTPOINT PASSED (psTime{psTimeFromTT} | tst_psTime_02.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psTime_02.c                                            *
+*            TestPoint: psTime{psTimeFromUTC}                                      *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testTimeFromUTC
+    Following should generate an error message for invalid time
+<DATE><TIME>|<HOST>|E|psTimeFromUTC (FILE:LINENO)
+    Error: nsec, 2000000000, is out of range.  Must be between 0 and 999999999.
+
+---> TESTPOINT PASSED (psTime{psTimeFromUTC} | tst_psTime_02.c)
+
Index: /trunk/psLib/test/astronomy/verified/tst_psTime_02.stdout
===================================================================
--- /trunk/psLib/test/astronomy/verified/tst_psTime_02.stdout	(revision 4057)
+++ /trunk/psLib/test/astronomy/verified/tst_psTime_02.stdout	(revision 4058)
@@ -1,31 +1,0 @@
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psTime_02.c                                            *
-*            TestPoint: psTime{Incorrect ISO time data}                            *
-*             TestType: Negative                                                   *
-*    ExpectedErrorText: Time not allowed                                           *
-*  ExpectedStatusValue: 0                                                          *
-\**********************************************************************************/
-
-
----> TESTPOINT PASSED (psTime{Incorrect ISO time data} | tst_psTime_02.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psTime_02.c                                            *
-*            TestPoint: psTime{Attempt to use null timeval}                        *
-*             TestType: Negative                                                   *
-*    ExpectedErrorText: Null value for timeval arg not allowed                     *
-*  ExpectedStatusValue: 0                                                          *
-\**********************************************************************************/
-
-
----> TESTPOINT PASSED (psTime{Attempt to use null timeval} | tst_psTime_02.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psTime_02.c                                            *
-*            TestPoint: psTime{Test C - Free data}                                 *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-
----> TESTPOINT PASSED (psTime{Test C - Free data} | tst_psTime_02.c)
-
