General Purpose Geodetic Library
SgEccDat.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 <math.h>
24 
25 
26 #include <QtCore/QDir>
27 #include <QtCore/QFile>
28 #include <QtCore/QTextStream>
29 
30 #include <SgEccDat.h>
31 #include <SgEccRec.h>
32 #include <SgEccSite.h>
33 #include <SgLogger.h>
34 
35 /*=======================================================================================================
36 *
37 * METHODS:
38 *
39 *======================================================================================================*/
40 //
41 // static first:
42 const QString SgEccDat::className()
43 {
44  return "SgEccDat";
45 };
46 
47 
48 
49 // A destructor:
51 {
52  QMap<QString, SgEccSite*>::iterator it=siteByName_.begin();
53  for (; it!=siteByName_.end(); ++it)
54  delete it.value();
55  siteByName_.clear();
56 };
57 
58 
59 
60 //
62 {
63  QString str("");
64  QDir dir(path2File_);
65  if (path2File_.size() && !dir.exists())
66  {
68  ": importEccFile(): the directory [" + path2File_ +
69  "] does not exist; import of eccentricities is not available");
70  return;
71  };
72  if (path2File_.size())
73  str = path2File_ + "/";
74  str += fileName_;
75  QFile f(str);
76  if (!f.exists())
77  {
79  ": importEccFile(): the file [" + fileName_ +
80  "] does not exist; import of eccentricities is not available");
81  return;
82  };
83  SgEccSite *site;
84  SgEccRec rec;
85  if (f.open(QFile::ReadOnly))
86  {
87  QTextStream s(&f);
88  while (!s.atEnd())
89  {
90  str = s.readLine();
91  if (str.size()>89 &&
92  str.mid(0,1) == " " && // all others are comments
93  rec.parseString(str))
94  {
95  if (siteByName_.contains(rec.getSiteName()))
96  site = siteByName_.find(rec.getSiteName()).value();
97  else
98  {
99  site = new SgEccSite(rec.getSiteName());
100  siteByName_.insert(rec.getSiteName(), site);
101  };
102  site->insertRecord(new SgEccRec(rec));
103  };
104  };
105  f.close();
106  s.setDevice(NULL);
107  };
108  QMap<QString, SgEccSite*>::iterator it=siteByName_.begin();
109  for (; it!=siteByName_.end(); ++it)
110  it.value()->checkRecords();
112  ": importEccFile(): imported " + QString().setNum(siteByName_.size()) +
113  " ecc sites from the file " + f.fileName());
114 };
115 
116 
117 
118 //
119 SgEccRec* SgEccDat::lookupRecord(const QString& siteName, const SgMJD& t)
120 {
121  SgEccSite *site=NULL;
122 
123  if (siteByName_.contains(siteName))
124  site = siteByName_.find(siteName).value();
125  else
126  {
128  ": lookupRecord(): cannot find site " + siteName + " in the ecc site list");
129  return NULL;
130  };
131  return site->findRecord(t);
132 };
133 /*=====================================================================================================*/
134 
135 
136 
137 /*=======================================================================================================
138 *
139 * FRIENDS:
140 *
141 *======================================================================================================*/
142 //
143 
144 
145 
146 /*=====================================================================================================*/
147 //
148 // aux functions:
149 //
150 
151 
152 // i/o:
153 
154 
155 /*=====================================================================================================*/
156 //
157 // constants:
158 //
159 /*=====================================================================================================*/
160 
161 
162 
163 
164 
165 
166 
167 
168 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
~SgEccDat()
Definition: SgEccDat.cpp:50
SgEccRec * lookupRecord(const QString &, const SgMJD &)
Definition: SgEccDat.cpp:119
static const QString className()
Definition: SgEccDat.cpp:42
QString path2File_
Definition: SgEccDat.h:91
QMap< QString, SgEccSite * > siteByName_
Definition: SgEccDat.h:93
QString fileName_
Definition: SgEccDat.h:92
void importEccFile()
Definition: SgEccDat.cpp:61
bool parseString(const QString &)
Definition: SgEccRec.cpp:45
const QString & getSiteName() const
Definition: SgEccRec.h:203
SgEccRec * findRecord(const SgMJD &)
Definition: SgEccSite.cpp:140
bool insertRecord(SgEccRec *)
Definition: SgEccSite.cpp:63
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
Definition: SgMJD.h:59