Earth Observation Mission CFI Software Usage Guide for Object Oriented Software |
The Earth Observation CFI Lib library provides the class Time with the following functionality:
A Time object can be constructed in two different ways:
Note that the time attributes (value, reference and format) are public and can be set in the constructor or modified afterwards. The Time object has to be constructed with the TimeCorrelation if Time is to be involved in time reference transformations. It is highly advisable to construct the time this way, as the user cannot be aware when the Time object is going to be involved in such tranformation (For example, when subtracting two times that are in different time references, internally it is neccessary to change the refence of one of them to allow the operation).
// ------------------------------------------------------------------------ // // C++ Example Program. // TIME OPERATIONS // // ------------------------------------------------------------------------ // Non-EOCFI include files #include <string> #include <vector> #include <iostream> // EOCFI includes #include "CfiError.h" #include "LibData.h" #include "TimeCorrelation.h" #include "EETime.h" // Namespaces using namespace EECFI; using namespace std; // Main program int main (int argc, char *argv[]) { //------------------------------------------------- //------------------------------------------------- try {
// ---------------------------------------------------------- // Time Correlation initialization. Example 1: with IERS file // ---------------------------------------------------------- cout << "\n\nTimeCorrelation initialisation: Using IERS bulletin" << endl; long timeModel = XLCFI_TIMEMOD_IERS_B_PREDICTED; TimeInterval timeInterval(XLCFI_TIME_TAI, 742.0, 962.0); TimeInterval valTime; vector<string> timeFiles; timeFiles.push_back("./iers_bulletin_b.txt"); // Create TimeCorrelation object TimeCorrelation timeCorr1(timeModel, timeFiles, timeInterval, valTime); //----------------------------- // Get leap seconds information //----------------------------- long leapFlag; string utcTimeBeforeLeap, utcTimeAfterLeap; timeCorr1.getLeapSecondInfo (XLCFI_ASCII_STD_REF_MICROSEC, leapFlag, utcTimeBeforeLeap, utcTimeAfterLeap); if (leapFlag != 0) { cout << "UTC time before leap second = " << utcTimeBeforeLeap << endl; cout << "UTC time after leap second = " << utcTimeBeforeLeap << endl; } // ------------------------------------------------------------- // Time Correlation initialization. Example 2: with fixed values // ------------------------------------------------------------- cout << "\n\nTimeCorrelation initialisation: fixed time correlations" << endl; double initTime[4]; initTime[0] = -245.1000000000000000; // TAI time [days] initTime[1] = -245.0995949074074074; // UTC time [days] (= TAI - 35.0 s) initTime[2] = -245.0995879629629630; // UT1 time [days] (= TAI - 35.6 s) initTime[3] = -245.0997800925925926; // GPS time [days] (= TAI - 19.0 s) // Construct the TimeCorrelation object TimeCorrelation timeCorr2(initTime);
// -------------------------------------------------------------- // Time transformations examples // -------------------------------------------------------------- long transportTime[4]; Time time1(timeCorr2); transportTime[0] = 245; // TAI time [integer days] transportTime[1] = 150; // TAI time [integer seconds] transportTime[2] = 1500; // TAI time [integer microseconds] transportTime[3] = 0; // Unused in Transport_Standard // Set the time in the object time1.setTransport(transportTime, XLCFI_TIME_TAI, XLCFI_TRANS_STD); cout << "Input Time: Transport format XLCFI_TRANS_STD (TAI)" << endl; cout << " time = (" << transportTime[0] << ", " << transportTime[1] << ", " << transportTime[2] << ", " << transportTime[3] << ", " << ")" << endl; cout << "Output Time: Processing format (TAI)" << endl; cout << " time = " << time1.time << endl << endl; // Get the ASCII time string asciiTime; time1.getAscii(asciiTime, XLCFI_TIME_GPS, XLCFI_ASCII_STD_REF_MICROSEC); cout << "Output Time: ASCII format (GPS)" << endl; cout << " time = " << asciiTime << endl << endl; // Get Transport format long transportTime2[4]; time1.getTransport(transportTime2, XLCFI_TIME_UTC, XLCFI_TRANS_CRYO_TM_SIRAL); cout << "Output Time: CRYOSAT SIRAL transport format (UTC)" << endl << endl; cout << " time = (" << transportTime[0] << ", " << transportTime[1] << ", " << transportTime[2] << ", " << transportTime[3] << ", " << ")" << endl; // Set the time to an ASCII date time1.setAscii("2010-05-03_14:12:10", XLCFI_TIME_TAI, XLCFI_ASCII_STD); cout << "Input Time: ASCII format XLCFI_ASCII_STD (TAI)" << endl; cout << " time = " << "2010-05-03_14:12:10" << endl; cout << "Output Time: Processing format (TAI)" << endl; cout << " time = " << time1.time << endl << endl; // Get a new time value in a different time reference Time time2 = time1.getProcessing(XLCFI_TIME_UTC); cout << "Output Time: Processing format (UTC)" << endl; cout << " time = " << time2.time << endl << endl; // Change time2 to a new time reference time2.change(XLCFI_TIME_GPS); cout << "Output Time: Processing format (GPS)" << endl; cout << " time = " << time2.time << endl << endl; // ------------------------------------------------------------------------ // Operation with Time objects // ------------------------------------------------------------------------ cout << "\nTime: Time operators" << endl; time1 = Time(timeCorr2, 245.123456, XLCFI_TIME_TAI, XLCFI_PROC); time2.setProcessing(110.100001, XLCFI_TIME_TAI, XLCFI_PROC); Time time3; time3 = time1 + 1.0; cout << "Time1 = " << time1.time << endl; cout << "Time2 = " << time2.time << endl; cout << "Time1 + 1.0 =" << time3.time << endl; cout << "Time1 - Time2 =" << (time1-time2) << endl; cout << "Time1 - 1.0 =" << (time1-1.0).time << endl; cout << "Time1 > Time2 ? " << (time1 > time2 ? "true" : "false") << endl; cout << "Time1 < Time2 ? " << (time1 < time2 ? "true" : "false") << endl; cout << "Time1 >= Time2 ? " << (time1 >= time2 ? "true" : "false") << endl; cout << "Time1 <= Time2 ? " << (time1 <= time2 ? "true" : "false") << endl; cout << "Time1 == Time2 ? " << (time1 == time2 ? "true" : "false") << endl; cout << "Time1 != Time2 ? " << (time1 != time2 ? "true" : "false") << endl; }//end try catch (CfiError cfiError) { //If an exception is thrown, there have been errors during execution vector<string> errorMessages; // Get error messages cfiError.getMsg(errorMessages); // Pring Error messages for (long i = 0; i < errorMessages.size(); i++) { cout << errorMessages[i] << endl; } } return 0; }