29 #include <QtCore/QCoreApplication>
30 #include <QtCore/QDir>
31 #include <QtCore/QFileInfo>
32 #include <QtCore/QList>
33 #include <QtCore/QSettings>
34 #include <QtCore/QString>
35 #include <QtCore/QStringList>
38 #if QT_VERSION >= 0x050000
39 # include <QtWidgets/QApplication>
41 # include <QtGui/QApplication>
59 void saveSettings(QSettings&,
bool shouldInvokeSystemWideWizard);
106 static int parse_opt(
int key,
char *arg,
struct argp_state *state)
125 ": parse_opt(): it is dangerous to use a string \"" + options->
altSetupName +
126 "\" as an alternative config name");
128 ": parse_opt(): you can overwrite another file (un)intentionally");
140 n = QString(arg).toInt(&is);
147 ": parse_opt(): masterfile format of version " + arg +
" is not supported");
152 ": parse_opt(): cannot convert \"" + arg +
"\" to int");
181 n = QString(arg).toInt(&is);
187 ": parse_opt(): cannot convert \"" + arg +
"\" to int");
212 if (1 < state->arg_num)
219 if (state->arg_num < 1 &&
224 return ARGP_ERR_UNKNOWN;
239 return new QApplication(argc, argv);
241 return new QCoreApplication(argc, argv);
257 int main(
int argc,
char** argv)
261 QString userCommand(
"");
266 const QString path2SystemWideConfig(SWCONFIG
"/xdg");
268 const QString path2SystemWideConfig(
"");
273 const char* envDisplay=NULL;
299 QCoreApplication::setOrganizationName(
origOrgName);
300 QCoreApplication::setOrganizationDomain(
origDmnName);
304 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
308 isGuiEnabled = (envDisplay=getenv(
"DISPLAY"))!=NULL && strlen(envDisplay)>0;
310 QScopedPointer<QCoreApplication>
312 if (qobject_cast<QApplication *>(app.data()))
328 for (
int i=0; i<argc; i++)
329 userCommand += QString(argv[i]) +
" ";
336 struct argp_option argp_options[] =
338 {0, 0, 0, 0,
"General options:", 10},
339 {
"std-locale",
'l', 0, 0,
340 "Use the standard locale"},
341 {
"output-dir",
'o',
"STRING", 0,
342 "Use an alternative path STRING to save files in vgosDb format"},
343 {
"mf-version",
'f',
"NUM", 0,
344 "Set the expected masterfile format version to NUM. The possible format versions are 1 and 2."},
346 {0, 0, 0, 0,
"Configuration control:", 11},
347 {
"alt",
'a',
"STRING", 0,
348 "Use an alternative configuration STRING"},
350 {0, 0, 0, 0,
"Database edit options:", 12},
351 {
"database",
'd',
"STRING", 0,
352 "Set database name to STRING"},
353 {
"correlator",
'r',
"STRING", 0,
354 "Set correlator name to STRING"},
355 {
"exp-sn",
's',
"NUM", 0,
356 "Set experiment serial number to NUM"},
358 {0, 0, 0, 0,
"Data extraction control:", 13},
359 {
"exclude",
'e',
"CHAR", 0,
360 "exclude observations with fringe error code CHAR. If CHAR is \"*\" only observations that have "
361 "no fringe error code will be extracted. There can be more than one \"-e\" option, "
363 {
"map",
'm',
"STRING", 0,
364 "Set a name map file to STRING"},
365 {
"report",
't',
"STRING", 0,
366 "Set a correlator report file to STRING"},
367 {
"adjust-ref-stn",
'x', 0, 0,
368 "KOMB files input only: adjust delays and rates for a reference station clock offset "
369 "(experimental mode)"},
371 {0, 0, 0, 0,
"Invocation of startup wizard:", 25},
372 {
"sys-wide-wizard",
'W', 0, 0,
373 "Run startup wizard for the system-wide settings"},
374 {
"wizard",
'w', 0, 0,
375 "Force call of the startup wizard"},
377 {0, 0, 0, 0,
"Operation modes:", -1},
378 {
"print-setup",
'p', 0, 0,
379 "Print set up and exit"},
380 {
"dry-mode",
'q', 0, 0,
381 "Process in a \"dry run\" mode: files will not be created, instead names of the files "
383 {
"version",
'V', 0, 0,
384 "Print program version"},
388 QString salute(
"vgosDbMake is a program that extracts data from fringe or "
389 "KOMB files and stores obtained info in vgosDb database. The mandatory argument INPUT_DIR is a "
390 "name of a directory where the software searches the correlator files.\v");
397 QString(
"\n\nThe utility vgosDbMake is a part of nuSolve package. See the datails in "
398 "\"vgosDbMake User Guide\", a part of nuSolve distribution. You can get the latest version of "
399 "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
401 struct argp argp={argp_options,
parse_opt,
"INPUT_DIR", salute.toLatin1()};
403 argp_parse (&argp, argc, argv, 0, 0, &options);
405 isFirstRun = options.
settings->allKeys().size()>0 ? false :
true;
411 ": using alternative config name \"" + options.
altSetupName +
"\"");
431 QSettings *swSettings =
433 if (!swSettings->isWritable())
436 ": Cannot write system wide config");
445 ": Using an alternative config name, system wide config edit request ignored");
450 if (startup.exec() == QDialog::Rejected)
474 ": cannot run graphical application.");
488 options.
settings->setValue(
"Setup/Path2VgosDbFiles",
498 if (options.
inputArg.at(0) != QChar(
'/'))
505 ": the provided input direcory, " + options.
inputArg +
", does not exist");
512 ": the provided input is a file, not a directory.");
516 if (!fInfo.isReadable())
519 ": the provided input direcory is unreadable.");
537 alHistory =
new SgLogger(0,
false,
"");
558 ": directory \"" + options.
inputArg +
"\": unable to determine the type of input files");
565 ": directory \"" + options.
inputArg +
"\": unsupported type of input files");
594 ": User command: \"" + userCommand +
"\"");
596 ": Input data : \"" + options.
inputArg +
"\"");
602 ": session serial number was mannualy set to " +
607 QString sLang(
""), sLcAll(
"");
611 sLang = QString(getenv(
"LANG"));
612 setenv(
"LANG",
"C", 1);
613 if (getenv(
"LC_ALL"))
614 sLcAll = QString(getenv(
"LC_ALL"));
615 setenv(
"LC_ALL",
"C", 1);
617 ": the env.variable LANG was set to \"C\"");
619 ": the env.variable LC_ALL was set to \"C\"");
636 ") has been imported from fringes files");
639 ": vgosDb object has been created");
645 ": the empty correlator name was adjusted to \"" + session.
getCorrelatorName() +
"\"");
648 if ((isOk=vgosDb->
init(&session)))
651 ": the vgosDb object has been prepared to save the new session in vgosDb format");
664 ": export of data into vgosDb tree has been " + (isOk?
"complete":
"failed"));
671 ": the elapsed time to process " + QString(
"").setNum(session.
observations().size()) +
672 " observations is: " +
interval2Str(finisEpoch - startEpoch) +
673 " (" + QString(
"").sprintf(
"%.2f", (finisEpoch - startEpoch)*86400.0) +
" sec)",
true);
679 ": initializing of the vgosDb object has failed");
685 ": vgosDb object has been destroyed.");
691 ": import data from \"" + options.
inputArg +
"\" failed");
696 setenv(
"LANG", qPrintable(sLang), 1);
697 setenv(
"LC_ALL", qPrintable(sLcAll), 1);
699 ": the env.variable LANG was set to \"" + sLang +
"\"");
701 ": the env.variable LC_ALL was set to \"" + sLcAll +
"\"");
723 settings.value(
"Identities/UserName",
726 settings.value(
"Identities/UserEmailAddress",
729 settings.value(
"Identities/UserDefaultInitials",
732 settings.value(
"Identities/AcFullName",
735 settings.value(
"Identities/AcAbbreviatedName",
738 settings.value(
"Identities/AcShortAbbreviatedName",
744 settings.value(
"Setup/Path2Home",
747 settings.value(
"Setup/Path2InputFiles",
750 settings.value(
"Setup/Path2VgosDbFiles",
753 settings.value(
"Setup/Path2MasterFiles",
756 settings.value(
"Setup/Path2AuxLogs",
759 settings.value(
"Setup/Have2SavePerSessionLog",
762 settings.value(
"Setup/UseLocalLocale",
767 settings.value(
"Logger/FileName",
768 "vgosDbMake.log").toString());
771 settings.value(
"Logger/Capacity", 400).toInt());
776 logLevel = settings.value(
"Logger/LogLevel", 2).toInt();
787 void saveSettings(QSettings& settings,
bool shouldInvokeSystemWideWizard)
790 if (!shouldInvokeSystemWideWizard)
792 settings.setValue(
"Identities/UserName",
794 settings.setValue(
"Identities/UserEmailAddress",
796 settings.setValue(
"Identities/UserDefaultInitials",
799 settings.setValue(
"Identities/AcFullName",
801 settings.setValue(
"Identities/AcAbbreviatedName",
803 settings.setValue(
"Identities/AcShortAbbreviatedName",
807 if (!shouldInvokeSystemWideWizard)
809 settings.setValue(
"Setup/Path2Home",
812 settings.setValue(
"Setup/Path2InputFiles",
814 settings.setValue(
"Setup/Path2VgosDbFiles",
816 settings.setValue(
"Setup/Path2MasterFiles",
818 settings.setValue(
"Setup/Path2AuxLogs",
820 settings.setValue(
"Setup/Have2SavePerSessionLog",
822 settings.setValue(
"Setup/UseLocalLocale",
826 settings.setValue(
"Logger/FileName",
829 settings.setValue(
"Logger/Capacity",
831 settings.setValue(
"Logger/IsStoreInFile",
833 settings.setValue(
"Logger/IsNeedTimeMark",
845 QStringList entryList;
846 QRegExp reKombFileName(
"B[0-9]{2,}");
847 QRegExp reScanDirName(
"[0-9]{3}-[0-9]{4}[a-zA-Z]{0,1}");
850 files2read = dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot, QDir::Name);
851 for (
int i=0; i<files2read.size(); i++)
852 if (files2read.at(i).contains(reKombFileName))
853 entryList << files2read.at(i);
854 if (entryList.size() >= 3)
857 "determineInputType(): directory " + path2data +
": looks like KOMB output");
864 files2read = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
865 for (
int i=0; i<files2read.size(); i++)
867 entryList << files2read.at(i);
868 if (entryList.size() >= 0)
871 "determineInputType(): directory " + path2data +
": looks like FRINGE output");
QString interval2Str(double days)
SgVersion libraryVersion("SgLib", 0, 8, 2, "Compton Peak (rc2)", SgMJD(2023, 4, 3, 10, 59))
const QString & getAcAbbrevName() const
const QString & getAcAbbName() const
void setAcAbbrevName(const QString &)
void setAcFullName(const QString &)
const QString & getUserEmailAddress() const
void setAcAbbName(const QString &)
const QString & getMachineMachineName() const
const QString & getMachineRelease() const
const QString & getMachineNodeName() const
const QString & getUserDefaultInitials() const
const QString & getAcFullName() const
void setUserDefaultInitials(const QString &)
void setUserEmailAddress(const QString &)
void setUserName(const QString &)
const QString & getUserName() const
const QString & getMachineSysName() const
virtual void write(LogLevel, quint32, const QString &, bool=false)
bool getIsStoreInFile() const
void attachSupplementLog(const QString &name, SgLogger *auxLogger)
void setIsStoreInFile(bool isStoreInFile)
void setLogFacility(LogLevel lvl, quint32 f)
void setFileName(const QString &fileName)
void setIsNeedTimeMark(bool isNeedTimeMark)
void setDirName(const QString &dirName)
virtual void clearSpool()
void setCapacity(int capacity)
bool getIsNeedTimeMark() const
const QString & getFileName() const
void detachSupplementLog(const QString &name)
@ F_DDMonYYYY
Date: 2010 Apr 02.
QString toString(Format format=F_Verbose) const
static SgMJD currentMJD()
const SgMJD & getReleaseEpoch() const
const QString & getSoftwareName() const
QString name(NameFormat fmt=NF_Human) const
void setOperationMode(SgNetCdf::OperationMode om)
void setPath2RootDir(const QString &path)
bool init(const QString path, const QString fileName)
const QString & getPath2RootDir() const
const QString & getName() const
const SgMJD & getTStart() const
@ OT_MK4
observations are from Mk4-compatible correlator output;
@ OT_KOMB
observations are from KOMB output (generated by NICT, Japan);
@ OT_UNKNOWN
unknown (=all others) source of import;
const QString & getCorrelatorName() const
int getExperimentSerialNumber() const
void setExperimentSerialNumber(int sn)
void setCorrelatorName(const QString &name)
const QString & getSessionCode() const
bool getDataFromFringeFiles(const QString &path2, const QString &altDatabaseName, const QString &altCorrelatorName, const QString &historyFileName, const QString &mapFileName, const QList< QString > &)
bool getDataFromKombFiles(const QString &path2, const QString &altDatabaseName, const QString &altCorrelatorName, const QString &historyFileName, const QString &mapFileName, bool need2correctRefClocks)
QList< SgVlbiObservation * > & observations()
void setPath2Masterfile(const QString &)
bool putDataIntoVgosDb(SgVgosDb *vgosDb)
void setExpectedMasterfileVersion(int v)
void setPath2VgosDbFiles(const QString &)
bool getUseLocalLocale() const
const QString & getPath2InputFiles() const
QString path2(const QString &) const
const QString & getPath2Home() const
void setPath2Home(const QString &)
const QString & getPath2VgosDbFiles() const
SgIdentities & identities()
void setPath2MasterFiles(const QString &)
void setUpBinaryIdentities(const QString &)
void setPath2InputFiles(const QString &)
void setUseLocalLocale(bool use)
const QString & getPath2AuxLogs() const
bool getHave2SavePerSessionLog() const
void setPath2AuxLogs(const QString &)
void setHave2SavePerSessionLog(bool)
const QString & getPath2MasterFiles() const
static int serialNumber()
bool need2correctRefClocks
QString altCorrelatorName
bool shouldInvokeSystemWideWizard
bool have2SaveAltOutputDir
QList< QString > fringeErrorCodes2Skip
QString correlatorReportFileName
int expectedMasterfileVersion
SgVlbiSessionInfo::OriginType determineInputType(const QString &path2data)
void loadSettings(QSettings &)
QCoreApplication * createApplication(int &argc, char *argv[], bool isGuiEnabled)
const QString origOrgName("NASA GSFC")
int main(int argc, char **argv)
const QString origDmnName("gsfc.nasa.gov")
const int defaultMasterfileVersion(1)
const char * argp_program_bug_address
static int parse_opt(int key, char *arg, struct argp_state *state)
void saveSettings(QSettings &, bool shouldInvokeSystemWideWizard)
const QString origAppName("vgosDbMake")
SgVersion vgosDbMakeVersion