- Timestamp:
- Nov 14, 2006, 11:15:43 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astro/tap_psEarthOrientation_corrections.c
r9948 r9976 18 18 #include "pstap.h" 19 19 20 static void testSphereRotCreate(void); 21 //static void testSphereRotConvert(void); 22 //static void testSphereOffsets(void); 20 static void testEOCInit(void); 21 static void testAberration(void); 22 static void testGravDef(void); 23 static void testEOC_Corrs(void); 24 25 #define MJD_1900 15021.0 // Modified Julian Day 1/1/1900 00:00:00 26 #define MJD_2100 88069.0 // Modified Julian Day 1/1/2100 00:00:00 23 27 24 28 int main(void) 25 29 { 26 plan_tests( 1);30 plan_tests(8); 27 31 28 32 diag("Tests for psEarthOrientation Correction Functions"); 29 33 30 testSphereRotCreate(); 31 // testSphereRotConvert(); 34 // Initialize library internal structures 35 psLibInit("pslib.config"); 36 37 testEOCInit(); 38 testAberration(); 39 testGravDef(); 40 testEOC_Corrs(); 32 41 // testSphereOffsets(); 42 43 // Cleanup library 44 psLibFinalize(); 33 45 34 46 done(); 35 47 } 36 48 37 void test SphereRotCreate(void)49 void testEOCInit(void) 38 50 { 39 diag(" >>>Test 1: psSphereRot Creation Functions"); 51 diag(" >>>Test 1: p_psEOCInit "); 52 //Test for psEarthPoleAlloc 53 //Return properly allocated psEarthPole 54 /* { 55 skip_start( ep == NULL, 3, 56 "Skipping 3 tests because psEarthPole is NULL!"); 57 ep = psEarthPoleAlloc(); 58 ok( ep != NULL, 59 "psEarthPoleAlloc: return properly allocated psEarthPole."); 60 psFree(ep); 61 ep = NULL; 62 } 63 */ 64 65 66 //Check for Memory leaks 67 { 68 checkMem(); 69 } 70 71 } 72 73 void testAberration(void) 74 { 75 diag(" >>>Test 2: psAberration "); 76 psSphere *apparent = NULL; 77 psSphere *empty = NULL; 78 psCube *actualCube = psCubeAlloc(); 79 //values from After gravity deflection// 80 actualCube->x = -0.35961949760293604; 81 actualCube->y = 0.5555613950298085; 82 actualCube->z = 0.7496835020836093; 83 psSphere *actual = psCubeToSphere(actualCube); 84 psCube *cubeDir = psCubeAlloc(); 85 cubeDir->x = 5148.713262821658; 86 cubeDir->y = -26945.04752348012; 87 cubeDir->z = -11682.787302030947; 88 cubeDir->x += -357.6031690489248; 89 cubeDir->y += 248.46429758174693; 90 cubeDir->z += 0.09694774143797581; 91 psSphere *direction = psCubeToSphere(cubeDir); 92 double speed = sqrt(cubeDir->x*cubeDir->x + cubeDir->y*cubeDir->y + cubeDir->z*cubeDir->z); 93 double c = 299792458.0; // Speed of light in vacuum (src:NIST) m/s 94 speed /= c; 95 96 //Tests for psAberration 97 //Return NULL for NULL actual sphere input 98 { 99 empty = psAberration(apparent, NULL, direction, speed); 100 ok( empty == NULL, 101 "psAberration: return NULL for NULL actual sphere input."); 102 } 103 //Return NULL for NULL direction sphere input 104 { 105 empty = psAberration(apparent, actual, NULL, speed); 106 ok( empty == NULL, 107 "psAberration: return NULL for NULL direction sphere input."); 108 } 109 //Return NULL for speed = 0.0 110 { 111 empty = psAberration(apparent, actual, direction, 0.0); 112 ok( empty == NULL, 113 "psAberration: return NULL for zero speed input."); 114 } 115 //Return NULL for speed > 1.0 116 { 117 empty = psAberration(apparent, actual, direction, 1.1); 118 ok( empty == NULL, 119 "psAberration: return NULL for impossible speed input (> c)."); 120 } 121 122 //Return correct values for valid inputs 123 { 124 double x, y, z; 125 x = -0.35963388069046304; 126 y = 0.5555192509816625; 127 z = 0.7497078321908413; 128 apparent = psAberration(apparent, actual, direction, speed); 129 skip_start( apparent == NULL, 3, 130 "Skipping 3 tests because psEarthPole is NULL!"); 131 psCube *outCube = psSphereToCube(apparent); 132 ok_double_tol( outCube->x, x, 0.001, 133 "psAberration: return correct sphere for valid inputs."); 134 ok_double_tol( outCube->y, y, 0.001, 135 "psAberration: return correct sphere for valid inputs."); 136 ok_double_tol( outCube->z, z, 0.001, 137 "psAberration: return correct sphere for valid inputs."); 138 psFree(outCube); 139 skip_end(); 140 } 141 142 //Check for Memory leaks 143 { 144 psFree(actualCube); 145 psFree(cubeDir); 146 psFree(apparent); 147 psFree(actual); 148 psFree(direction); 149 checkMem(); 150 } 151 152 } 153 154 void testGravDef(void) 155 { 156 diag(" >>>Test 3: psGravityDeflection "); 157 //Test for psGravityDeflection 158 //Return properly allocated psEarthPole 40 159 /* 41 //Tests for psSphereRotAlloc 42 //Return NULL for NAN input 43 { 44 psSphereRot *s1 = psSphereRotAlloc(ALPHA_P, NAN, PHI_P); 45 ok( s1 == NULL, 46 "psSphereRotAlloc: return NULL for NAN input."); 47 } 48 //Tests for psMemCheckSphereRot 49 //Make sure psMemCheckSphereRot works correctly - return false 50 { 51 int j = 2; 52 ok( !psMemCheckSphereRot(&j), 53 "psMemCheckSphereRot: return false for non-SphereRot input."); 54 skip_start( s1 == NULL, 1, 55 "Skipping 1 tests because psSphereRot is NULL!"); 56 skip_end(); 57 } 160 psSphere *apparent = NULL; 161 psSphere *empty = NULL; 162 psCube *actualCube = psCubeAlloc(); 163 actualCube->x = -0.3596195125758298; 164 actualCube->y = 0.5555613903455866; 165 actualCube->z = 0.7496834983724809; 166 psSphere *actual = psCubeToSphere(actualCube); 167 psCube *sunCube = psCubeAlloc(); 168 sunCube->x = 1.467797790127511e11; 169 sunCube->y = 2.5880956908748722e10; 170 sunCube->z = 1.1220046291457653e10; 171 double sunLength = sqrt(sunCube->x*sunCube->x + sunCube->y*sunCube->y + sunCube->z*sunCube->z); 172 sunCube->x /= sunLength; 173 sunCube->y /= sunLength; 174 sunCube->z /= sunLength; 175 if (VERBOSE) { 176 printf("sunCube = x,y,z = %.13g, %.13g, %.13g\n", 177 sunCube->x, sunCube->y, sunCube->z); 178 } 179 psSphere *sun = psCubeToSphere(sunCube); 180 if (VERBOSE) { 181 printf("sunSphere = r, d = %.13g, %.13g\n", sun->r, sun->d); 182 } 183 psCube *outCube = psCubeAlloc(); 184 185 empty = psGravityDeflection(apparent, empty, sun); 186 if (empty != NULL) { 187 psError(PS_ERR_BAD_PARAMETER_NULL, true, 188 "psGravityDeflection Failed to return NULL for NULL actual input sphere.\n"); 189 return 1; 190 } 191 empty = psGravityDeflection(apparent, actual, empty); 192 if (empty != NULL) { 193 psError(PS_ERR_BAD_PARAMETER_NULL, true, 194 "psGravityDeflection Failed to return NULL for NULL sun input sphere.\n"); 195 return 2; 196 } 197 198 apparent = psGravityDeflection(NULL, actual, sun); 199 // apparent->r *= -1.0; 200 // apparent->d *= -1.0; 201 psSphere *result2; 202 // psSphere *result2 = psSphereSetOffset(actual, apparent, PS_SPHERICAL, PS_RADIAN); 203 // psSphere *result = psSphereSetOffset(actual, apparent, PS_SPHERICAL, PS_RADIAN); 204 // psSphere *result = psSphereGetOffset(apparent, actual, PS_SPHERICAL, PS_RADIAN); 205 if (VERBOSE) { 206 printf(" -- actualCube = x,y,z = %.13g, %.13g, %.13g -- \n", 207 actualCube->x, actualCube->y, actualCube->z); 208 } 209 // psCube *outCube = psSphereToCube(result); 210 // printf(" -- resultCube = x,y,z = %.13g, %.13g, %.13g -- \n", 211 // outCube->x, outCube->y, outCube->z); 212 psCube *outCube2 = psSphereToCube(apparent); 213 if (VERBOSE) { 214 printf(" -- resultCube2= x,y,z = %.13g, %.13g, %.13g -- \n", 215 outCube2->x, outCube2->y, outCube2->z); 216 } 217 double x, y, z; 218 x = -0.35961949760293604; 219 y = 0.5555613950298085; 220 z = 0.7496835020836093; 221 222 if (VERBOSE) { 223 printf(" -- expectCube = x,y,z = %.13g, %.13g, %.13g -- \n\n", x, y, z); 224 225 // if ( fabs(x - outCube->x) > DBL_EPSILON || fabs(y - outCube->y) > DBL_EPSILON || 226 // fabs(z - outCube->z) > DBL_EPSILON ) { 227 // psError(PS_ERR_BAD_PARAMETER_VALUE, false, 228 // "psGravityDeflection returned incorrect values.\n"); 229 printf("expect-actual= x,y,z = %.13g, %.13g, %.13g \n", 230 (x - actualCube->x), (y - actualCube->y), (z - actualCube->z) ); 231 printf("expect-result= x,y,z = %.13g, %.13g, %.13g \n", 232 (x - outCube2->x), (y - outCube2->y), (z - outCube2->z) ); 233 printf("result-actual= x,y,z = %.13g, %.13g, %.13g \n", 234 (outCube2->x - actualCube->x), (outCube2->y - actualCube->y), 235 (outCube2->z - actualCube->z) ); 236 } 237 // return 1; 238 // } 239 // psFree(result2); 240 outCube2->x = x; 241 outCube2->y = y; 242 outCube2->z = z; 243 result2 = psCubeToSphere(outCube2); 244 // psFree(result); 245 psSphere *result = psSphereGetOffset(actual, result2, PS_SPHERICAL, PS_RADIAN); 246 psFree(result2); 247 result2 = psSphereGetOffset(actual, apparent, PS_SPHERICAL, PS_RADIAN); 248 if (VERBOSE) { 249 printf("The apparent output sphere = r,d = %.13g, %.13g\n", result2->r, result2->d); 250 printf("The expected output sphere = r,d = %.13g, %.13g\n\n", result->r, result->d); 251 } 252 psFree(result2); 253 254 psFree(outCube); 255 psFree(outCube2); 256 psFree(sunCube); 257 psFree(actualCube); 258 psFree(result); 259 psFree(actual); 260 psFree(apparent); 261 psFree(sun); 262 263 264 265 { 266 skip_start( ep == NULL, 3, 267 "Skipping 3 tests because psEarthPole is NULL!"); 268 ep = psEarthPoleAlloc(); 269 ok( ep != NULL, 270 "psEarthPoleAlloc: return properly allocated psEarthPole."); 271 psFree(ep); 272 ep = NULL; 273 } 58 274 */ 275 276 59 277 //Check for Memory leaks 60 278 { … … 64 282 } 65 283 66 67 284 void testEOC_Corrs(void) 285 { 286 diag(" >>>Test 4: psEOC Correction Functions"); 287 //Tests for psEOC_PrecessionCorr 288 /* 289 psTime *empty = NULL; 290 psTime *time2 = psTimeAlloc(PS_TIME_UTC); 291 time2->sec = timesec; 292 time2->nsec = 0; 293 time2->leapsecond = false; 294 // time2 = psTimeConvert(time2, PS_TIME_TAI); 295 296 //Tests for Precession Correction function// 297 //Return NULL for NULL time input 298 psEarthPole *pcorr = NULL; 299 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 300 pcorr = psEOC_PrecessionCorr(empty, PS_IERS_A); 301 if (pcorr != NULL) { 302 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 303 "psEOC_PrecessionCorr failed to return NULL for NULL time input.\n"); 304 return 5; 305 } 306 307 //Return NULL for Invalid IERS table 308 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 309 pcorr = psEOC_PrecessionCorr(time2, 3); 310 if (pcorr != NULL) { 311 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 312 "psEOC_PrecessionCorr failed to return NULL for incorrect IERS table.\n"); 313 return 6; 314 } 315 psFree(pcorr); 316 317 //Check values from IERS table A 318 pcorr = psEOC_PrecessionCorr(time2, PS_IERS_A); 319 if ( pcorr == NULL ) { 320 psError(PS_ERR_BAD_PARAMETER_NULL, false, 321 "psEOC_PrecessionCorr returned NULL for valid inputs.\n"); 322 return 7; 323 } else { 324 if (VERBOSE) { 325 printf("\nPrecessionCorr output (IERSA) = x,y,s = %.13g, %.13g, %.13g\n", 326 pcorr->x, pcorr->y, pcorr->s); 327 } 328 } 329 psFree(pcorr); 330 331 //Check values from IERS table B 332 pcorr = psEOC_PrecessionCorr(time2, PS_IERS_B); 333 if ( pcorr == NULL ) { 334 psError(PS_ERR_BAD_PARAMETER_NULL, false, 335 "psEOC_PrecessionCorr returned NULL for valid inputs.\n"); 336 return 9; 337 } else { 338 double xx, yy, ss; 339 xx = 0.06295703125; 340 yy = -0.0287618408203125; 341 ss = 0.0; 342 xx = SEC_TO_RAD(xx) * 1e-3; 343 yy = SEC_TO_RAD(yy) * 1e-3; 344 // if ( fabs(pcorr->x - xx) > DBL_EPSILON || fabs(pcorr->y - yy) > DBL_EPSILON 345 // || fabs(pcorr->s - ss) > DBL_EPSILON) { 346 // psError(PS_ERR_BAD_PARAMETER_VALUE, false, 347 // " psEOC_PrecessionCorr return incorrect values.\n"); 348 if (VERBOSE) { 349 printf("PrecessionCorr output (IERSB) = x,y,s = %.13g, %.13g, %.13g\n", 350 pcorr->x, pcorr->y, pcorr->s); 351 printf("Expected output = x,y,s = %.13g, %.13g, %.13g\n", xx, yy, ss); 352 printf(" A difference of: %.13g, %.13g, %.13g\n\n", 353 (pcorr->x - xx), (pcorr->y - yy), (pcorr->s - ss) ); 354 } 355 // return 10; 356 // } 357 } 358 //precess is the *actual* output from PrecessionModel + PrecessionCorr 359 psEarthPole *precess = psEOC_PrecessionModel(time2); 360 precess->x += pcorr->x; 361 precess->y += pcorr->y; 362 double xCorr, yCorr; 363 xCorr = 3.05224300720406e-10; 364 yCorr = -1.39441339235822e-10; 365 //pcorr is the *expected* output from PrecessionModel// 366 pcorr->x = 2.857175590089105e-4; 367 pcorr->y = 2.3968739377734732e-5; 368 pcorr->s = -1.3970066457904322e-8; 369 pcorr->x += xCorr; 370 pcorr->y += yCorr; 371 psSphereRot *precessNutInv = psSphereRot_CEOtoGCRS(precess); 372 psSphereRot *precessNut = psSphereRotConjugate(NULL, precessNutInv); 373 double q0, q1, q2; 374 q0 = -1.1984522406756289e-5; 375 q1 = 1.4285893358610674e-4; 376 q2 = 1.2191193518914336e-10; 377 psSphereRot *pni = psSphereRot_CEOtoGCRS(pcorr); 378 if (fabs(pni->q0-q0) > FLT_EPSILON || fabs(pni->q1-q1) > FLT_EPSILON || 379 fabs(pni->q2-q2) > FLT_EPSILON ) { 380 printf("\n Error at CEOtoGCRS, output psSphereRot doesn't match expected.\n"); 381 } 382 // printf(" Output from CEOtoGCRS only = %.13g,%.13g,%.13g,%.13g\n", 383 // pni->q0, pni->q1, pni->q2, pni->q3); 384 if (VERBOSE) { 385 printf(" Expected sphere rotation = %.13g, %.13g, %.13g\n", q0,q1,q2); 386 printf(" Result sphere rotation = %.13g, %.13g, %.13g\n", 387 precessNutInv->q0, precessNutInv->q1, precessNutInv->q2); 388 printf(" Difference = %.13g, %.13g, %.13g\n\n", 389 precessNutInv->q0-q0, precessNutInv->q1-q1, precessNutInv->q2-q2); 390 } 391 psCube *objC = psCubeAlloc(); 392 // objC->x = -3.5963388069046304; 393 // objC->y = 0.5555192509816625; 394 // objC->z = 0.7497078321908413; 395 // objSetup(); 396 397 //This is the sphere rotation for the *expected* precession output// 398 psSphereRot *pn = psSphereRotConjugate(NULL, pni); 399 400 // psSphere *sphere = psSphereAlloc(); 401 // *sphere = *obj; 402 // psFree(obj); 403 404 //create a psSphere for (from) the start position given in eoc_testing// 405 objC->x = -0.35963388069046304; 406 objC->y = 0.5555192509816625; 407 objC->z = 0.7497078321908413; 408 psSphere *sphere = psCubeToSphere(objC); 409 410 psSphere *expect = psSphereRotApply(NULL, pn, sphere); 411 //expected results below - stored in: sphere // 412 double x,y,z; 413 x = -0.3598480726985338; 414 y = 0.5555012823608123; 415 z = 0.7496183628158023; 416 if (VERBOSE) { 417 printf("\n<<Expected out = x,y,z = %.13g, %.13g, %.13g\n", x, y, z); 418 } 419 // psFree(objC); 420 // objC = psSphereToCube(expect); 421 //printf("<<Expected out (CEO) = x,y,z = %.13g, %.13g, %.13g\n", objC->x, objC->y, objC->z); 422 //printf(" Difference = %.13g, %.13g, %.13g\n", objC->x-x, objC->y-y, objC->z-z); 423 // x = objC->x; 424 // y = objC->y; 425 // z = objC->z; 426 psSphere *result = psSphereRotApply(NULL, precessNut, sphere); 427 psFree(objC); 428 objC = psSphereToCube(result); 429 double xx = greatCircle(result, expect); 430 if (VERBOSE) { 431 printf("<<Resulting out = x,y,z = %.13g, %.13g, %.13g\n", objC->x, objC->y, objC->z); 432 printf(" Difference = %.13g, %.13g, %.13g\n\n", 433 objC->x-x, objC->y-y, objC->z-z); 434 printf("GREAT CIRCLE DIFFERENCE = %.13g \n", xx); 435 } 436 437 psFree(precess); 438 psFree(precessNut); 439 psFree(precessNutInv); 440 psFree(expect); 441 psFree(objC); 442 443 psFree(sphere); 444 psFree(result); 445 psFree(pn); 446 psFree(pni); 447 psFree(pcorr); 448 psFree(time2); 449 if (!p_psEOCFinalize() ) { 450 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "EOC failed finalization!\n"); 451 return 12; 452 } 453 454 */ 455 456 //Tests for psEOC_PolarTideCorr 457 /* 458 psTime *in = psTimeAlloc(PS_TIME_UTC); 459 in->sec = timesec; 460 in->nsec = 0; 461 in->leapsecond = false; 462 psTime *empty = NULL; 463 psEarthPole *eop = NULL; 464 465 //Return NULL for NULL input time 466 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 467 eop = psEOC_PolarTideCorr(empty); 468 if (eop != NULL) { 469 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 470 "psEOC_PolarTideCorr failed to return NULL for NULL input time.\n"); 471 return 1; 472 } 473 474 eop = psEOC_PolarTideCorr(in); 475 if (eop == NULL) { 476 psError(PS_ERR_BAD_PARAMETER_NULL, false, 477 "psEOC_PolarTideCorr returned NULL for valid input time.\n"); 478 return 2; 479 } else { 480 if (VERBOSE) { 481 printf("\nPolarTideCorr output = x,y,s = %.13g, %.13g, %.13g\n", 482 eop->x, eop->y, eop->s); 483 } 484 } 485 486 psFree(in); 487 psFree(eop); 488 489 */ 490 491 492 493 //Tests for psEOC_NutationCorr 494 /* 495 psTime *in = psTimeAlloc(PS_TIME_UTC); 496 in->sec = timesec; 497 in->nsec = 0; 498 in->leapsecond = false; 499 psTime *empty = NULL; 500 psEarthPole *nute = NULL; 501 502 //Return NULL for NULL input time. 503 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 504 nute = psEOC_NutationCorr(empty); 505 if (nute != NULL) { 506 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 507 "psEOC_NutationCorr failed to return NULL for NULL input time.\n"); 508 return 1; 509 } 510 //Return NULL for UT1 time input 511 *//* psTime *UT1time = psTimeAlloc(PS_TIME_UT1); 512 nute = psEOC_NutationCorr(UT1time); 513 if (nute != NULL) { 514 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 515 "psEOC_NutationCorr failed to return NULL for UT1 input time.\n"); 516 return 2; 517 } 518 psFree(UT1time); 519 *//* 520 //Check return values from valid nutation time input 521 nute = psEOC_NutationCorr(in); 522 if ( nute == NULL ) { 523 psError(PS_ERR_BAD_PARAMETER_NULL, false, 524 "psEOC_NutationCorr returned NULL for valid input.\n"); 525 return 3; 526 } else { 527 if (VERBOSE) { 528 printf("Nutation Correction output = x,y,s = %.13g, %.13g, %.13g\n\n", 529 nute->x, nute->y, nute->s); 530 } 531 } 532 psFree(nute); 533 psFree(in); 534 535 if (!p_psEOCFinalize() ) { 536 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "EOC failed finalization!\n"); 537 return 12; 538 } 539 540 */ 541 //Return properly allocated psEarthPole 542 /* 543 544 545 { 546 skip_start( ep == NULL, 3, 547 "Skipping 3 tests because psEarthPole is NULL!"); 548 ep = psEarthPoleAlloc(); 549 ok( ep != NULL, 550 "psEarthPoleAlloc: return properly allocated psEarthPole."); 551 psFree(ep); 552 ep = NULL; 553 } 554 */ 555 556 557 //Check for Memory leaks 558 { 559 checkMem(); 560 } 561 562 } 563 564
Note:
See TracChangeset
for help on using the changeset viewer.
