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

# GENERATION OF EARTH OBSERVATION MISSION FILES

The Earth Observation CFI software contains a set of functions that generate the following orbit files:

- Orbit Scenario files
- Predicted Orbit files
- Restituted Orbit files (DORIS restituted and DORIS precise)
- DORIS Navigator files
- Orbit Event files

The calling sequence to generate those files is quite simple (see next figure):

- Initialise the time correlations (create TimeCorrelation object) and the ModelId if required. This step is not needed for the generation of orbit event files.

- Call one of the static methods for the file generation from the class OrbitFunc

- Optionally for the generation of OSFs: it is possible to add orbital changes within the OSF by calling one of these methods:
  - OrbitFunc::genOsfAppendOrbitChange
  - OrbitFunc::genOsfRepeatCycle
  - OrbitFunc::genOsfAddDriftCycle

## Example

Generation of an OSF and append one orbital change:

    // ------------------------------------------------------------------------
    //
    //                           C++ Example Program.
    //                           ORBIT FILES GENERATION
    //
    // ------------------------------------------------------------------------

    // Non-EOCFI include files
    #include <string>
    #include <vector>
    #include <iostream>

    // EOCFI includes
    #include "CfiError.h"
    #include "TimeCorrelation.h"
    #include "OrbitData.h"
    #include "OrbitFunc.h"
    #include "OrbitId.h"

    // Namespaces
    using namespace EECFI;
    using namespace std;

    // Main program
    int main (int argc, char *argv[])
    {

      //-------------------------------------------------
      // Put all the code inside try-catch statements
      //  so, if something fails, an exception is thrown
      //-------------------------------------------------
      try
      {
        ModelId  modelId;

        // Initializing Time Reference: Used for the first and second example
        double coorTime[4];

        coorTime[0]   = -1100.1000000000000;   // TAI time [days]
        coorTime[1]   = -1100.0995949074074;   // UTC time [days] (= TAI + 35.0 s)
        coorTime[2]   = -1100.0995914351852;   // UT1 time [days] (= TAI + 35.3 s)
        coorTime[3]   = -1100.099780092;       // GPS time [days] (= TAI + 19.0 s)

        TimeCorrelation timeCorr(coorTime);

        // ------------------------------------------------------------------------
        // Create OSF file.
        //-------------------------------------------------------------------------
        string outputDir = "./";
        string osfFile   = "OSF_FILE.xml";
        string fileClass = "EXAMPLE";
        string fhSystem  = "CFI_example";
        SatId  satId     = XOCFI_SAT_CRYOSAT;

        long   absOrbit      = 1;
        long   cycle         = 1;
        long   phase         = 1;
        long   versionNumber = 1;
        long   repeatCycle   = 369;
        long   cycleLength   = 5344;
        long   driftMode     = XOCFI_NOSUNSYNC_DRIFT;
        double mlstDrift     = -179.208556;
        double mlst          = 12.0;
        double anxLong       = 37.684960;

        double date          = 1643.395;

        double inclination;

        string outFile; // Name of the file created

        // With OrbitFunc class
        outFile = OrbitFunc::genOsf (satId,
                                     modelId,
                                     timeCorr,
                                     absOrbit,
                                     cycle,
                                     phase,
                                     repeatCycle,
                                     cycleLength,
                                     anxLong,
                                     driftMode,
                                     inclination,
                                     mlstDrift,
                                     mlst,
                                     date,
                                     outputDir,
                                     osfFile,
                                     fileClass,
                                     versionNumber,
                                     fhSystem);

        cout << endl << "File " << outFile << " created " << endl;

        // ------------------------------------------------------------------------
        // Append orbit change to OSF file.
        //-------------------------------------------------------------------------
        string outputFile     = "OSF_FILE_APPEND.xml";
        double oldNodalPeriod = 86400.0 * (1+mlstDrift/86400.0) *
                                (double)repeatCycle/(double)cycleLength;

        long   phaseInc       = XOCFI_NO_PHASE_INCREMENT;

        versionNumber++;
        absOrbit    = 5345;
        repeatCycle = 369;
        cycleLength = 5344;

        // small change wrt to nominal to check tolerances
        anxLong = 37.68497;
        mlst = mlst + mlstDrift*(5345-1)*oldNodalPeriod/(3600.0*86400.0) + 24.0;

        outFile = OrbitFunc::genOsfAppendOrbitChange( satId,
                                                      modelId,
                                                      timeCorr,
                                                      osfFile,
                                                      absOrbit,
                                                      repeatCycle,
                                                      cycleLength,
                                                      anxLong,
                                                      driftMode,
                                                      inclination,
                                                      mlstDrift,
                                                      mlst,
                                                      phaseInc,
                                                      outputDir,
                                                      outputFile,
                                                      fileClass,
                                                      versionNumber,
                                                      fhSystem );

        cout << endl << "File " << outFile << " created " << endl;

        // ------------------------------------------------------------------------
        // Change repeat cycle to OSF file.
        //-------------------------------------------------------------------------
        outputFile  = "OSF_FILE_CHANGE.xml";
        absOrbit    = 5000;
        phaseInc    = XOCFI_PHASE_INCREMENT;
        repeatCycle = 2;
        cycleLength = 29;
        anxLong     = 37.68497;
        driftMode   = XOCFI_NOSUNSYNC_INCLINATION;
        inclination = 92.0;

        versionNumber++;

        long searchDirection = XOCFI_SEARCH_FORWARD;

        outFile = OrbitFunc::genOsfChangeRepeatCycle( satId,
                                                      modelId,
                                                      timeCorr,
                                                      osfFile,
                                                      absOrbit,
                                                      searchDirection,
                                                      repeatCycle,
                                                      cycleLength,
                                                      anxLong,
                                                      driftMode,
                                                      inclination,
                                                      mlstDrift,
                                                      phaseInc,
                                                      outputDir,
                                                      outputFile,
                                                      fileClass,
                                                      versionNumber,
                                                      fhSystem );
        cout << endl << "File " << outFile << " created " << 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;

    }