Index: /trunk/psLib/src/astro/psCoord.h
===================================================================
--- /trunk/psLib/src/astro/psCoord.h	(revision 2047)
+++ /trunk/psLib/src/astro/psCoord.h	(revision 2048)
@@ -11,6 +11,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-12 01:23:20 $
+*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-10-12 01:34:09 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -53,5 +53,5 @@
  *
  */
-typedef struct
+typedef struct psSphere
 {
     double r;                   ///< RA
Index: /trunk/psLib/src/astro/psTime.c
===================================================================
--- /trunk/psLib/src/astro/psTime.c	(revision 2047)
+++ /trunk/psLib/src/astro/psTime.c	(revision 2048)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-09 00:17:14 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,6 +27,15 @@
 #include "psAbort.h"
 #include "psImage.h"
+#include "psCoord.h"
 
 #include "psAstronomyErrors.h"
+
+#ifndef SER7_FILE
+#define SER7_FILE "../../data/ser7.dat"
+#endif
+
+#ifndef TAIUTC_FILE
+#define TAIUTC_FILE "../../data/tai-utc.dat"
+#endif
 
 /** Sidereal angular conversion from seconds to radians for GMST in seconds (i.e. pi/(180*240)) */
@@ -61,22 +70,88 @@
 
                 /** 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;                                                                                           \
+                #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;                                                                                              \
+                #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;
 
-
-psImage* readTaiUtcFile(char *fileName)
+/** 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 SER7 data file.
+ *
+ *  Reads SER7 data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+static psImage* readSer7File(
+    const char *fileName                      ///< Name of file to read.
+);
+
+
+/** Read finals data file.
+ *
+ *  Reads finals data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+/* not yet used
+static psImage* readFinalsFile(
+    char *fileName                      ///< Name of file to read.
+);
+*/
+
+/** Read EOPC data file.
+ *
+ *  Reads EOPC data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+/* not yet used
+static psImage* readEopcFile(
+    char *fileName                      ///< Name of file to read.
+);
+*/
+
+/** Lookup and interpolate TAI-UTC data
+ *
+ *  Interpolates TAI-UTC data, given time in MJD format.
+ *
+ *  @return  double: Interpolated value.
+ */
+static double lookupTaiUtcTable(
+    const psTime *time                        ///< time to lookup.
+);
+
+/** Lookup and interpolate polar or UT1-UTC data
+ *
+ *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
+ *
+ *  @return  double: Interpolated value.
+ */
+static double lookupSer7Table(
+    const psTime *time,                        ///< time to lookup.
+    int col                              ///< Column to lookup.
+);
+
+static psImage* readTaiUtcFile(const char *fileName)
 {
     char line[LINESIZE];
@@ -113,8 +188,12 @@
     *(unsigned int *)&table->numRows = j;
 
+    p_psMemSetPersistent(table,true);
+    p_psMemSetPersistent(table->data.V,true);
+    p_psMemSetPersistent(table->rawDataBuffer,true);
+
     return table;
 }
 
-psImage* readSer7File(char *fileName)
+static psImage* readSer7File(const char *fileName)
 {
     bool beginRecord = false;
@@ -160,8 +239,13 @@
     *(unsigned int *)&table->numRows = j;
 
+    p_psMemSetPersistent(table,true);
+    p_psMemSetPersistent(table->data.V,true);
+    p_psMemSetPersistent(table->rawDataBuffer,true);
+
     return table;
 }
 
-psImage* readEopcFile(char *fileName)
+/* Not yet used...
+static psImage* readEopcFile(char *fileName)
 {
     char line[LINESIZE];
@@ -171,6 +255,6 @@
     psImage *table = NULL;
     FILE *fd = NULL;
-
-
+ 
+ 
     fd=fopen(fileName, "r");
     if(fd==NULL) {
@@ -178,5 +262,5 @@
         return NULL ;
     }
-
+ 
     // Table shouldn't be larger than 2500 rows. All columns are read.
     table  = psImageAlloc(11, maxLines, PS_TYPE_F64);
@@ -186,5 +270,5 @@
         }
     }
-
+ 
     while(fgets(line, LINESIZE, fd) != NULL) {
         if(j>=maxLines) {
@@ -197,11 +281,11 @@
                ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);
     }
-
+ 
     *(unsigned int *)&table->numRows = j;
-
+ 
     return table;
 }
-
-psImage* readFinalsFile(char *fileName)
+ 
+static psImage* readFinalsFile(char *fileName)
 {
     char line[LINESIZE];
@@ -210,6 +294,6 @@
     psImage *table = NULL;
     FILE *fd = NULL;
-
-
+ 
+ 
     fd=fopen(fileName, "r");
     if(fd==NULL) {
@@ -217,5 +301,5 @@
         return NULL ;
     }
-
+ 
     // Table shouldn't be larger than 15000 rows. Select columns are read.
     table  = psImageAlloc(6, maxLines, PS_TYPE_F64);
@@ -226,8 +310,8 @@
             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
@@ -236,5 +320,5 @@
             *ptr = atof(line+7);
         }
-
+ 
         if(*(line+18) == ' ') {                  // Polar motion X
             *(ptr+1) = 0.0;
@@ -242,5 +326,5 @@
             *(ptr+1) = atof(line+18);
         }
-
+ 
         if(*(line+27) == ' ') {                  // Polar motion X error
             *(ptr+2) = 0.0;
@@ -248,5 +332,5 @@
             *(ptr+2) = atof(line+27);
         }
-
+ 
         if(*(line+37) == ' ') {                  // Polar motion Y
             *(ptr+3) = 0.0;
@@ -254,5 +338,5 @@
             *(ptr+3) = atof(line+37);
         }
-
+ 
         if(*(line+46) == ' ') {                  // Polar motion Y error
             *(ptr+4) = 0.0;
@@ -260,5 +344,5 @@
             *(ptr+4) = atof(line+46);
         }
-
+ 
         if(*(line+58) == ' ') {                  // UT1-UTC
             *(ptr+5) = 0.0;
@@ -267,12 +351,12 @@
         }
     }
-
+ 
     *(unsigned int *)&table->numRows = j;
-
+ 
     return table;
 }
-
-
-double lookupTaiUtcTable(psImage *table, psTime *time)
+*/
+
+static double lookupTaiUtcTable(const psTime *time)
 {
     int hiIdx = 0;
@@ -286,5 +370,12 @@
     double const2 = 0.0;
     double const3 = 0.0;
-
+    static psImage* table = NULL;
+
+    if (table == NULL) {
+        table = readTaiUtcFile(TAIUTC_FILE);
+        if (table == NULL) {
+            psAbort(__func__,"Failed to read tai-utc.dat file");
+        }
+    }
 
     // Number of rows is the number of rows of data read from the data file
@@ -337,5 +428,5 @@
 }
 
-double lookupSer7Table(psImage *table, psTime *time, int col)
+static double lookupSer7Table(const psTime *time, int col)
 {
     int hiIdx = 0;
@@ -345,5 +436,12 @@
     double denom = 0.0;
     double mjdUtc = 0.0;
-
+    static psImage* table = NULL;
+
+    if (table == NULL) {
+        table = readSer7File(SER7_FILE);
+        if (table == NULL) {
+            psAbort(__func__,"Failed to read the ser7.dat file.");
+        }
+    }
 
     // Number of rows is the number of rows of data read from the data file
@@ -404,5 +502,5 @@
     // Add most leapseconds to UTC time to get TAI time if necessary
     if(type == PS_TIME_TAI) {
-        time->sec += psGetTAIDelta(time);
+        time->sec += psTimeGetTAIDelta(time);
     }
 
@@ -420,5 +518,5 @@
     }
 
-    delta = psGetTAIDelta(time);
+    delta = psTimeGetTAIDelta(time);
 
     if(type == PS_TIME_UTC) {
@@ -461,5 +559,5 @@
         taiTime = psMemIncrRefCounter(time);
         ALLOC_TIME(utcTime);
-        utcTime->sec = taiTime->sec - psGetTAIDelta(time);
+        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
         utcTime->usec = taiTime->usec;
         utcTime->type = PS_TIME_UTC;
@@ -467,5 +565,5 @@
         utcTime = psMemIncrRefCounter(time);
         ALLOC_TIME(taiTime);
-        taiTime->sec = utcTime->sec + psGetTAIDelta(time);
+        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
         taiTime->usec = utcTime->usec;
         taiTime->type = PS_TIME_TAI;
@@ -475,5 +573,5 @@
     ALLOC_TIME(ut1UtcDelta);
     ut1UtcDelta->type = PS_TIME_UTC;
-    ut1UtcDelta->usec = psGetUT1Delta(utcTime)*1e6;
+    ut1UtcDelta->usec = psTimeGetUT1Delta(utcTime)*1e6;
     ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
 
@@ -516,42 +614,30 @@
 }
 
-double psGetUT1Delta(psTime *time)
-{
-    static psImage* iersTable = NULL;
-    double ut1UtcDeltaUsec = 0.0;
-
-
-    if (iersTable == NULL) {
-        iersTable = readSer7File("../../data/ser7.dat");
-        p_psMemSetPersistent(iersTable,true);
-        p_psMemSetPersistent(iersTable->data.V,true);
-        p_psMemSetPersistent(iersTable->rawDataBuffer,true);
-    }
-
-    ut1UtcDeltaUsec = lookupSer7Table(iersTable, time, 6)*1.0e6;
-
-    return ut1UtcDeltaUsec;
-}
-
-double psGetTAIDelta(psTime *time)
-{
-    double delta = 0.0;
-    static psImage* taiUtcTable = NULL;
-
-
-    if (taiUtcTable == NULL) {
-        taiUtcTable = readTaiUtcFile("../../data/tai-utc.dat");
-        p_psMemSetPersistent(taiUtcTable,true);
-        p_psMemSetPersistent(taiUtcTable->data.V,true);
-        p_psMemSetPersistent(taiUtcTable->rawDataBuffer,true);
-    }
-    delta = lookupTaiUtcTable(taiUtcTable, time);
-
-    return delta;
-}
-
-psF64 psTimeLeapseconds(const psTime *time1, const psTime *time2)
-{
-    psF64 diff = 0.0;
+double psTimeGetUT1Delta(const psTime *time)
+{
+    return lookupSer7Table(time, 6);
+}
+
+struct psSphere* psTimeGetPoleCoords(const psTime* time)
+{
+
+    double x = lookupSer7Table((psTime*)time, 4);
+    double y = lookupSer7Table((psTime*)time, 5);
+
+    struct psSphere* 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;
+
+    return output;
+}
+
+double psTimeGetTAIDelta(const psTime *time)
+{
+    return lookupTaiUtcTable(time);
+}
+
+long psTimeLeapseconds(const psTime *time1, const psTime *time2)
+{
+    long diff = 0;
 
     // NULL error checks
@@ -559,10 +645,10 @@
     CHECK_NULL_TIME(time2,0);
 
-    diff = fabs(psGetTAIDelta((psTime*)time1)-psGetTAIDelta((psTime*)time2));
+    diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
 
     return diff;
 }
 
-double psTimeToJD(psTime *time)
+double psTimeToJD(const psTime *time)
 {
     double jd = 0.0;
@@ -582,5 +668,5 @@
 }
 
-double psTimeToMJD(psTime *time)
+double psTimeToMJD(const psTime *time)
 {
     double mjd = 0.0;
@@ -600,5 +686,5 @@
 }
 
-char* psTimeToISO(psTime *time)
+char* psTimeToISOTime(const psTime *time)
 {
     int ms = 0;
@@ -634,5 +720,5 @@
 }
 
-struct timeval psTimeToTimeval(psTime *time)
+struct timeval psTimeToTimeval(const psTime *time)
 {
     struct timeval timevalTime;
@@ -648,5 +734,5 @@
 }
 
-struct tm* psTimeToTM(psTime *time)
+struct tm* psTimeToTM(const psTime *time)
 {
     long cent = 0;
@@ -711,5 +797,5 @@
 }
 
-psTime* psJDToTime(double time)
+psTime* psTimeFromJD(double time)
 {
     double days = 0.0;
@@ -734,5 +820,5 @@
 }
 
-psTime* psMJDToTime(double time)
+psTime* psTimeFromMJD(double time)
 {
     double days = 0.0;
@@ -757,5 +843,5 @@
 }
 
-psTime* psISOToTime(char *time)
+psTime* psTimeFromISOTime(const char *time)
 {
     char tempString[MAX_TIME_STRING_LENGTH];
@@ -826,5 +912,5 @@
 
     // Convert tm time to psTime
-    outTime = psTMToTime(&tmTime);
+    outTime = psTimeFromTM(&tmTime);
     outTime->usec = millisecond * 1000;
 
@@ -832,5 +918,5 @@
 }
 
-psTime* psTimevalToTime(struct timeval *time)
+psTime* psTimeFromTimeval(const struct timeval *time)
 {
     psTime *outTime = NULL;
@@ -850,5 +936,5 @@
 }
 
-psTime* psTMToTime(struct tm* time)
+psTime* psTimeFromTM(const struct tm* time)
 {
     long year;
@@ -905,5 +991,5 @@
 }
 
-psTime* psTimeAdd(psTime *tai1, psTime *tai2)
+psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
@@ -929,5 +1015,5 @@
 }
 
-psTime* psTimeSub(psTime *tai1, psTime *tai2)
+psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
@@ -953,5 +1039,5 @@
 }
 
