Changeset 4601 for trunk/psLib/test/astro/tst_psCoord.c
- Timestamp:
- Jul 22, 2005, 4:44:50 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/astro/tst_psCoord.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astro/tst_psCoord.c
r4581 r4601 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $9 * @date $Date: 2005-07-2 0 01:21:13$8 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2005-07-23 02:44:09 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 14 14 #include "psTest.h" 15 15 #include "pslib_strict.h" 16 static psS32 testSphereRotAlloc(void);17 16 static psS32 testPlaneTransformAlloc(void); 18 17 static psS32 testPlaneDistortAlloc(void); 19 18 static psS32 testPlaneTransformApply(void); 20 19 static psS32 testPlaneDistortApply(void); 21 static psS32 testSphereRotApply1(void); 22 static psS32 testSphereRotApply2(void); 23 static psS32 testSphereRotApply3(void); 24 static psS32 testSphereRotApply4(void); 25 static psS32 testSphereRotApply5(void); 26 static psS32 testSphereRotICRSToEcliptic(void); 27 static psS32 testSphereRotEclipticToICRS(void); 28 static psS32 testSphereRotICRSToGalactic(void); 29 static psS32 testSphereRotGalacticToICRS(void); 30 static psS32 testSphereRotPrecess(void); 20 31 21 testDescription tests[] = { 32 {testSphereRotAlloc, 819, "psSphereRotAlloc()", 0, false},33 22 {testPlaneTransformAlloc, 826, "psPlaneTransformAlloc()", 0, false}, 34 23 {testPlaneDistortAlloc, 827, "psPlaneDistortAlloc()", 0, false}, 35 24 {testPlaneTransformApply, 831, "psPlaneTransformApply()", 0, false}, 36 25 {testPlaneDistortApply, 832, "psPlaneDistortApply()", 0, false}, 37 {testSphereRotApply1, 820, "psSphereRotApply()", 0, false},38 {testSphereRotApply2, 820, "psSphereRotApply()", 0, false},39 {testSphereRotApply3, 820, "psSphereRotApply()", 0, false},40 {testSphereRotApply4, 820, "psSphereRotApply()", 0, false},41 {testSphereRotApply5, 820, "psSphereRotApply()", 0, false},42 {testSphereRotICRSToEcliptic, 821, "psSphereRotICRSToEcliptic()", 0, false},43 {testSphereRotEclipticToICRS, 822, "psSphereRotEclipticToICRS()", 0, false},44 {testSphereRotICRSToGalactic, 824, "psSphereRotICRSToGalactic()", 0, false},45 {testSphereRotGalacticToICRS, 823, "psSphereRotGalacticToICRS()", 0, false},46 {testSphereRotPrecess, 825, "psSphereRotPrecess()", 0, false},47 26 {NULL} 48 27 }; … … 53 32 54 33 return ( ! runTestSuite( stderr, "psCoord", tests, argc, argv ) ); 55 }56 57 #define DEG_INC 30.058 59 #define MJD_1900 15021.0 // Modified Julian Day 1/1/1900 00:00:0060 #define MJD_2000 51544.0 // Modified Julian Day 1/1/2000 00:00:0061 #define MJD_2100 88069.0 // Modified Julian Day 1/1/2100 00:00:0062 63 #define ERROR_TOL 0.000164 65 #define ALPHA_P 1.066 #define DELTA_P 2.067 #define PHI_P 3.068 69 psS32 testSphereRotAlloc( void )70 {71 // Allocate data structure72 psSphereRot* myST = psSphereRotAlloc(ALPHA_P, DELTA_P, PHI_P);73 74 // Verify null not returned75 if(myST == NULL) {76 psError(PS_ERR_UNKNOWN,true,"Returned NULL with valid parameters");77 return 1;78 }79 // Verify sin member is updated80 double vx = cos(DELTA_P)*cos(ALPHA_P);81 double vy = cos(DELTA_P)*sin(ALPHA_P);82 double vz = sin(DELTA_P);83 double q0 = vx * sin(PHI_P/2.0);84 double q1 = vy * sin(PHI_P/2.0);85 double q2 = vz * sin(PHI_P/2.0);86 double q3 = cos(PHI_P/2.0);87 88 if (FLT_EPSILON < fabs(q0 - myST->q0)) {89 psError(PS_ERR_UNKNOWN,true,"myST->q0 is %f, should be %f\n", myST->q0, q0);90 return 2;91 }92 if (FLT_EPSILON < fabs(q1 - myST->q1)) {93 psError(PS_ERR_UNKNOWN,true,"myST->q1 is %f, should be %f\n", myST->q1, q1);94 return 3;95 }96 if (FLT_EPSILON < fabs(q2 - myST->q2)) {97 psError(PS_ERR_UNKNOWN,true,"myST->q2 is %f, should be %f\n", myST->q2, q2);98 return 4;99 }100 if (FLT_EPSILON < fabs(q3 - myST->q3)) {101 psError(PS_ERR_UNKNOWN,true,"myST->q0 is %f, should be %f\n", myST->q3, q3);102 return 5;103 }104 105 // Free data structure106 psFree(myST);107 108 return 0;109 34 } 110 35 … … 445 370 } 446 371 447 // We do a simple identity transformation on a few RA, DEC pairs.448 psS32 testSphereRotApply1( void )449 {450 psSphere *in = psSphereAlloc();451 psSphere *out = psSphereAlloc();452 psSphere *temp = NULL;453 psSphere *rc = NULL;454 psSphereRot *myST = psSphereRotAlloc(0.0, 0.0, 0.0);455 456 for (float r=0.0;r<180.0;r+=DEG_INC) {457 for (float d=0.0;d<90.0;d+=DEG_INC) {458 in->r = DEG_TO_RAD(r);459 in->d = DEG_TO_RAD(d);460 in->rErr = 0.0;461 in->dErr = 0.0;462 463 if(psSphereRotApply(out, myST, in) != out) {464 psError(PS_ERR_UNKNOWN,true,"Did not return output pointer.");465 return 1;466 }467 if (ERROR_TOL < fabs(out->r - in->r)) {468 psError(PS_ERR_UNKNOWN,true,"out->r is %f, should be %f\n", out->r, in->r);469 return 2;470 }471 if (ERROR_TOL < fabs(out->d - in->d)) {472 psError(PS_ERR_UNKNOWN,true,"out->d is %f, should be %f\n", out->d, in->d);473 return 3;474 }475 }476 }477 478 // Verify new sphere object is created if out parameter NULL479 temp = psSphereRotApply(NULL, myST, in);480 if ( temp == NULL) {481 psError(PS_ERR_UNKNOWN,true,"Returned NULL when out parameter was null");482 return 4;483 }484 psFree(temp);485 486 // Verify NULL returned if transform structure null487 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");488 rc = psSphereRotApply(NULL, NULL, in);489 if (rc != NULL) {490 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL.");491 return 5;492 }493 494 // Verify NULL returned when input sphere is NULL495 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error");496 rc = psSphereRotApply(NULL, myST, NULL);497 if (rc != NULL) {498 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply() did not return NULL");499 return 6;500 }501 502 psFree(myST);503 psFree(out);504 psFree(in);505 506 return 0;507 }508 509 /******************************************************************************510 testSphereRotApply2(): This test verifies that psSphereRotApply()511 works properly. We create two psSphereRots: a forward transform and a512 reverse transform (which is the mathematical inverse of the forward transform).513 We apply both transforms to several spherical coordinates and ensure that the514 original input coordinate is obtained after applying both transforms.515 516 XXX: We currently test the alpha and delta offsets independently. Attempts to517 test them both concurrently failed. Determine why this is. Are the following518 spherical transforms not mathematical inverses?519 psSphereRotAlloc(X, Y, 0.0)520 psSphereRotAlloc(-X, -Y, 0.0)521 *****************************************************************************/522 #define ERROR_PERCENT 0.01523 psS32 testSphereRotApply2( void )524 {525 psS32 testStatus = 0;526 psSphere in;527 psSphere out;528 psSphere out2;529 psSphereRot *mySphereRotForward = NULL;530 psSphereRot *mySphereRotReverse = NULL;531 532 533 mySphereRotForward = psSphereRotAlloc(DEG_TO_RAD(22.0),534 0.0,535 0.0);536 mySphereRotReverse = psSphereRotAlloc(DEG_TO_RAD(-22.0),537 0.0,538 0.0);539 540 for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) {541 for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) {542 in.r = DEG_TO_RAD(r);543 in.d = DEG_TO_RAD(d);544 in.rErr = 0.0;545 in.dErr = 0.0;546 547 psSphereRotApply(&out, mySphereRotForward, &in);548 psSphereRotApply(&out2, mySphereRotReverse, &out);549 550 if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) ||551 (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) {552 printf("ERROR: \n");553 printf("Input coords (R, D) are (%f, %f)\n", in.r, in.d);554 printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d);555 testStatus = 4;556 }557 }558 }559 psFree(mySphereRotForward);560 psFree(mySphereRotReverse);561 562 mySphereRotForward = psSphereRotAlloc(0.0,563 DEG_TO_RAD(33.0),564 0.0);565 mySphereRotReverse = psSphereRotAlloc(0.0,566 DEG_TO_RAD(-33.0),567 0.0);568 for (float r=0.1;r<180.0;r+=(DEG_INC/5.0)) {569 for (float d=0.1;d<90.0;d+=(DEG_INC/5.0)) {570 in.r = DEG_TO_RAD(r);571 in.d = DEG_TO_RAD(d);572 in.rErr = 0.0;573 in.dErr = 0.0;574 575 psSphereRotApply(&out, mySphereRotForward, &in);576 psSphereRotApply(&out2, mySphereRotReverse, &out);577 578 if ((fabs((in.r - out2.r) / in.r) > ERROR_PERCENT) ||579 (fabs((in.d - out2.d) / in.d) > ERROR_PERCENT)) {580 printf("ERROR: \n");581 printf("Input coords (R, D) are (%f, %f)\n", in.r, in.d);582 printf("Output coords (R, D) are (%f, %f)\n", out2.r, out2.d);583 testStatus = 4;584 }585 }586 }587 psFree(mySphereRotForward);588 psFree(mySphereRotReverse);589 590 return(testStatus);591 }592 593 // Test point 1 ADD ICRS(0,0) to Galactic (96.337272,-60.188553)594 // to Ecliptic (0,0) with T=1595 #define SPHERE_COORD_TP1_GAL_R 1.681409 // 96.337272 degrees596 #define SPHERE_COORD_TP1_GAL_D -1.050488 // -60.188553 degrees597 #define SPHERE_COORD_TP1_ECL_R 0.0598 #define SPHERE_COORD_TP1_ECL_D 0.0599 #define SPHERE_COORD_TP1_INVERSE_R 0.0600 #define SPHERE_COORD_TP1_INVERSE_D 0.0601 602 // Test point 2 ADD ICRS(0,90) to Galactic (122.93192, 27.12825)603 // to Ecliptic (90,66.560719) with T=1604 #define SPHERE_COORD_TP2_GAL_R 2.145567 // 122.93192 degrees605 #define SPHERE_COORD_TP2_GAL_D 0.473477 // 27.12825 degrees606 #define SPHERE_COORD_TP2_ECL_R 1.570796 // 90 degrees607 #define SPHERE_COORD_TP2_ECL_D 1.161704 // 66.560719 degrees608 #define SPHERE_COORD_TP2_INVERSE_R 0.0 // 0 degrees609 #define SPHERE_COORD_TP2_INVERSE_D 1.570796 // 90 degrees610 611 // Test point 3 ADD ICRS(180,30) to Galactic (195.639488, 78.353806)612 // to Ecliptic (167.072470, 27.308813) with T=2613 #define SPHERE_COORD_TP3_GAL_R 3.414553 // 195.639488 degrees614 #define SPHERE_COORD_TP3_GAL_D 1.367532 // 78.353806 degrees615 #define SPHERE_COORD_TP3_ECL_R 2.915965 // 167.07247 degrees616 #define SPHERE_COORD_TP3_ECL_D 0.476629 // 27.308813 degrees617 #define SPHERE_COORD_TP3_INVERSE_R 3.141593 // 180.0 degrees618 #define SPHERE_COORD_TP3_INVERSE_D 0.523599 // 30.0 degrees619 620 psS32 testSphereRotApply3( void)621 {622 623 psSphereRot* testTransform;624 psSphere* inputCoord = psSphereAlloc();625 psSphere* outputCoord = NULL;626 psSphere* inverseOutputCoord = NULL;627 628 inputCoord->r = SPHERE_COORD_TP1_INVERSE_R;629 inputCoord->d = SPHERE_COORD_TP1_INVERSE_D;630 inputCoord->rErr = 0.0;631 inputCoord->dErr = 0.0;632 633 // Set test date time to 1/1/2000 00:00:00634 psTime* testDateTime = psTimeFromMJD(MJD_2000);635 636 // Create transform ICRS to Galactic637 testTransform = psSphereRotICRSToGalactic();638 639 // Perform transform from ICRS to Galactic640 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);641 // Verify output not NULL and member values set correctly642 if(outputCoord == NULL) {643 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");644 return 1;645 }646 if(fabs(outputCoord->r - SPHERE_COORD_TP1_GAL_R) > ERROR_TOL) {647 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",648 outputCoord->r, SPHERE_COORD_TP1_GAL_R);649 return 2;650 }651 if(fabs(outputCoord->d - SPHERE_COORD_TP1_GAL_D) > ERROR_TOL) {652 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",653 outputCoord->d, SPHERE_COORD_TP1_GAL_D);654 return 3;655 }656 psFree(testTransform);657 658 // Create inverse transform Galactic to ICRS659 testTransform = psSphereRotGalacticToICRS();660 661 // Perform transform from Galactic to ICRS662 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);663 // Verify output not NULL and member values set correctly664 if(inverseOutputCoord == NULL) {665 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");666 return 4;667 }668 669 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP1_INVERSE_R) > ERROR_TOL) {670 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",671 inverseOutputCoord->r, SPHERE_COORD_TP1_INVERSE_R);672 return 5;673 }674 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP1_INVERSE_D) > ERROR_TOL) {675 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",676 inverseOutputCoord->d, SPHERE_COORD_TP1_INVERSE_D);677 return 6;678 }679 psFree(testTransform);680 681 // Create transform ICRS to Ecliptic682 testTransform = psSphereRotICRSToEcliptic(testDateTime);683 684 // Perform transform from ICRS to Ecliptic685 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);686 // Verify output not NULL and member values set correctly687 if(outputCoord == NULL) {688 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");689 return 7;690 }691 if(fabs(outputCoord->r - SPHERE_COORD_TP1_ECL_R) > ERROR_TOL) {692 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",693 outputCoord->r, SPHERE_COORD_TP1_ECL_R);694 return 8;695 }696 if(fabs(outputCoord->d - SPHERE_COORD_TP1_ECL_D) > ERROR_TOL) {697 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",698 outputCoord->d, SPHERE_COORD_TP1_ECL_D);699 return 9;700 }701 psFree(testTransform);702 703 // Create inverse transform Ecliptic to ICRS704 testTransform = psSphereRotEclipticToICRS(testDateTime);705 706 // Perform transform from Ecliptic to ICRS707 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);708 // Verify output not NULL and member values set correctly709 if(inverseOutputCoord == NULL) {710 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");711 return 10;712 }713 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP1_INVERSE_R) > ERROR_TOL) {714 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",715 inverseOutputCoord->r, SPHERE_COORD_TP1_INVERSE_R);716 return 11;717 }718 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP1_INVERSE_D) > ERROR_TOL) {719 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",720 inverseOutputCoord->d, SPHERE_COORD_TP1_INVERSE_D);721 return 12;722 }723 psFree(testTransform);724 725 psFree(testDateTime);726 psFree(outputCoord);727 psFree(inputCoord);728 psFree(inverseOutputCoord);729 730 return 0;731 }732 733 psS32 testSphereRotApply4( void)734 {735 736 psSphereRot* testTransform;737 psSphere* inputCoord = psSphereAlloc();738 psSphere* outputCoord = NULL;739 psSphere* inverseOutputCoord = NULL;740 741 inputCoord->r = SPHERE_COORD_TP2_INVERSE_R;742 inputCoord->d = SPHERE_COORD_TP2_INVERSE_D;743 inputCoord->rErr = 0.0;744 inputCoord->dErr = 0.0;745 746 // Set test date time to 1/1/2000 00:00:00747 psTime* testDateTime = psTimeFromMJD(MJD_2000);748 749 // Create transform ICRS to Galactic750 testTransform = psSphereRotICRSToGalactic();751 752 // Perform transform from ICRS to Galactic753 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);754 // Verify output not NULL and member values set correctly755 if(outputCoord == NULL) {756 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");757 return 1;758 }759 if(fabs(outputCoord->r - SPHERE_COORD_TP2_GAL_R) > ERROR_TOL) {760 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",761 outputCoord->r, SPHERE_COORD_TP2_GAL_R);762 return 2;763 }764 if(fabs(outputCoord->d - SPHERE_COORD_TP2_GAL_D) > ERROR_TOL) {765 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",766 outputCoord->d, SPHERE_COORD_TP2_GAL_D);767 return 3;768 }769 psFree(testTransform);770 771 // Create inverse transform Galactic to ICRS772 testTransform = psSphereRotGalacticToICRS();773 774 // Perform transform from Galactic to ICRS775 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);776 // Verify output not NULL and member values set correctly777 if(inverseOutputCoord == NULL) {778 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");779 return 4;780 }781 // atan2 function introduces some error with y close to zero, increased error tolerance782 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP2_INVERSE_R) > ERROR_TOL+0.1) {783 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",784 inverseOutputCoord->r, SPHERE_COORD_TP2_INVERSE_R);785 return 5;786 }787 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP2_INVERSE_D) > ERROR_TOL) {788 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",789 inverseOutputCoord->d, SPHERE_COORD_TP2_INVERSE_D);790 return 6;791 }792 psFree(testTransform);793 794 // Create transform ICRS to Ecliptic795 testTransform = psSphereRotICRSToEcliptic(testDateTime);796 797 // Perform transform from ICRS to Ecliptic798 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);799 // Verify output not NULL and member values set correctly800 if(outputCoord == NULL) {801 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");802 return 7;803 }804 if(fabs(outputCoord->r - SPHERE_COORD_TP2_ECL_R) > ERROR_TOL) {805 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",806 outputCoord->r, SPHERE_COORD_TP2_ECL_R);807 return 8;808 }809 if(fabs(outputCoord->d - SPHERE_COORD_TP2_ECL_D) > ERROR_TOL) {810 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",811 outputCoord->d, SPHERE_COORD_TP2_ECL_D);812 return 9;813 }814 psFree(testTransform);815 816 // Create inverse transform Ecliptic to ICRS817 testTransform = psSphereRotEclipticToICRS(testDateTime);818 819 // Perform transform from Ecliptic to ICRS820 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);821 // Verify output not NULL and member values set correctly822 if(inverseOutputCoord == NULL) {823 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");824 return 10;825 }826 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP2_INVERSE_R) > ERROR_TOL) {827 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",828 inverseOutputCoord->r, SPHERE_COORD_TP2_INVERSE_R);829 return 11;830 }831 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP2_INVERSE_D) > ERROR_TOL) {832 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",833 inverseOutputCoord->d, SPHERE_COORD_TP2_INVERSE_D);834 return 12;835 }836 psFree(testTransform);837 838 psFree(testDateTime);839 psFree(outputCoord);840 psFree(inputCoord);841 psFree(inverseOutputCoord);842 843 return 0;844 }845 846 psS32 testSphereRotApply5( void)847 {848 psSphereRot* testTransform;849 psSphere* inputCoord = psSphereAlloc();850 psSphere* outputCoord = NULL;851 psSphere* inverseOutputCoord = NULL;852 853 inputCoord->r = SPHERE_COORD_TP3_INVERSE_R;854 inputCoord->d = SPHERE_COORD_TP3_INVERSE_D;855 inputCoord->rErr = 0.0;856 inputCoord->dErr = 0.0;857 858 // Set test date time to 1/1/2100 00:00:00859 psTime* testDateTime = psTimeFromMJD(MJD_2100);860 861 // Create transform ICRS to Galactic862 testTransform = psSphereRotICRSToGalactic();863 864 // Perform transform from ICRS to Galactic865 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);866 // Verify output not NULL and member values set correctly867 if(outputCoord == NULL) {868 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");869 return 1;870 }871 if(fabs(outputCoord->r - SPHERE_COORD_TP3_GAL_R) > ERROR_TOL) {872 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",873 outputCoord->r, SPHERE_COORD_TP3_GAL_R);874 return 2;875 }876 if(fabs(outputCoord->d - SPHERE_COORD_TP3_GAL_D) > ERROR_TOL) {877 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",878 outputCoord->d, SPHERE_COORD_TP3_GAL_D);879 return 3;880 }881 psFree(testTransform);882 883 // Create inverse transform Galactic to ICRS884 testTransform = psSphereRotGalacticToICRS();885 886 // Perform transform from Galactic to ICRS887 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);888 // Verify output not NULL and member values set correctly889 if(inverseOutputCoord == NULL) {890 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");891 return 4;892 }893 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP3_INVERSE_R) > ERROR_TOL+0.1) {894 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",895 inverseOutputCoord->r, SPHERE_COORD_TP3_INVERSE_R);896 return 5;897 }898 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP3_INVERSE_D) > ERROR_TOL) {899 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",900 inverseOutputCoord->d, SPHERE_COORD_TP3_INVERSE_D);901 return 6;902 }903 psFree(testTransform);904 905 // Create transform ICRS to Ecliptic906 testTransform = psSphereRotICRSToEcliptic(testDateTime);907 908 // Perform transform from ICRS to Ecliptic909 outputCoord = psSphereRotApply(outputCoord,testTransform,inputCoord);910 // Verify output not NULL and member values set correctly911 if(outputCoord == NULL) {912 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");913 return 7;914 }915 if(fabs(outputCoord->r - SPHERE_COORD_TP3_ECL_R) > ERROR_TOL) {916 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",917 outputCoord->r, SPHERE_COORD_TP3_ECL_R);918 return 8;919 }920 if(fabs(outputCoord->d - SPHERE_COORD_TP3_ECL_D) > ERROR_TOL) {921 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",922 outputCoord->d, SPHERE_COORD_TP3_ECL_D);923 return 9;924 }925 psFree(testTransform);926 927 // Create inverse transform Ecliptic to ICRS928 testTransform = psSphereRotEclipticToICRS(testDateTime);929 930 // Perform transform from Ecliptic to ICRS931 inverseOutputCoord = psSphereRotApply(inverseOutputCoord,testTransform,outputCoord);932 // Verify output not NULL and member values set correctly933 if(inverseOutputCoord == NULL) {934 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply returned NULL");935 return 10;936 }937 if(fabs(inverseOutputCoord->r - SPHERE_COORD_TP3_INVERSE_R) > ERROR_TOL) {938 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord r %lg not as expected %lg",939 inverseOutputCoord->r, SPHERE_COORD_TP3_INVERSE_R);940 return 11;941 }942 if(fabs(inverseOutputCoord->d - SPHERE_COORD_TP3_INVERSE_D) > ERROR_TOL) {943 psError(PS_ERR_UNKNOWN,true,"psSphereRotApply return coord d %ld not as expected %lg",944 inverseOutputCoord->d, SPHERE_COORD_TP3_INVERSE_D);945 return 12;946 }947 psFree(testTransform);948 949 psFree(testDateTime);950 psFree(outputCoord);951 psFree(inputCoord);952 psFree(inverseOutputCoord);953 954 return 0;955 }956 957 #define SPHERE_PRECESS_TP1_R 0.0 // 0.0 degrees958 #define SPHERE_PRECESS_TP1_D 0.0 // 0.0 degrees959 #define SPHERE_PRECESS_TP1_EXPECT_R 6.238453 // 357.437 degrees960 #define SPHERE_PRECESS_TP1_EXPECT_D -0.019426 // -1.113 degrees961 #define SPHERE_PRECESS_TP2_R 0.0 // 0.0 degrees962 #define SPHERE_PRECESS_TP2_D 1.570796 // 90.0 degrees963 #define SPHERE_PRECESS_TP2_EXPECT_R 6.260828 // 358.719 degrees964 #define SPHERE_PRECESS_TP2_EXPECT_D 1.551353 // 88.886 degrees965 #define SPHERE_PRECESS_TP3_R 3.141593 // 180.0 degrees966 #define SPHERE_PRECESS_TP3_D 0.523599 // 30.0 degrees967 #define SPHERE_PRECESS_TP3_EXPECT_R 3.096616 // 177.423 degrees968 #define SPHERE_PRECESS_TP3_EXPECT_D 0.543024 // 31.113 degrees969 970 psS32 testSphereRotPrecess( void )971 {972 psSphere* inputCoord = psSphereAlloc();973 psSphere* outputCoord = NULL;974 psTime* fromTime = psTimeFromMJD(MJD_2100);975 psTime* toTime = psTimeFromMJD(MJD_1900);976 977 // Set input coordinate978 inputCoord->r = SPHERE_PRECESS_TP1_R;979 inputCoord->d = SPHERE_PRECESS_TP1_D;980 inputCoord->rErr = 0.0;981 inputCoord->dErr = 0.0;982 983 // Calculate precess984 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime);985 // Verify return is not NULL986 if(outputCoord == NULL) {987 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");988 return 1;989 }990 // Verify return with expected values991 if( fabs(outputCoord->r - SPHERE_PRECESS_TP1_EXPECT_R) > ERROR_TOL) {992 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg",993 outputCoord->r,SPHERE_PRECESS_TP1_EXPECT_R);994 return 2;995 }996 if( fabs(outputCoord->d - SPHERE_PRECESS_TP1_EXPECT_D) > ERROR_TOL) {997 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg",998 outputCoord->d,SPHERE_PRECESS_TP1_EXPECT_D);999 return 3;1000 }1001 psFree(outputCoord);1002 1003 // Set input coordinate1004 inputCoord->r = SPHERE_PRECESS_TP2_R;1005 inputCoord->d = SPHERE_PRECESS_TP2_D;1006 inputCoord->rErr = 0.0;1007 inputCoord->dErr = 0.0;1008 1009 // Calculate precess1010 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime);1011 // Verify return is not NULL1012 if(outputCoord == NULL) {1013 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");1014 return 4;1015 }1016 // Verify return with expected values1017 if( fabs(outputCoord->r - SPHERE_PRECESS_TP2_EXPECT_R) > ERROR_TOL) {1018 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg",1019 outputCoord->r,SPHERE_PRECESS_TP2_EXPECT_R);1020 return 5;1021 }1022 if( fabs(outputCoord->d - SPHERE_PRECESS_TP2_EXPECT_D) > ERROR_TOL) {1023 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg",1024 outputCoord->d,SPHERE_PRECESS_TP2_EXPECT_D);1025 return 6;1026 }1027 psFree(outputCoord);1028 1029 // Set input coordinate1030 inputCoord->r = SPHERE_PRECESS_TP3_R;1031 inputCoord->d = SPHERE_PRECESS_TP3_D;1032 inputCoord->rErr = 0.0;1033 inputCoord->dErr = 0.0;1034 1035 // Calculate precess1036 outputCoord = psSpherePrecess(inputCoord, fromTime, toTime);1037 // Verify return is not NULL1038 if(outputCoord == NULL) {1039 psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");1040 return 7;1041 }1042 // Verify return with expected values1043 if( fabs(outputCoord->r - SPHERE_PRECESS_TP3_EXPECT_R) > ERROR_TOL) {1044 psError(PS_ERR_UNKNOWN,true,"Precess r = %lg not equal to expected = %lg",1045 outputCoord->r,SPHERE_PRECESS_TP3_EXPECT_R);1046 return 8;1047 }1048 if( fabs(outputCoord->d - SPHERE_PRECESS_TP3_EXPECT_D) > ERROR_TOL) {1049 psError(PS_ERR_UNKNOWN,true,"Precess d = %lg not equal to expected = %lg",1050 outputCoord->d,SPHERE_PRECESS_TP3_EXPECT_D);1051 return 9;1052 }1053 psFree(outputCoord);1054 1055 // Invoke precess with invalid parameter1056 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1057 outputCoord = psSpherePrecess(inputCoord, fromTime, NULL);1058 if(outputCoord != NULL) {1059 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input");1060 return 10;1061 }1062 1063 // Invoke precess with invalid parameter1064 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1065 outputCoord = psSpherePrecess(inputCoord, NULL, toTime);1066 if(outputCoord != NULL) {1067 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input");1068 return 11;1069 }1070 1071 // Invoke precess with invalid parameter1072 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1073 outputCoord = psSpherePrecess(NULL, fromTime, toTime);1074 if(outputCoord != NULL) {1075 psError(PS_ERR_UNKNOWN,true,"Did not return NULL with invalid input");1076 return 12;1077 }1078 1079 // Free objects1080 psFree(fromTime);1081 psFree(toTime);1082 psFree(inputCoord);1083 1084 return 0;1085 }1086 1087 psS32 testSphereRotICRSToEcliptic( void )1088 {1089 psF64 expectedQ0 = 0.0;1090 psF64 expectedQ1 = 0.0;1091 psF64 expectedQ2 = 0.0;1092 psF64 expectedQ3 = 0.0;1093 1094 // Set test date time to 1/1/2000 00:00:001095 psTime* testDateTime = psTimeFromMJD(MJD_2000);1096 1097 // Invoke function to set psSphereRota objec1098 psSphereRot *myST = psSphereRotICRSToEcliptic(testDateTime);1099 1100 // Verify expected values for the specified time1101 if (ERROR_TOL < fabs(expectedQ0 - myST->q0)) {1102 psError(PS_ERR_UNKNOWN,true,"myST->q0 is %f, should be %f",1103 myST->q0, expectedQ0);1104 return 1;1105 }1106 if (ERROR_TOL < fabs(expectedQ1 - myST->q1)) {1107 psError(PS_ERR_UNKNOWN,true,"myST->q1 is %f, should be %f",1108 myST->q1, expectedQ1);1109 return 2;1110 }1111 if (ERROR_TOL < fabs(expectedQ2 - myST->q2)) {1112 psError(PS_ERR_UNKNOWN,true,"myST->q2 is %f, should be %f",1113 myST->q2, expectedQ2);1114 return 3;1115 }1116 if (ERROR_TOL < fabs(expectedQ3 - myST->q3)) {1117 psError(PS_ERR_UNKNOWN,true,"myST->q3 is %f, should be %f",1118 myST->q3, expectedQ3);1119 return 4;1120 }1121 psFree(myST);1122 psFree(testDateTime);1123 1124 // Set test date time to 1/1/2100 00:00:001125 testDateTime = psTimeFromMJD(MJD_2100);1126 1127 // Invoke function to set psSphereRota objec1128 myST = psSphereRotICRSToEcliptic(testDateTime);1129 1130 // Verify expected values for the specified time1131 // Verify expected values for the specified time1132 if (ERROR_TOL < fabs(expectedQ0 - myST->q0)) {1133 psError(PS_ERR_UNKNOWN,true,"myST->q0 is %f, should be %f",1134 myST->q0, expectedQ0);1135 return 5;1136 }1137 if (ERROR_TOL < fabs(expectedQ1 - myST->q1)) {1138 psError(PS_ERR_UNKNOWN,true,"myST->q1 is %f, should be %f",1139 myST->q1, expectedQ1);1140 return 6;1141 }1142 if (ERROR_TOL < fabs(expectedQ2 - myST->q2)) {1143 psError(PS_ERR_UNKNOWN,true,"myST->q2 is %f, should be %f",1144 myST->q2, expectedQ2);1145 return 7;1146 }1147 if (ERROR_TOL < fabs(expectedQ3 - myST->q3)) {1148 psError(PS_ERR_UNKNOWN,true,"myST->q3 is %f, should be %f",1149 myST->q3, expectedQ3);1150 return 8;1151 }1152 psFree(myST);1153 psFree(testDateTime);1154 1155 // Verify if argument psTime is NULL, function returns NULL and error message generated1156 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1157 myST = psSphereRotICRSToEcliptic(NULL);1158 if (myST != NULL) {1159 psError(PS_ERR_UNKNOWN,true,"psSphereRotICRSToEcliptic() did not return NULL.");1160 return 9;1161 }1162 1163 // Verify if argument psTime is less than 1900, function return NULL and error msg generated1164 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1165 testDateTime = psTimeFromMJD(MJD_1900 - 1.0);1166 myST = psSphereRotICRSToEcliptic(testDateTime);1167 if (myST != NULL) {1168 psError(PS_ERR_UNKNOWN,true,"psSphereRotICRSToEcliptic() did not return NULL.");1169 return 10;1170 }1171 psFree(testDateTime);1172 1173 return 0;1174 }1175 1176 1177 psS32 testSphereRotEclipticToICRS( void )1178 {1179 psF64 expectedPhiP = 0.0;1180 psF64 expectedAlphaP = 0.0;1181 psF64 expectedCosDeltaP = 0.0;1182 psF64 expectedSinDeltaP = 0.0;1183 1184 // Set test date time to 1/1/2000 00:00:001185 psTime* testDateTime = psTimeFromMJD(MJD_2000);1186 1187 // Invoke function to set psSphereRota object1188 psSphereRot *myST = psSphereRotEclipticToICRS(testDateTime);1189 1190 // Verify expected values for the specified time1191 if (ERROR_TOL < fabs(expectedSinDeltaP - myST->sinDeltaP)) {1192 psError(PS_ERR_UNKNOWN,true,"myST->sinDeltaP is %f, should be %f",1193 myST->sinDeltaP, expectedSinDeltaP);1194 return 1;1195 }1196 if (ERROR_TOL < fabs(expectedCosDeltaP - myST->cosDeltaP)) {1197 psError(PS_ERR_UNKNOWN,true,"myST->cosDeltaP is %f, should be %f",1198 myST->cosDeltaP, expectedCosDeltaP);1199 return 2;1200 }1201 if (ERROR_TOL < fabs(expectedAlphaP - myST->alphaP)) {1202 psError(PS_ERR_UNKNOWN,true,"myST->alphaP is %f, should be %f",1203 myST->alphaP, expectedAlphaP);1204 return 3;1205 }1206 if (ERROR_TOL < fabs(expectedPhiP - myST->phiP)) {1207 psError(PS_ERR_UNKNOWN,true,"myST->phiP is %f, should be %f",1208 myST->phiP, expectedPhiP);1209 return 4;1210 }1211 psFree(myST);1212 psFree(testDateTime);1213 1214 expectedCosDeltaP = EXPECT_COS_DELTAP_2100;1215 expectedSinDeltaP = -EXPECT_SIN_DELTAP_2100;1216 1217 // Set test date time to 1/1/2100 00:00:001218 testDateTime = psTimeFromMJD(MJD_2100);1219 1220 // Invoke function to set psSphereRota objec1221 myST = psSphereRotEclipticToICRS(testDateTime);1222 1223 // Verify expected values for the specified time1224 if (ERROR_TOL < fabs(expectedSinDeltaP - myST->sinDeltaP)) {1225 psError(PS_ERR_UNKNOWN,true,"myST->sinDeltaP is %f, should be %f",1226 myST->sinDeltaP, expectedSinDeltaP);1227 return 5;1228 }1229 if (ERROR_TOL < fabs(expectedCosDeltaP - myST->cosDeltaP)) {1230 psError(PS_ERR_UNKNOWN,true,"myST->cosDeltaP is %f, should be %f",1231 myST->cosDeltaP, expectedCosDeltaP);1232 return 6;1233 }1234 if (ERROR_TOL < fabs(expectedAlphaP - myST->alphaP)) {1235 psError(PS_ERR_UNKNOWN,true,"myST->alphaP is %f, should be %f",1236 myST->alphaP, expectedAlphaP);1237 return 7;1238 }1239 if (ERROR_TOL < fabs(expectedPhiP - myST->phiP)) {1240 psError(PS_ERR_UNKNOWN,true,"myST->phiP is %f, should be %f",1241 myST->phiP, expectedPhiP);1242 return 8;1243 }1244 psFree(myST);1245 psFree(testDateTime);1246 1247 // Verify if argument psTime is NULL, function returns NULL and error message generated1248 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1249 myST = psSphereRotEclipticToICRS(NULL);1250 if (myST != NULL) {1251 psError(PS_ERR_UNKNOWN,true,"psSphereRotEclipticICRS() did not return NULL.");1252 return 9;1253 }1254 1255 // Verify if argument psTime is less than 1900, function return NULL and error msg generated1256 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message");1257 testDateTime = psTimeFromMJD(MJD_1900 - 1.0);1258 myST = psSphereRotEclipticToICRS(testDateTime);1259 if (myST != NULL) {1260 psError(PS_ERR_UNKNOWN,true,"psSphereRotEclipticToICRS() did not return NULL.");1261 return 10;1262 }1263 psFree(testDateTime);1264 1265 return 0;1266 }1267 1268 #define ITG_EXPECT_ALPHAP 4.936831269 #define ITG_EXPECT_SINDELTAP 0.889991270 #define ITG_EXPECT_COSDELTAP 0.455981271 #define ITG_EXPECT_PHIP 0.574771272 1273 psS32 testSphereRotICRSToGalactic( void )1274 {1275 // Invoke function1276 psSphereRot *myST = psSphereRotICRSToGalactic();1277 1278 // Verify did not return NULL1279 if(myST == NULL) {1280 psError(PS_ERR_UNKNOWN,true,"psSphereRotICRSToGalactic returned NULL");1281 return 1;1282 }1283 // Verify returned structure has members set properly1284 if (ERROR_TOL < fabs(ITG_EXPECT_SINDELTAP - myST->sinDeltaP)) {1285 psError(PS_ERR_UNKNOWN,true,"myST->sinDeltaP is %f, should be %f",1286 myST->sinDeltaP, ITG_EXPECT_SINDELTAP);1287 return 2;1288 }1289 if (ERROR_TOL < fabs(ITG_EXPECT_COSDELTAP - myST->cosDeltaP)) {1290 psError(PS_ERR_UNKNOWN,true,"myST->cosDeltaP is %f, should be %f",1291 myST->cosDeltaP, ITG_EXPECT_COSDELTAP);1292 return 3;1293 }1294 if (ERROR_TOL < fabs(ITG_EXPECT_ALPHAP - myST->alphaP)) {1295 psError(PS_ERR_UNKNOWN,true,"myST->alphaP is %f, should be %f",1296 myST->alphaP, ITG_EXPECT_ALPHAP);1297 return 4;1298 }1299 if (ERROR_TOL < fabs(ITG_EXPECT_PHIP - myST->phiP)) {1300 psError(PS_ERR_UNKNOWN,true,"myST->phiP is %f, should be %f",1301 myST->phiP, ITG_EXPECT_PHIP);1302 return 5;1303 }1304 // Free data structure created1305 psFree(myST);1306 1307 return 0;1308 }1309 1310 #define GTI_EXPECT_PHIP 4.936831311 #define GTI_EXPECT_SINDELTAP -0.889991312 #define GTI_EXPECT_COSDELTAP 0.455981313 #define GTI_EXPECT_ALPHAP 0.574771314 1315 psS32 testSphereRotGalacticToICRS( void )1316 {1317 // Invoke function1318 psSphereRot *myST = psSphereRotGalacticToICRS();1319 1320 // Verify did not return NULL1321 if(myST == NULL) {1322 psError(PS_ERR_UNKNOWN,true,"psSphereRotGalacticToICRS returned NULL");1323 return 1;1324 }1325 // Verify returned structure has members set properly1326 if (ERROR_TOL < fabs(GTI_EXPECT_SINDELTAP - myST->sinDeltaP)) {1327 psError(PS_ERR_UNKNOWN,true,"myST->sinDeltaP is %f, should be %f",1328 myST->sinDeltaP, GTI_EXPECT_SINDELTAP);1329 return 2;1330 }1331 if (ERROR_TOL < fabs(GTI_EXPECT_COSDELTAP - myST->cosDeltaP)) {1332 psError(PS_ERR_UNKNOWN,true,"myST->cosDeltaP is %f, should be %f",1333 myST->cosDeltaP, GTI_EXPECT_COSDELTAP);1334 return 3;1335 }1336 if (ERROR_TOL < fabs(GTI_EXPECT_ALPHAP - myST->alphaP)) {1337 psError(PS_ERR_UNKNOWN,true,"myST->alphaP is %f, should be %f",1338 myST->alphaP, GTI_EXPECT_ALPHAP);1339 return 4;1340 }1341 if (ERROR_TOL < fabs(GTI_EXPECT_PHIP - myST->phiP)) {1342 psError(PS_ERR_UNKNOWN,true,"myST->phiP is %f, should be %f",1343 myST->phiP, GTI_EXPECT_PHIP);1344 return 5;1345 }1346 // Free data structure created1347 psFree(myST);1348 1349 return 0;1350 }1351
Note:
See TracChangeset
for help on using the changeset viewer.
