General Purpose Geodetic Library
SgVlbiSessionIoNgs.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/QFile>
27 #include <QtCore/QTextStream>
28 
29 
30 #include <SgVlbiSession.h>
31 
32 #include <SgConstants.h>
33 #include <SgLogger.h>
34 #include <SgVlbiBand.h>
35 #include <SgVlbiObservation.h>
36 
37 
38 /*=======================================================================================================
39 *
40 * Auxiliary data structures
41 *
42 *======================================================================================================*/
43 
44 
45 
46 
47 //
48 bool SgVlbiSession::exportDataIntoNgsFile(const QString& dirName)
49 {
50  SgMJD startEpoch(SgMJD::currentMJD());
51  static const QString mntTypeNames[] =
52  {
53  "AZEL",
54  "EQUA",
55  "X-YN",
56  "X-YE",
57  "RCHM",
58  "UNKN"
59  };
60  QString fileName(getName());
61  QString str(fileName);
62 
63  fileName += QString().sprintf("_N%03d", primaryBand_->getInputFileVersion() + 1);
64 
65  QFile f(dirName + "/" + fileName);
66  if (!f.open(QIODevice::WriteOnly))
67  {
69  ": error opening output file: " + dirName + "/" + fileName);
70  return false;
71  };
72  QTextStream ts(&f);
73  SgVlbiStationInfo *sti;
74 //SgVlbiStationInfo *st1i, *st2i;
75  SgVlbiSourceInfo *sri;
76 
77  // start output operations:
78  // header:
79  str += QString().sprintf("_V%03d", primaryBand_->getInputFileVersion() + 1);
80  // DATA IN NGS FORMAT FROM DATABASE 12JAN26XE_V004
81  ts << "DATA IN NGS FORMAT FROM DATABASE " << str << "\r\n";
82  //Observed delays and rates in card #2, modified errors in card #9
83  ts << "Observed delays and rates in card #2, modified errors in card #9\r\n";
84 
85  // station block:
86  StationsByName_it itSt;
87  itSt = stationsByName_.begin();
88  for (itSt=stationsByName_.begin(); itSt!=stationsByName_.end(); ++itSt)
89  {
90  sti = itSt.value();
91  //YEBES40M 4848762.10000 -261484.50000 4123084.90000 AZEL 2.06500
92  str.sprintf("%-8s %14.5f %14.5f %14.5f %4s %9.5f",
93  qPrintable(sti->getKey()),
94  sti->getR().at(X_AXIS),
95  sti->getR().at(Y_AXIS),
96  sti->getR().at(Z_AXIS),
97  qPrintable(mntTypeNames[sti->getMntType()]),
98  sti->getAxisOffset() );
99  ts << str << "\r\n";
100  };
101  ts << "$END\r\n";
102  // sources block:
103  SourcesByName_it itSr;
104  itSr = sourcesByName_.begin();
105  for (itSr=sourcesByName_.begin(); itSr!=sourcesByName_.end(); ++itSr)
106  {
107  sri = itSr.value();
108  char sgn;
109  int ra_hr, ra_min, de_deg, de_min;
110  double ra_sec, de_sec;
111  ra_sec = sri->getRA();
112  de_sec = sri->getDN();
113  sgn = ' ';
114  if (de_sec<0.0)
115  {
116  sgn = '-';
117  de_sec = - de_sec;
118  };
119  ra_sec*= 43200.0/M_PI;
120  ra_hr = trunc(ra_sec/60.0/60.0);
121  ra_sec-= ra_hr*60.0*60.0;
122  ra_min = trunc(ra_sec/60.0);
123  ra_sec-= ra_min*60.0;
124 
125  de_sec*= 648000.0/M_PI;
126  de_deg = trunc(de_sec/60.0/60.0);
127  de_sec-= de_deg*60.0*60.0;
128  de_min = trunc(de_sec/60.0);
129  de_sec-= de_min*60.0;
130  //3C446 22 25 47.259295 - 4 57 1.390820
131  str.sprintf("%-8s %2d %2d %9.6f %c%2d %2d %9.6f",
132  qPrintable(sri->getKey()),
133  ra_hr, ra_min, ra_sec,
134  sgn,
135  de_deg, de_min, de_sec );
136  ts << str << "\r\n";
137  };
138  ts << "$END\r\n";
139  // aux parameters:
140  // .8212990000000D+04 GR PH
141  str.sprintf("%20.13E GR PH",
143  ts << str << "\r\n$END\r\n";
144 
145  // observations:
146  QString strQual, strIonoQual;
147  int yr, month, day, hr, min;
148  double sec;
149  double effectiveGDSigma, effectivePRSigma, sigmaGD2add, sigmaPR2add;
150  for (int i=0; i<observations_.size(); i++)
151  {
152  SgVlbiObservation *obs = observations_.at(i);
153  SgVlbiObservable *o = obs->primeObs();
154  if (o)
155  {
156  SgMJD::MJD_reverse(obs->getDate(), obs->getTime(), yr, month, day, hr, min, sec);
157 // st1i = obs->stn_1();
158 // st2i = obs->stn_2();
159  strQual.sprintf("%2d", o->grDelay().getUnweightFlag());
161  strQual = " 1";
162  strIonoQual = " 0";
164  strIonoQual = "-1";
165 
166  sigmaGD2add = obs->baseline()->getSigma2add(DT_DELAY);
167  sigmaPR2add = 0.0;
168  effectiveGDSigma = sqrt(
169  o->grDelay().getSigma()*o->grDelay().getSigma() +
170  o->grDelay().getIonoSigma()*o->grDelay().getIonoSigma() +
171  sigmaGD2add*sigmaGD2add);
172 
173  effectivePRSigma = sqrt(
174  o->phDRate().getSigma()*o->phDRate().getSigma() +
175  o->phDRate().getIonoSigma()*o->phDRate().getIonoSigma() +
176  sigmaPR2add);
177 
178  // first record:
179  // 1 2 3 4 5 6 7
180  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
181  //YEBES40M ZELENCHK 1803+784 2012 01 26 18 30 30.0000000000 101
182  str.sprintf("%-8s %-8s %-8s %04d %02d %02d %02d %02d %14.10f %8d01",
183  qPrintable(o->stn_1()->getKey()), qPrintable(o->stn_2()->getKey()),
184  qPrintable(o->src()->getKey()),
185  yr, month, day, hr, min, sec,
186  i+1);
187  ts << str << "\r\n";
188 
189  // second record:
190  // 1 2 3 4 5 6 7
191  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
192  // 311082.58351570 .00174 -160030.5984109248 .00382 0 I 102
193  str.sprintf("%20.8f%10.5f%20.10f%10.5f%2s I %8d02",
194  (o->grDelay().getValue() + o->grDelay().ambiguity())*1.0e9,
195  o->grDelay().getSigma()*1.0e9,
196  o->phDRate().getValue()*1.0e12, o->phDRate().getSigma()*1.0e12,
197  qPrintable(strQual),
198  i+1);
199  ts << str << "\r\n";
200 
201  // third record:
202  // 1 2 3 4 5 6 7
203  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
204  // .00612 .00000 .00000 .00000 -1.665895811950809 0. 103
205  str.sprintf("%10.5f .00000 .00000 .00000 %19.15f 0.%8d03",
206  o->getCorrCoeff(),
207  o->getTotalPhase(),
208  i+1);
209  ts << str << "\r\n";
210 
211  // fourth record:
212  // 1 2 3 4 5 6 7
213  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
214  // .00 .0 .00 .0 .00 .0 .00 .0 104
215  str.sprintf(" .00 .0 .00 .0 .00 .0 .00 .0 %8d04",
216  i+1);
217  ts << str << "\r\n";
218 
219  // fifth record:
220  // 1 2 3 4 5 6 7
221  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
222  // .00343 -.01793 .00000 .00000 .00000 .00000 105
223  str.sprintf("%10.5f%10.5f .00000 .00000 .00000 .00000 %8d05",
224  obs->auxObs_1()->getCableCalibration()*1.0e9,
225  obs->auxObs_2()->getCableCalibration()*1.0e9,
226 // ???
227 // obs->auxObs_1()->getCableCalibration()*st1i->getCableCalMultiplier()*1.0e9,
228 // obs->auxObs_2()->getCableCalibration()*st2i->getCableCalMultiplier()*1.0e9,
229  i+1);
230  ts << str << "\r\n";
231 
232  // sixth record:
233  // 1 2 3 4 5 6 7
234  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
235  // 4.085 -8.990 911.093 882.400 78.146 74.630 0 0 106
236  str.sprintf("%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f 0 0 %8d06",
239  obs->auxObs_1()->getMeteoData().getPressure(),
240  obs->auxObs_2()->getMeteoData().getPressure(),
241  obs->auxObs_1()->getMeteoData().getRelativeHumidity()*100.0,
242  obs->auxObs_2()->getMeteoData().getRelativeHumidity()*100.0,
243  i+1);
244  ts << str << "\r\n";
245 
246  // eigth record:
247  // 1 2 3 4 5 6 7
248  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
249  // 1.2235335897 .00321 -.0311519821 .00530 0 108
250  str.sprintf("%20.10f%10.5f%20.10f%10.5f %2s %8d08",
251  o->grDelay().getIonoValue()*1.0e9,
252  o->grDelay().getIonoSigma()*1.0e9,
253  o->phDRate().getIonoValue()*1.0e12,
254  o->phDRate().getIonoSigma()*1.0e12,
255  qPrintable(strIonoQual),
256  i+1);
257  ts << str << "\r\n";
258 
259  // ninth record:
260  // 1 2 3 4 5 6 7
261  //01234567890123456789012345678901234567890123456789012345678901234567890123456789
262  // 311082.58351570 .05262 -160030.5984109248 .10084 0 I 109
263  str.sprintf("%20.8f%10.5f%20.10f%10.5f%2s I %8d09",
264  (o->grDelay().getValue() + o->grDelay().ambiguity())*1.0e9,
265  effectiveGDSigma*1.0e9,
266  o->phDRate().getValue()*1.0e12,
267  effectivePRSigma*1.0e12,
268  qPrintable(strQual),
269  i+1);
270  ts << str << "\r\n";
271  };
272  };
273 
274  ts.setDevice(NULL);
275  f.close();
276 
277 
278  SgMJD finisEpoch(SgMJD::currentMJD());
280  "::exportDataIntoNgsFile(): data have been exported into the NGS cards format file \"" + fileName +
281  "\", elapsed time: " + QString("").sprintf("%.2f", (finisEpoch - startEpoch)*86400000.0) + " ms");
282 
283  return true;
284 };
285 /*=====================================================================================================*/
286 
287 
288 
289 
290 
291 /*=====================================================================================================*/
292 //
293 // constants:
294 //
295 
296 
297 
298 /*=====================================================================================================*/
299 
300 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
@ Z_AXIS
Definition: SgMathSupport.h:81
@ X_AXIS
Definition: SgMathSupport.h:81
@ Y_AXIS
Definition: SgMathSupport.h:81
QMap< QString, SgVlbiSourceInfo * >::iterator SourcesByName_it
QMap< QString, SgVlbiStationInfo * >::iterator StationsByName_it
@ DT_DELAY
Definition: SgWrmsable.h:44
double at(DIRECTION i) const
Definition: Sg3dVector.h:91
bool isAttr(uint a) const
Definition: SgAttribute.h:226
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
Definition: SgMJD.h:59
double getTime() const
Definition: SgMJD.h:455
int getDate() const
Definition: SgMJD.h:447
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
static void MJD_reverse(int date, double time, int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec)
Definition: SgMJD.cpp:75
double getPressure() const
Definition: SgMeteoData.h:242
double getTemperature() const
Definition: SgMeteoData.h:234
double getRelativeHumidity() const
Definition: SgMeteoData.h:250
double getSigma2add(DataType) const
Definition: SgObjectInfo.h:367
const QString & getKey() const
Definition: SgObjectInfo.h:319
@ Attr_NOT_VALID
omit the observation;
Definition: SgObservation.h:78
double getCableCalibration() const
const SgMeteoData & getMeteoData() const
int getInputFileVersion() const
Definition: SgVlbiBand.h:344
double getFrequency() const
Definition: SgVlbiBand.h:320
short int getUnweightFlag() const
double ambiguity() const
double getValue() const
double getSigma() const
double getIonoValue() const
double getIonoSigma() const
SgVlbiStationInfo *& stn_2()
SgVlbiStationInfo *& stn_1()
SgVlbiMeasurement & phDRate()
SgVlbiSourceInfo *& src()
double getTotalPhase() const
double getCorrCoeff() const
SgVlbiMeasurement & grDelay()
@ Attr_NOT_MATCHED
there is no match at another band(s)
SgVlbiAuxObservation * auxObs_2()
SgVlbiBaselineInfo * baseline()
SgVlbiObservable * primeObs()
SgVlbiAuxObservation * auxObs_1()
const QString & getName() const
StationsByName stationsByName_
bool exportDataIntoNgsFile(const QString &fileName)
QList< SgVlbiObservation * > observations_
SgVlbiBand * primaryBand_
static QString className()
SourcesByName sourcesByName_
double getRA() const
double getDN() const
double getAxisOffset() const
const Sg3dVector & getR()
MountingType getMntType() const