File: goceXml2StarCamera.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 (114 lines) | stat: -rw-r--r-- 3,118 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
/***********************************************/
/**
* @file goceXml2StarCamera.cpp
*
* @brief Read ESA XML GOCE Data.
*
* @author Torsten Mayer-Guerr
* @date 2010-10-19
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Read ESA XML GOCE Data.
)";

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

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

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

/** @brief Read ESA XML GOCE Data.
* @ingroup programsConversionGroup */
class GoceXml2StarCamera
{
  void readFileGoceStarCamera(const FileName &fileName, StarCameraArc &arc);

public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(GoceXml2StarCamera, SINGLEPROCESS, "read ESA XML GOCE Data", Conversion, Instrument)

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

void GoceXml2StarCamera::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName outName;
    std::vector<FileName> fileName;

    readConfig(config, "outputfileStarCamera", outName, Config::MUSTSET,  "", "");
    readConfig(config, "inputfile", fileName, Config::MUSTSET,  "", "");
    if(isCreateSchema(config)) return;

    logStatus<<"read input files"<<Log::endl;
    StarCameraArc arc;
    for(UInt i=0; i<fileName.size(); i++)
    {
      logStatus<<"read file '"<<fileName.at(i)<<"'"<<Log::endl;
      readFileGoceStarCamera(fileName.at(i), arc);
    }

    // Daten speichern
    // ---------------
    logStatus<<"write gradiometer file <"<<outName<<">"<<Log::endl;
    std::list<Arc> arcList; arcList.push_back(arc);
    InstrumentFile::write(outName, arcList);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

void GoceXml2StarCamera::readFileGoceStarCamera(const FileName &fileName, StarCameraArc &arc)
{
  try
  {
    StarCameraEpoch epoch;

    InFile     file(fileName);
    XmlNodePtr rootNode = XmlNode::read(file);
    XmlNodePtr dataNode = getChild(rootNode, "Data_Block", TRUE);
    XmlNodePtr ggtNode  = getChild(dataNode, "EGG_IAQ_DS", TRUE);

    UInt epochCount = childCount(ggtNode, "EGG_IAQ_1i", TRUE);
    for(UInt i=0; i<epochCount; i++)
    {
      XmlNodePtr epochNode = getChild(ggtNode, "EGG_IAQ_1i", TRUE);
      Double t = 0;
      readXml(epochNode, "Tt_GPS", t, TRUE);
      epoch.time = seconds2time(t) + date2time(1980,1,6);

      XmlNodePtr tnsNode = getChild(epochNode, "Corr_Quat", TRUE);
      std::string tnsStr;
      readXml(tnsNode, "Q_Grad", tnsStr, TRUE);

      std::stringstream ss(tnsStr);
      Vector q(4);
      ss>>q(1)>>q(2)>>q(3)>>q(0);
      epoch.rotary = Rotary3d(q);

      if(arc.size() && (epoch.time <= arc.at(arc.size()-1).time))
        {logWarning<<"(epoch.time <= arc.at(arc.size()-1).time)"<<Log::endl; continue;}
      arc.push_back(epoch);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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