File: fileEarthTide.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 (283 lines) | stat: -rw-r--r-- 9,959 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/***********************************************/
/**
* @file fileEarthTide.cpp
*
* @brief Read/write EarthTide.
*
* @author Torsten Mayer-Guerr
* @date 2017-12-09
*
*/
/***********************************************/

#define DOCSTRING_FILEFORMAT_EarthTide

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

GROOPS_REGISTER_FILEFORMAT(EarthTide, FILE_EARTHTIDE_TYPE)

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

void readFileEarthTide(const FileName &fileName,
                       Matrix &kReal, Matrix &kImag, Matrix &kPlus,
                       Matrix &doodson20, Matrix &doodson21, Matrix &doodson22,
                       Vector &ampIp20, Vector &ampOp20, Vector &ampIp21, Vector &ampOp21, Vector &amp22,
                       Double &h2_0, Double &h2_2,
                       Double &l2_0, Double &l2_2, Double &l21_1, Double &l22_1,
                       Double &h21_imag, Double &l21_imag, Double &h22_imag, Double &l22_imag,
                       Double &h3, Double &l3,
                       Matrix &deformationArg21, Matrix &deformationArg20,
                       Vector &dR21_ip, Vector &dR21_op, Vector &dR20_ip, Vector &dR20_op,
                       Vector &dT21_ip, Vector &dT21_op, Vector &dT20_ip, Vector &dT20_op)
{
  try
  {
    UInt count;
    std::vector<Doodson> doodson;

    InFileArchive file(fileName, FILE_EARTHTIDE_TYPE, FILE_EARTHTIDE_VERSION);

    file>>beginGroup("loveNumber");
    file>>nameValue("kReal", kReal);
    file>>nameValue("kImag", kImag);
    file>>nameValue("kPlus", kPlus);
    file>>endGroup("loveNumber");

    file>>beginGroup("longPeriodic");
    file>>nameValue("count", count);
    doodson.resize(count);
    ampIp20   = Vector(count);
    ampOp20   = Vector(count);
    for(UInt i=0; i<count; i++)
    {
      file>>beginGroup("constituent");
      file>>nameValue("doodson", doodson.at(i));
      file>>nameValue("ampInPhase",  ampIp20(i));
      file>>nameValue("ampOutPhase", ampOp20(i));
      file>>endGroup("constituent");
    }
    doodson20 = Doodson::matrix(doodson);
    file>>endGroup("longPeriodic");

    file>>beginGroup("diurnal");
    file>>nameValue("count", count);
    doodson.resize(count);
    ampIp21   = Vector(count);
    ampOp21   = Vector(count);
    for(UInt i=0; i<count; i++)
    {
      file>>beginGroup("constituent");
      file>>nameValue("doodson", doodson.at(i));
      file>>nameValue("ampInPhase",  ampIp21(i));
      file>>nameValue("ampOutPhase", ampOp21(i));
      file>>endGroup("constituent");
    }
    doodson21 = Doodson::matrix(doodson);
    file>>endGroup("diurnal");

    file>>beginGroup("semidiurnal");
    file>>nameValue("count", count);
    doodson.resize(count);
    amp22 = Vector(count);
    for(UInt i=0; i<count; i++)
    {
      file>>beginGroup("constituent");
      file>>nameValue("doodson", doodson.at(i));
      file>>nameValue("ampInPhase",  amp22(i));
      file>>endGroup("constituent");
    }
    doodson22 = Doodson::matrix(doodson);
    file>>endGroup("semidiurnal");

    // read displacement values
    file>>beginGroup("displacement");
    file>>nameValue("h2_0",     h2_0);
    file>>nameValue("h2_2",     h2_2);
    file>>nameValue("l2_0",     l2_0);
    file>>nameValue("l2_2",     l2_2);
    file>>nameValue("h3",       h3);
    file>>nameValue("l3",       l3);
    file>>nameValue("h21_imag", h21_imag);
    file>>nameValue("l21_imag", l21_imag);
    file>>nameValue("h22_imag", h22_imag);
    file>>nameValue("l22_imag", l22_imag);
    file>>nameValue("l21_1",    l21_1);
    file>>nameValue("l22_1",    l22_1);

    file>>beginGroup("longPeriodic");
    file>>nameValue("count", count);
    doodson.resize(count);
    dR20_ip = Vector(count);
    dR20_op = Vector(count);
    dT20_ip = Vector(count);
    dT20_op = Vector(count);
    for(UInt i=0; i<count; i++)
    {
      file>>beginGroup("constituent");
      file>>nameValue("doodson", doodson.at(i));
      file>>nameValue("dRInPhase",  dR20_ip(i));
      file>>nameValue("dROutPhase", dR20_op(i));
      file>>nameValue("dTInPhase",  dT20_ip(i));
      file>>nameValue("dTOutPhase", dT20_op(i));
      file>>endGroup("constituent");
    }
    deformationArg20 = Doodson::matrix(doodson);
    file>>endGroup("longPeriodic");

    file>>beginGroup("diurnal");
    file>>nameValue("count", count);
    doodson.resize(count);
    dR21_ip = Vector(count);
    dR21_op = Vector(count);
    dT21_ip = Vector(count);
    dT21_op = Vector(count);
    for(UInt i=0; i<count; i++)
    {
      file>>beginGroup("constituent");
      file>>nameValue("doodson", doodson.at(i));
      file>>nameValue("dRInPhase",  dR21_ip(i));
      file>>nameValue("dROutPhase", dR21_op(i));
      file>>nameValue("dTInPhase",  dT21_ip(i));
      file>>nameValue("dTOutPhase", dT21_op(i));
      file>>endGroup("constituent");
    }
    deformationArg21 = Doodson::matrix(doodson);
    file>>endGroup("diurnal");

    file>>endGroup("displacement");
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

void writeFileEarthTide(const FileName &fileName,
                        const_MatrixSliceRef kReal, const_MatrixSliceRef kImag, const_MatrixSliceRef kPlus,
                        const_MatrixSliceRef doodson20, const_MatrixSliceRef doodson21, const_MatrixSliceRef doodson22,
                        const_MatrixSliceRef ampIp20, const_MatrixSliceRef ampOp20, const_MatrixSliceRef ampIp21, const_MatrixSliceRef ampOp21, const_MatrixSliceRef amp22,
                        Double h2_0, Double h2_2,
                        Double l2_0, Double l2_2, Double l21_1, Double l22_1,
                        Double h21_imag, Double l21_imag, Double h22_imag, Double l22_imag,
                        Double h3, Double l3,
                        const_MatrixSliceRef deformationArg21, const_MatrixSliceRef deformationArg20,
                        const_MatrixSliceRef dR21_ip, const_MatrixSliceRef dR21_op, const_MatrixSliceRef dR20_ip, const_MatrixSliceRef dR20_op,
                        const_MatrixSliceRef dT21_ip, const_MatrixSliceRef dT21_op, const_MatrixSliceRef dT20_ip, const_MatrixSliceRef dT20_op)
{
  try
  {
    OutFileArchive file(fileName, FILE_EARTHTIDE_TYPE, FILE_EARTHTIDE_VERSION);

    file<<beginGroup("loveNumber");
    file<<nameValue("kReal", kReal);
    file<<nameValue("kImag", kImag);
    file<<nameValue("kPlus", kPlus);
    file<<endGroup("loveNumber");

    file<<beginGroup("longPeriodic");
    file<<nameValue("count", doodson20.rows());
    for(UInt i=0; i<doodson20.rows(); i++)
    {
      Doodson doodson;
      for(UInt k=0; k<6; k++)
        doodson.d[k] = static_cast<Int>(doodson20(i, k));
      file<<beginGroup("constituent");
      file<<nameValue("doodson",     doodson);
      file<<nameValue("ampInPhase",  ampIp20(i,0));
      file<<nameValue("ampOutPhase", ampOp20(i,0));
      file<<endGroup("constituent");
    }
    file<<endGroup("longPeriodic");

    file<<beginGroup("diurnal");
    file<<nameValue("count", doodson21.rows());
    for(UInt i=0; i<doodson21.rows(); i++)
    {
      Doodson doodson;
      for(UInt k=0; k<6; k++)
        doodson.d[k] = static_cast<Int>(doodson21(i, k));
      file<<beginGroup("constituent");
      file<<nameValue("doodson",     doodson);
      file<<nameValue("ampInPhase",  ampIp21(i,0));
      file<<nameValue("ampOutPhase", ampOp21(i,0));
      file<<endGroup("constituent");
    }
    file<<endGroup("diurnal");

    file<<beginGroup("semidiurnal");
    file<<nameValue("count", doodson22.rows());
    for(UInt i=0; i<doodson22.rows(); i++)
    {
      Doodson doodson;
      for(UInt k=0; k<6; k++)
        doodson.d[k] = static_cast<Int>(doodson22(i, k));
      file<<beginGroup("constituent");
      file<<nameValue("doodson",    doodson);
      file<<nameValue("ampInPhase", amp22(i,0));
      file<<endGroup("constituent");
    }
    file<<endGroup("semidiurnal");

    // read displacement values
    file<<beginGroup("displacement");
    file<<nameValue("h2_0",     h2_0);
    file<<nameValue("h2_2",     h2_2);
    file<<nameValue("l2_0",     l2_0);
    file<<nameValue("l2_2",     l2_2);
    file<<nameValue("h3",       h3);
    file<<nameValue("l3",       l3);
    file<<nameValue("h21_imag", h21_imag);
    file<<nameValue("l21_imag", l21_imag);
    file<<nameValue("h22_imag", h22_imag);
    file<<nameValue("l22_imag", l22_imag);
    file<<nameValue("l21_1",    l21_1);
    file<<nameValue("l22_1",    l22_1);

    file<<beginGroup("longPeriodic");
    file<<nameValue("count", deformationArg20.rows());
    for(UInt i=0; i<deformationArg20.rows(); i++)
    {
      Doodson doodson;
      for(UInt k=0; k<6; k++)
        doodson.d[k] = static_cast<Int>(deformationArg20(i, k));
      file<<beginGroup("constituent");
      file<<nameValue("doodson",    doodson);
      file<<nameValue("dRInPhase",  dR20_ip(i,0));
      file<<nameValue("dROutPhase", dR20_op(i,0));
      file<<nameValue("dTInPhase",  dT20_ip(i,0));
      file<<nameValue("dTOutPhase", dT20_op(i,0));
      file<<endGroup("constituent");
    }
    file<<endGroup("longPeriodic");

    file<<beginGroup("diurnal");
    file<<nameValue("count", deformationArg21.rows());
    for(UInt i=0; i<deformationArg21.rows(); i++)
    {
      Doodson doodson;
      for(UInt k=0; k<6; k++)
        doodson.d[k] = static_cast<Int>(deformationArg21(i, k));
      file<<beginGroup("constituent");
      file<<nameValue("doodson",    doodson);
      file<<nameValue("dRInPhase",  dR21_ip(i,0));
      file<<nameValue("dROutPhase", dR21_op(i,0));
      file<<nameValue("dTInPhase",  dT21_ip(i,0));
      file<<nameValue("dTOutPhase", dT21_op(i,0));
      file<<endGroup("constituent");
    }
    file<<endGroup("diurnal");

    file<<endGroup("displacement");
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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