IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 26, 2009, 10:21:48 AM (17 years ago)
Author:
Paul Price
Message:

API for psTimeConvert was confusing: the time is converted in-place, but returning a psTime* implies that a new structure is created and the operation is performed on it.

File:
1 edited

Legend:

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

    r22680 r22682  
    6666static char *cleanString(char *inString, int sLen);
    6767static char* getToken(char **inString, char *delimiter, psParseErrorType *status);
    68 static psTime* convertTimeTAIUTC(psTime* time);
    69 static psTime* convertTimeUTCTAI(psTime* time);
    70 static psTime* convertTimeTAITT(psTime* time);
    71 static psTime* convertTimeTTTAI(psTime* time);
    72 static psTime* convertTimeUTCUT1(psTime* time);
     68static bool convertTimeTAIUTC(psTime* time);
     69static bool convertTimeUTCTAI(psTime* time);
     70static bool convertTimeTAITT(psTime* time);
     71static bool convertTimeTTTAI(psTime* time);
     72static bool convertTimeUTCUT1(psTime* time);
    7373
    7474static bool timeInit(const char *fileName);
     
    510510}
    511511
    512 static psTime* convertTimeTAIUTC(psTime* time)
     512static bool convertTimeTAIUTC(psTime* time)
    513513{
    514514    psF64  deltaTAI     = 0.0;
     
    550550    }
    551551
    552     return time;
    553 }
    554 
    555 static psTime* convertTimeUTCTAI(psTime* time)
     552    return true;
     553}
     554
     555static bool convertTimeUTCTAI(psTime* time)
    556556{
    557557    psF64  delta     = 0.0;
     
    580580    time->type = PS_TIME_TAI;
    581581
    582     //XXX: Set leapseconds to TRUE
    583     //    time->leapsecond = true;
    584     return time;
    585 }
    586 
    587 static psTime* convertTimeTAITT(psTime* time)
     582    return true;
     583}
     584
     585static bool convertTimeTAITT(psTime* time)
    588586{
    589587    // Add TT offset
     
    600598    time->type = PS_TIME_TT;
    601599
    602     return time;
    603 }
    604 
    605 static psTime* convertTimeTTTAI(psTime* time)
     600    return true;
     601}
     602
     603static bool convertTimeTTTAI(psTime* time)
    606604{
    607605    // Subtract TT offset
     
    625623    time->type = PS_TIME_TAI;
    626624
    627     return time;
    628 }
    629 
    630 static psTime* convertTimeUTCUT1(psTime* time)
     625    return true;
     626}
     627
     628static bool convertTimeUTCUT1(psTime* time)
    631629{
    632630    psS64   ut1utc  = 0;
     
    664662    time->type = PS_TIME_UT1;
    665663
    666     return time;
    667 }
    668 
    669 psTime* psTimeConvert(psTime *time,
    670                       psTimeType type)
     664    return true;
     665}
     666
     667bool psTimeConvert(psTime *time, psTimeType type)
    671668{
    672669    // Error checks
    673     PS_ASSERT_PTR_NON_NULL(time,NULL);
    674     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1), NULL);
    675 
    676     // If the input type is UT1 then return time and generate error message
     670    PS_ASSERT_PTR_NON_NULL(time, false);
     671    PS_ASSERT_INT_WITHIN_RANGE(time->nsec, 0, (psU32)((1e9)-1), false);
     672
    677673    if (time->type == PS_TIME_UT1) {
    678         psError(PS_ERR_BAD_PARAMETER_VALUE,true,"Cannot convert from UT1 time type");
    679         return NULL;
    680     }
    681 
    682     // If the time to convert to is the same as psTime the return time
     674        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot convert from UT1 time type");
     675        return false;
     676    }
    683677    if (time->type == type) {
    684         return time;
    685     }
    686 
    687     // Convert from TAI to UTC, TT, UT1
    688     if (time->type == PS_TIME_TAI) {
    689         // Convert from TAI to UTC
    690         if (type == PS_TIME_UTC) {
    691             time = convertTimeTAIUTC(time);
    692             // Convert from TAI to TT
    693         } else if (type == PS_TIME_TT) {
    694             time = convertTimeTAITT(time);
    695             // Convert from TAI to UT1
    696         } else if (type == PS_TIME_UT1) {
    697             // Convert to UTC first
    698             time = convertTimeTAIUTC(time);
    699             // Convert UTC to UT1
    700             time = convertTimeUTCUT1(time);
    701             // Convert from TAI to unknown time type
    702         } else {
     678        // No action required
     679        return true;
     680    }
     681
     682    switch (time->type) {
     683      case PS_TIME_TAI:
     684        switch (type) {
     685          case PS_TIME_UTC:
     686            return convertTimeTAIUTC(time);
     687          case PS_TIME_TT:
     688            return convertTimeTAITT(time);
     689          case PS_TIME_UT1:
     690            convertTimeTAIUTC(time);
     691            return convertTimeUTCUT1(time);
     692          default:
     693            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
     694            return false;
     695        }
     696        break;
     697      case PS_TIME_TT:
     698        switch (type) {
     699          case PS_TIME_UTC:
     700            convertTimeTTTAI(time);
     701            return convertTimeTAIUTC(time);
     702          case PS_TIME_TAI:
     703            return convertTimeTTTAI(time);
     704          case PS_TIME_UT1:
     705            convertTimeTTTAI(time);
     706            convertTimeTAIUTC(time);
     707            return convertTimeUTCUT1(time);
     708          default:
    703709            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
    704710            return NULL;
    705711        }
    706         // Convert from TT to TAI, UTC, UT1
    707     } else if (time->type == PS_TIME_TT) {
    708         // Convert from TT to UTC
    709         if (type == PS_TIME_UTC) {
    710             // Convert to TAI time first
    711             time = convertTimeTTTAI(time);
    712             // Convert from TAI to UTC
    713             time = convertTimeTAIUTC(time);
    714             // Convert from TT to TAI
    715         } else if (type == PS_TIME_TAI) {
    716             time = convertTimeTTTAI(time);
    717             // Convert from TT to UT1
    718         } else if (type == PS_TIME_UT1) {
    719             // Convert to UTC first
    720             // Convert to TAI time first
    721             time = convertTimeTTTAI(time);
    722             // Convert from TAI to UTC
    723             time = convertTimeTAIUTC(time);
    724             // Convert from UTC to UT1
    725             time = convertTimeUTCUT1(time);
    726             // Convert from TT to unknown time type
    727         } else {
     712        break;
     713      case PS_TIME_UTC:
     714        switch (type) {
     715          case PS_TIME_TAI:
     716            return convertTimeUTCTAI(time);
     717          case PS_TIME_TT:
     718            convertTimeUTCTAI(time);
     719            return convertTimeTAITT(time);
     720          case PS_TIME_UT1:
     721            return convertTimeUTCUT1(time);
     722          default:
    728723            psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
    729724            return NULL;
    730725        }
    731         // Convert from UTC to TAI, TT, UT1
    732     } else if (time->type == PS_TIME_UTC) {
    733         // Convert UTC to TAI
    734         if (type == PS_TIME_TAI) {
    735             time = convertTimeUTCTAI(time);
    736             // Convert UTC to TT
    737         } else if (type == PS_TIME_TT) {
    738             // Convert to TAI time first
    739             time = convertTimeUTCTAI(time);
    740             // Convert TAI to TT
    741             time = convertTimeTAITT(time);
    742             // Convert UTC to UT1
    743         } else if (type == PS_TIME_UT1) {
    744             time = convertTimeUTCUT1(time);
    745             // Convert UTC to unknown time type
    746         } else {
    747             psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), type);
    748             return NULL;
    749         }
    750         // Convert unknown time type
    751     } else {
     726        break;
     727      default:
    752728        psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Specified type, %d, is not supported."), time->type);
    753729        return NULL;
    754730    }
    755731
    756     return time;
     732    psAbort("Should never reach here.");
     733    return false;
    757734}
    758735
     
    792769    tdtTime->nsec = time->nsec;
    793770    tdtTime->leapsecond = time->leapsecond;
    794     tdtTime = psTimeConvert(tdtTime,PS_TIME_TT);
     771    psTimeConvert(tdtTime,PS_TIME_TT);
    795772
    796773    // Determine time reference to UT1
     
    799776    ut1Time->nsec = time->nsec;
    800777    ut1Time->leapsecond = time->leapsecond;
    801     ut1Time = psTimeConvert(ut1Time,PS_TIME_UT1);
     778    psTimeConvert(ut1Time,PS_TIME_UT1);
    802779
    803780    // Calculate UT1 as Julian Centuries since J2000.0
     
    996973    *out = *time;
    997974    if (out->type != PS_TIME_UT1) {
    998         out = psTimeConvert(out, PS_TIME_UT1);
     975        psTimeConvert(out, PS_TIME_UT1);
    999976    }
    1000977    //see if corrections include seconds or just nano-seconds
     
    12911268    //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following:
    12921269    if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) {
    1293         time2 = psTimeConvert(time2, PS_TIME_TAI);
     1270        psTimeConvert(time2, PS_TIME_TAI);
    12941271    }
    12951272
     
    13171294    //XXX: ADD says that this formula works only for PS_TIME_TAI, so adding the following:
    13181295    if (time->type == PS_TIME_UTC || time->type == PS_TIME_TT) {
    1319         time2 = psTimeConvert(time2, PS_TIME_TAI);
     1296        psTimeConvert(time2, PS_TIME_TAI);
    13201297    }
    13211298
     
    17711748        tempTime->sec = time->sec;
    17721749        tempTime->nsec = time->nsec;
    1773         tempTime = psTimeConvert(tempTime, PS_TIME_TAI);
     1750        psTimeConvert(tempTime, PS_TIME_TAI);
    17741751        outTime = psTimeAlloc(PS_TIME_TAI);
    17751752    } else {
     
    17891766    // Convert result to same time type as input
    17901767    if (time->type == PS_TIME_UTC) {
    1791         outTime = psTimeConvert(outTime, PS_TIME_UTC);
     1768        psTimeConvert(outTime, PS_TIME_UTC);
    17921769    }
    17931770
     
    18231800        tempTime1->sec = time1->sec;
    18241801        tempTime1->nsec = time1->nsec;
    1825         tempTime1 = psTimeConvert(tempTime1, PS_TIME_TAI);
     1802        psTimeConvert(tempTime1, PS_TIME_TAI);
    18261803    } else {
    18271804        tempTime1 = psMemIncrRefCounter((psTime*)time1);
     
    18311808        tempTime2->sec = time2->sec;
    18321809        tempTime2->nsec = time2->nsec;
    1833         tempTime2 = psTimeConvert(tempTime2, PS_TIME_TAI);
     1810        psTimeConvert(tempTime2, PS_TIME_TAI);
    18341811    } else {
    18351812        tempTime2 = psMemIncrRefCounter((psTime*)time2);
Note: See TracChangeset for help on using the changeset viewer.