| 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 2 classes (Swath and SwathId) that provide 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 that 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.

The SwathId objects have to be constructed in the following way:

1. Construct the SwathInfo object. It can be done using:
   - STF or SDF file name.
   - A SdfFile object.
   - A StfFile object.
   Note: for SDF (file or object), the number of regeneration orbits must be provided.
2. Construct an AtmosId object
3. Construct the SwathId using the SwathInfo and the AtmosId objects.
4. The SwathId data can be modified using the method SwathId::setData

Once the objects are constructed, the following operations can be performed:

- Visibility calculations of zones and stations.
- Generate a STF from a SDF with Swath::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 Swath::getPosCompute method.

## Example

    // ------------------------------------------------------------------------
    //
    //                           JAVA Example Program.
    //                           SWATH CALCULATIONS
    //
    // ------------------------------------------------------------------------

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

        //-------------------------------------------------
        // 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 = new SatId(XPCFI_SAT_ENVISAT);

          ModelId          modelId = new ModelId(); //Do nothing: using default models.

          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)

          TimeCorrelation  timeId = new TimeCorrelation( initTime );

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

          double time0, time1;
          long orbit0, orbit1;

          Vector<String> inputFiles = new Vector<String>();

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

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

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

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

          Swath swathDef = new SwathDef( orbitId, 1, swathDefFile );

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

          long   requestedOrbit = 320;
          String dirName        = new String("./");
          String swathFile      = new String("STF_EXAMPLE.xml");
          String fileClass      = new String("TEST");
          String fhSystem       = new String("FHSystem_example");
          long   version        = 1;

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

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

          // Read SDF file

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

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

          // ------------------------------------------------------------------------
          // Get swath position: Swath::getPosCompute
          // ------------------------------------------------------------------------

          // input
          VisTime posTime = new VisTime();
          posTime.type     = XVCFI_ORBIT_TYPE;
          posTime.orbitNum = 501;
          posTime.sec      = 3600;
          posTime.msec     = 811000;

          AtmosId atmosId = new AtmosId();

          SwathInfo swathInfo = new SwathInfo();
          swathInfo.type = XVCFI_STF_DATA;
          swathInfo.stfFile = stfFile;
          SwathId swathId = new SwathId(atmosId, swathInfo);

          // Get position
          Vector<Geodetic> geoVector;

          geoVector = swathDef.getPosCompute( swathId, posTime );

          System.out.println( "Inputs for getPosCompute:" );
          System.out.println( "\tPosition for orbit " + posTime.orbit
               + " seconds "             + posTime.sec
               + " microseconds "        + posTime.msec );

          System.out.println( "Swath points:" );

          for (int i = 0 ; i < geoVector.size() ; i ++ )
          {
            System.out.println( "Point " + i + ": "
                 + "lon = " + geoVector.elementAt(i).lon
                 + "lat = " + geoVector.elementAt(i).lat
                 + "alt = " + geoVector.elementAt(i).alt );
          }

        }
        //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) );
          }
        }

      }

    }