Index: trunk/psLib/src/astro/psTime.c
===================================================================
--- trunk/psLib/src/astro/psTime.c	(revision 1406)
+++ trunk/psLib/src/astro/psTime.c	(revision 1407)
@@ -1,2 +1,3 @@
+
 /** @file  psTime.c
  *
@@ -12,13 +13,14 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-06 22:34:05 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-08-07 00:06:06 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
 
-
 /******************************************************************************/
+
 /*  INCLUDE FILES                                                             */
+
 /******************************************************************************/
 
@@ -32,5 +34,7 @@
 
 /******************************************************************************/
+
 /*  DEFINE STATEMENTS                                                         */
+
 /******************************************************************************/
 
@@ -73,6 +77,9 @@
 }                                                                                                            \
 
+
 /******************************************************************************/
+
 /*  TYPE DEFINITIONS                                                          */
+
 /******************************************************************************/
 
@@ -80,5 +87,7 @@
 
 /*****************************************************************************/
+
 /*  GLOBAL VARIABLES                                                         */
+
 /*****************************************************************************/
 
@@ -86,5 +95,7 @@
 
 /*****************************************************************************/
+
 /*  FILE STATIC VARIABLES                                                    */
+
 /*****************************************************************************/
 
@@ -119,79 +130,57 @@
 
 // Table for Julian date of leapsecond update and current total number of leapseconds at that date
-static double leapseconds[NUM_LEAPSECOND_UPDATES][2] =
-    {
-        {
-            2441317.5, 10.0
-        },
-        {
-            2441499.5, 11.0
-        },
-        {
-            2441683.5, 12.0
-        },
-        {
-            2442048.5, 13.0
-        },
-        {
-            2442413.5, 14.0
-        },
-        {
-            2442778.5, 15.0
-        },
-        {
-            2443144.5, 16.0
-        },
-        {
-            2443509.5, 17.0
-        },
-        {
-            2443874.5, 18.0
-        },
-        {
-            2444239.5, 19.0
-        },
-        {
-            2444786.5, 20.0
-        },
-        {
-            2445151.5, 21.0
-        },
-        {
-            2445516.5, 22.0
-        },
-        {
-            2446247.5, 23.0
-        },
-        {
-            2447161.5, 24.0
-        },
-        {
-            2447892.5, 25.0
-        },
-        {
-            2448257.5, 26.0
-        },
-        {
-            2448804.5, 27.0
-        },
-        {
-            2449169.5, 28.0
-        },
-        {
-            2449534.5, 29.0
-        },
-        {
-            2450083.5, 30.0
-        },
-        {
-            2450630.5, 31.0
-        },
-        {
-            2451179.5, 32.0
-        }
-    };
-
-/*****************************************************************************/
+static double leapseconds[NUM_LEAPSECOND_UPDATES][2] = {
+            {
+                2441317.5, 10.0},
+            {
+                2441499.5, 11.0},
+            {
+                2441683.5, 12.0},
+            {
+                2442048.5, 13.0},
+            {
+                2442413.5, 14.0},
+            {
+                2442778.5, 15.0},
+            {
+                2443144.5, 16.0},
+            {
+                2443509.5, 17.0},
+            {
+                2443874.5, 18.0},
+            {
+                2444239.5, 19.0},
+            {
+                2444786.5, 20.0},
+            {
+                2445151.5, 21.0},
+            {
+                2445516.5, 22.0},
+            {
+                2446247.5, 23.0},
+            {
+                2447161.5, 24.0},
+            {
+                2447892.5, 25.0},
+            {
+                2448257.5, 26.0},
+            {
+                2448804.5, 27.0},
+            {
+                2449169.5, 28.0},
+            {
+                2449534.5, 29.0},
+            {
+                2450083.5, 30.0},
+            {
+                2450630.5, 31.0},
+            {
+                2451179.5, 32.0}
+        };
+
+/*****************************************************************************/
+
 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
+
 /*****************************************************************************/
 
@@ -199,5 +188,7 @@
 
 /*****************************************************************************/
+
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
+
 /*****************************************************************************/
 
@@ -210,9 +201,8 @@
     time.tv_usec = 0;
 
