General Purpose Geodetic Library
SgDbhImage.h
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SG_DBHIMAGE_H
24 #define SG_DBHIMAGE_H
25 
26 #include <math.h>
27 
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 
34 #include <QtCore/QString>
35 #include <QtCore/QDataStream>
36 #include <QtCore/QTextStream>
37 #include <QtCore/QList>
38 #include <QtCore/QHash>
39 
40 
41 
42 #include <SgMJD.h>
43 
44 
45 /* To Do:
46  *
47  * 0) There could be duplicates of LCODEs in different TOCs (e.g., "UTC TAG "). Should we
48  * delete data from some TOC or it is OK?
49  *
50  * 1) Some old DB files have TOCs that are not presented in data section (e.g., 79NOV25X__V048),
51  * software should be aware of it.
52  *
53  * 2) Epochs of history records -- what about time zones? Convert them to UTC?
54  *
55  */
56 
57 
58 /***===================================================================================================*/
64 class SgDbhStream : public QDataStream // just reserved type for this kind of operations
65 {};
66 /*=====================================================================================================*/
67 
68 
69 
70 /***===================================================================================================*/
77 {
78  friend class SgDbhTeBlock;
79 public:
80  enum Type {T_R8=0, T_I2=1, T_A2=2, T_D8=3, T_J4=4, T_UNKN=5};
81  //
82  // constructors/destructors:
83  //
85  SgDbhDatumDescriptor(const QString&, const QString&);
86  inline ~SgDbhDatumDescriptor() {};
87  //
88  // Interfaces:
89  //
90  inline const QString& getLCode() const {return lCode_;};
91  inline const QString& getDescription() const {return description_;};
92  inline short dim1() const {return dim1_;};
93  inline short dim2() const {return dim2_;};
94  inline short dim3() const {return dim3_;};
95  inline short getModifiedAtVersion() const {return modifiedAtVersion_;};
96  inline short nTc() const {return nTc_;};
97  inline short nTe() const {return nTe_;};
98  inline int offset() const {return offset_;};
99  inline Type type() const {return type_;};
100 
101  void setLCode(const QString& lCode);
102  void setDescription(const QString& description);
103  inline void setType(Type type) {type_=type;};
104  inline void setDimensions(int d1, int d2, int d3)
105  {dim1_=(short)d1; dim2_=(short)d2; dim3_=(short)d3;};
106  inline void setModifiedAtVersion(int V) {modifiedAtVersion_=(short)V;};
107  inline void setNTc(int nTc) {nTc_=(short)nTc;};
108  inline void setNTe(int nTe) {nTe_=(short)nTe;};
109  inline void setOffset(int offset) {offset_=offset;};
110  //
111  // Functions:
112  //
114  inline QString className() const {return "SgDbhDatumDescriptor";};
115  inline const QString& typeName() const {return typeNames_[type_];};
116  static const QString& typeName(Type type) {return typeNames_[type];};
117  //
118 protected:
119  static const QString
121  QString lCode_;
122  QString description_;
124  short dim1_, dim2_, dim3_;
126  short nTc_, nTe_;
127  int offset_;
128 };
129 /*=====================================================================================================*/
130 
131 
132 
133 
134 
135 // Try do not use <SgDbhFormat.h>, keep DBH reading/writting stuff not visible to end user,
136 // so user should use SgDbhImage class and its methods to manipulate with data from DBH files.
137 class SgDbhStream;
138 class SgDbhStartBlock;
139 class SgDbhHistoryEntry;
140 class SgDbhTcBlock;
141 class SgDbhDataBlock;
142 class SgDbhFormat;
143 class SgDbhPhysicalRecord;
145 /***===================================================================================================*/
152 {
153 public:
154  enum ContentState { CS_Bare, //< image contains nothing useful, just has been inited
155  CS_DataFromFile, //< image keeps data form DBH file
156  CS_DataAltered, //< image keeps data form DBH file, some data are altered
157  };
158  enum FormatState { FS_Bare, //< image does not contain format, just has been inited
159  FS_FormatFromFile, //< image keeps format according to read DBH file
160  FS_FormatAltering, //< the format of the image is in changing state
161  FS_FormatAltered, //< the format of the image has been changed
162  };
163  //
164  // constructors/destructors:
165  //
168  SgDbhImage();
169 
173  ~SgDbhImage();
174 
175  //
176  // Interfaces:
177  //
178  inline void setDumpStream(QTextStream*);
179  inline ContentState contentState() const {return contentState_;};
180  inline FormatState formatState() const {return formatState_;};
181 
182  inline QTextStream* getDumpStream();
183  SgMJD fileCreationEpoch() const;
184  int fileVersion() const;
185  inline int currentVersion() const;
186  const QString& fileName() const;
187  const QString& sessionDescription() const;
188  const QString& sessionID() const;
189  const QString& previousFileName() const;
190  const QString& previousFileDescription() const;
191 
193 
194  //
195  // Functions:
196  //
197  inline const QString className() const {return "SgDbhImage";};
198 
199  void addHistoryEntry(const QString& text, const SgMJD& t = SgMJD::currentMJD().toUtc());
200 
201  void startFormatModifying();
202 
203  void finisFormatModifying();
204 
206 
208 
209  // get a descriptor for the tag (=LCODE)
210  inline SgDbhDatumDescriptor *lookupDescriptor(const char* tag);
211 
212  // returns number of observations in the image
213  int numberOfObservations() const {return listOfObservations_.size();};
214 
215  // reading data:
216  QString getStr(SgDbhDatumDescriptor *d, int i, int j, int obsNumber=-1);
217 
218  template<class C> C getData(const QString&, SgDbhDatumDescriptor*, int, int, int, int =-1);
219 
220  double getR8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1);
221 
222  double getD8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1);
223 
224  int getJ4(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1);
225 
226  short getI2(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1);
227 
228  // altering data:
229  void setStr(SgDbhDatumDescriptor *d, int i, int j, int obsNumber, const QString& str);
230 
231  template<class C> void setData(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, C r8);
232 
233  void setR8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, double r8);
234 
235  void setD8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, double d8);
236 
237  void setJ4(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, int j4);
238 
239  void setI2(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, short i2);
240 
241  //
242  void dumpFormat();
243 
244  // setups proper values for the header of a file:
245  void prepare2save();
246 
247  inline void alterCode(const QString& c) {isSessionCodeAltered_=true; alterCode_=c;};
248 
249  //
250  // Friends:
251  //
253 
254  friend SgDbhStream &operator<<(SgDbhStream&, const SgDbhImage&);
255 
256  //
257  // I/O:
258  //
259  // ...
260 
261 private:
262  void clearHistoryList();
264  void copyToc0Content();
268  void writeDataRecords(SgDbhStream&, const QList<SgDbhDataBlock*>*, int) const;
269 
270 protected:
271  //
275  QString canonicalName_; // that sould looks like: `10MAY06XE'
276  // dump stream:
277  QTextStream *dumpStream_;
278  // initial block:
280  // history block (just a list of SgDbhHistoryEntry, nothing special):
282  // fromat description:
284  // an array of parameter descriptors that is indexed by thier LCodes (common for whole image):
285  QHash<QString, SgDbhDatumDescriptor*> descriptorByLCode_;
286  // Common data (TOC#0):
288  // Observations:
290  // for format changing:
293 
294  // for test purposes:
296  QString alterCode_;
297 };
298 /*=====================================================================================================*/
299 
300 
301 
302 
303 /*=====================================================================================================*/
304 /* */
305 /* SgDbhImage inline members: */
306 /* */
307 /*=====================================================================================================*/
308 //
309 //
310 // CONSTRUCTORS:
311 //
312 
313 //
314 // INTERFACES:
315 //
316 inline void SgDbhImage::setDumpStream(QTextStream* s)
317 {
318  dumpStream_ = s;
319 };
320 
321 
322 
323 inline QTextStream* SgDbhImage::getDumpStream()
324 {
325  return dumpStream_;
326 };
327 
328 
329 
330 //
331 inline int SgDbhImage::currentVersion() const
332 {
333  return currentVersion_;
334 };
335 
336 
337 
338 //
339 // FUNCTIONS:
340 //
342 {
343  return descriptorByLCode_.contains(tag) ? descriptorByLCode_.value(tag) : NULL;
344 };
345 /*=====================================================================================================*/
346 
347 
348 
349 /*=====================================================================================================*/
350 #endif //SG_DBHIMAGE_H
short nTe() const
Definition: SgDbhImage.h:97
static const QString typeNames_[6]
Definition: SgDbhImage.h:116
void setDescription(const QString &description)
Definition: SgDbhImage.cpp:63
int offset() const
Definition: SgDbhImage.h:98
const QString & typeName() const
Definition: SgDbhImage.h:115
static const QString & typeName(Type type)
Definition: SgDbhImage.h:116
short dim2() const
Definition: SgDbhImage.h:93
void setLCode(const QString &lCode)
Definition: SgDbhImage.cpp:55
short getModifiedAtVersion() const
Definition: SgDbhImage.h:95
const QString & getLCode() const
Definition: SgDbhImage.h:90
const QString & getDescription() const
Definition: SgDbhImage.h:91
short nTc() const
Definition: SgDbhImage.h:96
void setDimensions(int d1, int d2, int d3)
Definition: SgDbhImage.h:104
void setType(Type type)
Definition: SgDbhImage.h:103
void setNTe(int nTe)
Definition: SgDbhImage.h:108
Type type() const
Definition: SgDbhImage.h:99
SgDbhDatumDescriptor & operator=(const SgDbhDatumDescriptor &descriptor)
Definition: SgDbhImage.cpp:84
void setOffset(int offset)
Definition: SgDbhImage.h:109
short dim3() const
Definition: SgDbhImage.h:94
QString className() const
Definition: SgDbhImage.h:114
short dim1() const
Definition: SgDbhImage.h:92
void setModifiedAtVersion(int V)
Definition: SgDbhImage.h:106
void setNTc(int nTc)
Definition: SgDbhImage.h:107
void writeDataRecords(SgDbhStream &, const QList< SgDbhDataBlock * > *, int) const
Definition: SgDbhImage.cpp:782
friend SgDbhStream & operator>>(SgDbhStream &, SgDbhImage &)
const QString & fileName() const
Definition: SgDbhImage.cpp:178
FormatState formatState_
Definition: SgDbhImage.h:273
void updateDescriptorsParameters()
Definition: SgDbhImage.cpp:746
int fileVersion() const
Definition: SgDbhImage.cpp:170
QList< SgDbhHistoryEntry * > history_
Definition: SgDbhImage.h:281
const QString & sessionID() const
Definition: SgDbhImage.cpp:194
QString canonicalName_
Definition: SgDbhImage.h:275
ContentState contentState() const
Definition: SgDbhImage.h:179
int currentVersion() const
Definition: SgDbhImage.h:331
void startFormatModifying()
Definition: SgDbhImage.cpp:508
double getR8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1)
Definition: SgDbhImage.cpp:347
short getI2(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1)
Definition: SgDbhImage.cpp:371
QList< SgDbhDataBlock * > listOfDataBlocksToc0_
Definition: SgDbhImage.h:287
C getData(const QString &, SgDbhDatumDescriptor *, int, int, int, int=-1)
Definition: SgDbhImage.cpp:332
friend SgDbhStream & operator<<(SgDbhStream &, const SgDbhImage &)
void addHistoryEntry(const QString &text, const SgMJD &t=SgMJD::currentMJD().toUtc())
Definition: SgDbhImage.cpp:238
void setI2(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, short i2)
Definition: SgDbhImage.cpp:448
FormatState formatState() const
Definition: SgDbhImage.h:180
double getD8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1)
Definition: SgDbhImage.cpp:355
void alterCode(const QString &c)
Definition: SgDbhImage.h:247
void setJ4(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, int j4)
Definition: SgDbhImage.cpp:440
void setData(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, C r8)
Definition: SgDbhImage.cpp:402
ContentState contentState_
Definition: SgDbhImage.h:272
QString alterCode_
Definition: SgDbhImage.h:296
SgMJD fileCreationEpoch() const
Definition: SgDbhImage.cpp:162
QList< SgDbhDatumDescriptor * > listOfNewDescriptors_
Definition: SgDbhImage.h:291
QTextStream * getDumpStream()
Definition: SgDbhImage.h:323
SgDbhStartBlock * startBlock_
Definition: SgDbhImage.h:279
void dumpFormat()
Definition: SgDbhImage.cpp:975
void setD8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, double d8)
Definition: SgDbhImage.cpp:432
void setStr(SgDbhDatumDescriptor *d, int i, int j, int obsNumber, const QString &str)
Definition: SgDbhImage.cpp:379
void copyToc0Content()
Definition: SgDbhImage.cpp:456
QList< SgDbhDatumDescriptor * > listOfDeletedDescriptors_
Definition: SgDbhImage.h:292
void finisFormatModifying()
Definition: SgDbhImage.cpp:518
const QString & sessionDescription() const
Definition: SgDbhImage.cpp:186
QHash< QString, SgDbhDatumDescriptor * > descriptorByLCode_
Definition: SgDbhImage.h:285
const QList< SgDbhHistoryEntry * > & historyList()
Definition: SgDbhImage.h:192
QTextStream * dumpStream_
Definition: SgDbhImage.h:277
void clearListOfObservations()
Definition: SgDbhImage.cpp:228
const QString & previousFileName() const
Definition: SgDbhImage.cpp:202
bool delDescriptor(SgDbhDatumDescriptor *)
Definition: SgDbhImage.cpp:922
void clearHistoryList()
Definition: SgDbhImage.cpp:218
@ FS_FormatAltered
Definition: SgDbhImage.h:161
@ FS_FormatFromFile
Definition: SgDbhImage.h:159
@ FS_FormatAltering
Definition: SgDbhImage.h:160
@ CS_DataAltered
Definition: SgDbhImage.h:156
@ CS_DataFromFile
Definition: SgDbhImage.h:155
QList< SgDbhObservationEntry * > listOfObservations_
Definition: SgDbhImage.h:289
void setR8(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber, double r8)
Definition: SgDbhImage.cpp:424
int numberOfObservations() const
Definition: SgDbhImage.h:213
SgDbhDatumDescriptor * lookupDescriptor(const char *tag)
Definition: SgDbhImage.h:341
SgDbhPhysicalRecord * properRecord(SgDbhDatumDescriptor *, int)
Definition: SgDbhImage.cpp:249
void setDumpStream(QTextStream *)
Definition: SgDbhImage.h:316
void updateDataRecords(QList< SgDbhDataBlock * > *, int)
Definition: SgDbhImage.cpp:638
bool addDescriptor(SgDbhDatumDescriptor *)
Definition: SgDbhImage.cpp:823
int currentVersion_
Definition: SgDbhImage.h:274
SgDbhFormat * format_
Definition: SgDbhImage.h:283
bool isSessionCodeAltered_
Definition: SgDbhImage.h:295
const QString & previousFileDescription() const
Definition: SgDbhImage.cpp:210
QString getStr(SgDbhDatumDescriptor *d, int i, int j, int obsNumber=-1)
Definition: SgDbhImage.cpp:318
int getJ4(SgDbhDatumDescriptor *d, int i, int j, int k, int obsNumber=-1)
Definition: SgDbhImage.cpp:363
void prepare2save()
Definition: SgDbhImage.cpp:989
const QString className() const
Definition: SgDbhImage.h:197
Definition: SgMJD.h:59
static SgMJD currentMJD()
Definition: SgMJD.cpp:118