Index: /trunk/psLib/psTableParse.c
===================================================================
--- /trunk/psLib/psTableParse.c	(revision 5968)
+++ /trunk/psLib/psTableParse.c	(revision 5969)
@@ -1,5 +1,5 @@
 /** @file  psTableParse.c
  *
- *  @brief Parses input data tables and outputs .dat files for specified format
+ *  @brief Parses input data tables (finals2000A.data) and outputs files for specified format
  *
  *  @ingroup psTableParse
@@ -7,6 +7,6 @@
  *  @author Dave Robbins, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-04 22:59:31 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-12 20:40:12 $
  *
  *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
@@ -19,4 +19,9 @@
 #include <math.h>
 
+static FILE *output = NULL;
+static FILE *input = NULL;
+
+static void printHeader(char *filename);
+
 int main(int argc, char *argv[])
 {
@@ -26,58 +31,215 @@
     }
     if (!strncmp(argv[1], "-h", 2) ) {
-        printf("\n Usage:  psTableParse inputTable.data outputTable.dat columnNumbers.\n");
+        printf("\n Usage:  psTableParse inputTable.data outputTable.dat <Sections>.\n");
         printf(" i.e.    psTableParse finals.data finals.dat 1 3 4 8\n");
+        printf("\n Sections:\n 1)MJD Date       2)X (Bull A)     3)Y (Bull A)");
+        printf("\n 4)X (Bull B)     5)Y (Bull B)     6)dX (Bull A)");
+        printf("\n 7)dY (Bull A)    8)dX (Bull B)    9)dY (Bull B)");
+        printf("\n 10)UT1-UTC (Bull A)      11)UT1-UTC (Bull B)\n");
         return 0;
     }
-
-    FILE *output;
-    FILE *input;
     input = fopen(argv[1], "r");
     output = fopen(argv[2], "w");
-    //    char data;
     char data2[200];
+    printHeader(argv[1]);
+    fprintf(output, "#  ");
+    for (int i = 3; i < argc; i++) {
+        if(!strncmp(argv[i], "1", 2)) {
+            fprintf(output, "MJD       ");
+        }
+        if(!strncmp(argv[i], "2", 2)) {
+            fprintf(output, " X (A)     ");
+        }
+        if(!strncmp(argv[i], "3", 2)) {
+            fprintf(output, " Y (A)     ");
+        }
+        if(!strncmp(argv[i], "4", 2)) {
+            fprintf(output, " X (B)     ");
+        }
+        if(!strncmp(argv[i], "5", 2)) {
+            fprintf(output, "  Y (B)     ");
+        }
+        if(!strncmp(argv[i], "6", 2)) {
+            fprintf(output, " dX (A)     ");
+        }
+        if(!strncmp(argv[i], "7", 2)) {
+            fprintf(output, " dY (A)     ");
+        }
+        if(!strncmp(argv[i], "8", 2)) {
+            fprintf(output, " dX (B)     ");
+        }
+        if(!strncmp(argv[i], "9", 2)) {
+            fprintf(output, " dY (B)     ");
+        }
+        if(!strncmp(argv[i], "10", 2)) {
+            fprintf(output, "UT1-UTC (A)  ");
+        }
+        if(!strncmp(argv[i], "11", 2)) {
+            fprintf(output, "UT1-UTC (B)  ");
+        }
+    }
+    fprintf(output, "\n#\n#\n");
     int i;
     while ( fscanf(input, "%188c", data2) != EOF) {
-        for (i = 7; i <= 14; i++) {
-            fprintf(output, "%c", data2[i]);
-        }
-        fprintf(output, "  ");
-        for (i = 97; i <= 105; i++) {
-            if (data2[102] == ' ') {
-                fprintf(output, "    0.000 ");
-                i = 106;
-            } else {
-                fprintf(output, "%c", data2[i]);
-            }
-        }
-        fprintf(output, "  ");
-        for (i = 116; i <= 124; i++) {
-            if (data2[121] == ' ') {
-                fprintf(output, "   0.000");
-                i = 125;
-            } else {
-                fprintf(output, "%c", data2[i]);
-            }
-        }
-        fprintf(output, "  ");
-        for (i = 165; i <= 174; i++) {
-            if (data2[170] == ' ') {
-                fprintf(output, "     0.000 ");
-                i = 175;
-            } else {
-                fprintf(output, "%c", data2[i]);
-            }
-        }
-        fprintf(output, "  ");
-        for (i = 175; i <= 184; i++) {
-            if (data2[180] == ' ') {
-                fprintf(output, "    0.000 ");
-                i = 185;
-            } else {
-                fprintf(output, "%c", data2[i]);
-            }
-        }
-
-
+
+        for(int j = 3; j < argc; j++) {
+            if(!strncmp(argv[j], "1", 2) ) {
+                for (i = 7; i <= 14; i++) {
+                    fprintf(output, "%c", data2[i]);
+                }
+            }
+            if(!strncmp(argv[j], "2", 2) ) {
+                if (data2[23] == ' ') {
+                    fprintf(output, "   0.000 ");
+                } else {
+                    for (i = 18; i <= 26; i++) {
+                        if (i == 18 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 21;
+                        }
+                        if (i == 19) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "3", 2) ) {
+                if (data2[42] == ' ') {
+                    fprintf(output, "   0.000 ");
+                } else {
+                    for (i = 37; i <= 45; i++) {
+                        if (i == 37 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 40;
+                        }
+                        if (i == 38) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "4", 2) ) {
+                if (data2[139] == ' ') {
+                    fprintf(output, "    0.000 ");
+                    //                    i = 144;
+                } else {
+                    for (i = 134; i <= 143; i++) {
+                        if (i == 135 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 138;
+                        }
+                        if (i == 136) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "5", 2) ) {
+                if (data2[149] == ' ') {
+                    fprintf(output, "    0.000 ");
+                } else {
+                    for (i = 144; i <= 153; i++) {
+                        if (i == 145 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 148;
+                        }
+                        if (i == 146) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "6", 2) ) {
+                if (data2[102] == ' ') {
+                    fprintf(output, "   0.000 ");
+                } else {
+                    for (i = 97; i <= 105; i++) {
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "7", 2) ) {
+                if (data2[121] == ' ') {
+                    fprintf(output, "   0.000 ");
+                } else {
+                    for (i = 116; i <= 124; i++) {
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "8", 2) ) {
+                if (data2[170] == ' ') {
+                    fprintf(output, "    0.000 ");
+                } else {
+                    for (i = 165; i <= 174; i++) {
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "9", 2) ) {
+                if (data2[180] == ' ') {
+                    fprintf(output, "    0.000 ");
+                } else {
+                    for (i = 175; i <= 184; i++) {
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "10", 2) ) {
+                if (data2[63] == ' ') {
+                    fprintf(output, "    0.000 ");
+                } else {
+                    for (i = 58; i <= 67; i++) {
+                        if (i == 58 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 61;
+                        }
+                        if (i == 59) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            if(!strncmp(argv[j], "11", 2) ) {
+                if (data2[159] == ' ') {
+                    fprintf(output, "     0.000 ");
+                } else {
+                    for (i = 154; i <= 164; i++) {
+                        if (i == 155 && data2[i+1] == '-' && data2[i+2] == '.') {
+                            fprintf(output, "-0.");
+                            i = 158;
+                        }
+                        if (i == 156) {
+                            if (data2[i] == ' ' && data2[i+1] == '.') {
+                                fprintf(output, "0");
+                                i++;
+                            }
+                        }
+                        fprintf(output, "%c", data2[i]);
+                    }
+                }
+            }
+            fprintf(output, "  ");
+        }
         fprintf(output, "\n");
     }
@@ -88,2 +250,11 @@
 }
 
+void printHeader(char *filename)
+{
+    if (output == NULL) {
+        printf("\n Unable to access output file.  Output is NULL.\n");
+    } else {
+        fprintf(output, "#\n#  Stripped version of %s file\n#\n#\n", filename);
+    }
+}
+
Index: /trunk/psLib/share/pslib/iers_corr.dat
===================================================================
--- /trunk/psLib/share/pslib/iers_corr.dat	(revision 5968)
+++ /trunk/psLib/share/pslib/iers_corr.dat	(revision 5969)
@@ -359,5 +359,5 @@
 42035.00    42.35   1.793   0.000   0.000
 42036.00    42.178  1.784   0.000   0.000
-42037.00    42  1.749   0.000   0.000
+42037.00    42.000  1.749   0.000   0.000
 42038.00    41.879  1.69    0.000   0.000
 42039.00    41.897  1.591   0.000   0.000
@@ -389,5 +389,5 @@
 42065.00    42.372  1.61    0.000   0.000
 42066.00    42.14   1.53    0.000   0.000
-42067.00    42  1.434   0.000   0.000
+42067.00    42.000  1.434   0.000   0.000
 42068.00    42.095  1.347   0.000   0.000
 42069.00    42.37   1.385   0.000   0.000
@@ -409,5 +409,5 @@
 42085.00    42.366  1.122   0.000   0.000
 42086.00    42.585  1.301   0.000   0.000
-42087.00    42.752  1.3 0.000   0.000
+42087.00    42.752  1.300   0.000   0.000
 42088.00    42.759  1.237   0.000   0.000
 42089.00    42.532  1.215   0.000   0.000
@@ -566,5 +566,5 @@
 42242.00    37.181  -2.28   0.000   0.000
 42243.00    36.551  -2.161  0.000   0.000
-42244.00    36.355  -2  0.000   0.000
+42244.00    36.355  -2.000  0.000   0.000
 42245.00    36.571  -2.015  0.000   0.000
 42246.00    36.975  -2.212  0.000   0.000
@@ -631,5 +631,5 @@
 42307.00    32.054  -1.762  0.000   0.000
 42308.00    32.171  -1.814  0.000   0.000
-42309.00    32  -1.735  0.000   0.000
+42309.00    32.000  -1.735  0.000   0.000
 42310.00    31.682  -1.606  0.000   0.000
 42311.00    31.644  -1.598  0.000   0.000
@@ -723,5 +723,5 @@
 42399.00    40.025  1.194   0.000   0.000
 42400.00    39.984  1.121   0.000   0.000
-42401.00    39.751  1.1 0.000   0.000
+42401.00    39.751  1.100   0.000   0.000
 42402.00    39.503  1.135   0.000   0.000
 42403.00    39.346  1.128   0.000   0.000
@@ -1112,5 +1112,5 @@
 42788.00    34.767  0.353   0.000   0.000
 42789.00    34.811  0.267   0.000   0.000
-42790.00    34.794  0.3 0.000   0.000
+42790.00    34.794  0.300   0.000   0.000
 42791.00    34.754  0.377   0.000   0.000
 42792.00    34.769  0.325   0.000   0.000
@@ -1322,5 +1322,5 @@
 42998.00    22.668  -4.107  0.000   0.000
 42999.00    22.859  -3.942  0.000   0.000
-43000.00    23  -3.703  0.000   0.000
+43000.00    23.000  -3.703  0.000   0.000
 43001.00    22.955  -3.54   0.000   0.000
 43002.00    22.739  -3.523  0.000   0.000
@@ -1586,5 +1586,5 @@
 43262.00    30.823  -4.916  0.000   0.000
 43263.00    30.438  -5.08   0.000   0.000
-43264.00    30.183  -5  0.000   0.000
+43264.00    30.183  -5.000  0.000   0.000
 43265.00    30.125  -4.748  0.000   0.000
 43266.00    30.058  -4.613  0.000   0.000
@@ -2066,5 +2066,5 @@
 43742.00    9.784   -4.557  0.000   0.000
 43743.00    9.223   -4.334  0.000   0.000
-43744.00    9   -4.218  0.000   0.000
+43744.00    9.000   -4.218  0.000   0.000
 43745.00    9.183   -4.329  0.000   0.000
 43746.00    9.42    -4.554  0.000   0.000
@@ -2563,5 +2563,5 @@
 44239.00    8.94    -0.017  0.000   0.000
 44240.00    9.19    0.106   0.000   0.000
-44241.00    9.345   0.2 0.000   0.000
+44241.00    9.345   0.200   0.000   0.000
 44242.00    9.427   0.185   0.000   0.000
 44243.00    9.562   0.103   0.000   0.000
@@ -2606,5 +2606,5 @@
 44282.00    9.07    -0.245  0.000   0.000
 44283.00    8.773   -0.538  0.000   0.000
-44284.00    8.6 -0.902  0.000   0.000
+44284.00    8.600   -0.902  0.000   0.000
 44285.00    8.907   -1.017  0.000   0.000
 44286.00    9.531   -0.834  0.000   0.000
@@ -2793,8 +2793,8 @@
 44469.00    1.082   -3.255  0.000   0.000
 44470.00    0.771   -3.136  0.000   0.000
-44471.00    0.2 -3.009  0.000   0.000
+44471.00    0.200   -3.009  0.000   0.000
 44472.00    -0.191  -2.91   0.000   0.000
 44473.00    -0.189  -2.895  0.000   0.000
-44474.00    0   -3.025  0.000   0.000
+44474.00    0.000   -3.025  0.000   0.000
 44475.00    0.109   -3.242  0.000   0.000
 44476.00    0.14    -3.348  0.000   0.000
@@ -3238,5 +3238,5 @@
 44914.00    5.739   -1.652  0.000   0.000
 44915.00    6.083   -1.478  0.000   0.000
-44916.00    6.2 -1.35   0.000   0.000
+44916.00    6.200   -1.35   0.000   0.000
 44917.00    6.278   -1.16   0.000   0.000
 44918.00    6.344   -0.924  0.000   0.000
@@ -3299,5 +3299,5 @@
 44975.00    -17.752 6.005   0.000   0.000
 44976.00    -18.316 5.936   0.000   0.000
-44977.00    -18.684 5.8 0.000   0.000
+44977.00    -18.684 5.800   0.000   0.000
 44978.00    -18.614 5.759   0.000   0.000
 44979.00    -18.119 5.834   0.000   0.000
@@ -3484,5 +3484,5 @@
 45160.00    3.069   0.674   0.000   0.000
 45161.00    3.146   0.81    0.000   0.000
-45162.00    3.308   1   0.000   0.000
+45162.00    3.308   1.000   0.000   0.000
 45163.00    3.322   1.143   0.000   0.000
 45164.00    3.066   1.174   0.000   0.000
@@ -3504,5 +3504,5 @@
 45180.00    2.038   1.305   0.000   0.000
 45181.00    1.831   1.304   0.000   0.000
-45182.00    1.765   1.3 0.000   0.000
+45182.00    1.765   1.300   0.000   0.000
 45183.00    1.839   1.224   0.000   0.000
 45184.00    1.923   1.147   0.000   0.000
@@ -3531,5 +3531,5 @@
 45207.00    -0.065  0.861   0.000   0.000
 45208.00    -0.017  0.643   0.000   0.000
-45209.00    0   0.609   0.000   0.000
+45209.00    0.000   0.609   0.000   0.000
 45210.00    0.012   0.649   0.000   0.000
 45211.00    -0.004  0.607   0.000   0.000
@@ -3548,5 +3548,5 @@
 45224.00    -1.508  0.046   0.000   0.000
 45225.00    -1.266  -0.001  0.000   0.000
-45226.00    -0.933  0.1 0.000   0.000
+45226.00    -0.933  0.100   0.000   0.000
 45227.00    -0.758  0.311   0.000   0.000
 45228.00    -0.827  0.484   0.000   0.000
@@ -3691,5 +3691,5 @@
 45367.00    3.959   1.628   0.000   0.000
 45368.00    3.572   1.993   0.000   0.000
-45369.00    3.24    2.2 0.000   0.000
+45369.00    3.24    2.200   0.000   0.000
 45370.00    2.983   2.117   0.000   0.000
 45371.00    2.712   1.881   0.000   0.000
@@ -3934,5 +3934,5 @@
 45610.00    -5.303  0.157   0.000   0.000
 45611.00    -5.058  0.62    0.000   0.000
-45612.00    -5.177  0.9 0.000   0.000
+45612.00    -5.177  0.900   0.000   0.000
 45613.00    -5.331  0.866   0.000   0.000
 45614.00    -5.286  0.651   0.000   0.000
@@ -3986,5 +3986,5 @@
 45662.00    -0.136  2.751   0.000   0.000
 45663.00    0.206   2.886   0.000   0.000
-45664.00    0.5 2.984   0.000   0.000
+45664.00    0.500   2.984   0.000   0.000
 45665.00    0.717   3.07    0.000   0.000
 45666.00    0.771   3.192   0.000   0.000
@@ -4000,9 +4000,9 @@
 45676.00    0.122   3.994   0.000   0.000
 45677.00    0.432   4.171   0.000   0.000
-45678.00    0.678   4.3 0.000   0.000
+45678.00    0.678   4.300   0.000   0.000
 45679.00    0.821   4.289   0.000   0.000
 45680.00    0.948   4.206   0.000   0.000
 45681.00    1.109   4.207   0.000   0.000
-45682.00    1.2 4.376   0.000   0.000
+45682.00    1.200   4.376   0.000   0.000
 45683.00    1.11    4.663   0.000   0.000
 45684.00    0.904   4.956   0.000   0.000
@@ -4035,5 +4035,5 @@
 45711.00    2.564   4.283   0.000   0.000
 45712.00    2.823   4.147   0.000   0.000
-45713.00    3.075   4   0.000   0.000
+45713.00    3.075   4.000   0.000   0.000
 45714.00    3.274   3.828   0.000   0.000
 45715.00    3.245   3.487   0.000   0.000
@@ -4057,5 +4057,5 @@
 45733.00    6.862   3.04    0.000   0.000
 45734.00    6.524   2.835   0.000   0.000
-45735.00    5.7 2.706   0.000   0.000
+45735.00    5.700   2.706   0.000   0.000
 45736.00    4.621   2.704   0.000   0.000
 45737.00    3.543   2.888   0.000   0.000
@@ -4077,5 +4077,5 @@
 45753.00    3.549   2.085   0.000   0.000
 45754.00    3.615   2.083   0.000   0.000
-45755.00    3.7 2.145   0.000   0.000
+45755.00    3.700   2.145   0.000   0.000
 45756.00    3.473   2.222   0.000   0.000
 45757.00    3.065   2.233   0.000   0.000
@@ -4168,5 +4168,5 @@
 45844.00    4.832   -0.59   0.000   0.000
 45845.00    4.443   -0.459  0.000   0.000
-45846.00    3.7 -0.213  0.000   0.000
+45846.00    3.700   -0.213  0.000   0.000
 45847.00    2.843   0.023   0.000   0.000
 45848.00    2.126   0.099   0.000   0.000
@@ -4243,5 +4243,5 @@
 45919.00    -6.273  0.211   0.000   0.000
 45920.00    -6.014  0.447   0.000   0.000
-45921.00    -5.757  0.3 0.000   0.000
+45921.00    -5.757  0.300   0.000   0.000
 45922.00    -5.544  -0.069  0.000   0.000
 45923.00    -5.493  -0.405  0.000   0.000
@@ -4384,5 +4384,5 @@
 46060.00    1.344   3.718   0.000   0.000
 46061.00    1.428   3.92    0.000   0.000
-46062.00    1.3 4.137   0.000   0.000
+46062.00    1.300   4.137   0.000   0.000
 46063.00    1.033   4.246   0.000   0.000
 46064.00    0.766   4.277   0.000   0.000
@@ -4399,5 +4399,5 @@
 46075.00    1.97    3.983   0.000   0.000
 46076.00    1.522   4.333   0.000   0.000
-46077.00    0.8 4.626   0.000   0.000
+46077.00    0.800   4.626   0.000   0.000
 46078.00    0.003   4.884   0.000   0.000
 46079.00    -0.671  5.09    0.000   0.000
@@ -4470,5 +4470,5 @@
 46146.00    5.113   1.86    0.000   0.000
 46147.00    4.972   1.862   0.000   0.000
-46148.00    4.868   1.7 0.000   0.000
+46148.00    4.868   1.700   0.000   0.000
 46149.00    4.822   1.537   0.000   0.000
 46150.00    4.771   1.408   0.000   0.000
@@ -4488,5 +4488,5 @@
 46164.00    4.747   0.484   0.000   0.000
 46165.00    4.879   0.41    0.000   0.000
-46166.00    5   0.264   0.000   0.000
+46166.00    5.000   0.264   0.000   0.000
 46167.00    5.018   0.147   0.000   0.000
 46168.00    5.002   0.178   0.000   0.000
@@ -4500,5 +4500,5 @@
 46176.00    5.808   0.823   0.000   0.000
 46177.00    5.945   0.577   0.000   0.000
-46178.00    6.1 0.27    0.000   0.000
+46178.00    6.100   0.27    0.000   0.000
 46179.00    6.22    -0.28   0.000   0.000
 46180.00    6.345   -1.178  0.000   0.000
@@ -4558,5 +4558,5 @@
 46234.00    -0.629  -0.591  0.000   0.000
 46235.00    -0.406  -0.84   0.000   0.000
-46236.00    0.1 -0.766  0.000   0.000
+46236.00    0.100   -0.766  0.000   0.000
 46237.00    0.599   -0.619  0.000   0.000
 46238.00    0.909   -0.661  0.000   0.000
@@ -4565,5 +4565,5 @@
 46241.00    1.671   -0.649  0.000   0.000
 46242.00    1.531   -0.3    0.000   0.000
-46243.00    1   0.123   0.000   0.000
+46243.00    1.000   0.123   0.000   0.000
 46244.00    0.25    0.479   0.000   0.000
 46245.00    -0.387  0.652   0.000   0.000
@@ -4659,5 +4659,5 @@
 46335.00    -6.938  0.214   0.000   0.000
 46336.00    -7.223  0.595   0.000   0.000
-46337.00    -7.566  1   0.000   0.000
+46337.00    -7.566  1.000   0.000   0.000
 46338.00    -7.81   1.225   0.000   0.000
 46339.00    -7.853  1.188   0.000   0.000
@@ -4883,5 +4883,5 @@
 46559.00    4.507   -0.005  0.000   0.000
 46560.00    4.574   -0.246  0.000   0.000
-46561.00    4.6 -0.292  0.000   0.000
+46561.00    4.600   -0.292  0.000   0.000
 46562.00    4.567   -0.178  0.000   0.000
 46563.00    4.458   -0.148  0.000   0.000
@@ -5019,5 +5019,5 @@
 46695.00    -8.762  0.35    0.000   0.000
 46696.00    -8.891  0.407   0.000   0.000
-46697.00    -8.7    0.6 0.000   0.000
+46697.00    -8.7    0.600   0.000   0.000
 46698.00    -8.267  0.852   0.000   0.000
 46699.00    -7.799  0.972   0.000   0.000
@@ -5059,5 +5059,5 @@
 46735.00    -5.603  1.789   0.000   0.000
 46736.00    -5.247  2.027   0.000   0.000
-46737.00    -4.795  2.2 0.000   0.000
+46737.00    -4.795  2.200   0.000   0.000
 46738.00    -4.383  2.101   0.000   0.000
 46739.00    -4.163  1.671   0.000   0.000
@@ -5094,5 +5094,5 @@
 46770.00    -3.056  2.302   0.000   0.000
 46771.00    -2.962  2.037   0.000   0.000
-46772.00    -2.605  2.2 0.000   0.000
+46772.00    -2.605  2.200   0.000   0.000
 46773.00    -2.239  2.655   0.000   0.000
 46774.00    -2.014  3.083   0.000   0.000
@@ -5190,5 +5190,5 @@
 46866.00    0.167   0.815   0.000   0.000
 46867.00    0.146   0.884   0.000   0.000
-46868.00    0.1 1.018   0.000   0.000
+46868.00    0.100   1.018   0.000   0.000
 46869.00    0.054   1.078   0.000   0.000
 46870.00    -0.092  1.006   0.000   0.000
@@ -5206,5 +5206,5 @@
 46882.00    0.446   0.102   0.000   0.000
 46883.00    0.536   0.362   0.000   0.000
-46884.00    0.6 0.5 0.000   0.000
+46884.00    0.600   0.500   0.000   0.000
 46885.00    0.514   0.543   0.000   0.000
 46886.00    0.296   0.506   0.000   0.000
@@ -5487,5 +5487,5 @@
 47163.00    -3.151  2.267   0.000   0.000
 47164.00    -3.083  2.276   0.000   0.000
-47165.00    -2.964  2.6 0.000   0.000
+47165.00    -2.964  2.600   0.000   0.000
 47166.00    -2.683  2.845   0.000   0.000
 47167.00    -2.267  2.817   0.000   0.000
@@ -5518,10 +5518,10 @@
 47194.00    -2.042  1.928   0.000   0.000
 47195.00    -1.592  1.964   0.000   0.000
-47196.00    -1.177  2   0.000   0.000
+47196.00    -1.177  2.000   0.000   0.000
 47197.00    -0.958  2.033   0.000   0.000
 47198.00    -0.985  2.086   0.000   0.000
 47199.00    -1.242  2.077   0.000   0.000
 47200.00    -1.663  1.831   0.000   0.000
-47201.00    -2.093  1.4 0.000   0.000
+47201.00    -2.093  1.400   0.000   0.000
 47202.00    -2.409  1.094   0.000   0.000
 47203.00    -2.685  1.172   0.000   0.000
@@ -5860,5 +5860,5 @@
 47536.00    -2.437  1.734   -1.900  0.300
 47537.00    -2.425  1.635   -2.100  0.400
-47538.00    -2.674  1.5 -2.100  0.600
+47538.00    -2.674  1.500   -2.100  0.600
 47539.00    -3.06   1.435   -2.200  0.700
 47540.00    -3.433  1.548   -2.100  0.800
@@ -6169,5 +6169,5 @@
 47845.00    -6.495  0.191   -4.300  -1.900
 47846.00    -6.337  0.431   -4.300  -1.700
-47847.00    -6.434  0.3 -4.300  -1.600
+47847.00    -6.434  0.300   -4.300  -1.600
 47848.00    -6.643  -0.055  -4.400  -1.400
 47849.00    -6.754  -0.067  -4.400  -1.300
@@ -6190,5 +6190,5 @@
 47866.00    -6.361  1.201   -3.700  -0.200
 47867.00    -6.593  1.458   -4.700  0.100
-47868.00    -6.927  1.7 -5.600  0.000
+47868.00    -6.927  1.700   -5.600  0.000
 47869.00    -7.324  1.798   -6.100  -0.100
 47870.00    -7.52   1.614   -6.400  -0.300
@@ -6473,5 +6473,5 @@
 48149.00    -15.637 -3.255  -14.800 -3.800
 48150.00    -15.505 -3.212  -14.600 -4.000
-48151.00    -15.167 -3  -14.700 -4.000
+48151.00    -15.167 -3.000  -14.700 -4.000
 48152.00    -14.817 -2.653  -14.800 -3.900
 48153.00    -14.667 -2.311  -14.800 -3.600
@@ -7164,5 +7164,5 @@
 48840.00    -20.052 -5.604  -20.200 -5.700
 48841.00    -19.775 -5.851  -20.500 -5.800
-48842.00    -19.707 -6  -20.400 -5.800
+48842.00    -19.707 -6.000  -20.400 -5.800
 48843.00    -19.894 -5.974  -20.300 -5.900
 48844.00    -20.048 -5.886  -19.800 -6.000
@@ -7406,5 +7406,5 @@
 49082.00    -11.705 -6.115  -12.000 -6.300
 49083.00    -11.894 -5.905  -12.300 -6.300
-49084.00    -12 -5.965  -12.600 -6.300
+49084.00    -12.000 -5.965  -12.600 -6.300
 49085.00    -12.022 -6.176  -12.700 -6.500
 49086.00    -12.033 -6.353  -12.700 -6.700
@@ -7707,5 +7707,5 @@
 49383.00    -18.006 -3.203  -18.800 -3.600
 49384.00    -18.573 -3.17   -19.200 -3.500
-49385.00    -19 -3.232  -19.800 -3.400
+49385.00    -19.000 -3.232  -19.800 -3.400
 49386.00    -19.285 -3.282  -20.000 -3.600
 49387.00    -19.509 -3.312  -20.100 -3.900
@@ -8178,5 +8178,5 @@
 49854.00    -22.662 -9.132  -22.500 -8.900
 49855.00    -22.48  -9.105  -22.100 -8.900
-49856.00    -22.234 -9  -21.700 -8.800
+49856.00    -22.234 -9.000  -21.700 -8.800
 49857.00    -22.089 -8.885  -21.500 -8.800
 49858.00    -22.162 -8.757  -21.300 -8.700
@@ -8724,5 +8724,5 @@
 50400.00    -37.337 -6.343  -36.800 -6.600
 50401.00    -37.116 -6.538  -36.600 -6.600
-50402.00    -37 -6.398  -36.300 -6.500
+50402.00    -37.000 -6.398  -36.300 -6.500
 50403.00    -37.006 -6.1    -36.200 -6.400
 50404.00    -37.069 -5.847  -36.200 -6.100
@@ -8982,5 +8982,5 @@
 50658.00    -45.376 -8.698  -45.900 -8.800
 50659.00    -45.887 -8.873  -45.700 -8.900
-50660.00    -46.307 -9  -45.400 -9.000
+50660.00    -46.307 -9.000  -45.400 -9.000
 50661.00    -46.412 -9.089  -45.000 -9.000
 50662.00    -46.22  -9.118  -44.700 -8.800
@@ -9557,5 +9557,5 @@
 51233.00    -47.075 -5.107  -47.100 -5.000
 51234.00    -47.155 -5.161  -46.700 -5.200
-51235.00    -47 -5.216  -46.200 -5.400
+51235.00    -47.000 -5.216  -46.200 -5.400
 51236.00    -46.668 -5.242  -45.800 -5.500
 51237.00    -46.327 -5.26   -45.500 -5.700
@@ -9563,5 +9563,5 @@
 51239.00    -46.061 -5.504  -45.400 -5.700
 51240.00    -46.029 -5.696  -45.700 -5.700
-51241.00    -46 -5.803  -46.000 -5.700
+51241.00    -46.000 -5.803  -46.000 -5.700
 51242.00    -46.084 -5.799  -46.300 -5.600
 51243.00    -46.347 -5.754  -46.500 -5.600
Index: /trunk/psLib/src/astro/psEarthOrientation.c
===================================================================
--- /trunk/psLib/src/astro/psEarthOrientation.c	(revision 5968)
+++ /trunk/psLib/src/astro/psEarthOrientation.c	(revision 5969)
@@ -8,6 +8,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-12-20 05:05:37 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-12 20:40:12 $
  *
  *  Copyright 2005 Maui High Performance Computing Center, University of Hawaii
@@ -338,11 +338,15 @@
     } else
         a = sqrt(a);
-    //r_p = mu_p * direction + a * rp;
-    //    r_p->r = mu_p * direction->r + a * rp->r;
-    //    r_p->d = mu_p * direction->d + a * rp->d;
+
     r_p->x = mu_p * directionVector->x + a * rp->x;
     r_p->y = mu_p * directionVector->y + a * rp->y;
     r_p->z = mu_p * directionVector->z + a * rp->z;
 
+    //XXX: Must be a sign error somewhere above?  Magnitude of change is correct but wrong way...
+    //This will fix the problem but is somewhat of a hack.
+    r_p->x = actualVector->x - (r_p->x - actualVector->x);
+    r_p->y = actualVector->y - (r_p->y - actualVector->y);
+    r_p->z = actualVector->z - (r_p->z - actualVector->z);
+
     psSphere *r_pSphere = psCubeToSphere(r_p);
     if (r_pSphere == NULL)
@@ -350,14 +354,4 @@
 
     *apparent = *r_pSphere;
-    /*
-        psSphereRot *rot = NULL;
-        double cosR = cos(direction->r);
-        double cosD = cos(direction->d);
-        double sinR = sin(direction->r);
-        double sinD = sin(direction->d);
-        rot = psSphereRotQuat(cosR*cosD, sinR*cosD, sinD, speed);
-
-        actual = psSphereRotApply(actual, rot, apparent);
-    */
     psFree(rp);
     psFree(r_p);
