IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2725


Ignore:
Timestamp:
Dec 16, 2004, 8:53:35 AM (22 years ago)
Author:
harman
Message:

Added new time math functions

Location:
trunk/psLib
Files:
11 edited

Legend:

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

    r2607 r2725  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-12-03 23:15:00 $
     12 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-12-16 18:52:41 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    151151    // Check time metadata. Function call reports errors.
    152152    if(timeMetadata == NULL) {
    153         if(!psTimeInit(TIME_CONFIG_FILE))
     153        if(!p_psTimeInit(TIME_CONFIG_FILE))
    154154            return 0.0;
    155155    }
     
    184184}
    185185
    186 bool psTimeInit(const char *fileName)
     186bool p_psTimeInit(const char *fileName)
    187187{
    188188    bool foundTable = false;
     
    326326}
    327327
    328 bool psTimeFinalize(void)
     328bool p_psTimeFinalize(void)
    329329{
    330330    if(timeMetadata != NULL) {
     
    405405        time->sec = time->sec + delta;    // User wants TAI time. Add leapseconds.
    406406    } else {
    407         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    408                 PS_ERRORTEXT_psTime_TYPE_UNKNOWN,
    409                 type);
     407        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_TYPE_UNKNOWN, type);
    410408    }
    411409
     
    431429    psF64  const6       =  0.0000013;
    432430    psTime *ut1UtcDelta = NULL;
    433     psTime *tdtDelta    = NULL;
    434431    psTime *tdtTime     = NULL;
    435432    psTime *taiTime     = NULL;
     
    456453
    457454    // Convert Universal Time (UTC) to  UT1
    458     ut1UtcDelta = psTimeAlloc(PS_TIME_UTC);
    459     ut1UtcDbl = psTimeGetUT1Delta(taiTime)*1e6;
    460     ut1UtcDelta->usec = (psU32)fabs(ut1UtcDbl);
    461     if(ut1UtcDbl<0) {
    462         ut1Time = psTimeSubtract(utcTime, ut1UtcDelta);
    463     } else {
    464         ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
    465     }
     455    ut1UtcDbl = psTimeGetUT1Delta(taiTime);
     456    utcTime->type = PS_TIME_TAI; // Don't allow addition of leapseconds to ut1Time
     457    ut1Time = psTimeMath(utcTime, ut1UtcDbl);
     458    utcTime->type = PS_TIME_UTC;
    466459
    467460    // Calculate UT1 as Julian Centuries since J2000.0
     
    471464
    472465    // Calculate Terrestial Dynamical Time (TDT)
    473     tdtDelta = psTimeAlloc(PS_TIME_TAI);
    474     tdtDelta->sec = 32;
    475     tdtDelta->usec = 184000;
    476     tdtTime = psTimeAdd(taiTime, tdtDelta);
     466    tdtTime = psTimeMath(taiTime, 32.184);
    477467
    478468    // Calculate TDT as Julian centuries since J2000.0
     
    496486    psFree(ut1Time);
    497487    psFree(tdtTime);
    498     psFree(tdtDelta);
    499488    psFree(utcTime);
    500489    psFree(taiTime);
     
    718707    // Check time metadata
    719708    if(timeMetadata == NULL) {
    720         if(!psTimeInit(TIME_CONFIG_FILE))
     709        if(!p_psTimeInit(TIME_CONFIG_FILE)) {
    721710            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_FILE_NOT_FOUND, "psTime.config");
    722         return 0.0;
     711            return 0.0;
     712        }
    723713    }
    724714
     
    741731    // Check for successful interpolation
    742732    for(i=0; i<stats->n; i++) {
    743         if(stats->data.U32[i]!=PS_LOOKUP_PAST_BOTTOM && stats->data.U32[i]!=PS_LOOKUP_PAST_TOP) {
     733        if(stats->data.U32[i] == PS_LOOKUP_ERROR) {
    744734            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_INTERPOLATION_FAILED);
    745735        }
     
    835825    // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form
    836826    if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) {
    837         psError(PS_ERR_OS_CALL_FAILED, true,
    838                 PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED);
     827        psError(PS_ERR_OS_CALL_FAILED, true, PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED);
    839828    }
    840829
    841830    if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3dZ", tempString, ms) < 0) {
    842         psError(PS_ERR_OS_CALL_FAILED, true,
    843                 PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED);
     831        psError(PS_ERR_OS_CALL_FAILED, true, PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED);
    844832    }
    845833    psFree(tempString);
     
    987975
    988976    // Convert YYYY-MM-DDThh:mm:ss.sss in string form to tm time
    989     if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d",
    990                &tmTime.tm_year,&tmTime.tm_mon,&tmTime.tm_mday,
    991                &tmTime.tm_hour,&tmTime.tm_min,&tmTime.tm_sec,&millisecond) < 7) {
    992         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    993                 PS_ERRORTEXT_psTime_ISOTIME_MALFORMED,
    994                 time);
     977    if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d", &tmTime.tm_year, &tmTime.tm_mon, &tmTime.tm_mday,
     978               &tmTime.tm_hour, &tmTime.tm_min, &tmTime.tm_sec,&millisecond) < 7) {
     979        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_ISOTIME_MALFORMED, time);
    995980        return NULL;
    996981    }
     
    10951080}
    10961081
    1097 psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
    1098 {
    1099     psF64 deltaSec = 0;
    1100     psS64 deltaUsec = 0;
     1082psTime* psTimeMath(const psTime *time, psF64 delta)
     1083{
     1084    psS64 deltaSec = 0;
     1085    psF64 uSecTimeInput = 0.0;
    11011086    psTime *outTime = NULL;
    1102 
    1103 
    1104     // Error checks
    1105     PS_PTR_CHECK_NULL(tai1,NULL);
    1106     PS_PTR_CHECK_NULL(tai2,NULL);
    1107     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1108     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1109 
    1110     if(tai1->type != tai2->type) {
    1111         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1112                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1113         return NULL;
    1114     }
    1115 
    1116     outTime = psTimeAlloc(tai1->type);
    1117     outTime->sec = tai1->sec + tai2->sec;
    1118     deltaUsec = tai1->usec + tai2->usec;
    1119 
    1120     // Adjust time in case of microsecond overflow after addition
    1121     if(deltaUsec >= 1e6) {
    1122         if(deltaSec < 0 ) {
    1123             outTime->sec--; // Negative seconds - make more negative
    1124         } else {
    1125             outTime->sec++; // Positive seconds - make more positive
    1126         }
    1127         outTime->usec = deltaUsec - 1e6;
     1087    psTime *tempTime = NULL;
     1088
     1089
     1090    // Error checks
     1091    PS_PTR_CHECK_NULL(time,NULL);
     1092    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
     1093
     1094    // Convert time to TAI if necessary, but without changing input arguments
     1095    if(time->type == PS_TIME_UTC) {
     1096        tempTime = psTimeAlloc(PS_TIME_UTC);
     1097        tempTime->sec = time->sec;
     1098        tempTime->usec = time->usec;
     1099        tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
    11281100    } else {
    1129         outTime->usec = deltaUsec;
    1130     }
     1101        tempTime = psMemIncrRefCounter((psTime*)time);
     1102    }
     1103
     1104    uSecTimeInput = tempTime->sec >= 0 ? 1.0 : -1.0;
     1105    uSecTimeInput = uSecTimeInput*tempTime->usec/1e6;
     1106    delta = delta + uSecTimeInput;
     1107    deltaSec = (psS64)delta;
     1108
     1109    // Create output time
     1110    outTime = psTimeAlloc(PS_TIME_TAI);
     1111    outTime->sec = delta + (psF64)tempTime->sec;
     1112    outTime->usec = fabs((delta-(psF64)deltaSec)*1e6);
    11311113
    11321114    // Error check
    11331115    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
    11341116
     1117    // Convert result to same time type as input
     1118    if(time->type == PS_TIME_UTC) {
     1119        outTime = psTimeConvert(outTime, PS_TIME_UTC);
     1120    }
     1121
     1122    psFree(tempTime);
     1123
    11351124    return outTime;
    11361125}
    11371126
    1138 psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
    1139 {
    1140     psS64 deltaSec = 0;
    1141     psS64 deltaUsec = 0;
    1142     psTime *outTime = NULL;
    1143 
    1144 
    1145     // Error checks
    1146     PS_PTR_CHECK_NULL(tai1,NULL);
    1147     PS_PTR_CHECK_NULL(tai2,NULL);
    1148     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1149     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1150     if(tai1->type != tai2->type) {
    1151         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1152                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1153         return NULL;
    1154     }
    1155 
    1156     outTime = psTimeAlloc(tai1->type);
    1157     deltaSec = tai1->sec - tai2->sec;
    1158     deltaUsec = (psS64)tai1->usec - (psS64)tai2->usec;
    1159 
    1160     // Adjust time in case of microsecond underflow after subtraction
    1161     if(deltaUsec < 0) {
    1162         if(deltaSec < 0) {
    1163             deltaSec++; // Negative seconds - make less negative
    1164         } else {
    1165             deltaSec--; // Positive seconds - make less positive
    1166         }
    1167         outTime->usec = 1e6+deltaUsec;
     1127psF64 psTimeDelta(const psTime *time1, const psTime *time2)
     1128{
     1129    psF64 out = 0.0;
     1130    psF64 uSec1 = 0.0;
     1131    psF64 uSec2 = 0.0;
     1132    psTime *tempTime1 = NULL;
     1133    psTime *tempTime2 = NULL;
     1134
     1135
     1136    // Error checks
     1137    PS_PTR_CHECK_NULL(time1,0.0);
     1138    PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0.0);
     1139    PS_PTR_CHECK_NULL(time2,0.0);
     1140    PS_INT_CHECK_RANGE(time2->usec,0,1e6-1,0.0);
     1141
     1142    // Convert time to TAI if necessary, but without changing input arguments
     1143    if(time1->type == PS_TIME_UTC) {
     1144        tempTime1 = psTimeAlloc(PS_TIME_UTC);
     1145        tempTime1->sec = time1->sec;
     1146        tempTime1->usec = time1->usec;
     1147        tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
    11681148    } else {
    1169         outTime->usec = deltaUsec;
    1170     }
    1171 
    1172     outTime->sec = deltaSec;
    1173 
    1174     return outTime;
    1175 }
    1176 
    1177 psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
    1178 {
    1179     psS64 deltaSec = 0;
    1180     psS64 deltaUsec = 0;
    1181     psTime *outTime = NULL;
    1182 
    1183 
    1184     // Error checks
    1185     // Error checks
    1186     PS_PTR_CHECK_NULL(tai1,NULL);
    1187     PS_PTR_CHECK_NULL(tai2,NULL);
    1188     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1189     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1190     if(tai1->type != tai2->type) {
    1191         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1192                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1193         return NULL;
    1194     }
    1195 
    1196     outTime = psTimeAlloc(tai1->type);
    1197     deltaSec = tai1->sec - tai2->sec;
    1198     deltaUsec = (psS64)tai1->usec - (psS64)tai2->usec;
    1199 
    1200     // Adjust time in case of microsecond underflow after subtraction
    1201     if(deltaUsec < 0) {
    1202         if(deltaSec < 0) {
    1203             deltaSec++; // Negative seconds - make less negative
    1204         } else {
    1205             deltaSec--; // Positive seconds - make less positive
    1206         }
    1207         outTime->usec = 1e6+deltaUsec;
     1149        tempTime1 = psMemIncrRefCounter((psTime*)time1);
     1150    }
     1151    if(time2->type == PS_TIME_UTC) {
     1152        tempTime2 = psTimeAlloc(PS_TIME_UTC);
     1153        tempTime2->sec = time2->sec;
     1154        tempTime2->usec = time2->usec;
     1155        tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
    12081156    } else {
    1209         outTime->usec = deltaUsec;
    1210     }
    1211 
    1212     outTime->sec = abs(deltaSec);
    1213 
    1214     return outTime;
    1215 }
     1157        tempTime2 = psMemIncrRefCounter((psTime*)time2);
     1158    }
     1159
     1160    uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0;
     1161    uSec1 = uSec1*tempTime1->usec/1e6;
     1162    uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0;
     1163    uSec2 = uSec2*tempTime2->usec/1e6;
     1164    out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2);
     1165
     1166    psFree(tempTime1);
     1167    psFree(tempTime2);
     1168
     1169    return out;
     1170}
     1171
  • trunk/psLib/src/astro/psTime.h

    r2318 r2725  
    55 *
    66 *  A collection of functions are required by psLib to manipulate time data. These functions primarily consist
    7  *  of conversions between specific time formats.  PSLib currently uses the UNIX timeval time system as the
    8  *  base upon which International Atomic Time (TAI) and Universal Time Coordinated (UTC) are calculated. TAI
    9  *  time varies over time due to the earth's rotation and the movement of the continental plates. It is
    10  *  currentls 32 seconds faster than UTC/timeval time. The conversion between TAI and UTC time for other dates
    11  *  is given in the table below, which comes from:
    12  *
    13  *  ftp://maia.usno.navy.mil/ser7/tai-utc.dat
    14  *
    15  *  This table is placed into a static array and used by the psTime functions for conversions.
    16  *
    17  *   1961 JAN  1 =JD 2437300.5  TAI-UTC=   1.4228180 S + (MJD - 37300.) X 0.001296 S
    18  *   1961 AUG  1 =JD 2437512.5  TAI-UTC=   1.3728180 S + (MJD - 37300.) X 0.001296 S
    19  *   1962 JAN  1 =JD 2437665.5  TAI-UTC=   1.8458580 S + (MJD - 37665.) X 0.0011232S
    20  *   1963 NOV  1 =JD 2438334.5  TAI-UTC=   1.9458580 S + (MJD - 37665.) X 0.0011232S
    21  *   1964 JAN  1 =JD 2438395.5  TAI-UTC=   3.2401300 S + (MJD - 38761.) X 0.001296 S
    22  *   1964 APR  1 =JD 2438486.5  TAI-UTC=   3.3401300 S + (MJD - 38761.) X 0.001296 S
    23  *   1964 SEP  1 =JD 2438639.5  TAI-UTC=   3.4401300 S + (MJD - 38761.) X 0.001296 S
    24  *   1965 JAN  1 =JD 2438761.5  TAI-UTC=   3.5401300 S + (MJD - 38761.) X 0.001296 S
    25  *   1965 MAR  1 =JD 2438820.5  TAI-UTC=   3.6401300 S + (MJD - 38761.) X 0.001296 S
    26  *   1965 JUL  1 =JD 2438942.5  TAI-UTC=   3.7401300 S + (MJD - 38761.) X 0.001296 S
    27  *   1965 SEP  1 =JD 2439004.5  TAI-UTC=   3.8401300 S + (MJD - 38761.) X 0.001296 S
    28  *   1966 JAN  1 =JD 2439126.5  TAI-UTC=   4.3131700 S + (MJD - 39126.) X 0.002592 S
    29  *   1968 FEB  1 =JD 2439887.5  TAI-UTC=   4.2131700 S + (MJD - 39126.) X 0.002592 S
    30  *   1972 JAN  1 =JD 2441317.5  TAI-UTC=  10.0       S + (MJD - 41317.) X 0.0      S
    31  *   1972 JUL  1 =JD 2441499.5  TAI-UTC=  11.0       S + (MJD - 41317.) X 0.0      S
    32  *   1973 JAN  1 =JD 2441683.5  TAI-UTC=  12.0       S + (MJD - 41317.) X 0.0      S
    33  *   1974 JAN  1 =JD 2442048.5  TAI-UTC=  13.0       S + (MJD - 41317.) X 0.0      S
    34  *   1975 JAN  1 =JD 2442413.5  TAI-UTC=  14.0       S + (MJD - 41317.) X 0.0      S
    35  *   1976 JAN  1 =JD 2442778.5  TAI-UTC=  15.0       S + (MJD - 41317.) X 0.0      S
    36  *   1977 JAN  1 =JD 2443144.5  TAI-UTC=  16.0       S + (MJD - 41317.) X 0.0      S
    37  *   1978 JAN  1 =JD 2443509.5  TAI-UTC=  17.0       S + (MJD - 41317.) X 0.0      S
    38  *   1979 JAN  1 =JD 2443874.5  TAI-UTC=  18.0       S + (MJD - 41317.) X 0.0      S
    39  *   1980 JAN  1 =JD 2444239.5  TAI-UTC=  19.0       S + (MJD - 41317.) X 0.0      S
    40  *   1981 JUL  1 =JD 2444786.5  TAI-UTC=  20.0       S + (MJD - 41317.) X 0.0      S
    41  *   1982 JUL  1 =JD 2445151.5  TAI-UTC=  21.0       S + (MJD - 41317.) X 0.0      S
    42  *   1983 JUL  1 =JD 2445516.5  TAI-UTC=  22.0       S + (MJD - 41317.) X 0.0      S
    43  *   1985 JUL  1 =JD 2446247.5  TAI-UTC=  23.0       S + (MJD - 41317.) X 0.0      S
    44  *   1988 JAN  1 =JD 2447161.5  TAI-UTC=  24.0       S + (MJD - 41317.) X 0.0      S
    45  *   1990 JAN  1 =JD 2447892.5  TAI-UTC=  25.0       S + (MJD - 41317.) X 0.0      S
    46  *   1991 JAN  1 =JD 2448257.5  TAI-UTC=  26.0       S + (MJD - 41317.) X 0.0      S
    47  *   1992 JUL  1 =JD 2448804.5  TAI-UTC=  27.0       S + (MJD - 41317.) X 0.0      S
    48  *   1993 JUL  1 =JD 2449169.5  TAI-UTC=  28.0       S + (MJD - 41317.) X 0.0      S
    49  *   1994 JUL  1 =JD 2449534.5  TAI-UTC=  29.0       S + (MJD - 41317.) X 0.0      S
    50  *   1996 JAN  1 =JD 2450083.5  TAI-UTC=  30.0       S + (MJD - 41317.) X 0.0      S
    51  *   1997 JUL  1 =JD 2450630.5  TAI-UTC=  31.0       S + (MJD - 41317.) X 0.0      S
    52  *   1999 JAN  1 =JD 2451179.5  TAI-UTC=  32.0       S + (MJD - 41317.) X 0.0      S
     7 *  of conversions between specific time formats.  They use the UNIX timeval time system as the
     8 *  base upon which International Atomic Time (TAI) and Universal Time Coordinated (UTC) are calculated.
    539 *
    5410 *  @author Ross Harman, MHPCC
    5511 *
    56  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    57  *  @date $Date: 2004-11-10 18:27:08 $
     12 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-12-16 18:52:51 $
    5814 *
    5915 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    6016 */
     17
    6118
    6219#ifndef PSTIME_H
     
    10764 * @return  bool: True for success, false for failure.
    10865 */
    109 psBool psTimeInit(const char *fileName);
     66psBool p_psTimeInit(const char *fileName);
    11067
    11168/** Free memory persistant time data.
     
    11572 * @return  void: void.
    11673 */
    117 psBool psTimeFinalize(void);
     74psBool p_psTimeFinalize(void);
    11875
    11976/** Allocate time struct.
     
    305262);
    306263
    307 /** Add two TAI times.
    308  *
    309  *  Adds two TAI times. This function does not add or subtract leapseconds.
     264/** Adds delta to time. Result is in TAI time.
     265 *
     266 *  Adds delta to time. Input time is converted to TAI format if necessary.
    310267 *
    311268 *  @return  psTime*: time.
    312269 */
    313 psTime* psTimeAdd(
    314     const psTime *tai1,                 ///< First TAI time.
    315     const psTime *tai2                  ///< Second TAI time.
    316 );
    317 
    318 /** Subtract two TAI times.
    319  *
    320  *  Subtracts two TAI times. This function does not add or subtract leapseconds.
    321  *
    322  *  @return  psTime*: time.
    323  */
    324 psTime* psTimeSubtract(
    325     const psTime *tai1,                 ///< First TAI time.
    326     const psTime *tai2                  ///< Second TAI time.
    327 );
    328 
    329 
    330 /** Find delta of two TAI times.
    331  *
    332  *  Finds the absolute difference of two TAI times. This function does not add or subtract leapseconds.
    333  *
    334  *  @return  psTime*: time.
    335  */
    336 psTime* psTimeDelta(
    337     const psTime *tai1,                 ///< First TAI time.
    338     const psTime *tai2                  ///< Second TAI time.
     270psTime* psTimeMath(
     271    const psTime *time,                 ///< Time.
     272    psF64 delta                         ///< Time delta.
     273);
     274
     275/** Determine difference between two times. Result is in TAI time.
     276 *
     277 *  Determine difference between two times. Input times are converted to TAI format if necessary.
     278 *
     279 *  @return psF64: Time difference.
     280 */
     281psF64 psTimeDelta(
     282    const psTime *time1,                ///< First time.
     283    const psTime *time2                 ///< Second time.
    339284);
    340285
  • trunk/psLib/src/astronomy/psTime.c

    r2607 r2725  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-12-03 23:15:00 $
     12 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-12-16 18:52:41 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    151151    // Check time metadata. Function call reports errors.
    152152    if(timeMetadata == NULL) {
    153         if(!psTimeInit(TIME_CONFIG_FILE))
     153        if(!p_psTimeInit(TIME_CONFIG_FILE))
    154154            return 0.0;
    155155    }
     
    184184}
    185185
    186 bool psTimeInit(const char *fileName)
     186bool p_psTimeInit(const char *fileName)
    187187{
    188188    bool foundTable = false;
     
    326326}
    327327
    328 bool psTimeFinalize(void)
     328bool p_psTimeFinalize(void)
    329329{
    330330    if(timeMetadata != NULL) {
     
    405405        time->sec = time->sec + delta;    // User wants TAI time. Add leapseconds.
    406406    } else {
    407         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    408                 PS_ERRORTEXT_psTime_TYPE_UNKNOWN,
    409                 type);
     407        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_TYPE_UNKNOWN, type);
    410408    }
    411409
     
    431429    psF64  const6       =  0.0000013;
    432430    psTime *ut1UtcDelta = NULL;
    433     psTime *tdtDelta    = NULL;
    434431    psTime *tdtTime     = NULL;
    435432    psTime *taiTime     = NULL;
     
    456453
    457454    // Convert Universal Time (UTC) to  UT1
    458     ut1UtcDelta = psTimeAlloc(PS_TIME_UTC);
    459     ut1UtcDbl = psTimeGetUT1Delta(taiTime)*1e6;
    460     ut1UtcDelta->usec = (psU32)fabs(ut1UtcDbl);
    461     if(ut1UtcDbl<0) {
    462         ut1Time = psTimeSubtract(utcTime, ut1UtcDelta);
    463     } else {
    464         ut1Time = psTimeAdd(utcTime, ut1UtcDelta);
    465     }
     455    ut1UtcDbl = psTimeGetUT1Delta(taiTime);
     456    utcTime->type = PS_TIME_TAI; // Don't allow addition of leapseconds to ut1Time
     457    ut1Time = psTimeMath(utcTime, ut1UtcDbl);
     458    utcTime->type = PS_TIME_UTC;
    466459
    467460    // Calculate UT1 as Julian Centuries since J2000.0
     
    471464
    472465    // Calculate Terrestial Dynamical Time (TDT)
    473     tdtDelta = psTimeAlloc(PS_TIME_TAI);
    474     tdtDelta->sec = 32;
    475     tdtDelta->usec = 184000;
    476     tdtTime = psTimeAdd(taiTime, tdtDelta);
     466    tdtTime = psTimeMath(taiTime, 32.184);
    477467
    478468    // Calculate TDT as Julian centuries since J2000.0
     
    496486    psFree(ut1Time);
    497487    psFree(tdtTime);
    498     psFree(tdtDelta);
    499488    psFree(utcTime);
    500489    psFree(taiTime);
     
    718707    // Check time metadata
    719708    if(timeMetadata == NULL) {
    720         if(!psTimeInit(TIME_CONFIG_FILE))
     709        if(!p_psTimeInit(TIME_CONFIG_FILE)) {
    721710            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_FILE_NOT_FOUND, "psTime.config");
    722         return 0.0;
     711            return 0.0;
     712        }
    723713    }
    724714
     
    741731    // Check for successful interpolation
    742732    for(i=0; i<stats->n; i++) {
    743         if(stats->data.U32[i]!=PS_LOOKUP_PAST_BOTTOM && stats->data.U32[i]!=PS_LOOKUP_PAST_TOP) {
     733        if(stats->data.U32[i] == PS_LOOKUP_ERROR) {
    744734            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_INTERPOLATION_FAILED);
    745735        }
     
    835825    // Converts psTime to YYYY-MM-DDThh:mm:ss.sss in string form
    836826    if (!strftime(tempString, MAX_TIME_STRING_LENGTH, "%Y-%m-%dT%H:%M:%S", tmTime)) {
    837         psError(PS_ERR_OS_CALL_FAILED, true,
    838                 PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED);
     827        psError(PS_ERR_OS_CALL_FAILED, true, PS_ERRORTEXT_psTime_CONVERT_TIME_TO_STRING_FAILED);
    839828    }
    840829
    841830    if (snprintf(timeString, MAX_TIME_STRING_LENGTH, "%s.%3.3dZ", tempString, ms) < 0) {
    842         psError(PS_ERR_OS_CALL_FAILED, true,
    843                 PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED);
     831        psError(PS_ERR_OS_CALL_FAILED, true, PS_ERRORTEXT_psTime_APPEND_MSEC_FAILED);
    844832    }
    845833    psFree(tempString);
     
    987975
    988976    // Convert YYYY-MM-DDThh:mm:ss.sss in string form to tm time
    989     if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d",
    990                &tmTime.tm_year,&tmTime.tm_mon,&tmTime.tm_mday,
    991                &tmTime.tm_hour,&tmTime.tm_min,&tmTime.tm_sec,&millisecond) < 7) {
    992         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    993                 PS_ERRORTEXT_psTime_ISOTIME_MALFORMED,
    994                 time);
     977    if (sscanf(time, "%d-%d-%dT%d:%d:%d.%d", &tmTime.tm_year, &tmTime.tm_mon, &tmTime.tm_mday,
     978               &tmTime.tm_hour, &tmTime.tm_min, &tmTime.tm_sec,&millisecond) < 7) {
     979        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_ISOTIME_MALFORMED, time);
    995980        return NULL;
    996981    }
     
    10951080}
    10961081
    1097 psTime* psTimeAdd(const psTime *tai1, const psTime *tai2)
    1098 {
    1099     psF64 deltaSec = 0;
    1100     psS64 deltaUsec = 0;
     1082psTime* psTimeMath(const psTime *time, psF64 delta)
     1083{
     1084    psS64 deltaSec = 0;
     1085    psF64 uSecTimeInput = 0.0;
    11011086    psTime *outTime = NULL;
    1102 
    1103 
    1104     // Error checks
    1105     PS_PTR_CHECK_NULL(tai1,NULL);
    1106     PS_PTR_CHECK_NULL(tai2,NULL);
    1107     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1108     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1109 
    1110     if(tai1->type != tai2->type) {
    1111         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1112                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1113         return NULL;
    1114     }
    1115 
    1116     outTime = psTimeAlloc(tai1->type);
    1117     outTime->sec = tai1->sec + tai2->sec;
    1118     deltaUsec = tai1->usec + tai2->usec;
    1119 
    1120     // Adjust time in case of microsecond overflow after addition
    1121     if(deltaUsec >= 1e6) {
    1122         if(deltaSec < 0 ) {
    1123             outTime->sec--; // Negative seconds - make more negative
    1124         } else {
    1125             outTime->sec++; // Positive seconds - make more positive
    1126         }
    1127         outTime->usec = deltaUsec - 1e6;
     1087    psTime *tempTime = NULL;
     1088
     1089
     1090    // Error checks
     1091    PS_PTR_CHECK_NULL(time,NULL);
     1092    PS_INT_CHECK_RANGE(time->usec,0,1e6-1,NULL);
     1093
     1094    // Convert time to TAI if necessary, but without changing input arguments
     1095    if(time->type == PS_TIME_UTC) {
     1096        tempTime = psTimeAlloc(PS_TIME_UTC);
     1097        tempTime->sec = time->sec;
     1098        tempTime->usec = time->usec;
     1099        tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
    11281100    } else {
    1129         outTime->usec = deltaUsec;
    1130     }
     1101        tempTime = psMemIncrRefCounter((psTime*)time);
     1102    }
     1103
     1104    uSecTimeInput = tempTime->sec >= 0 ? 1.0 : -1.0;
     1105    uSecTimeInput = uSecTimeInput*tempTime->usec/1e6;
     1106    delta = delta + uSecTimeInput;
     1107    deltaSec = (psS64)delta;
     1108
     1109    // Create output time
     1110    outTime = psTimeAlloc(PS_TIME_TAI);
     1111    outTime->sec = delta + (psF64)tempTime->sec;
     1112    outTime->usec = fabs((delta-(psF64)deltaSec)*1e6);
    11311113
    11321114    // Error check
    11331115    PS_INT_CHECK_RANGE(outTime->usec,0,1e6-1,outTime);
    11341116
     1117    // Convert result to same time type as input
     1118    if(time->type == PS_TIME_UTC) {
     1119        outTime = psTimeConvert(outTime, PS_TIME_UTC);
     1120    }
     1121
     1122    psFree(tempTime);
     1123
    11351124    return outTime;
    11361125}
    11371126
    1138 psTime* psTimeSubtract(const psTime *tai1, const psTime *tai2)
    1139 {
    1140     psS64 deltaSec = 0;
    1141     psS64 deltaUsec = 0;
    1142     psTime *outTime = NULL;
    1143 
    1144 
    1145     // Error checks
    1146     PS_PTR_CHECK_NULL(tai1,NULL);
    1147     PS_PTR_CHECK_NULL(tai2,NULL);
    1148     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1149     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1150     if(tai1->type != tai2->type) {
    1151         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1152                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1153         return NULL;
    1154     }
    1155 
    1156     outTime = psTimeAlloc(tai1->type);
    1157     deltaSec = tai1->sec - tai2->sec;
    1158     deltaUsec = (psS64)tai1->usec - (psS64)tai2->usec;
    1159 
    1160     // Adjust time in case of microsecond underflow after subtraction
    1161     if(deltaUsec < 0) {
    1162         if(deltaSec < 0) {
    1163             deltaSec++; // Negative seconds - make less negative
    1164         } else {
    1165             deltaSec--; // Positive seconds - make less positive
    1166         }
    1167         outTime->usec = 1e6+deltaUsec;
     1127psF64 psTimeDelta(const psTime *time1, const psTime *time2)
     1128{
     1129    psF64 out = 0.0;
     1130    psF64 uSec1 = 0.0;
     1131    psF64 uSec2 = 0.0;
     1132    psTime *tempTime1 = NULL;
     1133    psTime *tempTime2 = NULL;
     1134
     1135
     1136    // Error checks
     1137    PS_PTR_CHECK_NULL(time1,0.0);
     1138    PS_INT_CHECK_RANGE(time1->usec,0,1e6-1,0.0);
     1139    PS_PTR_CHECK_NULL(time2,0.0);
     1140    PS_INT_CHECK_RANGE(time2->usec,0,1e6-1,0.0);
     1141
     1142    // Convert time to TAI if necessary, but without changing input arguments
     1143    if(time1->type == PS_TIME_UTC) {
     1144        tempTime1 = psTimeAlloc(PS_TIME_UTC);
     1145        tempTime1->sec = time1->sec;
     1146        tempTime1->usec = time1->usec;
     1147        tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
    11681148    } else {
    1169         outTime->usec = deltaUsec;
    1170     }
    1171 
    1172     outTime->sec = deltaSec;
    1173 
    1174     return outTime;
    1175 }
    1176 
    1177 psTime* psTimeDelta(const psTime *tai1, const psTime *tai2)
    1178 {
    1179     psS64 deltaSec = 0;
    1180     psS64 deltaUsec = 0;
    1181     psTime *outTime = NULL;
    1182 
    1183 
    1184     // Error checks
    1185     // Error checks
    1186     PS_PTR_CHECK_NULL(tai1,NULL);
    1187     PS_PTR_CHECK_NULL(tai2,NULL);
    1188     PS_INT_CHECK_RANGE(tai1->usec,0,1e6-1,NULL);
    1189     PS_INT_CHECK_RANGE(tai2->usec,0,1e6-1,NULL);
    1190     if(tai1->type != tai2->type) {
    1191         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    1192                 PS_ERRORTEXT_psTime_TYPE_MISMATCH);
    1193         return NULL;
    1194     }
    1195 
    1196     outTime = psTimeAlloc(tai1->type);
    1197     deltaSec = tai1->sec - tai2->sec;
    1198     deltaUsec = (psS64)tai1->usec - (psS64)tai2->usec;
    1199 
    1200     // Adjust time in case of microsecond underflow after subtraction
    1201     if(deltaUsec < 0) {
    1202         if(deltaSec < 0) {
    1203             deltaSec++; // Negative seconds - make less negative
    1204         } else {
    1205             deltaSec--; // Positive seconds - make less positive
    1206         }
    1207         outTime->usec = 1e6+deltaUsec;
     1149        tempTime1 = psMemIncrRefCounter((psTime*)time1);
     1150    }
     1151    if(time2->type == PS_TIME_UTC) {
     1152        tempTime2 = psTimeAlloc(PS_TIME_UTC);
     1153        tempTime2->sec = time2->sec;
     1154        tempTime2->usec = time2->usec;
     1155        tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
    12081156    } else {
    1209         outTime->usec = deltaUsec;
    1210     }
    1211 
    1212     outTime->sec = abs(deltaSec);
    1213 
    1214     return outTime;
    1215 }
     1157        tempTime2 = psMemIncrRefCounter((psTime*)time2);
     1158    }
     1159
     1160    uSec1 = tempTime1->sec >= 0 ? 1.0 : -1.0;
     1161    uSec1 = uSec1*tempTime1->usec/1e6;
     1162    uSec2 = tempTime2->sec >= 0 ? 1.0 : -1.0;
     1163    uSec2 = uSec2*tempTime2->usec/1e6;
     1164    out = (tempTime1->sec-tempTime2->sec) + (uSec1-uSec2);
     1165
     1166    psFree(tempTime1);
     1167    psFree(tempTime2);
     1168
     1169    return out;
     1170}
     1171
  • trunk/psLib/src/astronomy/psTime.h

    r2318 r2725  
    55 *
    66 *  A collection of functions are required by psLib to manipulate time data. These functions primarily consist
    7  *  of conversions between specific time formats.  PSLib currently uses the UNIX timeval time system as the
    8  *  base upon which International Atomic Time (TAI) and Universal Time Coordinated (UTC) are calculated. TAI
    9  *  time varies over time due to the earth's rotation and the movement of the continental plates. It is
    10  *  currentls 32 seconds faster than UTC/timeval time. The conversion between TAI and UTC time for other dates
    11  *  is given in the table below, which comes from:
    12  *
    13  *  ftp://maia.usno.navy.mil/ser7/tai-utc.dat
    14  *
    15  *  This table is placed into a static array and used by the psTime functions for conversions.
    16  *
    17  *   1961 JAN  1 =JD 2437300.5  TAI-UTC=   1.4228180 S + (MJD - 37300.) X 0.001296 S
    18  *   1961 AUG  1 =JD 2437512.5  TAI-UTC=   1.3728180 S + (MJD - 37300.) X 0.001296 S
    19  *   1962 JAN  1 =JD 2437665.5  TAI-UTC=   1.8458580 S + (MJD - 37665.) X 0.0011232S
    20  *   1963 NOV  1 =JD 2438334.5  TAI-UTC=   1.9458580 S + (MJD - 37665.) X 0.0011232S
    21  *   1964 JAN  1 =JD 2438395.5  TAI-UTC=   3.2401300 S + (MJD - 38761.) X 0.001296 S
    22  *   1964 APR  1 =JD 2438486.5  TAI-UTC=   3.3401300 S + (MJD - 38761.) X 0.001296 S
    23  *   1964 SEP  1 =JD 2438639.5  TAI-UTC=   3.4401300 S + (MJD - 38761.) X 0.001296 S
    24  *   1965 JAN  1 =JD 2438761.5  TAI-UTC=   3.5401300 S + (MJD - 38761.) X 0.001296 S
    25  *   1965 MAR  1 =JD 2438820.5  TAI-UTC=   3.6401300 S + (MJD - 38761.) X 0.001296 S
    26  *   1965 JUL  1 =JD 2438942.5  TAI-UTC=   3.7401300 S + (MJD - 38761.) X 0.001296 S
    27  *   1965 SEP  1 =JD 2439004.5  TAI-UTC=   3.8401300 S + (MJD - 38761.) X 0.001296 S
    28  *   1966 JAN  1 =JD 2439126.5  TAI-UTC=   4.3131700 S + (MJD - 39126.) X 0.002592 S
    29  *   1968 FEB  1 =JD 2439887.5  TAI-UTC=   4.2131700 S + (MJD - 39126.) X 0.002592 S
    30  *   1972 JAN  1 =JD 2441317.5  TAI-UTC=  10.0       S + (MJD - 41317.) X 0.0      S
    31  *   1972 JUL  1 =JD 2441499.5  TAI-UTC=  11.0       S + (MJD - 41317.) X 0.0      S
    32  *   1973 JAN  1 =JD 2441683.5  TAI-UTC=  12.0       S + (MJD - 41317.) X 0.0      S
    33  *   1974 JAN  1 =JD 2442048.5  TAI-UTC=  13.0       S + (MJD - 41317.) X 0.0      S
    34  *   1975 JAN  1 =JD 2442413.5  TAI-UTC=  14.0       S + (MJD - 41317.) X 0.0      S
    35  *   1976 JAN  1 =JD 2442778.5  TAI-UTC=  15.0       S + (MJD - 41317.) X 0.0      S
    36  *   1977 JAN  1 =JD 2443144.5  TAI-UTC=  16.0       S + (MJD - 41317.) X 0.0      S
    37  *   1978 JAN  1 =JD 2443509.5  TAI-UTC=  17.0       S + (MJD - 41317.) X 0.0      S
    38  *   1979 JAN  1 =JD 2443874.5  TAI-UTC=  18.0       S + (MJD - 41317.) X 0.0      S
    39  *   1980 JAN  1 =JD 2444239.5  TAI-UTC=  19.0       S + (MJD - 41317.) X 0.0      S
    40  *   1981 JUL  1 =JD 2444786.5  TAI-UTC=  20.0       S + (MJD - 41317.) X 0.0      S
    41  *   1982 JUL  1 =JD 2445151.5  TAI-UTC=  21.0       S + (MJD - 41317.) X 0.0      S
    42  *   1983 JUL  1 =JD 2445516.5  TAI-UTC=  22.0       S + (MJD - 41317.) X 0.0      S
    43  *   1985 JUL  1 =JD 2446247.5  TAI-UTC=  23.0       S + (MJD - 41317.) X 0.0      S
    44  *   1988 JAN  1 =JD 2447161.5  TAI-UTC=  24.0       S + (MJD - 41317.) X 0.0      S
    45  *   1990 JAN  1 =JD 2447892.5  TAI-UTC=  25.0       S + (MJD - 41317.) X 0.0      S
    46  *   1991 JAN  1 =JD 2448257.5  TAI-UTC=  26.0       S + (MJD - 41317.) X 0.0      S
    47  *   1992 JUL  1 =JD 2448804.5  TAI-UTC=  27.0       S + (MJD - 41317.) X 0.0      S
    48  *   1993 JUL  1 =JD 2449169.5  TAI-UTC=  28.0       S + (MJD - 41317.) X 0.0      S
    49  *   1994 JUL  1 =JD 2449534.5  TAI-UTC=  29.0       S + (MJD - 41317.) X 0.0      S
    50  *   1996 JAN  1 =JD 2450083.5  TAI-UTC=  30.0       S + (MJD - 41317.) X 0.0      S
    51  *   1997 JUL  1 =JD 2450630.5  TAI-UTC=  31.0       S + (MJD - 41317.) X 0.0      S
    52  *   1999 JAN  1 =JD 2451179.5  TAI-UTC=  32.0       S + (MJD - 41317.) X 0.0      S
     7 *  of conversions between specific time formats.  They use the UNIX timeval time system as the
     8 *  base upon which International Atomic Time (TAI) and Universal Time Coordinated (UTC) are calculated.
    539 *
    5410 *  @author Ross Harman, MHPCC
    5511 *
    56  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    57  *  @date $Date: 2004-11-10 18:27:08 $
     12 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-12-16 18:52:51 $
    5814 *
    5915 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    6016 */
     17
    6118
    6219#ifndef PSTIME_H
     
    10764 * @return  bool: True for success, false for failure.
    10865 */
    109 psBool psTimeInit(const char *fileName);
     66psBool p_psTimeInit(const char *fileName);
    11067
    11168/** Free memory persistant time data.
     
    11572 * @return  void: void.
    11673 */
    117 psBool psTimeFinalize(void);
     74psBool p_psTimeFinalize(void);
    11875
    11976/** Allocate time struct.
     
    305262);
    306263
    307 /** Add two TAI times.
    308  *
    309  *  Adds two TAI times. This function does not add or subtract leapseconds.
     264/** Adds delta to time. Result is in TAI time.
     265 *
     266 *  Adds delta to time. Input time is converted to TAI format if necessary.
    310267 *
    311268 *  @return  psTime*: time.
    312269 */
    313 psTime* psTimeAdd(
    314     const psTime *tai1,                 ///< First TAI time.
    315     const psTime *tai2                  ///< Second TAI time.
    316 );
    317 
    318 /** Subtract two TAI times.
    319  *
    320  *  Subtracts two TAI times. This function does not add or subtract leapseconds.
    321  *
    322  *  @return  psTime*: time.
    323  */
    324 psTime* psTimeSubtract(
    325     const psTime *tai1,                 ///< First TAI time.
    326     const psTime *tai2                  ///< Second TAI time.
    327 );
    328 
    329 
    330 /** Find delta of two TAI times.
    331  *
    332  *  Finds the absolute difference of two TAI times. This function does not add or subtract leapseconds.
    333  *
    334  *  @return  psTime*: time.
    335  */
    336 psTime* psTimeDelta(
    337     const psTime *tai1,                 ///< First TAI time.
    338     const psTime *tai2                  ///< Second TAI time.
     270psTime* psTimeMath(
     271    const psTime *time,                 ///< Time.
     272    psF64 delta                         ///< Time delta.
     273);
     274
     275/** Determine difference between two times. Result is in TAI time.
     276 *
     277 *  Determine difference between two times. Input times are converted to TAI format if necessary.
     278 *
     279 *  @return psF64: Time difference.
     280 */
     281psF64 psTimeDelta(
     282    const psTime *time1,                ///< First time.
     283    const psTime *time2                 ///< Second time.
    339284);
    340285
  • trunk/psLib/src/dataIO/psLookupTable.c

    r2369 r2725  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2004-11-15 20:51:15 $
     9*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2004-12-16 18:53:02 $
    1111*
    1212*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    618618            if(hiIdx >= numRows) {
    619619                psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_HIGH, hiIdx);
     620                *status = PS_LOOKUP_ERROR;
    620621                return 0.0;
    621622            }
     
    625626        if(loIdx < 0) {
    626627            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_LOW, loIdx);
     628            *status = PS_LOOKUP_ERROR;
    627629            return 0.0;
    628630        }
     
    631633        if(fabs(denom) < FLT_EPSILON) {
    632634            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_DIVIDE_BY_ZERO);
     635            *status = PS_LOOKUP_ERROR;
    633636            return 0.0;
    634637        } else {
  • trunk/psLib/src/fileUtils/psLookupTable.c

    r2369 r2725  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2004-11-15 20:51:15 $
     9*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2004-12-16 18:53:02 $
    1111*
    1212*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    618618            if(hiIdx >= numRows) {
    619619                psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_HIGH, hiIdx);
     620                *status = PS_LOOKUP_ERROR;
    620621                return 0.0;
    621622            }
     
    625626        if(loIdx < 0) {
    626627            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_LOW, loIdx);
     628            *status = PS_LOOKUP_ERROR;
    627629            return 0.0;
    628630        }
     
    631633        if(fabs(denom) < FLT_EPSILON) {
    632634            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_DIVIDE_BY_ZERO);
     635            *status = PS_LOOKUP_ERROR;
    633636            return 0.0;
    634637        } else {
  • trunk/psLib/src/sys/psConfigure.c

    r2644 r2725  
    1212 *  @author Robert DeSonia, MHPCC
    1313 *
    14  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-12-07 00:02:54 $
     14 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-12-16 18:53:19 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434    // Please code me, Robert and George.
    3535
    36     if(!psTimeInit(timeConfig)) {
     36    if(!p_psTimeInit(timeConfig)) {
    3737        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psTime");
    3838        return;
     
    4242void psLibFinalize(void)
    4343{
    44     if(!psTimeFinalize()) {
     44    if(!p_psTimeFinalize()) {
    4545        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psTime");
    4646        return;
  • trunk/psLib/src/sysUtils/psConfigure.c

    r2644 r2725  
    1212 *  @author Robert DeSonia, MHPCC
    1313 *
    14  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2004-12-07 00:02:54 $
     14 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2004-12-16 18:53:19 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434    // Please code me, Robert and George.
    3535
    36     if(!psTimeInit(timeConfig)) {
     36    if(!p_psTimeInit(timeConfig)) {
    3737        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psTime");
    3838        return;
     
    4242void psLibFinalize(void)
    4343{
    44     if(!psTimeFinalize()) {
     44    if(!p_psTimeFinalize()) {
    4545        psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psTime");
    4646        return;
  • trunk/psLib/src/types/psLookupTable.c

    r2369 r2725  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2004-11-15 20:51:15 $
     9*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2004-12-16 18:53:02 $
    1111*
    1212*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    618618            if(hiIdx >= numRows) {
    619619                psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_HIGH, hiIdx);
     620                *status = PS_LOOKUP_ERROR;
    620621                return 0.0;
    621622            }
     
    625626        if(loIdx < 0) {
    626627            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_INTERPOLATE_LOW, loIdx);
     628            *status = PS_LOOKUP_ERROR;
    627629            return 0.0;
    628630        }
     
    631633        if(fabs(denom) < FLT_EPSILON) {
    632634            psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psLookupTable_DIVIDE_BY_ZERO);
     635            *status = PS_LOOKUP_ERROR;
    633636            return 0.0;
    634637        } else {
  • trunk/psLib/test/astronomy/tst_psTime_03.c

    r2681 r2725  
    1212 *  @author  Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
    15  *  @date  $Date: 2004-12-10 02:50:15 $
     14 *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
     15 *  @date  $Date: 2004-12-16 18:53:28 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030    // Test A - Add two times
    3131    printPositiveTestHeader(stdout, "psTime", "Test A - Add two times");
    32     psTime *time1a   = NULL;
    33     psTime *time1b   = NULL;
     32    psTime *time1a = NULL;
     33    psF64 time1b = 1.111111;
    3434    psTime *timeOut1 = NULL;
    35     time1a = psTimeAlloc(PS_TIME_UTC);
    36     time1b = psTimeAlloc(PS_TIME_UTC);
     35    time1a = psTimeAlloc(PS_TIME_TAI);
    3736    time1a->sec  = 1;
    3837    time1a->usec = 111111;
    39     time1b->sec  = 1;
    40     time1b->usec = 111111;
    41     timeOut1 = psTimeAdd(time1a, time1b);
    42     PRINT_TIME("Time 1:",time1a);
    43     PRINT_TIME("Time 2:",time1b);
    44     PRINT_TIME("Output Time:",timeOut1);
     38    timeOut1 = psTimeMath(time1a, time1b);
     39    if(timeOut1->sec!=2 && timeOut1->usec!=222222) {
     40        printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222\n",timeOut1->sec, timeOut1->usec);
     41    }
    4542    printFooter(stdout, "psTime", "Test A - Add two times", true);
     43
    4644
    4745    // Test B - Add two times with overflow in microseconds
    4846    printPositiveTestHeader(stdout, "psTime", "Test B - Add two times with overflow in microseconds");
    49     psTime *time2a   = NULL;
    50     psTime *time2b   = NULL;
     47    psTime *time2a = NULL;
     48    psF64 time2b = 5.500001;
    5149    psTime *timeOut2 = NULL;
    52     time2a = psTimeAlloc(PS_TIME_UTC);
    53     time2b = psTimeAlloc(PS_TIME_UTC);
     50    time2a = psTimeAlloc(PS_TIME_TAI);
    5451    time2a->sec  = 6;
    5552    time2a->usec = 600001;
    56     time2b->sec  = 5;
    57     time2b->usec = 500001;
    58     timeOut2 = psTimeAdd(time2a, time2b);
    59     PRINT_TIME("Time 1:",time2a);
    60     PRINT_TIME("Time 2:",time2b);
    61     PRINT_TIME("Output Time:",timeOut2);
     53    timeOut2 = psTimeMath(time2a, time2b);
     54    if(timeOut2->sec!=12 && timeOut2->usec!=100002) {
     55        printf("ERROR: Incorrect time, %lld:%u. Expected 12:100002\n",timeOut2->sec, timeOut2->usec);
     56    }
    6257    printFooter(stdout, "psTime", "Test B - Add two times with overflow in microseconds", true);
    6358
     
    6560    // Test C - Subtact two times
    6661    printPositiveTestHeader(stdout, "psTime", "Test C - Subtract two times");
    67     psTime *time3a   = NULL;
    68     psTime *time3b   = NULL;
     62    psTime *time3a = NULL;
     63    psF64 time3b = -1.111111;
    6964    psTime *timeOut3 = NULL;
    70     time3a = psTimeAlloc(PS_TIME_UTC);
    71     time3b = psTimeAlloc(PS_TIME_UTC);
     65    time3a = psTimeAlloc(PS_TIME_TAI);
    7266    time3a->sec  = 3;
    7367    time3a->usec = 333333;
    74     time3b->sec  = 1;
    75     time3b->usec = 111111;
    76     timeOut3 = psTimeSubtract(time3a, time3b);
    77     PRINT_TIME("Time 1:",time3a);
    78     PRINT_TIME("Time 2:",time3b);
    79     PRINT_TIME("Output Time:",timeOut3);
     68    timeOut3 = psTimeMath(time3a, time3b);
     69    if(timeOut3->sec!=2 && timeOut3->usec!=222222) {
     70        printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222\n",timeOut3->sec, timeOut3->usec);
     71    }
    8072    printFooter(stdout, "psTime", "Test C - Subtract two times", true);
    8173
     
    8375    // Test D - Subtact two times with underflow in microseconds
    8476    printPositiveTestHeader(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds");
    85     psTime *time4a   = NULL;
    86     psTime *time4b   = NULL;
     77    psTime *time4a = NULL;
     78    psF64 time4b = -2.000003;
    8779    psTime *timeOut4 = NULL;
    88     time4a = psTimeAlloc(PS_TIME_UTC);
    89     time4b = psTimeAlloc(PS_TIME_UTC);
     80    time4a = psTimeAlloc(PS_TIME_TAI);
    9081    time4a->sec  = 5;
    9182    time4a->usec = 1;
    92     time4b->sec  = 2;
    93     time4b->usec = 3;
    94     timeOut4 = psTimeSubtract(time4a, time4b);
    95     PRINT_TIME("Time 1:",time4a);
    96     PRINT_TIME("Time 2:",time4b);
    97     PRINT_TIME("Output Time:",timeOut4);
     83    timeOut4 = psTimeMath(time4a, time4b);
     84    if(timeOut4->sec!=2 && timeOut4->usec!=999997) {
     85        printf("ERROR: Incorrect time, %lld:%u. Expected 2:999997\n",timeOut4->sec, timeOut4->usec);
     86    }
    9887    printFooter(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds", true);
     88
    9989
    10090    // Test E - Delta two times
    10191    printPositiveTestHeader(stdout, "psTime", "Test E - Delta two times");
    102     psTime *time5a   = NULL;
    103     psTime *time5b   = NULL;
    104     psTime *timeOut5 = NULL;
    105     time5a = psTimeAlloc(PS_TIME_UTC);
    106     time5b = psTimeAlloc(PS_TIME_UTC);
    107     time5a->sec  = 2;
    108     time5a->usec = 1;
    109     time5b->sec  = 5;
    110     time5b->usec = 3;
     92    psTime *time5a = NULL;
     93    psTime *time5b = NULL;
     94    psF64 timeOut5 = 0.0;
     95    time5a = psTimeAlloc(PS_TIME_TAI);
     96    time5b = psTimeAlloc(PS_TIME_TAI);
     97    time5a->sec  = 8;
     98    time5a->usec = 8;
     99    time5b->sec  = 7;
     100    time5b->usec = 7;
    111101    timeOut5 = psTimeDelta(time5a, time5b);
    112     PRINT_TIME("Time 1:",time5a);
    113     PRINT_TIME("Time 2:",time5b);
    114     PRINT_TIME("Output Time:",timeOut5);
     102    if(fabs(timeOut5-1.000001) > FLT_EPSILON) {
     103        printf("ERROR: Incorrect delta, %lf. Expected -1.000001\n", timeOut5);
     104    }
    115105    printFooter(stdout, "psTime", "Test E - Delta two times", true);
    116106
    117107
    118     // Test D - Free data
    119     printPositiveTestHeader(stdout, "psTime", "Test D - Free data");
     108    // Test F - Delta two times with underflow in microseconds
     109    printPositiveTestHeader(stdout, "psTime", "Test F - Delta two times with underflow in microseconds");
     110    psTime *time6a = NULL;
     111    psTime *time6b = NULL;
     112    psF64 timeOut6 = 0.0;
     113    time6a = psTimeAlloc(PS_TIME_TAI);
     114    time6b = psTimeAlloc(PS_TIME_TAI);
     115    time6a->sec  = 8;
     116    time6a->usec = 1;
     117    time6b->sec  = 7;
     118    time6b->usec = 7;
     119    timeOut6 = psTimeDelta(time6a, time6b);
     120    if(fabs(timeOut6-0.999994) > FLT_EPSILON) {
     121        printf("ERROR: Incorrect delta, %lf. Expected 0.999994\n", timeOut6);
     122    }
     123    printFooter(stdout, "psTime", "Test F - Delta two times with underflow in microseconds", true);
     124
     125
     126    // Test G - Add two times across leapsecond boundary
     127    printPositiveTestHeader(stdout, "psTime", "Test G - Add two times across leapsecond boundary");
     128    psF64 time7b = 30.0;
     129    char *out7 = NULL;
     130    psTime *time7a = NULL;
     131    psTime *timeOut7 = NULL;
     132    time7a = psTimeFromISOTime("1998-12-31T23:59:45.00");
     133    time7a->type = PS_TIME_UTC;
     134    timeOut7 = psTimeMath(time7a, time7b);
     135    out7 = psTimeToISOTime(timeOut7);
     136    printf("%s\n", out7);
     137    printFooter(stdout, "psTime", "Test G - Add two times across leapsecond boundary", true);
     138
     139
     140    // Test G - Free data
     141    printPositiveTestHeader(stdout, "psTime", "Test G - Free data");
     142    psLibFinalize();
    120143    psFree(time1a);
    121     psFree(time1b);
    122144    psFree(timeOut1);
    123145    psFree(time2a);
    124     psFree(time2b);
    125146    psFree(timeOut2);
    126147    psFree(time3a);
    127     psFree(time3b);
    128148    psFree(timeOut3);
    129149    psFree(time4a);
    130     psFree(time4b);
    131150    psFree(timeOut4);
    132151    psFree(time5a);
    133152    psFree(time5b);
    134     psFree(timeOut5);
    135     if ( psMemCheckLeaks(0, NULL, stdout,false) ) {
     153    psFree(time6a);
     154    psFree(time6b);
     155    psFree(out7);
     156    psFree(time7a);
     157    psFree(timeOut7);
     158    if (psMemCheckLeaks(0, NULL, stdout,false)) {
    136159        psError(PS_ERR_UNKNOWN,true,"Memory leaks detected.");
    137160        return 10;
     
    142165        printf("ERROR: Found %d bad memory blocks\n", nBad);
    143166    }
    144     printFooter(stdout, "psTime", "Test D - Free data", true);
     167    printFooter(stdout, "psTime", "Test G - Free data", true);
    145168    return 0;
    146169}
  • trunk/psLib/test/astronomy/tst_psTime_04.c

    r2392 r2725  
    1414 *  @author  Ross Harman, MHPCC
    1515 *
    16  *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
    17  *  @date  $Date: 2004-11-22 20:52:45 $
     16 *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
     17 *  @date  $Date: 2004-12-16 18:53:35 $
    1818 *
    1919 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2929    // Test A - Initialize time
    3030    printPositiveTestHeader(stdout, "psTime", "Test A - Initialize time");
    31     bool status = true;
    32     status = psTimeInit("../../config/psTime.config");
    33     psTimeFinalize();
     31    psLibInit(true, "../../config/psTime.config");
     32    psLibFinalize();
    3433    printFooter(stdout, "psTime", "Test A - Initialize time", true);
    3534
     
    3837    printNegativeTestHeader(stdout,"psTime", "Test B - Attempt to open non-existant time config file",
    3938                            "Failed to open file 'zzz'.  Check if it exists and it has the proper permissions.", 0);
    40     status = psTimeInit("zzz");
     39    psLibInit(true, "zzz");
    4140    printFooter(stdout, "psTime", "Test B - Attempt to open non-existant time config file", true);
    4241
     
    4544    printNegativeTestHeader(stdout,"psTime", "Test C - Attempt to open non-existant time data files",
    4645                            "Failed to open file 'zzz'.  Check if it exists and it has the proper permissions.", 0);
    47     status = psTimeInit("./test.psTime.config1");
    48     psTimeFinalize();
     46    psLibInit(true, "./test.psTime.config1");
     47    psLibFinalize();
    4948    printFooter(stdout, "psTime", "Test C - Attempt to open non-existant time data files", true);
    5049
     
    5352    printNegativeTestHeader(stdout,"psTime", "Test D - Attempt to read incorrect number of files",
    5453                            "Incorrect number of table files entered. Found: 3. Expected: 4.", 0);
    55     status = psTimeInit("./test.psTime.config2");
    56     psTimeFinalize();
     54    psLibInit(true, "./test.psTime.config2");
     55    psLibFinalize();
    5756    printFooter(stdout, "psTime", "Test D - Attempt to read incorrect number of files", true);
    5857
     
    6160    printNegativeTestHeader(stdout,"psTime", "Test E - Attempt to read incorrect number of from values",
    6261                            "Incorrect vector size. Size: 3, Expected 4.", 0);
    63     status = psTimeInit("./test.psTime.config3");
    64     psTimeFinalize();
     62    psLibInit(true, "./test.psTime.config3");
     63    psLibFinalize();
    6564    printFooter(stdout, "psTime", "Test E - Attempt to read incorrect number of from values", true);
    6665
     
    6968    printNegativeTestHeader(stdout,"psTime", "Test F - Attempt to read data file with typo in number",
    7069                            "Unable to parse string, number on line 16.", 0);
    71     status = psTimeInit("./test.psTime.config4");
    72     psTimeFinalize();
     70    psLibInit(true, "./test.psTime.config4");
     71    psLibFinalize();
    7372    printFooter(stdout, "psTime", "Test F - Attempt to read data file with typo in number", true);
    7473
     
    7675    // Test G - Free data
    7776    printPositiveTestHeader(stdout, "psTime", "Test G - Free data");
    78     psTimeFinalize();
     77    psLibFinalize();
    7978    if( psMemCheckLeaks(0, NULL, stdout,false) != 0 ) {
    8079        psError(PS_ERR_UNKNOWN,true,"Memory leak detected.");
Note: See TracChangeset for help on using the changeset viewer.