IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 3, 2004, 3:05:00 PM (22 years ago)
Author:
desonia
Message:

changed the psError signature to match SDRS. Also made misc. cleanups as
I was combing the files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psTime.c

    r2204 r2273  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-27 00:57:30 $
     13 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-11-04 01:04:57 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3131#include "psMetadata.h"
    3232#include "psMetadataIO.h"
    33 
     33#include "psConstants.h"
    3434#include "psAstronomyErrors.h"
    3535
     
    151151    char line[LINESIZE];
    152152    psS32 j = 0;
    153     psS32 maxLines = 100;
     153    psS32 maxLines = 1000;
    154154    psF64 *ptr = NULL;
    155155    psImage *table = NULL;
     
    159159    fd=fopen(fileName, "r");
    160160    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");
    162164        return NULL;
    163165    }
     
    168170    while(fgets(line, LINESIZE, fd) != NULL) {
    169171        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);
    171175            return NULL;
    172176            psFree(table);
     
    201205    fd=fopen(fileName, "r");
    202206    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");
    204210        return NULL ;
    205211    }
     
    218224
    219225            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);
    221229                return NULL;
    222230                psFree(table);
     
    240248}
    241249
    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 entry
    311         if(*(line+7) == ' ') {                   // MJD
    312             *ptr = 0.0;
    313         } else {
    314             *ptr = atof(line+7);
    315         }
    316  
    317         if(*(line+18) == ' ') {                  // Polar motion X
    318             *(ptr+1) = 0.0;
    319         } else {
    320             *(ptr+1) = atof(line+18);
    321         }
    322  
    323         if(*(line+27) == ' ') {                  // Polar motion X error
    324             *(ptr+2) = 0.0;
    325         } else {
    326             *(ptr+2) = atof(line+27);
    327         }
    328  
    329         if(*(line+37) == ' ') {                  // Polar motion Y
    330             *(ptr+3) = 0.0;
    331         } else {
    332             *(ptr+3) = atof(line+37);
    333         }
    334  
    335         if(*(line+46) == ' ') {                  // Polar motion Y error
    336             *(ptr+4) = 0.0;
    337         } else {
    338             *(ptr+4) = atof(line+46);
    339         }
    340  
    341         if(*(line+58) == ' ') {                  // UT1-UTC
    342             *(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 */
    353250
    354251static double lookupTaiUtcTable(const psTime *time)
     
    389286            hiIdx++;
    390287            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");
    392291                return 0.0;
    393292            }
     
    395294        loIdx = hiIdx--;
    396295        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");
    398299            return 0.0;
    399300        }
    400301
     302        // since rows of table can not have same jd, this check is probably not needed.
    401303        denom = table->data.F64[hiIdx][0]-table->data.F64[loIdx][0];
    402304        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");
    404308            return 0.0;
    405309        } else {
    406 
    407310            // Interpolate three constants required to calculate TAI-UTC
    408311            const1 = table->data.F64[loIdx][1]+(table->data.F64[hiIdx][1]-table->data.F64[loIdx][1])
     
    445348    mjdUtc = psTimeToMJD(time);
    446349    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");
    448353
    449354    } 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");
    451358    } else {                                                                // All other times..interpolate
    452359        while(mjdUtc > table->data.F64[hiIdx][3]) {
    453360            hiIdx++;
    454361            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");
    456365                return 0.0;
    457366            }
     
    460369        loIdx = hiIdx--;
    461370        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");
    463374        }
    464375
    465376        denom = table->data.F64[hiIdx][3] - table->data.F64[loIdx][3];
    466377        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");
    468381        } else {
    469382            out = table->data.F64[loIdx][col]+(table->data.F64[hiIdx][col]-table->data.F64[loIdx][col])
     
    525438    // Error checks
    526439    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);
    528443        return NULL;
    529444    }
    530445
    531446    outTime = (psTime*)psAlloc(sizeof(psTime));
    532     if(outTime == NULL) {
    533         psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
    534     }
    535447
    536448    outTime->sec = 0;
     
    551463
    552464    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);
    554467        return NULL;
    555468    }
     
    573486
    574487    // 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;
    584493    }
    585494
    586495    delta = psTimeGetTAIDelta(time);
    587496
    588     if(type == PS_TIME_UTC) {
     497    if (type == PS_TIME_UTC) {
    589498        time->sec = time->sec - delta;    // User wants UTC time. Subtract leapseconds.
    590499    } else if(type == PS_TIME_TAI) {
    591500        time->sec = time->sec + delta;    // User wants TAI time. Add leapseconds.
    592501    } 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);
    594505    }
    595506
     
    623534
    624535    // 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);
    632538
    633539    // Calculate TAI or UTC time based on type of time user passes
     
    698604
    699605    // 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);
    707608
    708609    return lookupSer7Table(time, 6);
     
    717618
    718619    // 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);
    728622
    729623    x = lookupSer7Table((psTime*)time, 4);
     
    741635
    742636    // 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);
    750639
    751640    return lookupTaiUtcTable(time);
     
    758647
    759648    // 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);
    773653
    774654    diff = abs(psTimeGetTAIDelta((psTime*)time1)-psTimeGetTAIDelta((psTime*)time2));
     
    781661    double jd = 0.0;
    782662
    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);
    792666
    793667    // Julian date conversion
     
    807681
    808682    // 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);
    816685
    817686    // Modified Julian date conversion
     
    835704
    836705    // 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);
    844708
    845709    tempString = psAlloc(MAX_TIME_STRING_LENGTH);
     
    854718    // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form
    855719    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);
    857722    }
    858723
    859724    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);
    861727    }
    862728    psFree(tempString);
     
    869735    struct timeval timevalTime;
    870736
    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);
    882743
    883744    timevalTime.tv_sec = time->sec;
     
    901762
    902763    // 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);
    912766
    913767    seconds = time->sec%60;
     
    945799    // Allocate output
    946800    tmTime = (struct tm*)psAlloc(sizeof(struct tm));
    947     if (tmTime == NULL)
    948     {
    949         psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
    950     }
    951801
    952802    tmTime->tm_year = year - 1900;
     
    982832
    983833    // 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);
    987835
    988836    return outTime;
     
    1010858
    1011859    // 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);
    1015861
    1016862    return outTime;
     
    1020866{
    1021867    char tempString[MAX_TIME_STRING_LENGTH];
    1022     psS32 month;
    1023     psS32 day;
    1024     psS32 year;
    1025     psS32 hour;
    1026     psS32 minute;
    1027     psS32 second;
    1028868    psS32 millisecond;
    1029869    struct tm tmTime;
    1030870    psTime *outTime = NULL;
    1031871
    1032 
    1033     // Preserve input string by creating duplicate
    1034     strncpy(tempString, time, MAX_TIME_STRING_LENGTH);
    1035 
    1036872    // 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--;
    1085892    tmTime.tm_isdst = -1;
    1086893
     
    1089896    outTime->usec = millisecond * 1000;
    1090897
     898    return outTime;
     899}
     900
     901psTime* psTimeFromTimeval(const struct timeval *time)
     902{
     903    psTime *outTime = NULL;
     904
     905
    1091906    // 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);
    1110908
    1111909    // Allocate psTime struct
     
    1117915
    1118916    // 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);
    1123918
    1124919    return outTime;
     
    1138933
    1139934    // 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);
    1145936
    1146937    // Allocate psTime struct
     
    1183974
    1184975    // 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);
    1189977
    1190978    return outTime;
     
    1199987
    1200988    // 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
    1201994    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);
    1215997        return NULL;
    1216998    }
     
    12331015
    12341016    // 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);
    12381018
    12391019    return outTime;
     
    12481028
    12491029    // 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);
    12501034    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);
    12641037        return NULL;
    12651038    }
     
    12941067
    12951068    // 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);
    12961074    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);
    13101077        return NULL;
    13111078    }
Note: See TracChangeset for help on using the changeset viewer.