File: ephemerides.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 (120 lines) | stat: -rw-r--r-- 4,048 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
/***********************************************/
/**
* @file ephemerides.cpp
*
* @brief Ephemerides of Sun, Moon and planets.
*
* @author Torsten Mayer-Guerr
* @date 2020-06-07
*
*/
/***********************************************/

#define DOCSTRING_Ephemerides
#define DOCSTRING_EphemeridesPlanet

#include "base/import.h"
#include "config/configRegister.h"
#include "classes/ephemerides/ephemeridesJpl.h"
#include "classes/ephemerides/ephemerides.h"

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

GROOPS_REGISTER_CLASS(Ephemerides, "ephemeridesType",
                      EphemeridesJpl)

GROOPS_READCONFIG_CLASS(Ephemerides, "ephemeridesType")

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

EphemeridesPtr Ephemerides::create(Config &config, const std::string &name)
{
  try
  {
    EphemeridesPtr ptr;
    std::string    type;

    readConfigChoice(config, name, type, Config::MUSTSET, "", "ephemerides of Sun, Moon and planets");
    if(readConfigChoiceElement(config, "jpl", type, ""))
      ptr = std::make_shared<EphemeridesJpl>(config);
    endChoice(config);

    return ptr;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

// Wrapper class
class EphemeridesPlanet
{
public:
  Ephemerides::Planet planet;
  EphemeridesPlanet(Config &config, const std::string &name);
  static EphemeridesPlanet create(Config &config, const std::string &name) {return EphemeridesPlanet(config, name);}
};

GROOPS_REGISTER_CLASS_WITHOUT_SUBS(EphemeridesPlanet, "planetType")

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

template<> Bool readConfig(Config &config, const std::string &name, Ephemerides::Planet &var, Config::Appearance mustSet, const std::string &defaultValue, const std::string &annotation)
{
  try
  {
    if(isCreateSchema(config))
    {
      config.xselement(name, "planetType", mustSet, Config::ONCE, defaultValue, annotation);
      return FALSE;
    }

    if(!hasName(config, name, mustSet))
      return FALSE;
    EphemeridesPlanet tmp(config, name);
    var = tmp.planet;
    return TRUE;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

EphemeridesPlanet::EphemeridesPlanet(Config &config, const std::string &name)
{
  try
  {
    planet = Ephemerides::EARTH;
    std::string choice;

    readConfigChoice(config, name, choice, Config::MUSTSET, "", "planet");
    if(readConfigChoiceElement(config, "earth",               choice, "")) planet = Ephemerides::EARTH;
    if(readConfigChoiceElement(config, "sun",                 choice, "")) planet = Ephemerides::SUN;
    if(readConfigChoiceElement(config, "moon",                choice, "")) planet = Ephemerides::MOON;
    if(readConfigChoiceElement(config, "mercury",             choice, "")) planet = Ephemerides::MERCURY;
    if(readConfigChoiceElement(config, "venus",               choice, "")) planet = Ephemerides::VENUS;
    if(readConfigChoiceElement(config, "mars",                choice, "")) planet = Ephemerides::MARS;
    if(readConfigChoiceElement(config, "jupiter",             choice, "")) planet = Ephemerides::JUPITER;
    if(readConfigChoiceElement(config, "saturn",              choice, "")) planet = Ephemerides::SATURN;
    if(readConfigChoiceElement(config, "uranus",              choice, "")) planet = Ephemerides::URANUS;
    if(readConfigChoiceElement(config, "neptune",             choice, "")) planet = Ephemerides::NEPTUNE;
    if(readConfigChoiceElement(config, "pluto",               choice, "")) planet = Ephemerides::PLUTO;
    if(readConfigChoiceElement(config, "solarBaryCenter",     choice, "")) planet = Ephemerides::SOLARBARYCENTER;
    if(readConfigChoiceElement(config, "earthMoonBaryCenter", choice, "")) planet = Ephemerides::EARTHMOONBARYCENTER;
    endChoice(config);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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