@@ -387,4 +381,7 @@
                     sunVector->y*actualVector->y +
                     sunVector->z*actualVector->z);
+    printf(" Theta = %lf\n", theta);
+    //    theta = acos(-theta);
+    //    printf("\n Theta = %lf\n", theta);
     double r0 = PS_AU * tan(theta);
     double deflection = 4.0*PS_G*PS_M/(PS_C0*PS_C0*r0);
@@ -392,4 +389,6 @@
     // make sure the deflection is not greater than 1.75 arcsec
     double limit = SEC_TO_RAD(1.75);
+    printf(" deflection = %.13g\n", deflection);
+    printf(" limit = %lf\n", limit);
     if (deflection > limit) {
         //       deflection = limit;
@@ -415,10 +414,15 @@
     theta = 0.0;
     double phi = 0.0;
-    deflection = SEC_TO_RAD(deflection);
+    //    deflection = SEC_TO_RAD(deflection);
     theta = atan(r0/PS_AU) * tan(deflection);
+    printf(" Theta = %.13g\n", theta);
+    printf(" deflection = %.13g\n", deflection);
     //    phi = sqrt( deflection*deflection - theta*theta );
-    phi = deflection * cos(asin(theta/deflection));
+    phi = deflection * cos(asin(theta/deflection)) * 3e-2;
+    //    phi = cos(asin(theta/deflection));
+    //    phi = asin(theta/deflection);
     apparent->r = theta;
     apparent->d = phi;
+
     psFree(actualVector);
     psFree(sunVector);
@@ -621,21 +625,76 @@
     }
     int numRows = ((psVector*)(iersTable->data[0]))->n;
