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

# SWATH CALCULATIONS

A swath can be defined as the track swept by the field of view of an instrument in the satellite along a time interval. For the aim of this section this definition is enough, however the definition of a swath can be much more complex. For a detailed definition about swaths refer to [VISIB_SUM]. The Earth Observation CFI software can handle swath data using two different data sets provided by :

- Swath Definition files (SDF): they contain information about the swath type and geometry and the satellite attitude.
- Swath Template files (STF): they contain the list of longitude and latitude points of the swath if the orbit started at longitude and latitude 0.

This files are handle with the CFI classes StfFile and SdfFile in [D_H_SUM]. These classe are also explained in Working with Earth Observation CFI files. Moreover, the CFI Visibility library also contains a class Swath that provides more complex functionality. The Swath objects have to be constructed in the following way:

1. Construct the OrbitId object
2. Construct the Swath object with one of this options:
   - Class constructor with the OrbitId and the STF filename
   - Class constructor with the OrbitId, the SDF filename and a flag number (n>0). This number is used for other Swath methods to indicate that the Swath Template data has to be generated from the input SDF for every n orbits. (In other words, when the method required swath template data, that data will be valid along n orbits)
   - Empty constructor. In this case the Swath has to be initialised afterwards with a Swath::set method (there are two methods that corresponds to the other constructors)
3. It can be possible take into account the atmosphere refraction for the STF generation. In this case, if the SDF indicates the the atmosphere is USER_REF or PRED_REF, then the AtmosId has to be added to the Swath object using one of the Swath::set methods.

Once the object is constructed, the following operations can be performed:

- Visibility calculations of zones and stations.
- Generate a STF from a SDF with genSwath methods: The STF can be written to disk or keep in memory in a StfFile object.
- Calculating the swath position for a given ANXTime with getPos method.

## Example

    // ------------------------------------------------------------------------
    //
    //                           C++ Example Program.
    //                           SWATH CALCULATIONS
    //
    // ------------------------------------------------------------------------

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

    // EOCFI includes
    #include "DataHandlingData.h"
    #include "TimeCorrelation.h"
    #include "ModelId.h"
    #include "VisibilityData.h"
    #include "SatNomTransId.h"
    #include "SatTransId.h"
    #include "InstrTransId.h"
    #include "AtmosId.h"
    #include "Swath.h"
    #include "OrbitId.h"
    #include "DRS.h"
    #include "SatId.h"
    #include "StfFile.h"
    #include "SdfFile.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
      {
        // ------------------------------------------------------------------------
        // Satellite Id, ModelId and TimeCorrelatins initialization
        // ------------------------------------------------------------------------

        SatId satId(XPCFI_SAT_ENVISAT);

        ModelId          modelId; //Do nothing: using default models.

        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)

        TimeCorrelation  timeId( initTime );

        // ------------------------------------------------------------------------
        // Initialise orbit Id
        // ------------------------------------------------------------------------

        double time0, time1;
        long orbit0, orbit1;

        vector<string> inputFiles;

        long orbitMode    = XOCFI_ORBIT_INIT_OSF_MODE;
        long timeInitMode = XOCFI_SEL_FILE;
        long timeRef      = XOCFI_TIME_UTC;

        inputFiles.push_back( "./data/OSF.EEF" );

        OrbitId orbitId( satId, modelId, timeId, timeRef, orbitMode,
                         inputFiles, timeInitMode, time0, time1, orbit0, orbit1 );

        // ------------------------------------------------------------------------
        // Initialization of Swath object (With Swath Definition file)
        // ------------------------------------------------------------------------
        string swathDefFile = "./SDF_RA2.N1";

        Swath swathDef( orbitId, 1, swathDefFile );

        // ------------------------------------------------------------------------
        // Generate Swath Template file (1st Example)
        // ------------------------------------------------------------------------

        long   requestedOrbit = 320;
        string dirName        = "./";
        string swathFile      = "STF_EXAMPLE.xml";
        string fileClass      = "TEST";
        string fhSystem       = "FHSystem_example";
        long   version        = 1;

        swathDef.genSwath( requestedOrbit, dirName, swathFile,
                      fileClass, version, fhSystem );

        // ------------------------------------------------------------------------
        // Generate Swath Template file (2nd Example)
        // ------------------------------------------------------------------------

        // Read SDF file

        SdfFile sdfFile( swathDefFile );
        sdfFile.read();

        StfFile *stfFile;
        stfFile = swathDef.genSwath(requestedOrbit, sdfFile);

        // ------------------------------------------------------------------------
        // Get swath position: Swath::getPos
        // ------------------------------------------------------------------------

        // input
        ANXTime anxTime(501, 3600,811000);

        // Get position
        vector<Geodetic> geoVector;

        geoVector = swathDef.getPos( (*stfFile), anxTime );

        cout << "Inputs for getPos:" << endl;
        cout << "\tPosition for orbit " << anxTime.orbit
             << " seconds "             << anxTime.seconds
             << " microseconds "        << anxTime.microseconds << endl;

        cout << "Swath points:" << endl;

        for (long i = 0 ; i < geoVector.size() ; i ++ )
        {
          cout << "Point " << i << ": "
               << "lon = " << geoVector[i].lon
               << "lat = " << geoVector[i].lat
               << "alt = " << geoVector[i].alt << 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;

    }