File: fileTideGeneratingPotential.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 (99 lines) | stat: -rw-r--r-- 2,955 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
/***********************************************/
/**
* @file fileTideGeneratingPotential.cpp
*
* @brief Read/write tide genearting potential.
*
* @author Torsten Mayer-Guerr
* @date 2005-01-14
*
*/
/***********************************************/

#define DOCSTRING_FILEFORMAT_TideGeneratingPotential

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

GROOPS_REGISTER_FILEFORMAT(TideGeneratingPotential, FILE_TIDEGENERATINGPOTENTIAL_TYPE)

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

template<> void save(OutArchive &ar, const TideGeneratingPotential &x)
{
  const UInt constituentsCount = x.size();
  ar<<nameValue("constituentsCount", constituentsCount);
  ar.comment("Degree    Dood.    cos                       sin                      name");
  ar.comment("==========================================================================");
  for(UInt i=0; i<constituentsCount; i++)
  {
    std::string name = (x.at(i).name() != x.at(i).code()) ? x.at(i).name() : "";
    ar<<beginGroup("constituent");
    ar<<nameValue("degree",  x.at(i).degree);
    ar<<nameValue("doodson", *dynamic_cast<const Doodson*>(&x.at(i)));
    ar<<nameValue("c",       x.at(i).c);
    ar<<nameValue("s",       x.at(i).s);
    ar<<nameValue("name",    name);
    ar<<endGroup("constituent");
  }
}

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

template<> void load(InArchive &ar, TideGeneratingPotential &x)
{
  UInt constituentsCount;
  ar>>nameValue("constituentsCount", constituentsCount);
  x.resize(constituentsCount);
  for(UInt i=0; i<constituentsCount; i++)
  {
    ar>>beginGroup("constituent");
    UInt        degree = 2;
    Doodson     dood;
    Double      c, s;
    std::string name;
    if(ar.version() >= 20241108)
      ar>>nameValue("degree",  degree);
    ar>>nameValue("doodson", dood);
    ar>>nameValue("c",       c);
    ar>>nameValue("s",       s);
    ar>>nameValue("name",    name);
    x.at(i) = TideGeneratingConstituent(dood, degree, c, s);
    ar>>endGroup("constituent");
  }
}

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

void writeFileTideGeneratingPotential(const FileName &fileName, const TideGeneratingPotential &x)
{
  try
  {
    OutFileArchive file(fileName, FILE_TIDEGENERATINGPOTENTIAL_TYPE, FILE_TIDEGENERATINGPOTENTIAL_VERSION);
    file<<nameValue("tideGeneratingPotential", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

void readFileTideGeneratingPotential(const FileName &fileName, TideGeneratingPotential &x)
{
  try
  {
    InFileArchive file(fileName, FILE_TIDEGENERATINGPOTENTIAL_TYPE, FILE_TIDEGENERATINGPOTENTIAL_VERSION);
    file>>nameValue("tideGeneratingPotential", x);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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