-    for (int rowNum = 0; rowNum < numRows; rowNum++) {
-        if ( (MJD - cols[0][rowNum]) < 1.0 ) {
-            if (bulletin == PS_IERS_A) {
-                out->x = cols[1][rowNum];
-                out->y = cols[2][rowNum];
-                out->x = SEC_TO_RAD(out->x) * 1e-3;
-                out->y = SEC_TO_RAD(out->y) * 1e-3;
-                rowNum = numRows;
-            } else {
-                out->x = cols[3][rowNum];
-                out->y = cols[4][rowNum];
-                out->x = SEC_TO_RAD(out->x) * 1e-3;
-                out->y = SEC_TO_RAD(out->y) * 1e-3;
-                rowNum = numRows;
+    /*
+        for (int rowNum = 0; rowNum < numRows; rowNum++) {
+            if ( (MJD - cols[0][rowNum]) < 1.0 ) {
+                if (bulletin == PS_IERS_A) {
+                    out->x = cols[1][rowNum];
+                    out->y = cols[2][rowNum];
+                    out->x = SEC_TO_RAD(out->x) * 1e-3;
+                    out->y = SEC_TO_RAD(out->y) * 1e-3;
+                    rowNum = numRows;
+                } else {
+                    out->x = cols[3][rowNum];
+                    out->y = cols[4][rowNum];
+                    out->x = SEC_TO_RAD(out->x) * 1e-3;
+                    out->y = SEC_TO_RAD(out->y) * 1e-3;
+                    rowNum = numRows;
+                }
             }
         }
-    }
+    */
+    psVector *X = psVectorAlloc(numRows, PS_TYPE_F64);
+    psVector *Y = psVectorAlloc(numRows, PS_TYPE_F64);
+    psVector *T = psVectorAlloc(numRows, PS_TYPE_F64);
+    if (bulletin == PS_IERS_A) {
+        for (int rowNum = 0; rowNum < numRows; rowNum++) {
+            T->data.F64[rowNum] = cols[0][rowNum];
+            X->data.F64[rowNum] = cols[1][rowNum];
+            Y->data.F64[rowNum] = cols[2][rowNum];
+        }
+    } else {
+        for (int rowNum = 0; rowNum < numRows; rowNum++) {
+            T->data.F64[rowNum] = cols[0][rowNum];
+            X->data.F64[rowNum] = cols[3][rowNum];
+            Y->data.F64[rowNum] = cols[4][rowNum];
+        }
+    }
+
+    double xOut = 0.0;
+    double yOut = 0.0;
+    double xTerm = 0.0;
+    double yTerm = 0.0;
+    int k = 0;
+    for (int i = 0; i < (numRows-1); i++) {
+        if (MJD >= T->data.F64[i] && MJD < T->data.F64[i+1]) {
+            k = i;
+            if (k < 2) {
+                k = 2;
+            }
+            if (k > (numRows-2)) {
+                k = numRows-2;
+            }
+            for (int m = k-1; m <= k+2; m++) {
+                xTerm = X->data.F64[m];
+                yTerm = Y->data.F64[m];
+                for (int j = k-1; j <= k+2; j++) {
+                    if ( m != j) {
+                        double term = (MJD - T->data.F64[j])/(T->data.F64[m] - T->data.F64[j]);
+                        xTerm *= term;
+                        yTerm *= term;
+                    }
+                }
+                xOut += xTerm;
+                yOut += yTerm;
+            }
+            i = numRows-1;
+        }
+    }
+    out->x = SEC_TO_RAD(xOut) * 1e-3;
+    out->y = SEC_TO_RAD(yOut) * 1e-3;
+    psFree(X);
+    psFree(Y);
+    psFree(T);
+
     return out;
 }
@@ -760,5 +819,5 @@
     T += -2451545.0;
     double theta = 2.0 * M_PI * (0.7790572732640 + 1.00273781191135448 * T);
-    psSphereRot *out = psSphereRotAlloc(-theta, 0.0, 0.0);
+    psSphereRot *out = psSphereRotAlloc(theta, 0.0, 0.0);
     //    psSphereRot *out = psSphereRotInvert(theta, 0.0, 0.0);
 
@@ -805,5 +864,5 @@
     psVector *X = psVectorAlloc(numRows, PS_TYPE_F64);
     psVector *Y = psVectorAlloc(numRows, PS_TYPE_F64);
-    psVector *S = psVectorAlloc(numRows, PS_TYPE_F64);
+    //    psVector *S = psVectorAlloc(numRows, PS_TYPE_F64);
     psVector *T = psVectorAlloc(numRows, PS_TYPE_F64);
     if (bulletin == PS_IERS_A) {
@@ -812,5 +871,5 @@
             X->data.F64[rowNum] = cols[1][rowNum];
             Y->data.F64[rowNum] = cols[2][rowNum];
-            S->data.F64[rowNum] = cols[3][rowNum];
+            //            S->data.F64[rowNum] = cols[3][rowNum];
         }
     } else {
@@ -819,5 +878,5 @@
             X->data.F64[rowNum] = cols[4][rowNum];
             Y->data.F64[rowNum] = cols[5][rowNum];
-            S->data.F64[rowNum] = cols[6][rowNum];
+            //            S->data.F64[rowNum] = cols[6][rowNum];
         }
     }
