File: fileDoodsonHarmonic.cpp

package info (click to toggle)
groops 0%2Bgit20240830%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 11,052 kB
  • sloc: cpp: 134,939; fortran: 1,569; makefile: 20
file content (101 lines) | stat: -rw-r--r-- 2,501 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
/***********************************************/
/**
* @file fileDoodsonHarmonic.cpp
*
* @brief Read/write harmonics coded with doodson frequencies.
*
* @author Torsten Mayer-Guerr
* @date 2010-06-10
*
*/
/***********************************************/

#define DOCSTRING_FILEFORMAT_DoodsonHarmonic

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

GROOPS_REGISTER_FILEFORMAT(DoodsonHarmonic, FILE_DOODSONHARMONIC_TYPE)

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

template<> void save(OutArchive &ar, const DoodsonHarmonic &x)
{
  UInt count = x.doodson.size();
  ar<<nameValue("GM", x.GM);
  ar<<nameValue("R",  x.R);
  ar<<nameValue("constituentsCount", count);
  for(UInt i=0; i<count; i++)
  {
    ar<<beginGroup("constituent");
    ar<<nameValue("doodson", x.doodson.at(i));
    ar<<nameValue("cnmCos",  x.cnmCos.at(i));
    ar<<nameValue("snmCos",  x.snmCos.at(i));
    ar<<nameValue("cnmSin",  x.cnmSin.at(i));
    ar<<nameValue("snmSin",  x.snmSin.at(i));
    ar<<endGroup("constituent");
  }
}

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

template<> void load(InArchive &ar, DoodsonHarmonic &x)
{
  UInt count;

  ar>>nameValue("GM", x.GM);
  ar>>nameValue("R",  x.R);
  ar>>nameValue("constituentsCount", count);

  x.doodson.resize(count);
  x.cnmCos.resize(count);
  x.cnmSin.resize(count);
  x.snmCos.resize(count);
  x.snmSin.resize(count);

  for(UInt i=0; i<count; i++)
  {
    ar>>beginGroup("constituent");
    ar>>nameValue("doodson", x.doodson.at(i));
    ar>>nameValue("cnmCos",  x.cnmCos.at(i));
    ar>>nameValue("snmCos",  x.snmCos.at(i));
    ar>>nameValue("cnmSin",  x.cnmSin.at(i));
    ar>>nameValue("snmSin",  x.snmSin.at(i));
    ar>>endGroup("constituent");
  }
}

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

void writeFileDoodsonHarmonic(const FileName &fileName, const DoodsonHarmonic &x)
{
  try
  {
    OutFileArchive file(fileName, FILE_DOODSONHARMONIC_TYPE);
    file<<nameValue("doodsonHarmonic", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

void readFileDoodsonHarmonic(const FileName &fileName, DoodsonHarmonic &x)
{
  try
  {
    InFileArchive file(fileName, FILE_DOODSONHARMONIC_TYPE);
    file>>nameValue("doodsonHarmonic", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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