File: sacc2Orbit.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 (100 lines) | stat: -rw-r--r-- 2,658 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
/***********************************************/
/**
* @file sacc2Orbit.cpp
*
* @brief read SACC orbit data.
*
* @author Norbert Zehentner
* @date 2014-08-22
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program reads in SACC orbit data.
)";

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

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

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

/** @brief read SACC orbit data.
* @ingroup programsConversionGroup */
class Sacc2Orbit
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(Sacc2Orbit, SINGLEPROCESS, "read SACC orbit data", Conversion, Orbit, Instrument)

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

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

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

    logStatus<<"read input files"<<Log::endl;
    OrbitArc arc;
    for(const auto &fileName : fileNamesIn)
    {
      try
      {
        logStatus<<"read file <"<<fileName<<">"<<Log::endl;
        InFile file(fileName);

        std::string line;
        while(std::getline(file, line))
        {
          if(line.empty())
            continue;
          std::stringstream ss(line);
          ss.exceptions(std::ios::badbit | std::ios::failbit);

          UInt       id, year, month, day, hour, minute;
          Double     second;
          OrbitEpoch epoch;

          ss>>id>>year>>month>>day>>hour>>minute>>second;
          ss>>epoch.position.x()>>epoch.position.y()>>epoch.position.z();
          ss>>epoch.velocity.x()>>epoch.velocity.y()>>epoch.velocity.z();

          epoch.time = timeUTC2GPS(date2time(year, month, day, hour, minute, second));
          epoch.position *= 1000; // km => m
          epoch.velocity *= 1000; // km/s => m/s
          arc.push_back(epoch);
        } // while(getline)
      }
      catch(std::exception &e)
      {
        logError<<e.what()<<": continue..."<<Log::endl;
      }
    } // for(idFile)

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

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