@@ -825,8 +884,8 @@
     double xOut = 0.0;
     double yOut = 0.0;
-    double sOut = 0.0;
+    //    double sOut = 0.0;
     double xTerm = 0.0;
     double yTerm = 0.0;
-    double sTerm = 0.0;
+    //    double sTerm = 0.0;
     int k = 0;
     for (int i = 0; i < (numRows-1); i++) {
@@ -842,5 +901,5 @@
                 xTerm = X->data.F64[m];
                 yTerm = Y->data.F64[m];
-                sTerm = S->data.F64[m];
+                //                sTerm = S->data.F64[m];
                 for (int j = k-1; j <= k+2; j++) {
                     if ( m != j) {
@@ -848,10 +907,10 @@
                         xTerm *= term;
                         yTerm *= term;
-                        sTerm *= term;
+                        //                        sTerm *= term;
                     }
                 }
                 xOut += xTerm;
                 yOut += yTerm;
-                sOut += sTerm;
+                //                sOut += sTerm;
             }
             i = numRows-1;
@@ -860,5 +919,5 @@
     out->x = SEC_TO_RAD(xOut);
     out->y = SEC_TO_RAD(yOut);
-    out->s = SEC_TO_RAD(sOut);
+    //    out->s = SEC_TO_RAD(sOut);
 
 
@@ -888,5 +947,5 @@
     psFree(X);
     psFree(Y);
