General Purpose Geodetic Library
SgExternalWeights.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 #include <iostream>
26 
27 
28 #include <QtCore/QFile>
29 #include <QtCore/QStringList>
30 #include <QtCore/QTextStream>
31 
32 #include <SgExternalWeights.h>
33 #include <SgLogger.h>
34 
35 
36 
37 /*=======================================================================================================
38 *
39 * SgBaselineExternalWeight's METHODS:
40 *
41 *======================================================================================================*/
42 //
43 // static first:
45 {
46  return "SgBaselineExternalWeight";
47 };
48 
49 
50 
51 //
52 bool SgBaselineExternalWeight::parseString(const QString& str)
53 {
54  // 1 2 3 4 5 6 7
55  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
56  //12MAY03XE 4 WETTZELL/YEBES40M 45.63 221.45 0.10 0.00
57 
58  // ok, we do not know exactly the format specifications, guess, it is a space separated
59  // fileds:
60  bool isOk;
61  QStringList l = str.mid(9).simplified().split(' ', QString::SkipEmptyParts);
62  if (l.size() < 4)
63  {
65  "parseString(): cannot parse external weights string: [" + str + "]");
66  return false;
67  };
68 
69  dbhVersionNumber_ = l.at(0).toInt(&isOk);
70  if (!isOk)
71  {
74  "parseString(): cannot get DBH version number from external weights string: [" + str + "]");
75  return false;
76  };
77 
78  baselineName_ = l.at(1);
79  // adjust notation:
80  baselineName_.replace(8, 1, ':');
81  baselineName_.replace('_', ' ');
82 
83  delayWeight_ = l.at(2).toDouble(&isOk);
84  if (!isOk)
85  {
86  delayWeight_ = 0.0;
88  "parseString(): cannot get delay weight from external weights string: [" + str + "]");
89  return false;
90  };
91 
92  rateWeight_ = l.at(3).toDouble(&isOk);
93  if (!isOk)
94  {
95  rateWeight_ = 0.0;
97  "parseString(): cannot get rate weight from external weights string: [" + str + "]");
98  return false;
99  };
100 
101  return true;
102 };
103 /*=====================================================================================================*/
104 
105 
106 
107 
108 
109 
110 /*=======================================================================================================
111 *
112 * SgExternalWeights's METHODS:
113 *
114 *======================================================================================================*/
115 //
116 // static first:
118 {
119  return "SgExternalWeights";
120 };
121 
122 
123 
124 //
125 bool SgExternalWeights::readFile(const QString& fileName)
126 {
127  QString str;
128  QFile f((fileName_=fileName));
129  isOk_ = false;
130  if (!f.exists())
131  {
133  ": readFile(): the file [" + fileName + "] with external weights does not exist");
134  return isOk_;
135  };
136  //
137  // clear the stuff:
138  for (QMap<QString, SgBaselineExternalWeight*>::iterator it=weights_.begin(); it!=weights_.end(); ++it)
139  delete it.value();
140  weights_.clear();
141  //
143  if (f.open(QFile::ReadOnly))
144  {
145  QTextStream s(&f);
146  while (!s.atEnd())
147  {
148  str = s.readLine();
149  if (str.mid(0, 9) == sessionName_)
150  {
151  if (w.parseString(str))
152  {
153  // check for duplicate names:
154  if (!weights_.contains(w.getBaselineName()))
156  else if (weights_.value(w.getBaselineName())->getDbhVersionNumber() != w.getDbhVersionNumber())
157  {
158  // pick up just latest version:
159  if (weights_.value(w.getBaselineName())->getDbhVersionNumber() < w.getDbhVersionNumber())
160  {
162  bew->setDelayWeight(w.getDelayWeight());
163  bew->setRateWeight(w.getRateWeight());
165  };
166  }
167  else
169  ": readFile(): got a duplicate record for " + w.getBaselineName() + "'s weight of the" +
170  " session " + sessionName_ + " in the external weights file " + fileName_);
171  };
172  };
173  };
174  f.close();
175  s.setDevice(NULL);
176  };
177  if ((isOk_=(weights_.size()!=0)))
179  ": readFile(): " + QString().setNum(weights_.size()) + " weight records have been acquired from" +
180  " the external weightsfile " + fileName_);
181  return isOk_;
182 };
183 
184 
185 
186 //
188 {
189  for (BaselinesByName_it it=baselines.begin(); it!=baselines.end(); ++it)
190  {
191  SgVlbiBaselineInfo *bi=it.value();
192  if (weights_.contains(bi->getKey()))
193  {
194  SgBaselineExternalWeight *w=weights_.find(bi->getKey()).value();
195  bi->setSigma2add(DT_DELAY, w->getDelayWeight()*1.0e-12);
196  bi->setSigma2add(DT_RATE, w->getRateWeight() *1.0e-15); // fs/s?
197  }
198  else
200  ": setupExternalWeights(): cannot find a weight record for the baseline " +
201  bi->getKey());
202  };
203 };
204 /*=====================================================================================================*/
205 
206 
207 
208 
209 
210 
211 /*=======================================================================================================
212 *
213 * FRIENDS:
214 *
215 *======================================================================================================*/
216 //
217 
218 
219 
220 /*=====================================================================================================*/
221 //
222 // aux functions:
223 //
224 
225 // i/o:
226 
227 
228 /*=====================================================================================================*/
229 //
230 // constants:
231 //
232 /*=====================================================================================================*/
233 
234 
235 
236 
237 
238 
239 
240 
241 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
QMap< QString, SgVlbiBaselineInfo * >::iterator BaselinesByName_it
QMap< QString, SgVlbiBaselineInfo * > BaselinesByName
@ DT_DELAY
Definition: SgWrmsable.h:44
@ DT_RATE
Definition: SgWrmsable.h:45
bool parseString(const QString &)
const QString & getBaselineName() const
static const QString className()
bool readFile(const QString &)
QMap< QString, SgBaselineExternalWeight * > weights_
static const QString className()
void setupExternalWeights(BaselinesByName &)
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
const QString & getKey() const
Definition: SgObjectInfo.h:319
void setSigma2add(DataType dType, double d)
Definition: SgObjectInfo.h:471