General Purpose Geodetic Library
SgVex.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) 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 <SgVex.h>
24 
25 
26 
27 #include <QtCore/QFile>
28 #include <QtCore/QRegularExpression>
29 
30 
31 
32 
33 
34 
35 
36 
37 /*======================================================================================================
38  *
39  * SgVexParameter implementation
40  *
41  *=====================================================================================================*/
42 //
43 // static first:
45 {
46  return "SgVexParameter";
47 };
48 
49 
50 
51 //
52 bool SgVexParameter::parseVexStatement(const QString& str)
53 {
54  QRegularExpression re("(\\S+)\\s*=\\s*(.*)");
55  QRegularExpressionMatch match=re.match(str);
56  if (match.hasMatch())
57  {
58  values_.clear();
59  key_ = match.captured(1).trimmed();
60  if (match.captured(2).size())
61  {
62  QList<QString> lst=match.captured(2).split(':');
63  for (int i=0; i<lst.size(); i++)
64  values_ << lst.at(i).trimmed();
65  };
66  }
67  else
68  return false;
69  return true;
70 };
71 /*=====================================================================================================*/
72 
73 
74 
75 
76 
77 
78 /*======================================================================================================
79  *
80  * SgVexRefSatement implementation
81  *
82  *=====================================================================================================*/
83 //
84 // static first:
86 {
87  return "SgVexRefSatement";
88 };
89 
90 
91 
92 //
93 bool SgVexRefSatement::parseVexStatement(const QString& str)
94 {
95  QRegularExpression re("ref\\s+(\\S+)\\s+=\\s+([^:]+):?(.*)");
96  QRegularExpressionMatch match=re.match(str);
97  if (match.hasMatch())
98  {
99  qualifiers_.clear();
100  qualifierByQ_.clear();
101  key_ = match.captured(1).trimmed();
102  value_ = match.captured(2).trimmed();
103  if (match.captured(3).size())
104  {
105  QList<QString> lst=match.captured(3).split(':');
106  for (int i=0; i<lst.size(); i++)
107  {
108  qualifiers_ << lst.at(i);
109  qualifierByQ_[lst.at(i)] = lst.at(i);
110  };
111  };
112  }
113  else
114  return false;
115  return true;
116 };
117 /*=====================================================================================================*/
118 
119 
120 
121 
122 
123 
124 /*======================================================================================================
125  *
126  * SgVexLiteralBlock implementation
127  *
128  *=====================================================================================================*/
129 //
130 // static first:
132 {
133  return "SgVexLiteralBlock";
134 };
135 
136 
137 
138 //
139 bool SgVexLiteralBlock::parseVex(const QList<QString>& statements, int& idx)
140 {
141  QRegularExpression reEnd("end_literal\\((.*)\\)$");
142  QRegularExpression re("^start_literal\\((.*)\\)");
143  QString str=statements.at(idx);
144  QRegularExpressionMatch match=re.match(str);
145  if (match.hasMatch())
146  {
147  literalStrings_.clear();
148  key_ = match.captured(1).trimmed();
149  while(++idx < statements.size() && !reEnd.match((str=statements.at(idx))).hasMatch() )
150  literalStrings_ << str;
151  }
152  else
153  return false;
155  "::parseVex(): literalBlock \"" + key_ + "\": collected " +
156  QString("").setNum(literalStrings_.size()) + " string(s)");
157 
158  return true;
159 };
160 /*=====================================================================================================*/
161 
162 
163 
164 
165 
166 
167 /*======================================================================================================
168  *
169  * SgVexRefSatement implementation
170  *
171  *=====================================================================================================*/
172 //
173 // static first:
175 {
176  return "SgVexDefBlock";
177 };
178 
179 
180 
181 //
182 SgVexDefBlock::SgVexDefBlock(const SgVexDefBlock& df) : key_(df.key_)
183 {
184  for (int i=0; i<df.refStatements_.size(); i++)
185  {
187  refStatements_ << rs;
188  refsByKey_.insertMulti(rs->getKey(), rs);
189  };
190  for (int i=0; i<df.parameters_.size(); i++)
191  {
192  SgVexParameter *par=new SgVexParameter(*df.parameters_.at(i));
193  parameters_ << par;
194  parsByKey_.insertMulti(par->getKey(), par);
195  };
196  for (int i=0; i<df.literalas_.size(); i++)
197  literalas_ << new SgVexLiteralBlock(*df.literalas_.at(i));
198 };
199 
200 
201 
202 
204 {
205  refsByKey_.clear();
206  parsByKey_.clear();
207  for (int i=0; i<refStatements_.size(); i++)
208  delete refStatements_.at(i);
209  for (int i=0; i<parameters_.size(); i++)
210  delete parameters_.at(i);
211  for (int i=0; i<literalas_.size(); i++)
212  delete literalas_.at(i);
213  refStatements_.clear();
214  parameters_.clear();
215  literalas_.clear();
216 };
217 
218 
219 
220 //
221 bool SgVexDefBlock::parseVex(const QList<QString>& statements, int& idx)
222 {
223  const QString strEndDef("enddef");
224  bool isOk=false;
225  QString str=statements.at(idx);
229  QRegularExpression reDef("^def\\s+(.+)");
230  QRegularExpression reRef("^ref\\s+(.+)");
231  QRegularExpression reLit("start_literal\\(");
232 //QRegularExpression reEndDef("enddef");
233  QRegularExpressionMatch match=reDef.match(str);
234  if (match.hasMatch())
235  {
236  refStatements_.clear();
237  parameters_.clear();
238  literalas_.clear();
239  key_ = match.captured(1).trimmed();
240 
241  while(++idx < statements.size() && (str=statements.at(idx)) != strEndDef)
242  {
243  if (reRef.match(str).hasMatch() && rs->parseVexStatement(str))
244  {
245  refStatements_ << rs;
246  refsByKey_.insertMulti(rs->getKey(), rs);
247  rs = new SgVexRefSatement;
248  }
249  else if (reLit.match(str).hasMatch() && lit->parseVex(statements, idx))
250  {
251  literalas_ << lit;
252  lit = new SgVexLiteralBlock;
253  }
254  else if (par->parseVexStatement(str))
255  {
256  parameters_ << par;
257  parsByKey_.insertMulti(par->getKey(), par);
258  par = new SgVexParameter;
259  }
260  else
262  "::parseVex(): encountered an unknown statement \"" + str + "\"");
263  };
264  isOk = true;
265  };
267  "::parseVex(): defBlock \"" + key_ + "\": collected " + QString("").setNum(refStatements_.size()) +
268  " ref(s) and " + QString("").setNum(parameters_.size()) + " par(s)");
269 
270  return isOk;
271 };
272 /*=====================================================================================================*/
273 
274 
275 
276 
277 
278 
279 
280 /*======================================================================================================
281  *
282  * SgVexScanBlock implementation
283  *
284  *=====================================================================================================*/
285 //
286 // static first:
288 {
289  return "SgVexScanBlock";
290 };
291 
292 
293 
294 //
295 bool SgVexScanBlock::parseVex(const QList<QString>& statements, int& idx)
296 {
297  const QString strEndScan("endscan");
298  bool isOk=false;
299  QString str=statements.at(idx);
301  QRegularExpression reScan("^scan\\s+(.+)");
302  QRegularExpressionMatch match=reScan.match(str);
303  if (match.hasMatch())
304  {
305  parameters_.clear();
306  key_ = match.captured(1).trimmed();
307 
308  while(++idx < statements.size() && (str=statements.at(idx)) != strEndScan)
309  {
310  if (par->parseVexStatement(str))
311  {
312  parameters_ << par;
313  par = new SgVexParameter;
314  }
315  else
317  "::parseVex(): encountered an unknown statement \"" + str + "\"");
318  };
319  isOk = true;
320  };
322  "::parseVex(): scanBlock \"" + key_ + "\": collected " + QString("").setNum(parameters_.size()) +
323  " par(s)");
324 
325  return isOk;
326 };
327 /*=====================================================================================================*/
328 
329 
330 
331 
332 
333 
334 
335 /*======================================================================================================
336  *
337  * SgVexSection implementation
338  *
339  *=====================================================================================================*/
340 //
341 // static first:
342 const QString SgVexSection::className()
343 {
344  return "SgVexSection";
345 };
346 
347 
348 
350 {
351  refByKey_.clear();
352  defByKey_.clear();
353  scanByKey_.clear();
354 
355  for (int i=0; i<refStatements_.size(); i++)
356  delete refStatements_.at(i);
357  for (int i=0; i<defBlocks_.size(); i++)
358  delete defBlocks_.at(i);
359  for (int i=0; i<scanBlocks_.size(); i++)
360  delete scanBlocks_.at(i);
361  statements_.clear();
362  refStatements_.clear();
363  defBlocks_.clear();
364  scanBlocks_.clear();
365 };
366 
367 
368 
369 //
370 bool SgVexSection::parseVex(const QList<QString>& statements, int& idx)
371 {
372  while(idx < statements.size() && statements.at(idx).at(0)!='$')
373  statements_ << statements.at(idx++);
374 
375  refStatements_.clear();
376  defBlocks_.clear();
377  scanBlocks_.clear();
378 
379  QRegularExpression reRef("^ref\\s+(.+)");
380  QRegularExpression reDef("^def\\s+(.+)");
381  QRegularExpression reScn("^scan\\s+(.+)");
382 
386  for (int i=0; i<statements_.size(); i++)
387  {
388  if (reDef.match(statements_.at(i)).hasMatch() && df->parseVex(statements_, i))
389  {
390  defBlocks_ << df;
391  defByKey_[df->getKey()] = df;
392  df = new SgVexDefBlock;
393  }
394  else if (reRef.match(statements_.at(i)).hasMatch() && rs->parseVexStatement(statements_.at(i)))
395  {
396  refStatements_ << rs;
397  refByKey_.insertMulti(rs->getKey(), rs);
398  rs = new SgVexRefSatement;
399  }
400  else if (reScn.match(statements_.at(i)).hasMatch() && sb->parseVex(statements_, i))
401  {
402  scanBlocks_ << sb;
403  scanByKey_[sb->getKey()] = sb;
404  sb = new SgVexScanBlock;
405  }
406  else
407  std::cout << " ++ unparsed [" << qPrintable(statements_.at(i)) << "]\n";
408  };
410  "::parseVex(): section \"" + key_ + "\": collected " + QString("").setNum(defBlocks_.size()) +
411  " def(s), " + QString("").setNum(refStatements_.size()) + " ref(s) and " +
412  QString("").setNum(scanBlocks_.size()) + " scan(s)");
413 
414  return true;
415 };
416 /*=====================================================================================================*/
417 
418 
419 
420 
421 
422 
423 
424 
425 
426 
427 
428 /*======================================================================================================
429  *
430  * SgVexFile implementation
431  *
432  *=====================================================================================================*/
433 //
434 // static first:
435 const QString SgVexFile::className()
436 {
437  return "SgVexFile";
438 };
439 
440 
441 
442 //
444  inputFileName_(""),
445  exper_(""),
446  experName_(""),
447  experDescription_(""),
448  experNominalStart_(tZero),
449  experNominalStop_(tZero),
450  piName_(""),
451  piEmail_(""),
452  contactName_(""),
453  contactEmail_(""),
454  schedulerName_(""),
455  schedulerEmail_(""),
456  targetCorrelator_(""),
457  sections_(),
458  sectionByName_(),
459  stnSetupById_()
460 {
461 
462 };
463 
464 
465 
466 //
467 SgVexFile::SgVexFile(const QString& inputFileName) :
468  inputFileName_(inputFileName),
469  exper_(""),
470  experName_(""),
471  experDescription_(""),
472  experNominalStart_(tZero),
473  experNominalStop_(tZero),
474  piName_(""),
475  piEmail_(""),
476  contactName_(""),
477  contactEmail_(""),
478  schedulerName_(""),
479  schedulerEmail_(""),
480  targetCorrelator_(""),
481  sections_(),
482  stnSetupById_()
483 {
484 
485 };
486 
487 
488 
489 
490 //
492 {
493  for (int i=0; i<sections_.size(); i++)
494  delete sections_.at(i);
495  sections_.clear();
496  stnSetupById_.clear();
497 };
498 
499 
500 
501 //
502 bool SgVexFile::parseVexFile(const QString& fileName)
503 {
504  bool isOk=false;
505  if (fileName.size())
506  inputFileName_ = fileName;
507 
508 
509  QFile f(inputFileName_);
510  QString str("");
511 //QRegularExpression reComments("([^\\*.]*)\\*(.*)");
512  QRegularExpression reComments("([^\\*]*)\\*(.*)");
513 
514  if (f.open(QFile::ReadOnly))
515  {
516  QTextStream s(&f);
517  int strCount=0;
518  QString statement("");
519  statements_.clear();
520 
521 
522  while (!s.atEnd())
523  {
524  str = s.readLine().trimmed();
525  strCount++;
526 
527  QRegularExpressionMatch matchComments=reComments.match(str);
528  if (matchComments.hasMatch())
529  str = matchComments.captured(1).trimmed();
530 
531  // skip empty strings:
532  if (str.size())
533  {
534  if (str.contains(';'))
535  {
536  QList<QString> lst=str.split(';');
537  for (int i=0; i<lst.size(); i++)
538  {
539  str = lst.at(i).trimmed();
540  statement += str;
541  if (statement.size())
542  statements_.append(statement);
543  statement = "";
544  };
545  }
546  else
547  statement += str + " ";
548  };
549  };
551  "::parseVexFile(): read " + QString("").setNum(strCount) + " strings, " +
552  QString("").setNum(statements_.size()) + " statements from " + f.fileName());
553 
554 std::cout << "\n\n";
555 for (int i=0; i<statements_.size(); i++)
556 std::cout << " " << i << ": [" << qPrintable(statements_.at(i)) << "]\n";
557 
558  s.setDevice(NULL);
559  };
560  f.close();
561 
562  //
563  if (statements_.size() < 2)
564  {
566  "::parseVexFile(): not enough statements to proceed");
567  return false;
568  };
569 
570  str = statements_.at(0);
571  if (str.left(9) != "VEX_rev =")
572  {
574  "::parseVexFile(): got unknown file type");
575  return false;
576  };
577 
578  // process sections:
579  int idx;
580  idx = 1;
581  while (idx < statements_.size() && parseSection(idx))
582  ;
583 
584 
585  for (int i=0; i<sections_.size(); i++)
586  {
587 std::cout << " ++ " << i << " -> " << qPrintable(sections_.at(i)->getKey())
588 << " n=" << sections_.at(i)->getDefBlocks().size()
589 << "\n";
590 
591  sectionByName_[sections_.at(i)->getKey()] = sections_.at(i);
592  };
593 
594  analyzeVex();
595 std::cout << " analyzed\n";
596 
597  return isOk;
598 };
599 
600 
601 
602 //
604 {
605  bool isOk;
606  isOk = true;
607 
608  if (statements_.at(idx).at(0) == '$')
609  {
610  SgVexSection *sect=new SgVexSection(statements_.at(idx++));
611  sections_ << sect;
612  sect->parseVex(statements_, idx);
613  }
614  else
615  {
617  "::parseSection(): unexpected begin of a section: \"" + statements_.at(idx) + "\", idx=" +
618  QString("").setNum(idx));
619  return false;
620  };
621  return isOk;
622 };
623 
624 
625 
626 //
628 {
629  QString str;
630  const QString snStation("$STATION");
631  const QString snBbc("$BBC");
632  const QString snFreq("$FREQ");
633  const QString snIf("$IF");
634  const QString snMode("$MODE");
635  const QString snSite("$SITE");
636  //
637  QList<QString> stations;
638  QMap<QString, QString> stationById;
640 
641 std::cout << " ++ 0\n";
642  if (!sectionByName_.contains(snStation))
643  {
645  "::analyzeVex(): canot find section \"" + snStation + "\", exitting");
646  return false;
647  };
648  if (!sectionByName_.contains(snBbc))
649  {
651  "::analyzeVex(): canot find section \"" + snBbc + "\", exitting");
652  return false;
653  };
654  if (!sectionByName_.contains(snFreq))
655  {
657  "::analyzeVex(): canot find section \"" + snFreq + "\", exitting");
658  return false;
659  };
660  if (!sectionByName_.contains(snIf))
661  {
663  "::analyzeVex(): canot find section \"" + snIf + "\", exitting");
664  return false;
665  };
666  if (!sectionByName_.contains(snMode))
667  {
669  "::analyzeVex(): canot find section \"" + snMode + "\", exitting");
670  return false;
671  };
672  if (!sectionByName_.contains(snSite))
673  {
675  "::analyzeVex(): canot find section \"" + snSite + "\", exitting");
676  return false;
677  };
678 
679 
680  const SgVexSection *sectStations=sectionByName_[snStation];
681  const SgVexSection *sectMode=sectionByName_[snMode];
682 
683  if (sectMode->getDefBlocks().size() != 1)
684  {
685 
686  };
687 
688  // one def in $mode secton:
689  const SgVexDefBlock *pModeDef=sectMode->getDefBlocks().at(0);
690 
691 
692 
693  for (int i=0; i<sectStations->getDefBlocks().size(); i++)
694  {
695  const SgVexDefBlock *pStnDef=sectStations->getDefBlocks().at(i);
696  const SgVexRefSatement *ref=lookupRef(pStnDef, snSite);
697  StationSetup* stnS;
698  if (!ref)
699  {
701  "::analyzeVex(): canot find \"" + snSite + "\" in \"" + pStnDef->getKey() + "\", exitting");
702  return false;
703  };
704  const SgVexDefBlock *pSiteDef=lookupDef(ref->getKey(), ref->getValue());
705  if (!pSiteDef)
706  {
708  "::analyzeVex(): canot find \"" + ref->getValue() + "\" in " + ref->getKey()
709  + ", exitting");
710  return false;
711  };
712  SgVexParameter *par;
713 
714  QString siteId(""), siteName("");
715 
716  par = pSiteDef->parsByKey().value("site_ID");
717  if (!par)
718  {
720  "::analyzeVex(): canot find \"site_ID\" in " + pSiteDef->getKey()
721  + ", exitting");
722  return false;
723  };
724  siteId = par->getValues().at(0);
725 
726  par = pSiteDef->parsByKey().value("site_name");
727  if (!par)
728  {
730  "::analyzeVex(): canot find \"site_ID\" in " + pSiteDef->getKey()
731  + ", exitting");
732  return false;
733  };
734  siteName = par->getValues().at(0);
735 
736  stationById[siteId] = siteName;
737 
738  const SgVexRefSatement *refFreq=lookupRef(pModeDef, snFreq, siteId);
739  const SgVexRefSatement *refIf=lookupRef(pModeDef, snIf, siteId);
740  const SgVexRefSatement *refBbc=lookupRef(pModeDef, snBbc, siteId);
741 
742  if (!refFreq)
743  {
745  "::analyzeVex(): canot find \"" + snFreq + "\" in \"" + snMode + "\" for " +
746  siteName + ", exitting");
747  return false;
748  };
749  if (!refIf)
750  {
752  "::analyzeVex(): canot find \"" + snIf + "\" in \"" + snMode + "\" for " +
753  siteName + ", exitting");
754  };
755  if (!refBbc)
756  {
758  "::analyzeVex(): canot find \"" + snBbc + "\" in \"" + snMode + "\" for " +
759  siteName + ", exitting");
760  };
761  stnS = new StationSetup;
762  stnSetupById_.insert(siteId, stnS);
763 
764 
765  // check IF:
766  const SgVexDefBlock *df=lookupDef(refIf->getKey(), refIf->getValue());
767  QList<SgVexParameter*> pars=df->parsByKey().values("if_def");
768  for (int i=0; i<pars.size(); i++)
769  {
770  IfSetup *ifS=ifSetup(pars.at(i));
771  stnS->ifs() << ifS;
772  };
773  //
774  // compose BBC:
775  df = lookupDef(refBbc->getKey(), refBbc->getValue());
776  pars = df->parsByKey().values("BBC_assign");
777  for (int i=0; i<pars.size(); i++)
778  {
779  BbcSetup *bbcS=bbcSetup(pars.at(i));
780  stnS->bbcs() << bbcS;
781  };
782  //
783  // and channels:
784  df = lookupDef(refFreq->getKey(), refFreq->getValue());
785  pars = df->parsByKey().values("chan_def");
786  for (int i=0; i<pars.size(); i++)
787  {
788  FreqSetup *freqS=freqSetup(pars.at(i));
789  stnS->freqs() << freqS;
790  };
791 
792 
793 
794  };
795 
796 
797 
798 
799  for (QMap<QString, QString>::iterator it=stationById.begin(); it!=stationById.end(); ++it)
800  {
801 std::cout << " :: got: [" << qPrintable(it.key()) << "] -> [" << qPrintable(it.value()) << "]\n";
802 
803  QString siteId = it.key();
804  if (stnSetupById_.contains(siteId))
805  {
806  StationSetup *stnS=stnSetupById_.value(siteId);
807  if (stnS)
808  {
809  std::cout << " .. " << qPrintable(it.value()) << " got " << stnS->getIfs().size() << " IF setup records:\n";
810  for (int i=0; i<stnS->getIfs().size(); i++)
811  {
812  IfSetup *ifS=stnS->getIfs().at(i);
813  std::cout << " " << i << ": " << qPrintable(ifS->getIfId()) << " : \""
814  << qPrintable(ifS->getIfName()) << "\" LO= " << ifS->getTotalLo()
815  << " SideBand: " << qPrintable(sideBand2Str(ifS->getNetSideBand()))
816  << " Polarizations: " << qPrintable(polarization2Str(ifS->getPolarization()))
817  << "\n";
818  };
819  std::cout << " .. " << " got " << stnS->getBbcs().size() << " BBC setup records:\n";
820  for (int i=0; i<stnS->getBbcs().size(); i++)
821  {
822  BbcSetup *bbcS=stnS->getBbcs().at(i);
823  std::cout << " " << i << ": " << qPrintable(bbcS->getBbcId()) << " IF = "
824  << qPrintable(bbcS->getIfId()) << " phys.num= " << bbcS->getPhysNumber()
825  << "\n";
826  };
827  std::cout << " .. " << " got " << stnS->getFreqs().size() << " FREQ setup records:\n";
828  for (int i=0; i<stnS->getFreqs().size(); i++)
829  {
830  FreqSetup *freqS=stnS->getFreqs().at(i);
831  std::cout << " " << i
832  << ": Band=[" << qPrintable(freqS->getBandId()) << "]"
833  << " skyFreq = " << freqS->getSkyFreq()
834  << " SideBand: [" << qPrintable(sideBand2Str(freqS->getNetSideBand())) << "]"
835  << " bandwidth = " << freqS->getBandwidth()
836  << " Chan=[" << qPrintable(freqS->getChanId()) << "]"
837  << " BBCId=[" << qPrintable(freqS->getBbcId()) << "]"
838  << " PhaseCalId=[" << qPrintable(freqS->getPhaseCalId()) << "]"
839  << "\n";
840  };
841 
842 
843 
844  }
845  else
847  "::analyzeVex(): found \"" + siteId + "\" station setup is NULL");
848  }
849  else
851  "::analyzeVex(): canot find \"" + siteId + "\" in the station setups");
852 
853 
854 
855  };
856 
857 
858 
859  return true;
860 };
861 
862 
863 
865 {
866  const QList<QString>& lst=par->getValues();
867  int l=lst.size();
868  QString str("");
869  QString ifId("");
870  QString ifName("");
871  double totalLo(0.0);
872  SgChannelPolarization polarization(CP_UNDEF);
873  SgChannelSideBand netSideBand(CSB_UNDEF);
874 
875  ifId = lst.at(0);
876  if (1 < l)
877  ifName = lst.at(1);
878  if (2 < l)
879  {
880  str = lst.at(2);
881  if (str == "R")
882  polarization = CP_RightCP;
883  else if (str == "L")
884  polarization = CP_LeftCP;
885  else if (str == "H")
886  polarization = CP_HorizontalLP;
887  else if (str == "V")
888  polarization = CP_VerticalLP;
889  else
891  "::ifSetup(): got an unlnown polarization code: \"" + str + "\"");
892  };
893  if (3 < l)
894  totalLo = str2frq(lst.at(3));
895  if (4 < l)
896  {
897  str = lst.at(4);
898  if (str == "L")
899  netSideBand = CSB_LSB;
900  else if (str == "U")
901  netSideBand = CSB_USB;
902  };
903 
904  return new IfSetup(ifId, ifName, totalLo, polarization, netSideBand);
905 };
906 
907 
908 
909 //
911 {
912  const QList<QString>& lst=par->getValues();
913  int l=lst.size();
914 
915  bool isOk;
916  QString bbcId("");
917  QString ifId("");
918  int physNumber(0);
919 
920  bbcId = lst.at(0);
921  if (1 < l)
922  {
923  physNumber = lst.at(1).toInt(&isOk);
924  if (!isOk)
926  "::bbcSetup(): cannot convert \"" + lst.at(1) + "\" to int");
927  }
928  if (2 < l)
929  ifId = lst.at(2);
930  //
931  return new BbcSetup(bbcId, ifId, physNumber);
932 };
933 
934 
935 
936 //
938 {
939  const QList<QString>& lst=par->getValues();
940  int l=lst.size();
941  QString str("");
942  QString bandId("");
943  double skyFreq(0.0);
944  SgChannelSideBand netSideBand(CSB_UNDEF);
945  double bandwidth(0.0);
946  QString chanId("");
947  QString bbcId("");
948  QString phaseCalId("");
949  //
950  bandId = lst.at(0);
951  if (1 < l)
952  skyFreq = str2frq(lst.at(1));
953  if (2 < l)
954  {
955  str = lst.at(2);
956  if (str == "L")
957  netSideBand = CSB_LSB;
958  else if (str == "U")
959  netSideBand = CSB_USB;
960  };
961  if (3 < l)
962  bandwidth = str2frq(lst.at(3));
963  if (4 < l)
964  chanId = lst.at(4);
965  if (5 < l)
966  bbcId = lst.at(5);
967  if (6 < l)
968  phaseCalId = lst.at(6);
969  //
970  return new FreqSetup(bandId, skyFreq, netSideBand, bandwidth, chanId, bbcId, phaseCalId);
971 };
972 
973 
974 
975 
976 
977 //
978 const SgVexDefBlock* SgVexFile::lookupDef(const QString& sectName, const QString& refName)
979 {
980  const SgVexSection *sect=sectionByName_[sectName];
981  SgVexDefBlock *def=NULL;
982  if (sect)
983  {
984  if (sect->getDefByKey().contains(refName))
985  {
986  def = sect->getDefByKey().value(refName);
987  };
988  };
989 std::cout << "--lookupDef: [" << (def?qPrintable(def->getKey()):"NULL") << "]\n";
990  return def;
991 }
992 
993 
994 //
995 const SgVexRefSatement* SgVexFile::lookupRef(const QString& sectName, const QString& refCode)
996 {
997  const SgVexSection *sect=sectionByName_[sectName];
998  const SgVexRefSatement *ref=NULL;
999  if (sect && sect->getRefByKey().contains(refCode))
1000  ref = sect->getRefByKey().value(refCode);
1001 
1002 std::cout << "--lookupRef: [" << (ref?qPrintable(ref->getValue()):"NULL") << "]\n";
1003 
1004  return ref;
1005 };
1006 
1007 
1008 
1009 //
1010 const SgVexRefSatement* SgVexFile::lookupRef(const SgVexDefBlock* defBlock, const QString& refCode)
1011 {
1012  const SgVexRefSatement *ref=NULL;
1013 
1014  if (defBlock && defBlock->refsByKey().contains(refCode))
1015  ref = defBlock->refsByKey().value(refCode);
1016 
1017 std::cout << "--lookupRef: [" << (ref?qPrintable(ref->getValue()):"NULL") << "]\n";
1018 
1019  return ref;
1020 };
1021 
1022 
1023 
1024 
1025 const SgVexRefSatement* SgVexFile::lookupRef(const SgVexDefBlock* defBlock, const QString& refCode,
1026  const QString& qualifier)
1027 {
1028  const SgVexRefSatement *ref=NULL;
1029 
1030 std::cout << "--lookupRef: [" << qPrintable(refCode) << "][" << qPrintable(qualifier) << "] ";
1031 
1032 
1033  if (defBlock && defBlock->refsByKey().contains(refCode))
1034  {
1035  if (defBlock->refsByKey().values(refCode).size() == 1)
1036  {
1037 std::cout << "(single)";
1038  ref = defBlock->refsByKey().value(refCode);
1039  }
1040  else
1041  {
1042 std::cout << "(multi)";
1043  for (int i=0; i<defBlock->refsByKey().values(refCode).size(); i++)
1044  if (defBlock->refsByKey().values(refCode).at(i)->getQualifierByQ().contains(qualifier))
1045  ref = defBlock->refsByKey().values(refCode).at(i);
1046  };
1047  };
1048 
1049 std::cout << " => [" << (ref?qPrintable(ref->getValue()):"NULL") << "]\n";
1050 
1051  return ref;
1052 };
1053 
1054 
1055 
1056 //
1057 double SgVexFile::str2frq(const QString& str) const
1058 {
1059  double f;
1060  bool isOk;
1061  double scale;
1062  f = 0.0;
1063  scale = 1.0;
1064 
1065  f = str.toDouble(&isOk);
1066  if (!isOk)
1067  {
1068  if (str.right(4) == " MHz")
1069  {
1070  scale = 1.0;
1071  f = str.left(str.size() - 4).toDouble(&isOk);
1072  if (!isOk)
1074  "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) + "\"");
1075  }
1076  else if (str.right(4) == " GHz")
1077  {
1078  scale = 1.0e3;
1079  f = str.left(str.size() - 4).toDouble(&isOk);
1080  if (!isOk)
1082  "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) + "\"");
1083  }
1084  else if (str.right(4) == " kHz")
1085  {
1086  scale = 1.0e-3;
1087  f = str.left(str.size() - 4).toDouble(&isOk);
1088  if (!isOk)
1090  "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) + "\"");
1091  }
1092  else if (str.right(3) == " Hz")
1093  {
1094  scale = 1.0e-6;
1095  f = str.left(str.size() - 3).toDouble(&isOk);
1096  if (!isOk)
1098  "::str2frq(): cannot convert to double \"" + str.left(str.size() - 3) + "\"");
1099  }
1100  else
1102  "::str2frq(): cannot convert to double \"" + str + "\"");
1103  };
1104 
1105  return f*scale;
1106 };
1107 
1108 
1109 
1110 
1111 /*=====================================================================================================*/
1112 
1114 {
1115  if (sb == CSB_LSB)
1116  return "LSB";
1117  else if (sb == CSB_USB)
1118  return "USB";
1119  else if (sb == CSB_DUAL)
1120  return "DUO";
1121  else
1122  return "N/A";
1123 };
1124 
1125 
1126 
1128 {
1129  if (p == CP_LeftCP)
1130  return "LCP";
1131  else if (p == CP_RightCP)
1132  return "RCP";
1133  else if (p == CP_HorizontalLP)
1134  return "HLP";
1135  else if (p == CP_VerticalLP)
1136  return "VLP";
1137  else
1138  return "N/A";
1139 };
1140 
1141 
1142 
1143 
1144 
1145 
1146 
1147 
1148 
SgLogger * logger
Definition: SgLogger.cpp:231
const SgMJD tZero(1957, 10, 4)
QString polarization2Str(SgChannelPolarization p)
Definition: SgVex.cpp:1127
QString sideBand2Str(SgChannelSideBand sb)
Definition: SgVex.cpp:1113
SgChannelPolarization
Definition: SgVex.h:57
@ CP_UNDEF
Definition: SgVex.h:58
@ CP_VerticalLP
Definition: SgVex.h:62
@ CP_RightCP
Definition: SgVex.h:59
@ CP_HorizontalLP
Definition: SgVex.h:61
@ CP_LeftCP
Definition: SgVex.h:60
SgChannelSideBand
Definition: SgVex.h:47
@ CSB_DUAL
Definition: SgVex.h:51
@ CSB_USB
Definition: SgVex.h:50
@ CSB_LSB
Definition: SgVex.h:49
@ CSB_UNDEF
Definition: SgVex.h:48
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
@ IO_TXT
Definition: SgLogger.h:65
QList< SgVexLiteralBlock * > literalas_
Definition: SgVex.h:190
QMap< QString, SgVexRefSatement * > refsByKey_
Definition: SgVex.h:192
static const QString className()
Definition: SgVex.cpp:174
QString key_
Definition: SgVex.h:187
SgVexDefBlock()
Definition: SgVex.h:166
QList< SgVexParameter * > parameters_
Definition: SgVex.h:189
QList< SgVexRefSatement * > refStatements_
Definition: SgVex.h:188
QMap< QString, SgVexParameter * > parsByKey_
Definition: SgVex.h:193
const QString & getKey() const
Definition: SgVex.h:172
bool parseVex(const QList< QString > &statements, int &idx)
Definition: SgVex.cpp:221
const QMap< QString, SgVexRefSatement * > & refsByKey() const
Definition: SgVex.h:176
~SgVexDefBlock()
Definition: SgVex.cpp:203
const QMap< QString, SgVexParameter * > & parsByKey() const
Definition: SgVex.h:177
const QString & getBbcId() const
Definition: SgVex.h:334
int getPhysNumber() const
Definition: SgVex.h:336
const QString & getIfId() const
Definition: SgVex.h:335
const QString & getBbcId() const
Definition: SgVex.h:368
const QString & getPhaseCalId() const
Definition: SgVex.h:369
SgChannelSideBand getNetSideBand() const
Definition: SgVex.h:365
const QString & getBandId() const
Definition: SgVex.h:363
double getSkyFreq() const
Definition: SgVex.h:364
double getBandwidth() const
Definition: SgVex.h:366
const QString & getChanId() const
Definition: SgVex.h:367
const QString & getIfId() const
Definition: SgVex.h:304
double getTotalLo() const
Definition: SgVex.h:306
SgChannelPolarization getPolarization() const
Definition: SgVex.h:307
SgChannelSideBand getNetSideBand() const
Definition: SgVex.h:308
const QString & getIfName() const
Definition: SgVex.h:305
QList< IfSetup * > & ifs()
Definition: SgVex.h:402
QList< FreqSetup * > & freqs()
Definition: SgVex.h:404
const QList< FreqSetup * > & getFreqs() const
Definition: SgVex.h:400
const QList< BbcSetup * > & getBbcs() const
Definition: SgVex.h:399
QList< BbcSetup * > & bbcs()
Definition: SgVex.h:403
const QList< IfSetup * > & getIfs() const
Definition: SgVex.h:398
const SgVexDefBlock * lookupDef(const QString &sectName, const QString &refName)
Definition: SgVex.cpp:978
QList< SgVexSection * > sections_
Definition: SgVex.h:504
QList< QString > statements_
Definition: SgVex.h:502
~SgVexFile()
Definition: SgVex.cpp:491
const SgVexRefSatement * lookupRef(const QString &sectName, const QString &refName)
Definition: SgVex.cpp:995
QString inputFileName_
Definition: SgVex.h:483
IfSetup * ifSetup(const SgVexParameter *par)
Definition: SgVex.cpp:864
bool parseVexFile(const QString &fileName)
Definition: SgVex.cpp:502
QMap< QString, StationSetup * > stnSetupById_
Definition: SgVex.h:507
SgVexFile()
Definition: SgVex.cpp:443
static const QString className()
Definition: SgVex.cpp:435
double str2frq(const QString &) const
Definition: SgVex.cpp:1057
bool analyzeVex()
Definition: SgVex.cpp:627
QMap< QString, SgVexSection * > sectionByName_
Definition: SgVex.h:505
bool parseSection(int &idx)
Definition: SgVex.cpp:603
BbcSetup * bbcSetup(const SgVexParameter *par)
Definition: SgVex.cpp:910
FreqSetup * freqSetup(const SgVexParameter *par)
Definition: SgVex.cpp:937
QString key_
Definition: SgVex.h:154
QList< QString > literalStrings_
Definition: SgVex.h:155
bool parseVex(const QList< QString > &statements, int &idx)
Definition: SgVex.cpp:139
static const QString className()
Definition: SgVex.cpp:131
QList< QString > values_
Definition: SgVex.h:91
QString key_
Definition: SgVex.h:90
bool parseVexStatement(const QString &str)
Definition: SgVex.cpp:52
static const QString className()
Definition: SgVex.cpp:44
const QString & getKey() const
Definition: SgVex.h:80
const QList< QString > & getValues() const
Definition: SgVex.h:81
QString key_
Definition: SgVex.h:122
bool parseVexStatement(const QString &str)
Definition: SgVex.cpp:93
const QString & getValue() const
Definition: SgVex.h:111
QString value_
Definition: SgVex.h:123
QMap< QString, QString > qualifierByQ_
Definition: SgVex.h:125
const QString & getKey() const
Definition: SgVex.h:110
QList< QString > qualifiers_
Definition: SgVex.h:124
static const QString className()
Definition: SgVex.cpp:85
QList< SgVexParameter * > parameters_
Definition: SgVex.h:221
QString key_
Definition: SgVex.h:220
static const QString className()
Definition: SgVex.cpp:287
bool parseVex(const QList< QString > &statements, int &idx)
Definition: SgVex.cpp:295
QList< SgVexScanBlock * > scanBlocks_
Definition: SgVex.h:266
QList< QString > statements_
Definition: SgVex.h:263
QList< SgVexDefBlock * > defBlocks_
Definition: SgVex.h:265
QMap< QString, SgVexRefSatement * > refByKey_
Definition: SgVex.h:269
QMap< QString, SgVexScanBlock * > scanByKey_
Definition: SgVex.h:271
QList< SgVexRefSatement * > refStatements_
Definition: SgVex.h:264
const QMap< QString, SgVexDefBlock * > & getDefByKey() const
Definition: SgVex.h:252
QString key_
Definition: SgVex.h:262
QMap< QString, SgVexDefBlock * > defByKey_
Definition: SgVex.h:270
bool parseVex(const QList< QString > &statements, int &idx)
Definition: SgVex.cpp:370
const QMap< QString, SgVexRefSatement * > & getRefByKey() const
Definition: SgVex.h:251
static const QString className()
Definition: SgVex.cpp:342
const QList< SgVexDefBlock * > & getDefBlocks() const
Definition: SgVex.h:247
~SgVexSection()
Definition: SgVex.cpp:349