General Purpose Geodetic Library
SgEccSite.cpp
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 
24 #include <math.h>
25 
26 #include <SgEccRec.h>
27 #include <SgEccSite.h>
28 #include <SgLogger.h>
29 
30 
31 
33 {
34  return r1->getTTill() > r2->getTTill();
35 };
36 
37 
38 /*=======================================================================================================
39 *
40 * METHODS:
41 *
42 *======================================================================================================*/
43 //
44 // static first:
45 const QString SgEccSite::className()
46 {
47  return "SgEccSite";
48 };
49 
50 
51 
52 //
54 {
55  for (int i=0; i<records_.size(); i++)
56  delete records_.at(i);
57  records_.clear();
58 };
59 
60 
61 
62 //
64 {
65  // check for clinical cases:
66  if (!rec)
67  {
69  ": insertRecord(): the record is NULL");
70  return false;
71  };
72  if (rec->getSiteName() != siteName_)
73  {
75  ": insertRecord(): the record's name [" + rec->getSiteName() +
76  "] is not the same as the site's one [" + siteName_ + "]");
77  return false;
78  };
79  if (records_.size()==0) // first record, just insert it:
80  {
81  records_.append(rec);
82  tBegin_ = rec->getTSince();
83  tEnd_ = rec->getTTill();
84  return true;
85  };
86  // some additional checks:
87  if (rec->getTTill()>tEnd_ && rec->getTSince()>tBegin_ && tEnd_>rec->getTSince())
89  ": insertRecord(): the " + siteName_ + "'s records are overlapped: list: [" +
90  tBegin_.toString() + ":" + tEnd_.toString() + "]; the record: [" +
91  rec->getTSince().toString() + ":" + rec->getTTill().toString() + "]");
92  if (tBegin_>rec->getTSince() && rec->getTTill()>tBegin_ && tEnd_>rec->getTTill())
94  ": insertRecord(): the " + siteName_ + "'s records are overlapped: list: [" +
95  tBegin_.toString() + ":" + tEnd_.toString() + "]; the record: [" +
96  rec->getTSince().toString() + ":" + rec->getTTill().toString() + "]");
97  if (rec->getTSince()>tBegin_ && tEnd_>rec->getTTill())
99  ": insertRecord(): the " + siteName_ + "'s records are overlapped: list: [" +
100  tBegin_.toString() + ":" + tEnd_.toString() + "]; the record: [" +
101  rec->getTSince().toString() + ":" + rec->getTTill().toString() + "]");
102  if (tBegin_>rec->getTSince() && rec->getTTill()>tEnd_)
104  ": insertRecord(): the " + siteName_ + "'s records are overlapped: list: [" +
105  tBegin_.toString() + ":" + tEnd_.toString() + "]; the record: [" +
106  rec->getTSince().toString() + ":" + rec->getTTill().toString() + "]");
107 
108  // append the record:
109  records_.append(rec);
110  if (tBegin_>rec->getTSince())
111  tBegin_ = rec->getTSince();
112  if (rec->getTTill()>tEnd_)
113  tEnd_ = rec->getTTill();
114 
115  return true;
116 };
117 
118 
119 
120 //
122 {
123  if (records_.size()<2)
124  return;
125  qSort(records_.begin(), records_.end(), tillEpochSortingOrderLessThan);
126 
127  for (int i=0; i<records_.size()-1; i++)
128  {
129  if (records_.at(i)->getTTill() < records_.at(i+1)->getTSince())
131  ": checkRecords(): there are gaps in " + siteName_ + "'s records: from " +
132  records_.at(i)->getTTill().toString() + " till " +
133  records_.at(i+1)->getTSince().toString());
134  };
135 };
136 
137 
138 
139 //
141 {
142  SgEccRec* rec=NULL;
143  for (int i=0; i<records_.size(); i++)
144  if (records_.at(i)->getTSince()<=t && t<=records_.at(i)->getTTill())
145  rec = records_.at(i);
146  if (!rec)
148  ": findRecord(): cannot find ecc record for the epoch " + t.toString());
149  return rec;
150 };
151 /*=====================================================================================================*/
152 
153 
154 
155 /*=======================================================================================================
156 *
157 * FRIENDS:
158 *
159 *======================================================================================================*/
160 //
161 
162 
163 
164 /*=====================================================================================================*/
165 //
166 // aux functions:
167 //
168 
169 
170 // i/o:
171 
172 
173 /*=====================================================================================================*/
174 //
175 // constants:
176 //
177 /*=====================================================================================================*/
178 
179 
180 
181 
182 
183 
184 
185 
186 /*=====================================================================================================*/
bool tillEpochSortingOrderLessThan(SgEccRec *r1, SgEccRec *r2)
Definition: SgEccSite.cpp:32
SgLogger * logger
Definition: SgLogger.cpp:231
const SgMJD & getTTill() const
Definition: SgEccRec.h:235
const SgMJD & getTSince() const
Definition: SgEccRec.h:227
const QString & getSiteName() const
Definition: SgEccRec.h:203
SgEccRec * findRecord(const SgMJD &)
Definition: SgEccSite.cpp:140
static const QString className()
Definition: SgEccSite.cpp:45
SgMJD tEnd_
Definition: SgEccSite.h:91
QString siteName_
Definition: SgEccSite.h:89
SgMJD tBegin_
Definition: SgEccSite.h:90
void checkRecords()
Definition: SgEccSite.cpp:121
bool insertRecord(SgEccRec *)
Definition: SgEccSite.cpp:63
QList< SgEccRec * > records_
Definition: SgEccSite.h:88
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
Definition: SgMJD.h:59
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1008