Changeset 2181 for trunk/psLib/src/astro/psTime.c
- Timestamp:
- Oct 20, 2004, 11:21:58 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astro/psTime.c (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psTime.c
r2179 r2181 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.3 5$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-10-20 2 0:05:51$13 * @version $Revision: 1.36 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-10-20 21:21:58 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 72 72 #define LINESIZE 1024 73 73 74 /** Preprocessor macro to check for null psTime struct */ 75 #define CHECK_NULL_TIME(TIME,RETURN) \ 76 if(TIME == NULL) { \ 77 psError(__func__,"NULL value not allowed"); \ 78 return RETURN; \ 79 } 80 81 /** Preprocessor macro to allocate psTime struct */ 82 #define ALLOC_TIME(TIME) \ 83 TIME = (psTime*)psAlloc(sizeof(psTime)); \ 84 if (TIME == NULL) { \ 85 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__); \ 86 } \ 87 TIME->sec = 0; \ 88 TIME->usec = 0; \ 89 TIME->type = PS_TIME_TAI; 90 91 /** Read TAI/UTC data file. 92 * 93 * Reads TAI/UTC data file. 94 * 95 * @return psImage*: Two-dimensional array with table data. 96 */ 97 static psImage* readTaiUtcFile( 98 const char *fileName ///< Name of file to read. 99 ); 74 /** Read TAI/UTC data file. 75 * 76 * Reads TAI/UTC data file. 77 * 78 * @return psImage*: Two-dimensional array with table data. 79 */ 80 static psImage* readTaiUtcFile( 81 const char *fileName ///< Name of file to read. 82 ); 100 83 101 84 … … 488 471 psTime *outTime = NULL; 489 472 473 474 // Error checks 490 475 if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) { 491 476 psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type); … … 512 497 513 498 // Allocate psTime struct 514 ALLOC_TIME(time);499 time = psTimeAlloc(type); 515 500 516 501 if (gettimeofday(&now, (struct timezone *)0) == -1) { … … 522 507 time->sec = now.tv_sec; 523 508 time->usec = now.tv_usec; 524 time->type = type;525 509 526 510 // Add most leapseconds to UTC time to get TAI time if necessary … … 537 521 538 522 539 if(time->type == type) { 540 psError(__func__, " : Line %d - Time is already in the correct psTime format. Time type: %d", __LINE__, type); 523 // Error checks 524 if(time == NULL) { 525 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 526 return NULL; 527 } else if(time->usec >= 1e6) { 528 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 529 return NULL; 530 } else if(time->type == type) { 531 psError(__func__, " : Line %d - Time already in correct psTime type. Time type: %d", __LINE__, type); 541 532 return NULL; 542 533 } … … 545 536 546 537 if(type == PS_TIME_UTC) { 547 time->sec = time->sec - delta; // User wants UTC time. Removeleapseconds.538 time->sec = time->sec - delta; // User wants UTC time. Subtract leapseconds. 548 539 } else if(type == PS_TIME_TAI) { 549 540 time->sec = time->sec + delta; // User wants TAI time. Add leapseconds. … … 580 571 581 572 573 // Error checks 574 if(time == NULL) { 575 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 576 return 0; 577 } else if(time->usec >= 1e6) { 578 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 579 return 0; 580 } 581 582 582 // Calculate TAI or UTC time based on type of time user passes 583 583 if(time->type == PS_TIME_TAI) { 584 584 taiTime = psMemIncrRefCounter(time); 585 ALLOC_TIME(utcTime);585 utcTime = psTimeAlloc(PS_TIME_UTC); 586 586 utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time); 587 587 utcTime->usec = taiTime->usec; 588 utcTime->type = PS_TIME_UTC;589 588 } else if(time->type == PS_TIME_UTC) { 590 589 utcTime = psMemIncrRefCounter(time); 591 ALLOC_TIME(taiTime);590 taiTime = psTimeAlloc(PS_TIME_TAI); 592 591 taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time); 593 592 taiTime->usec = utcTime->usec; 594 taiTime->type = PS_TIME_TAI;595 593 } 596 594 597 595 // Convert Universal Time (UTC) to UT1 598 ALLOC_TIME(ut1UtcDelta); 599 ut1UtcDelta->type = PS_TIME_UTC; 596 ut1UtcDelta = psTimeAlloc(PS_TIME_UTC); 600 597 601 598 ut1UtcDbl = psTimeGetUT1Delta(utcTime)*1e6; … … 614 611 615 612 // Calculate Terrestial Dynamical Time (TDT) 616 ALLOC_TIME(tdtDelta);613 tdtDelta = psTimeAlloc(PS_TIME_TAI); 617 614 tdtDelta->sec = 32; 618 615 tdtDelta->usec = 184000; … … 648 645 double psTimeGetUT1Delta(const psTime *time) 649 646 { 647 648 // Error checks 649 if(time == NULL) { 650 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 651 return 0.0; 652 } else if(time->usec >= 1e6) { 653 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 654 return 0.0; 655 } 656 650 657 return lookupSer7Table(time, 6); 651 658 } … … 653 660 struct psSphere* psTimeGetPoleCoords(const psTime* time) 654 661 { 655 656 double x = lookupSer7Table((psTime*)time, 4); 657 double y = lookupSer7Table((psTime*)time, 5); 658 659 struct psSphere* output = psAlloc(sizeof(psSphere)); 662 double x = 0.0; 663 double y = 0.0; 664 struct psSphere* output = NULL; 665 666 667 // Error checks 668 if(time == NULL) 669 { 670 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 671 return NULL; 672 } else if(time->usec >= 1e6) 673 { 674 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 675 return NULL; 676 } 677 678 x = lookupSer7Table((psTime*)time, 4); 679 y = lookupSer7Table((psTime*)time, 5); 680 681 output = psAlloc(sizeof(psSphere)); 660 682 output->r = x * M_PI / 648000.0; // x in arcsec converted to radians, i.e., x/60/60*M_PI/180 661 683 output->d = y * M_PI / 648000.0; … … 666 688 double psTimeGetTAIDelta(const psTime *time) 667 689 { 690 691 // Error checks 692 if(time == NULL) { 693 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 694 return 0.0; 695 } else if(time->usec >= 1e6) { 696 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 697 return 0.0; 698 } 699 668 700 return lookupTaiUtcTable(time); 669 701 } … … 673 705 long diff = 0; 674 706 675 // NULL error checks 676 CHECK_NULL_TIME(time1,0); 677 CHECK_NULL_TIME(time2,0); 707 708 // Error checks 709 if(time1 == NULL) { 710 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 711 return 0; 712 } else if(time1->usec >= 1e6) { 713 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time1->usec); 714 return 0; 715 } else if(time2 == NULL) { 716 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 717 return 0; 718 } else if(time2->usec >= 1e6) { 719 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time2->usec); 720 return 0; 721 } 678 722 679 723 diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2)); … … 687 731 688 732 689 // NULL error check 690 CHECK_NULL_TIME(time,0.0); 733 // Error checks 734 if(time == NULL) { 735 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 736 return 0.0; 737 } else if(time->usec >= 1e6) { 738 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 739 return 0.0; 740 } 691 741 692 742 // Julian date conversion … … 705 755 706 756 707 // NULL error check 708 CHECK_NULL_TIME(time,0.0); 757 // Error checks 758 if(time == NULL) { 759 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 760 return 0.0; 761 } else if(time->usec >= 1e6) { 762 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 763 return 0.0; 764 } 709 765 710 766 // Modified Julian date conversion … … 727 783 728 784 729 // NULL error check 730 CHECK_NULL_TIME(time,NULL); 785 // Error checks 786 if(time == NULL) { 787 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 788 return NULL; 789 } else if(time->usec >= 1e6) { 790 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 791 return NULL; 792 } 731 793 732 794 tempString = psAlloc(MAX_TIME_STRING_LENGTH); … … 757 819 758 820 759 // NULL error check 760 CHECK_NULL_TIME(time,timevalTime); 821 // Error checks 822 if(time == NULL) 823 { 824 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 825 return timevalTime; 826 } else if(time->usec >= 1e6) 827 { 828 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 829 return timevalTime; 830 } 761 831 762 832 timevalTime.tv_sec = time->sec; … … 779 849 780 850 851 // Error checks 852 if(time == NULL) 853 { 854 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 855 return NULL; 856 } else if(time->usec >= 1e6) 857 { 858 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 859 return NULL; 860 } 861 781 862 seconds = time->sec%60; 782 863 minute = time->sec/60%60; … … 837 918 838 919 // Allocate psTime struct 839 ALLOC_TIME(outTime);920 outTime = psTimeAlloc(PS_TIME_TAI); 840 921 841 922 // Julian date conversion courtesy of Eugene Magnier … … 849 930 outTime->sec = seconds; 850 931 932 // Error check 933 if(outTime->usec >= 1e6) { 934 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 935 } 936 851 937 return outTime; 852 938 } … … 860 946 861 947 // Allocate psTime struct 862 ALLOC_TIME(outTime);948 outTime = psTimeAlloc(PS_TIME_TAI); 863 949 864 950 // Modified Julian date conversion courtesy of Eugene Magnier … … 871 957 } 872 958 outTime->sec = seconds; 959 960 // Error check 961 if(outTime->usec >= 1e6) { 962 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 963 } 873 964 874 965 return outTime; … … 947 1038 outTime->usec = millisecond * 1000; 948 1039 1040 // Error check 1041 if(outTime->usec >= 1e6) { 1042 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1043 } 1044 949 1045 return outTime; 950 1046 } … … 955 1051 956 1052 957 // NULL error check 958 CHECK_NULL_TIME(time,NULL); 1053 // Error check 1054 if(time == NULL) 1055 { 1056 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1057 return NULL; 1058 } 959 1059 960 1060 // Allocate psTime struct 961 ALLOC_TIME(outTime)1061 outTime = psTimeAlloc(PS_TIME_TAI); 962 1062 963 1063 // Convert to psTime 964 1064 outTime->sec = time->tv_sec; 965 1065 outTime->usec = time->tv_usec; 1066 1067 // Error check 1068 if(outTime->usec >= 1e6) 1069 { 1070 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1071 } 966 1072 967 1073 return outTime; … … 979 1085 psTime *outTime = NULL; 980 1086 981 // NULL error check 982 CHECK_NULL_TIME(time,NULL); 1087 1088 // Error check 1089 if(time == NULL) 1090 { 1091 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1092 return NULL; 1093 } 983 1094 984 1095 // Allocate psTime struct 985 ALLOC_TIME(outTime);1096 outTime = psTimeAlloc(PS_TIME_TAI); 986 1097 987 1098 // Extract data from TM struct … … 1020 1131 outTime->usec = 0; 1021 1132 1133 // Error check 1134 if(outTime->usec >= 1e6) 1135 { 1136 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1137 } 1138 1022 1139 return outTime; 1023 1140 } … … 1030 1147 1031 1148 1149 // Error checks 1032 1150 if(tai1->type != tai2->type) { 1033 1151 psError(__func__, " : Line %d - Argument types inconsistent for time addition", __LINE__); 1034 1152 return NULL; 1153 } else if(tai1 == NULL) { 1154 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1155 return NULL; 1035 1156 } else if(tai1->usec >= 1e6) { 1036 1157 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1037 1158 return NULL; 1159 } else if(tai2 == NULL) { 1160 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1161 return NULL; 1038 1162 } else if(tai2->usec >= 1e6) { 1039 1163 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); … … 1041 1165 } 1042 1166 1043 ALLOC_TIME(outTime); 1044 outTime->type = tai1->type; 1167 outTime = psTimeAlloc(tai1->type); 1045 1168 outTime->sec = tai1->sec + tai2->sec; 1046 1169 deltaUsec = tai1->usec + tai2->usec; … … 1058 1181 } 1059 1182 1183 // Error check 1184 if(outTime->usec >= 1e6) { 1185 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1186 } 1187 1060 1188 return outTime; 1061 1189 } … … 1068 1196 1069 1197 1198 // Error checks 1070 1199 if(tai1->type != tai2->type) { 1071 1200 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1072 1201 return NULL; 1202 } else if(tai1 == NULL) { 1203 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1204 return NULL; 1073 1205 } else if(tai1->usec >= 1e6) { 1074 1206 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1075 1207 return NULL; 1208 } else if(tai2 == NULL) { 1209 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1210 return NULL; 1076 1211 } else if(tai2->usec >= 1e6) { 1077 1212 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); … … 1079 1214 } 1080 1215 1081 ALLOC_TIME(outTime); 1082 outTime->type = tai1->type; 1216 outTime = psTimeAlloc(tai1->type); 1083 1217 deltaSec = tai1->sec - tai2->sec; 1084 1218 deltaUsec = (long)tai1->usec - (long)tai2->usec; … … 1108 1242 1109 1243 1244 // Error checks 1110 1245 if(tai1->type != tai2->type) { 1111 1246 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1112 1247 return NULL; 1248 } else if(tai1 == NULL) { 1249 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1250 return NULL; 1113 1251 } else if(tai1->usec >= 1e6) { 1114 1252 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1115 1253 return NULL; 1254 } else if(tai2 == NULL) { 1255 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1256 return NULL; 1116 1257 } else if(tai2->usec >= 1e6) { 1117 1258 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); … … 1119 1260 } 1120 1261 1121 ALLOC_TIME(outTime); 1122 outTime->type = tai1->type; 1262 outTime = psTimeAlloc(tai1->type); 1123 1263 deltaSec = tai1->sec - tai2->sec; 1124 1264 deltaUsec = (long)tai1->usec - (long)tai2->usec;
Note:
See TracChangeset
for help on using the changeset viewer.