-psTime* psTimeDelta(psTime *tai1, psTime *tai2)
+psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
Index: /trunk/psLib/src/astro/psTime.h
===================================================================
--- /trunk/psLib/src/astro/psTime.h	(revision 2047)
+++ /trunk/psLib/src/astro/psTime.h	(revision 2048)
@@ -54,6 +54,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-11 00:55:13 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -69,4 +69,6 @@
 #include "psType.h"
 #include "psImage.h"
+
+struct psSphere;
 
 /// @addtogroup Time
@@ -138,6 +140,6 @@
  *  @return  double: Time difference.
  */
-double psGetUT1Delta(
-    psTime *time                        ///< psTime to be looked up.
+double psTimeGetUT1Delta(
+    const psTime *time                  ///< psTime to be looked up.
 );
 
@@ -148,6 +150,6 @@
  *  @return  double: Time difference.
  */
-double psGetTAIDelta(
-    psTime *time                        ///< psTime to be looked up.
+double psTimeGetTAIDelta(
+    const psTime *time                  ///< psTime to be looked up.
 );
 
@@ -158,7 +160,7 @@
  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
  */
-/*psSphere* psGetPoleCoords(
-    psTime *time                        ///< psTime determine polar orientation.
-);*/
+struct psSphere* psTimeGetPoleCoords(
+                const psTime *time                  ///< psTime determine polar orientation.
+            );
 
 /** Calculate the number of leapseconds between two times.
@@ -166,9 +168,9 @@
  *  Calculates the number of leapseconds between two times.
  *
- *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
- */
-psF64 psTimeLeapseconds(
-    const psTime *time1,                ///< First input time.
-    const psTime *time2                 ///< Second input time.
+ *  @return  long: leapseconds added between given times
+ */
+long psTimeLeapseconds(
+    const psTime* time1,                ///< First input time.
+    const psTime* time2                 ///< Second input time.
 );
 
@@ -180,5 +182,5 @@
  */
 double psTimeToJD(
-    psTime *time                        ///< Input time to be converted.
+    const psTime* time                  ///< Input time to be converted.
 );
 /** Convert psTime to modified Julian date time.
@@ -189,5 +191,5 @@
  */
 double psTimeToMJD(
-    psTime *time                        ///< Input time to be converted.
+    const psTime* time                  ///< Input time to be converted.
 );
 
@@ -199,6 +201,6 @@
  *  @return  char*: Pointer null terminated array of chars in ISO time.
  */
-char* psTimeToISO(
-    psTime *time                        ///< Input time to be converted.
+char* psTimeToISOTime(
+    const psTime* time                  ///< Input time to be converted.
 );
 
@@ -210,5 +212,5 @@
  */
 struct timeval psTimeToTimeval(
-                psTime *time                        ///< Input time to be converted.
+                const psTime* time                  ///< Input time to be converted.
             );
 
@@ -221,5 +223,5 @@
  */
 struct tm* psTimeToTM(
-                psTime *time                        ///< Input time to be converted.
+                const psTime *time                  ///< Input time to be converted.
             );
 
@@ -230,5 +232,5 @@
  *  @return  psTime: time.
  */
-psTime* psJDToTime(
+psTime* psTimeFromJD(
     double time                         ///< Input time to be converted.
 );
@@ -240,5 +242,5 @@
  *  @return  psTime: time.
  */
-psTime* psMJDToTime(
+psTime* psTimeFromMJD(
     double time                         ///< Input time to be converted.
 );
@@ -250,6 +252,6 @@
  *  @return  psTime*: time
  */
-psTime* psISOToTime(
-    char *time                          ///< Input time to be converted.
+psTime* psTimeFromISOTime(
+    const char* time                    ///< Input time to be converted.
 );
 
@@ -260,6 +262,6 @@
  *  @return  psTime*: time.
  */
-psTime* psTimevalToTime(
-    struct timeval *time                ///< Input time to be converted.
+psTime* psTimeFromTimeval(
+    const struct timeval *time          ///< Input time to be converted.
 );
 
@@ -271,6 +273,6 @@
  *  @return  psTime*: time.
  */
-psTime* psTMToTime(
-    struct tm *time                     ///< Input time to be converted.
+psTime* psTimeFromTM(
+    const struct tm *time               ///< Input time to be converted.
 );
 
@@ -282,6 +284,6 @@
  */
 psTime* psTimeAdd(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
 );
 
@@ -292,7 +294,7 @@
  *  @return  psTime*: time.
  */
-psTime* psTimeSub(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
+psTime* psTimeSubtract(
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
 );
 
@@ -305,72 +307,8 @@
  */
 psTime* psTimeDelta(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
-);
-
-
-/** Read TAI/UTC data file.
- *
- *  Reads TAI/UTC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readTaiUtcFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-
-/** Read SER7 data file.
- *
- *  Reads SER7 data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readSer7File(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Read finals data file.
- *
- *  Reads finals data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readFinalsFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Read EOPC data file.
- *
- *  Reads EOPC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readEopcFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Lookup and interpolate TAI-UTC data
- *
- *  Interpolates TAI-UTC data, given time in MJD format.
- *
- *  @return  double: Interpolated value.
- */
-double lookupTaiUtcTable(
-    psImage *table,                     ///< Table with data.
-    psTime *time                        ///< time to lookup.
-);
-
-/** Lookup and interpolate polar or UT1-UTC data
- *
- *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
- *
- *  @return  double: Interpolated value.
- */
-double lookupSer7Table(
-    psImage *table,                      ///< Table with data.
-    psTime *time,                        ///< time to lookup.
-    int col                              ///< Column to lookup.
-);
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
+);
+
 /// @}
 
Index: /trunk/psLib/src/astronomy/psAstrometry.c
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.c	(revision 2047)
+++ /trunk/psLib/src/astronomy/psAstrometry.c	(revision 2048)
@@ -8,6 +8,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-07 19:16:46 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -455,22 +455,26 @@
 psGrommit* psGrommitAlloc(const psExposure* exp)
 {
+    double* AOPRMS = psAlloc(sizeof(double)*14);
+
     if (exp == NULL) {
         psAbort(__func__, "the 'exp' parameter is NULL\n");
     }
 
-    double date = TBD;  // XXX: "mjd" in psExposure will become a psTime
-    // from which it will be possible to get UTC.
-    double dut = 0.0;
-    double elongm = TBD; // XXX
-    double phim = TBD;   // XXX
-    double hm = TBD;     // XXX
-    double xp = 0.0;
-    double yp = 0.0;
+    double date = psTimeToMJD(exp->time);
+    double dut = psTimeGetUT1Delta(exp->time);
+    double elongm = exp->observatory->longitude;
+    double phim = exp->observatory->latitude;
+    double hm = exp->observatory->height;
+
+    psSphere* polarMotion = psTimeGetPoleCoords(exp->time);
+    double xp = polarMotion->r;
+    double yp = polarMotion->d;
+    psFree(polarMotion);
+
     double tdk = exp->temperature;
     double pmb = exp->pressure;
     double rh = exp->humidity;
     double wl = exp->wavelength;
-    double tlr = TBD;    // XXX
-    double *AOPRMS = NULL;
+    double tlr = exp->observatory->tlr;
 
     slaAoppa(date, dut, elongm, phim, hm, xp, yp,
@@ -493,4 +497,6 @@
     *(double *)&grommit->siderealTime = AOPRMS[13];
 
+    psFree(AOPRMS);
+
     return (grommit);
 }
Index: /trunk/psLib/src/astronomy/psAstrometry.h
===================================================================
--- /trunk/psLib/src/astronomy/psAstrometry.h	(revision 2047)
+++ /trunk/psLib/src/astronomy/psAstrometry.h	(revision 2048)
@@ -8,6 +8,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-10-07 19:16:46 $
+*  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-10-12 01:34:09 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -192,7 +192,7 @@
 {
     const char* name;                  ///< Name of observatory
-    const double latitude;             ///< Latitude of observatory, east positive
-    const double longitude;            ///< Longitude of observatory
-    const double height;               ///< Height of observatory
+    const double latitude;             ///< Latitude of observatory, east positive (degrees?)
+    const double longitude;            ///< Longitude of observatory (degrees?)
+    const double height;               ///< Height of observatory in meters
     const double tlr;                  ///< Tropospheric Lapse Rate
 }
@@ -214,10 +214,10 @@
     const double azimuth;              ///< Azimuth
     const psTime* time;                ///< Time of observation
-    const float rotAngle;              ///< Rotator position angle
-    const float temperature;           ///< Air temperature, for estimating refraction
-    const float pressure;              ///< Air pressure, for calculating refraction
+    const float rotAngle;              ///< Rotator position angle in degrees? XXX: see bug#209
+    const float temperature;           ///< Air temperature in Kelvin
+    const float pressure;              ///< Air pressure in mB
     const float humidity;              ///< Relative humidity, for refraction
     const float exposureTime;          ///< Exposure time
-    const float wavelength;            ///< Wavelength
+    const float wavelength;            ///< Wavelength in microns
     const psObservatory* observatory;  ///< Observatory data
 
Index: /trunk/psLib/src/astronomy/psCoord.h
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.h	(revision 2047)
+++ /trunk/psLib/src/astronomy/psCoord.h	(revision 2048)
@@ -11,6 +11,6 @@
 *  @author George Gusciora, MHPCC
 *
-*  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-12 01:23:20 $
+*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-10-12 01:34:09 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -53,5 +53,5 @@
  *
  */
-typedef struct
+typedef struct psSphere
 {
     double r;                   ///< RA
Index: /trunk/psLib/src/astronomy/psTime.c
===================================================================
--- /trunk/psLib/src/astronomy/psTime.c	(revision 2047)
+++ /trunk/psLib/src/astronomy/psTime.c	(revision 2048)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-09 00:17:14 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -27,6 +27,15 @@
 #include "psAbort.h"
 #include "psImage.h"
+#include "psCoord.h"
 
 #include "psAstronomyErrors.h"
+
+#ifndef SER7_FILE
+#define SER7_FILE "../../data/ser7.dat"
+#endif
+
+#ifndef TAIUTC_FILE
+#define TAIUTC_FILE "../../data/tai-utc.dat"
+#endif
 
 /** Sidereal angular conversion from seconds to radians for GMST in seconds (i.e. pi/(180*240)) */
@@ -61,22 +70,88 @@
 
                 /** 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;                                                                                           \
+                #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;                                                                                              \
+                #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;
 
-
-psImage* readTaiUtcFile(char *fileName)
+/** 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 SER7 data file.
+ *
+ *  Reads SER7 data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+static psImage* readSer7File(
+    const char *fileName                      ///< Name of file to read.
+);
+
+
+/** Read finals data file.
+ *
+ *  Reads finals data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+/* not yet used
+static psImage* readFinalsFile(
+    char *fileName                      ///< Name of file to read.
+);
+*/
+
+/** Read EOPC data file.
+ *
+ *  Reads EOPC data file.
+ *
+ *  @return  psImage*: Two-dimensional array with table data.
+ */
+/* not yet used
+static psImage* readEopcFile(
+    char *fileName                      ///< Name of file to read.
+);
+*/
+
+/** Lookup and interpolate TAI-UTC data
+ *
+ *  Interpolates TAI-UTC data, given time in MJD format.
+ *
+ *  @return  double: Interpolated value.
+ */
+static double lookupTaiUtcTable(
+    const psTime *time                        ///< time to lookup.
+);
+
+/** Lookup and interpolate polar or UT1-UTC data
+ *
+ *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
+ *
+ *  @return  double: Interpolated value.
+ */
+static double lookupSer7Table(
+    const psTime *time,                        ///< time to lookup.
+    int col                              ///< Column to lookup.
+);
+
+static psImage* readTaiUtcFile(const char *fileName)
 {
     char line[LINESIZE];
@@ -113,8 +188,12 @@
     *(unsigned int *)&table->numRows = j;
 
+    p_psMemSetPersistent(table,true);
+    p_psMemSetPersistent(table->data.V,true);
+    p_psMemSetPersistent(table->rawDataBuffer,true);
+
     return table;
 }
 
-psImage* readSer7File(char *fileName)
+static psImage* readSer7File(const char *fileName)
 {
     bool beginRecord = false;
@@ -160,8 +239,13 @@
     *(unsigned int *)&table->numRows = j;
 
+    p_psMemSetPersistent(table,true);
+    p_psMemSetPersistent(table->data.V,true);
+    p_psMemSetPersistent(table->rawDataBuffer,true);
+
     return table;
 }
 
-psImage* readEopcFile(char *fileName)
+/* Not yet used...
+static psImage* readEopcFile(char *fileName)
 {
     char line[LINESIZE];
@@ -171,6 +255,6 @@
     psImage *table = NULL;
     FILE *fd = NULL;
-
-
+ 
+ 
     fd=fopen(fileName, "r");
     if(fd==NULL) {
@@ -178,5 +262,5 @@
         return NULL ;
     }
-
+ 
     // Table shouldn't be larger than 2500 rows. All columns are read.
     table  = psImageAlloc(11, maxLines, PS_TYPE_F64);
@@ -186,5 +270,5 @@
         }
     }
-
+ 
     while(fgets(line, LINESIZE, fd) != NULL) {
         if(j>=maxLines) {
@@ -197,11 +281,11 @@
                ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);
     }
-
+ 
     *(unsigned int *)&table->numRows = j;
-
+ 
     return table;
 }
-
-psImage* readFinalsFile(char *fileName)
+ 
+static psImage* readFinalsFile(char *fileName)
 {
     char line[LINESIZE];
@@ -210,6 +294,6 @@
     psImage *table = NULL;
     FILE *fd = NULL;
-
-
+ 
+ 
     fd=fopen(fileName, "r");
     if(fd==NULL) {
@@ -217,5 +301,5 @@
         return NULL ;
     }
-
+ 
     // Table shouldn't be larger than 15000 rows. Select columns are read.
     table  = psImageAlloc(6, maxLines, PS_TYPE_F64);
@@ -226,8 +310,8 @@
             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
@@ -236,5 +320,5 @@
             *ptr = atof(line+7);
         }
-
+ 
         if(*(line+18) == ' ') {                  // Polar motion X
             *(ptr+1) = 0.0;
@@ -242,5 +326,5 @@
             *(ptr+1) = atof(line+18);
         }
-
+ 
         if(*(line+27) == ' ') {                  // Polar motion X error
             *(ptr+2) = 0.0;
@@ -248,5 +332,5 @@
             *(ptr+2) = atof(line+27);
         }
-
+ 
         if(*(line+37) == ' ') {                  // Polar motion Y
             *(ptr+3) = 0.0;
@@ -254,5 +338,5 @@
             *(ptr+3) = atof(line+37);
         }
-
+ 
         if(*(line+46) == ' ') {                  // Polar motion Y error
             *(ptr+4) = 0.0;
@@ -260,5 +344,5 @@
             *(ptr+4) = atof(line+46);
         }
-
+ 
         if(*(line+58) == ' ') {                  // UT1-UTC
             *(ptr+5) = 0.0;
@@ -267,12 +351,12 @@
         }
     }
-
+ 
     *(unsigned int *)&table->numRows = j;
-
+ 
     return table;
 }
-
-
-double lookupTaiUtcTable(psImage *table, psTime *time)
+*/
+
+static double lookupTaiUtcTable(const psTime *time)
 {
     int hiIdx = 0;
@@ -286,5 +370,12 @@
     double const2 = 0.0;
     double const3 = 0.0;
-
+    static psImage* table = NULL;
+
+    if (table == NULL) {
+        table = readTaiUtcFile(TAIUTC_FILE);
+        if (table == NULL) {
+            psAbort(__func__,"Failed to read tai-utc.dat file");
+        }
+    }
 
     // Number of rows is the number of rows of data read from the data file
@@ -337,5 +428,5 @@
 }
 
-double lookupSer7Table(psImage *table, psTime *time, int col)
+static double lookupSer7Table(const psTime *time, int col)
 {
     int hiIdx = 0;
@@ -345,5 +436,12 @@
     double denom = 0.0;
     double mjdUtc = 0.0;
-
+    static psImage* table = NULL;
+
+    if (table == NULL) {
+        table = readSer7File(SER7_FILE);
+        if (table == NULL) {
+            psAbort(__func__,"Failed to read the ser7.dat file.");
+        }
+    }
 
     // Number of rows is the number of rows of data read from the data file
@@ -404,5 +502,5 @@
     // Add most leapseconds to UTC time to get TAI time if necessary
     if(type == PS_TIME_TAI) {
-        time->sec += psGetTAIDelta(time);
+        time->sec += psTimeGetTAIDelta(time);
     }
 
@@ -420,5 +518,5 @@
     }
 
-    delta = psGetTAIDelta(time);
+    delta = psTimeGetTAIDelta(time);
 
     if(type == PS_TIME_UTC) {
@@ -461,5 +559,5 @@
         taiTime = psMemIncrRefCounter(time);
         ALLOC_TIME(utcTime);
-        utcTime->sec = taiTime->sec - psGetTAIDelta(time);
+        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
         utcTime->usec = taiTime->usec;
         utcTime->type = PS_TIME_UTC;
@@ -467,5 +565,5 @@
         utcTime = psMemIncrRefCounter(time);
         ALLOC_TIME(taiTime);
-        taiTime->sec = utcTime->sec + psGetTAIDelta(time);
+        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
         taiTime->usec = utcTime->usec;
         taiTime->type = PS_TIME_TAI;
@@ -475,5 +573,5 @@
     ALLOC_TIME(ut1UtcDelta);
     ut1UtcDelta->type = PS_TIME_UTC;
-    ut1UtcDelta->usec = psGetUT1Delta(utcTime)*1e6;
+    ut1UtcDelta->usec = psTimeGetUT1Delta(utcTime)*1e6;
     ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
 
@@ -516,42 +614,30 @@
 }
 
-double psGetUT1Delta(psTime *time)
-{
-    static psImage* iersTable = NULL;
-    double ut1UtcDeltaUsec = 0.0;
-
-
-    if (iersTable == NULL) {
-        iersTable = readSer7File("../../data/ser7.dat");
-        p_psMemSetPersistent(iersTable,true);
-        p_psMemSetPersistent(iersTable->data.V,true);
-        p_psMemSetPersistent(iersTable->rawDataBuffer,true);
-    }
-
-    ut1UtcDeltaUsec = lookupSer7Table(iersTable, time, 6)*1.0e6;
-
-    return ut1UtcDeltaUsec;
-}
-
-double psGetTAIDelta(psTime *time)
-{
-    double delta = 0.0;
-    static psImage* taiUtcTable = NULL;
-
-
-    if (taiUtcTable == NULL) {
-        taiUtcTable = readTaiUtcFile("../../data/tai-utc.dat");
-        p_psMemSetPersistent(taiUtcTable,true);
-        p_psMemSetPersistent(taiUtcTable->data.V,true);
-        p_psMemSetPersistent(taiUtcTable->rawDataBuffer,true);
-    }
-    delta = lookupTaiUtcTable(taiUtcTable, time);
-
-    return delta;
-}
-
-psF64 psTimeLeapseconds(const psTime *time1, const psTime *time2)
-{
-    psF64 diff = 0.0;
+double psTimeGetUT1Delta(const psTime *time)
+{
+    return lookupSer7Table(time, 6);
+}
+
+struct psSphere* psTimeGetPoleCoords(const psTime* time)
+{
+
+    double x = lookupSer7Table((psTime*)time, 4);
+    double y = lookupSer7Table((psTime*)time, 5);
+
+    struct psSphere* 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;
+
+    return output;
+}
+
+double psTimeGetTAIDelta(const psTime *time)
+{
+    return lookupTaiUtcTable(time);
+}
+
+long psTimeLeapseconds(const psTime *time1, const psTime *time2)
+{
+    long diff = 0;
 
     // NULL error checks
@@ -559,10 +645,10 @@
     CHECK_NULL_TIME(time2,0);
 
-    diff = fabs(psGetTAIDelta((psTime*)time1)-psGetTAIDelta((psTime*)time2));
+    diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
 
     return diff;
 }
 
-double psTimeToJD(psTime *time)
+double psTimeToJD(const psTime *time)
 {
     double jd = 0.0;
@@ -582,5 +668,5 @@
 }
 
-double psTimeToMJD(psTime *time)
+double psTimeToMJD(const psTime *time)
 {
     double mjd = 0.0;
@@ -600,5 +686,5 @@
 }
 
-char* psTimeToISO(psTime *time)
+char* psTimeToISOTime(const psTime *time)
 {
     int ms = 0;
@@ -634,5 +720,5 @@
 }
 
-struct timeval psTimeToTimeval(psTime *time)
+struct timeval psTimeToTimeval(const psTime *time)
 {
     struct timeval timevalTime;
@@ -648,5 +734,5 @@
 }
 
-struct tm* psTimeToTM(psTime *time)
+struct tm* psTimeToTM(const psTime *time)
 {
     long cent = 0;
@@ -711,5 +797,5 @@
 }
 
-psTime* psJDToTime(double time)
+psTime* psTimeFromJD(double time)
 {
     double days = 0.0;
@@ -734,5 +820,5 @@
 }
 
-psTime* psMJDToTime(double time)
+psTime* psTimeFromMJD(double time)
 {
     double days = 0.0;
@@ -757,5 +843,5 @@
 }
 
-psTime* psISOToTime(char *time)
+psTime* psTimeFromISOTime(const char *time)
 {
     char tempString[MAX_TIME_STRING_LENGTH];
@@ -826,5 +912,5 @@
 
     // Convert tm time to psTime
-    outTime = psTMToTime(&tmTime);
+    outTime = psTimeFromTM(&tmTime);
     outTime->usec = millisecond * 1000;
 
@@ -832,5 +918,5 @@
 }
 
-psTime* psTimevalToTime(struct timeval *time)
+psTime* psTimeFromTimeval(const struct timeval *time)
 {
     psTime *outTime = NULL;
@@ -850,5 +936,5 @@
 }
 
-psTime* psTMToTime(struct tm* time)
+psTime* psTimeFromTM(const struct tm* time)
 {
     long year;
@@ -905,5 +991,5 @@
 }
 
-psTime* psTimeAdd(psTime *tai1, psTime *tai2)
+psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
@@ -929,5 +1015,5 @@
 }
 
-psTime* psTimeSub(psTime *tai1, psTime *tai2)
+psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
@@ -953,5 +1039,5 @@
 }
 
-psTime* psTimeDelta(psTime *tai1, psTime *tai2)
+psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
 {
     psTime *outTime = NULL;
Index: /trunk/psLib/src/astronomy/psTime.h
===================================================================
--- /trunk/psLib/src/astronomy/psTime.h	(revision 2047)
+++ /trunk/psLib/src/astronomy/psTime.h	(revision 2048)
@@ -54,6 +54,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-11 00:55:13 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -69,4 +69,6 @@
 #include "psType.h"
 #include "psImage.h"
+
+struct psSphere;
 
 /// @addtogroup Time
@@ -138,6 +140,6 @@
  *  @return  double: Time difference.
  */
-double psGetUT1Delta(
-    psTime *time                        ///< psTime to be looked up.
+double psTimeGetUT1Delta(
+    const psTime *time                  ///< psTime to be looked up.
 );
 
@@ -148,6 +150,6 @@
  *  @return  double: Time difference.
  */
-double psGetTAIDelta(
-    psTime *time                        ///< psTime to be looked up.
+double psTimeGetTAIDelta(
+    const psTime *time                  ///< psTime to be looked up.
 );
 
@@ -158,7 +160,7 @@
  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
  */
-/*psSphere* psGetPoleCoords(
-    psTime *time                        ///< psTime determine polar orientation.
-);*/
+struct psSphere* psTimeGetPoleCoords(
+                const psTime *time                  ///< psTime determine polar orientation.
+            );
 
 /** Calculate the number of leapseconds between two times.
@@ -166,9 +168,9 @@
  *  Calculates the number of leapseconds between two times.
  *
- *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
- */
-psF64 psTimeLeapseconds(
-    const psTime *time1,                ///< First input time.
-    const psTime *time2                 ///< Second input time.
+ *  @return  long: leapseconds added between given times
+ */
+long psTimeLeapseconds(
+    const psTime* time1,                ///< First input time.
+    const psTime* time2                 ///< Second input time.
 );
 
@@ -180,5 +182,5 @@
  */
 double psTimeToJD(
-    psTime *time                        ///< Input time to be converted.
+    const psTime* time                  ///< Input time to be converted.
 );
 /** Convert psTime to modified Julian date time.
@@ -189,5 +191,5 @@
  */
 double psTimeToMJD(
-    psTime *time                        ///< Input time to be converted.
+    const psTime* time                  ///< Input time to be converted.
 );
 
@@ -199,6 +201,6 @@
  *  @return  char*: Pointer null terminated array of chars in ISO time.
  */
-char* psTimeToISO(
-    psTime *time                        ///< Input time to be converted.
+char* psTimeToISOTime(
+    const psTime* time                  ///< Input time to be converted.
 );
 
@@ -210,5 +212,5 @@
  */
 struct timeval psTimeToTimeval(
-                psTime *time                        ///< Input time to be converted.
+                const psTime* time                  ///< Input time to be converted.
             );
 
@@ -221,5 +223,5 @@
  */
 struct tm* psTimeToTM(
-                psTime *time                        ///< Input time to be converted.
+                const psTime *time                  ///< Input time to be converted.
             );
 
@@ -230,5 +232,5 @@
  *  @return  psTime: time.
  */
-psTime* psJDToTime(
+psTime* psTimeFromJD(
     double time                         ///< Input time to be converted.
 );
@@ -240,5 +242,5 @@
  *  @return  psTime: time.
  */
-psTime* psMJDToTime(
+psTime* psTimeFromMJD(
     double time                         ///< Input time to be converted.
 );
@@ -250,6 +252,6 @@
  *  @return  psTime*: time
  */
-psTime* psISOToTime(
-    char *time                          ///< Input time to be converted.
+psTime* psTimeFromISOTime(
+    const char* time                    ///< Input time to be converted.
 );
 
@@ -260,6 +262,6 @@
  *  @return  psTime*: time.
  */
-psTime* psTimevalToTime(
-    struct timeval *time                ///< Input time to be converted.
+psTime* psTimeFromTimeval(
+    const struct timeval *time          ///< Input time to be converted.
 );
 
@@ -271,6 +273,6 @@
  *  @return  psTime*: time.
  */
-psTime* psTMToTime(
-    struct tm *time                     ///< Input time to be converted.
+psTime* psTimeFromTM(
+    const struct tm *time               ///< Input time to be converted.
 );
 
@@ -282,6 +284,6 @@
  */
 psTime* psTimeAdd(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
 );
 
@@ -292,7 +294,7 @@
  *  @return  psTime*: time.
  */
-psTime* psTimeSub(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
+psTime* psTimeSubtract(
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
 );
 
@@ -305,72 +307,8 @@
  */
 psTime* psTimeDelta(
-    psTime *tai1,                       ///< First TAI time.
-    psTime *tai2                        ///< Second TAI time.
-);
-
-
-/** Read TAI/UTC data file.
- *
- *  Reads TAI/UTC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readTaiUtcFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-
-/** Read SER7 data file.
- *
- *  Reads SER7 data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readSer7File(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Read finals data file.
- *
- *  Reads finals data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readFinalsFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Read EOPC data file.
- *
- *  Reads EOPC data file.
- *
- *  @return  psImage*: Two-dimensional array with table data.
- */
-psImage* readEopcFile(
-    char *fileName                      ///< Name of file to read.
-);
-
-/** Lookup and interpolate TAI-UTC data
- *
- *  Interpolates TAI-UTC data, given time in MJD format.
- *
- *  @return  double: Interpolated value.
- */
-double lookupTaiUtcTable(
-    psImage *table,                     ///< Table with data.
-    psTime *time                        ///< time to lookup.
-);
-
-/** Lookup and interpolate polar or UT1-UTC data
- *
- *  Interpolates TAI-UT1 or polar coordinate data, given time in MJD format.
- *
- *  @return  double: Interpolated value.
- */
-double lookupSer7Table(
-    psImage *table,                      ///< Table with data.
-    psTime *time,                        ///< time to lookup.
-    int col                              ///< Column to lookup.
-);
+    const psTime *tai1,                 ///< First TAI time.
+    const psTime *tai2                  ///< Second TAI time.
+);
+
 /// @}
 
Index: /trunk/psLib/test/astronomy/tst_psAstrometry.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2047)
+++ /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2048)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-07 19:51:30 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -19,8 +19,11 @@
 static int testExposureAlloc(void);
 static int testObservatoryAlloc(void);
+static int testFPAAlloc(void);
+// static int testGrommitAlloc(void);
 
 testDescription tests[] = {
                               {testExposureAlloc,735,"psExposureAlloc",0,false},
                               {testObservatoryAlloc,736,"psObservatoryAlloc",0,false},
+                              {testFPAAlloc,739,"psFPAAlloc",0,false},
                               {NULL}
                           };
@@ -119,12 +122,12 @@
     char* name = "The Kaiser Royal Observatory";
     psObservatory* obs = psObservatoryAlloc(name,
-                                            20.7, 156.3, 3055.0, 9.0);
-
-    if (fabs(obs->latitude - 20.7) > DBL_EPSILON) {
+                                            20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 9.0);
+
+    if (fabs(obs->latitude - 20.7*M_PI/180.0) > DBL_EPSILON) {
         psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set latitude.");
         return 1;
     }
 
-    if (fabs(obs->longitude - 156.3) > DBL_EPSILON) {
+    if (fabs(obs->longitude - 156.3*M_PI/180.0) > DBL_EPSILON) {
         psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set longitude.");
         return 2;
@@ -152,5 +155,5 @@
 
     psObservatory* obs2 = psObservatoryAlloc(NULL,
-                          20.7, 156.3, 3055.0, 9.0);
+                          20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 9.0);
 
     if (obs2->name != NULL) {
@@ -164,2 +167,157 @@
     return 0;
 }
+
+static int testFPAAlloc(void)
+{
+
+    psTime* now = psTimeGetTime(PS_TIME_UTC);
+    char* name = "The Kaiser Royal Observatory";
+
+    psObservatory* obs = psObservatoryAlloc(name,
+                                            20.7*M_PI/180.0, 156.3*M_PI/180.0, 3055.0, 0.0065f);
+
+    psExposure* exp = psExposureAlloc(1.0, 2.0, 3.0, 4.0, 5.0,
+                                      now, 6.0f, 260.0f, 1013.0f, 0.7f, 10.0f, 0.650f, obs);
+
+    /*
+        1. Call psFPAAlloc with nChips > 0 and a non-NULL psExposure.
+        a) Verify that the psExposure reference is: 1. is set in struct as
+        exposure; 2. its reference count is incremented.
+        b) Verify that the chip attribute is of the size specified by the
+        parameter nChips and that the chips array elements are all NULL.
+        c) verify that all other references in the struct is NULL.
+    */
+
+    psFPA* fpa = psFPAAlloc(8, exp);
+
+    if (fpa == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc returned a NULL.");
+        return 1;
+    }
+
+    if (fpa->exposure != exp) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set the exposure.");
+        return 2;
+    }
+
+    if (psMemGetRefCounter(exp) != 2) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not increment reference counter for exposure.");
+        return 3;
+    }
+
+    if (fpa->chips->n != 8) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set the number of chips properly.");
+        return 4;
+    }
+
+    for (int lcv=0; lcv < 8; lcv++) {
+        if (fpa->chips->data[lcv] != NULL) {
+            psLogMsg(__func__,PS_LOG_ERROR,
+                     "psFPAAlloc did not set chip %d to NULL.", lcv);
+            return 5;
+        }
+    }
+
+    if (fpa->metadata != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set metadata to NULL.");
+        return 6;
+    }
+
+    if (fpa->fromTangentPlane != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set fromTangentPlane to NULL.");
+        return 7;
+    }
+
+    if (fpa->toTangentPlane != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set toTangentPlane to NULL.");
+        return 8;
+    }
+
+    if (fpa->pattern != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set pattern to NULL.");
+        return 9;
+    }
+
+    if (fpa->grommit == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set grommit using given exposure.");
+        return 10;
+    }
+
+    if (fpa->colorPlus != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set colorPlus to NULL.");
+        return 11;
+    }
+
+    if (fpa->colorMinus != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set colorMinus to NULL.");
+        return 12;
+    }
+
+    if (fpa->projection != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set projection to NULL.");
+        return 13;
+    }
+
+    /*
+        2. Call psFPAAlloc with nChips = 0. Verify that the chips array is 
+           zero in size and the program execution does not stop.
+    */
+
+    psFPA* fpa2 = psFPAAlloc(0,exp);
+
+    if (fpa2->chips->n != 0) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set the number of chips properly.");
+        return 14;
+    }
+
+    /*
+        3. Call psFPAAlloc with a NULL psExposure. Verify that the program 
+           execution doe not stop and the exposure attribute is NULL.
+    */
+
+    psFPA* fpa3 = psFPAAlloc(4,NULL);
+    if (fpa3->exposure != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "psFPAAlloc did not set the exposure to NULL given NULL parameter.");
+        return 15;
+    }
+
+    /*
+        4. Call psFPAAlloc and set all references in the struct to a memory 
+           buffer. Verify that psFree cleans up all the buffers referenced in 
+           the struct, i.e., there is no memory leaks generated.
+    */
+
+    for (int lcv=0; lcv < 8; lcv++) {
+        fpa->chips->data[lcv] = psAlloc(4);
+    }
+
+    fpa->metadata = psAlloc(4);
+    fpa->fromTangentPlane = psAlloc(4);
+    fpa->toTangentPlane = psAlloc(4);
+    fpa->pattern = psAlloc(4);
+    fpa->colorPlus  = psAlloc(4);
+    fpa->colorMinus  = psAlloc(4);
+    fpa->projection  = psAlloc(4);
+
+    psFree(fpa3);
+    psFree(fpa2);
+    psFree(fpa);
+    psFree(exp);
+    psFree(obs);
+
+    return 0;
+}
Index: /trunk/psLib/test/astronomy/tst_psTime_01.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psTime_01.c	(revision 2047)
+++ /trunk/psLib/test/astronomy/tst_psTime_01.c	(revision 2048)
@@ -23,6 +23,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.11 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-10-08 23:30:47 $
+ *  @version $Revision: 1.12 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -62,5 +62,5 @@
     printPositiveTestHeader(stdout,"psTime", "Convert psTime to ISO time");
     char *isoString;
-    isoString = psTimeToISO(testTime);
+    isoString = psTimeToISOTime(testTime);
     printf("%s\n", isoString);
     if(strncmp(isoString, testString, 256)) {
@@ -74,5 +74,5 @@
     printPositiveTestHeader(stdout,"psTime", "Convert ISO time to psTime");
     psTime *timeD = NULL;
-    timeD = psISOToTime(isoString);
+    timeD = psTimeFromISOTime(isoString);
     printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeD->sec, (psU32)timeD->usec);
     psFree(isoString);
@@ -118,5 +118,5 @@
     printPositiveTestHeader(stdout,"psTime", "Convert MJD time to psTime");
     psTime *timeH = NULL;
-    timeH = psMJDToTime(mjdTime);
+    timeH = psTimeFromMJD(mjdTime);
     printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeH->sec, (psU32)timeH->usec);
     psFree(timeH);
@@ -135,5 +135,5 @@
     printPositiveTestHeader(stdout,"psTime", "Convert JD time to psTime");
     psTime *timeJ = NULL;
-    timeJ = psJDToTime(jdTime);
+    timeJ = psTimeFromJD(jdTime);
     printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeJ->sec, (psU32)timeJ->usec);
     psFree(timeJ);
@@ -152,5 +152,5 @@
     printPositiveTestHeader(stdout,"psTime", "Convert timeval time to psTime");
     psTime *timeL = NULL;
-    timeL = psTimevalToTime(&timevalTime);
+    timeL = psTimeFromTimeval(&timevalTime);
     printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeL->sec, (psU32)timeL->usec);
     psFree(timeL);
@@ -175,5 +175,5 @@
     printPositiveTestHeader(stdout, "psTime", "Convert tm time to psTime");
     psTime *timeN = NULL;
-    timeN = psTMToTime(tmTime);
+    timeN = psTimeFromTM(tmTime);
     printf("psTime: Seconds = %ld Microseconds = %d\n", (long)timeN->sec, (psU32)timeN->usec);
     psFree(timeN);
@@ -186,5 +186,5 @@
     char *testString2 = "2004-09-10T1:00:00.00Z";
     psTime* testTime2 = NULL;
-    testTime2 = psISOToTime(testString2);
+    testTime2 = psTimeFromISOTime(testString2);
     double dblTime = psTimeToLST(testTime2, 1);
     printf("LST (rad): %lf\n", dblTime);
Index: /trunk/psLib/test/astronomy/tst_psTime_02.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psTime_02.c	(revision 2047)
+++ /trunk/psLib/test/astronomy/tst_psTime_02.c	(revision 2048)
@@ -9,6 +9,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-10-08 22:58:47 $
+ *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-10-12 01:34:09 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,10 +24,10 @@
     // Test A - Incorrect ISO time data
     printNegativeTestHeader(stdout,"psTime", "Incorrect ISO time data", "Time not allowed", 0);
-    psISOToTime("2004-99-21T18:22:24.272Z");
-    psISOToTime("2004-07-99T18:22:24.272Z");
-    psISOToTime("2004-07-21T99:22:24.272Z");
-    psISOToTime("2004-07-21T18:99:24.272Z");
-    psISOToTime("2004-07-21T18:22:99.272Z");
-    psISOToTime("2004-07-21T18:22:24.-999Z");
+    psTimeFromISOTime("2004-99-21T18:22:24.272Z");
+    psTimeFromISOTime("2004-07-99T18:22:24.272Z");
+    psTimeFromISOTime("2004-07-21T99:22:24.272Z");
+    psTimeFromISOTime("2004-07-21T18:99:24.272Z");
+    psTimeFromISOTime("2004-07-21T18:22:99.272Z");
+    psTimeFromISOTime("2004-07-21T18:22:24.-999Z");
     printFooter(stdout, "psTime", "Incorrect ISO time data", true);
 
@@ -36,5 +36,5 @@
     printNegativeTestHeader(stdout,"psTime", "Attempt to use null timeval",
                             "Null value for timeval arg not allowed", 0);
-    psTimevalToTime(NULL);
+    psTimeFromTimeval(NULL);
     printFooter(stdout, "psTime", "Attempt to use null timeval", true);
 
