Changeset 9976 for trunk/psLib/test/astro/tap_psEarthOrientation_motion.c
- Timestamp:
- Nov 14, 2006, 11:15:43 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astro/tap_psEarthOrientation_motion.c
r9948 r9976 4 4 * Description: Tests for psEarthPoleAlloc, psEOC_PrecessionModel, psSpherePrecess 5 5 * psSphereRot_CEOtoGCRS, psSphereRot_TEOtoCEO, 6 * psEOC_GetPolarMotion, psSphereRot_ITRStoTEO ,6 * psEOC_GetPolarMotion, psSphereRot_ITRStoTEO 7 7 * 8 8 * Author: dRob <David.Robbins@mhpcc.hpc.mil>, (C) 2006 … … 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 testPrecessionModel(void); 21 static void testPolarMotion(void); 22 static void testSphereRots(void); 23 static void testSpherePrecess(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(48); 27 31 28 32 diag("Tests for psEarthOrientation Motion Functions"); 29 33 30 testSphereRotCreate(); 31 // testSphereRotConvert(); 32 // testSphereOffsets(); 34 // Initialize library internal structures 35 psLibInit("pslib.config"); 36 37 testPrecessionModel(); 38 testPolarMotion(); 39 testSphereRots(); 40 testSpherePrecess(); 41 42 // Cleanup library 43 psLibFinalize(); 33 44 34 45 done(); 35 46 } 36 47 37 void test SphereRotCreate(void)48 void testPrecessionModel(void) 38 49 { 39 diag(" >>>Test 1: psSphereRot Creation Functions"); 50 diag(" >>>Test 1: psEOC_PrecessionModel"); 51 52 psEarthPole *ep = NULL; 53 psTime *testTime = NULL; 54 55 //Test for psEarthPoleAlloc 56 //Return properly allocated psEarthPole 57 { 58 ep = psEarthPoleAlloc(); 59 ok( ep != NULL, 60 "psEarthPoleAlloc: return properly allocated psEarthPole."); 61 psFree(ep); 62 ep = NULL; 63 } 64 //Tests for psEOC_PrecessionModel 65 //Return NULL for NULL time input. 66 { 67 ep = psEOC_PrecessionModel(NULL); 68 ok( ep == NULL, 69 "psEOC_PrecessionModel: return NULL for NULL time input."); 70 } 71 //Return NULL for UT1 time input. 72 { 73 testTime = psTimeAlloc(PS_TIME_UT1); 74 ep = psEOC_PrecessionModel(testTime); 75 ok( ep == NULL, 76 "psEOC_PrecessionModel: return NULL for UT1 time input."); 77 } 78 //Return NULL for invalid time input. 79 { 80 psFree(testTime); 81 testTime = psTimeAlloc(PS_TIME_UTC); 82 testTime->nsec = 2e9; 83 ep = psEOC_PrecessionModel(testTime); 84 ok( ep == NULL, 85 "psEOC_PrecessionModel: return NULL for invalid time input."); 86 testTime->nsec = 0; 87 } 88 //Return NULL for failed eoc init - missing file 89 // printf("\n filename = '%s' \n", p_psGetConfigFileName()); 90 { 91 testTime->sec = 1049160600; 92 testTime->nsec = 0; 93 testTime->leapsecond = false; 94 skip_start(rename("../../etc/pslib.config", "../../etc/pslib_config.bak"), 95 1, "Skipping 1 tests because file rename failed!"); 96 ep = psEOC_PrecessionModel(testTime); 97 ok( ep == NULL, 98 "psEOC_PrecessionModel: return NULL for failed eoc init."); 99 rename("../../etc/pslib_config.bak", "../../etc/pslib.config"); 100 skip_end(); 101 } 102 //Return valid EarthPole for valid time input 103 { 104 double x, y, s; 105 x = 2.857175590089105e-4; 106 y = 2.3968739377734732e-5; 107 s = -1.3970066457904322e-8; 108 ep = psEOC_PrecessionModel(testTime); 109 skip_start( ep == NULL, 3, 110 "Skipping 3 tests because psEarthPole is NULL!"); 111 ok_double_tol(ep->x, x, 0.1, 112 "psEOC_PrecessionModel: return valid EarthPole for valid inputs (x)."); 113 ok_double_tol(ep->y, y, 0.1, 114 "psEOC_PrecessionModel: return valid EarthPole for valid inputs (y)."); 115 ok_double_tol(ep->s, s, 0.1, 116 "psEOC_PrecessionModel: return valid EarthPole for valid inputs (s)."); 117 skip_end(); 118 } 119 120 40 121 /* 41 //Tests for psSphereRotAlloc42 //Return NULL for NAN input43 {44 psSphereRot *s1 = psSphereRotAlloc(ALPHA_P, NAN, PHI_P);45 ok( s1 == NULL,46 "psSphereRotAlloc: return NULL for NAN input.");47 }48 122 //Tests for psMemCheckSphereRot 49 123 //Make sure psMemCheckSphereRot works correctly - return false … … 59 133 //Check for Memory leaks 60 134 { 135 psFree(testTime); 136 psFree(ep); 61 137 checkMem(); 62 138 } … … 64 140 } 65 141 142 void testPolarMotion(void) 143 { 144 diag(" >>>Test 2: psEOC_GetPolarMotion "); 145 146 psTime *in = psTimeAlloc(PS_TIME_UTC); 147 in->sec = 1049160600; 148 in->nsec = 0; 149 in->leapsecond = false; 150 psEarthPole *polarMotion = NULL; 151 152 //Tests for psEOC_GetPolarMotion 153 //Return NULL for NULL time input. 154 { 155 polarMotion = psEOC_GetPolarMotion(NULL, PS_IERS_B); 156 ok( polarMotion == NULL, 157 "psEOC_GetPolarMotion: return NULL for NULL time input."); 158 } 159 //Return NULL for invalid IERS table input 160 { 161 polarMotion = psEOC_GetPolarMotion(NULL, PS_IERS_B+1); 162 ok( polarMotion == NULL, 163 "psEOC_GetPolarMotion: return NULL for invalid IERS table input."); 164 } 165 //Return NULL for invalid time input. 166 { 167 in->nsec = 2e9; 168 polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B); 169 ok( polarMotion == NULL, 170 "psEOC_GetPolarMotion: return NULL for invalid time input."); 171 in->nsec = 0; 172 } 173 //Return NULL for failed eoc init - missing file 174 { 175 p_psEOCFinalize(); 176 skip_start(rename("../../etc/pslib.config", "../../etc/pslib_config.bak"), 177 1, "Skipping 1 tests because file rename failed!"); 178 polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B); 179 ok( polarMotion == NULL, 180 "psEOC_GetPolarMotion: return NULL for failed eoc init."); 181 rename("../../etc/pslib_config.bak", "../../etc/pslib.config"); 182 skip_end(); 183 } 184 //Return valid EarthPole for valid time input - IERS B 185 { 186 double x, y, s; 187 x = -6.454389659777e-07; 188 y = 2.112606414597e-06; 189 s = 0.0; 190 polarMotion = psEOC_GetPolarMotion(in, PS_IERS_B); 191 skip_start( polarMotion == NULL, 3, 192 "Skipping 3 tests because psEarthPole is NULL!"); 193 ok_double_tol(polarMotion->x, x, 0.1, 194 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 195 "(x) - IERS B."); 196 ok_double_tol(polarMotion->y, y, 0.1, 197 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 198 "(y) - IERS B."); 199 ok_double_tol(polarMotion->s, s, 0.1, 200 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 201 "(s) - IERS B."); 202 skip_end(); 203 psFree(polarMotion); 204 } 205 //Return valid EarthPole for valid time input - IERS A 206 { 207 double x, y, s; 208 x = -6.45381397904e-07; 209 y = 2.112819726698e-06; 210 s = 0.0; 211 polarMotion = psEOC_GetPolarMotion(in, PS_IERS_A); 212 skip_start( polarMotion == NULL, 3, 213 "Skipping 3 tests because psEarthPole is NULL!"); 214 ok_double_tol(polarMotion->x, x, 0.1, 215 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 216 "(x) - IERS A."); 217 ok_double_tol(polarMotion->y, y, 0.1, 218 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 219 "(y) - IERS A."); 220 ok_double_tol(polarMotion->s, s, 0.1, 221 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs " 222 "(s) - IERS A."); 223 skip_end(); 224 psFree(polarMotion); 225 } 226 //Return valid EarthPole for valid time input - IERS A 227 { 228 psTime *firstTime = psTimeFromMJD(41684.50); 229 polarMotion = psEOC_GetPolarMotion(firstTime, PS_IERS_B); 230 ok( polarMotion != NULL, 231 "psEOC_GetPolarMotion: return valid EarthPole for valid inputs."); 232 psFree(firstTime); 233 } 234 235 236 //Check for Memory leaks 237 { 238 psFree(in); 239 psFree(polarMotion); 240 checkMem(); 241 } 242 243 } 244 245 static psSphere *objSetup(void) 246 { 247 psSphere *obj = NULL; 248 psCube *tempCube = psCubeAlloc(); 249 tempCube->x = -0.3598480726985338; 250 tempCube->y = 0.5555012823608123; 251 tempCube->z = 0.7496183628158023; 252 obj = psCubeToSphere(tempCube); 253 psFree(tempCube); 254 return obj; 255 } 256 257 void testSphereRots(void) 258 { 259 diag(" >>>Test 3: psSphereRot Functions"); 260 psSphereRot *out = NULL; 261 psEarthPole *in = NULL; 262 double q0,q1,q2,q3; 263 q0 = -1.1984522406756289e-5; 264 q1 = 1.4285893358610674e-4; 265 q2 = 1.2191193518914336e-10; 266 q3 = -0.9999999897238481; 267 268 //Tests for psSphereRot_CEOtoGCRS 269 //Return NULL for NULL earthPole input 270 { 271 out = psSphereRot_CEOtoGCRS(in); 272 ok( out == NULL, 273 "psSphereRot_CEOtoGCRS: return NULL for NULL earthPole input."); 274 in = psEarthPoleAlloc(); 275 } 276 in->x = 2.857175590089105e-4; 277 in->y = 2.3968739377734732e-5; 278 in->s = -1.3970066457904322e-8; 279 //Return correct psSphereRot for valid input 280 { 281 out = psSphereRot_CEOtoGCRS(in); 282 skip_start( out == NULL, 4, 283 "Skipping 4 tests because psSphereRot output is NULL!"); 284 ok_double_tol( out->q0, q0, 0.0001, 285 "psSphereRot_CEOtoGCRS: return correct psSphereRot for valid input (q0)."); 286 ok_double_tol( out->q1, q1, 0.0001, 287 "psSphereRot_CEOtoGCRS: return correct psSphereRot for valid input (q1)."); 288 ok_double_tol( out->q2, q2, 0.0001, 289 "psSphereRot_CEOtoGCRS: return correct psSphereRot for valid input (q2)."); 290 ok_double_tol( out->q3, -q3, 0.0001, 291 "psSphereRot_CEOtoGCRS: return correct psSphereRot for valid input (q3)."); 292 skip_end(); 293 } 294 295 //Tests for psSphereRot_TEOtoCEO 296 psFree(out); 297 psTime *time = psTimeAlloc(PS_TIME_UT1); 298 psTime *time2 = psTimeAlloc(PS_TIME_UTC); 299 time->sec = 1049160600-1; 300 time->nsec = 657017200; 301 time->leapsecond = false; 302 psEarthPole *temp = psEarthPoleAlloc(); 303 temp->s = -2.0; 304 //Return NULL for NULL time input 305 { 306 out = psSphereRot_TEOtoCEO(NULL, NULL); 307 ok( out == NULL, 308 "psSphereRot_TEOtoCEO: return NULL for NULL time input."); 309 } 310 //Return NULL for invalid time input - large nsec, UTC time type 311 { 312 time2->nsec = 3e9; 313 out = psSphereRot_TEOtoCEO(time2, NULL); 314 ok( out == NULL, 315 "psSphereRot_TEOtoCEO: return NULL for invalid time input."); 316 } 317 //Return NULL for invalid time input - UT1 time type, large nsec 318 { 319 psFree(time2); 320 time2 = psTimeAlloc(PS_TIME_UT1); 321 time2->nsec = 1e9; 322 temp->s = 1.0; 323 out = psSphereRot_TEOtoCEO(time2, temp); 324 ok( out == NULL, 325 "psSphereRot_TEOtoCEO: return NULL for invalid time input."); 326 } 327 //Return NULL for invalid earthPole input 328 { 329 time2->nsec = 0; 330 psEarthPole *temp = psEarthPoleAlloc(); 331 temp->s = -2.0; 332 out = psSphereRot_TEOtoCEO(time2, temp); 333 ok( out == NULL, 334 "psSphereRot_TEOtoCEO: return NULL for invalid earthPole input."); 335 } 336 //Return correct psSphereRot for valid inputs 337 double x, y, z; 338 x = 0.01698625430807123; 339 y = -0.6616523084626379; 340 z = 0.7496183628158023; 341 { 342 psEarthPole *polarTideCorr = psEOC_PolarTideCorr(time); 343 out = psSphereRot_TEOtoCEO(time, polarTideCorr); 344 skip_start( out == NULL, 3, 345 "Skipping 3 tests because psSphereRot output is NULL!"); 346 psSphere *obj = objSetup(); 347 psSphereRot *earthRot = psSphereRotConjugate(NULL, out); 348 psSphere *result = psSphereRotApply(NULL, earthRot, obj); 349 psCube *cube = psSphereToCube(result); 350 ok_double_tol( cube->x, x, 0.0001, 351 "psSphereRot_TEOtoCEO: return NULL for NULL time input. (x)"); 352 ok_double_tol( cube->y, y, 0.0001, 353 "psSphereRot_TEOtoCEO: return NULL for NULL time input. (y)"); 354 ok_double_tol( cube->z, z, 0.0001, 355 "psSphereRot_TEOtoCEO: return NULL for NULL time input. (z)"); 356 psFree(earthRot); 357 psFree(result); 358 psFree(cube); 359 psFree(obj); 360 skip_end(); 361 psFree(polarTideCorr); 362 } 363 364 //Tests for psSphereRot_ITRStoTEO 365 //Return NULL for NULL earthPole input 366 { 367 psFree(out); 368 out = psSphereRot_ITRStoTEO(NULL); 369 ok( out == NULL, 370 "psSphereRot_ITRStoTEO: return NULL for NULL earthPole input."); 371 in = psEarthPoleAlloc(); 372 } 373 //Return correct psSphereRot for valid input 374 { 375 q0 = -1.0567571848664005e-6; 376 q1 = 3.218036562931509e-7; 377 q2 = -3.3580195807204483e-12; 378 q3 = -0.9999999999993899; 379 in->x = SEC_TO_RAD(-0.13275353774074533); 380 in->y = SEC_TO_RAD(0.4359436319739848); 381 in->s = SEC_TO_RAD(-4.2376965863576153e-10); 382 out = psSphereRot_ITRStoTEO(in); 383 skip_start( out == NULL, 4, 384 "Skipping 4 tests because psSphereRot output is NULL!"); 385 ok_double_tol( out->q0, q0, 0.0001, 386 "psSphereRot_ITRStoTEO: return correct psSphereRot for valid input (q0)."); 387 ok_double_tol( out->q1, q1, 0.0001, 388 "psSphereRot_ITRStoTEO: return correct psSphereRot for valid input (q1)."); 389 ok_double_tol( out->q2, q2, 0.0001, 390 "psSphereRot_ITRStoTEO: return correct psSphereRot for valid input (q2)."); 391 ok_double_tol( out->q3, q3, 0.0001, 392 "psSphereRot_ITRStoTEO: return correct psSphereRot for valid input (q3)."); 393 skip_end(); 394 } 395 396 //Check for Memory leaks 397 { 398 psFree(temp); 399 psFree(time2); 400 psFree(time); 401 psFree(out); 402 psFree(in); 403 checkMem(); 404 } 405 } 406 407 #define SPHERE_PRECESS_TP1_R 0.0 // 0.0 degrees 408 #define SPHERE_PRECESS_TP1_D 0.0 // 0.0 degrees 409 #define SPHERE_PRECESS_TP1_EXPECT_R 6.238453 // 357.437 degrees 410 #define SPHERE_PRECESS_TP1_EXPECT_D -0.019426 // -1.113 degrees 411 #define SPHERE_PRECESS_TP2_R 0.0 // 0.0 degrees 412 #define SPHERE_PRECESS_TP2_D 1.570796 // 90.0 degrees 413 #define SPHERE_PRECESS_TP2_EXPECT_R 6.260828 // 358.719 degrees 414 #define SPHERE_PRECESS_TP2_EXPECT_D 1.551353 // 88.886 degrees 415 #define SPHERE_PRECESS_TP3_R 3.141593 // 180.0 degrees 416 #define SPHERE_PRECESS_TP3_D 0.523599 // 30.0 degrees 417 #define SPHERE_PRECESS_TP3_EXPECT_R 3.096616 // 177.423 degrees 418 #define SPHERE_PRECESS_TP3_EXPECT_D 0.543024 // 31.113 degrees 419 #define ERROR_TOL 0.0001 420 421 void testSpherePrecess(void) 422 { 423 diag(" >>>Test 4: psSpherePrecess"); 424 psSphereRot *rot = NULL; 425 psTime *fromTime = NULL; 426 psTime *toTime = NULL; 427 psSphere* inputCoord = psSphereAlloc(); 428 psSphere* outputCoord = NULL; 429 430 //Return NULL for NULL time inputs 431 { 432 rot = psSpherePrecess(fromTime, toTime, PS_PRECESS_ROUGH); 433 ok( rot == NULL, 434 "psSpherePrecess: return NULL for NULL time inputs."); 435 } 436 //Return NULL for invalid mode input 437 { 438 fromTime = psTimeFromMJD(MJD_2100); 439 toTime = psTimeFromMJD(MJD_1900); 440 rot = psSpherePrecess(fromTime, toTime, -1); 441 ok( rot == NULL, 442 "psSpherePrecess: return NULL for invalid mode input."); 443 } 444 //Return correct psSphereRot for valid inputs, mode = ROUGH 445 { 446 inputCoord->r = SPHERE_PRECESS_TP1_R; 447 inputCoord->d = SPHERE_PRECESS_TP1_D; 448 inputCoord->rErr = 0.0; 449 inputCoord->dErr = 0.0; 450 451 rot = psSpherePrecess(fromTime, toTime, PS_PRECESS_ROUGH); 452 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 453 if (outputCoord->r < -0.0001) 454 outputCoord->r += 2.0 * M_PI; 455 skip_start( rot == NULL || outputCoord == NULL, 2, 456 "Skipping 2 tests because psSphereRot output is NULL!"); 457 ok_double_tol( outputCoord->r, SPHERE_PRECESS_TP1_EXPECT_R, ERROR_TOL, 458 "psSpherePrecess: return correct psSphereRot for valid" 459 " inputs and PS_PRECESS_ROUGH mode. (r)"); 460 ok_double_tol( outputCoord->d, SPHERE_PRECESS_TP1_EXPECT_D, ERROR_TOL, 461 "psSpherePrecess: return correct psSphereRot for valid" 462 " inputs and PS_PRECESS_ROUGH mode. (d)"); 463 skip_end(); 464 psFree(outputCoord); 465 psFree(rot); 466 } 467 //Return correct psSphereRot for valid inputs, mode = ROUGH 468 { 469 inputCoord->r = SPHERE_PRECESS_TP2_R; 470 inputCoord->d = SPHERE_PRECESS_TP2_D; 471 inputCoord->rErr = 0.0; 472 inputCoord->dErr = 0.0; 473 474 rot = psSpherePrecess(fromTime, toTime, PS_PRECESS_ROUGH); 475 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 476 if (outputCoord->r < -0.0001) 477 outputCoord->r += 2.0 * M_PI; 478 skip_start( rot == NULL || outputCoord == NULL, 2, 479 "Skipping 2 tests because psSphereRot output is NULL!"); 480 ok_double_tol( outputCoord->r, SPHERE_PRECESS_TP2_EXPECT_R, ERROR_TOL, 481 "psSpherePrecess: return correct psSphereRot for valid" 482 " inputs and PS_PRECESS_ROUGH mode. (r)"); 483 ok_double_tol( outputCoord->d, SPHERE_PRECESS_TP2_EXPECT_D, ERROR_TOL, 484 "psSpherePrecess: return correct psSphereRot for valid" 485 " inputs and PS_PRECESS_ROUGH mode. (d)"); 486 skip_end(); 487 psFree(outputCoord); 488 psFree(rot); 489 } 490 //Return correct psSphereRot for valid inputs, mode = ROUGH 491 { 492 inputCoord->r = SPHERE_PRECESS_TP3_R; 493 inputCoord->d = SPHERE_PRECESS_TP3_D; 494 inputCoord->rErr = 0.0; 495 inputCoord->dErr = 0.0; 496 497 rot = psSpherePrecess(fromTime, toTime, PS_PRECESS_ROUGH); 498 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 499 if (outputCoord->r < -0.0001) 500 outputCoord->r += 2.0 * M_PI; 501 skip_start( rot == NULL || outputCoord == NULL, 2, 502 "Skipping 2 tests because psSphereRot output is NULL!"); 503 ok_double_tol( outputCoord->r, SPHERE_PRECESS_TP3_EXPECT_R, ERROR_TOL, 504 "psSpherePrecess: return correct psSphereRot for valid" 505 " inputs and PS_PRECESS_ROUGH mode. (r)"); 506 ok_double_tol( outputCoord->d, SPHERE_PRECESS_TP3_EXPECT_D, ERROR_TOL, 507 "psSpherePrecess: return correct psSphereRot for valid" 508 " inputs and PS_PRECESS_ROUGH mode. (d)"); 509 skip_end(); 510 psFree(outputCoord); 511 psFree(rot); 512 } 513 //Return correct psSphereRot for valid inputs, mode = COMPLETE_A 514 { 515 rot = psSpherePrecess(NULL, toTime, PS_PRECESS_COMPLETE_A); 516 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 517 ok( outputCoord != NULL && rot != NULL, 518 "psSpherePrecess: return correct psSphereRot for valid" 519 " inputs and PS_PRECESS_COMPLETE_A mode."); 520 psFree(outputCoord); 521 psFree(rot); 522 } 523 //Return correct psSphereRot for valid inputs, mode = COMPLETE_B 524 { 525 rot = psSpherePrecess(NULL, toTime, PS_PRECESS_COMPLETE_B); 526 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 527 ok( outputCoord != NULL && rot != NULL, 528 "psSpherePrecess: return correct psSphereRot for valid" 529 " inputs and PS_PRECESS_COMPLETE_B mode."); 530 psFree(outputCoord); 531 psFree(rot); 532 } 533 //Return correct psSphereRot for valid inputs, mode = IAU2000A 534 { 535 rot = psSpherePrecess(NULL, toTime, PS_PRECESS_IAU2000A); 536 outputCoord = psSphereRotApply(NULL, rot, inputCoord); 537 ok( outputCoord != NULL && rot != NULL, 538 "psSpherePrecess: return correct psSphereRot for valid" 539 " inputs and PS_PRECESS_IAU2000A mode."); 540 } 541 542 //Check for Memory leaks 543 { 544 psFree(fromTime); 545 psFree(toTime); 546 psFree(outputCoord); 547 psFree(rot); 548 checkMem(); 549 } 550 551 } 552 553
Note:
See TracChangeset
for help on using the changeset viewer.
