File: fileMeanPolarMotion.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 (143 lines) | stat: -rw-r--r-- 4,085 bytes parent folder | download
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/***********************************************/
/**
* @file fileMeanPolarMotion.cpp
*
* @brief Read/write MeanPolarMotion.
*
* @author Torsten Mayer-Guerr
* @date 2017-12-09
*
*/
/***********************************************/

#define DOCSTRING_FILEFORMAT_MeanPolarMotion

#include "base/import.h"
#include "inputOutput/fileArchive.h"
#include "files/fileFormatRegister.h"
#include "files/fileMeanPolarMotion.h"

GROOPS_REGISTER_FILEFORMAT(MeanPolarMotion, FILE_MEANPOLARMOTION_TYPE)

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

void MeanPolarMotion::compute(const Time &time, Double &xBar, Double &yBar) const
{
  try
  {
    xBar = 0;
    yBar = 0;
    if(timeStart.size() == 0)
      return;

    // find correct interval
    if(time<timeStart.at(0))
      throw(Exception("mean pole model is not valid before "+timeStart.at(0).dateTimeStr()));
    UInt idxInterval = 0;
    while((idxInterval+1 < timeStart.size()) && (time >= timeStart.at(idxInterval+1)))
      idxInterval++;

    // mean pole (IERS2010, eq. (7.25))
    Double tn   = 1;
    const Double t = (time.mjd()-J2000)/365.25; // years after J2000
    for(UInt n=0; n<=degree.at(idxInterval); n++)
    {
      xBar += tn * xp.at(idxInterval)(n);
      yBar += tn * yp.at(idxInterval)(n);
      tn *= t;
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

template<> void save(OutArchive &ar, const MeanPolarMotion &x)
{
  const UInt intervalCount = x.timeStart.size();
  ar<<nameValue("intervalCount", intervalCount);
  if(!intervalCount)
    return;

  //comment
  const UInt maxDegree = *std::max_element(x.degree.begin(), x.degree.end());
  std::string str = "start time [MJD]            degree";
  for(UInt n=0; n<=maxDegree; n++)
    str += "  xp [arcsec/year^"+n%"%i"s+"]      ";
  for(UInt n=0; n<=maxDegree; n++)
    str += "  yp [arcsec/year^"+n%"%i"s+"]      ";
  ar.comment(str);
  ar.comment(std::string(str.size(), '='));

  for(UInt idxInterval=0; idxInterval<intervalCount; idxInterval++)
  {
    ar<<beginGroup("interval");
    ar<<nameValue("timeStart", x.timeStart.at(idxInterval));
    ar<<nameValue("degree",    x.degree.at(idxInterval));
    for(UInt n=0; n<=x.degree.at(idxInterval); n++)
      ar<<nameValue("xp", x.xp.at(idxInterval)(n));
    for(UInt n=0; n<=x.degree.at(idxInterval); n++)
      ar<<nameValue("yp", x.yp.at(idxInterval)(n));
    ar<<endGroup("interval");
  }
}

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

template<> void load(InArchive &ar, MeanPolarMotion &x)
{
  UInt intervalCount;
  ar>>nameValue("intervalCount", intervalCount);
  x.timeStart.resize(intervalCount);
  x.degree.resize(intervalCount);
  x.xp.resize(intervalCount);
  x.yp.resize(intervalCount);
  for(UInt idxInterval=0; idxInterval<intervalCount; idxInterval++)
  {
    ar>>beginGroup("interval");
    ar>>nameValue("timeStart", x.timeStart.at(idxInterval));
    ar>>nameValue("degree",    x.degree.at(idxInterval));
    x.xp.at(idxInterval) = Vector(x.degree.at(idxInterval)+1);
    x.yp.at(idxInterval) = Vector(x.degree.at(idxInterval)+1);
    for(UInt n=0; n<=x.degree.at(idxInterval); n++)
      ar>>nameValue("xp", x.xp.at(idxInterval)(n));
    for(UInt n=0; n<=x.degree.at(idxInterval); n++)
      ar>>nameValue("yp", x.yp.at(idxInterval)(n));
    ar>>endGroup("interval");
  }
}

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

void writeFileMeanPolarMotion(const FileName &fileName, const MeanPolarMotion &x)
{
  try
  {
    OutFileArchive file(fileName, FILE_MEANPOLARMOTION_TYPE, FILE_MEANPOLARMOTION_VERSION);
    file<<nameValue("meanPolarMotion", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

void readFileMeanPolarMotion(const FileName &fileName, MeanPolarMotion &x)
{
  try
  {
    InFileArchive file(fileName, FILE_MEANPOLARMOTION_TYPE, FILE_MEANPOLARMOTION_VERSION);
    file>>nameValue("meanPolarMotion", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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