File: sentinel2Orbit.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (129 lines) | stat: -rw-r--r-- 4,077 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/***********************************************/
/**
* @file sentinel2orbit.cpp
*
* @brief Read Sentinel orbits from XML format.
*
* @author Barbara Suesser-Rechberger
* @date 2019-11-25
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Read Sentinel orbits from XML format.
)";

/***********************************************/

#include "programs/program.h"
#include "parser/xml.h"
#include "files/fileInstrument.h"
#include "classes/earthRotation/earthRotation.h"


/***** CLASS ***********************************/

/** @brief Read XML Sentinel Data.
* @ingroup programsConversionGroup */
class SentinelXml2Orbit
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(SentinelXml2Orbit, SINGLEPROCESS, "read XML Sentinel Data", Conversion, Orbit, Instrument)

/***********************************************/

void SentinelXml2Orbit::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName              fileNameOrbit;
    std::vector<FileName> fileNamesIn;
    EarthRotationPtr      earthRotation;

    readConfig(config, "outputfileOrbit", fileNameOrbit, Config::MUSTSET,  "", "");
    readConfig(config, "earthRotation",   earthRotation, Config::MUSTSET,  "", "");
    readConfig(config, "inputfile",       fileNamesIn,   Config::MUSTSET,  "", "");
    if(isCreateSchema(config)) return;

    logStatus<<"read input files"<<Log::endl;
    OrbitArc orbit;
    for(const auto &fileName : fileNamesIn)
    {
      try
      {
        logStatus<<"read file <"<<fileName<<">"<<Log::endl;
        InFile file(fileName);
        XmlNodePtr rootNode    = XmlNode::read(file);
        XmlNodePtr dataNode    = getChild(rootNode, "Data_Block",   TRUE);
        XmlNodePtr osvListNode = getChild(dataNode, "List_of_OSVs", TRUE);

        const UInt epochCount = childCount(osvListNode, "OSV", TRUE);
        for(UInt i=0; i<epochCount; i++)
        {
          XmlNodePtr epochNode = getChild(osvListNode, "OSV", TRUE);

          // Read UTC string and convert it into modified julian date and then into GPS time
          std::string timeUTC;
          Char   tmp;
          UInt   year, month, day, hour, minute;
          Double second;
          readXml(epochNode, "UTC", timeUTC, TRUE);
          std::stringstream ss(timeUTC.substr(4));
          ss>>year>>tmp>>month>>tmp>>day>>tmp>>hour>>tmp>>minute>>tmp>>second;

          OrbitEpoch epoch;
          epoch.time = timeUTC2GPS(date2time(year, month, day, hour, minute, second));

          // position coordinates
          readXml(epochNode, "X", epoch.position.x(), TRUE);
          readXml(epochNode, "Y", epoch.position.y(), TRUE);
          readXml(epochNode, "Z", epoch.position.z(), TRUE);

          // Velocity coordinates
          readXml(epochNode, "VX", epoch.velocity.x(), TRUE);
          readXml(epochNode, "VY", epoch.velocity.y(), TRUE);
          readXml(epochNode, "VZ", epoch.velocity.z(), TRUE);

          orbit.push_back(epoch);
        }
      }
      catch(std::exception &e)
      {
        logError<<e.what()<<": continue..."<<Log::endl;
      }
    }

    // Rotation TRF -> CRF
    // -------------------
    if(earthRotation)
    {
      logStatus<<"rotation from TRF to CRF"<<Log::endl;
      Single::forEach(orbit.size(), [&](UInt i)
      {
        const Rotary3d rotation = inverse(earthRotation->rotaryMatrix(orbit.at(i).time));
        orbit.at(i).position    = rotation.rotate(orbit.at(i).position);
        if(orbit.at(i).velocity.r() > 0)
          orbit.at(i).velocity = rotation.rotate(orbit.at(i).velocity) + crossProduct(earthRotation->rotaryAxis(orbit.at(i).time), orbit.at(i).position);
      });
    }

    if(!fileNameOrbit.empty())
    {
      logInfo<<"write data to <"<<fileNameOrbit<<">"<<Log::endl;
      InstrumentFile::write(fileNameOrbit, orbit);
      Arc::printStatistics(orbit);
    }
  }
  catch (std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/