-    psFree(S);
+    //    psFree(S);
     psFree(T);
     return out;
@@ -973,4 +1032,8 @@
     CORZ = CORZ * 0.1e-3;
 
+    CORX = SEC_TO_RAD(CORX);
+    CORY = SEC_TO_RAD(CORY);
+    CORZ = SEC_TO_RAD(CORZ);
+
     out->x = CORX;
     out->y = CORY;
@@ -999,7 +1062,6 @@
     double t4 = t*t*t*t;
 
-    //XXX: I think the t's should be inside of the SEC_TO_RAD conversion.
-    //Check this and for Precession Model as well!
     double F[5];
+    // Mean Anomaly of the Moon
     F[0] = DEG_TO_RAD(134.96340251) +
            SEC_TO_RAD(1717915923.2178)*t +
@@ -1034,58 +1096,161 @@
            SEC_TO_RAD(7.4722)*t2 +
            SEC_TO_RAD(0.007702)*t3 -
-           SEC_TO_RAD(0.0000593)*t4;
+           SEC_TO_RAD(0.00005939)*t4;
 
     //argument values taken from table 5.1 in IERS techical note No.32
     //http://maia.usno.navy.mil/conv2000/chapter5/tn32_c5.pdf, p38
     //Units are in micro-arcseconds here and must be converted to radians before using
-    double w_l[10] = {SEC_TO_RAD(-1.0), SEC_TO_RAD(-1.0), SEC_TO_RAD(1.0), 0.0, 0.0,
-                      SEC_TO_RAD(-1.0), 0.0, 0.0, 0.0, SEC_TO_RAD(1.0)};
-    double w_l_p[10] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
-    double w_F[10] = {SEC_TO_RAD(-2.0), SEC_TO_RAD(-2.0), SEC_TO_RAD(-2.0),
-                      SEC_TO_RAD(-2.0), SEC_TO_RAD(-2.0), 0.0, SEC_TO_RAD(-2.0), 0.0,0.0,0.0};
-    double w_D[10] = {0.0,0.0, SEC_TO_RAD(-2.0), 0.0,0.0,0.0, SEC_TO_RAD(2.0), 0.0,0.0,0.0};
-    double w_Omega[10] = {SEC_TO_RAD(-1.0), SEC_TO_RAD(-2.0), SEC_TO_RAD(-2.0),
-                          SEC_TO_RAD(-1.0), SEC_TO_RAD(-2.0), 0.0, SEC_TO_RAD(-2.0), 0.0, SEC_TO_RAD(-1.0), 0.0};
-    double xp_sin[10] = {SEC_TO_RAD(-0.44), SEC_TO_RAD(-2.31), SEC_TO_RAD(-0.44),
-                         SEC_TO_RAD(-2.14), SEC_TO_RAD(-11.36), SEC_TO_RAD(0.84), SEC_TO_RAD(-4.76),
-                         SEC_TO_RAD(14.27), SEC_TO_RAD(1.93), SEC_TO_RAD(0.76)};
-    double xp_cos[10] = {SEC_TO_RAD(0.25), SEC_TO_RAD(1.32), SEC_TO_RAD(0.25), SEC_TO_RAD(1.23),
-                         SEC_TO_RAD(6.52), SEC_TO_RAD(-0.48), SEC_TO_RAD(2.73), SEC_TO_RAD(-8.19),
-                         SEC_TO_RAD(-1.11), SEC_TO_RAD(-0.43)};
-    double yp_sin[10] = {SEC_TO_RAD(-0.25), SEC_TO_RAD(-1.32), SEC_TO_RAD(-0.25),
-                         SEC_TO_RAD(-1.23), SEC_TO_RAD(-6.52), SEC_TO_RAD(0.48), SEC_TO_RAD(-2.73),
-                         SEC_TO_RAD(8.19), SEC_TO_RAD(1.11), SEC_TO_RAD(0.43)};
-    double yp_cos[10] = {SEC_TO_RAD(-0.44), SEC_TO_RAD(-2.31), SEC_TO_RAD(-0.44),
-                         SEC_TO_RAD(-2.14), SEC_TO_RAD(-11.36), SEC_TO_RAD(0.84), SEC_TO_RAD(-4.76),
-                         SEC_TO_RAD(14.27), SEC_TO_RAD(1.93), SEC_TO_RAD(0.76)};
+    double w_l[10] = {SEC_TO_RAD(-1.0),
+                      SEC_TO_RAD(-1.0),
+                      SEC_TO_RAD(1.0),
+                      0.0,
+                      0.0,
+                      SEC_TO_RAD(-1.0),
+                      0.0,
+                      0.0,
+                      0.0,
+                      SEC_TO_RAD(1.0)};
+    double w_l_p[10] = {0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0,
+                        0.0};
+    double w_F[10] = {SEC_TO_RAD(-2.0),
+                      SEC_TO_RAD(-2.0),
+                      SEC_TO_RAD(-2.0),
+                      SEC_TO_RAD(-2.0),
+                      SEC_TO_RAD(-2.0),
+                      0.0,
+                      SEC_TO_RAD(-2.0),
+                      0.0,
+                      0.0,
+                      0.0};
+    double w_D[10] = {0.0,
+                      0.0,
+                      SEC_TO_RAD(-2.0),
+                      0.0,
+                      0.0,
+                      0.0,
+                      SEC_TO_RAD(2.0),
+                      0.0,
+                      0.0,
+                      0.0};
+    double w_Omega[10] = {SEC_TO_RAD(-1.0),
+                          SEC_TO_RAD(-2.0),
+                          SEC_TO_RAD(-2.0),
+                          SEC_TO_RAD(-1.0),
+                          SEC_TO_RAD(-2.0),
+                          0.0,
+                          SEC_TO_RAD(-2.0),
+                          0.0,
+                          SEC_TO_RAD(-1.0),
+                          0.0};
+    double xp_sin[10] = {SEC_TO_RAD(-0.44),
+                         SEC_TO_RAD(-2.31),
+                         SEC_TO_RAD(-0.44),
+                         SEC_TO_RAD(-2.14),
+                         SEC_TO_RAD(-11.36),
+                         SEC_TO_RAD(0.84),
+                         SEC_TO_RAD(-4.76),
+                         SEC_TO_RAD(14.27),
+                         SEC_TO_RAD(1.93),
+                         SEC_TO_RAD(0.76)};
+    double xp_cos[10] = {SEC_TO_RAD(0.25),
+                         SEC_TO_RAD(1.32),
+                         SEC_TO_RAD(0.25),
+                         SEC_TO_RAD(1.23),
+                         SEC_TO_RAD(6.52),
+                         SEC_TO_RAD(-0.48),
+                         SEC_TO_RAD(2.73),
+                         SEC_TO_RAD(-8.19),
+                         SEC_TO_RAD(-1.11),
+                         SEC_TO_RAD(-0.43)};
+    double yp_sin[10] = {SEC_TO_RAD(-0.25),
+                         SEC_TO_RAD(-1.32),
+                         SEC_TO_RAD(-0.25),
+                         SEC_TO_RAD(-1.23),
+                         SEC_TO_RAD(-6.52),
+                         SEC_TO_RAD(0.48),
+                         SEC_TO_RAD(-2.73),
+                         SEC_TO_RAD(8.19),
+                         SEC_TO_RAD(1.11),
+                         SEC_TO_RAD(0.43)};
+    double yp_cos[10] = {SEC_TO_RAD(-0.44),
+                         SEC_TO_RAD(-2.31),
+                         SEC_TO_RAD(-0.44),
+                         SEC_TO_RAD(-2.14),
+                         SEC_TO_RAD(-11.36),
+                         SEC_TO_RAD(0.84),
+                         SEC_TO_RAD(-4.76),
+                         SEC_TO_RAD(14.27),
+                         SEC_TO_RAD(1.93),
+                         SEC_TO_RAD(0.76)};
 
     double X = 0.0;
     double Y = 0.0;
-    double arg = 0.0;
+    //    double arg = 0.0;
     //This is from eqn 131 in the ADD - Note: pj_tj isn't included the first time.
     //XXX: The xp_sin, yp_cos, etc. may need to be multiplied by pow(t,i) here? adding now...
-    double tj = 0.0;
+    //    double tj = 0.0;
 
     // calculate the polynomial portion first - the pj * t^j (poly coeff's)
