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);
102 static int parse_opt(
int key,
char *arg,
struct argp_state *state)
121 ": parse_opt(): it is dangerous to use a string \"" + options->
altSetupName +
122 "\" as an alternative config name");
124 ": parse_opt(): you can overwrite another file (un)intentionally");
160 n = QString(arg).toInt(&is);
166 ": parse_opt(): cannot convert \"" + arg +
"\" to int");
191 if (1 < state->arg_num)
198 if (state->arg_num < 1 &&
203 return ARGP_ERR_UNKNOWN;
218 return new QApplication(argc, argv);
220 return new QCoreApplication(argc, argv);
236 int main(
int argc,
char** argv)
240 QString userCommand(
"");
245 const QString path2SystemWideConfig(SWCONFIG
"/xdg");
247 const QString path2SystemWideConfig(
"");
252 const char* envDisplay=NULL;
277 QCoreApplication::setOrganizationName(
origOrgName);
278 QCoreApplication::setOrganizationDomain(
origDmnName);
282 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
286 isGuiEnabled = (envDisplay=getenv(
"DISPLAY"))!=NULL && strlen(envDisplay)>0;
288 QScopedPointer<QCoreApplication>
290 if (qobject_cast<QApplication *>(app.data()))
304 for (
int i=0; i<argc; i++)
305 userCommand += QString(argv[i]) +
" ";
312 struct argp_option argp_options[] =
314 {0, 0, 0, 0,
"General options:", 10},
315 {
"std-locale",
'l', 0, 0,
316 "Use the standard locale"},
317 {
"output-dir",
'o',
"STRING", 0,
318 "Use an alternative path STRING to save files in vgosDb format"},
320 {0, 0, 0, 0,
"Configuration control:", 11},
321 {
"alt",
'a',
"STRING", 0,
322 "Use an alternative configuration STRING"},
324 {0, 0, 0, 0,
"Database edit options:", 12},
325 {
"database",
'd',
"STRING", 0,
326 "Set database name to STRING"},
327 {
"correlator",
'r',
"STRING", 0,
328 "Set correlator name to STRING"},
329 {
"exp-sn",
's',
"NUM", 0,
330 "Set experiment serial number to NUM"},
332 {0, 0, 0, 0,
"Data extraction control:", 13},
333 {
"exclude",
'e',
"CHAR", 0,
334 "exclude observations with fringe error code CHAR. If CHAR is \"*\" only observations that have "
335 "no fringe error code will be extracted. There can be more than one \"-e\" option, "
337 {
"map",
'm',
"STRING", 0,
338 "Set a name map file to STRING"},
339 {
"report",
't',
"STRING", 0,
340 "Set a correlator report file to STRING"},
341 {
"adjust-ref-stn",
'x', 0, 0,
342 "KOMB files input only: adjust delays and rates for a reference station clock offset "
343 "(experimental mode)"},
345 {0, 0, 0, 0,
"Invocation of startup wizard:", 25},
346 {
"sys-wide-wizard",
'W', 0, 0,
347 "Run startup wizard for the system-wide settings"},
348 {
"wizard",
'w', 0, 0,
349 "Force call of the startup wizard"},
351 {0, 0, 0, 0,
"Operation modes:", -1},
352 {
"print-setup",
'p', 0, 0,
353 "Print set up and exit"},
354 {
"dry-mode",
'q', 0, 0,
355 "Process in a \"dry run\" mode: files will not be created, instead names of the files "
357 {
"version",
'V', 0, 0,
358 "Print program version"},
362 QString salute(
"vgosDbMake is a program that extracts data from fringe or "
363 "KOMB files and stores obtained info in vgosDb database. The mandatory argument INPUT_DIR is a "
364 "name of a directory where the software searches the correlator files.\v");
371 QString(
"\n\nThe utility vgosDbMake is a part of nuSolve package. See the datails in "
372 "\"vgosDbMake User Guide\", a part of nuSolve distribution. You can get the latest version of "
373 "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
375 struct argp argp={argp_options,
parse_opt,
"INPUT_DIR", salute.toLatin1()};
377 argp_parse (&argp, argc, argv, 0, 0, &options);
379 isFirstRun = options.
settings->allKeys().size()>0 ? false :
true;
385 ": using alternative config name \"" + options.
altSetupName +
"\"");
405 QSettings *swSettings =
407 if (!swSettings->isWritable())
410 ": Cannot write system wide config");
419 ": Using an alternative config name, system wide config edit request ignored");
424 if ((rc=startup.exec())==0)
447 ": cannot run graphical application.");
461 options.
settings->setValue(
"Setup/Path2VgosDbFiles",
471 if (options.
inputArg.at(0) != QChar(
'/'))
478 ": the provided input direcory, " + options.
inputArg +
", does not exist");
485 ": the provided input is a file, not a directory.");
489 if (!fInfo.isReadable())
492 ": the provided input direcory is unreadable.");
510 alHistory =
new SgLogger(0,
false,
"");
531 ": directory \"" + options.
inputArg +
"\": unable to determine the type of input files");
538 ": directory \"" + options.
inputArg +
"\": unsupported type of input files");
567 ": User command: \"" + userCommand +
"\"");
569 ": Input data : \"" + options.
inputArg +
"\"");
575 ": session serial number was mannualy set to " +
579 QString sLang(
""), sLcAll(
"");
583 sLang = QString(getenv(
"LANG"));
584 setenv(
"LANG",
"C", 1);
585 if (getenv(
"LC_ALL"))
586 sLcAll = QString(getenv(
"LC_ALL"));
587 setenv(
"LC_ALL",
"C", 1);
589 ": the env.variable LANG was set to \"C\"");
591 ": the env.variable LC_ALL was set to \"C\"");
608 ") has been imported from fringes files");
611 ": vgosDb object has been created");
613 vgosDb->
init(&session);
615 ": the vgosDb object has been prepared to save the new session in vgosDb format");
623 ": ______________________________________________________________________");
628 ": export of data into vgosDb tree has been " + (isOk?
"complete":
"failed"));
630 ": ______________________________________________________________________");
634 ": the elapsed time to process " + QString(
"").setNum(session.
observations().size()) +
635 " observations is: " +
interval2Str(finisEpoch - startEpoch) +
636 " (" + QString(
"").sprintf(
"%.2f", (finisEpoch - startEpoch)*86400.0) +
" sec)",
true);
640 ": vgosDb object has been destroyed.");
644 ": import data from \"" + options.
inputArg +
"\" failed");
648 setenv(
"LANG", qPrintable(sLang), 1);
649 setenv(
"LC_ALL", qPrintable(sLcAll), 1);
651 ": the env.variable LANG was set to \"" + sLang +
"\"");
653 ": the env.variable LC_ALL was set to \"" + sLcAll +
"\"");
676 settings.value(
"Identities/UserName",
679 settings.value(
"Identities/UserEmailAddress",
682 settings.value(
"Identities/UserDefaultInitials",
685 settings.value(
"Identities/AcFullName",
688 settings.value(
"Identities/AcAbbreviatedName",
691 settings.value(
"Identities/AcShortAbbreviatedName",
697 settings.value(
"Setup/Path2Home",
700 settings.value(
"Setup/Path2InputFiles",
703 settings.value(
"Setup/Path2VgosDbFiles",
706 settings.value(
"Setup/Path2MasterFiles",
709 settings.value(
"Setup/Path2AuxLogs",
712 settings.value(
"Setup/Have2SavePerSessionLog",
715 settings.value(
"Setup/UseLocalLocale",
720 settings.value(
"Logger/FileName",
721 "vgosDbMake.log").toString());
724 settings.value(
"Logger/Capacity", 400).toInt());
729 logLevel = settings.value(
"Logger/LogLevel", 2).toInt();
740 void saveSettings(QSettings& settings,
bool shouldInvokeSystemWideWizard)
743 if (!shouldInvokeSystemWideWizard)
745 settings.setValue(
"Identities/UserName",
747 settings.setValue(
"Identities/UserEmailAddress",
749 settings.setValue(
"Identities/UserDefaultInitials",
752 settings.setValue(
"Identities/AcFullName",
754 settings.setValue(
"Identities/AcAbbreviatedName",
756 settings.setValue(
"Identities/AcShortAbbreviatedName",
760 if (!shouldInvokeSystemWideWizard)
762 settings.setValue(
"Setup/Path2Home",
765 settings.setValue(
"Setup/Path2InputFiles",
767 settings.setValue(
"Setup/Path2VgosDbFiles",
769 settings.setValue(
"Setup/Path2MasterFiles",
771 settings.setValue(
"Setup/Path2AuxLogs",
773 settings.setValue(
"Setup/Have2SavePerSessionLog",
775 settings.setValue(
"Setup/UseLocalLocale",
779 settings.setValue(
"Logger/FileName",
782 settings.setValue(
"Logger/Capacity",
784 settings.setValue(
"Logger/IsStoreInFile",
786 settings.setValue(
"Logger/IsNeedTimeMark",
798 QStringList entryList;
799 QRegExp reKombFileName(
"B[0-9]{2,}");
800 QRegExp reScanDirName(
"[0-9]{3}-[0-9]{4}[a-zA-Z]{0,1}");
803 files2read = dir.entryList(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot, QDir::Name);
804 for (
int i=0; i<files2read.size(); i++)
805 if (files2read.at(i).contains(reKombFileName))
806 entryList << files2read.at(i);
807 if (entryList.size() >= 3)
810 "determineInputType(): directory " + path2data +
": looks like KOMB output");
817 files2read = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name);
818 for (
int i=0; i<files2read.size(); i++)
820 entryList << files2read.at(i);
821 if (entryList.size() >= 0)
824 "determineInputType(): directory " + path2data +
": looks like FRINGE output");
QString interval2Str(double days)
SgVersion libraryVersion("SgLib", 0, 7, 5, "Tuscarora (rc1)", SgMJD(2022, 2, 18, 17, 34))
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;
int getExperimentSerialNumber() const
void setExperimentSerialNumber(int sn)
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 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
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 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