General Purpose Geodetic Library
SgMasterRecord.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 #include <iostream>
24 #include <stdlib.h>
25 
26 #include <QtCore/QDir>
27 #include <QtCore/QFile>
28 #include <QtCore/QStringList>
29 #include <QtCore/QTextStream>
30 
31 
32 #include <SgMasterRecord.h>
33 #include <SgLogger.h>
34 
35 
36 
37 /*=======================================================================================================
38 *
39 * METHODS:
40 *
41 *======================================================================================================*/
42 //
43 // static first:
45 {
46  return "SgMasterRecord";
47 };
48 
49 
50 
51 //
53 {
54  isValid_ = r.isValid_;
55  name_ = r.name_;
56  code_ = r.code_;
57  date_ = r.date_;
58  stations_ = r.stations_;
59  dbcCode_ = r.dbcCode_;
63  return *this;
64 };
65 
66 
67 
68 //
69 void SgMasterRecord::parseString(const QString& str)
70 {
71  isValid_ = false;
72  if (str.at(0) != QChar('|') ||
73  str.at(str.size()-1)!=QChar('|') ||
74  str.count(QChar('|')) != 16)
75  {
76  //complain (?):
77  //logger->write(SgLogger::DBG, SgLogger::IO_TXT, className() +
78  // ": got a not valid MR-string: [" + str + "]; skipped");
79  return;
80  };
81  QStringList fields = str.split("|");
82  name_ = fields.at(1).simplified();
83  code_ = fields.at(2).simplified();
84  date_ = fields.at(3).simplified();
85  stations_ = fields.at(7).simplified();
86  dbcCode_ = fields.at(12).simplified();
87  scheduledBy_ = fields.at(8).simplified();
88  correlatedBy_ = fields.at(9).simplified();
89  submittedBy_ = fields.at(13).simplified();
90  if (name_.size() && code_.size() && dbcCode_.size() && date_.size())
91  isValid_ = true;
92 };
93 
94 
95 
96 //
97 bool SgMasterRecord::lookupRecordByName(const QString& nickName, const QString& path)
98 {
99  QDir dir(path);
100  if (!dir.exists())
101  {
103  "::lookupRecordByName(): the masterfile directory [" + path +
104  "] does not exist; master file records are unavailable");
105  return false;
106  };
107  // nickName: 12FEB27XA
108  QString sYear(nickName.mid(0, 2));
109  QString sDate(nickName.mid(2, 5));
110  QString sCode(nickName.mid(7, 2));
111  if (findRecordByName(sDate, sCode, path + "/" + "master" + sYear + "-loc.txt") ||
112  findRecordByName(sDate, sCode, path + "/" + "master" + sYear + ".txt") ||
113  findRecordByName(sDate, sCode, path + "/" + "master" + sYear + "-int.txt") ||
114  findRecordByName(sDate, sCode, path + "/" + "master" + sYear + "-vgos.txt") )
115  return true;
116  return false;
117 };
118 
119 
120 
121 //
122 bool SgMasterRecord::findRecordByName(const QString& date, const QString& dbcCode,
123  const QString& fileName)
124 {
125  SgMasterRecord mr;
126  QString str;
127  QFile f(fileName);
128  if (!f.exists())
129  {
131  "::findRecordByName(): the masterfile [" + fileName + "] does not exist");
132  return false;
133  };
134  //
135  if (f.open(QFile::ReadOnly))
136  {
137  QTextStream s(&f);
138  while (!s.atEnd())
139  {
140  str = s.readLine();
141  if (str.size()>16)
142  {
143  mr.parseString(str);
144  if (mr.getDate() == date && mr.getDbcCode() == dbcCode)
145  {
146  *this = mr;
147  f.close();
148  s.setDevice(NULL);
149  return true;
150  };
151  };
152  };
153  f.close();
154  s.setDevice(NULL);
155  };
156  return false;
157 };
158 
159 
160 
161 //
162 bool SgMasterRecord::lookupRecordByCode(const QString& sessionCode, const QString& sYear,
163  const QString& path)
164 {
165  QDir dir(path);
166  if (!dir.exists())
167  {
169  "::lookupRecordByCode(): the masterfile directory [" + path +
170  "] does not exist; master file records are unavailable");
171  return false;
172  };
173  if (findRecordByCode(sessionCode, path + "/" + "master" + sYear + "-loc.txt") ||
174  findRecordByCode(sessionCode, path + "/" + "master" + sYear + ".txt") ||
175  findRecordByCode(sessionCode, path + "/" + "master" + sYear + "-int.txt") ||
176  findRecordByCode(sessionCode, path + "/" + "master" + sYear + "-vgos.txt") )
177  return true;
178  return false;
179 };
180 
181 
182 
183 //
184 bool SgMasterRecord::findRecordByCode(const QString& sessionCode, const QString& fileName)
185 {
186  SgMasterRecord mr;
187  QString str;
188  QFile f(fileName);
189  if (!f.exists())
190  {
192  "::findRecordByCode(): the masterfile [" + fileName + "] does not exist");
193  return false;
194  };
195  //
196  if (f.open(QFile::ReadOnly))
197  {
199  "::findRecordByCode(): processing the masterfile " + fileName);
200  QTextStream s(&f);
201  while (!s.atEnd())
202  {
203  str = s.readLine();
204  if (str.size()>16)
205  {
206  mr.parseString(str);
207  if (mr.getCode() == sessionCode.toUpper()) // some correlators provide lower case here
208  {
209  *this = mr;
210  f.close();
211  s.setDevice(NULL);
212  return true;
213  };
214  };
215  };
216  f.close();
217  s.setDevice(NULL);
218  };
219  return false;
220 };
221 /*=====================================================================================================*/
222 //
223 // FRIENDS:
224 //
225 /*=====================================================================================================*/
226 //
227 
228 /*=====================================================================================================*/
229 //
230 // aux functions:
231 //
232 
233 /*=====================================================================================================*/
234 //
235 // constants:
236 //
237 
238 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
const QString & getDate() const
static const QString className()
bool lookupRecordByCode(const QString &sessionCode, const QString &sYear, const QString &path)
bool findRecordByCode(const QString &sessionCode, const QString &fileName)
QString scheduledBy_
QString correlatedBy_
const QString & getCode() const
SgMasterRecord & operator=(const SgMasterRecord &r)
void parseString(const QString &)
bool findRecordByName(const QString &date, const QString &dbcCode, const QString &fileName)
const QString & getDbcCode() const
QString submittedBy_
bool lookupRecordByName(const QString &nickName, const QString &path)