Changeset 3712
- Timestamp:
- Apr 18, 2005, 4:13:53 PM (21 years ago)
- Location:
- trunk/psLib
- Files:
-
- 8 edited
-
src/astro/psTime.c (modified) (28 diffs)
-
src/astro/psTime.h (modified) (3 diffs)
-
src/astronomy/psTime.c (modified) (28 diffs)
-
src/astronomy/psTime.h (modified) (3 diffs)
-
test/astronomy/tst_psTime_01.c (modified) (10 diffs)
-
test/astronomy/tst_psTime_03.c (modified) (9 diffs)
-
test/astronomy/verified/tst_psTime_01.stdout (modified) (8 diffs)
-
test/astronomy/verified/tst_psTime_03.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psTime.c
r3708 r3712 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-04-19 0 0:17:05$12 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-04-19 02:13:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 64 64 65 65 /** Microseconds per day */ 66 #define USEC_PER_DAY 86400000000.066 #define NSEC_PER_DAY 86400000000000.0 67 67 68 68 /** Time metadata read from config file */ … … 363 363 364 364 outTime->sec = 0; 365 outTime-> usec = 0;365 outTime->nsec = 0; 366 366 outTime->type = type; 367 outTime->leapsecond = false; 367 368 368 369 return outTime; … … 386 387 // Convert timeval time to psTime 387 388 time->sec = now.tv_sec; 388 time-> usec = now.tv_usec;389 time->nsec = now.tv_usec*1000; 389 390 390 391 // Add most leapseconds to UTC time to get TAI time if necessary … … 403 404 // Error checks 404 405 PS_PTR_CHECK_NULL(time,NULL); 405 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);406 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 406 407 407 408 if (time->type == type) { // time already right type. That was easy! … … 448 449 // Error checks 449 450 PS_PTR_CHECK_NULL(time,NAN); 450 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);451 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 451 452 452 453 // Calculate TAI or UTC time based on type of time user passes … … 455 456 utcTime = psTimeAlloc(PS_TIME_UTC); 456 457 utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time); 457 utcTime-> usec = taiTime->usec;458 utcTime->nsec = taiTime->nsec; 458 459 } else if(time->type == PS_TIME_UTC) { 459 460 utcTime = psMemIncrRefCounter(time); 460 461 taiTime = psTimeAlloc(PS_TIME_TAI); 461 462 taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time); 462 taiTime-> usec = utcTime->usec;463 taiTime->nsec = utcTime->nsec; 463 464 } 464 465 … … 519 520 // Error checks 520 521 PS_PTR_CHECK_NULL(time,NAN); 521 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);522 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 522 523 523 524 if(time->type != PS_TIME_TAI) { … … 592 593 // Error checks 593 594 PS_PTR_CHECK_NULL(time,NULL); 594 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);595 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 595 596 596 597 if(time->type != PS_TIME_TAI) … … 715 716 // Error checks 716 717 PS_PTR_CHECK_NULL(time,NAN); 717 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);718 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 718 719 719 720 // Check time metadata … … 768 769 PS_PTR_CHECK_NULL(time1,0); 769 770 PS_PTR_CHECK_NULL(time2,0); 770 PS_INT_CHECK_RANGE(time1-> usec,0,1e6-1,0);771 PS_INT_CHECK_RANGE(time2-> usec,0,1e6-1,0);771 PS_INT_CHECK_RANGE(time1->nsec,0,1e9-1,0); 772 PS_INT_CHECK_RANGE(time2->nsec,0,1e9-1,0); 772 773 diff = abs((psS64)psTimeGetTAIDelta((psTime*)time1)-(psS64)psTimeGetTAIDelta((psTime*)time2)); 773 774 … … 781 782 // Error checks 782 783 PS_PTR_CHECK_NULL(time,NAN); 783 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);784 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 784 785 785 786 // Julian date conversion 786 787 if(time->sec < 0) { 787 jd = time->sec / SEC_PER_DAY - time-> usec / USEC_PER_DAY + 2440587.5; // psTime earlier than epoch788 jd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 2440587.5; // psTime earlier than epoch 788 789 } else { 789 jd = time->sec / SEC_PER_DAY + time-> usec / USEC_PER_DAY + 2440587.5; // psTime greater than epoch790 jd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 2440587.5; // psTime greater than epoch 790 791 } 791 792 … … 800 801 // Error checks 801 802 PS_PTR_CHECK_NULL(time,NAN); 802 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);803 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 803 804 804 805 // Modified Julian date conversion 805 806 if(time->sec < 0) { 806 mjd = time->sec / SEC_PER_DAY - time-> usec / USEC_PER_DAY + 40587.0; // psTime earlier than epoch807 mjd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 40587.0; // psTime earlier than epoch 807 808 } else { 808 mjd = time->sec / SEC_PER_DAY + time-> usec / USEC_PER_DAY + 40587.0; // psTime greater than epoch809 mjd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 40587.0; // psTime greater than epoch 809 810 } 810 811 … … 823 824 // Error checks 824 825 PS_PTR_CHECK_NULL(time,NULL); 825 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);826 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 826 827 827 828 tempString = psAlloc(MAX_TIME_STRING_LENGTH); 828 829 timeString = psAlloc(MAX_TIME_STRING_LENGTH); 829 830 830 ms = time-> usec / 1000;831 ms = time->nsec / 1000000; 831 832 sec = time->sec; 832 833 … … 856 857 // Error checks 857 858 PS_PTR_CHECK_NULL(time,timevalTime); 858 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,timevalTime);859 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,timevalTime); 859 860 860 861 timevalTime.tv_sec = time->sec; 861 timevalTime.tv_usec = time-> usec;862 timevalTime.tv_usec = time->nsec / 1000; 862 863 863 864 return timevalTime; … … 879 880 // Error checks 880 881 PS_PTR_CHECK_NULL(time,NULL); 881 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);882 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 882 883 883 884 seconds = time->sec%60; … … 941 942 seconds = days * SEC_PER_DAY; 942 943 if(seconds < 0.0) { 943 outTime-> usec = (seconds - (psS64)seconds) * -1000000.0; // psTime earlier than epoch944 outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0; // psTime earlier than epoch 944 945 } else { 945 outTime-> usec = (seconds - (psS64)seconds) * 1000000.0; // psTime greater than epoch946 outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0; // psTime greater than epoch 946 947 } 947 948 outTime->sec = seconds; 948 949 949 950 // Error check 950 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);951 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 951 952 952 953 return outTime; … … 967 968 seconds = days * SEC_PER_DAY; 968 969 if(seconds < 0.0) { 969 outTime-> usec = (seconds - (psS64)seconds) * -1000000.0; // psTime earlier than epoch970 outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0; // psTime earlier than epoch 970 971 } else { 971 outTime-> usec = (seconds - (psS64)seconds) * 1000000.0; // psTime greater than epoch972 outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0; // psTime greater than epoch 972 973 } 973 974 outTime->sec = seconds; 974 975 975 976 // Error check 976 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);977 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 977 978 978 979 return outTime; … … 1006 1007 // Convert tm time to psTime 1007 1008 outTime = psTimeFromTM(&tmTime); 1008 outTime-> usec = millisecond * 1000;1009 outTime->nsec = millisecond * 1000000; 1009 1010 1010 1011 return outTime; … … 1024 1025 // Convert to psTime 1025 1026 outTime->sec = time->tv_sec; 1026 outTime-> usec = time->tv_usec;1027 outTime->nsec = time->tv_usec * 1000; 1027 1028 1028 1029 // Error check 1029 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1030 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1030 1031 1031 1032 return outTime; … … 1083 1084 1084 1085 // C's TM does not define a microsecond field. Microseconds must be manipulated by calling function. 1085 outTime-> usec = 0;1086 outTime->nsec = 0; 1086 1087 1087 1088 // Error check 1088 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1089 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1089 1090 1090 1091 return outTime; … … 1100 1101 // Error checks 1101 1102 PS_PTR_CHECK_NULL(time,NULL); 1102 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);1103 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 1103 1104 1104 1105 // Convert time to TAI if necessary, but without changing input arguments … … 1106 1107 tempTime = psTimeAlloc(PS_TIME_UTC); 1107 1108 tempTime->sec = time->sec; 1108 tempTime-> usec = time->usec;1109 tempTime->nsec = time->nsec; 1109 1110 tempTime = psTimeConvert(tempTime, PS_TIME_TAI); 1110 1111 } else { … … 1114 1115 // Create output time 1115 1116 outTime = psTimeAlloc(PS_TIME_TAI); 1116 sec = delta + (psF64)tempTime->sec + (psF64)tempTime-> usec/1e6;1117 sec = delta + (psF64)tempTime->sec + (psF64)tempTime->nsec/1e9; 1117 1118 outTime->sec = sec; 1118 outTime-> usec = (sec - outTime->sec)*1e6;1119 outTime->nsec = (sec - outTime->sec)*1e9; 1119 1120 1120 1121 // Error check 1121 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1122 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1122 1123 1123 1124 // Convert result to same time type as input … … 1142 1143 // Error checks 1143 1144 PS_PTR_CHECK_NULL(time1,0.0); 1144 PS_INT_CHECK_RANGE(time1-> usec,0,1e6-1,0.0);1145 PS_INT_CHECK_RANGE(time1->nsec,0,1e9-1,0.0); 1145 1146 PS_PTR_CHECK_NULL(time2,0.0); 1146 PS_INT_CHECK_RANGE(time2-> usec,0,1e6-1,0.0);1147 PS_INT_CHECK_RANGE(time2->nsec,0,1e9-1,0.0); 1147 1148 1148 1149 // Convert time to TAI if necessary, but without changing input arguments … … 1150 1151 tempTime1 = psTimeAlloc(PS_TIME_UTC); 1151 1152 tempTime1->sec = time1->sec; 1152 tempTime1-> usec = time1->usec;1153 tempTime1->nsec = time1->nsec; 1153 1154 tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI); 1154 1155 } else { … … 1158 1159 tempTime2 = psTimeAlloc(PS_TIME_UTC); 1159 1160 tempTime2->sec = time2->sec; 1160 tempTime2-> usec = time2->usec;1161 tempTime2->nsec = time2->nsec; 1161 1162 tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI); 1162 1163 } else { … … 1165 1166 1166 1167 uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0; 1167 uSec1 = uSec1*tempTime1-> usec/1e6;1168 uSec1 = uSec1*tempTime1->nsec/1e9; 1168 1169 uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0; 1169 uSec2 = uSec2*tempTime2-> usec/1e6;1170 uSec2 = uSec2*tempTime2->nsec/1e9; 1170 1171 out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2); 1171 1172 -
trunk/psLib/src/astro/psTime.h
r3708 r3712 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-04-19 0 0:17:05$12 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-04-19 02:13:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 40 40 PS_TIME_TAI, ///< Temps Atomique International (TAI) time (time with leapseconds). 41 41 PS_TIME_UTC, ///< Universal Time Coordinated (UTC) time (time without leapseconds). 42 PS_TIME_UT1, ///< Universal Time corrected for polar motion 43 PS_TIME_TT, ///< Terrestrial Time 42 44 } psTimeType; 43 45 … … 52 54 { 53 55 psS64 sec; ///< Seconds since epoch, Jan 1, 1970. 54 psU32 usec; ///< Microseconds since last second. 56 psU32 nsec; ///< Nanoseconds since last second. 57 psBool leapsecond; ///< if time falls on UTC leapsecond 55 58 psTimeType type; ///< Type of time. 56 59 } -
trunk/psLib/src/astronomy/psTime.c
r3708 r3712 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.5 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-04-19 0 0:17:05$12 * @version $Revision: 1.59 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-04-19 02:13:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 64 64 65 65 /** Microseconds per day */ 66 #define USEC_PER_DAY 86400000000.066 #define NSEC_PER_DAY 86400000000000.0 67 67 68 68 /** Time metadata read from config file */ … … 363 363 364 364 outTime->sec = 0; 365 outTime-> usec = 0;365 outTime->nsec = 0; 366 366 outTime->type = type; 367 outTime->leapsecond = false; 367 368 368 369 return outTime; … … 386 387 // Convert timeval time to psTime 387 388 time->sec = now.tv_sec; 388 time-> usec = now.tv_usec;389 time->nsec = now.tv_usec*1000; 389 390 390 391 // Add most leapseconds to UTC time to get TAI time if necessary … … 403 404 // Error checks 404 405 PS_PTR_CHECK_NULL(time,NULL); 405 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);406 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 406 407 407 408 if (time->type == type) { // time already right type. That was easy! … … 448 449 // Error checks 449 450 PS_PTR_CHECK_NULL(time,NAN); 450 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);451 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 451 452 452 453 // Calculate TAI or UTC time based on type of time user passes … … 455 456 utcTime = psTimeAlloc(PS_TIME_UTC); 456 457 utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time); 457 utcTime-> usec = taiTime->usec;458 utcTime->nsec = taiTime->nsec; 458 459 } else if(time->type == PS_TIME_UTC) { 459 460 utcTime = psMemIncrRefCounter(time); 460 461 taiTime = psTimeAlloc(PS_TIME_TAI); 461 462 taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time); 462 taiTime-> usec = utcTime->usec;463 taiTime->nsec = utcTime->nsec; 463 464 } 464 465 … … 519 520 // Error checks 520 521 PS_PTR_CHECK_NULL(time,NAN); 521 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);522 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 522 523 523 524 if(time->type != PS_TIME_TAI) { … … 592 593 // Error checks 593 594 PS_PTR_CHECK_NULL(time,NULL); 594 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);595 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 595 596 596 597 if(time->type != PS_TIME_TAI) … … 715 716 // Error checks 716 717 PS_PTR_CHECK_NULL(time,NAN); 717 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);718 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 718 719 719 720 // Check time metadata … … 768 769 PS_PTR_CHECK_NULL(time1,0); 769 770 PS_PTR_CHECK_NULL(time2,0); 770 PS_INT_CHECK_RANGE(time1-> usec,0,1e6-1,0);771 PS_INT_CHECK_RANGE(time2-> usec,0,1e6-1,0);771 PS_INT_CHECK_RANGE(time1->nsec,0,1e9-1,0); 772 PS_INT_CHECK_RANGE(time2->nsec,0,1e9-1,0); 772 773 diff = abs((psS64)psTimeGetTAIDelta((psTime*)time1)-(psS64)psTimeGetTAIDelta((psTime*)time2)); 773 774 … … 781 782 // Error checks 782 783 PS_PTR_CHECK_NULL(time,NAN); 783 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);784 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 784 785 785 786 // Julian date conversion 786 787 if(time->sec < 0) { 787 jd = time->sec / SEC_PER_DAY - time-> usec / USEC_PER_DAY + 2440587.5; // psTime earlier than epoch788 jd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 2440587.5; // psTime earlier than epoch 788 789 } else { 789 jd = time->sec / SEC_PER_DAY + time-> usec / USEC_PER_DAY + 2440587.5; // psTime greater than epoch790 jd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 2440587.5; // psTime greater than epoch 790 791 } 791 792 … … 800 801 // Error checks 801 802 PS_PTR_CHECK_NULL(time,NAN); 802 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NAN);803 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NAN); 803 804 804 805 // Modified Julian date conversion 805 806 if(time->sec < 0) { 806 mjd = time->sec / SEC_PER_DAY - time-> usec / USEC_PER_DAY + 40587.0; // psTime earlier than epoch807 mjd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 40587.0; // psTime earlier than epoch 807 808 } else { 808 mjd = time->sec / SEC_PER_DAY + time-> usec / USEC_PER_DAY + 40587.0; // psTime greater than epoch809 mjd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 40587.0; // psTime greater than epoch 809 810 } 810 811 … … 823 824 // Error checks 824 825 PS_PTR_CHECK_NULL(time,NULL); 825 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);826 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 826 827 827 828 tempString = psAlloc(MAX_TIME_STRING_LENGTH); 828 829 timeString = psAlloc(MAX_TIME_STRING_LENGTH); 829 830 830 ms = time-> usec / 1000;831 ms = time->nsec / 1000000; 831 832 sec = time->sec; 832 833 … … 856 857 // Error checks 857 858 PS_PTR_CHECK_NULL(time,timevalTime); 858 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,timevalTime);859 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,timevalTime); 859 860 860 861 timevalTime.tv_sec = time->sec; 861 timevalTime.tv_usec = time-> usec;862 timevalTime.tv_usec = time->nsec / 1000; 862 863 863 864 return timevalTime; … … 879 880 // Error checks 880 881 PS_PTR_CHECK_NULL(time,NULL); 881 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);882 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 882 883 883 884 seconds = time->sec%60; … … 941 942 seconds = days * SEC_PER_DAY; 942 943 if(seconds < 0.0) { 943 outTime-> usec = (seconds - (psS64)seconds) * -1000000.0; // psTime earlier than epoch944 outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0; // psTime earlier than epoch 944 945 } else { 945 outTime-> usec = (seconds - (psS64)seconds) * 1000000.0; // psTime greater than epoch946 outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0; // psTime greater than epoch 946 947 } 947 948 outTime->sec = seconds; 948 949 949 950 // Error check 950 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);951 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 951 952 952 953 return outTime; … … 967 968 seconds = days * SEC_PER_DAY; 968 969 if(seconds < 0.0) { 969 outTime-> usec = (seconds - (psS64)seconds) * -1000000.0; // psTime earlier than epoch970 outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0; // psTime earlier than epoch 970 971 } else { 971 outTime-> usec = (seconds - (psS64)seconds) * 1000000.0; // psTime greater than epoch972 outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0; // psTime greater than epoch 972 973 } 973 974 outTime->sec = seconds; 974 975 975 976 // Error check 976 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);977 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 977 978 978 979 return outTime; … … 1006 1007 // Convert tm time to psTime 1007 1008 outTime = psTimeFromTM(&tmTime); 1008 outTime-> usec = millisecond * 1000;1009 outTime->nsec = millisecond * 1000000; 1009 1010 1010 1011 return outTime; … … 1024 1025 // Convert to psTime 1025 1026 outTime->sec = time->tv_sec; 1026 outTime-> usec = time->tv_usec;1027 outTime->nsec = time->tv_usec * 1000; 1027 1028 1028 1029 // Error check 1029 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1030 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1030 1031 1031 1032 return outTime; … … 1083 1084 1084 1085 // C's TM does not define a microsecond field. Microseconds must be manipulated by calling function. 1085 outTime-> usec = 0;1086 outTime->nsec = 0; 1086 1087 1087 1088 // Error check 1088 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1089 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1089 1090 1090 1091 return outTime; … … 1100 1101 // Error checks 1101 1102 PS_PTR_CHECK_NULL(time,NULL); 1102 PS_INT_CHECK_RANGE(time-> usec,0,1e6-1,NULL);1103 PS_INT_CHECK_RANGE(time->nsec,0,1e9-1,NULL); 1103 1104 1104 1105 // Convert time to TAI if necessary, but without changing input arguments … … 1106 1107 tempTime = psTimeAlloc(PS_TIME_UTC); 1107 1108 tempTime->sec = time->sec; 1108 tempTime-> usec = time->usec;1109 tempTime->nsec = time->nsec; 1109 1110 tempTime = psTimeConvert(tempTime, PS_TIME_TAI); 1110 1111 } else { … … 1114 1115 // Create output time 1115 1116 outTime = psTimeAlloc(PS_TIME_TAI); 1116 sec = delta + (psF64)tempTime->sec + (psF64)tempTime-> usec/1e6;1117 sec = delta + (psF64)tempTime->sec + (psF64)tempTime->nsec/1e9; 1117 1118 outTime->sec = sec; 1118 outTime-> usec = (sec - outTime->sec)*1e6;1119 outTime->nsec = (sec - outTime->sec)*1e9; 1119 1120 1120 1121 // Error check 1121 PS_INT_CHECK_RANGE(outTime-> usec,0,1e6-1,outTime);1122 PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime); 1122 1123 1123 1124 // Convert result to same time type as input … … 1142 1143 // Error checks 1143 1144 PS_PTR_CHECK_NULL(time1,0.0); 1144 PS_INT_CHECK_RANGE(time1-> usec,0,1e6-1,0.0);1145 PS_INT_CHECK_RANGE(time1->nsec,0,1e9-1,0.0); 1145 1146 PS_PTR_CHECK_NULL(time2,0.0); 1146 PS_INT_CHECK_RANGE(time2-> usec,0,1e6-1,0.0);1147 PS_INT_CHECK_RANGE(time2->nsec,0,1e9-1,0.0); 1147 1148 1148 1149 // Convert time to TAI if necessary, but without changing input arguments … … 1150 1151 tempTime1 = psTimeAlloc(PS_TIME_UTC); 1151 1152 tempTime1->sec = time1->sec; 1152 tempTime1-> usec = time1->usec;1153 tempTime1->nsec = time1->nsec; 1153 1154 tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI); 1154 1155 } else { … … 1158 1159 tempTime2 = psTimeAlloc(PS_TIME_UTC); 1159 1160 tempTime2->sec = time2->sec; 1160 tempTime2-> usec = time2->usec;1161 tempTime2->nsec = time2->nsec; 1161 1162 tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI); 1162 1163 } else { … … 1165 1166 1166 1167 uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0; 1167 uSec1 = uSec1*tempTime1-> usec/1e6;1168 uSec1 = uSec1*tempTime1->nsec/1e9; 1168 1169 uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0; 1169 uSec2 = uSec2*tempTime2-> usec/1e6;1170 uSec2 = uSec2*tempTime2->nsec/1e9; 1170 1171 out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2); 1171 1172 -
trunk/psLib/src/astronomy/psTime.h
r3708 r3712 10 10 * @author Ross Harman, MHPCC 11 11 * 12 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $13 * @date $Date: 2005-04-19 0 0:17:05$12 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-04-19 02:13:53 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 40 40 PS_TIME_TAI, ///< Temps Atomique International (TAI) time (time with leapseconds). 41 41 PS_TIME_UTC, ///< Universal Time Coordinated (UTC) time (time without leapseconds). 42 PS_TIME_UT1, ///< Universal Time corrected for polar motion 43 PS_TIME_TT, ///< Terrestrial Time 42 44 } psTimeType; 43 45 … … 52 54 { 53 55 psS64 sec; ///< Seconds since epoch, Jan 1, 1970. 54 psU32 usec; ///< Microseconds since last second. 56 psU32 nsec; ///< Nanoseconds since last second. 57 psBool leapsecond; ///< if time falls on UTC leapsecond 55 58 psTimeType type; ///< Type of time. 56 59 } -
trunk/psLib/test/astronomy/tst_psTime_01.c
r3708 r3712 23 23 * @author Ross Harman, MHPCC 24 24 * 25 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $26 * @date $Date: 2005-04-19 0 0:17:06$25 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 26 * @date $Date: 2005-04-19 02:13:53 $ 27 27 * 28 28 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 44 44 testTime = (psTime*)psAlloc(sizeof(psTime)); 45 45 testTime->sec = 1090434144; 46 testTime-> usec = 272044;46 testTime->nsec = 272044000; 47 47 testTime->type = PS_TIME_TAI; 48 48 … … 57 57 // Test B - Print test time 58 58 printPositiveTestHeader(stdout,"psTime", "Print test time"); 59 printf("Test time: Seconds = %lld Microseconds = %u\n",59 printf("Test time: Seconds = %lld Nanoseconds = %u\n", 60 60 (long long int)testTime->sec, 61 testTime-> usec);61 testTime->nsec); 62 62 printFooter(stdout, "psTime", "Print test time", true); 63 63 … … 79 79 psTime *timeD = NULL; 80 80 timeD = psTimeFromISO(isoString); 81 printf("psTime: Seconds = %lld Microseconds = %u\n",81 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 82 82 (long long int)timeD->sec, 83 timeD-> usec);83 timeD->nsec); 84 84 psFree(isoString); 85 85 psFree(timeD); … … 92 92 timeE = (psTime*)psAlloc(sizeof(psTime)); 93 93 timeE->sec = 1090434144; 94 timeE-> usec = 272044;94 timeE->nsec = 272044000; 95 95 timeE->type = PS_TIME_TAI; 96 96 timeE = psTimeConvert(timeE, PS_TIME_UTC); 97 97 psFree(timeE); 98 printf("psTime: Seconds = %lld Microseconds = %u\n",98 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 99 99 (long long int)timeE->sec, 100 timeE-> usec);100 timeE->nsec); 101 101 printFooter(stdout, "psTime", "Convert psTime time to UTC time", true); 102 102 … … 107 107 timeF = (psTime*)psAlloc(sizeof(psTime)); 108 108 timeF->sec = 1090434112; 109 timeF-> usec = 272044;109 timeF->nsec = 272044000; 110 110 timeF->type = PS_TIME_UTC; 111 111 timeF = psTimeConvert(timeF, PS_TIME_TAI); 112 112 psFree(timeF); 113 printf("psTime: Seconds = %lld Microseconds = %u\n",113 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 114 114 (long long int)timeF->sec, 115 timeF-> usec);115 timeF->nsec); 116 116 printFooter(stdout, "psTime", "Convert UTC time to psTime", true); 117 117 … … 129 129 psTime *timeH = NULL; 130 130 timeH = psTimeFromMJD(mjdTime); 131 printf("psTime: Seconds = %lld Microseconds = %u\n",131 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 132 132 (long long int)timeH->sec, 133 timeH-> usec);133 timeH->nsec); 134 134 psFree(timeH); 135 135 printFooter(stdout, "psTime", "Convert MJD time to psTime", true); … … 148 148 psTime *timeJ = NULL; 149 149 timeJ = psTimeFromJD(jdTime); 150 printf("psTime: Seconds = %lld Microseconds = %u\n",150 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 151 151 (long long int)timeJ->sec, 152 timeJ-> usec);152 timeJ->nsec); 153 153 psFree(timeJ); 154 154 printFooter(stdout, "psTime", "Convert JD time to psTime", true); … … 169 169 psTime *timeL = NULL; 170 170 timeL = psTimeFromTimeval(&timevalTime); 171 printf("psTime: Seconds = %lld Microseconds = %u\n",171 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 172 172 (long long int)timeL->sec, 173 timeL-> usec);173 timeL->nsec); 174 174 psFree(timeL); 175 175 printFooter(stdout, "psTime", "Convert timeval time to psTime", true); … … 194 194 psTime *timeN = NULL; 195 195 timeN = psTimeFromTM(tmTime); 196 printf("psTime: Seconds = %lld Microseconds = %u\n",196 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 197 197 (long long int)timeN->sec, 198 timeN-> usec);198 timeN->nsec); 199 199 psFree(timeN); 200 200 psFree(tmTime); -
trunk/psLib/test/astronomy/tst_psTime_03.c
r3705 r3712 19 19 * @author Ross Harman, MHPCC 20 20 * 21 * @version $Revision: 1.1 5$ $Name: not supported by cvs2svn $22 * @date $Date: 2005-04-1 8 23:30:54$21 * @version $Revision: 1.16 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-04-19 02:13:53 $ 23 23 * 24 24 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 31 31 #define PRINT_TIME(TEXT,TIME) \ 32 printf("%s Seconds = %lld Microseconds = %u\n", TEXT, (long long int)TIME->sec, TIME->usec);32 printf("%s Seconds = %lld Nanoseconds = %u\n", TEXT, (long long int)TIME->sec, TIME->nsec); 33 33 34 34 psS32 main(psS32 argc, char* argv[]) … … 44 44 time1a = psTimeAlloc(PS_TIME_TAI); 45 45 time1a->sec = 1; 46 time1a-> usec = 111111;46 time1a->nsec = 111111000; 47 47 timeOut1 = psTimeMath(time1a, time1b); 48 if(timeOut1->sec!=2 && timeOut1-> usec!=222222) {49 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222 \n",(long long int)timeOut1->sec, timeOut1->usec);48 if(timeOut1->sec!=2 && timeOut1->nsec!=222222000) { 49 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222000\n",(long long int)timeOut1->sec, timeOut1->nsec); 50 50 } 51 51 printFooter(stdout, "psTime", "Test A - Add two times", true); 52 52 53 53 54 // Test B - Add two times with overflow in microseconds54 // Test B - Add two times with overflow in nanoseconds 55 55 printPositiveTestHeader(stdout, "psTime", "Test B - Add two times with overflow in microseconds"); 56 56 psTime *time2a = NULL; … … 59 59 time2a = psTimeAlloc(PS_TIME_TAI); 60 60 time2a->sec = 6; 61 time2a-> usec = 600001;61 time2a->nsec = 600001000; 62 62 timeOut2 = psTimeMath(time2a, time2b); 63 if(timeOut2->sec!=12 && timeOut2-> usec!=100002) {64 printf("ERROR: Incorrect time, %lld:%u. Expected 12:100002 \n",(long long int)timeOut2->sec, timeOut2->usec);63 if(timeOut2->sec!=12 && timeOut2->nsec!=100002000) { 64 printf("ERROR: Incorrect time, %lld:%u. Expected 12:100002000\n",(long long int)timeOut2->sec, timeOut2->nsec); 65 65 } 66 66 printFooter(stdout, "psTime", "Test B - Add two times with overflow in microseconds", true); … … 74 74 time3a = psTimeAlloc(PS_TIME_TAI); 75 75 time3a->sec = 3; 76 time3a-> usec = 333333;76 time3a->nsec = 333333000; 77 77 timeOut3 = psTimeMath(time3a, time3b); 78 if(timeOut3->sec!=2 && timeOut3-> usec!=222222) {79 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222 \n",(long long int)timeOut3->sec, timeOut3->usec);78 if(timeOut3->sec!=2 && timeOut3->nsec!=222222000) { 79 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222000\n",(long long int)timeOut3->sec, timeOut3->nsec); 80 80 } 81 81 printFooter(stdout, "psTime", "Test C - Subtract two times", true); 82 82 83 83 84 // Test D - Subtact two times with underflow in microseconds85 printPositiveTestHeader(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds");84 // Test D - Subtact two times with underflow in nanoseconds 85 printPositiveTestHeader(stdout, "psTime", "Test D - Subtact two times with underflow in nanoseconds"); 86 86 psTime *time4a = NULL; 87 87 psF64 time4b = -2.000003; … … 89 89 time4a = psTimeAlloc(PS_TIME_TAI); 90 90 time4a->sec = 5; 91 time4a-> usec = 1;91 time4a->nsec = 1000; 92 92 timeOut4 = psTimeMath(time4a, time4b); 93 if(timeOut4->sec!=2 && timeOut4-> usec!=999997) {94 printf("ERROR: Incorrect time, %lld:%u. Expected 2:999997 \n",(long long int)timeOut4->sec, timeOut4->usec);95 } 96 printFooter(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds", true);93 if(timeOut4->sec!=2 && timeOut4->nsec!=999997000) { 94 printf("ERROR: Incorrect time, %lld:%u. Expected 2:999997000\n",(long long int)timeOut4->sec, timeOut4->nsec); 95 } 96 printFooter(stdout, "psTime", "Test D - Subtact two times with underflow in nanoseconds", true); 97 97 98 98 … … 105 105 time5b = psTimeAlloc(PS_TIME_TAI); 106 106 time5a->sec = 8; 107 time5a-> usec = 8;107 time5a->nsec = 8000; 108 108 time5b->sec = 7; 109 time5b-> usec = 7;109 time5b->nsec = 7000; 110 110 timeOut5 = psTimeDelta(time5a, time5b); 111 111 if(fabs(timeOut5-1.000001) > FLT_EPSILON) { … … 123 123 time6b = psTimeAlloc(PS_TIME_TAI); 124 124 time6a->sec = 8; 125 time6a-> usec = 1;125 time6a->nsec = 1000; 126 126 time6b->sec = 7; 127 time6b-> usec = 7;127 time6b->nsec = 7000; 128 128 timeOut6 = psTimeDelta(time6a, time6b); 129 129 if(fabs(timeOut6-0.999994) > FLT_EPSILON) { … … 140 140 time20b = psTimeAlloc(PS_TIME_UTC); 141 141 time20a->sec = 1090434113; 142 time20a-> usec = 272044;142 time20a->nsec = 272044000; 143 143 time20b->sec = 1090434112; 144 time20b-> usec = 272044;144 time20b->nsec = 272044000; 145 145 timeOut20 = psTimeDelta(time20a, time20b); 146 146 if(fabs(timeOut20-1.000000000) > FLT_EPSILON) { -
trunk/psLib/test/astronomy/verified/tst_psTime_01.stdout
r2746 r3712 14 14 \**********************************************************************************/ 15 15 16 Test time: Seconds = 1090434144 Microseconds = 27204416 Test time: Seconds = 1090434144 Nanoseconds = 272044000 17 17 18 18 ---> TESTPOINT PASSED (psTime{Print test time} | tst_psTime_01.c) … … 34 34 \**********************************************************************************/ 35 35 36 psTime: Seconds = 1090434144 Microseconds = 27200036 psTime: Seconds = 1090434144 Nanoseconds = 272000000 37 37 38 38 ---> TESTPOINT PASSED (psTime{Convert ISO time to psTime} | tst_psTime_01.c) … … 44 44 \**********************************************************************************/ 45 45 46 psTime: Seconds = 1090434112 Microseconds = 27204446 psTime: Seconds = 1090434112 Nanoseconds = 272044000 47 47 48 48 ---> TESTPOINT PASSED (psTime{Convert psTime time to UTC time} | tst_psTime_01.c) … … 54 54 \**********************************************************************************/ 55 55 56 psTime: Seconds = 1090434144 Microseconds = 27204456 psTime: Seconds = 1090434144 Nanoseconds = 272044000 57 57 58 58 ---> TESTPOINT PASSED (psTime{Convert UTC time to psTime} | tst_psTime_01.c) … … 74 74 \**********************************************************************************/ 75 75 76 psTime: Seconds = 1090434144 Microseconds = 27204376 psTime: Seconds = 1090434144 Nanoseconds = 272043704 77 77 78 78 ---> TESTPOINT PASSED (psTime{Convert MJD time to psTime} | tst_psTime_01.c) … … 94 94 \**********************************************************************************/ 95 95 96 psTime: Seconds = 1090434144 Microseconds = 27204896 psTime: Seconds = 1090434144 Nanoseconds = 272048711 97 97 98 98 ---> TESTPOINT PASSED (psTime{Convert JD time to psTime} | tst_psTime_01.c) … … 114 114 \**********************************************************************************/ 115 115 116 psTime: Seconds = 1090434144 Microseconds = 272044116 psTime: Seconds = 1090434144 Nanoseconds = 272044000 117 117 118 118 ---> TESTPOINT PASSED (psTime{Convert timeval time to psTime} | tst_psTime_01.c) … … 140 140 \**********************************************************************************/ 141 141 142 psTime: Seconds = 1090434144 Microseconds = 0142 psTime: Seconds = 1090434144 Nanoseconds = 0 143 143 144 144 ---> TESTPOINT PASSED (psTime{Convert tm time to psTime} | tst_psTime_01.c) -
trunk/psLib/test/astronomy/verified/tst_psTime_03.stdout
r2966 r3712 28 28 /***************************** TESTPOINT ******************************************\ 29 29 * TestFile: tst_psTime_03.c * 30 * TestPoint: psTime{Test D - Subtact two times with underflow in microseconds} *30 * TestPoint: psTime{Test D - Subtact two times with underflow in nanoseconds} * 31 31 * TestType: Positive * 32 32 \**********************************************************************************/ 33 33 34 34 35 ---> TESTPOINT PASSED (psTime{Test D - Subtact two times with underflow in microseconds} | tst_psTime_03.c)35 ---> TESTPOINT PASSED (psTime{Test D - Subtact two times with underflow in nanoseconds} | tst_psTime_03.c) 36 36 37 37 /***************************** TESTPOINT ******************************************\
Note:
See TracChangeset
for help on using the changeset viewer.
