General Purpose Geodetic Library
SgVlbiSession.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 
27 #include <QtCore/QDataStream>
28 #include <QtCore/QRegularExpression>
29 
30 
31 #if QT_VERSION >= 0x050000
32 # include <QtWidgets/QMessageBox>
33 #else
34 # include <QtGui/QMessageBox>
35 #endif
36 
37 
38 
39 #include <SgVlbiSession.h>
40 
41 #include <SgAPrioriData.h>
42 #include <SgCubicSpline.h>
43 #include <SgEccDat.h>
44 #include <SgEccRec.h>
45 #include <SgLogger.h>
46 #include <SgMasterRecord.h>
47 #include <SgTaskConfig.h>
48 #include <SgVector.h>
49 #include <SgVersion.h>
50 #include <SgVlbiBand.h>
51 #include <SgVlbiNetworkId.h>
52 #include <SgVlbiObservation.h>
53 
54 
55 
56 // aux functions:
60 
61 
62 
63 const QString SgVlbiSession::sSkipCode_("---");
64 
65 
66 
67 /*=======================================================================================================
68 *
69 * METHODS:
70 *
71 *======================================================================================================*/
72 //
73 // static first:
75 {
76  return "SgVlbiSession";
77 };
78 
79 
80 
81 // CONSTRUCTORS:
82 //
83 // A constructor:
86  bands_(),
87  bandByKey_(),
88  observations_(),
89  scanEpochs_(),
90  observationByKey_(),
91  stationsByName_(),
92  baselinesByName_(),
93  sourcesByName_(),
94  tRefer_(tZero),
95  storedConfig_(),
96  lastProcessedConfig_(),
97  stationsByIdx_(),
98  baselinesByIdx_(),
99  sourcesByIdx_(),
100  calcInfo_(),
101  path2Masterfile_("./"),
102  path2APrioriFiles_("./"),
103  apStationPositions_(SgAPriories::DT_STN_POS),
104  apStationVelocities_(SgAPriories::DT_STN_VEL),
105  apSourcePositions_(SgAPriories::DT_SRC_POS),
106  apSourceStrModel_(SgAPriories::DT_SRC_SSM),
107  apAxisOffsets_(SgAPriories::DT_AXS_OFS),
108  apHiFyEop_(),
109  apStationGradients_(SgAPriories::DT_STN_GRD),
110  externalWeights_(),
111  externalErpFile_(),
112  contemporaryHistory_(),
113  skyFreqByIfId_(),
114  userCorrectionsUse_(),
115  userCorrectionsName_(),
116  lastProcessed_(tZero)
117 {
118  hasOceanTideContrib_ = false;
119  hasPoleTideContrib_= false;
120  hasEarthTideContrib_= false;
121  hasWobblePxContrib_= false;
122  hasWobblePyContrib_= false;
123  hasWobbleNutContrib_= false;
125  hasUt1HighFreqContrib_ = false;
126  hasFeedCorrContrib_= false;
127  hasTiltRemvrContrib_= false;
128  hasPxyLibrationContrib_ = false;
129  hasUt1LibrationContrib_ = false;
130  hasOceanPoleTideContrib_ = false;
131  hasGpsIonoContrib_ = false;
132  hasPoleTideOldContrib_ = false;
133  hasOceanTideOldContrib_ = false;
134  hasNdryContrib_= false;
135  hasNwetContrib_= false;
136  hasUnPhaseCalContrib_= false;
137  hasGradPartials_ = false;
138  hasCipPartials_ = false;
139 // calcVersionValue_ = 0.0;
140  primaryBand_ = NULL;
141 
142  // config & descriptor of parameters:
143  config_ = NULL;
144  parametersDescriptor_ = NULL;
145 
146  leapSeconds_ = 0.0;
147 
148  // parameters:
149  pPolusX_ = NULL;
150  pPolusY_ = NULL;
151  pUT1_ = NULL;
152  pUT1Rate_ = NULL;
153  pPolusXRate_ = NULL;
154  pPolusYRate_ = NULL;
155  pNutX_ = NULL;
156  pNutY_ = NULL;
157  pNutXRate_ = NULL;
158  pNutYRate_ = NULL;
159 
160  reporter_ = NULL;
161  numOfParameters_ = 0;
163  numOfDOF_= 0;
164 
166  hasOutlierRestoratioRun_ = false;
167 
168  have2InteractWithGui_ = false;
169  longOperationStart_ = NULL;
170  longOperationProgress_ = NULL;
171  longOperationStop_ = NULL;
172  longOperationMessage_ = NULL;
174 
176 
177  args4Ut1Interpolation_ = NULL;
178  tabs4Ut1Interpolation_ = NULL;
179  hasUt1Interpolation_ = false;
180  args4PxyInterpolation_ = NULL;
181  tabs4PxyInterpolation_ = NULL;
182  hasPxyInterpolation_ = false;
184  innerUt1Interpolator_ = NULL;
185  innerPxyInterpolator_ = NULL;
187  isAble2InterpolateErp_ = false;
188 
189  inputDriver_ = NULL;
190 };
191 
192 
193 
194 // A destructor:
196 {
198  stationsByIdx_.clear();
199  baselinesByIdx_.clear();
200  sourcesByIdx_.clear();
201 
202  primaryBand_ = NULL;
203  for (StationsByName_it i=stationsByName_.begin(); i!=stationsByName_.end(); ++i)
204  delete i.value();
205  stationsByName_.clear();
206 
207  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
208  delete i.value();
209  baselinesByName_.clear();
210 
211  for (SourcesByName_it i=sourcesByName_.begin(); i!=sourcesByName_.end(); ++i)
212  delete i.value();
213  sourcesByName_.clear();
214 
215  // not an onwer:
216  config_ = NULL;
217  parametersDescriptor_ = NULL;
218  inputDriver_ = NULL;
219 
220  // free bands:
221  for (int i=0; i<bands_.size(); i++)
222  delete bands_.at(i);
223  bands_.clear();
224  bandByKey_.clear();
225 
226  // free observations:
227  observationByKey_.clear();
228  for (int i=0; i<observations_.size(); i++)
229  delete observations_.at(i);
230  observations_.clear();
231 
232  for (int i=0; i<scanEpochs_.size(); i++)
233  delete scanEpochs_.at(i);
234  scanEpochs_.clear();
235 
237  {
238  delete args4Ut1Interpolation_;
239  args4Ut1Interpolation_ = NULL;
240  };
242  {
243  delete tabs4Ut1Interpolation_;
244  tabs4Ut1Interpolation_ = NULL;
245  };
247  {
248  delete args4PxyInterpolation_;
249  args4PxyInterpolation_ = NULL;
250  };
252  {
253  delete tabs4PxyInterpolation_;
254  tabs4PxyInterpolation_ = NULL;
255  };
257  {
258  delete innerUt1Interpolator_;
259  innerUt1Interpolator_ = NULL;
260  };
262  {
263  delete innerPxyInterpolator_;
264  innerPxyInterpolator_ = NULL;
265  };
267  {
270  };
271  skyFreqByIfId_.clear();
272  userCorrectionsUse_.clear();
273  userCorrectionsName_.clear();
274 };
275 
276 
277 
278 // FUNCTIONS:
279 //
280 //
282 {
283  tMean_ = (tStart_.toDouble() + tFinis_.toDouble())/2.0;
284 };
285 
286 
287 
288 //
290 {
291  return bands_.size();
292 };
293 
294 
295 
296 //
298 {
299  QString eopPrefix = "EOP: ";
301  pPolusX_ = new SgParameter(eopPrefix + "P_x, mas");
302  pPolusY_ = new SgParameter(eopPrefix + "P_y, mas");
303  pUT1_ = new SgParameter(eopPrefix + "dUT1, ms");
304  pUT1Rate_ = new SgParameter(eopPrefix + "dUT1Rate, ms/day");
305  pPolusXRate_ = new SgParameter(eopPrefix + "dPxRate, mas/day");
306  pPolusYRate_ = new SgParameter(eopPrefix + "dPyRate, mas/day");
307  pNutX_ = new SgParameter(eopPrefix + "dX, mas");
308  pNutY_ = new SgParameter(eopPrefix + "dY, mas");
309  pNutXRate_ = new SgParameter(eopPrefix + "dXRate, mas/day");
310  pNutYRate_ = new SgParameter(eopPrefix + "dYRate, mas/day");
311 
312  for (StationsByName_it i=stationsByName_.begin(); i!=stationsByName_.end(); ++i)
313  {
314  i.value()->createParameters();
315  i.value()->clockBreaks().setT0(tRefer_);
316  };
317  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
318  i.value()->createParameters();
319  // The sky is a neighborhood
320  for (SourcesByName_it i=sourcesByName_.begin(); i!=sourcesByName_.end(); ++i)
321  i.value()->createParameters();
322  // So keep it down
323 
324 /*
325  // later, remove this part:
326  for (int i=0; i<bands_.size(); i++)
327  {
328  SgVlbiBand *band=bands_.at(i);
329  for (StationsByName_it it=band->stationsByName().begin(); it!=band->stationsByName().end(); ++it)
330  it.value()->createParameters();
331  };
332  //
333 */
334 };
335 
336 
337 
338 //
340 {
341  for (StationsByName_it i=stationsByName_.begin(); i!=stationsByName_.end(); ++i)
342  i.value()->releaseParameters();
343  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
344  i.value()->releaseParameters();
345  for (SourcesByName_it i=sourcesByName_.begin(); i!=sourcesByName_.end(); ++i)
346  i.value()->releaseParameters();
347 /*
348  // later, remove this part:
349  for (int i=0; i<bands_.size(); i++)
350  {
351  SgVlbiBand *band=bands_.at(i);
352  for (StationsByName_it it=band->stationsByName().begin(); it!=band->stationsByName().end(); ++it)
353  it.value()->releaseParameters();
354  };
355  //
356 */
357  if (pPolusX_)
358  {
359  delete pPolusX_;
360  pPolusX_ = NULL;
361  };
362  if (pPolusY_)
363  {
364  delete pPolusY_;
365  pPolusY_ = NULL;
366  };
367  if (pUT1_)
368  {
369  delete pUT1_;
370  pUT1_ = NULL;
371  };
372  if (pUT1Rate_)
373  {
374  delete pUT1Rate_;
375  pUT1Rate_ = NULL;
376  };
377  if (pPolusXRate_)
378  {
379  delete pPolusXRate_;
380  pPolusXRate_ = NULL;
381  };
382  if (pPolusYRate_)
383  {
384  delete pPolusYRate_;
385  pPolusYRate_ = NULL;
386  };
387  if (pNutX_)
388  {
389  delete pNutX_;
390  pNutX_ = NULL;
391  };
392  if (pNutY_)
393  {
394  delete pNutY_;
395  pNutY_ = NULL;
396  };
397 
398  if (pNutXRate_)
399  {
400  delete pNutXRate_;
401  pNutXRate_ = NULL;
402  };
403  if (pNutYRate_)
404  {
405  delete pNutYRate_;
406  pNutYRate_ = NULL;
407  };
408 };
409 
410 
411 
412 //
413 bool SgVlbiSession::checkChannelSetup(bool guiExpected)
414 {
415  //
416  QMap<QString, QList<QString> >
417  strLstByBand;
418  int num=0;
419  QString str("");
420  //
421  // collect info:
422  for (int i=0; i<bands_.size(); i++)
423  {
424  SgVlbiBand *band=bands_.at(i);
425  for (BaselinesByName_it it=band->baselinesByName().begin(); it!=band->baselinesByName().end(); ++it)
426  {
427  SgVlbiBaselineInfo *bi=it.value();
428  if (!bi->numOfChanByCount().size())
430  "::checkChannelSetup(): cannot check channels for baseline " + bi->getKey() +
431  ", the numOfChanByCount map is empty");
432  else if (bi->numOfChanByCount().size() > 1)
433  {
434  num = bi->observables().size();
435  str = bi->getKey() + ": ";
436  for (QMap<int, int>::const_iterator jt=bi->numOfChanByCount().begin();
437  jt!=bi->numOfChanByCount().end(); ++jt)
438  str += QString("").sprintf("%d (%.1f%%), ", jt.key(), jt.value()*100.0/num);
439  str = str.left(str.size() - 2);
440  strLstByBand[band->getKey()] << str;
441  };
442  };
443  };
444  //
445  // make a report:
446  if (strLstByBand.size())
447  {
448  QString str("");
450  "::checkChannelSetup(): the session has a mixed channel setup:");
451  for (QMap<QString, QList<QString> >::iterator it=strLstByBand.begin(); it!=strLstByBand.end(); ++it)
452  {
453  const QList<QString>& strLst=it.value();
454  QString key=it.key();
455  str += "Numbers of channels at the " + key + "-band: \n";
456  for (int i=0; i<strLst.size(); i++)
457  {
458  str += "\t" + strLst.at(i) + "\n";
460  "::checkChannelSetup(): " + key + "-band: " + strLst.at(i));
461  };
462  str += "\n";
463  };
464  //
465  if (guiExpected)
466  QMessageBox::warning(NULL, "Warning: mixed channels setup",
467  "The session contains mixed channels setup for the following baseline(s):\n\n" + str +
468  "\nSometimes this happens by mistake, you may need to report it to the correlator.");
469  }
470  else
472  "::checkChannelSetup(): the session is ok");
473  //
474  strLstByBand.clear();
475  return true;
476 };
477 
478 
479 
480 //
481 bool SgVlbiSession::selfCheck(bool guiExpected)
482 {
483  QVector<QChar> abetka;
484  QString str("");
485  double dTmp;
486  bool isOk=true;
487  SgMJD t(tZero);
488  int numBands(bands().size());
489  QRegularExpression reOldDbName("(\\d{2})([A-Z]{3})(\\d{2})([A-Z0-9]{1,2})");
490  QRegularExpression reNewDbName("(\\d{8})-([\\S]{2,12})");
491  QRegularExpressionMatch match;
492 
493 
494  abetka.resize(14);
495  abetka[ 0] = 'a';
496  abetka[ 1] = 'b';
497  abetka[ 2] = 'c';
498  abetka[ 3] = 'd';
499  abetka[ 4] = 'e';
500  abetka[ 5] = 'f';
501  abetka[ 6] = 'g';
502  abetka[ 7] = 'h';
503  abetka[ 8] = 'i';
504  abetka[ 9] = 'j';
505  abetka[10] = 'k';
506  abetka[11] = 'l';
507  abetka[12] = 'm';
508  abetka[13] = 'n';
510  "::selfCheck(): the operation started", true);
511 
512  // make selfcheck here:
513  if (!observations_.size()) // there is no observations at all
514  {
516  "::selfCheck(): the session [" + name_ + "] does not contain any observations");
517  return false;
518  };
519  // sort in wavelength order:
520  qSort(bands_.begin(), bands_.end(), wavelengthSortingOrderLessThan);
521 
522 
523  //
524  // check for deselected stations (the info is in baselines)
526 
527  //
528  // set up a primary band:
529  if (!primaryBand_)
531  QString pBandKey(primaryBand_->getKey());
533  "::selfCheck(): the " + pBandKey + "-band is set as the primary one");
534  //
535  QMap<QString, QMap<QString, QString> >
536  scanNameByIdByStn;
537  QMap<QString, QMap<QString, int> >
538  numByScanIdBySrc;
539  int iObs;
540  dTmp = 0.0;
541  iObs = 0;
542  //
543  // process the data in time order:
544  for (QMap<QString, SgVlbiObservation*>::iterator it=observationByKey_.begin();
545  it!=observationByKey_.end(); ++it, iObs++)
546  {
547  SgVlbiObservation *obs=it.value();
548  if (obs->getMediaIdx() == -1)
549  obs->setMediaIdx(iObs);
550  // mark unmatched observables:
551  if (obs->observableByKey().size() != numBands)
553  // set up identities:
554  obs->setupIdentities();
555  obs->setupActiveObservable(pBandKey);
556  obs->selfCheck();
557  scanNameByIdByStn[obs->stn_1()->getKey()][obs->getScanId()] = obs->getScanName();
558  scanNameByIdByStn[obs->stn_2()->getKey()][obs->getScanId()] = obs->getScanName();
559  numByScanIdBySrc[obs->src()->getKey()][obs->getScanId()]++;
560  dTmp += obs->getDTecStdDev();
561  /*
562  SgVlbiObservable *pbObs=obs->primeObs();
563  if (pbObs)
564  {
565 
566  };
567  */
568  };
570  "::selfCheck(): the identities of observations were set up", true);
571  //
572  if (dTmp > 0.0)
573  {
576  "::selfCheck(): found dTec values");
577  };
578  //
579  // and sort it:
580  //
581 //-> if (originType_==OT_MK4 || originType_==OT_KOMB)
583 //-> else
584 //-> qSort(observations_.begin(), observations_.end(), observationSortingOrderLessThan);
585 
587  "::selfCheck(): the observations were sorted", true);
588 
589  //
590  // collect scan epochs and check scan names:
591  // This is a new session, check and adjust scan names:
592  QMap<QString, QString> scanIdByName;
593  QMap<QString, QMap<QString, QString> >
594  duplicateByName;
595  for (int i=0; i<observations_.size(); i++)
596  {
597  SgVlbiObservation *obs=observations_.at(i);
598  if (t != obs->getMJD())
599  {
600  t = obs->getMJD();
601  scanEpochs_.append(new SgMJD(t));
602  };
603  // collect scan names:
604  if (!scanIdByName.contains(obs->getScanName()))
605  scanIdByName.insert(obs->getScanName(), obs->getScanId());
606  else if (scanIdByName[obs->getScanName()] != obs->getScanId())
607  {
608  if (!duplicateByName.contains(obs->getScanName()))
609  duplicateByName[obs->getScanName()].insert(scanIdByName[obs->getScanName()], obs->getScanName());
610  duplicateByName[obs->getScanName()].insert(obs->getScanId(), obs->getScanName());
611  };
612  };
614  "::selfCheck(): " + QString("").setNum(scanEpochs_.size()) +
615  " scans have been found in the session", true);
616  //
617  // Check for duplicate scan names:
618  if (duplicateByName.size())
619  {
621  "::selfCheck(): found " + QString("").setNum(duplicateByName.size()) +
622  " duplicate scan names:", true);
623  for (QMap<QString, QMap<QString, QString> >::iterator it=duplicateByName.begin();
624  it!=duplicateByName.end(); ++it)
625  {
626  int idx=0;
627  for (QMap<QString, QString>::iterator jt=it.value().begin(); jt!=it.value().end(); ++jt, idx++)
628  {
630  "::selfCheck(): the scan ID " + jt.key() + " has a scan name \"" + jt.value() + "\"");
631  // alter the scan name:
632  if (originType_==OT_KOMB)
633  {
634  str = jt.value().simplified() + abetka[idx];
635  jt.value() = str;
636  };
637  };
638  };
639  // correct scan names:
640  if (originType_==OT_KOMB)
641  {
642  QString oldScanName("");
643  for (int i=0; i<observations_.size(); i++)
644  {
645  SgVlbiObservation *obs=observations_.at(i);
646  if (duplicateByName.contains(obs->getScanName()))
647  {
648  oldScanName = obs->getScanName();
649  if (!duplicateByName.value(obs->getScanName()).contains(obs->getScanId()))
651  "::selfCheck(): cannot find the corrected scan name for scan ID " + obs->getScanId() +
652  " and scan name \"" + oldScanName + "\"");
653  else
654  {
655  str = duplicateByName.value(obs->getScanName())[obs->getScanId()];
656  if (str.size())
657  {
658  obs->setScanName(str);
660  "::selfCheck(): the scan name of " + obs->getScanId() +
661  " scan has been changed from \"" + oldScanName + "\" to \"" + str + "\"");
662  }
663  else
665  "::selfCheck(): the corrected scan name is empty for scan ID " + obs->getScanId() +
666  " and scan name \"" + oldScanName + "\"");
667  };
668  }
669  };
670  };
671  };
672  scanIdByName.clear();
673  duplicateByName.clear();
674  //
675  //
676  //
677  // set up band-dependent stuff:
678  int numChan=0, bitsPerSample=0;
679  double rbw=0.0;
680  for (int i=0; i<numBands; i++)
681  {
682  bands_.at(i)->selfCheck();
683  numChan += bands_.at(i)->getMaxNumOfChannels();
684  rbw += bands_.at(i)->getMaxNumOfChannels()*bands_.at(i)->sampleRate();
685  if (bitsPerSample == 0)
686  bitsPerSample = bands_.at(i)->bitsPerSample();
687  else if (bitsPerSample != bands_.at(i)->bitsPerSample())
689  "::selfCheck(): at the " + bands_.at(i)->getKey() +
690  "-band there is a different value for bits per sample: " +
691  QString("").sprintf("%d vs %d", bitsPerSample, bands_.at(i)->bitsPerSample()));
692  };
694  "::selfCheck(): the selfcheck procedure for the bands was done", true);
695  // set up the recording mode:
696  recordingMode_.sprintf("NChan:%d Rbw:%.1f Bps:%d", numChan, rbw*1.0e-6, bitsPerSample);
698  "::selfCheck(): the record mode has been set to \"" + recordingMode_ + "\"");
699 
700 
701  //
702  // calculate baseline length:
704  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
705  {
706  SgVlbiBaselineInfo *bi=i.value();
707  SgVlbiStationInfo *si1=NULL, *si2=NULL;
708  str = bi->getKey().left(8);
709  if (stationsByName_.contains(str))
710  si1 = stationsByName_.value(str);
711  else
713  "::selfCheck(): cannot find the station \"" + str + "\" in the map", true);
714  str = bi->getKey().right(8);
715  if (stationsByName_.contains(str))
716  si2 = stationsByName_.value(str);
717  else
719  "::selfCheck(): cannot find the station \"" + str + "\" in the map", true);
720  if (si1 && si2)
721  {
722  bi->setLength((si2->getR() - si1->getR()).module());
724  "::selfCheck(): set the length of the baseline \"" + bi->getKey() + "\" to " +
725  QString("").sprintf("%.3f (m)", bi->getLength()));
726  };
727  };
728  //
729  // set up a clock reference attribute for the session:
730  SgVlbiStationInfo *bandRC=NULL;
731  for (StationsByName_it it=stationsByName_.begin(); it!=stationsByName_.end(); ++it)
732  if (it.value()->isAttr(SgVlbiStationInfo::Attr_REFERENCE_CLOCKS))
733  bandRC = it.value();
734  if (!bandRC) // there is no presetupped RC staion on a session level, pick one:
735  {
736  for (int i=0; i<numBands; i++)
737  {
738  SgVlbiBand *band=bands_.at(i);
739  for (StationsByName_it it=band->stationsByName().begin(); it!=band->stationsByName().end(); ++it)
740  if (it.value()->isAttr(SgVlbiStationInfo::Attr_REFERENCE_CLOCKS))
741  bandRC = it.value();
742  };
743  if (bandRC) // one of bands has one of stations with RC-flag
745  };
746  if (bandRC && config_ && config_->getIsSolveCompatible())
747  stationsByName_[bandRC->getKey()]->setClocksModelOrder(0);
749  "::selfCheck(): a reference clock station has been set up", true);
750 
751 
752  // set up proper time of creation:
753  t = tZero;
754  for (int i=0; i<numBands; i++)
755  {
756  if (!bands_.at(i)->observables().size()) // there is no observations at some band
757  {
759  "::selfCheck(): the band " + bands_.at(i)->getKey() +
760  " at the session " + name_ + " does not contain any observations");
761  return false;
762  };
763  if (t<bands_.at(i)->getTCreation())
764  t = bands_.at(i)->getTCreation();
765  };
766  //
767  // set up correct tStart and tFinis:
768  tStart_ = observations_.at(0)->getMJD();
769  tFinis_ = observations_.at(observations_.size() - 1)->getMJD();
770  setTCreation(t); // set up "creation time" to the oldest from the bands
771  calcTMean();
772  setupTimeRefer();
774  "::selfCheck(): epochs of start/finish were established", true);
775  //
776  //
777  // check masterfile:
778  SgMasterRecord mr;
780  {
781  // if user explicitly specified the database name:
782  if (name_!="unnamed" && 2<name_.size())
783  {
785  "::selfCheck(): trying to check the provided by a user the database name \"" + name_ + "\"");
787  {
788  sessionCode_ = mr.getCode();
789  sessionType_ = mr.getType();
790  officialName_ = mr.getName();
791  if (correlatorName_.size() == 0)
796  "::selfCheck(): a corresponding masterfile record was found");
797  }
798  else
800  "::selfCheck(): cannot find a masterfile record for the database \"" + name_ + "\"");
801  }
802  else
803  {
804  QString sYear;
805  int year(tStart_.calcYear());
806 
807  if (getExpectedMasterfileVersion() == 2) // version 2.0 of masterfile
808  sYear.sprintf("%04d", year);
809  else
810  sYear.sprintf("%02d", year - (year>=2000?2000:1900)); // version 1.0 of masterfile
812  {
814  "::selfCheck(): a masterfile record was found");
815 
816  if (getExpectedMasterfileVersion() == 2) // version 2.0 of masterfile
817  name_ = sYear + QString("").sprintf("%02d%02d", tStart_.calcMonth(), tStart_.calcDay()) +
818  "-" + mr.getCode().toLower();
819  else
820  name_ = sYear + mr.getDate() + mr.getDbcCode(); // version 1.0 of masterfile
821 
822  networkSuffix_ = "+";
823  officialName_ = mr.getName();
824  if (mr.getType().size())
825  sessionType_ = mr.getType();
826  if (correlatorName_.size() == 0)
830  }
831  else
833  "::selfCheck(): cannot find a masterfile record for the session code \"" + sessionCode_ + "\"");
834  };
836  "::selfCheck(): for the session code: " + sessionCode_ +
837  ", the following attributes were assigned:");
839  "::selfCheck(): type: " + sessionType_);
841  "::selfCheck(): name: " + name_);
843  "::selfCheck(): official name: " + officialName_);
845  "::selfCheck(): scheduler/correlator/submitter: " +
847  }
848  else
849  {
851  {
852  sessionCode_ = mr.getCode();
853  sessionType_ = mr.getType();
854  officialName_ = mr.getName();
855  if (correlatorName_.size() == 0)
860  "::selfCheck(): a masterfile record was found");
861  }
862  else
863  {
865  "::selfCheck(): cannot find a masterfile record for the session [" + name_ + "] ");
866  };
868  "::selfCheck(): for the session name: " + name_ +
869  ", the following attributes were assigned:");
871  "::selfCheck(): code: " + sessionCode_);
873  "::selfCheck(): type: " + sessionType_);
875  "::selfCheck(): official name: " + officialName_);
877  "::selfCheck(): scheduler/correlator/submitter: " +
878  schedulerName_ + "/" + correlatorName_ + "/" + submitterName_, true);
879  };
880  //
881  //
882  //
883  // check for Eccs:
885  {
887  "::selfCheck(): skipping the eccentricities set up: incomplete data set ", true);
888  }
889  else if (config_)
890  {
892  if (config_->getEccentricitiesFileName().size() > 0)
893  {
895  if (config_->getEccentricitiesFileName().at(0) == '/')
896  eccDat.setPath2File("");
897  };
898  eccDat.importEccFile();
900  "::selfCheck(): the eccentricity file was read", true);
901  for (StationsByName_it it=stationsByName_.begin(); it!=stationsByName_.end(); ++it)
902  {
903  SgVlbiStationInfo *si=it.value();
904  if (!si->eccRec())
905  {
906  SgEccRec *eccRec=eccDat.lookupRecord(si->getKey(), tRefer_);
907  if (eccRec) // setup eccentricity:
908  {
909  si->eccRec() = new SgEccRec(*eccRec);
910  si->setCdpNumber(eccRec->getNCdp());
911  if (eccRec->getDR().module() > 0.0)
912  si->adjustEccVector();
915  "::selfCheck(): set up the eccentricity for the station " + si->getKey());
916  }
917  else
918  {
919  si->eccRec() = new SgEccRec();
921  "::selfCheck(): cannot find the eccentricity record for the station " + si->getKey());
922  };
923  };
924  };
926  "::selfCheck(): the eccentricities of stations were set up", true);
927  };
928  //
929  //
930  //
931  //
932  // check for the external a priori data:
934  {
935  //
936  }
937  else if (config_)
938  {
941  "::selfCheck(): the external a priori were collected", true);
942 
943  // lookup a file with external weights:
947  "::selfCheck(): the file with external weights was read", true);
948  };
949  //
950  //
951  // perform station set up:
952  // check for different observations of a station at the same epoch (a rare case, just for curiosity),
953  for (StationsByName_it it=stationsByName_.begin(); it!=stationsByName_.end(); ++it)
954  {
955  SgVlbiStationInfo *si=it.value();
956  si->checkAuxObs(scanNameByIdByStn[si->getKey()]);
957 // if (parametersDescriptor_)
958 // {
959 // si->pcClocks()->setPMode(parametersDescriptor_->getClock0Mode());
960 // si->pcZenith()->setPMode(parametersDescriptor_->getZenithMode());
961 // };
962  };
964  "::selfCheck(): the auxiliary observations were checked", true);
965  //
966  // sources:
967  //
968  //for (QMap<QString, QMap<QString, int> >::iterator it=numByScanIdBySrc.begin();
969  // it!=numByScanIdBySrc.end(); ++it)
970  //{
971  // std::cout << " +++ source " << qPrintable(it.key()) << ":\n";
972  // for (QMap<QString, int>::iterator jt=it.value().begin(); jt!=it.value().end(); ++jt)
973  // std::cout << " " << qPrintable(jt.key()) << " => " << jt.value() << "\n";
974  //};
975  for (SourcesByName_it it=sourcesByName_.begin(); it!=sourcesByName_.end(); ++it)
976  {
977  SgVlbiSourceInfo *si=it.value();
978  if (numByScanIdBySrc.contains(si->getKey()))
979  si->setTotalScanNum(numByScanIdBySrc.value(si->getKey()).size());
980  else
981  {
982  str = si->getKey();
983  // the source have no any observations on the primary band, remove it from the maps:
984  --it;
985  sourcesByName_.remove(str);
986  delete si;
988  "::selfCheck(): the source \"" + str + "\" has no any good observations in the primary band"
989  ", it was removed from the whole session");
990  };
991  };
993  "::selfCheck(): numbers of scans per a source were calculated", true);
994 
995  //
996  //
997  if (calcInfo_.stations().size()==0)
998  {
999  calcInfo_.stations() = stationsByName_.values();
1001  "::selfCheck(): the calcInfo's list of stations is empty; set it up: " +
1002  QString("").setNum(calcInfo_.stations().size()) + " stations in the list");
1003  };
1004  //
1005  // guess the network ID:
1006  guessNetworkId();
1008  "::selfCheck(): the network ID was set up", true);
1009  //
1010  checkChannelSetup(guiExpected);
1012  "::selfCheck(): the session selfcheck has been completed", true);
1013  //
1014  return isOk;
1015 };
1016 
1017 
1018 
1019 //
1021 {
1022  if (tStart_ == tFinis_) // trivial case
1023  tRefer_ = tStart_;
1024  else if (tStart_.getDate() != tFinis_.getDate()) // set tRefer to midnight:
1025  {
1026  tRefer_ = tFinis_;
1027  tRefer_.setTime(0); // 0hr
1028  }
1029  else
1030  {
1031  int nYr_s, nMon_s, nDay_s, nHr_s, nMi_s;
1032  int nYr_f, nMon_f, nDay_f, nHr_f, nMi_f;
1033  double dSec_s, dSec_f;
1034 
1035  tStart_.toYMDHMS_tr(nYr_s, nMon_s, nDay_s, nHr_s, nMi_s, dSec_s);
1036  tFinis_.toYMDHMS_tr(nYr_f, nMon_f, nDay_f, nHr_f, nMi_f, dSec_f);
1037  //
1038  if (nHr_s == nHr_f)
1039  {
1040  if (20 < nMi_f-nMi_s)
1041  nMi_s = 10*round(double(nMi_s + nMi_f)/20.0);
1042  else
1043  nMi_s = round(double(nMi_s + nMi_f)/2.0);
1044  }
1045  else if (nHr_s+1 == nHr_f)
1046  {
1047  if (nMi_s > 20)
1048  {
1049  nHr_s++;
1050  nMi_s = 0;
1051  }
1052  else
1053  nMi_s = 30;
1054  }
1055  else
1056  {
1057  nHr_s = round(double(nHr_s + nHr_f)/2.0);
1058  nMi_s = 0;
1059  };
1060 
1061  tRefer_.setUpEpoch(nYr_s, nMon_s, nDay_s, nHr_s, nMi_s, 0.0);
1062  };
1064  "::setupTimeRefer(): the reference epoch was set to " + tRefer_.toString());
1065 };
1066 
1067 
1068 
1069 //
1071 {
1072  if (!bands_.size())
1073  return;
1074  if (idx<0 || bands_.size()<=idx)
1075  return;
1076  for (int i=0; i<bands_.size(); i++)
1077  {
1078  if (i==idx)
1079  {
1080  primaryBand_ = bands_.at(i);
1082  }
1083  else
1084  if (bands_.at(i)->isAttr(SgVlbiBand::Attr_PRIMARY))
1085  bands_.at(i)->delAttr(SgVlbiBand::Attr_PRIMARY);
1086  };
1087 };
1088 
1089 
1090 
1091 //
1093 {
1094  // there is no any band:
1095  if (!bands_.size())
1096  return;
1097 
1098  // one band, trivia:
1099  if (bands_.size()==1)
1100  {
1101  primaryBand_ = bands_.at(0);
1103  return;
1104  };
1105  int numOfPrimaryBands=0;
1106  for (int i=0; i<bands_.size(); i++)
1107  if (bands_.at(i)->isAttr(SgVlbiBand::Attr_PRIMARY))
1108  {
1109  primaryBand_ = bands_.at(i);
1110  numOfPrimaryBands++;
1111  };
1112  if (numOfPrimaryBands==1) // ok, there is one pband, just return;
1113  return;
1114 
1115  if (numOfPrimaryBands>1) // something get wrong, clear flags and set up pband
1116  for (int i=0; i<bands_.size(); i++)
1117  bands_.at(i)->delAttr(SgVlbiBand::Attr_PRIMARY);
1118  primaryBand_ = NULL;
1119  for (int i=0; i<bands_.size(); i++)
1120  {
1121  if (bands_.at(i)->getKey() == "X")
1122  {
1123  primaryBand_ = bands_.at(i);
1125  };
1126  };
1127  if (!primaryBand_) // "X"-band was not found
1128  {
1129  primaryBand_ = bands_.at(0); // first element, highest freq
1131  };
1132 };
1133 
1134 
1135 
1136 //
1138 {
1139  // clear statistics:
1140  // common observations:
1141  for (StationsByName_it i=stationsByName_.begin(); i!=stationsByName_.end(); ++i)
1142  {
1143  i.value()->clearWrms();
1144  QMap<QString, SgVlbiAuxObservation*>::iterator auxObsIt=i.value()->auxObservationByScanId()->begin();
1145  for (; auxObsIt!=i.value()->auxObservationByScanId()->end(); ++auxObsIt)
1146  {
1147  SgVlbiAuxObservation *auxObs=auxObsIt.value();
1148  auxObs->setEstClocks(0.0);
1149  auxObs->setEstClocksSigma(0.0);
1150  auxObs->setEstZenithDelay(0.0);
1151  auxObs->setEstZenithDelaySigma(0.0);
1152  auxObs->setEstAtmGradN(0.0);
1153  auxObs->setEstAtmGradNSigma(0.0);
1154  auxObs->setEstAtmGradE(0.0);
1155  auxObs->setEstAtmGradESigma(0.0);
1157  };
1158  };
1159  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
1160  i.value()->clearWrms();
1161  for (SourcesByName_it i=sourcesByName_.begin(); i!=sourcesByName_.end(); ++i)
1162  i.value()->clearWrms();
1163  // per band observations:
1164  for (int iBand=0; iBand<bands_.size(); iBand++)
1165  {
1166  SgVlbiBand *band=bands_.at(iBand);
1167  band->clearWrms();
1168  for (StationsByName_it i=band->stationsByName().begin(); i!=band->stationsByName().end(); ++i)
1169  i.value()->clearWrms();
1170  for (BaselinesByName_it i=band->baselinesByName().begin(); i!=band->baselinesByName().end(); ++i)
1171  i.value()->clearWrms();
1172  for (SourcesByName_it i=band->sourcesByName().begin(); i!=band->sourcesByName().end(); ++i)
1173  i.value()->clearWrms();
1174  };
1175 };
1176 
1177 
1178 
1179 //
1181 {
1182  if (!observations_.size())
1183  return;
1184  for (int i=0; i<observations_.size(); i++)
1185  observations_.at(i)->calcIonoCorrections(cfg);
1186  if (cfg)
1187  {
1190  addAttr(Attr_FF_AMBIGS_RESOLVED); // assume ambigs are ok so set the flag on.
1191  };
1192 };
1193 
1194 
1195 
1196 //
1198 {
1199  for (int i=0; i<observations_.size(); i++)
1200  observations_.at(i)->zerofyIono();
1203 };
1204 
1205 
1206 
1207 //
1209 {
1210  for (int iBand=0; iBand<bands_.size(); iBand++)
1211  {
1212  SgVlbiBand *band=bands_.at(iBand);
1213  QMap<QString, SgVlbiBaselineInfo*>::iterator itBaselineInfo=band->baselinesByName().begin();
1214  for (int iBaseline=0; itBaselineInfo!=band->baselinesByName().end(); ++itBaselineInfo, iBaseline++)
1215  {
1216  SgVlbiBaselineInfo *baselineInfo=itBaselineInfo.value();
1217  if (baselineInfo && !baselineInfo->isAttr(SgVlbiBaselineInfo::Attr_NOT_VALID))
1218  baselineInfo->calculateClockF1(config_);
1219  };
1220  };
1221 };
1222 
1223 
1224 
1225 //
1227 {
1228  double sig4bln4del=0.0, sig4bln4rat=0.0, sig4bnd4del=0.0, sig4bnd4rat=0.0;
1230  {
1231  sig4bnd4del = config_->getInitAuxSigma4Delay();
1232  sig4bnd4rat = config_->getInitAuxSigma4Rate();
1233  }
1235  {
1236  sig4bln4del = config_->getInitAuxSigma4Delay();
1237  sig4bln4rat = config_->getInitAuxSigma4Rate();
1238  }
1239  else
1240  {
1241  //
1242  };
1243  for (int iBand=0; iBand<bands_.size(); iBand++)
1244  {
1245  bands_.at(iBand)->setSigma2add(DT_DELAY, sig4bnd4del);
1246  bands_.at(iBand)->setSigma2add(DT_RATE, sig4bnd4rat);
1247  for (BaselinesByName_it jt=bands_.at(iBand)->baselinesByName().begin();
1248  jt!=bands_.at(iBand)->baselinesByName().end(); ++jt)
1249  {
1250  jt.value()->setSigma2add(DT_DELAY, sig4bln4del);
1251  jt.value()->setSigma2add(DT_RATE, sig4bln4rat);
1252  };
1253  };
1254  for (BaselinesByName_it i=baselinesByName_.begin(); i!=baselinesByName_.end(); ++i)
1255  {
1256  i.value()->setSigma2add(DT_DELAY, sig4bln4del);
1257  i.value()->setSigma2add(DT_RATE, sig4bln4rat);
1258  };
1259 };
1260 
1261 
1262 
1263 /*
1264 QString SgVlbiSession::nickName()
1265 {
1266  QString str(name_);
1267  //
1268  if (name_.at(0) == '$')
1269  str.remove(0, 1);
1270  //
1271  if (bands_.size() == 2)
1272  {
1273  str = str.mid(0, 7);
1274  str += primaryBand_->getKey() + networkSuffix_;
1275  };
1276  //
1277  return str;
1278 };
1279 */
1280 
1281 
1282 //
1283 void SgVlbiSession::resetAllEditings(bool have2resetConfig)
1284 {
1285  // Attributes:
1295 
1296 
1297  // bands:
1298  for (int i=0; i<bands_.size(); i++)
1299  bands_.at(i)->resetAllEditings();
1300  //
1301  // stations:
1302  for (QMap<QString, SgVlbiStationInfo*>::const_iterator it=stationsByName_.begin();
1303  it!=stationsByName_.end(); ++it)
1304  it.value()->resetAllEditings();
1305  //
1306  // sources:
1307  for (QMap<QString, SgVlbiSourceInfo*>::const_iterator it=sourcesByName_.begin();
1308  it!=sourcesByName_.end(); ++it)
1309  it.value()->resetAllEditings();
1310  //
1311  // baselines:
1312  for (QMap<QString, SgVlbiBaselineInfo*>::const_iterator it=baselinesByName_.begin();
1313  it!=baselinesByName_.end(); ++it)
1314  it.value()->resetAllEditings();
1315  //
1316  // observations:
1317  for (int i=0; i<observations_.size(); i++)
1318  observations_.at(i)->resetAllEditings();
1319  //
1320  // config:
1321  if (have2resetConfig)
1322  *config_ = storedConfig_; // ? do we need to reset the config at all?
1323  //
1324  // parameterization:
1326  //
1328  //
1330  *ap=(config_->apByNetId().contains(networkID_)?
1331  &config_->apByNetId()[networkID_] :
1333  if (ap->doSessionSetup_)
1334  {
1338  };
1339  //
1340  numOfParameters_ = 0;
1341  numOfConstraints_= 0;
1342  numOfDOF_= 0;
1343  //
1345  "::resetAllEditings(): all editings have been cleared");
1346 };
1347 
1348 
1349 
1350 //
1351 QString SgVlbiSession::name4SirFile(bool isThroughCatalog)
1352 {
1353  QString str(name_);
1354  QString altName(config_->getName());
1355  if (altName.size() > 0)
1356  altName += ".";
1357  str += QString("").sprintf("_V%03d_M%02d_C%c.%ssir",
1358  primaryBand_->getInputFileVersion(), (int)originType_, isThroughCatalog?'Y':'N',
1359  qPrintable(altName));
1360  return str;
1361 };
1362 
1363 
1364 
1365 //
1367 {
1368  s << name_ << getAttributes();
1369  if (s.status() != QDataStream::Ok)
1370  {
1372  "::saveIntermediateResults(): error writting data");
1373  return false;
1374  };
1375  // store the current version too:
1377  {
1379  "::saveIntermediateResults(): error writting data for the version");
1380  return false;
1381  };
1382  //
1383  // bands:
1384  for (int i=0; i<bands_.size(); i++)
1385  {
1386  if (!bands_.at(i)->saveIntermediateResults(s))
1387  {
1389  "::saveIntermediateResults(): error writting data for " + bands_.at(i)->getKey() + "-band: " +
1390  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1391  return false;
1392  };
1393  }
1394  //
1395  // stations:
1396  for (QMap<QString, SgVlbiStationInfo*>::const_iterator it=stationsByName_.begin();
1397  it!=stationsByName_.end(); ++it)
1398  if (!it.value()->saveIntermediateResults(s))
1399  {
1401  "::saveIntermediateResults(): error writting data for station " + it.value()->getKey() + ": " +
1402  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1403  return false;
1404  };
1405  //
1406  // sources:
1407  for (QMap<QString, SgVlbiSourceInfo*>::const_iterator it=sourcesByName_.begin();
1408  it!=sourcesByName_.end(); ++it)
1409  if (!it.value()->saveIntermediateResults(s))
1410  {
1412  "::saveIntermediateResults(): error writting data for source " + it.value()->getKey() + ": " +
1413  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1414  return false;
1415  };
1416  //
1417  // baselines:
1418  for (QMap<QString, SgVlbiBaselineInfo*>::const_iterator it=baselinesByName_.begin();
1419  it!=baselinesByName_.end(); ++it)
1420  if (!it.value()->saveIntermediateResults(s))
1421  {
1423  "::saveIntermediateResults(): error writting data for baseline " + it.value()->getKey() + ": " +
1424  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1425  return false;
1426  };
1427  //
1428  // observations:
1429  for (int i=0; i<observations_.size(); i++)
1430  if (!observations_.at(i)->saveIntermediateResults(s))
1431  {
1433  "::saveIntermediateResults(): error writting data for observation " +
1434  observations_.at(i)->getKey() + ": " +
1435  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1436  return false;
1437  };
1438  //
1439  // config:
1441  {
1443  "::saveIntermediateResults(): error writting data for config: " +
1444  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1445  return false;
1446  };
1447  //
1448  // parameterization:
1450  {
1452  "::saveIntermediateResults(): error writting data for parameters setup: " +
1453  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1454  return false;
1455  };
1456 
1457  return s.status() == QDataStream::Ok;
1458 };
1459 
1460 
1461 
1462 //
1464 {
1465  QString name;
1466  unsigned int attributes;
1467  SgVersion version(libraryVersion);
1468  s >> name >> attributes;
1469  if (s.status() != QDataStream::Ok)
1470  {
1472  "::loadIntermediateResults(): error reading data: " +
1473  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1474  return false;
1475  };
1476  if (getName() != name)
1477  {
1479  "::loadIntermediateResults(): error reading data: wrong session, names mismatch: got [" + name +
1480  "], expected [" + getName() + "]");
1481  return false;
1482  };
1483  if (!version.loadIntermediateResults(s))
1484  {
1486  "::loadIntermediateResults(): error reading data for version: " +
1487  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1488  return false;
1489  };
1490 /*
1491  if (version != libraryVersion)
1492  {
1493  logger->write(SgLogger::ERR, SgLogger::IO_BIN, className() +
1494  "::loadIntermediateResults(): version mismatch, wouldn't dare to read that file");
1495  return false;
1496  };
1497 */
1498  if (version != libraryVersion)
1499  {
1501  "::loadIntermediateResults(): version mismatch, could get a problem");
1502 // return false;
1503  };
1504  //
1505  // bands:
1506  for (int i=0; i<bands_.size(); i++)
1507  if (!bands_.at(i)->loadIntermediateResults(s))
1508  {
1510  "::loadIntermediateResults(): error writting data for " + bands_.at(i)->getKey() + "-band: " +
1511  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1512  return false;
1513  };
1514  //
1515  // stations:
1516  for (QMap<QString, SgVlbiStationInfo*>::const_iterator it=stationsByName_.begin();
1517  it!=stationsByName_.end(); ++it)
1518  if (!it.value()->loadIntermediateResults(s))
1519  {
1521  "::loadIntermediateResults(): error writting data for station " + it.value()->getKey() + ": " +
1522  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1523  return false;
1524  };
1525  //
1526  // sources:
1527  for (QMap<QString, SgVlbiSourceInfo*>::const_iterator it=sourcesByName_.begin();
1528  it!=sourcesByName_.end(); ++it)
1529  if (!it.value()->loadIntermediateResults(s))
1530  {
1532  "::loadIntermediateResults(): error writting data for source " + it.value()->getKey() + ": " +
1533  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1534  return false;
1535  };
1536  //
1537  // baselines:
1538  for (QMap<QString, SgVlbiBaselineInfo*>::const_iterator it=baselinesByName_.begin();
1539  it!=baselinesByName_.end(); ++it)
1540  if (!it.value()->loadIntermediateResults(s))
1541  {
1543  "::loadIntermediateResults(): error writting data for baseline " + it.value()->getKey() + ": " +
1544  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1545  return false;
1546  };
1547  //
1548  // observations:
1549  for (int i=0; i<observations_.size(); i++)
1550  if (!observations_.at(i)->loadIntermediateResults(s))
1551  {
1553  "::loadIntermediateResults(): error writting data for observation " +
1554  observations_.at(i)->getKey() + ": " +
1555  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1556  return false;
1557  };
1558  //
1559  // config:
1561  {
1563  "::loadIntermediateResults(): error writting data for config: " +
1564  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1565  return false;
1566  };
1567  //
1568  // parameterization:
1570  {
1572  "::loadIntermediateResults(): error writting data for parameters setup: " +
1573  (s.status()==QDataStream::ReadPastEnd?"read past end of the file":"read corrupt data"));
1574  return false;
1575  };
1576  //
1577  setAttributes(attributes);
1578  //
1579  return s.status()==QDataStream::Ok;
1580 };
1581 
1582 
1583 
1584 //
1586 {
1587  if (!bi)
1588  return false;
1589  if (baselinesByName_.contains(bi->getKey()))
1590  return !baselinesByName_.value(bi->getKey())->isAttr(SgVlbiBaselineInfo::Attr_NOT_VALID);
1591  else
1592  return false;
1593 };
1594 
1595 
1596 
1597 //
1599 {
1600  if (!si)
1601  return false;
1602  if (stationsByName_.contains(si->getKey()))
1603  return !stationsByName_.value(si->getKey())->isAttr(SgVlbiStationInfo::Attr_NOT_VALID);
1604  else
1605  return false;
1606 };
1607 
1608 
1609 
1610 //
1611 void SgVlbiSession::allocUt1InterpolEpochs(double t0, double dt, unsigned int numOfPts)
1612 {
1613  if (args4Ut1Interpolation_ && args4Ut1Interpolation_->n() != numOfPts)
1614  {
1615  delete args4Ut1Interpolation_;
1616  args4Ut1Interpolation_ = NULL;
1618  "::allocUt1InterpolEpochs(): the vector of UT1 arguments has been deleted");
1619  };
1621  {
1622  args4Ut1Interpolation_ = new SgVector(numOfPts);
1624  "::allocUt1InterpolEpochs(): the vector of UT1 arguments has been created");
1625  };
1626  for (unsigned int i=0; i<numOfPts; i++)
1627  args4Ut1Interpolation_->setElement(i, t0 + dt*i);
1629  "::allocUt1InterpolEpochs(): the vector of UT1 arguments has been filled");
1630 };
1631 
1632 
1633 
1634 //
1635 void SgVlbiSession::allocPxyInterpolEpochs(double t0, double dt, unsigned int numOfPts)
1636 {
1637  if (args4PxyInterpolation_ && args4PxyInterpolation_->n() != numOfPts)
1638  {
1639  delete args4PxyInterpolation_;
1640  args4PxyInterpolation_ = NULL;
1642  "::allocPxyInterpolEpochs(): the vector of Pxy arguments has been deleted");
1643  };
1645  {
1646  args4PxyInterpolation_ = new SgVector(numOfPts);
1648  "::allocPxyInterpolEpochs(): the vector of Pxy arguments has been created");
1649  };
1650  for (unsigned int i=0; i<numOfPts; i++)
1651  args4PxyInterpolation_->setElement(i, t0 + dt*i);
1653  "::allocPxyInterpolEpochs(): the vector of Pxy arguments has been filled");
1654 };
1655 
1656 
1657 
1658 //
1660 {
1661  if (!vals)
1662  {
1664  "::allocUt1InterpolValues(): the input vector is NULL");
1665  return;
1666  };
1667  if (vals->n() == 0)
1668  {
1670  "::allocUt1InterpolValues(): the size of the input vector is zero");
1671  return;
1672  };
1673 
1674  if (tabs4Ut1Interpolation_ && tabs4Ut1Interpolation_->nRow() != vals->n())
1675  {
1676  delete tabs4Ut1Interpolation_;
1677  tabs4Ut1Interpolation_ = NULL;
1679  "::allocUt1InterpolValues(): the matrix of UT1 values has been deleted");
1680  };
1682  {
1683  tabs4Ut1Interpolation_ = new SgMatrix(vals->n(), 1);
1685  "::allocUt1InterpolValues(): the matrix of UT1 values has been created");
1686  };
1687  for (unsigned int i=0; i<vals->n(); i++)
1688  tabs4Ut1Interpolation_->setElement(i, 0, vals->getElement(i));
1690  "::allocUt1InterpolValues(): the matrix of UT1 values has been filled");
1691 };
1692 
1693 
1694 
1695 //
1697 {
1698  if (!vals)
1699  {
1701  "::allocPxyInterpolValues(): the input matrix is NULL");
1702  return;
1703  };
1704  if (vals->nRow()==0 || vals->nCol()!=2)
1705  {
1707  "::allocPxyInterpolValues(): the size of the input matrix is wrong");
1708  return;
1709  };
1711  {
1712  delete tabs4PxyInterpolation_;
1713  tabs4PxyInterpolation_ = NULL;
1715  "::allocPxyInterpolValues(): the matrix of Pxy values has been deleted");
1716  };
1718  {
1719  tabs4PxyInterpolation_ = new SgMatrix(vals->nRow(), 2);
1721  "::allocPxyInterpolValues(): the matrix of Pxy values has been created");
1722  };
1723  for (unsigned int i=0; i<vals->nRow(); i++)
1724  {
1725  tabs4PxyInterpolation_->setElement(i, 0, vals->getElement(i, 0));
1726  tabs4PxyInterpolation_->setElement(i, 1, vals->getElement(i, 1));
1727  };
1729  "::allocPxyInterpolValues(): the matrix of Pxy values has been filled");
1730 };
1731 
1732 
1733 
1734 
1735 
1736 /*=====================================================================================================*/
1737 
1738 
1739 
1740 
1741 
1742 
1743 /*=====================================================================================================*/
1744 //
1745 // AUX Functions:
1746 //
1747 /*=====================================================================================================*/
1748 // sorts bands by frequency:
1750 {
1751  return b1->getFrequency() > b2->getFrequency();
1752 };
1753 
1754 
1755 
1756 //
1758 {
1759  SgVlbiObservable *o1, *o2;
1760  o1 = obs1->primeObs();
1761  o2 = obs2->primeObs();
1762  if (obs1->getMJD() == obs2->getMJD())
1763  {
1764  if (o1 && o2)
1765  return o1->getMediaIdx() < o2->getMediaIdx();
1766  else
1767  return obs1->getMediaIdx() < obs2->getMediaIdx();
1768  };
1769  return obs1->getMJD() < obs2->getMJD();
1770 };
1771 
1772 
1773 
1774 //
1776 {
1777  if (obs1->getMJD() == obs2->getMJD())
1778  {
1779  if (obs1->src()->getKey() == obs2->src()->getKey())
1780  {
1781  if (obs1->stn_1()->getKey() == obs2->stn_1()->getKey())
1782  return obs1->stn_2()->getKey() < obs2->stn_2()->getKey();
1783  else
1784  return obs1->stn_1()->getKey() < obs2->stn_1()->getKey();
1785  }
1786  else
1787  return obs1->src()->getKey() < obs2->src()->getKey();
1788  };
1789  return obs1->getMJD() < obs2->getMJD();
1790 };
1791 /*=====================================================================================================*/
1792 
1793 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
const SgMJD tZero(1957, 10, 4)
SgVersion libraryVersion("SgLib", 0, 8, 2, "Compton Peak (rc2)", SgMJD(2023, 4, 3, 10, 59))
QMap< QString, SgVlbiBaselineInfo * >::iterator BaselinesByName_it
const QString defaultNetIdName
bool wavelengthSortingOrderLessThan(SgVlbiBand *, SgVlbiBand *)
bool observationSortingOrderLessThan4newSession(SgVlbiObservation *, SgVlbiObservation *)
bool observationSortingOrderLessThan(SgVlbiObservation *, SgVlbiObservation *)
QMap< QString, SgVlbiSourceInfo * >::iterator SourcesByName_it
QMap< QString, SgVlbiStationInfo * >::iterator StationsByName_it
@ DT_DELAY
Definition: SgWrmsable.h:44
@ DT_RATE
Definition: SgWrmsable.h:45
double module() const
Definition: Sg3dVector.h:99
bool isAttr(uint a) const
Definition: SgAttribute.h:226
void setAttributes(unsigned int a)
Definition: SgAttribute.h:191
unsigned int getAttributes() const
Definition: SgAttribute.h:183
void delAttr(uint a)
Definition: SgAttribute.h:210
void addAttr(uint a)
Definition: SgAttribute.h:202
SgEccRec * lookupRecord(const QString &, const SgMJD &)
Definition: SgEccDat.cpp:119
void setPath2File(const QString &)
Definition: SgEccDat.h:142
void setFileName(const QString &)
Definition: SgEccDat.h:150
void importEccFile()
Definition: SgEccDat.cpp:61
int getNCdp() const
Definition: SgEccRec.h:219
const Sg3dVector & getDR() const
Definition: SgEccRec.h:243
void setSessionName(const QString &)
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_BIN
Definition: SgLogger.h:64
@ IO_DBH
Definition: SgLogger.h:67
@ DATA
Definition: SgLogger.h:78
@ PREPROC
Definition: SgLogger.h:98
Definition: SgMJD.h:59
void setTime(double dTime)
Definition: SgMJD.cpp:166
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1008
double toDouble() const
Definition: SgMJD.h:531
void toYMDHMS_tr(int &nYear, int &nMonth, int &nDay, int &nHour, int &nMin, double &dSec) const
Definition: SgMJD.cpp:1306
int getDate() const
Definition: SgMJD.h:447
int calcDay() const
Definition: SgMJD.cpp:227
void setUpEpoch(int year, int month, int day, int hour, int min, double sec)
Definition: SgMJD.cpp:255
int calcMonth() const
Definition: SgMJD.cpp:216
int calcYear() const
Definition: SgMJD.cpp:205
const QString & getCorrelatedBy() const
const QString & getDate() const
bool lookupRecordByCode(const QString &sessionCode, const QString &sYear, const QString &path)
const QString & getScheduledBy() const
const QString & getName() const
const QString & getType() const
const QString & getCode() const
const QString & getDbcCode() const
const QString & getSubmittedBy() const
bool lookupRecordByName(const QString &nickName, const QString &path)
unsigned int nRow() const
Definition: SgMatrix.h:352
void setElement(unsigned int i, unsigned int j, double d)
Definition: SgMatrix.h:402
double getElement(unsigned int i, unsigned int j) const
Definition: SgMatrix.h:385
unsigned int nCol() const
Definition: SgMatrix.h:360
QList< SgVlbiStationInfo * > & stations()
Definition: SgModelsInfo.h:155
void clearWrms()
Definition: SgObjectInfo.h:550
const QString & getKey() const
Definition: SgObjectInfo.h:319
virtual int getMediaIdx() const
virtual void setMediaIdx(int idx)
@ Attr_PROCESSED
the observation has been processed;
Definition: SgObservation.h:79
virtual const SgMJD & getMJD() const
bool saveIntermediateResults(QDataStream &) const
bool loadIntermediateResults(QDataStream &)
const QString & getEccentricitiesFileName() const
bool saveIntermediateResults(QDataStream &) const
bool getIsSolveCompatible() const
Definition: SgTaskConfig.h:913
WeightCorrectionMode getWcMode() const
Definition: SgTaskConfig.h:945
QMap< QString, AutomaticProcessing > & apByNetId()
Definition: SgTaskConfig.h:637
double getInitAuxSigma4Delay() const
Definition: SgTaskConfig.h:243
const QString & getName() const
Definition: SgTaskConfig.h:825
double getInitAuxSigma4Rate() const
Definition: SgTaskConfig.h:244
bool loadIntermediateResults(QDataStream &)
unsigned int n() const
Definition: SgVector.h:327
void setElement(unsigned int i, double d)
Definition: SgVector.h:348
double getElement(unsigned int i) const
Definition: SgVector.h:362
bool loadIntermediateResults(QDataStream &)
Definition: SgVersion.cpp:99
bool saveIntermediateResults(QDataStream &) const
Definition: SgVersion.cpp:78
void setEstAtmGradESigma(double s)
void setEstClocksSigma(double e)
void setEstAtmGradNSigma(double s)
void setEstZenithDelaySigma(double e)
void setEstZenithDelay(double d)
QMap< QString, SgVlbiBaselineInfo * > & baselinesByName()
Definition: SgVlbiBand.h:376
QMap< QString, SgVlbiStationInfo * > & stationsByName()
Definition: SgVlbiBand.h:368
int getInputFileVersion() const
Definition: SgVlbiBand.h:344
QMap< QString, SgVlbiSourceInfo * > & sourcesByName()
Definition: SgVlbiBand.h:384
double getFrequency() const
Definition: SgVlbiBand.h:320
@ Attr_PRIMARY
the band is a primary band;
Definition: SgVlbiBand.h:60
void setLength(double l)
@ Attr_NOT_VALID
omit the baseline;
QList< SgVlbiObservable * > & observables()
void calculateClockF1(SgTaskConfig *)
const QMap< int, int > & numOfChanByCount() const
double getLength() const
int getMediaIdx() const
@ Attr_NOT_MATCHED
there is no match at another band(s)
SgVlbiStationInfo * stn_1()
SgVlbiSourceInfo * src()
void setScanName(const QString &sName)
double getDTecStdDev() const
virtual bool selfCheck()
void setupActiveObservable(const QString &)
SgVlbiStationInfo * stn_2()
SgVlbiObservable * primeObs()
const QString & getScanName() const
QMap< QString, SgVlbiObservable * > & observableByKey()
const QString & getScanId() const
const QString & getName() const
@ OT_MK4
observations are from Mk4-compatible correlator output;
@ OT_KOMB
observations are from KOMB output (generated by NICT, Japan);
QString officialName_
Official Name (from MasterFile)
@ Attr_FF_EDIT_INFO_MODIFIED
edit info has been modified by user;
@ Attr_FF_WEIGHTS_CORRECTED
weights have been corrected;
@ Attr_PRE_PROCESSED
the observations has been prepared for analysis;
@ Attr_FF_ION_C_CALCULATED
ionospheric corrections have been calculated;
@ Attr_FF_OUTLIERS_PROCESSED
outliers have been processed;
@ Attr_HAS_CALC_DATA
the theoretical values are available;
@ Attr_HAS_DTEC
the session contains diffTec values;
@ Attr_FF_AMBIGS_RESOLVED
ambiguities have been resolved;
@ Attr_FF_ECC_UPDATED
eccentricity data for one of stations were updated;
@ Attr_HAS_IONO_CORR
the theoretical values are available;
@ Attr_HAS_CLOCK_BREAKS
there is at least one clock break at one of stations;
void setTCreation(const SgMJD &t)
SgMJD tFinis_
last epoch of the observations;
QString networkID_
Network ID (a key);.
QString sessionType_
official session type (from Masterfile);
QString networkSuffix_
a char that specifies network (e.g., A, E, U, etc.);
QString sessionCode_
official session code (from Masterfile);
SgMJD tMean_
mean epoch of the observations;
QString schedulerName_
Name of resposible organization (from MasterFile)
QString correlatorName_
Correlator Name (from MasterFile)
OriginType originType_
type of origin of the imported file(s);
QString submitterName_
Name of resposible organization (from MasterFile)
QString name_
name of the session (e.g., 10JUL22XE);
SgMJD tStart_
first epoch of the observations;
QList< SgMJD * > scanEpochs_
void(* longOperationStart_)(int minStep, int maxStep, const QString &message)
int numberOfBands() const
StationsByName stationsByName_
bool hasOceanPoleTideContrib_
bool hasWobbleNutContrib_
SgParameter * pPolusYRate_
void allocPxyInterpolValues(const SgMatrix *vals)
QString path2Masterfile_
bool hasUt1LibrationContrib_
QMap< QString, SgVlbiObservation * > observationByKey_
SgParameter * pPolusX_
SgParameter * pNutYRate_
QList< SgVlbiBand * > & bands()
QList< SgVlbiBand * > bands_
QVector< bool > userCorrectionsUse_
void setPrimaryBandByIdx(int)
SgTidalUt1::UT1TideContentType tabsUt1Type_
void calculateIonoCorrections(const SgTaskConfig *)
SgVector * args4PxyInterpolation_
double leapSeconds_
void(* longOperationProgress_)(int step)
bool hasGpsIonoContrib_
bool selfCheck(bool guiExpected)
virtual ~SgVlbiSession()
QMap< QString, SgVlbiBand * > bandByKey_
SgParameter * pPolusXRate_
bool hasOceanTideContrib_
QList< SgVlbiObservation * > observations_
void allocPxyInterpolEpochs(double t0, double dt, unsigned int numOfPts)
bool hasPoleTideOldContrib_
SgParameter * pNutY_
SgParameter * pPolusY_
bool hasWobblePxContrib_
void allocUt1InterpolEpochs(double t0, double dt, unsigned int numOfPts)
bool hasWobbleHighFreqContrib_
SgSolutionReporter * reporter_
bool saveIntermediateResults(QDataStream &) const
bool hasUnPhaseCalContrib_
void(* longOperationStop_)()
bool hasOutlierRestoratioRun_
QMap< int, SgVlbiStationInfo * > stationsByIdx_
virtual void setUpPrimaryBand()
QString name4SirFile(bool)
SgCubicSpline * externalErpInterpolator_
bool isInUse(SgVlbiBaselineInfo *)
SgParameter * pUT1Rate_
SgModelsInfo calcInfo_
SgParametersDescriptor storedParametersDescriptor_
SgExternalWeights externalWeights_
void(* longOperationMessage_)(const QString &message)
void resetAllEditings(bool have2resetConfig)
bool hasUt1HighFreqContrib_
void allocUt1InterpolValues(const SgVector *vals)
bool hasPxyInterpolation_
QMap< QString, double > skyFreqByIfId_
void zerofyIonoCorrections(const SgTaskConfig *)
SgCubicSpline * innerUt1Interpolator_
bool hasWobblePyContrib_
QVector< QString > userCorrectionsName_
static const QString sSkipCode_
BaselinesByName baselinesByName_
bool hasUt1Interpolation_
SgParametersDescriptor * parametersDescriptor_
void createParameters()
QString path2APrioriFiles_
SgVlbiBand * primaryBand_
bool hasPoleTideContrib_
SgIoDriver * inputDriver_
SgParameter * pUT1_
bool hasEarthTideContrib_
bool hasOutlierEliminationRun_
static QString className()
SgTaskConfig storedConfig_
virtual void calcTMean()
bool loadIntermediateResults(QDataStream &)
SgVector * args4Ut1Interpolation_
bool hasPxyLibrationContrib_
SgMatrix * tabs4Ut1Interpolation_
SgParameter * pNutX_
void(* longOperationShowStats_)(const QString &label, int numTot, int numPrc, double wrms, double chi2)
bool have2InteractWithGui_
SgParameter * pNutXRate_
int numOfPts4ErpInterpolation_
bool hasFeedCorrContrib_
QMap< int, SgVlbiBaselineInfo * > baselinesByIdx_
SourcesByName sourcesByName_
bool isAble2InterpolateErp_
SgCubicSpline * innerPxyInterpolator_
void releaseParameters()
void calculateBaselineClock_F1()
int getExpectedMasterfileVersion() const
SgTaskConfig * config_
bool hasTiltRemvrContrib_
bool hasOceanTideOldContrib_
SgMatrix * tabs4PxyInterpolation_
QMap< int, SgVlbiSourceInfo * > sourcesByIdx_
bool checkChannelSetup(bool guiExpected)
void setTotalScanNum(int n)
@ Attr_NOT_VALID
omit the station;
@ Attr_REFERENCE_CLOCKS
the clocks are the reference ones;
const Sg3dVector & getR()
void setCdpNumber(int cdp)
void checkAuxObs(const QMap< QString, QString > &scanNameById)