-    if(gettimeofday(&now,(struct timezone *) 0) == -1) {
+    if (gettimeofday(&now, (struct timezone *)0) == -1) {
         psError(__func__, " : Line %d - Failed to get time", __LINE__);
         return time;
     }
-
     // Convert timeval time to psTime
     time.tv_sec = now.tv_sec;
@@ -220,10 +210,10 @@
 
     // Add most current leapseconds value to UTC time to get TAI time
-    time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES-1][1];
+    time.tv_sec += leapseconds[NUM_LEAPSECOND_UPDATES - 1][1];
 
     return time;
 }
 
-char* psTimeToISO(psTime time)
+char *psTimeToISO(psTime time)
 {
     int ms = 0;
@@ -232,5 +222,5 @@
     struct tm *tmTime = NULL;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,NULL);
+    CHECK_NEGATIVE_TIME_STRUCT(time, NULL);
 
     tempString = psAlloc(MAX_TIME_STRING_LENGTH);
@@ -238,13 +228,13 @@
 
     // Converts psTime to YYYY/MM/DD,HH:MM:SS.SSS in string form
-    ms = time.tv_usec/1000;
+    ms = time.tv_usec / 1000;
 
     // tmTime variable is statically allocated, no need to free
     tmTime = gmtime(&time.tv_sec);
-    if(!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y/%m/%d,%H:%M:%S", tmTime)) {
+    if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y/%m/%d,%H:%M:%S", tmTime)) {
         psError(__func__, " : Line %d - Failed strftime conversion", __LINE__);
     }
 
-    if(snprintf(timeString,MAX_TIME_STRING_LENGTH,"%s.%3.3d", tempString, ms) < 0) {
+    if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3d", tempString, ms) < 0) {
         psError(__func__, " : Line %d - Failed snprintf conversion", __LINE__);
     }
@@ -262,11 +252,11 @@
     psTime outTime;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,outTime);
+    CHECK_NEGATIVE_TIME_STRUCT(time, outTime);
 
     // Find leapseconds to subtract from psTime to get UTC time
     jd = psTimeToJD(time);
     jdTable = leapseconds[0];
-    for(i=0; i<NUM_LEAPSECOND_UPDATES; i++, jdTable+=2) {
-        if(jd > *jdTable) {
+    for (i = 0; i < NUM_LEAPSECOND_UPDATES; i++, jdTable += 2) {
+        if (jd > *jdTable) {
             ls = *(jdTable + 1);
         }
@@ -276,5 +266,5 @@
     outTime.tv_usec = time.tv_usec;
 
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
 
     return outTime;
@@ -285,8 +275,8 @@
     double mjd = 0.0;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,mjd);
+    CHECK_NEGATIVE_TIME_STRUCT(time, mjd);
 
     // Modified Julian date conversion courtesy of Eugene Magnier
-    mjd = time.tv_sec/SEC_PER_DAY + time.tv_usec/USEC_PER_DAY + 40587.0;
+    mjd = time.tv_sec / SEC_PER_DAY + time.tv_usec / USEC_PER_DAY + 40587.0;
 
     return mjd;
@@ -297,8 +287,8 @@
     double jd = 0.0;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,jd);
+    CHECK_NEGATIVE_TIME_STRUCT(time, jd);
 
     // Julian date conversion courtesy of Eugene Magnier
-    jd = time.tv_sec/SEC_PER_DAY + time.tv_usec/USEC_PER_DAY + 2440587.5;
+    jd = time.tv_sec / SEC_PER_DAY + time.tv_usec / USEC_PER_DAY + 2440587.5;
 
     return jd;
@@ -309,5 +299,5 @@
     struct timeval timevalTime;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,timevalTime);
+    CHECK_NEGATIVE_TIME_STRUCT(time, timevalTime);
     timevalTime.tv_sec = time.tv_sec;
     timevalTime.tv_usec = time.tv_usec;
@@ -316,9 +306,9 @@
 }
 
-struct tm* psTimeToTM(psTime time)
+struct tm *psTimeToTM(psTime time)
 {
     struct tm *tmTime = NULL;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,tmTime);
+    CHECK_NEGATIVE_TIME_STRUCT(time, tmTime);
     tmTime = gmtime(&time.tv_sec);
 
@@ -343,42 +333,42 @@
     // Convert YYYY/MM/DD,HH:MM:SS.SSS in string form to tm time
     year = atoi(strtok(tempString, "/"));
