General Purpose Geodetic Library
SgNetworkStnRecord.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) 2016-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 <SgNetworkStnRecord.h>
33 #include <SgLogger.h>
34 
35 
36 
37 
38 /*=======================================================================================================
39 *
40 * METHODS:
41 *
42 *======================================================================================================*/
43 //
44 // static first:
46 {
47  return "SgNetworkStnRecord";
48 };
49 
50 
52 {
53  isValid_ = r.isValid_;
54  name_ = r.name_;
55  code_ = r.code_;
56  domesId_ = r.domesId_;
57  cdpId_ = r.cdpId_;
59 };
60 
61 
62 
63 //
65 {
66  isValid_ = r.isValid_;
67  name_ = r.name_;
68  code_ = r.code_;
69  domesId_ = r.domesId_;
70  cdpId_ = r.cdpId_;
72  return *this;
73 };
74 
75 
76 
77 //
78 bool SgNetworkStnRecord::parseString(const QString& str)
79 {
80 // 1 2 3 4 5
81 //012345678901234567890123456789012345678901234567890123456789
82 // Dm DEADMANL 40431M001 7267 mobile Deadman Lake, CA, USA
83  code_ = str.mid(1, 2);
84  name_ = str.mid(4, 8).simplified();
85  name_.replace('_', ' ');
86  name_ = name_.leftJustified(8, ' ');
87  domesId_ = str.mid(13, 9);
88  cdpId_ = str.mid(23, 4);
89  description_ = str.mid(28);
90  isValid_ = (name_ != QString("--------"));
91  return isValid_;
92 };
93 /*=====================================================================================================*/
94 //
95 // FRIENDS:
96 //
97 /*=====================================================================================================*/
98 //
99 
100 
101 
102 
103 
104 
105 /*=======================================================================================================
106 *
107 * METHODS:
108 *
109 *======================================================================================================*/
110 //
111 // static first:
113 {
114  return "SgNetworkStations";
115 };
116 
117 
118 
119 //
121 {
122  QString fName(path2file_ + "/" + fileName_);
123  QString str;
124  QFile f(fName);
125  if (!f.exists())
126  {
128  "::readFile(): the ns-codes file [" + fName +
129  "] does not exist; ns-code records are unavailable");
130  return (isOk_=false);
131  };
132  //
133  if (f.open(QFile::ReadOnly))
134  {
135  QTextStream s(&f);
136  SgNetworkStnRecord rec;
137  while (!s.atEnd())
138  {
139  str = s.readLine();
140  if (str.size()>29 && str.at(0)==' ' && rec.parseString(str))
141  {
142  if (recByName_.contains(rec.getName()))
144  "::readFile(): got a duplicate record \"" + str +
145  "\" for the station name \"" + rec.getName() + "\" in the ns-codes file [" + fName + "]");
146  else
147  recByName_.insert(rec.getName(), rec);
148  //
149  if (recById_.contains(rec.getCode()))
151  "::readFile(): got a duplicate record \"" + str +
152  "\" for the station code \"" + rec.getCode() + "\" in the ns-codes file [" + fName + "]");
153  else
154  recById_.insert(rec.getCode(), rec);
155  };
156  };
157  f.close();
158  s.setDevice(NULL);
159  isOk_ = (recByName_.size()>0);
160  }
161  else
162  isOk_ = false;
164  "::readFile(): extracted " + QString("").setNum(recByName_.size()) +
165  " records from the ns-codes file [" + fName + "]");
166 
167  return isOk_;
168 };
169 
170 
171 
172 //
174 {
175  return recByName_.find(key).value();
176 };
177 /*=====================================================================================================*/
178 //
179 // FRIENDS:
180 //
181 /*=====================================================================================================*/
182 //
183 
184 /*=====================================================================================================*/
185 //
186 // aux functions:
187 //
188 
189 /*=====================================================================================================*/
190 //
191 // constants:
192 //
193 
194 /*=====================================================================================================*/
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 SgNetworkStnRecord & lookUp(const QString &)
static const QString className()
QMultiMap< QString, SgNetworkStnRecord > recById_
QMultiMap< QString, SgNetworkStnRecord > recByName_
bool parseString(const QString &)
const QString & getName() const
SgNetworkStnRecord & operator=(const SgNetworkStnRecord &r)
static const QString className()
const QString & getCode() const