| Earth Observation Mission CFI Software Usage Guide for Object Oriented Software |

# TIME OPERATIONS

The Earth Observation CFI Lib library provides the class Time with the following functionality:

- The Time object stores as attributes, the time value in MJD2000 for a given time reference
- Those attributes can be accessed directly to set the values (public attributes) or
- Time attributes can be set with other time formats (transport or ascii).
- It provides methods to get the date in a different time reference and/or format
- Add/Subtract a time duration to the current time
- Get the time period between two times
- Compare two times

## How to work with the Time object

A Time object can be constructed in two different ways:

- Using a TimeCorrelation object in the constructor
- Without a TimeCorrelation object in the constructor

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).

#### Example:

    // ------------------------------------------------------------------------
    //
    //                           JAVA Example Program.
    //                           TIME OPERATIONS
    //
    // ------------------------------------------------------------------------

    import EECFI.*;

    import java.util.Vector;
    import java.lang.String;
    import java.lang.Long;

    // Main program
    public class Example
    {
      public static void main(String[] args)
      {
        //-------------------------------------------------
        //-------------------------------------------------

        try
        {

          // ----------------------------------------------------------
          // Time Correlation initialization. Example 1: with IERS file
          // ----------------------------------------------------------
          System.out.println( "\n\nTimeCorrelation initialisation: Using IERS bulletin" );

          long         timeModel = XLCFI_TIMEMOD_IERS_B_PREDICTED;
          TimeInterval timeInterval = new TimeInterval(XLCFI_TIME_TAI, 742.0, 962.0);
          TimeInterval valTime = new TimeInterval();

          Vector<String> timeFiles = new Vector<String>();
          timeFiles.addElement(new String("./iers_bulletin_b.txt"));

          // Create TimeCorrelation object
          TimeCorrelation timeCorr1 = new TimeCorrelation(timeModel, timeFiles, timeInterval, valTime);

          //-----------------------------
          // Get leap seconds information
          //-----------------------------
          long   leapFlag;
          String utcTimeBeforeLeap = new String();
          String utcTimeAfterLeap = new String();

          LeapSecond leap = timeCorr1.getLeapSecondInfo (XLCFI_ASCII_STD_REF_MICROSEC);
          if (leap.flag != 0)
          {
            System.out.println( "UTC time before leap second = " + leap.UtcTimeBeforeLeap );
            System.out.println( "UTC time after leap second = "  + leap.UtcTimeAfterLeap );
          }

          // -------------------------------------------------------------
          // Time Correlation initialization. Example 2: with fixed values
          // -------------------------------------------------------------

          System.out.println( "\n\nTimeCorrelation initialisation: fixed time correlations" );

          double[] initTime = new double[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 = new TimeCorrelation(initTime);

         // --------------------------------------------------------------
         // Time transformations examples
         // --------------------------------------------------------------

         long[]  transportTime = new long[4];

         Time time1 = new Time(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);

         System.out.println( "Input Time: Transport format XLCFI_TRANS_STD (TAI)" );
         System.out.println( "   time = ("
              + transportTime[0] + ", "
              + transportTime[1] + ", "
              + transportTime[2] + ", "
              + transportTime[3] + ", "
              + ")" );

         System.out.println( "Output Time: Processing format (TAI)" );
         System.out.println( "   time = " + time1.time ) );

         // Get the ASCII time
         String asciiTime = new String();
         asciiTime = time1.getAscii(XLCFI_TIME_GPS, XLCFI_ASCII_STD_REF_MICROSEC);

         System.out.println( "Output Time: ASCII format (GPS)" );
         System.out.println( "   time = " + asciiTime ) );

         // Get Transport format
         long[]  transportTime2 = new long[4];
         time1.getTransport(transportTime2, XLCFI_TIME_UTC, XLCFI_TRANS_CRYO_TM_SIRAL);
         System.out.println( "Output Time: CRYOSAT SIRAL transport format (UTC)" ) );
         System.out.println( "   time = ("
              + transportTime[0] + ", "
              + transportTime[1] + ", "
              + transportTime[2] + ", "
              + transportTime[3] + ", "
              + ")" );

         // Set the time to an ASCII date
         time1.setAscii(new String("2010-05-03_14:12:10"), XLCFI_TIME_TAI, XLCFI_ASCII_STD);

         System.out.println( "Input Time: ASCII format XLCFI_ASCII_STD (TAI)" );
         System.out.println( "   time = " + "2010-05-03_14:12:10" );
         System.out.println( "Output Time: Processing format (TAI)" );
         System.out.println( "   time = " + time1.time ) );

         // Get a new time value in a different time reference
         Time time2 = time1.getProcessing(XLCFI_TIME_UTC);
         System.out.println( "Output Time: Processing format (UTC)" );
         System.out.println( "   time = " + time2.time ) );

         // Change time2 to a new time reference
         time2.change(XLCFI_TIME_GPS);
         System.out.println( "Output Time: Processing format (GPS)" );
         System.out.println( "   time = " + time2.time ) );

         // ------------------------------------------------------------------------
         // Operation with Time objects
         // ------------------------------------------------------------------------

         System.out.println( "\nTime: Time operators" );

         time1 = Time(timeCorr2, 245.123456, XLCFI_TIME_TAI, XLCFI_PROC);
         time2.setProcessing(110.100001, XLCFI_TIME_TAI, XLCFI_PROC);

         Time time3 = new Time();

         time3 = time1.add(1.0);
         System.out.println( "Time1 = " + time1.time );
         System.out.println( "Time2 = " + time2.time );
         System.out.println( "Time1 + 1.0 =" + time3.time );
         System.out.println( "Time1 - Time2 =" + (time1-time2) );
         System.out.println( "Time1 - 1.0 =" + (time1-1.0).time );

         System.out.println( "Time1 > Time2 ? "  + (time1 > time2  ? "true" : "false") );
         System.out.println( "Time1 < Time2 ? "  + (time1 < time2  ? "true" : "false") );
         System.out.println( "Time1 >= Time2 ? " + (time1 >= time2 ? "true" : "false") );
         System.out.println( "Time1 <= Time2 ? " + (time1 <= time2 ? "true" : "false") );
         System.out.println( "Time1 == Time2 ? " + (time1 == time2 ? "true" : "false") );
         System.out.println( "Time1 != Time2 ? " + (time1 != time2 ? "true" : "false") );

        }//end try

        catch (CfiError cfiError)
        {
          //If an exception is thrown, there have been errors during execution
          Vector<String> errorMessages = new Vector<String>();

          // Get error messages
          errorMessages = cfiError.getMsg(errorMessages);

          // Pring Error messages
          for (int i = 0; i < errorMessages.size(); i++)
          {
            System.out.println( errorMessages.elementAt(i) );
          }
        }

      }

    }