-    if(year < 1900) {
-        psError(__func__,"Years less than 1900 not allowed. Value: %d", year);
+    if (year < 1900) {
+        psError(__func__, "Years less than 1900 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);
+    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, ","));
-    if(day<1 || day>31) {
-        psError(__func__,"Day must have a value from 1 to 31. Value: %d", day);
+    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);
+    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);
+    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);
+    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, "X"));
-    if(millisecond<0 || millisecond>1000) {
-        psError(__func__,"Millisecond must have a value from 0 to 999. Value: %d", millisecond);
+    if (millisecond < 0 || millisecond > 1000) {
+        psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond);
         return outTime;
     }
@@ -394,5 +384,5 @@
     // Convert tm time to psTime
     outTime = psTMToTime(&tmTime);
-    outTime.tv_usec = millisecond*1000;
+    outTime.tv_usec = millisecond * 1000;
 
     return outTime;
@@ -403,10 +393,10 @@
     psTime outTime;
 
-    CHECK_NEGATIVE_TIME_STRUCT(time,outTime);
+    CHECK_NEGATIVE_TIME_STRUCT(time, outTime);
 
     // Convert UTC time to psTime/TAI
-    outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES-1][1];
+    outTime.tv_sec = time.tv_sec + leapseconds[NUM_LEAPSECOND_UPDATES - 1][1];
     outTime.tv_usec = time.tv_usec;
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
 
     return outTime;
@@ -419,5 +409,5 @@
     double seconds = 0.0;
 
-    CHECK_NEGATIVE_TIME(time,outTime);
+    CHECK_NEGATIVE_TIME(time, outTime);
 
     // Modified Julian date conversion courtesy of Eugene Magnier
@@ -425,9 +415,9 @@
 
     // Convert to psTime/TAI
-    seconds = days*SEC_PER_DAY;
-    outTime.tv_usec = (seconds -(long)seconds)*1000000.0;
+    seconds = days * SEC_PER_DAY;
+    outTime.tv_usec = (seconds - (long)seconds) * 1000000.0;
     outTime.tv_sec = seconds;
 
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
 
     return outTime;
@@ -440,5 +430,5 @@
     psTime outTime;
 
-    CHECK_NEGATIVE_TIME(time,outTime);
+    CHECK_NEGATIVE_TIME(time, outTime);
 
     // Julian date conversion courtesy of Eugene Magnier
@@ -446,106 +436,96 @@
 
     // Convert to psTime/TAI
-    seconds = days*SEC_PER_DAY;
+    seconds = days * SEC_PER_DAY;
     outTime.tv_sec = seconds;
