Index: /trunk/psLib/test/astro/tst_psEarthOrientation.c
===================================================================
--- /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5715)
+++ /trunk/psLib/test/astro/tst_psEarthOrientation.c	(revision 5716)
@@ -5,6 +5,6 @@
 *  @author d-Rob, MHPCC
 *
-*  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-12-02 04:40:00 $
+*  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-12-07 02:13:40 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,5 @@
 static psS32 testGravityDeflect(void);
 static psS32 testEOCPrecession(void);
+static psS32 testEOCPrecessionCorr(void);
 static psS32 testEOCPolar(void);
 static psS32 testEOCNutation(void);
@@ -28,9 +29,10 @@
                               {testGravityDeflect, 667, "psGravityDeflect()", 0, false},
                               {testEOCPrecession, 669, "psEOCPrecession()", 0, false},
-                              {testEOCPolar, 670, "psEOCPolar()", 0, false},
-                              {testEOCNutation, 671, "psEOCNutation()", 0, false},
-                              {testSphereRot_TEOtoCEO, 672, "psSphereRot_TEOtoCEO()", 0, false},
-                              {testSphereRot_CEOtoGCRS, 673, "psSphereRot_CEOtoGCRS()", 0, false},
-                              {testSphereRot_ITRStoTEO, 674, "psSphereRRot_ITRStoTEO()", 0, false},
+                              {testEOCPrecessionCorr, 670, "psEOCPrecessionCorr()", 0, false},
+                              {testEOCPolar, 671, "psEOCPolar()", 0, false},
+                              {testEOCNutation, 672, "psEOCNutation()", 0, false},
+                              {testSphereRot_TEOtoCEO, 673, "psSphereRot_TEOtoCEO()", 0, false},
+                              {testSphereRot_CEOtoGCRS, 674, "psSphereRot_CEOtoGCRS()", 0, false},
+                              {testSphereRot_ITRStoTEO, 675, "psSphereRRot_ITRStoTEO()", 0, false},
                               {NULL}
                           };
@@ -257,17 +259,40 @@
         return 3;
     } else {
-        printf("Precession Model output = x,y,s = %.8g, %.8g, %.8g\n",
-               pmodel->x, pmodel->y, pmodel->s);
         double x, y, s;
         x = 2.857175590089105e-4;
         y = 2.3968739377734732e-5;
         s = -1.3970066457904322e-8;
-        printf("Expected output = x,y,s = %.13g, %.13g, %.13g\n\n", x, y, s);
+        if ( fabs(pmodel->x - x) > DBL_EPSILON || fabs(pmodel->y - y) > DBL_EPSILON
+                || fabs(pmodel->s - s) > DBL_EPSILON) {
+            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;
+        }
     }
     psFree(pmodel);
 
+    psFree(time);
+    if (!p_psEOCFinalize() ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "EOC failed finalization!\n");
+        return 12;
+    }
+
+    return 0;
+}
+
+psS32 testEOCPrecessionCorr(void)
+{
+    psTime *empty = NULL;
+    psTime *time2 = psTimeAlloc(PS_TIME_UTC);
+    time2->sec = timesec;
+    time2->nsec = 0;
+    time2->leapsecond = false;
+
     //XXX:  MAY Be an Error here... Time for Precession Correction has to be TAI or seg faults
-    psTime *time2 = psTimeAlloc(PS_TIME_UTC);
-    *time2 = *time;
     time2 = psTimeConvert(time2, PS_TIME_TAI);
     //Tests for Precession Correction function//
@@ -278,5 +303,5 @@
         psError(PS_ERR_BAD_PARAMETER_VALUE, false,
                 "psEOC_PrecessionCorr failed to return NULL for NULL time input.\n");
-        return 4;
+        return 5;
     }
 
@@ -286,5 +311,5 @@
         psError(PS_ERR_BAD_PARAMETER_VALUE, false,
                 "psEOC_PrecessionCorr failed to return NULL for incorrect IERS table.\n");
-        return 5;
+        return 6;
     }
     psFree(pcorr);
@@ -295,7 +320,7 @@
         psError(PS_ERR_BAD_PARAMETER_NULL, false,
                 "psEOC_PrecessionCorr returned NULL for valid inputs.\n");
-        return 6;
+        return 7;
     } else {
-        printf("Precession Correction output (IERSA) = x,y,s = %.8g, %.8g, %.8g\n",
+        printf("\nPrecession Correction output (IERSA) = x,y,s = %.13g, %.13g, %.13g\n\n",
                pcorr->x, pcorr->y, pcorr->s);
     }
@@ -307,17 +332,25 @@
         psError(PS_ERR_BAD_PARAMETER_NULL, false,
                 "psEOC_PrecessionCorr returned NULL for valid inputs.\n");
-        return 7;
+        return 9;
     } else {
-        printf("Precession Correction output (IERSB) = x,y,s = %.8g, %.8g, %.8g\n",
-               pcorr->x, pcorr->y, pcorr->s);
         double xx, yy, ss;
         xx = 0.06295703125;
         yy = -0.0287618408203125;
         ss = 0.0;
-        printf("Expected output = x,y,s = %.13g, %.13g, %.13g\n\n", xx, yy, ss);
-    }
+        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",
+                   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) );
+            return 10;
+        }
+    }
+
     psFree(pcorr);
 
-    psFree(time);
     psFree(time2);
     if (!p_psEOCFinalize() ) {
@@ -355,18 +388,4 @@
         return 2;
     }