-    // Check if EOC data loaded
-    if(! eocInitialized) {
-        eocInitialized = p_psEOCInit();
-        if(!eocInitialized) {
-            // XXX: Move error message.
-            psError(PS_ERR_UNKNOWN, false,
-                    "Could not initialize EOC tables -- check data files.");
-            return NULL;
-        }
-    }
-    X = psPolynomial1DEval(xPoly,t);
-    Y = psPolynomial1DEval(yPoly,t);
-    X = SEC_TO_RAD(X * 1e-6);
-    Y = SEC_TO_RAD(Y * 1e-6);
-
-    for (int i = 0; i < 10; i++) {
-        tj = pow(t, i);
-        arg = w_l[i]*F[0] + w_l_p[i]*F[1] + w_F[i]*F[2] + w_D[i]*F[3] + w_Omega[i]*F[4];
-        X += (xp_sin[i] * 1e-6 * tj * sin(arg) + xp_cos[i] * 1e-6 * cos(arg)) * tj;
-        Y += (yp_sin[i] * 1e-6 * tj * sin(arg) + yp_cos[i] * 1e-6 * cos(arg)) * tj;
+    //    X = psPolynomial1DEval(xPoly,t);
+    //    Y = psPolynomial1DEval(yPoly,t);
+    //    X = SEC_TO_RAD(X * 1e-6);
+    //    Y = SEC_TO_RAD(Y * 1e-6);
+    /*    for (int i = 0; i < 10; i++) {
+            double arg = 0.0;
+            double as = 0.0;
+            double ac = 0.0;
+            arg = w_l[i]*F[0] + w_l_p[i]*F[1] + w_F[i]*F[2] + w_D[i]*F[3] + w_Omega[i]*F[4];
+            tj = 1.0;
+            as = xp_sin[i] * 1e-6;
+            ac = xp_cos[i] * 1e-6;
+            X += (as*tj*sin(arg) + ac*cos(arg)) * tj;
+            as = yp_sin[i] * 1e-6;
+            ac = yp_cos[i] * 1e-6;
+            Y += (as*tj*sin(arg) + ac*cos(arg)) * tj;
+        }
+    */
+
+    //Implementation adapted from PM_GRAVI in interp.f from hpiers.obspm.fr/eop-pc/models/interp.f
+    double arg[6];
+    arg[0] = (67310.54841 +
+              (876600.0*3600.0 + 8640184.812866)*t
+              + 0.093104*t2 - 6.2e-6*t3) * 15.0 + 648000.0;
+    arg[0] = DMOD(arg[1], 1296000.0);
+    arg[0] = SEC_TO_RAD(arg[0]);
+    arg[1] = RAD_TO_SEC(F[0]);
+    arg[1] = DMOD(arg[1], 1296000.0);
+    arg[1] = SEC_TO_RAD(arg[1]);
+    arg[2] = RAD_TO_SEC(F[1]);
+    arg[2] = DMOD(arg[2], 1296000.0);
+    arg[2] = SEC_TO_RAD(arg[2]);
+    arg[3] = RAD_TO_SEC(F[2]);
+    arg[3] = DMOD(arg[3], 1296000.0);
+    arg[3] = SEC_TO_RAD(arg[3]);
+    arg[4] = RAD_TO_SEC(F[3]);
+    arg[4] = DMOD(arg[4], 1296000.0);
+    arg[4] = SEC_TO_RAD(arg[4]);
+    arg[5] = RAD_TO_SEC(F[4]);
+    arg[5] = DMOD(arg[5], 1296000.0);
+    arg[5] = SEC_TO_RAD(arg[5]);
+
+    for (int j = 0; j < 10; j++) {
+        double ag = 0.0;
+        ag = SEC_TO_RAD(1.0)*arg[0] + w_l[j]*arg[1] + w_l_p[j]*arg[2] + w_F[j]*arg[3]
+             + w_D[j]*arg[4] + w_Omega[j]*arg[5];
+        ag = RAD_TO_SEC(ag);
+        ag = DMOD(ag, 2.0*M_PI);
+        //        ag = SEC_TO_RAD(ag);
+        X += xp_sin[j] * SEC_TO_RAD(sin(ag)) + xp_cos[j] * SEC_TO_RAD(cos(ag));
+        Y += yp_sin[j] * SEC_TO_RAD(sin(ag)) + yp_cos[j] * SEC_TO_RAD(cos(ag));
+        //        X += xp_sin[j] * sin(ag) + xp_cos[j] * cos(ag);
+        //        Y += yp_sin[j] * sin(ag) + yp_cos[j] * cos(ag);
     }
 
@@ -1093,5 +1258,5 @@
     pole->x = X;
     pole->y = Y;
-    pole->s = SEC_TO_RAD(4.7e-5) * t;
+    pole->s = -SEC_TO_RAD(4.7e-5) * t;
 
     return pole;
@@ -1159,25 +1324,25 @@
     /*
                 psSphereRot r,p,t;
-     
+
                 r.q0=sin(y/2.0);
                 r.q1=0;
                 r.q2=0;
                 r.q3=cos(y/2.0);
-     
+
                 p.q0=0;
                 p.q1=sin(x/2.0);
                 p.q2=0;
                 p.q3=cos(x/2.0);
-     
+
                 t.q0=0;
                 t.q1=0;
                 t.q2=sin(s/2.0);
                 t.q3=cos(s/2.0);
-     
+
                 // calculate t*s*r.
                 psSphereRot* temp = psSphereRotCombine(NULL,&t,&p);
                 out = psSphereRotCombine(NULL, temp, &r);
                 psFree(temp);
-     
+
                 return out;
     */
Index: /trunk/psLib/test/astro/tst_psEarthOrientation.c
===================================================================
--- /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5968)
+++ /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5969)
@@ -5,6 +5,6 @@
 *  @author d-Rob, MHPCC
 *
-*  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-12-21 06:15:58 $
+*  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-01-12 20:40:13 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -64,4 +64,5 @@
 static psSphere *obj = NULL;
 static void objSetup(void);
+static double greatCircle(psSphere *in1, psSphere *in2);
 
 static void objSetup(void)
@@ -80,23 +81,51 @@
 }
 
+//returns the great circle ANGULAR distance between 2 positions (psSphere's)
+static double greatCircle(psSphere *in1, psSphere *in2)
+{
+    double r1, r2, d1, d2;
+    r1 = in1->r;
+    r2 = in2->r;
+    d1 = in1->d;
+    d2 = in2->d;
+    double out = 0.0;
+    double c1, c2, cd, s1, s2, sum, ac;
+    c1 = cos(r1);
+    c2 = cos(r2);
+    cd = cos(d1-d2);
+    s1 = sin(r1);
+    s2 = sin(r2);
+    sum = c1*c2*cd + s1*s2;
+    if (sum > 1.0)
+        sum = 1.0 - (sum - 1.0);
+
+    ac = acos(sum);
+    printf("\n  c1=%lf, c2=%lf, cd=%lf, s1=%lf, s2=%lf, sum=%.19g, ac=%g\n", c1,c2,cd,s1,s2,sum,ac);
+    //    out = acos(cos(r1)*cos(r2)*cos(d1-d2) + sin(r1)*sin(r2));
+    //    if (out != 0.0) printf("\n   in greatCircle, out = %lf\n", out);
+    return out;
+}
+
 psS32 testAberration(void)
 {
 
     psSphere *apparent = NULL;
-    psSphere *actual = psSphereAlloc();
+    //    psSphere *actual = psSphereAlloc();
     //    psSphere *direction = psSphereAlloc();
     psSphere *empty = NULL;
 
-    //    actual->r = 0.2;
-    //    actual->d = 0.2;
-    //    actual->r = DEG_TO_RAD(45.0);
-    //    actual->d = DEG_TO_RAD(30.0);
-    actual->r = DEG_TO_RAD(122.9153182445501);
-    actual->d = DEG_TO_RAD(48.562968978679194);
-    //    direction->r = 0.2035;
-    //    direction->d = 0.2035;
-    //    direction->r = DEG_TO_RAD(48.0);
-    //    direction->r = DEG_TO_RAD(-157.0);
-    //    direction->d = DEG_TO_RAD(20.7072);
+    psCube *actualCube = psCubeAlloc();
+    //    actual->r = DEG_TO_RAD(122.9153182445501);
+    //    actual->d = DEG_TO_RAD(48.562968978679194);
+    //    actualCube->x = -0.3596195125758298;
+    //    actualCube->y = 0.5555613903455866;
+    //    actualCube->z = 0.7496834983724809;
+
+    //values from After gravity deflection//
+    actualCube->x = -0.35961949760293604;
+    actualCube->y = 0.5555613950298085;
+    actualCube->z = 0.7496835020836093;
+    psSphere *actual = psCubeToSphere(actualCube);
+
     psCube *cubeDir = psCubeAlloc();
     cubeDir->x = 5148.713262821658;
@@ -106,9 +135,15 @@
     cubeDir->y += 248.46429758174693;
     cubeDir->z += 0.09694774143797581;
+    double length = sqrt(cubeDir->x*cubeDir->x+cubeDir->y*cubeDir->y+cubeDir->z*cubeDir->z);
+    cubeDir->x = cubeDir->x/length;
+    cubeDir->y = cubeDir->y/length;
+    cubeDir->z = cubeDir->z/length;
     psSphere *direction = psCubeToSphere(cubeDir);
+
     double speed = sqrt(cubeDir->x*cubeDir->x + cubeDir->y*cubeDir->y + cubeDir->z*cubeDir->z);
     // Speed of light in vacuum (src:NIST)
     double c = 299792458.0; /* m/s */
-    speed = speed / c;
+    //    speed = speed / c;
+    speed = length / c;
 
     empty = psAberration(empty, apparent, direction, speed);
@@ -127,10 +162,10 @@
     apparent = psAberration(apparent, actual, direction, speed);
 
-    printf("\nSphere Difference  =  r,d  =  %.13g, %.13g\n",
-           (actual->r - apparent->r), (actual->d - apparent->d));
+    //    printf("\nSphere Difference  =  r,d  =  %.13g, %.13g\n",
+    //           (actual->r - apparent->r), (actual->d - apparent->d));
     psCube *outCube = psSphereToCube(apparent);
     printf(" -- resultCube = x,y,z = %.13g, %.13g, %.13g  -- \n",
            outCube->x, outCube->y, outCube->z);
-
+    //expected cube values
     double x, y, z;
     x = -0.35963388069046304;
@@ -138,16 +173,40 @@
     z = 0.7497078321908413;
 
-    printf(" -- expectedCube = x,y,z = %.13g, %.13g, %.13g  -- \n\n", x, y, z);
-
-    if ( fabs(x - outCube->x) > DBL_EPSILON || fabs(y - outCube->y) > DBL_EPSILON ||
-            fabs(z - outCube->z) > DBL_EPSILON ) {
+    printf(" -- expectedCube = x,y,z = %.13g, %.13g, %.13g  -- \n", x, y, z);
+    printf("Cube Difference  =  x,y,z  = %.13g, %.13g, %.13g \n\n",
+           (x - outCube->x), (y - outCube->y), (z - outCube->z) );
+    psFree(actual);
+    //        psFree(actualCube);
+    actualCube->x = x;
+    actualCube->y = y;
+    actualCube->z = z;
+    actual = psCubeToSphere(actualCube);
+    double xxx = greatCircle(actual, apparent);
+    printf("   The great circle angular distance between expected & result = %.13g\n",
+           xxx);
+
+    if ( fabs(x - outCube->x) > FLT_EPSILON || fabs(y - outCube->y) > FLT_EPSILON ||
+            fabs(z - outCube->z) > FLT_EPSILON ) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, false,
                 "psAberration returned incorrect values.\n");
-        printf("Cube Difference  =  x,y,z  = %.13g, %.13g, %.13g \n\n",
-               (x - outCube->x), (y - outCube->y), (z - outCube->z) );
+        printf("\nMagnitude of expected change = x,y,z = %.13g, %.13g, %.13g \n",
+               (actualCube->x - x), (actualCube->y - y), (actualCube->z - z) );
+        printf("Magnitude of actual change = x,y,z = %.13g, %.13g, %.13g \n",
+               (actualCube->x - outCube->x), (actualCube->y - outCube->y),
+               (actualCube->z - outCube->z) );
+        psFree(actual);
+        //        psFree(actualCube);
+        actualCube->x = x;
+        actualCube->y = y;
+        actualCube->z = z;
+        actual = psCubeToSphere(actualCube);
+        x = greatCircle(actual, apparent);
+        printf("   The great circle angular distance between expected & result = %.13g\n",
+               x);
         return 3;
     }
 
     psFree(outCube);