-    outTime.tv_usec = (seconds -(long)seconds)*1000000.0;
-
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
-
-    return outTime;
-}
-
-psTime psTimevalToTime(struct timeval *time)
-{
-    psTime outTime;
-    if(time == NULL)
-    {
-        psError(__func__,"Null value for timeval arg not allowed");
-        return outTime;
-    } else
-        if(time->tv_sec < 0)
-        {
-            psError(__func__,"Negative seconds are not allowed: %ld", time->tv_sec);
-            return outTime;
-        } else
-            if(time->tv_usec<0)
-            {
-                psError(__func__,"Negative microseconds are not allowed: %ld", time->tv_usec);
-                return outTime;
-            }
-
+    outTime.tv_usec = (seconds - (long)seconds) * 1000000.0;
+
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
+
+    return outTime;
+}
+
+psTime psTimevalToTime(struct timeval * time)
+{
+    psTime outTime;
+
+    if (time == NULL)
+    {
+        psError(__func__, "Null value for timeval arg not allowed");
+        return outTime;
+    } else if (time->tv_sec < 0)
+    {
+        psError(__func__, "Negative seconds are not allowed: %ld", time->tv_sec);
+        return outTime;
+    } else if (time->tv_usec < 0)
+    {
+        psError(__func__, "Negative microseconds are not allowed: %ld", time->tv_usec);
+        return outTime;
+    }
     // Convert to psTime/TAI
     outTime.tv_sec = time->tv_sec;
     outTime.tv_usec = time->tv_usec;
 
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
-
-    return outTime;
-}
-
-
-psTime psTMToTime(struct tm *time)
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
+
+    return outTime;
+}
+
+psTime psTMToTime(struct tm * time)
 {
     int i;
     int n;
     int y;
-    int mon [] =
-        {
-            31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-        };
+    int mon[] = {
+                    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
+                };
     long epoch;
     psTime outTime;
 
-    i= 0;
+    i = 0;
     n = 0;
     y = 0;
     epoch = 0;
 
-    if(time == NULL)
-    {
-        psError(__func__,"Null value for tm arg not allowed");
-        return outTime;
-    } else
-        if(time->tm_year < 70)
-        {
-            psError(__func__,"Input times earlier than 1970 not allowed. Value: %d", time->tm_year+1900);
-            return outTime;
-        } else
-            if(time->tm_mon<0 || time->tm_mon>11)
-            {
-                psError(__func__,"Month must have a value from 0 to 11. Value: %d", time->tm_mon);
-                return outTime;
-            } else
-                if(time->tm_mday<1 || time->tm_mday>31)
-                {
-                    psError(__func__,"Day must have a value from 1 to 31. Value: %d", time->tm_mday);
-                    return outTime;
-                } else
-                    if(time->tm_hour<0 || time->tm_hour>23)
-                    {
-                        psError(__func__,"Hour must have a value from 0 to 23. Value: %d", time->tm_hour);
-                        return outTime;
-                    } else
-                        if(time->tm_min<0 || time->tm_min>59)
-                        {
-                            psError(__func__,"Minute must have a value from 0 to 59. Value: %d", time->tm_min);
-                            return outTime;
-                        } else
-                            if(time->tm_sec<0 || time->tm_sec>59)
-                            {
-                                psError(__func__,"Second must have a value from 0 to 59. Value: %d", time->tm_sec);
-                                return outTime;
-                            }
+    if (time == NULL)
+    {
+        psError(__func__, "Null value for tm arg not allowed");
+        return outTime;
+    } else if (time->tm_year < 70)
+    {
+        psError(__func__, "Input times earlier than 1970 not allowed. Value: %d", time->tm_year + 1900);
+        return outTime;
+    } else if (time->tm_mon < 0 || time->tm_mon > 11)
+    {
+        psError(__func__, "Month must have a value from 0 to 11. Value: %d", time->tm_mon);
+        return outTime;
+    } else if (time->tm_mday < 1 || time->tm_mday > 31)
+    {
+        psError(__func__, "Day must have a value from 1 to 31. Value: %d", time->tm_mday);
+        return outTime;
+    } else if (time->tm_hour < 0 || time->tm_hour > 23)
+    {
+        psError(__func__, "Hour must have a value from 0 to 23. Value: %d", time->tm_hour);
+        return outTime;
+    } else if (time->tm_min < 0 || time->tm_min > 59)
+    {
+        psError(__func__, "Minute must have a value from 0 to 59. Value: %d", time->tm_min);
+        return outTime;
+    } else if (time->tm_sec < 0 || time->tm_sec > 59)
+    {
+        psError(__func__, "Second must have a value from 0 to 59. Value: %d", time->tm_sec);
+        return outTime;
+    }
 
     n = time->tm_year + 1900 - 1;
-    epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n/4 - n/100 + n/400) -
-            (1969/4 - 1969/100 + 1969/400)) * SEC_PER_DAY;
+    epoch = (time->tm_year - 70) * SEC_PER_YEAR + ((n / 4 - n / 100 + n / 400) -
+            (1969 / 4 - 1969 / 100 + 1969 / 400)) * SEC_PER_DAY;
 
     y = time->tm_year + 1900;
 
     // Adjust for leap years
-    for(i = 0; i<time->tm_mon; i++)
-    {
-        epoch += mon [i] * SEC_PER_DAY;
-        if(i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
+    for (i = 0; i < time->tm_mon; i++)
+    {
+        epoch += mon[i] * SEC_PER_DAY;
+        if (i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
             epoch += SEC_PER_DAY;
         }
@@ -554,5 +534,5 @@
     // Add everything
     epoch += (time->tm_mday - 1) * SEC_PER_DAY;
-    epoch += time->tm_hour *SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec;
+    epoch += time->tm_hour * SEC_PER_HOUR + time->tm_min * SEC_PER_MINUTE + time->tm_sec;
 
     // Create psTime
@@ -560,6 +540,6 @@
     outTime.tv_sec = epoch;
 
-    CHECK_NEGATIVE_TIME_STRUCT(outTime,outTime);
-
-    return outTime;
-}
+    CHECK_NEGATIVE_TIME_STRUCT(outTime, outTime);
+
+    return outTime;
+}
