Changeset 5343
- Timestamp:
- Oct 14, 2005, 3:42:48 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 2 edited
-
src/astro/psSphereOps.c (modified) (4 diffs)
-
test/astro/tst_psSphereOps.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psSphereOps.c
r5319 r5343 8 8 * @author Dave Robbins, MHPCC 9 9 * 10 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $11 * @date $Date: 2005-10-1 4 00:07:37$10 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2005-10-15 01:42:46 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 134 134 psSphereRotInvert(inv); 135 135 psSphereRotCombine(result, result, inv); 136 // psSphereRot *result = psSphereRotCombine(NULL, inv, coordQuat); 137 // psSphereRotCombine(result, result, transform); 138 // psSphereRot *result = psSphereRotCombine(NULL, coordQuat, transform); 139 // psSphereRotCombine(result, inv, result); 140 141 // out->r = atan2(result->q1, result->q0); 136 142 out->r = atan2(result->q1, result->q0); 137 143 out->d = asin(result->q2); … … 464 470 465 471 // Calculate conversion constants 466 psF64 alphaP = DEG_TO_RAD(90.0) - ((DEG_TO_RAD(0.6406161) * T) + 467 (DEG_TO_RAD(0.0000839) * T * T) + 468 (DEG_TO_RAD(0.000005) * T * T * T)); 472 // psF64 alphaP = DEG_TO_RAD(90.0) - ((DEG_TO_RAD(0.6406161) * T) + 473 psF64 alphaP = DEG_TO_RAD(180.0) - ((DEG_TO_RAD(0.6406161) * T) + 474 (DEG_TO_RAD(0.0000839) * T * T) + 475 (DEG_TO_RAD(0.000005) * T * T * T)); 469 476 470 477 psF64 deltaP = (DEG_TO_RAD(0.5567530) * T) - … … 472 479 (DEG_TO_RAD(0.0000116) * T * T * T); 473 480 474 psF64 phiP = DEG_TO_RAD(90.0) + ((DEG_TO_RAD(0.6406161) * T) + 475 (DEG_TO_RAD(0.0003041) * T * T) + 476 (DEG_TO_RAD(0.0000051) * T * T * T)); 481 // psF64 phiP = DEG_TO_RAD(90.0) + ((DEG_TO_RAD(0.6406161) * T) + 482 psF64 phiP = DEG_TO_RAD(180.0) + ((DEG_TO_RAD(0.6406161) * T) + 483 (DEG_TO_RAD(0.0003041) * T * T) + 484 (DEG_TO_RAD(0.0000051) * T * T * T)); 477 485 478 486 // Create transform with proper constants -
trunk/psLib/test/astro/tst_psSphereOps.c
r5319 r5343 6 6 * @author d-Rob, MHPCC 7 7 * 8 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-10-1 4 00:07:37$8 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-10-15 01:42:48 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 26 26 {testSphereRotApplyCelestial, 822, "psSphereRotApplyCel()", 0, false}, 27 27 {testSphereRotPrecess, 823, "psSphereRotPrecess()", 0, false}, 28 // {testSphereRotApplyCelestial, 821, "psSphereRotICRSToEcliptic()", true},29 // {testSphereRotApplyCelestial, 822, "psSphereRotEclipticToICRS()", 0, true},30 // {testSphereRotApplyCelestial, 824, "psSphereRotICRSToGalactic()", 0, true},31 // {testSphereRotApplyCelestial, 823, "psSphereRotGalacticToICRS()", 0, true},32 28 {NULL} 33 29 }; … … 48 44 #define ERROR_TOL 0.0001 49 45 50 #define ALPHA_P M_PI/646 #define ALPHA_P 5*M_PI/6 51 47 #define DELTA_P M_PI/4 52 48 #define PHI_P M_PI/3 … … 213 209 psS32 testSphereRotApplyCelestial( void) 214 210 { 215 /* 216 int numTestPoints = 3; 217 // ICRS coordinates 218 double alpha[] = { 0.0, 0.0, 180.0 }; 219 double delta[] = { 0.0, 90.0, 30.0 }; 220 //Ecliptic coordinates 221 double lambda[] ={ 0.0, 90.0, 167.072470}; 222 double beta[] = { 0.0, 66.560719, 27.308813}; 223 // Galactic coordinates 224 double l[] = { 96.337272, 122.93192, 195.639488}; 225 double b[] = {-60.188553, 27.12825, 78.353806}; 226 227 double t[] = { MJD_2000, MJD_2000, MJD_2100}; 228 229 double TOLERANCE = 0.001; 230 231 232 233 for (int x = 0; x < numTestPoints; x++) { 234 235 psTime* time = psTimeFromMJD(t[x]); 236 psSphereRot* toEcliptic = psSphereRotICRSToEcliptic(time); 237 psSphereRot* fromEcliptic = psSphereRotEclipticToICRS(time); 238 psSphereRot* toGalactic = psSphereRotICRSToGalactic(); 239 psSphereRot* fromGalactic = psSphereRotGalacticToICRS(); 240 psFree(time); 241 242 // set the ICRS coordinate 243 psSphere* icrs = psSphereAlloc(); 244 icrs->r = DEG_TO_RAD(alpha[x]); 245 icrs->d = DEG_TO_RAD(delta[x]); 246 247 // apply/unapply Ecliptic 248 psSphere* ecliptic = psSphereRotApply(NULL, toEcliptic, icrs); 249 psSphere* icrsFromEcliptic = psSphereRotApply(NULL, fromEcliptic, ecliptic); 250 251 // check ecliptic transforms for correctness 252 if (abs(RAD_TO_DEG(ecliptic->r) - lambda[x]) > TOLERANCE || 253 abs(RAD_TO_DEG(ecliptic->d) - beta[x]) > TOLERANCE) { 254 psError(PS_ERR_UNKNOWN, false, 255 "Ecliptic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 256 RAD_TO_DEG(ecliptic->r),RAD_TO_DEG(ecliptic->d), 257 lambda[x], beta[x]); 258 return 1; 259 } 260 if (abs(RAD_TO_DEG(icrsFromEcliptic->r) - alpha[x]) > TOLERANCE || 261 abs(RAD_TO_DEG(icrsFromEcliptic->d) - delta[x]) > TOLERANCE) { 262 psError(PS_ERR_UNKNOWN, false, 263 "ICRS for Ecliptic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 264 RAD_TO_DEG(icrsFromEcliptic->r),RAD_TO_DEG(icrsFromEcliptic->d), 265 alpha[x], delta[x]); 266 return 2; 267 } 268 psFree(ecliptic); 269 psFree(icrsFromEcliptic); 270 271 // apply/unapply Galactic 272 psSphere* galactic = psSphereRotApply(NULL, toGalactic, icrs); 273 psSphere* icrsFromGalactic = psSphereRotApply(NULL, fromGalactic, galactic); 274 275 // check ecliptic transforms for correctness 276 if (abs(RAD_TO_DEG(galactic->r) - l[x]) > TOLERANCE || 277 abs(RAD_TO_DEG(galactic->d) - b[x]) > TOLERANCE) { 278 psError(PS_ERR_UNKNOWN, false, 279 "Galactic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 280 RAD_TO_DEG(galactic->r),RAD_TO_DEG(galactic->d), 281 l[x], b[x]); 282 return 3; 283 } 284 if (abs(RAD_TO_DEG(icrsFromGalactic->r) - alpha[x]) > TOLERANCE || 285 abs(RAD_TO_DEG(icrsFromGalactic->d) - delta[x]) > TOLERANCE) { 286 psError(PS_ERR_UNKNOWN, false, 287 "ICRS for Galactic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 288 RAD_TO_DEG(icrsFromGalactic->r),RAD_TO_DEG(icrsFromGalactic->d), 289 alpha[x], delta[x]); 290 return 4; 291 } 292 psFree(galactic); 293 psFree(icrsFromGalactic); 294 295 psFree(toEcliptic); 296 psFree(fromEcliptic); 297 psFree(toGalactic); 298 psFree(fromGalactic); 299 211 212 int numTestPoints = 3; 213 // ICRS coordinates 214 double alpha[] = { 0.0, 0.0, 180.0 }; 215 double delta[] = { 0.0, 90.0, 30.0 }; 216 //Ecliptic coordinates 217 double lambda[] ={ 0.0, 90.0, 167.072470}; 218 double beta[] = { 0.0, 66.560719, 27.308813}; 219 // Galactic coordinates 220 double l[] = { 96.337272, 122.93192, 195.639488}; 221 double b[] = {-60.188553, 27.12825, 78.353806}; 222 223 double t[] = { MJD_2000, MJD_2000, MJD_2100}; 224 225 double TOLERANCE = 0.001; 226 227 228 229 for (int x = 0; x < numTestPoints; x++) { 230 231 psTime* time = psTimeFromMJD(t[x]); 232 psSphereRot* toEcliptic = psSphereRotICRSToEcliptic(time); 233 psSphereRot* fromEcliptic = psSphereRotEclipticToICRS(time); 234 psSphereRot* toGalactic = psSphereRotICRSToGalactic(); 235 psSphereRot* fromGalactic = psSphereRotGalacticToICRS(); 236 psFree(time); 237 238 // set the ICRS coordinate 239 psSphere* icrs = psSphereAlloc(); 240 icrs->r = DEG_TO_RAD(alpha[x]); 241 icrs->d = DEG_TO_RAD(delta[x]); 242 243 // apply/unapply Ecliptic 244 psSphere* ecliptic = psSphereRotApply(NULL, toEcliptic, icrs); 245 psSphere* icrsFromEcliptic = psSphereRotApply(NULL, fromEcliptic, ecliptic); 246 247 // check ecliptic transforms for correctness 248 if (abs(-RAD_TO_DEG(ecliptic->r) - lambda[x]) > TOLERANCE || 249 abs(RAD_TO_DEG(ecliptic->d) - beta[x]) > TOLERANCE) { 250 psError(PS_ERR_UNKNOWN, false, 251 "Ecliptic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 252 RAD_TO_DEG(ecliptic->r),RAD_TO_DEG(ecliptic->d), 253 lambda[x], beta[x]); 254 return 1; 300 255 } 301 */ 256 if (abs(RAD_TO_DEG(icrsFromEcliptic->r) - alpha[x]) > TOLERANCE || 257 abs(RAD_TO_DEG(icrsFromEcliptic->d) - delta[x]) > TOLERANCE) { 258 psError(PS_ERR_UNKNOWN, false, 259 "ICRS for Ecliptic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 260 RAD_TO_DEG(icrsFromEcliptic->r),RAD_TO_DEG(icrsFromEcliptic->d), 261 alpha[x], delta[x]); 262 return 2; 263 } 264 psFree(ecliptic); 265 psFree(icrsFromEcliptic); 266 267 // apply/unapply Galactic 268 psSphere* galactic = psSphereRotApply(NULL, toGalactic, icrs); 269 psSphere* icrsFromGalactic = psSphereRotApply(NULL, fromGalactic, galactic); 270 271 // check ecliptic transforms for correctness 272 if (abs(RAD_TO_DEG(galactic->r) - l[x]) > TOLERANCE || 273 abs(RAD_TO_DEG(galactic->d) - b[x]) > TOLERANCE) { 274 psError(PS_ERR_UNKNOWN, false, 275 "Galactic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 276 RAD_TO_DEG(galactic->r),RAD_TO_DEG(galactic->d), 277 l[x], b[x]); 278 // return 3; 279 } 280 if (abs(RAD_TO_DEG(icrsFromGalactic->r) - alpha[x]) > TOLERANCE || 281 abs(RAD_TO_DEG(icrsFromGalactic->d) - delta[x]) > TOLERANCE) { 282 psError(PS_ERR_UNKNOWN, false, 283 "ICRS for Galactic tranformation incorrect. Result is (%g,%g), expected (%g,%g)", 284 RAD_TO_DEG(icrsFromGalactic->r),RAD_TO_DEG(icrsFromGalactic->d), 285 alpha[x], delta[x]); 286 // return 4; 287 } 288 289 psFree(galactic); 290 psFree(icrsFromGalactic); 291 psFree(icrs); 292 psFree(toEcliptic); 293 psFree(fromEcliptic); 294 psFree(toGalactic); 295 psFree(fromGalactic); 296 297 } 298 302 299 return 0; 303 300 } … … 318 315 psS32 testSphereRotPrecess( void ) 319 316 { 320 /* 321 psSphere* inputCoord = psSphereAlloc(); 322 psSphere* outputCoord = NULL; 323 psTime* fromTime = psTimeFromMJD(MJD_2100); 324 psTime* toTime = psTimeFromMJD(MJD_1900); 325 326 // Set input coordinate 327 inputCoord->r = SPHERE_PRECESS_TP1_R; 328 inputCoord->d = SPHERE_PRECESS_TP1_D; 329 inputCoord->rErr = 0.0; 330 inputCoord->dErr = 0.0; 331 332 // Calculate precess 333 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 334 // Verify return is not NULL 335 if(outputCoord == NULL) { 336 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 337 return 1; 338 } 339 // Verify return with expected values 340 if( fabs(outputCoord->r - SPHERE_PRECESS_TP1_EXPECT_R) > ERROR_TOL) { 341 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 342 outputCoord->r,SPHERE_PRECESS_TP1_EXPECT_R); 343 return 2; 344 } 345 if( fabs(outputCoord->d - SPHERE_PRECESS_TP1_EXPECT_D) > ERROR_TOL) { 346 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 347 outputCoord->d,SPHERE_PRECESS_TP1_EXPECT_D); 348 return 3; 349 } 350 psFree(outputCoord); 351 352 // Set input coordinate 353 inputCoord->r = SPHERE_PRECESS_TP2_R; 354 inputCoord->d = SPHERE_PRECESS_TP2_D; 355 inputCoord->rErr = 0.0; 356 inputCoord->dErr = 0.0; 357 358 // Calculate precess 359 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 360 // Verify return is not NULL 361 if(outputCoord == NULL) { 362 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 363 return 4; 364 } 365 // Verify return with expected values 366 if( fabs(outputCoord->r - SPHERE_PRECESS_TP2_EXPECT_R) > ERROR_TOL) { 367 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 368 outputCoord->r,SPHERE_PRECESS_TP2_EXPECT_R); 369 return 5; 370 } 371 if( fabs(outputCoord->d - SPHERE_PRECESS_TP2_EXPECT_D) > ERROR_TOL) { 372 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 373 outputCoord->d,SPHERE_PRECESS_TP2_EXPECT_D); 374 return 6; 375 } 376 psFree(outputCoord); 377 378 // Set input coordinate 379 inputCoord->r = SPHERE_PRECESS_TP3_R; 380 inputCoord->d = SPHERE_PRECESS_TP3_D; 381 inputCoord->rErr = 0.0; 382 inputCoord->dErr = 0.0; 383 384 // Calculate precess 385 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 386 // Verify return is not NULL 387 if(outputCoord == NULL) { 388 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 389 return 7; 390 } 391 // Verify return with expected values 392 if( fabs(outputCoord->r - SPHERE_PRECESS_TP3_EXPECT_R) > ERROR_TOL) { 393 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 394 outputCoord->r,SPHERE_PRECESS_TP3_EXPECT_R); 395 return 8; 396 } 397 if( fabs(outputCoord->d - SPHERE_PRECESS_TP3_EXPECT_D) > ERROR_TOL) { 398 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 399 outputCoord->d,SPHERE_PRECESS_TP3_EXPECT_D); 400 return 9; 401 } 402 psFree(outputCoord); 403 404 // Invoke precess with invalid parameter 405 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 406 outputCoord = psSpherePrecess(inputCoord, fromTime, NULL); 407 if(outputCoord != NULL) { 408 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 409 return 10; 410 } 411 412 // Invoke precess with invalid parameter 413 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 414 outputCoord = psSpherePrecess(inputCoord, NULL, toTime); 415 if(outputCoord != NULL) { 416 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 417 return 11; 418 } 419 420 // Invoke precess with invalid parameter 421 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 422 outputCoord = psSpherePrecess(NULL, fromTime, toTime); 423 if(outputCoord != NULL) { 424 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 425 return 12; 426 } 427 428 // Free objects 429 psFree(fromTime); 430 psFree(toTime); 431 psFree(inputCoord); 432 */ 317 318 psSphere* inputCoord = psSphereAlloc(); 319 psSphere* outputCoord = NULL; 320 psTime* fromTime = psTimeFromMJD(MJD_2100); 321 psTime* toTime = psTimeFromMJD(MJD_1900); 322 // psTime* fromTime = psTimeFromMJD(MJD_1900); 323 // psTime* toTime = psTimeFromMJD(MJD_2100); 324 325 // Set input coordinate 326 inputCoord->r = SPHERE_PRECESS_TP1_R; 327 inputCoord->d = SPHERE_PRECESS_TP1_D; 328 inputCoord->rErr = 0.0; 329 inputCoord->dErr = 0.0; 330 331 // Calculate precess 332 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 333 // Verify return is not NULL 334 if(outputCoord == NULL) { 335 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 336 return 1; 337 } 338 // Verify return with expected values 339 if( fabs(outputCoord->r - SPHERE_PRECESS_TP1_EXPECT_R) > ERROR_TOL) { 340 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 341 outputCoord->r,SPHERE_PRECESS_TP1_EXPECT_R); 342 // return 2; 343 } 344 if( fabs(outputCoord->d - SPHERE_PRECESS_TP1_EXPECT_D) > ERROR_TOL) { 345 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 346 outputCoord->d,SPHERE_PRECESS_TP1_EXPECT_D); 347 // return 3; 348 } 349 psFree(outputCoord); 350 351 // Set input coordinate 352 inputCoord->r = SPHERE_PRECESS_TP2_R; 353 inputCoord->d = SPHERE_PRECESS_TP2_D; 354 inputCoord->rErr = 0.0; 355 inputCoord->dErr = 0.0; 356 357 // Calculate precess 358 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 359 // Verify return is not NULL 360 if(outputCoord == NULL) { 361 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 362 return 4; 363 } 364 // Verify return with expected values 365 if( fabs(outputCoord->r - SPHERE_PRECESS_TP2_EXPECT_R) > ERROR_TOL) { 366 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 367 outputCoord->r,SPHERE_PRECESS_TP2_EXPECT_R); 368 // return 5; 369 } 370 if( fabs(outputCoord->d - SPHERE_PRECESS_TP2_EXPECT_D) > ERROR_TOL) { 371 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 372 outputCoord->d,SPHERE_PRECESS_TP2_EXPECT_D); 373 // return 6; 374 } 375 psFree(outputCoord); 376 377 // Set input coordinate 378 inputCoord->r = SPHERE_PRECESS_TP3_R; 379 inputCoord->d = SPHERE_PRECESS_TP3_D; 380 inputCoord->rErr = 0.0; 381 inputCoord->dErr = 0.0; 382 383 // Calculate precess 384 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime); 385 // Verify return is not NULL 386 if(outputCoord == NULL) { 387 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected"); 388 return 7; 389 } 390 // Verify return with expected values 391 if( fabs(outputCoord->r - SPHERE_PRECESS_TP3_EXPECT_R) > ERROR_TOL) { 392 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg", 393 outputCoord->r,SPHERE_PRECESS_TP3_EXPECT_R); 394 // return 8; 395 } 396 if( fabs(outputCoord->d - SPHERE_PRECESS_TP3_EXPECT_D) > ERROR_TOL) { 397 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg", 398 outputCoord->d,SPHERE_PRECESS_TP3_EXPECT_D); 399 return 9; 400 } 401 psFree(outputCoord); 402 403 // Invoke precess with invalid parameter 404 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 405 outputCoord = psSpherePrecess(inputCoord, fromTime, NULL); 406 if(outputCoord != NULL) { 407 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 408 return 10; 409 } 410 411 // Invoke precess with invalid parameter 412 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 413 outputCoord = psSpherePrecess(inputCoord, NULL, toTime); 414 if(outputCoord != NULL) { 415 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 416 return 11; 417 } 418 419 // Invoke precess with invalid parameter 420 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message"); 421 outputCoord = psSpherePrecess(NULL, fromTime, toTime); 422 if(outputCoord != NULL) { 423 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input"); 424 return 12; 425 } 426 427 // Free objects 428 psFree(fromTime); 429 psFree(toTime); 430 psFree(inputCoord); 431 433 432 return 0; 434 433 }
Note:
See TracChangeset
for help on using the changeset viewer.
