IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3712


Ignore:
Timestamp:
Apr 18, 2005, 4:13:53 PM (21 years ago)
Author:
evanalst
Message:

Modify the psTime data structure. (SDR-13)

Location:
trunk/psLib
Files:
8 edited

Legend:

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

    r3708 r3712  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-04-19 00:17:05 $
     12 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-04-19 02:13:53 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6464
    6565                /** Microseconds per day */
    66                 #define USEC_PER_DAY 86400000000.0
     66                #define NSEC_PER_DAY 86400000000000.0
    6767
    6868                /** Time metadata read from config file */
     
    363363
    364364    outTime->sec = 0;
    365     outTime->usec = 0;
     365    outTime->nsec = 0;
    366366    outTime->type = type;
     367    outTime->leapsecond = false;
    367368
    368369    return outTime;
     
    386387    // Convert timeval time to psTime
    387388    time->sec = now.tv_sec;
    388     time->usec = now.tv_usec;
     389    time->nsec = now.tv_usec*1000;
    389390
    390391    // Add most leapseconds to UTC time to get TAI time if necessary
     
    403404    // Error checks
    404405    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);
    406407
    407408    if (time->type == type) { // time already right type.  That was easy!
     
    448449    // Error checks
    449450    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);
    451452
    452453    // Calculate TAI or UTC time based on type of time user passes
     
    455456        utcTime = psTimeAlloc(PS_TIME_UTC);
    456457        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
    457         utcTime->usec = taiTime->usec;
     458        utcTime->nsec = taiTime->nsec;
    458459    } else if(time->type == PS_TIME_UTC) {
    459460        utcTime = psMemIncrRefCounter(time);
    460461        taiTime = psTimeAlloc(PS_TIME_TAI);
    461462        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
    462         taiTime->usec = utcTime->usec;
     463        taiTime->nsec = utcTime->nsec;
    463464    }
    464465
     
    519520    // Error checks
    520521    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);
    522523
    523524    if(time->type != PS_TIME_TAI) {
     
    592593    // Error checks
    593594    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);
    595596
    596597    if(time->type != PS_TIME_TAI)
     
    715716    // Error checks
    716717    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);
    718719
    719720    // Check time metadata
     
    768769    PS_PTR_CHECK_NULL(time1,0);
    769770    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);
    772773    diff = abs((psS64)psTimeGetTAIDelta((psTime*)time1)-(psS64)psTimeGetTAIDelta((psTime*)time2));
    773774
     
    781782    // Error checks
    782783    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);
    784785
    785786    // Julian date conversion
    786787    if(time->sec < 0) {
    787         jd = time->sec / SEC_PER_DAY - time->usec / USEC_PER_DAY + 2440587.5; // psTime earlier than epoch
     788        jd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 2440587.5; // psTime earlier than epoch
    788789    } else {
    789         jd = time->sec / SEC_PER_DAY + time->usec / USEC_PER_DAY + 2440587.5; // psTime greater than epoch
     790        jd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 2440587.5; // psTime greater than epoch
    790791    }
    791792
     
    800801    // Error checks
    801802    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);
    803804
    804805    // Modified Julian date conversion
    805806    if(time->sec < 0) {
    806         mjd = time->sec / SEC_PER_DAY - time->usec / USEC_PER_DAY + 40587.0; // psTime earlier than epoch
     807        mjd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 40587.0; // psTime earlier than epoch
    807808    } else {
    808         mjd = time->sec / SEC_PER_DAY + time->usec / USEC_PER_DAY + 40587.0; // psTime greater than epoch
     809        mjd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 40587.0; // psTime greater than epoch
    809810    }
    810811
     
    823824    // Error checks
    824825    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);
    826827
    827828    tempString = psAlloc(MAX_TIME_STRING_LENGTH);
    828829    timeString = psAlloc(MAX_TIME_STRING_LENGTH);
    829830
    830     ms = time->usec / 1000;
     831    ms = time->nsec / 1000000;
    831832    sec = time->sec;
    832833
     
    856857    // Error checks
    857858    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);
    859860
    860861    timevalTime.tv_sec = time->sec;
    861     timevalTime.tv_usec = time->usec;
     862    timevalTime.tv_usec = time->nsec / 1000;
    862863
    863864    return timevalTime;
     
    879880    // Error checks
    880881    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);
    882883
    883884    seconds = time->sec%60;
     
    941942    seconds = days * SEC_PER_DAY;
    942943    if(seconds < 0.0) {
    943         outTime->usec = (seconds - (psS64)seconds) * -1000000.0;  // psTime earlier than epoch
     944        outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
    944945    } else {
    945         outTime->usec = (seconds - (psS64)seconds) * 1000000.0;   // psTime greater than epoch
     946        outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0;   // psTime greater than epoch
    946947    }
    947948    outTime->sec = seconds;
    948949
    949950    // Error check
    950     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     951    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    951952
    952953    return outTime;
     
    967968    seconds = days * SEC_PER_DAY;
    968969    if(seconds < 0.0) {
    969         outTime->usec = (seconds - (psS64)seconds) * -1000000.0;  // psTime earlier than epoch
     970        outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
    970971    } else {
    971         outTime->usec = (seconds - (psS64)seconds) * 1000000.0;   // psTime greater than epoch
     972        outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0;   // psTime greater than epoch
    972973    }
    973974    outTime->sec = seconds;
    974975
    975976    // Error check
    976     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     977    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    977978
    978979    return outTime;
     
    10061007    // Convert tm time to psTime
    10071008    outTime = psTimeFromTM(&tmTime);
    1008     outTime->usec = millisecond * 1000;
     1009    outTime->nsec = millisecond * 1000000;
    10091010
    10101011    return outTime;
     
    10241025    // Convert to psTime
    10251026    outTime->sec = time->tv_sec;
    1026     outTime->usec = time->tv_usec;
     1027    outTime->nsec = time->tv_usec * 1000;
    10271028
    10281029    // Error check
    1029     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1030    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    10301031
    10311032    return outTime;
     
    10831084
    10841085    // C's TM does not define a microsecond field. Microseconds must be manipulated by calling function.
    1085     outTime->usec = 0;
     1086    outTime->nsec = 0;
    10861087
    10871088    // Error check
    1088     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1089    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    10891090
    10901091    return outTime;
     
    11001101    // Error checks
    11011102    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);
    11031104
    11041105    // Convert time to TAI if necessary, but without changing input arguments
     
    11061107        tempTime = psTimeAlloc(PS_TIME_UTC);
    11071108        tempTime->sec = time->sec;
    1108         tempTime->usec = time->usec;
     1109        tempTime->nsec = time->nsec;
    11091110        tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
    11101111    } else {
     
    11141115    // Create output time
    11151116    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;
    11171118    outTime->sec = sec;
    1118     outTime->usec = (sec - outTime->sec)*1e6;
     1119    outTime->nsec = (sec - outTime->sec)*1e9;
    11191120
    11201121    // Error check
    1121     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1122    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    11221123
    11231124    // Convert result to same time type as input
     
    11421143    // Error checks
    11431144    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);
    11451146    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);
    11471148
    11481149    // Convert time to TAI if necessary, but without changing input arguments
     
    11501151        tempTime1 = psTimeAlloc(PS_TIME_UTC);
    11511152        tempTime1->sec = time1->sec;
    1152         tempTime1->usec = time1->usec;
     1153        tempTime1->nsec = time1->nsec;
    11531154        tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
    11541155    } else {
     
    11581159        tempTime2 = psTimeAlloc(PS_TIME_UTC);
    11591160        tempTime2->sec = time2->sec;
    1160         tempTime2->usec = time2->usec;
     1161        tempTime2->nsec = time2->nsec;
    11611162        tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
    11621163    } else {
     
    11651166
    11661167    uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0;
    1167     uSec1 = uSec1*tempTime1->usec/1e6;
     1168    uSec1 = uSec1*tempTime1->nsec/1e9;
    11681169    uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0;
    1169     uSec2 = uSec2*tempTime2->usec/1e6;
     1170    uSec2 = uSec2*tempTime2->nsec/1e9;
    11701171    out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2);
    11711172
  • trunk/psLib/src/astro/psTime.h

    r3708 r3712  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-04-19 00:17:05 $
     12 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-04-19 02:13:53 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4040    PS_TIME_TAI,        ///< Temps Atomique International (TAI) time (time with leapseconds).
    4141    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
    4244} psTimeType;
    4345
     
    5254{
    5355    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
    5558    psTimeType type;    ///< Type of time.
    5659}
  • trunk/psLib/src/astronomy/psTime.c

    r3708 r3712  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-04-19 00:17:05 $
     12 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-04-19 02:13:53 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6464
    6565                /** Microseconds per day */
    66                 #define USEC_PER_DAY 86400000000.0
     66                #define NSEC_PER_DAY 86400000000000.0
    6767
    6868                /** Time metadata read from config file */
     
    363363
    364364    outTime->sec = 0;
    365     outTime->usec = 0;
     365    outTime->nsec = 0;
    366366    outTime->type = type;
     367    outTime->leapsecond = false;
    367368
    368369    return outTime;
     
    386387    // Convert timeval time to psTime
    387388    time->sec = now.tv_sec;
    388     time->usec = now.tv_usec;
     389    time->nsec = now.tv_usec*1000;
    389390
    390391    // Add most leapseconds to UTC time to get TAI time if necessary
     
    403404    // Error checks
    404405    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);
    406407
    407408    if (time->type == type) { // time already right type.  That was easy!
     
    448449    // Error checks
    449450    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);
    451452
    452453    // Calculate TAI or UTC time based on type of time user passes
     
    455456        utcTime = psTimeAlloc(PS_TIME_UTC);
    456457        utcTime->sec = taiTime->sec - psTimeGetTAIDelta(time);
    457         utcTime->usec = taiTime->usec;
     458        utcTime->nsec = taiTime->nsec;
    458459    } else if(time->type == PS_TIME_UTC) {
    459460        utcTime = psMemIncrRefCounter(time);
    460461        taiTime = psTimeAlloc(PS_TIME_TAI);
    461462        taiTime->sec = utcTime->sec + psTimeGetTAIDelta(time);
    462         taiTime->usec = utcTime->usec;
     463        taiTime->nsec = utcTime->nsec;
    463464    }
    464465
     
    519520    // Error checks
    520521    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);
    522523
    523524    if(time->type != PS_TIME_TAI) {
     
    592593    // Error checks
    593594    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);
    595596
    596597    if(time->type != PS_TIME_TAI)
     
    715716    // Error checks
    716717    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);
    718719
    719720    // Check time metadata
     
    768769    PS_PTR_CHECK_NULL(time1,0);
    769770    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);
    772773    diff = abs((psS64)psTimeGetTAIDelta((psTime*)time1)-(psS64)psTimeGetTAIDelta((psTime*)time2));
    773774
     
    781782    // Error checks
    782783    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);
    784785
    785786    // Julian date conversion
    786787    if(time->sec < 0) {
    787         jd = time->sec / SEC_PER_DAY - time->usec / USEC_PER_DAY + 2440587.5; // psTime earlier than epoch
     788        jd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 2440587.5; // psTime earlier than epoch
    788789    } else {
    789         jd = time->sec / SEC_PER_DAY + time->usec / USEC_PER_DAY + 2440587.5; // psTime greater than epoch
     790        jd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 2440587.5; // psTime greater than epoch
    790791    }
    791792
     
    800801    // Error checks
    801802    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);
    803804
    804805    // Modified Julian date conversion
    805806    if(time->sec < 0) {
    806         mjd = time->sec / SEC_PER_DAY - time->usec / USEC_PER_DAY + 40587.0; // psTime earlier than epoch
     807        mjd = time->sec / SEC_PER_DAY - time->nsec / NSEC_PER_DAY + 40587.0; // psTime earlier than epoch
    807808    } else {
    808         mjd = time->sec / SEC_PER_DAY + time->usec / USEC_PER_DAY + 40587.0; // psTime greater than epoch
     809        mjd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + 40587.0; // psTime greater than epoch
    809810    }
    810811
     
    823824    // Error checks
    824825    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);
    826827
    827828    tempString = psAlloc(MAX_TIME_STRING_LENGTH);
    828829    timeString = psAlloc(MAX_TIME_STRING_LENGTH);
    829830
    830     ms = time->usec / 1000;
     831    ms = time->nsec / 1000000;
    831832    sec = time->sec;
    832833
     
    856857    // Error checks
    857858    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);
    859860
    860861    timevalTime.tv_sec = time->sec;
    861     timevalTime.tv_usec = time->usec;
     862    timevalTime.tv_usec = time->nsec / 1000;
    862863
    863864    return timevalTime;
     
    879880    // Error checks
    880881    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);
    882883
    883884    seconds = time->sec%60;
     
    941942    seconds = days * SEC_PER_DAY;
    942943    if(seconds < 0.0) {
    943         outTime->usec = (seconds - (psS64)seconds) * -1000000.0;  // psTime earlier than epoch
     944        outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
    944945    } else {
    945         outTime->usec = (seconds - (psS64)seconds) * 1000000.0;   // psTime greater than epoch
     946        outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0;   // psTime greater than epoch
    946947    }
    947948    outTime->sec = seconds;
    948949
    949950    // Error check
    950     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     951    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    951952
    952953    return outTime;
     
    967968    seconds = days * SEC_PER_DAY;
    968969    if(seconds < 0.0) {
    969         outTime->usec = (seconds - (psS64)seconds) * -1000000.0;  // psTime earlier than epoch
     970        outTime->nsec = (seconds - (psS64)seconds) * -1000000000.0;  // psTime earlier than epoch
    970971    } else {
    971         outTime->usec = (seconds - (psS64)seconds) * 1000000.0;   // psTime greater than epoch
     972        outTime->nsec = (seconds - (psS64)seconds) * 1000000000.0;   // psTime greater than epoch
    972973    }
    973974    outTime->sec = seconds;
    974975
    975976    // Error check
    976     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     977    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    977978
    978979    return outTime;
     
    10061007    // Convert tm time to psTime
    10071008    outTime = psTimeFromTM(&tmTime);
    1008     outTime->usec = millisecond * 1000;
     1009    outTime->nsec = millisecond * 1000000;
    10091010
    10101011    return outTime;
     
    10241025    // Convert to psTime
    10251026    outTime->sec = time->tv_sec;
    1026     outTime->usec = time->tv_usec;
     1027    outTime->nsec = time->tv_usec * 1000;
    10271028
    10281029    // Error check
    1029     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1030    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    10301031
    10311032    return outTime;
     
    10831084
    10841085    // C's TM does not define a microsecond field. Microseconds must be manipulated by calling function.
    1085     outTime->usec = 0;
     1086    outTime->nsec = 0;
    10861087
    10871088    // Error check
    1088     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1089    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    10891090
    10901091    return outTime;
     
    11001101    // Error checks
    11011102    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);
    11031104
    11041105    // Convert time to TAI if necessary, but without changing input arguments
     
    11061107        tempTime = psTimeAlloc(PS_TIME_UTC);
    11071108        tempTime->sec = time->sec;
    1108         tempTime->usec = time->usec;
     1109        tempTime->nsec = time->nsec;
    11091110        tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
    11101111    } else {
     
    11141115    // Create output time
    11151116    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;
    11171118    outTime->sec = sec;
    1118     outTime->usec = (sec - outTime->sec)*1e6;
     1119    outTime->nsec = (sec - outTime->sec)*1e9;
    11191120
    11201121    // Error check
    1121     PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
     1122    PS_INT_CHECK_RANGE(outTime->nsec,0,1e9-1,outTime);
    11221123
    11231124    // Convert result to same time type as input
     
    11421143    // Error checks
    11431144    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);
    11451146    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);
    11471148
    11481149    // Convert time to TAI if necessary, but without changing input arguments
     
    11501151        tempTime1 = psTimeAlloc(PS_TIME_UTC);
    11511152        tempTime1->sec = time1->sec;
    1152         tempTime1->usec = time1->usec;
     1153        tempTime1->nsec = time1->nsec;
    11531154        tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
    11541155    } else {
     
    11581159        tempTime2 = psTimeAlloc(PS_TIME_UTC);
    11591160        tempTime2->sec = time2->sec;
    1160         tempTime2->usec = time2->usec;
     1161        tempTime2->nsec = time2->nsec;
    11611162        tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
    11621163    } else {
     
    11651166
    11661167    uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0;
    1167     uSec1 = uSec1*tempTime1->usec/1e6;
     1168    uSec1 = uSec1*tempTime1->nsec/1e9;
    11681169    uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0;
    1169     uSec2 = uSec2*tempTime2->usec/1e6;
     1170    uSec2 = uSec2*tempTime2->nsec/1e9;
    11701171    out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2);
    11711172
  • trunk/psLib/src/astronomy/psTime.h

    r3708 r3712  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-04-19 00:17:05 $
     12 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-04-19 02:13:53 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4040    PS_TIME_TAI,        ///< Temps Atomique International (TAI) time (time with leapseconds).
    4141    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
    4244} psTimeType;
    4345
     
    5254{
    5355    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
    5558    psTimeType type;    ///< Type of time.
    5659}
  • trunk/psLib/test/astronomy/tst_psTime_01.c

    r3708 r3712  
    2323 *  @author  Ross Harman, MHPCC
    2424 *
    25  *  @version $Revision: 1.24 $  $Name: not supported by cvs2svn $
    26  *  @date  $Date: 2005-04-19 00:17:06 $
     25 *  @version $Revision: 1.25 $  $Name: not supported by cvs2svn $
     26 *  @date  $Date: 2005-04-19 02:13:53 $
    2727 *
    2828 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4444    testTime = (psTime*)psAlloc(sizeof(psTime));
    4545    testTime->sec = 1090434144;
    46     testTime->usec = 272044;
     46    testTime->nsec = 272044000;
    4747    testTime->type = PS_TIME_TAI;
    4848
     
    5757    // Test B - Print test time
    5858    printPositiveTestHeader(stdout,"psTime", "Print test time");
    59     printf("Test time: Seconds = %lld Microseconds = %u\n",
     59    printf("Test time: Seconds = %lld Nanoseconds = %u\n",
    6060           (long long int)testTime->sec,
    61            testTime->usec);
     61           testTime->nsec);
    6262    printFooter(stdout, "psTime", "Print test time", true);
    6363
     
    7979    psTime *timeD = NULL;
    8080    timeD = psTimeFromISO(isoString);
    81     printf("psTime: Seconds = %lld Microseconds = %u\n",
     81    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    8282           (long long int)timeD->sec,
    83            timeD->usec);
     83           timeD->nsec);
    8484    psFree(isoString);
    8585    psFree(timeD);
     
    9292    timeE = (psTime*)psAlloc(sizeof(psTime));
    9393    timeE->sec = 1090434144;
    94     timeE->usec = 272044;
     94    timeE->nsec = 272044000;
    9595    timeE->type = PS_TIME_TAI;
    9696    timeE = psTimeConvert(timeE, PS_TIME_UTC);
    9797    psFree(timeE);
    98     printf("psTime: Seconds = %lld Microseconds = %u\n",
     98    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    9999           (long long int)timeE->sec,
    100            timeE->usec);
     100           timeE->nsec);
    101101    printFooter(stdout, "psTime", "Convert psTime time to UTC time", true);
    102102
     
    107107    timeF = (psTime*)psAlloc(sizeof(psTime));
    108108    timeF->sec = 1090434112;
    109     timeF->usec = 272044;
     109    timeF->nsec = 272044000;
    110110    timeF->type = PS_TIME_UTC;
    111111    timeF = psTimeConvert(timeF, PS_TIME_TAI);
    112112    psFree(timeF);
    113     printf("psTime: Seconds = %lld Microseconds = %u\n",
     113    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    114114           (long long int)timeF->sec,
    115            timeF->usec);
     115           timeF->nsec);
    116116    printFooter(stdout, "psTime", "Convert UTC time to psTime", true);
    117117
     
    129129    psTime *timeH = NULL;
    130130    timeH = psTimeFromMJD(mjdTime);
    131     printf("psTime: Seconds = %lld Microseconds = %u\n",
     131    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    132132           (long long int)timeH->sec,
    133            timeH->usec);
     133           timeH->nsec);
    134134    psFree(timeH);
    135135    printFooter(stdout, "psTime", "Convert MJD time to psTime", true);
     
    148148    psTime *timeJ = NULL;
    149149    timeJ = psTimeFromJD(jdTime);
    150     printf("psTime: Seconds = %lld Microseconds = %u\n",
     150    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    151151           (long long int)timeJ->sec,
    152            timeJ->usec);
     152           timeJ->nsec);
    153153    psFree(timeJ);
    154154    printFooter(stdout, "psTime", "Convert JD time to psTime", true);
     
    169169    psTime *timeL = NULL;
    170170    timeL = psTimeFromTimeval(&timevalTime);
    171     printf("psTime: Seconds = %lld Microseconds = %u\n",
     171    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    172172           (long long int)timeL->sec,
    173            timeL->usec);
     173           timeL->nsec);
    174174    psFree(timeL);
    175175    printFooter(stdout, "psTime", "Convert timeval time to psTime", true);
     
    194194    psTime *timeN = NULL;
    195195    timeN = psTimeFromTM(tmTime);
    196     printf("psTime: Seconds = %lld Microseconds = %u\n",
     196    printf("psTime: Seconds = %lld Nanoseconds = %u\n",
    197197           (long long int)timeN->sec,
    198            timeN->usec);
     198           timeN->nsec);
    199199    psFree(timeN);
    200200    psFree(tmTime);
  • trunk/psLib/test/astronomy/tst_psTime_03.c

    r3705 r3712  
    1919 *  @author  Ross Harman, MHPCC
    2020 *
    21  *  @version $Revision: 1.15 $  $Name: not supported by cvs2svn $
    22  *  @date  $Date: 2005-04-18 23:30:54 $
     21 *  @version $Revision: 1.16 $  $Name: not supported by cvs2svn $
     22 *  @date  $Date: 2005-04-19 02:13:53 $
    2323 *
    2424 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3030
    3131#define PRINT_TIME(TEXT,TIME) \
    32 printf("%s Seconds = %lld Microseconds = %u\n", TEXT, (long long int)TIME->sec, TIME->usec);
     32printf("%s Seconds = %lld Nanoseconds = %u\n", TEXT, (long long int)TIME->sec, TIME->nsec);
    3333
    3434psS32 main(psS32 argc, char* argv[])
     
    4444    time1a = psTimeAlloc(PS_TIME_TAI);
    4545    time1a->sec  = 1;
    46     time1a->usec = 111111;
     46    time1a->nsec = 111111000;
    4747    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);
    5050    }
    5151    printFooter(stdout, "psTime", "Test A - Add two times", true);
    5252
    5353
    54     // Test B - Add two times with overflow in microseconds
     54    // Test B - Add two times with overflow in nanoseconds
    5555    printPositiveTestHeader(stdout, "psTime", "Test B - Add two times with overflow in microseconds");
    5656    psTime *time2a = NULL;
     
    5959    time2a = psTimeAlloc(PS_TIME_TAI);
    6060    time2a->sec  = 6;
    61     time2a->usec = 600001;
     61    time2a->nsec = 600001000;
    6262    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);
    6565    }
    6666    printFooter(stdout, "psTime", "Test B - Add two times with overflow in microseconds", true);
     
    7474    time3a = psTimeAlloc(PS_TIME_TAI);
    7575    time3a->sec  = 3;
    76     time3a->usec = 333333;
     76    time3a->nsec = 333333000;
    7777    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);
    8080    }
    8181    printFooter(stdout, "psTime", "Test C - Subtract two times", true);
    8282
    8383
    84     // Test D - Subtact two times with underflow in microseconds
    85     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");
    8686    psTime *time4a = NULL;
    8787    psF64 time4b = -2.000003;
     
    8989    time4a = psTimeAlloc(PS_TIME_TAI);
    9090    time4a->sec  = 5;
    91     time4a->usec = 1;
     91    time4a->nsec = 1000;
    9292    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);
    9797
    9898
     
    105105    time5b = psTimeAlloc(PS_TIME_TAI);
    106106    time5a->sec  = 8;
    107     time5a->usec = 8;
     107    time5a->nsec = 8000;
    108108    time5b->sec  = 7;
    109     time5b->usec = 7;
     109    time5b->nsec = 7000;
    110110    timeOut5 = psTimeDelta(time5a, time5b);
    111111    if(fabs(timeOut5-1.000001) > FLT_EPSILON) {
     
    123123    time6b = psTimeAlloc(PS_TIME_TAI);
    124124    time6a->sec  = 8;
    125     time6a->usec = 1;
     125    time6a->nsec = 1000;
    126126    time6b->sec  = 7;
    127     time6b->usec = 7;
     127    time6b->nsec = 7000;
    128128    timeOut6 = psTimeDelta(time6a, time6b);
    129129    if(fabs(timeOut6-0.999994) > FLT_EPSILON) {
     
    140140    time20b = psTimeAlloc(PS_TIME_UTC);
    141141    time20a->sec = 1090434113;
    142     time20a->usec = 272044;
     142    time20a->nsec = 272044000;
    143143    time20b->sec = 1090434112;
    144     time20b->usec = 272044;
     144    time20b->nsec = 272044000;
    145145    timeOut20 = psTimeDelta(time20a, time20b);
    146146    if(fabs(timeOut20-1.000000000) > FLT_EPSILON) {
  • trunk/psLib/test/astronomy/verified/tst_psTime_01.stdout

    r2746 r3712  
    1414\**********************************************************************************/
    1515
    16 Test time: Seconds = 1090434144 Microseconds = 272044
     16Test time: Seconds = 1090434144 Nanoseconds = 272044000
    1717
    1818---> TESTPOINT PASSED (psTime{Print test time} | tst_psTime_01.c)
     
    3434\**********************************************************************************/
    3535
    36 psTime: Seconds = 1090434144 Microseconds = 272000
     36psTime: Seconds = 1090434144 Nanoseconds = 272000000
    3737
    3838---> TESTPOINT PASSED (psTime{Convert ISO time to psTime} | tst_psTime_01.c)
     
    4444\**********************************************************************************/
    4545
    46 psTime: Seconds = 1090434112 Microseconds = 272044
     46psTime: Seconds = 1090434112 Nanoseconds = 272044000
    4747
    4848---> TESTPOINT PASSED (psTime{Convert psTime time to UTC time} | tst_psTime_01.c)
     
    5454\**********************************************************************************/
    5555
    56 psTime: Seconds = 1090434144 Microseconds = 272044
     56psTime: Seconds = 1090434144 Nanoseconds = 272044000
    5757
    5858---> TESTPOINT PASSED (psTime{Convert UTC time to psTime} | tst_psTime_01.c)
     
    7474\**********************************************************************************/
    7575
    76 psTime: Seconds = 1090434144 Microseconds = 272043
     76psTime: Seconds = 1090434144 Nanoseconds = 272043704
    7777
    7878---> TESTPOINT PASSED (psTime{Convert MJD time to psTime} | tst_psTime_01.c)
     
    9494\**********************************************************************************/
    9595
    96 psTime: Seconds = 1090434144 Microseconds = 272048
     96psTime: Seconds = 1090434144 Nanoseconds = 272048711
    9797
    9898---> TESTPOINT PASSED (psTime{Convert JD time to psTime} | tst_psTime_01.c)
     
    114114\**********************************************************************************/
    115115
    116 psTime: Seconds = 1090434144 Microseconds = 272044
     116psTime: Seconds = 1090434144 Nanoseconds = 272044000
    117117
    118118---> TESTPOINT PASSED (psTime{Convert timeval time to psTime} | tst_psTime_01.c)
     
    140140\**********************************************************************************/
    141141
    142 psTime: Seconds = 1090434144 Microseconds = 0
     142psTime: Seconds = 1090434144 Nanoseconds = 0
    143143
    144144---> TESTPOINT PASSED (psTime{Convert tm time to psTime} | tst_psTime_01.c)
  • trunk/psLib/test/astronomy/verified/tst_psTime_03.stdout

    r2966 r3712  
    2828/***************************** TESTPOINT ******************************************\
    2929*             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} *
    3131*             TestType: Positive                                                   *
    3232\**********************************************************************************/
    3333
    3434
    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)
    3636
    3737/***************************** TESTPOINT ******************************************\
Note: See TracChangeset for help on using the changeset viewer.