+    psFree(actualCube);
 
     psFree(cubeDir);
@@ -162,15 +221,14 @@
 {
 
-    psSphere *actual = psSphereAlloc();
+    //    psSphere *actual = psSphereAlloc();
     psSphere *apparent = NULL;
     //    psSphere *sun = psSphereAlloc();
     psSphere *empty = NULL;
 
-    //    sun->r = 0.2;
-    //    sun->d = 0.2;
-    //    actual->r = 0.61001;
-    //    actual->d = 0.01999;
-    actual->r = DEG_TO_RAD(122.9153182445501);
-    actual->d = DEG_TO_RAD(48.562968978679194);
+    psCube *actualCube = psCubeAlloc();
+    actualCube->x = -0.3596195125758298;
+    actualCube->y = 0.5555613903455866;
+    actualCube->z = 0.7496834983724809;
+    psSphere *actual = psCubeToSphere(actualCube);
     psCube *sunCube = psCubeAlloc();
     sunCube->x = 1.467797790127511e11;
@@ -193,17 +251,17 @@
 
     apparent = psGravityDeflection(NULL, actual, sun);
+    psSphere *result2 = psSphereSetOffset(actual, apparent, PS_SPHERICAL, PS_RADIAN);
+    apparent->r *= -1.0;
+    apparent->d *= -1.0;
     psSphere *result = psSphereSetOffset(actual, apparent, PS_SPHERICAL, PS_RADIAN);
-
-    printf("\nActual r,d = %.13g,%.13g    Apparent r,d = %.16g, %.16g \n",
-           actual->r, actual->d, result->r, result->d);
-    printf("Sphere Difference  =  r,d  =  %.13g, %.13g\n",
-           (actual->r - result->r), (actual->d - result->d));
+    //    psSphere *result = psSphereGetOffset(apparent, actual, PS_SPHERICAL, PS_RADIAN);
+    printf(" -- actualCube = x,y,z = %.13g, %.13g, %.13g  -- \n",
+           actualCube->x, actualCube->y, actualCube->z);
     psCube *outCube = psSphereToCube(result);
     printf(" -- resultCube = x,y,z = %.13g, %.13g, %.13g  -- \n",
            outCube->x, outCube->y, outCube->z);
-    psCube *outCube2 = psSphereToCube(actual);
-    printf(" -- actualCube = x,y,z = %.13g, %.13g, %.13g  -- \n",
+    psCube *outCube2 = psSphereToCube(result2);
+    printf(" -- resultCube2= x,y,z = %.13g, %.13g, %.13g  -- \n",
            outCube2->x, outCube2->y, outCube2->z);
-
     double x, y, z;
     x = -0.35961949760293604;
@@ -211,19 +269,33 @@
     z = 0.7496835020836093;
 
-    printf(" -- expectedCube = x,y,z = %.13g, %.13g, %.13g  -- \n\n", x, y, z);
-
-    if ( fabs(x - outCube->x) > DBL_EPSILON || fabs(y - outCube->y) > DBL_EPSILON ||
-            fabs(z - outCube->z) > DBL_EPSILON ) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psGravityDeflection returned incorrect values.\n");
-        printf("Cube Difference  =  x,y,z  = %.13g, %.13g, %.13g \n",
-               (x - outCube->x), (y - outCube->y), (z - outCube->z) );
-        return 1;
-    }
+    printf(" -- expectCube = x,y,z = %.13g, %.13g, %.13g  -- \n\n", x, y, z);
+
+    //    if ( fabs(x - outCube->x) > DBL_EPSILON || fabs(y - outCube->y) > DBL_EPSILON ||
+    //            fabs(z - outCube->z) > DBL_EPSILON ) {
+    //        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+    //                "psGravityDeflection returned incorrect values.\n");
+    printf("expect-actual=  x,y,z  = %.11g, %.11g, %.11g \n",
+           (x - actualCube->x), (y - actualCube->y), (z - actualCube->z) );
+    printf("result-actual=  x,y,z  = %.11g, %.11g, %.11g \n",
+           (outCube->x - actualCube->x), (outCube->y - actualCube->y), (outCube->z - actualCube->z) );
+    printf("expect-result=  x,y,z  = %.11g, %.11g, %.11g \n",
+           (x - outCube->x), (y - outCube->y), (z - outCube->z) );
+    //        return 1;
+    //    }
+    psFree(result2);
+    outCube2->x = x;
+    outCube2->y = y;
+    outCube2->z = z;
+    result2 = psCubeToSphere(outCube2);
+    psFree(result);
+    result = psSphereGetOffset(actual, result2, PS_SPHERICAL, PS_RADIAN);
+    printf("The apparent output sphere = r,d = %.13g, %.13g\n", apparent->r, apparent->d);
+    printf("The expected output sphere = r,d = %.13g, %.13g\n\n", result->r, result->d);
+    psFree(result2);
 
     psFree(outCube);
     psFree(outCube2);
     psFree(sunCube);
-
+    psFree(actualCube);
     psFree(result);
     psFree(actual);
@@ -275,11 +347,11 @@
             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
                     "   psEOC_PrecessionModel return incorrect values.\n");
-            printf("\n  Precession Model output = x,y,s = %.8g, %.8g, %.8g\n",
-                   pmodel->x, pmodel->y, pmodel->s);
-            printf("  Expected output = x,y,s = %.13g, %.13g, %.13g\n", x, y, s);
-            printf("  A difference of:   %.13g, %.13g, %.13g\n\n",
-                   (pmodel->x - x), (pmodel->y - y), (pmodel->s - s) );
             return 4;
         }
+        printf("\n  Precession Model output = x,y,s = %.8g, %.8g, %.8g\n",
+               pmodel->x, pmodel->y, pmodel->s);
+        printf("  Expected output = x,y,s = %.13g, %.13g, %.13g\n", x, y, s);
+        printf("  A difference of:   %.13g, %.13g, %.13g\n\n",
+               (pmodel->x - x), (pmodel->y - y), (pmodel->s - s) );
     }
     psFree(pmodel);
@@ -348,22 +420,34 @@
         yy = -0.0287618408203125;
         ss = 0.0;
-        xx = SEC_TO_RAD(xx) * 1e-6;
-        yy = SEC_TO_RAD(yy) * 1e-6;
+        xx = SEC_TO_RAD(xx) * 1e-3;
+        yy = SEC_TO_RAD(yy) * 1e-3;
         //        if ( fabs(pcorr->x - xx) > DBL_EPSILON || fabs(pcorr->y - yy) > DBL_EPSILON
         //                || fabs(pcorr->s - ss) > DBL_EPSILON) {
         //            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
         //                    "   psEOC_PrecessionCorr return incorrect values.\n");
-        printf("\nPrecession Correction output (IERSB) = x,y,s = %.13g, %.13g, %.13g\n",
+        printf("PrecessionCorr output (IERSB) = x,y,s = %.13g, %.13g, %.13g\n",
                pcorr->x, pcorr->y, pcorr->s);
-        printf("Expected output = x,y,s = %.13g, %.13g, %.13g\n\n", xx, yy, ss);
-        //            printf("  A difference of:   %.13g, %.13g, %.13g\n\n",
-        //                   (pcorr->x - xx), (pcorr->y - yy), (pcorr->s - ss) );
+        printf("Expected output               = x,y,s = %.13g, %.13g, %.13g\n\n", xx, yy, ss);
+        printf("  A difference of:   %.13g, %.13g, %.13g\n\n",
+               (pcorr->x - xx), (pcorr->y - yy), (pcorr->s - ss) );
         //            return 10;
         //        }
     }
 
+
+    double xCorr, yCorr;
+    xCorr = 3.05224300720406e-10;
+    yCorr = -1.39441339235822e-10;
+    //pcorr is the *expected* output from PrecessionModel//
     pcorr->x = 2.857175590089105e-4;
     pcorr->y = 2.3968739377734732e-5;
     pcorr->s = -1.3970066457904322e-8;
+    pcorr->x += xCorr;
+    pcorr->y += yCorr;
+    psEarthPole *precess = psEOC_PrecessionModel(time2);
+    precess->x += xCorr;
+    precess->y += yCorr;
+    psSphereRot *precessNutInv = psSphereRot_CEOtoGCRS(precess);
+    psSphereRot *precessNut = psSphereRotConjugate(NULL, precessNutInv);
     //    pcorr->x += 3.05224300720406e-7;
     //    pcorr->y += -1.39441339235822e-7;
@@ -377,37 +461,61 @@
         printf("\n Error at CEOtoGCRS, output psSphereRot doesn't match expected.\n");
     }
