Changeset 2273 for trunk/psLib/src/astro/psTime.c
- Timestamp:
- Nov 3, 2004, 3:05:00 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/astro/psTime.c (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/astro/psTime.c
r2204 r2273 11 11 * @author Ross Harman, MHPCC 12 12 * 13 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $14 * @date $Date: 2004-1 0-27 00:57:30$13 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2004-11-04 01:04:57 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 31 #include "psMetadata.h" 32 32 #include "psMetadataIO.h" 33 33 #include "psConstants.h" 34 34 #include "psAstronomyErrors.h" 35 35 … … 151 151 char line[LINESIZE]; 152 152 psS32 j = 0; 153 psS32 maxLines = 100 ;153 psS32 maxLines = 1000; 154 154 psF64 *ptr = NULL; 155 155 psImage *table = NULL; … … 159 159 fd=fopen(fileName, "r"); 160 160 if(fd==NULL) { 161 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName); 161 psError(PS_ERR_IO,true, 162 PS_ERRORTEXT_psTime_FILE_NOT_FOUND, 163 fileName,"Tai-Utc"); 162 164 return NULL; 163 165 } … … 168 170 while(fgets(line, LINESIZE, fd) != NULL) { 169 171 if(j>=maxLines) { 170 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines); 172 psError(PS_ERR_IO,true, 173 PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS, 174 fileName,maxLines); 171 175 return NULL; 172 176 psFree(table); … … 201 205 fd=fopen(fileName, "r"); 202 206 if(fd==NULL) { 203 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName); 207 psError(PS_ERR_IO,true, 208 PS_ERRORTEXT_psTime_FILE_NOT_FOUND, 209 fileName,"Ser7"); 204 210 return NULL ; 205 211 } … … 218 224 219 225 if(j>=maxLines) { 220 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines); 226 psError(PS_ERR_IO,true, 227 PS_ERRORTEXT_psTime_FILE_TOO_MANY_ROWS, 228 fileName,maxLines); 221 229 return NULL; 222 230 psFree(table); … … 240 248 } 241 249 242 /* Not yet used...243 static psImage* readEopcFile(char *fileName)244 {245 char line[LINESIZE];246 psS32 i = 0;247 psS32 j = 0;248 psS32 maxLines = 2500;249 psImage *table = NULL;250 FILE *fd = NULL;251 252 253 fd=fopen(fileName, "r");254 if(fd==NULL) {255 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);256 return NULL ;257 }258 259 // Table shouldn't be larger than 2500 rows. All columns are read.260 table = psImageAlloc(11, maxLines, PS_TYPE_F64);261 for(i=0; i<3; i++) {262 if((fgets(line, LINESIZE, fd) != NULL)) {263 psError(__func__, " : Line %d - Error reading %s", __LINE__, fileName);264 }265 }266 267 while(fgets(line, LINESIZE, fd) != NULL) {268 if(j>=maxLines) {269 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);270 return NULL;271 psFree(table);272 }273 psF64 *ptr = table->data.F64[j++];274 sscanf(line, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",275 ptr, ptr+1, ptr+2, ptr+3, ptr+4, ptr+5, ptr+6, ptr+7, ptr+8, ptr+9, ptr+10);276 }277 278 *(psU32 *)&table->numRows = j;279 280 return table;281 }282 283 static psImage* readFinalsFile(char *fileName)284 {285 char line[LINESIZE];286 psS32 j = 0;287 psS32 maxLines = 15000;288 psImage *table = NULL;289 FILE *fd = NULL;290 291 292 fd=fopen(fileName, "r");293 if(fd==NULL) {294 psError(__func__, " : Line %d - Couldn't open %s", __LINE__, fileName);295 return NULL ;296 }297 298 // Table shouldn't be larger than 15000 rows. Select columns are read.299 table = psImageAlloc(6, maxLines, PS_TYPE_F64);300 while(fgets(line, LINESIZE, fd) != NULL) {301 if(j>=maxLines) {302 psError(__func__, " : Line %d - Too many rows in file. Max size: %d", __LINE__, maxLines);303 return NULL;304 psFree(table);305 }306 307 psF64 *ptr = table->data.F64[j++];308 ptr = table->data.F64[j++];309 310 // Sometimes there are blank entries in this table, so check for a space to determine if there is no entry311 if(*(line+7) == ' ') { // MJD312 *ptr = 0.0;313 } else {314 *ptr = atof(line+7);315 }316 317 if(*(line+18) == ' ') { // Polar motion X318 *(ptr+1) = 0.0;319 } else {320 *(ptr+1) = atof(line+18);321 }322 323 if(*(line+27) == ' ') { // Polar motion X error324 *(ptr+2) = 0.0;325 } else {326 *(ptr+2) = atof(line+27);327 }328 329 if(*(line+37) == ' ') { // Polar motion Y330 *(ptr+3) = 0.0;331 } else {332 *(ptr+3) = atof(line+37);333 }334 335 if(*(line+46) == ' ') { // Polar motion Y error336 *(ptr+4) = 0.0;337 } else {338 *(ptr+4) = atof(line+46);339 }340 341 if(*(line+58) == ' ') { // UT1-UTC342 *(ptr+5) = 0.0;343 } else {344 *(ptr+5) = atof(line+58);345 }346 }347 348 *(psU32 *)&table->numRows = j;349 350 return table;351 }352 */353 250 354 251 static double lookupTaiUtcTable(const psTime *time) … … 389 286 hiIdx++; 390 287 if(hiIdx >= numRows) { 391 psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx); 288 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 289 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 290 jd, "TAI-UTC"); 392 291 return 0.0; 393 292 } … … 395 294 loIdx = hiIdx--; 396 295 if(loIdx < 0) { 397 psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx); 296 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 297 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 298 jd, "TAI-UTC"); 398 299 return 0.0; 399 300 } 400 301 302 // since rows of table can not have same jd, this check is probably not needed. 401 303 denom = table->data.F64[hiIdx][0]-table->data.F64[loIdx][0]; 402 304 if(fabs(denom) < FLT_EPSILON) { 403 psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__); 305 psError(PS_ERR_UNKNOWN,true, 306 PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS 307 "Ser7"); 404 308 return 0.0; 405 309 } else { 406 407 310 // Interpolate three constants required to calculate TAI-UTC 408 311 const1 = table->data.F64[loIdx][1]+(table->data.F64[hiIdx][1]-table->data.F64[loIdx][1]) … … 445 348 mjdUtc = psTimeToMJD(time); 446 349 if(mjdUtc < table->data.F64[0][3]) { // MJD time before start of table 447 psError(__func__, " : Line %d - MJD too small. Value: %d", __LINE__, mjdUtc); 350 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 351 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 352 mjdUtc, "Ser7"); 448 353 449 354 } else if(mjdUtc > table->data.F64[numRows-1][3]) { // MJD time after end of table 450 psError(__func__, " : Line %d - MJD too big. Value: %d", __LINE__, mjdUtc); 355 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 356 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 357 mjdUtc, "Ser7"); 451 358 } else { // All other times..interpolate 452 359 while(mjdUtc > table->data.F64[hiIdx][3]) { 453 360 hiIdx++; 454 361 if(hiIdx >= numRows) { 455 psError(__func__, " : Line %d - High index too big. Value: %d", __LINE__, hiIdx); 362 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 363 PS_ERRORTEXT_psTime_TIME_POSTDATES_TABLE, 364 mjdUtc, "Ser7"); 456 365 return 0.0; 457 366 } … … 460 369 loIdx = hiIdx--; 461 370 if(loIdx < 0) { 462 psError(__func__, " : Line %d - Low index too small. Value: %d", __LINE__, loIdx); 371 psError(PS_ERR_BAD_PARAMETER_VALUE,true, 372 PS_ERRORTEXT_psTime_TIME_PREDATES_TABLE, 373 mjdUtc, "Ser7"); 463 374 } 464 375 465 376 denom = table->data.F64[hiIdx][3] - table->data.F64[loIdx][3]; 466 377 if(fabs(denom) < FLT_EPSILON) { 467 psError(__func__, " : Line %d - Divide by zero error during interpolation", __LINE__); 378 psError(PS_ERR_UNKNOWN,true, 379 PS_ERRORTEXT_psTime_TABLE_DUPLICATE_ROWS, 380 "Ser7"); 468 381 } else { 469 382 out = table->data.F64[loIdx][col]+(table->data.F64[hiIdx][col]-table->data.F64[loIdx][col]) … … 525 438 // Error checks 526 439 if(type!=PS_TIME_TAI && type!=PS_TIME_UTC) { 527 psError(__func__, " : Line %d - Incorrect type. Type: %d", __LINE__, type); 440 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 441 PS_ERRORTEXT_psTime_TYPE_UNKNOWN, 442 type); 528 443 return NULL; 529 444 } 530 445 531 446 outTime = (psTime*)psAlloc(sizeof(psTime)); 532 if(outTime == NULL) {533 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);534 }535 447 536 448 outTime->sec = 0; … … 551 463 552 464 if (gettimeofday(&now, (struct timezone *)0) == -1) { 553 psError(__func__, " : Line %d - Failed to get time", __LINE__); 465 psError(PS_ERR_OS_CALL_FAILED, true, 466 PS_ERRORTEXT_psTime_GET_TOD_FAILED); 554 467 return NULL; 555 468 } … … 573 486 574 487 // Error checks 575 if(time == NULL) { 576 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 577 return NULL; 578 } else if(time->usec >= 1e6) { 579 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 580 return NULL; 581 } else if(time->type == type) { 582 psError(__func__, " : Line %d - Time already in correct psTime type. Time type: %d", __LINE__, type); 583 return NULL; 488 PS_PTR_CHECK_NULL(time,NULL); 489 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 490 491 if (time->type == type) { // time already right type. That was easy! 492 return time; 584 493 } 585 494 586 495 delta = psTimeGetTAIDelta(time); 587 496 588 if (type == PS_TIME_UTC) {497 if (type == PS_TIME_UTC) { 589 498 time->sec = time->sec - delta; // User wants UTC time. Subtract leapseconds. 590 499 } else if(type == PS_TIME_TAI) { 591 500 time->sec = time->sec + delta; // User wants TAI time. Add leapseconds. 592 501 } else { 593 psError(__func__, " : Line %d - Invalid psTimeType: %d", __LINE__, type); 502 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 503 PS_ERRORTEXT_psTime_TYPE_UNKNOWN, 504 type); 594 505 } 595 506 … … 623 534 624 535 // Error checks 625 if(time == NULL) { 626 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 627 return 0; 628 } else if(time->usec >= 1e6) { 629 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 630 return 0; 631 } 536 PS_PTR_CHECK_NULL(time,NAN); 537 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 632 538 633 539 // Calculate TAI or UTC time based on type of time user passes … … 698 604 699 605 // Error checks 700 if(time == NULL) { 701 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 702 return 0.0; 703 } else if(time->usec >= 1e6) { 704 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 705 return 0.0; 706 } 606 PS_PTR_CHECK_NULL(time,NAN); 607 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 707 608 708 609 return lookupSer7Table(time, 6); … … 717 618 718 619 // Error checks 719 if(time == NULL) 720 { 721 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 722 return NULL; 723 } else if(time->usec >= 1e6) 724 { 725 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 726 return NULL; 727 } 620 PS_PTR_CHECK_NULL(time,NULL); 621 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 728 622 729 623 x = lookupSer7Table((psTime*)time, 4); … … 741 635 742 636 // Error checks 743 if(time == NULL) { 744 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 745 return 0.0; 746 } else if(time->usec >= 1e6) { 747 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 748 return 0.0; 749 } 637 PS_PTR_CHECK_NULL(time,NAN); 638 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 750 639 751 640 return lookupTaiUtcTable(time); … … 758 647 759 648 // Error checks 760 if(time1 == NULL) { 761 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 762 return 0; 763 } else if(time1->usec >= 1e6) { 764 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time1->usec); 765 return 0; 766 } else if(time2 == NULL) { 767 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 768 return 0; 769 } else if(time2->usec >= 1e6) { 770 psError(__func__, " : Line %d - First input time microseconds too big. Value %u", __LINE__, time2->usec); 771 return 0; 772 } 649 PS_PTR_CHECK_NULL(time1,0); 650 PS_PTR_CHECK_NULL(time2,0); 651 PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0); 652 PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0); 773 653 774 654 diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2)); … … 781 661 double jd = 0.0; 782 662 783 784 // Error checks 785 if(time == NULL) { 786 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 787 return 0.0; 788 } else if(time->usec >= 1e6) { 789 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 790 return 0.0; 791 } 663 // Error checks 664 PS_PTR_CHECK_NULL(time,NAN); 665 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 792 666 793 667 // Julian date conversion … … 807 681 808 682 // Error checks 809 if(time == NULL) { 810 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 811 return 0.0; 812 } else if(time->usec >= 1e6) { 813 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 814 return 0.0; 815 } 683 PS_PTR_CHECK_NULL(time,NAN); 684 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NAN); 816 685 817 686 // Modified Julian date conversion … … 835 704 836 705 // Error checks 837 if(time == NULL) { 838 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 839 return NULL; 840 } else if(time->usec >= 1e6) { 841 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 842 return NULL; 843 } 706 PS_PTR_CHECK_NULL(time,NULL); 707 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 844 708 845 709 tempString = psAlloc(MAX_TIME_STRING_LENGTH); … … 854 718 // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form 855 719 if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) { 856 psError(__func__, " : Line %d - Failed strftime conversion", __LINE__); 720 psError(PS_ERR_OS_CALL_FAILED, true, 721 PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED); 857 722 } 858 723 859 724 if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3dZ", tempString, ms) < 0) { 860 psError(__func__, " : Line %d - Failed snprintf conversion", __LINE__); 725 psError(PS_ERR_OS_CALL_FAILED, true, 726 PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED); 861 727 } 862 728 psFree(tempString); … … 869 735 struct timeval timevalTime; 870 736 871 872 // Error checks 873 if(time == NULL) 874 { 875 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 876 return timevalTime; 877 } else if(time->usec >= 1e6) 878 { 879 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 880 return timevalTime; 881 } 737 timevalTime.tv_sec = 0; 738 timevalTime.tv_usec = 0; 739 740 // Error checks 741 PS_PTR_CHECK_NULL(time,timevalTime); 742 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,timevalTime); 882 743 883 744 timevalTime.tv_sec = time->sec; … … 901 762 902 763 // Error checks 903 if(time == NULL) 904 { 905 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 906 return NULL; 907 } else if(time->usec >= 1e6) 908 { 909 psError(__func__, " : Line %d - Input time microseconds too big. Value %u", __LINE__, time->usec); 910 return NULL; 911 } 764 PS_PTR_CHECK_NULL(time,NULL); 765 PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL); 912 766 913 767 seconds = time->sec%60; … … 945 799 // Allocate output 946 800 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 947 if (tmTime == NULL)948 {949 psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);950 }951 801 952 802 tmTime->tm_year = year - 1900; … … 982 832 983 833 // Error check 984 if(outTime->usec >= 1e6) { 985 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 986 } 834 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 987 835 988 836 return outTime; … … 1010 858 1011 859 // Error check 1012 if(outTime->usec >= 1e6) { 1013 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1014 } 860 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1015 861 1016 862 return outTime; … … 1020 866 { 1021 867 char tempString[MAX_TIME_STRING_LENGTH]; 1022 psS32 month;1023 psS32 day;1024 psS32 year;1025 psS32 hour;1026 psS32 minute;1027 psS32 second;1028 868 psS32 millisecond; 1029 869 struct tm tmTime; 1030 870 psTime *outTime = NULL; 1031 871 1032 1033 // Preserve input string by creating duplicate1034 strncpy(tempString, time, MAX_TIME_STRING_LENGTH);1035 1036 872 // Convert YYYY-MM-DDThh:mm:ss.sss in string form to tm time 1037 year = atoi(strtok(tempString, "-")); 1038 if (year < 0) { 1039 psError(__func__, "Years less than 0 not allowed. Value: %d", year); 1040 return outTime; 1041 } 1042 1043 month = atoi(strtok(NULL, "-")); 1044 if (month < 1 || month > 12) { 1045 psError(__func__, "Month must have a value from 1 to 12. Value: %d", month); 1046 return outTime; 1047 } 1048 1049 day = atoi(strtok(NULL, "T")); 1050 if (day < 1 || day > 31) { 1051 psError(__func__, "Day must have a value from 1 to 31. Value: %d", day); 1052 return outTime; 1053 } 1054 1055 hour = atoi(strtok(NULL, ":")); 1056 if (hour < 0 || hour > 23) { 1057 psError(__func__, "Hour must have a value from 0 to 23. Value: %d", hour); 1058 return outTime; 1059 } 1060 1061 minute = atoi(strtok(NULL, ":")); 1062 if (minute < 0 || minute > 59) { 1063 psError(__func__, "Minute must have a value from 0 to 59. Value: %d", minute); 1064 return outTime; 1065 } 1066 1067 second = atoi(strtok(NULL, ".")); 1068 if (second < 0 || second > 59) { 1069 psError(__func__, "Second must have a value from 0 to 59. Value: %d", second); 1070 return outTime; 1071 } 1072 1073 millisecond = atoi(strtok(NULL, "Z")); 1074 if (millisecond < 0 || millisecond > 1000) { 1075 psError(__func__, "Millisecond must have a value from 0 to 999. Value: %d", millisecond); 1076 return outTime; 1077 } 1078 1079 tmTime.tm_year = year - 1900; 1080 tmTime.tm_mon = month - 1; 1081 tmTime.tm_mday = day; 1082 tmTime.tm_hour = hour; 1083 tmTime.tm_min = minute; 1084 tmTime.tm_sec = second; 873 if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d", 874 &tmTime.tm_year,&tmTime.tm_mon,&tmTime.tm_mday, 875 &tmTime.tm_hour,&tmTime.tm_min,&tmTime.tm_sec,&millisecond) < 7) { 876 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 877 PS_ERRORTEXT_psTime_ISOTIME_MALFORMED, 878 time); 879 return NULL; 880 } 881 882 PS_INT_CHECK_NON_NEGATIVE(tmTime.tm_year, outTime); 883 PS_INT_CHECK_RANGE(tmTime.tm_mon,1,12,outTime); 884 PS_INT_CHECK_RANGE(tmTime.tm_mday,1,31,outTime); 885 PS_INT_CHECK_RANGE(tmTime.tm_hour,0,23,outTime); 886 PS_INT_CHECK_RANGE(tmTime.tm_min,0,59,outTime); 887 PS_INT_CHECK_RANGE(tmTime.tm_sec,0,59,outTime); 888 PS_INT_CHECK_RANGE(millisecond,0,999,outTime); 889 890 tmTime.tm_year -= 1900; 891 tmTime.tm_mon--; 1085 892 tmTime.tm_isdst = -1; 1086 893 … … 1089 896 outTime->usec = millisecond * 1000; 1090 897 898 return outTime; 899 } 900 901 psTime* psTimeFromTimeval(const struct timeval *time) 902 { 903 psTime *outTime = NULL; 904 905 1091 906 // Error check 1092 if(outTime->usec >= 1e6) { 1093 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1094 } 1095 1096 return outTime; 1097 } 1098 1099 psTime* psTimeFromTimeval(const struct timeval *time) 1100 { 1101 psTime *outTime = NULL; 1102 1103 1104 // Error check 1105 if(time == NULL) 1106 { 1107 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1108 return NULL; 1109 } 907 PS_PTR_CHECK_NULL(time,NULL); 1110 908 1111 909 // Allocate psTime struct … … 1117 915 1118 916 // Error check 1119 if(outTime->usec >= 1e6) 1120 { 1121 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1122 } 917 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1123 918 1124 919 return outTime; … … 1138 933 1139 934 // Error check 1140 if(time == NULL) 1141 { 1142 psError(__func__, " : Line %d - NULL value not allowed", __LINE__); 1143 return NULL; 1144 } 935 PS_PTR_CHECK_NULL(time,NULL); 1145 936 1146 937 // Allocate psTime struct … … 1183 974 1184 975 // Error check 1185 if(outTime->usec >= 1e6) 1186 { 1187 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1188 } 976 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1189 977 1190 978 return outTime; … … 1199 987 1200 988 // Error checks 989 PS_PTR_CHECK_NULL(tai1,NULL); 990 PS_PTR_CHECK_NULL(tai2,NULL); 991 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 992 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 993 1201 994 if(tai1->type != tai2->type) { 1202 psError(__func__, " : Line %d - Argument types inconsistent for time addition", __LINE__); 1203 return NULL; 1204 } else if(tai1 == NULL) { 1205 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1206 return NULL; 1207 } else if(tai1->usec >= 1e6) { 1208 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1209 return NULL; 1210 } else if(tai2 == NULL) { 1211 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1212 return NULL; 1213 } else if(tai2->usec >= 1e6) { 1214 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 995 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 996 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1215 997 return NULL; 1216 998 } … … 1233 1015 1234 1016 // Error check 1235 if(outTime->usec >= 1e6) { 1236 psError(__func__, " : Line %d - Output time microseconds too big. Value %u", __LINE__, outTime->usec); 1237 } 1017 PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime); 1238 1018 1239 1019 return outTime; … … 1248 1028 1249 1029 // Error checks 1030 PS_PTR_CHECK_NULL(tai1,NULL); 1031 PS_PTR_CHECK_NULL(tai2,NULL); 1032 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 1033 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 1250 1034 if(tai1->type != tai2->type) { 1251 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1252 return NULL; 1253 } else if(tai1 == NULL) { 1254 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1255 return NULL; 1256 } else if(tai1->usec >= 1e6) { 1257 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1258 return NULL; 1259 } else if(tai2 == NULL) { 1260 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1261 return NULL; 1262 } else if(tai2->usec >= 1e6) { 1263 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 1035 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1036 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1264 1037 return NULL; 1265 1038 } … … 1294 1067 1295 1068 // Error checks 1069 // Error checks 1070 PS_PTR_CHECK_NULL(tai1,NULL); 1071 PS_PTR_CHECK_NULL(tai2,NULL); 1072 PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL); 1073 PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL); 1296 1074 if(tai1->type != tai2->type) { 1297 psError(__func__, " : Line %d - Argument types inconsistent for time subtraction", __LINE__); 1298 return NULL; 1299 } else if(tai1 == NULL) { 1300 psError(__func__, " : Line %d - NULL value not allowed for first input", __LINE__); 1301 return NULL; 1302 } else if(tai1->usec >= 1e6) { 1303 psError(__func__, " : Line %d - Argument 1 microseconds too big. Value %u", __LINE__, tai1->usec); 1304 return NULL; 1305 } else if(tai2 == NULL) { 1306 psError(__func__, " : Line %d - NULL value not allowed for second input", __LINE__); 1307 return NULL; 1308 } else if(tai2->usec >= 1e6) { 1309 psError(__func__, " : Line %d - Argument 2 microseconds too big. Value %u", __LINE__, tai2->usec); 1075 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 1076 PS_ERRORTEXT_psTime_TYPE_MISMATCH); 1310 1077 return NULL; 1311 1078 }
Note:
See TracChangeset
for help on using the changeset viewer.
