File: iers2OceanPoleTide.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 (114 lines) | stat: -rw-r--r-- 4,157 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
/***********************************************/
/**
* @file iers2OceanPoleTide.cpp
*
* @brief Read Ocean pole tide model.
*
* @author Torsten Mayer-Guerr
* @date 2007-04-08
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Read ocean pole tide model according to IERS conventions
and convert into \file{oceanPoleTide file}{oceanPoleTide}.
)";

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

#include "programs/program.h"
#include "inputOutput/file.h"
#include "files/fileOceanPoleTide.h"
#include "files/fileMatrix.h"

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

/** @brief Read ocean pole tide model.
* @ingroup programsConversionGroup */
class Iers2OceanPoleTide
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(Iers2OceanPoleTide, SINGLEPROCESS, "Read ocean pole tide model", Conversion)

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

void Iers2OceanPoleTide::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName outputName, inputName, loveNumberName;
    Double GM, R, Omega;
    Double rho, G, g;
    UInt   maxDegree;

    readConfig(config, "outputfileOceanPole",        outputName,     Config::MUSTSET, "",                "");
    readConfig(config, "inputfile",                  inputName,      Config::MUSTSET, "",                "");
    readConfig(config, "inputfileLoadingLoveNumber", loveNumberName, Config::MUSTSET, "{groopsDataDir}/loading/loadLoveNumbers_Gegout97.txt", "");
    readConfig(config, "maxDegree",                  maxDegree,      Config::MUSTSET, "",                "");
    readConfig(config, "GM",                         GM,             Config::DEFAULT, STRING_DEFAULT_GM, "Geocentric gravitational constant");
    readConfig(config, "R",                          R,              Config::DEFAULT, STRING_DEFAULT_R,  "Reference radius");
    readConfig(config, "Omega",                      Omega,          Config::DEFAULT, "7.292115e-05",    "[rad/s] earth rotation");
    readConfig(config, "rho",                        rho,            Config::DEFAULT, "1025",            "[kg/m**3] density of sea water");
    readConfig(config, "G",                          G,              Config::DEFAULT, "6.673e-11",       "[m**3/(kg*s**2)] gravitational constant");
    readConfig(config, "g",                          g,              Config::DEFAULT, "9.7803278",       "[m/s**2] gravity");
    if(isCreateSchema(config)) return;

    // Loading Love Numbers
    // --------------------
    Vector kn;
    readFileMatrix(loveNumberName, kn);

    // read potential coefficients
    // ---------------------------
    logStatus<<"read file <"<<inputName<<">"<<Log::endl;
    Matrix cnmReal(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix snmReal(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix cnmImag(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix snmImag(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    {
      InFile file(inputName);
      std::string line;
      std::getline(file, line); // read header
      while(file.good())
      {
        std::getline(file, line);
        if(line.empty())
          continue;
        std::stringstream ss(line);
        ss.exceptions(std::ios::badbit | std::ios::failbit);
        UInt n,m;
        ss>>n>>m;
        if(n<=maxDegree)
          ss>>cnmReal(n,m)>>snmReal(n,m)>>cnmImag(n,m)>>snmImag(n,m);
      }
    }

    // apply factors
    // -------------
    for(UInt n=0; n<=maxDegree; n++)
    {
      const Double f = pow(Omega,2)*pow(R,4)*4*PI*G*rho/GM/g * (1.+kn(n))/(2.*n+1.);
      cnmReal.row(n) *= f;
      snmReal.row(n) *= f;
      cnmImag.row(n) *= f;
      snmImag.row(n) *= f;
    }

    // write result
    // ------------
    logStatus<<"write ocean pole tide <"<<outputName<<">"<<Log::endl;
    writeFileOceanPoleTide(outputName, SphericalHarmonics(GM, R, cnmReal, snmReal), SphericalHarmonics(GM, R, cnmImag, snmImag));
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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