Changeset 22682
- Timestamp:
- Feb 26, 2009, 10:21:48 AM (17 years ago)
- Location:
- trunk/psLib/src/astro
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psEarthOrientation.c
r21388 r22682 767 767 psTime *in = psTimeCopy(time); 768 768 if (in->type != PS_TIME_UT1) { 769 in =psTimeConvert(in, PS_TIME_UT1);769 psTimeConvert(in, PS_TIME_UT1); 770 770 } 771 771 //Check if tidal corrections should be included. -
trunk/psLib/src/astro/psTime.c
r22680 r22682 66 66 static char *cleanString(char *inString, int sLen); 67 67 static char* getToken(char **inString, char *delimiter, psParseErrorType *status); 68 static psTime*convertTimeTAIUTC(psTime* time);69 static psTime*convertTimeUTCTAI(psTime* time);70 static psTime*convertTimeTAITT(psTime* time);71 static psTime*convertTimeTTTAI(psTime* time);72 static psTime*convertTimeUTCUT1(psTime* time);68 static bool convertTimeTAIUTC(psTime* time); 69 static bool convertTimeUTCTAI(psTime* time); 70 static bool convertTimeTAITT(psTime* time); 71 static bool convertTimeTTTAI(psTime* time); 72 static bool convertTimeUTCUT1(psTime* time); 73 73 74 74 static bool timeInit(const char *fileName); … … 510 510 } 511 511 512 static psTime*convertTimeTAIUTC(psTime* time)512 static bool convertTimeTAIUTC(psTime* time) 513 513 { 514 514 psF64 deltaTAI = 0.0; … … 550 550 } 551 551 552 return t ime;553 } 554 555 static psTime*convertTimeUTCTAI(psTime* time)552 return true; 553 } 554 555 static bool convertTimeUTCTAI(psTime* time) 556 556 { 557 557 psF64 delta = 0.0; … … 580 580 time->type = PS_TIME_TAI; 581 581 582 //XXX: Set leapseconds to TRUE 583 // time->leapsecond = true; 584 return time; 585 } 586 587 static psTime* convertTimeTAITT(psTime* time) 582 return true; 583 } 584 585 static bool convertTimeTAITT(psTime* time) 588 586 { 589 587 // Add TT offset … … 600 598 time->type = PS_TIME_TT; 601 599 602 return t ime;603 } 604 605 static psTime*convertTimeTTTAI(psTime* time)600 return true; 601 } 602 603 static bool convertTimeTTTAI(psTime* time) 606 604 { 607 605 // Subtract TT offset … … 625 623 time->type = PS_TIME_TAI; 626 624 627 return t ime;628 } 629 630 static psTime*convertTimeUTCUT1(psTime* time)625 return true; 626 } 627 628 static bool convertTimeUTCUT1(psTime* time) 631 629 { 632 630 psS64 ut1utc = 0; … … 664 662 time->type = PS_TIME_UT1; 665 663 666 return time; 667 } 668 669 psTime* psTimeConvert(psTime *time, 670 psTimeType type) 664 return true; 665 } 666 667 bool psTimeConvert(psTime *time, psTimeType type) 671 668 { 672 669 // Error checks 673 PS_ASSERT_PTR_NON_NULL(time,NULL); 674 PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1), NULL); 675 676 // If the input type is UT1 then return time and generate error message 670 PS_ASSERT_PTR_NON_NULL(time, false); 671 PS_ASSERT_INT_WITHIN_RANGE(time->nsec, 0, (psU32)((1e9)-1), false); 672 677 673 if (time->type == PS_TIME_UT1) { 678 psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Cannot convert from UT1 time type"); 679 return NULL; 680 } 681 682 // If the time to convert to is the same as psTime the return time 674 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot convert from UT1 time type"); 675 return false; 676 } 683 677 if (time->type == type) { 684 return time; 685 } 686 687 // Convert from TAI to UTC, TT, UT1 688 if (time->type == PS_TIME_TAI) { 689 // Convert from TAI to UTC 690 if (type == PS_TIME_UTC) { 691 time = convertTimeTAIUTC(time); 692 // Convert from TAI to TT 693 } else if (type == PS_TIME_TT) { 694 time = convertTimeTAITT(time); 695 // Convert from TAI to UT1 696 } else if (type == PS_TIME_UT1) { 697 // Convert to UTC first 698 time = convertTimeTAIUTC(time); 699 // Convert UTC to UT1 700 time = convertTimeUTCUT1(time); 701 // Convert from TAI to unknown time type 702 } else { 678 // No action required 679 return true; 680 } 681 682 switch (time->type) { 683 case PS_TIME_TAI: 684 switch (type) { 685 case PS_TIME_UTC: 686 return convertTimeTAIUTC(time); 687 case PS_TIME_TT: 688 return convertTimeTAITT(time); 689 case PS_TIME_UT1: 690 convertTimeTAIUTC(time); 691 return convertTimeUTCUT1(time); 692 default: 693 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type); 694 return false; 695 } 696 break; 697 case PS_TIME_TT: 698 switch (type) { 699 case PS_TIME_UTC: 700 convertTimeTTTAI(time); 701 return convertTimeTAIUTC(time); 702 case PS_TIME_TAI: 703 return convertTimeTTTAI(time); 704 case PS_TIME_UT1: 705 convertTimeTTTAI(time); 706 convertTimeTAIUTC(time); 707 return convertTimeUTCUT1(time); 708 default: 703 709 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type); 704 710 return NULL; 705 711 } 706 // Convert from TT to TAI, UTC, UT1 707 } else if (time->type == PS_TIME_TT) { 708 // Convert from TT to UTC 709 if (type == PS_TIME_UTC) { 710 // Convert to TAI time first 711 time = convertTimeTTTAI(time); 712 // Convert from TAI to UTC 713 time = convertTimeTAIUTC(time); 714 // Convert from TT to TAI 715 } else if (type == PS_TIME_TAI) { 716 time = convertTimeTTTAI(time); 717 // Convert from TT to UT1 718 } else if (type == PS_TIME_UT1) { 719 // Convert to UTC first 720 // Convert to TAI time first 721 time = convertTimeTTTAI(time); 722 // Convert from TAI to UTC 723 time = convertTimeTAIUTC(time); 724 // Convert from UTC to UT1 725 time = convertTimeUTCUT1(time); 726 // Convert from TT to unknown time type 727 } else { 712 break; 713 case PS_TIME_UTC: 714 switch (type) { 715 case PS_TIME_TAI: 716 return convertTimeUTCTAI(time); 717 case PS_TIME_TT: 718 convertTimeUTCTAI(time); 719 return convertTimeTAITT(time); 720 case PS_TIME_UT1: 721 return convertTimeUTCUT1(time); 722 default: 728 723 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type); 729 724 return NULL; 730 725 } 731 // Convert from UTC to TAI, TT, UT1 732 } else if (time->type == PS_TIME_UTC) { 733 // Convert UTC to TAI 734 if (type == PS_TIME_TAI) { 735 time = convertTimeUTCTAI(time); 736 // Convert UTC to TT 737 } else if (type == PS_TIME_TT) { 738 // Convert to TAI time first 739 time = convertTimeUTCTAI(time); 740 // Convert TAI to TT 741 time = convertTimeTAITT(time); 742 // Convert UTC to UT1 743 } else if (type == PS_TIME_UT1) { 744 time = convertTimeUTCUT1(time); 745 // Convert UTC to unknown time type 746 } else { 747 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type); 748 return NULL; 749 } 750 // Convert unknown time type 751 } else { 726 break; 727 default: 752 728 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), time->type); 753 729 return NULL; 754 730 } 755 731 756 return time; 732 psAbort("Should never reach here."); 733 return false; 757 734 } 758 735 … … 792 769 tdtTime->nsec = time->nsec; 793 770 tdtTime->leapsecond = time->leapsecond; 794 tdtTime =psTimeConvert(tdtTime,PS_TIME_TT);771 psTimeConvert(tdtTime,PS_TIME_TT); 795 772 796 773 // Determine time reference to UT1 … … 799 776 ut1Time->nsec = time->nsec; 800 777 ut1Time->leapsecond = time->leapsecond; 801 ut1Time =psTimeConvert(ut1Time,PS_TIME_UT1);778 psTimeConvert(ut1Time,PS_TIME_UT1); 802 779 803 780 // Calculate UT1 as Julian Centuries since J2000.0 … … 996 973 *out = *time; 997 974 if (out->type != PS_TIME_UT1) { 998 out =psTimeConvert(out, PS_TIME_UT1);975 psTimeConvert(out, PS_TIME_UT1); 999 976 } 1000 977 //see if corrections include seconds or just nano-seconds … … 1291 1268 //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following: 1292 1269 if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) { 1293 time2 =psTimeConvert(time2, PS_TIME_TAI);1270 psTimeConvert(time2, PS_TIME_TAI); 1294 1271 } 1295 1272 … … 1317 1294 //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following: 1318 1295 if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) { 1319 time2 =psTimeConvert(time2, PS_TIME_TAI);1296 psTimeConvert(time2, PS_TIME_TAI); 1320 1297 } 1321 1298 … … 1771 1748 tempTime->sec = time->sec; 1772 1749 tempTime->nsec = time->nsec; 1773 tempTime =psTimeConvert(tempTime, PS_TIME_TAI);1750 psTimeConvert(tempTime, PS_TIME_TAI); 1774 1751 outTime = psTimeAlloc(PS_TIME_TAI); 1775 1752 } else { … … 1789 1766 // Convert result to same time type as input 1790 1767 if (time->type == PS_TIME_UTC) { 1791 outTime =psTimeConvert(outTime, PS_TIME_UTC);1768 psTimeConvert(outTime, PS_TIME_UTC); 1792 1769 } 1793 1770 … … 1823 1800 tempTime1->sec = time1->sec; 1824 1801 tempTime1->nsec = time1->nsec; 1825 tempTime1 =psTimeConvert(tempTime1, PS_TIME_TAI);1802 psTimeConvert(tempTime1, PS_TIME_TAI); 1826 1803 } else { 1827 1804 tempTime1 = psMemIncrRefCounter((psTime*)time1); … … 1831 1808 tempTime2->sec = time2->sec; 1832 1809 tempTime2->nsec = time2->nsec; 1833 tempTime2 =psTimeConvert(tempTime2, PS_TIME_TAI);1810 psTimeConvert(tempTime2, PS_TIME_TAI); 1834 1811 } else { 1835 1812 tempTime2 = psMemIncrRefCounter((psTime*)time2); -
trunk/psLib/src/astro/psTime.h
r22680 r22682 135 135 /** Convert psTime to UTC, TAI, UT1, or TT time. 136 136 * 137 * Converts psTime to UTC, TAI, UT1, or TT time based on the psTimeType argument.138 * 139 * @return psTime*: Pointer to psTime.140 */ 141 psTime*psTimeConvert(137 * Converts psTime in-place to UTC, TAI, UT1, or TT time based on the psTimeType argument. 138 * 139 * @return bool: Successful conversion? 140 */ 141 bool psTimeConvert( 142 142 psTime *time, ///< Time to be converted. 143 143 psTimeType type ///< Type to be converted to.
Note:
See TracChangeset
for help on using the changeset viewer.
