27 #include <QtCore/QFile>
28 #include <QtCore/QRegularExpression>
46 return "SgVexParameter";
54 QRegularExpression re(
"(\\S+)\\s*=\\s*(.*)");
55 QRegularExpressionMatch match=re.match(str);
59 key_ = match.captured(1).trimmed();
60 if (match.captured(2).size())
63 for (
int i=0; i<lst.size(); i++)
87 return "SgVexRefSatement";
95 QRegularExpression re(
"ref\\s+(\\S+)\\s+=\\s+([^:]+):?(.*)");
96 QRegularExpressionMatch match=re.match(str);
101 key_ = match.captured(1).trimmed();
102 value_ = match.captured(2).trimmed();
103 if (match.captured(3).size())
106 for (
int i=0; i<lst.size(); i++)
133 return "SgVexLiteralBlock";
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())
148 key_ = match.captured(1).trimmed();
149 while(++idx < statements.size() && !reEnd.match((str=statements.at(idx))).hasMatch() )
155 "::parseVex(): literalBlock \"" +
key_ +
"\": collected " +
176 return "SgVexDefBlock";
223 const QString strEndDef(
"enddef");
225 QString str=statements.at(idx);
229 QRegularExpression reDef(
"^def\\s+(.+)");
230 QRegularExpression reRef(
"^ref\\s+(.+)");
231 QRegularExpression reLit(
"start_literal\\(");
233 QRegularExpressionMatch match=reDef.match(str);
234 if (match.hasMatch())
239 key_ = match.captured(1).trimmed();
241 while(++idx < statements.size() && (str=statements.at(idx)) != strEndDef)
249 else if (reLit.match(str).hasMatch() && lit->
parseVex(statements, idx))
262 "::parseVex(): encountered an unknown statement \"" + str +
"\"");
267 "::parseVex(): defBlock \"" +
key_ +
"\": collected " + QString(
"").setNum(
refStatements_.size()) +
268 " ref(s) and " + QString(
"").setNum(
parameters_.size()) +
" par(s)");
289 return "SgVexScanBlock";
297 const QString strEndScan(
"endscan");
299 QString str=statements.at(idx);
301 QRegularExpression reScan(
"^scan\\s+(.+)");
302 QRegularExpressionMatch match=reScan.match(str);
303 if (match.hasMatch())
306 key_ = match.captured(1).trimmed();
308 while(++idx < statements.size() && (str=statements.at(idx)) != strEndScan)
317 "::parseVex(): encountered an unknown statement \"" + str +
"\"");
322 "::parseVex(): scanBlock \"" +
key_ +
"\": collected " + QString(
"").setNum(
parameters_.size()) +
344 return "SgVexSection";
372 while(idx < statements.size() && statements.at(idx).at(0)!=
'$')
379 QRegularExpression reRef(
"^ref\\s+(.+)");
380 QRegularExpression reDef(
"^def\\s+(.+)");
381 QRegularExpression reScn(
"^scan\\s+(.+)");
407 std::cout <<
" ++ unparsed [" << qPrintable(
statements_.at(i)) <<
"]\n";
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)");
447 experDescription_(
""),
448 experNominalStart_(
tZero),
449 experNominalStop_(
tZero),
456 targetCorrelator_(
""),
468 inputFileName_(inputFileName),
471 experDescription_(
""),
472 experNominalStart_(
tZero),
473 experNominalStop_(
tZero),
480 targetCorrelator_(
""),
512 QRegularExpression reComments(
"([^\\*]*)\\*(.*)");
514 if (f.open(QFile::ReadOnly))
518 QString statement(
"");
524 str = s.readLine().trimmed();
527 QRegularExpressionMatch matchComments=reComments.match(str);
528 if (matchComments.hasMatch())
529 str = matchComments.captured(1).trimmed();
534 if (str.contains(
';'))
537 for (
int i=0; i<lst.size(); i++)
539 str = lst.at(i).trimmed();
541 if (statement.size())
547 statement += str +
" ";
551 "::parseVexFile(): read " + QString(
"").setNum(strCount) +
" strings, " +
552 QString(
"").setNum(
statements_.size()) +
" statements from " + f.fileName());
556 std::cout <<
" " << i <<
": [" << qPrintable(
statements_.at(i)) <<
"]\n";
566 "::parseVexFile(): not enough statements to proceed");
571 if (str.left(9) !=
"VEX_rev =")
574 "::parseVexFile(): got unknown file type");
587 std::cout <<
" ++ " << i <<
" -> " << qPrintable(
sections_.at(i)->getKey())
588 <<
" n=" <<
sections_.at(i)->getDefBlocks().size()
595 std::cout <<
" analyzed\n";
617 "::parseSection(): unexpected begin of a section: \"" +
statements_.at(idx) +
"\", idx=" +
618 QString(
"").setNum(idx));
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");
638 QMap<QString, QString> stationById;
641 std::cout <<
" ++ 0\n";
645 "::analyzeVex(): canot find section \"" + snStation +
"\", exitting");
651 "::analyzeVex(): canot find section \"" + snBbc +
"\", exitting");
657 "::analyzeVex(): canot find section \"" + snFreq +
"\", exitting");
663 "::analyzeVex(): canot find section \"" + snIf +
"\", exitting");
669 "::analyzeVex(): canot find section \"" + snMode +
"\", exitting");
675 "::analyzeVex(): canot find section \"" + snSite +
"\", exitting");
693 for (
int i=0; i<sectStations->
getDefBlocks().size(); i++)
701 "::analyzeVex(): canot find \"" + snSite +
"\" in \"" + pStnDef->
getKey() +
"\", exitting");
708 "::analyzeVex(): canot find \"" + ref->
getValue() +
"\" in " + ref->
getKey()
714 QString siteId(
""), siteName(
"");
716 par = pSiteDef->
parsByKey().value(
"site_ID");
720 "::analyzeVex(): canot find \"site_ID\" in " + pSiteDef->
getKey()
726 par = pSiteDef->
parsByKey().value(
"site_name");
730 "::analyzeVex(): canot find \"site_ID\" in " + pSiteDef->
getKey()
736 stationById[siteId] = siteName;
745 "::analyzeVex(): canot find \"" + snFreq +
"\" in \"" + snMode +
"\" for " +
746 siteName +
", exitting");
752 "::analyzeVex(): canot find \"" + snIf +
"\" in \"" + snMode +
"\" for " +
753 siteName +
", exitting");
758 "::analyzeVex(): canot find \"" + snBbc +
"\" in \"" + snMode +
"\" for " +
759 siteName +
", exitting");
768 for (
int i=0; i<pars.size(); i++)
776 pars = df->
parsByKey().values(
"BBC_assign");
777 for (
int i=0; i<pars.size(); i++)
780 stnS->
bbcs() << bbcS;
785 pars = df->
parsByKey().values(
"chan_def");
786 for (
int i=0; i<pars.size(); i++)
789 stnS->
freqs() << freqS;
799 for (QMap<QString, QString>::iterator it=stationById.begin(); it!=stationById.end(); ++it)
801 std::cout <<
" :: got: [" << qPrintable(it.key()) <<
"] -> [" << qPrintable(it.value()) <<
"]\n";
803 QString siteId = it.key();
809 std::cout <<
" .. " << qPrintable(it.value()) <<
" got " << stnS->
getIfs().size() <<
" IF setup records:\n";
810 for (
int i=0; i<stnS->
getIfs().size(); i++)
813 std::cout <<
" " << i <<
": " << qPrintable(ifS->
getIfId()) <<
" : \""
819 std::cout <<
" .. " <<
" got " << stnS->
getBbcs().size() <<
" BBC setup records:\n";
820 for (
int i=0; i<stnS->
getBbcs().size(); i++)
823 std::cout <<
" " << i <<
": " << qPrintable(bbcS->
getBbcId()) <<
" IF = "
827 std::cout <<
" .. " <<
" got " << stnS->
getFreqs().size() <<
" FREQ setup records:\n";
828 for (
int i=0; i<stnS->
getFreqs().size(); i++)
831 std::cout <<
" " << i
832 <<
": Band=[" << qPrintable(freqS->
getBandId()) <<
"]"
836 <<
" Chan=[" << qPrintable(freqS->
getChanId()) <<
"]"
837 <<
" BBCId=[" << qPrintable(freqS->
getBbcId()) <<
"]"
838 <<
" PhaseCalId=[" << qPrintable(freqS->
getPhaseCalId()) <<
"]"
847 "::analyzeVex(): found \"" + siteId +
"\" station setup is NULL");
851 "::analyzeVex(): canot find \"" + siteId +
"\" in the station setups");
891 "::ifSetup(): got an unlnown polarization code: \"" + str +
"\"");
904 return new IfSetup(ifId, ifName, totalLo, polarization, netSideBand);
923 physNumber = lst.at(1).toInt(&isOk);
926 "::bbcSetup(): cannot convert \"" + lst.at(1) +
"\" to int");
931 return new BbcSetup(bbcId, ifId, physNumber);
945 double bandwidth(0.0);
948 QString phaseCalId(
"");
962 bandwidth =
str2frq(lst.at(3));
968 phaseCalId = lst.at(6);
970 return new FreqSetup(bandId, skyFreq, netSideBand, bandwidth, chanId, bbcId, phaseCalId);
989 std::cout <<
"--lookupDef: [" << (def?qPrintable(def->
getKey()):
"NULL") <<
"]\n";
1002 std::cout <<
"--lookupRef: [" << (ref?qPrintable(ref->
getValue()):
"NULL") <<
"]\n";
1014 if (defBlock && defBlock->
refsByKey().contains(refCode))
1015 ref = defBlock->
refsByKey().value(refCode);
1017 std::cout <<
"--lookupRef: [" << (ref?qPrintable(ref->
getValue()):
"NULL") <<
"]\n";
1026 const QString& qualifier)
1030 std::cout <<
"--lookupRef: [" << qPrintable(refCode) <<
"][" << qPrintable(qualifier) <<
"] ";
1033 if (defBlock && defBlock->
refsByKey().contains(refCode))
1035 if (defBlock->
refsByKey().values(refCode).size() == 1)
1037 std::cout <<
"(single)";
1038 ref = defBlock->
refsByKey().value(refCode);
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);
1049 std::cout <<
" => [" << (ref?qPrintable(ref->
getValue()):
"NULL") <<
"]\n";
1065 f = str.toDouble(&isOk);
1068 if (str.right(4) ==
" MHz")
1071 f = str.left(str.size() - 4).toDouble(&isOk);
1074 "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) +
"\"");
1076 else if (str.right(4) ==
" GHz")
1079 f = str.left(str.size() - 4).toDouble(&isOk);
1082 "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) +
"\"");
1084 else if (str.right(4) ==
" kHz")
1087 f = str.left(str.size() - 4).toDouble(&isOk);
1090 "::str2frq(): cannot convert to double \"" + str.left(str.size() - 4) +
"\"");
1092 else if (str.right(3) ==
" Hz")
1095 f = str.left(str.size() - 3).toDouble(&isOk);
1098 "::str2frq(): cannot convert to double \"" + str.left(str.size() - 3) +
"\"");
1102 "::str2frq(): cannot convert to double \"" + str +
"\"");
const SgMJD tZero(1957, 10, 4)
QString polarization2Str(SgChannelPolarization p)
QString sideBand2Str(SgChannelSideBand sb)
virtual void write(LogLevel, quint32, const QString &, bool=false)
QList< SgVexLiteralBlock * > literalas_
QMap< QString, SgVexRefSatement * > refsByKey_
static const QString className()
QList< SgVexParameter * > parameters_
QList< SgVexRefSatement * > refStatements_
QMap< QString, SgVexParameter * > parsByKey_
const QString & getKey() const
bool parseVex(const QList< QString > &statements, int &idx)
const QMap< QString, SgVexRefSatement * > & refsByKey() const
const QMap< QString, SgVexParameter * > & parsByKey() const
const QString & getBbcId() const
int getPhysNumber() const
const QString & getIfId() const
const QString & getBbcId() const
const QString & getPhaseCalId() const
SgChannelSideBand getNetSideBand() const
const QString & getBandId() const
double getSkyFreq() const
double getBandwidth() const
const QString & getChanId() const
const QString & getIfId() const
double getTotalLo() const
SgChannelPolarization getPolarization() const
SgChannelSideBand getNetSideBand() const
const QString & getIfName() const
QList< IfSetup * > & ifs()
QList< FreqSetup * > & freqs()
const QList< FreqSetup * > & getFreqs() const
const QList< BbcSetup * > & getBbcs() const
QList< BbcSetup * > & bbcs()
const QList< IfSetup * > & getIfs() const
const SgVexDefBlock * lookupDef(const QString §Name, const QString &refName)
QList< SgVexSection * > sections_
QList< QString > statements_
const SgVexRefSatement * lookupRef(const QString §Name, const QString &refName)
IfSetup * ifSetup(const SgVexParameter *par)
bool parseVexFile(const QString &fileName)
QMap< QString, StationSetup * > stnSetupById_
static const QString className()
double str2frq(const QString &) const
QMap< QString, SgVexSection * > sectionByName_
bool parseSection(int &idx)
BbcSetup * bbcSetup(const SgVexParameter *par)
FreqSetup * freqSetup(const SgVexParameter *par)
QList< QString > literalStrings_
bool parseVex(const QList< QString > &statements, int &idx)
static const QString className()
bool parseVexStatement(const QString &str)
static const QString className()
const QString & getKey() const
const QList< QString > & getValues() const
bool parseVexStatement(const QString &str)
const QString & getValue() const
QMap< QString, QString > qualifierByQ_
const QString & getKey() const
QList< QString > qualifiers_
static const QString className()
QList< SgVexParameter * > parameters_
static const QString className()
bool parseVex(const QList< QString > &statements, int &idx)
QList< SgVexScanBlock * > scanBlocks_
QList< QString > statements_
QList< SgVexDefBlock * > defBlocks_
QMap< QString, SgVexRefSatement * > refByKey_
QMap< QString, SgVexScanBlock * > scanByKey_
QList< SgVexRefSatement * > refStatements_
const QMap< QString, SgVexDefBlock * > & getDefByKey() const
QMap< QString, SgVexDefBlock * > defByKey_
bool parseVex(const QList< QString > &statements, int &idx)
const QMap< QString, SgVexRefSatement * > & getRefByKey() const
static const QString className()
const QList< SgVexDefBlock * > & getDefBlocks() const