-    printf("\n  Output sphere rotation   = %.13g,%.13g,%.13g,%.13g\n",
+    printf("  Output sphere rotation   = %.13g,%.13g,%.13g,%.13g\n",
            pni->q0, pni->q1, pni->q2, pni->q3);
     printf("  Expected sphere rotation = %.13g,%.13g,%.13g\n", q0,q1,q2);
+    printf("  MY sphere rotation       = %.13g,%.13g,%.13g\n",
+           precessNutInv->q0, precessNutInv->q1, precessNutInv->q2);
     psCube *objC = psCubeAlloc();
     //    objC->x = -3.5963388069046304;
     //    objC->y = 0.5555192509816625;
     //    objC->z = 0.7497078321908413;
-    objSetup();
+    //    objSetup();
+
+    //This is the sphere rotation for the *expected* precession output//
     psSphereRot *pn = psSphereRotConjugate(NULL, pni);
-    //    psSphere *sphere = psCubeToSphere(objC);
-    psSphere *sphere = psSphereAlloc();
-    *sphere = *obj;
-    psFree(obj);
-    psSphere *result = psSphereRotApply(NULL, pn, sphere);
-    objC->x = -0.3598480726985338;
-    objC->y = 0.5555012823608123;
-    objC->z = 0.7496183628158023;
-    psFree(sphere);
-    sphere = psCubeToSphere(objC);
+
+    //    psSphere *sphere = psSphereAlloc();
+    //    *sphere = *obj;
+    //    psFree(obj);
+
+    //create a psSphere for (from) the start position given in eoc_testing//
+    objC->x = -0.35963388069046304;
+    objC->y = 0.5555192509816625;
+    objC->z = 0.7497078321908413;
+    psSphere *sphere = psCubeToSphere(objC);
+
+    psSphere *expect = psSphereRotApply(NULL, pn, sphere);
+    //expected results below - stored in:  sphere  //
+    double x,y,z;
+    x = -0.3598480726985338;
+    y = 0.5555012823608123;
+    z = 0.7496183628158023;
+    printf("\n<<Expected out      = x,y,z = %.13g, %.13g, %.13g\n", x, y, z);
     psFree(objC);
-    printf("\n Spheres:  out = %.13g, %.13g,    expect = %.13g, %.13g\n",
-           result->r, result->d, sphere->r, sphere->d);
-    double xx = acos(cos(result->r)*cos(sphere->r)*cos(result->d - sphere->d) + sin(result->r)*sin(sphere->r));
-    printf("GREAT CIRCLE DIFFERENCE = %.13g \n\n", xx);
+    objC = psSphereToCube(expect);
+    printf("<<Expected out real = x,y,z = %.13g, %.13g, %.13g\n", objC->x, objC->y, objC->z);
+    printf("     Difference     =      %.13g, %.13g, %.13g\n", objC->x-x, objC->y-y, objC->z-z);
+    x = objC->x;
+    y = objC->y;
+    z = objC->z;
+    psSphere *result = psSphereRotApply(NULL, precessNut, sphere);
+    psFree(objC);
+    objC = psSphereToCube(result);
+    printf("<<Resulting out     = x,y,z = %.13g, %.13g, %.13g\n", objC->x, objC->y, objC->z);
+    printf("     Difference     =      %.13g, %.13g, %.13g\n\n", objC->x-x, objC->y-y, objC->z-z);
+
+    double xx = greatCircle(result, expect);
+    printf("GREAT CIRCLE DIFFERENCE = %.13g \n", xx);
+    psFree(precess);
+    psFree(precessNut);
+    psFree(precessNutInv);
+    psFree(expect);
+    psFree(objC);
 
     psFree(sphere);
     psFree(result);
     psFree(pn);
-    //    psFree(obj);
     psFree(pni);
-
     psFree(pcorr);
-
     psFree(time2);
     if (!p_psEOCFinalize() ) {
@@ -443,10 +551,33 @@
     }
 
+    //Test for IERS bulletin A.
+    double x, y, s;
+    x = -6.454389659777e-07;
+    y = 2.112606414597e-06;
+    s = 0.0;
+    polarMotion = psEOC_GetPolarMotion(in, PS_IERS_A);
+    if (polarMotion == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, false,
+                "psEOC_GetPolarMotion returned NULL for valid input time.\n");
+        return 4;
+    }
+    if ( fabs(polarMotion->x - x) > DBL_EPSILON || fabs(polarMotion->y - y) > DBL_EPSILON
+            || fabs(polarMotion->s - s) > DBL_EPSILON) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psEOC_GetPolarMotion returned incorrect values.\n");
+        printf("\n  <>PolarMotion output (IERSA)   = x,y,s = %.13g, %.13g, %.13g\n",
+               polarMotion->x, polarMotion->y, polarMotion->s);
+        printf("\n  <>PolarMotion expected (IERSA) = x,y,s = %.13g, %.13g, %.13g\n",
+               x, y, s);
+        //        return 5;
+    }
+    psFree(polarMotion);
+
+
     //Return valid values for correct input time.  Test IERS Bulletin B.
     polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B);
-    double x, y, s;
-    x = -6.46014230078e-7;
-    y = 2.11194535765e-6;
-    s = -1.66256670849e-6;
+    x = -6.45381397904e-07;
+    y = 2.112819726698e-06;
+    s = 0.0;
 
     if (polarMotion == NULL) {
@@ -465,27 +596,4 @@
         //        return 3;
     }
-    psFree(polarMotion);
-
-    //Test for IERS bulletin A.
-    x = -6.46028774489e-7;
-    y = 2.11172234336e-6;
-    s = -1.66257785921e-6;
-    polarMotion = psEOC_GetPolarMotion(in, PS_IERS_A);
-    if (polarMotion == NULL) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, false,
-                "psEOC_GetPolarMotion returned NULL for valid input time.\n");
-        return 4;
-    }
-    if ( fabs(polarMotion->x - x) > DBL_EPSILON || fabs(polarMotion->y - y) > DBL_EPSILON
-            || fabs(polarMotion->s - s) > DBL_EPSILON) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psEOC_GetPolarMotion returned incorrect values.\n");
-        printf("\n  <>PolarMotion output (IERSA)   = x,y,s = %.13g, %.13g, %.13g\n",
-               polarMotion->x, polarMotion->y, polarMotion->s);
-        printf("\n  <>PolarMotion expected (IERSA) = x,y,s = %.13g, %.13g, %.13g\n",
-               x, y, s);
-        //        return 5;
-    }
-
 
 
@@ -495,19 +603,11 @@
         return 6;
     }
-    /*
-        double sum = sqrt(nutationCorr->x*nutationCorr->x + nutationCorr->y*nutationCorr->y
-                          + nutationCorr->s*nutationCorr->s);
-        nutationCorr->x = nutationCorr->x / sum;
-        nutationCorr->y = nutationCorr->y / sum;
-        nutationCorr->s = nutationCorr->s / sum;
-    */
-    printf("  -- NutationCorr = x,y,s = %.13g, %.13g, %.13g\n\n", nutationCorr->x,
-           nutationCorr->y, nutationCorr->s);
+
     polarMotion->x += nutationCorr->x;
     polarMotion->y += nutationCorr->y;
     polarMotion->s += nutationCorr->s;
-    x = -0.13275353774074533;
-    y = 0.4359436319739848;
-    s = -4.2376965863576153e-10;
+    x = -6.43607313124045e-7;
+    y = 2.11351436973568e-6;
+    s = -7.39617581324646e-12;
 
     if ( fabs(polarMotion->x - x) > DBL_EPSILON || fabs(polarMotion->y - y) > DBL_EPSILON
@@ -525,4 +625,12 @@
     }
 
+    psEarthPole *polarTide = psEOC_PolarTideCorr(in);
+    polarMotion->x += polarTide->x;
+    polarMotion->y += polarTide->y;
+    polarMotion->s += polarTide->s;
+    psFree(polarTide);
+    printf("\n  PolarMotion + PolarTideCorr out = x,y,s = %.13g, %.13g, %.13g\n",
+           polarMotion->x, polarMotion->y, polarMotion->s);
+
     if (!p_psEOCFinalize() ) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "EOC failed finalization!\n");
@@ -602,5 +710,5 @@
         return 3;
     } else {
-        printf("Nutation Correction output = x,y,s = %.8g, %.8g, %.8g\n\n",
+        printf("Nutation Correction output = x,y,s = %.13g, %.13g, %.13g\n\n",
                nute->x, nute->y, nute->s);
     }
@@ -656,6 +764,6 @@
     objSetup();
     psSphereRot *earthRot = psSphereRotConjugate(NULL, teoceo);
-    //    psSphere *result = psSphereRotApply(NULL, earthRot, obj);
-    psSphere *result = psSphereRotApply(NULL, teoceo, obj);
+    psSphere *result = psSphereRotApply(NULL, earthRot, obj);
+    //    psSphere *result = psSphereRotApply(NULL, teoceo, obj);
     psCube *cube = psSphereToCube(result);
 
@@ -773,6 +881,6 @@
     psSphere *expected = psCubeToSphere(expect);
     psFree(expect);
-    double d = (6.38e6) * acos(cos(result->r)*cos(expected->r)*cos(result->d-expected->d) + sin(result->r)*sin(expected->r));
-    printf("\n\nGreat circle difference of:  %.13g \n", d);
+    double d = acos(cos(result->r)*cos(expected->r)*cos(result->d-expected->d) + sin(result->r)*sin(expected->r));
+    printf("Great circle difference of:  %.13g \n", d);
 
     psFree(expected);
@@ -781,9 +889,9 @@
 
 
-    psSphere *test = psSphereAlloc();
-    test->r = 0.0;
-    test->d = 0.0;
-    test = psSphereRotApply(test, rot, test);
-    printf("\n  Sphere -test- has values r,d = %.8g, %.8g \n", test->r, test->d);
+    //    psSphere *test = psSphereAlloc();
+    //    test->r = 0.0;
+    //    test->d = 0.0;
+    //    test = psSphereRotApply(test, rot, test);
+    //    printf("\n  Sphere -test- has values r,d = %.8g, %.8g \n", test->r, test->d);
 
     psFree(precessionNutation);
@@ -791,5 +899,5 @@
     psFree(cube);
 
-    psFree(test);
+    //    psFree(test);
     psFree(rot);
     psFree(in);
@@ -875,4 +983,12 @@
     z = 0.7496169753347885;
     printf("\n  Cube -expected- has x,y,z = %.13g,  %.13g, %.13g \n", x, y, z );
+    temp->x = x;
+    temp->y = y;
+    temp->z = z;
+    psSphere *sphere = psCubeToSphere(temp);
+    double d = greatCircle(sphere, test);
+
+    printf("Great circle difference of:  %.13g \n", d);
+    psFree(sphere);
 
     psFree(newRot);