-
-    psEarthPole *polarMotion = NULL;
-    polarMotion = psEOC_GetPolarMotion(empty, PS_IERS_B);
-    if (polarMotion != NULL) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psEOC_GetPolarMotion failed to return NULL for NULL input time.\n");
-        return 3;
-    }
-    polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B);
-    if (polarMotion == NULL) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, false,
-                "psEOC_GetPolarMotion returned NULL for valid input time.\n");
-        return 4;
-    }
     psTime *in2 = psTimeAlloc(PS_TIME_UTC);
     in2->sec = timesec;
@@ -375,6 +394,21 @@
     in2 = psTimeConvert(in2, PS_TIME_TAI);
     psSphere *interm = p_psTimeGetPoleCoords(in2);
+    printf("\n  Polar Tide Corrections \n");
     printf(" -- sphere = r=%.8g, d=%.8g\n", interm->r, interm->d);
     printf(" -- Eop = x=%.8g, y=%.8g, s=%.8g\n", eop->x, eop->y, eop->s);
+
+    psEarthPole *polarMotion = NULL;
+    polarMotion = psEOC_GetPolarMotion(empty, PS_IERS_B);
+    if (polarMotion != NULL) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psEOC_GetPolarMotion failed to return NULL for NULL input time.\n");
+        return 3;
+    }
+    polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B);
+    if (polarMotion == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, false,
+                "psEOC_GetPolarMotion returned NULL for valid input time.\n");
+        return 4;
+    }
 
 
@@ -384,18 +418,34 @@
         return 5;
     }
-    printf("\n -- PolarMotion = x=%.13g, y=%.13g, s=%.13g\n", polarMotion->x,
+    printf("\n  -- PolarMotion = x=%.13g, y=%.13g, s=%.13g\n", polarMotion->x,
            polarMotion->y, polarMotion->s);
-    printf("  -- NutationCorr = x,y,s = %.13g, %.13g, %.13g\n", nutationCorr->x,
+    double sum;
+    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;
-    printf("\n  -- Output Earthpole = x,y,s = %.13g, %.13g, %.13g\n", polarMotion->x,
-           polarMotion->y, polarMotion->s);
     double x,y,s;
     x = -0.13275353774074533;
     y = 0.4359436319739848;
     s = -4.2376965863576153e-10;
-    printf("  -- Expected Earthpole = x,y,s = %.13g, %.13g, %.13g\n", x, y, s);
+
+    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  Precession Correction output (IERSB) = x,y,s = %.13g, %.13g, %.13g\n",
+               polarMotion->x, polarMotion->y, polarMotion->s);
+        printf("  Expected output = x,y,s = %.13g, %.13g, %.13g\n", x, y, s);
+        printf("  A difference of:   %.13g, %.13g, %.13g\n\n",
+               (polarMotion->x - x), (polarMotion->y - y), (polarMotion->s - s) );
+        return 10;
+    }
 
     if (!p_psEOCFinalize() ) {
@@ -564,7 +614,18 @@
         return 2;
     }
-    printf("Output sphere rotation = %.13g,%.13g,%.13g,%.13g\n",
-           rot->q0, rot->q1, rot->q2, rot->q3);
-    printf("Expected sphere rotation = %.13g,%.13g,%.13g,%.13g\n", q0,q1,q2,q3);
+
+    if (fabs(rot->q0-q0) > DBL_EPSILON || fabs(rot->q1-q1) > DBL_EPSILON ||
+            fabs(rot->q2-q2) > DBL_EPSILON || fabs(rot->q3-q3) > DBL_EPSILON) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psSphereRot_CEOtoGCRS failed to return expected values.\n");
+        printf("\n  Output sphere rotation   = %.13g,%.13g,%.13g,%.13g\n",
+               rot->q0, rot->q1, rot->q2, rot->q3);
+        printf("  Expected sphere rotation = %.13g,%.13g,%.13g,%.13g\n", q0,q1,q2,q3);
+        printf("  a difference:   %.13g, %.13g, %.13g, %.13g \n", (rot->q0-q0), (rot->q1-q1),
+               (rot->q2-q2), (rot->q3-q3) );
+        printf("  abs difference:   %.13g, %.13g, %.13g, %.13g \n\n", (rot->q0+q0), (rot->q1+q1),
+               (rot->q2+q2), (rot->q3+q3) );
+        return 3;
+    }
 
     psSphere *test = psSphereAlloc();
@@ -606,6 +667,5 @@
         return 2;
     }
-    printf("Output sphere rotation = %.13g,%.13g,%.13g,%.13g\n",
-           rot->q0, rot->q1, rot->q2, rot->q3);
+
     double q0,q1,q2,q3;
     q0 = -1.0567571848664005e-6;
@@ -613,5 +673,15 @@
     q2 = -3.3580195807204483e-12;
     q3 = -0.9999999999993899;
-    printf("Expected sphere rotation = %.13g,%.13g,%.13g,%.13g\n", q0,q1,q2,q3);
+    if (fabs(rot->q0-q0) > DBL_EPSILON || fabs(rot->q1-q1) > DBL_EPSILON ||
+            fabs(rot->q2-q2) > DBL_EPSILON || fabs(rot->q3-q3) > DBL_EPSILON) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psSphereRot_ITRStoTEO failed to return expected values.\n");
+        printf("\n  Output sphere rotation   = %.13g,%.13g,%.13g,%.13g\n",
+               rot->q0, rot->q1, rot->q2, rot->q3);
+        printf("  Expected sphere rotation = %.13g,%.13g,%.13g,%.13g\n", q0,q1,q2,q3);
+        printf("  a difference:   %.13g, %.13g, %.13g, %.13g \n", (rot->q0-q0), (rot->q1-q1),
+               (rot->q2-q2), (rot->q3-q3) );
+        return 3;
+    }
 
     psSphere *test = psSphereAlloc();
