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>
60 void saveSettings(QSettings&,
bool shouldInvokeSystemWideWizard);
102 static int parse_opt(
int key,
char *arg,
struct argp_state *state)
119 ": parse_opt(): it is dangerous to use a string \"" + options->
altSetupName +
120 "\" as an alternative config name");
122 ": parse_opt(): you can overwrite another file (un)intentionally");
133 options->
kinds.append(str);
136 ": parse_opt(): got an unknown kind \"" + str +
"\", ignoring");
156 ": parse_opt(): the station \"" + str +
"\" is added to the process list");
159 if (strcmp(arg,
"c") == 0)
161 else if (strcmp(arg,
"m") == 0)
163 else if (strcmp(arg,
"t") == 0)
168 ": parse_opt(): unrecognized argument \"" + arg +
"\" of \"-z\" option; "
169 "expected: \"c\", \"m\" or \"t\"");
187 if (1 < state->arg_num)
194 if (state->arg_num < 1 &&
199 return ARGP_ERR_UNKNOWN;
223 return new QApplication(argc, argv);
225 return new QCoreApplication(argc, argv);
236 int main(
int argc,
char** argv)
242 QString sessionName(
"");
243 QString path2wrapperFile(
"");
244 QString wrapperFileName(
"");
245 QString userCommand(
"");
249 const QString path2SystemWideConfig(SWCONFIG
"/xdg");
251 const QString path2SystemWideConfig(
"");
257 const char* envDisplay=NULL;
267 options.
kinds.clear();
285 QCoreApplication::setOrganizationName(
origOrgName);
286 QCoreApplication::setOrganizationDomain(
origDmnName);
290 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
294 isGuiEnabled = (envDisplay=getenv(
"DISPLAY"))!=NULL && 0<strlen(envDisplay);
296 QScopedPointer<QCoreApplication>
298 if (qobject_cast<QApplication *>(app.data()))
311 for (
int i=0; i<argc; i++)
312 userCommand += QString(argv[i]) +
" ";
319 struct argp_option argp_options[] =
321 {0, 0, 0, 0,
"General options:", 10},
322 {
"input-dir",
'd',
"STRING", 0,
323 "Use an alternative path STRING to search for input files"},
324 {
"std-locale",
'l', 0, 0,
325 "Use the standard locale"},
327 {0, 0, 0, 0,
"Configuration control:", 11},
328 {
"alt",
'a',
"STRING", 0,
329 "Use an alternative configuration STRING"},
331 {0, 0, 0, 0,
"Data processing control:", 13},
332 {
"kind",
'k',
"STRING", 0,
333 "Use only the specified by STRING kind of input. Known kinds are: log (FS log files), "
334 "cdms (files with CDMS values), "
335 "pcmt (files with PCMT values), "
336 "met (files with meteorological data). "
337 "There can be more than one \"-k\" option"},
338 {
"meteo-order",
'o',
"STRING", 0,
339 "An order of meteo parameters in /wx/ record of a log file. STRING is a string with at least 3 "
340 "characters: T (temperature), P (pressure) and H (relative humidity). The order of the chars in "
341 "STRING determines the order of data in a log file. The default is TPH. The values are case "
342 "insensitive. The argument is supposed to be used with \"-s\" option, otherwise change of the "
343 "order will affect all stations."},
344 {
"station",
's',
"STRING", 0,
345 "Use only station STRING (STRING can be either two-char station code or 8-chars station name). "
346 "There can be more than one \"-s\" option"},
347 {
"zerofy",
'z',
"CHAR", 0,
348 "Reset data type CHAR. CHAR can be \"c\" (cable calibration), "
349 "\"m\" (meteorological data) or \"t\" (tsys). There can be more than one \"-z\" option"},
351 {0, 0, 0, 0,
"Invocation of startup wizard:", 25},
352 {
"sys-wide-wizard",
'W', 0, 0,
353 "Run startup wizard for the system-wide settings"},
354 {
"wizard",
'w', 0, 0,
355 "Force call of the startup wizard"},
357 {0, 0, 0, 0,
"Operation modes:", -1},
358 {
"print-setup",
'p', 0, 0,
359 "Print set up and exit"},
360 {
"dry-mode",
'q', 0, 0,
361 "Process in a \"dry run\" mode: files will not be created, instead names of the files "
363 {
"version",
'V', 0, 0,
364 "Print program version"},
368 QString salute(
"vgosDbProcLogs is a program that extracts data from filed "
369 "system log files and stores obtained info in vgosDb database. The mandatory argument DATABASE is "
370 "a name of a database (with or without version part) or a name of wrapper file (absolute or "
371 "relative to the default path of the vgosDb files).\v");
378 QString(
"\n\nThe utility vgosDbProcLogs is a part of nuSolve package. See the datails in "
379 "\"vgosDbProcLogs User Guide\", a part of nuSolve distribution. You can get the latest version of "
380 "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
382 struct argp argp={argp_options,
parse_opt,
"DATABASE", salute.toLatin1()};
384 argp_parse (&argp, argc, argv, 0, 0, &options);
387 isFirstRun = options.
settings->allKeys().size()>0 ? false :
true;
393 ": using alternative config name \"" + options.
altSetupName +
"\"");
408 ": the size of meteo order string (" + QString(
"").setNum(options.
orderOfMeteo.size()) +
409 ") is less than 3; ignoring");
415 ": the meteo order string \"" + options.
orderOfMeteo +
"\" does not contain temperature tag "
416 "(T or t); ignoring");
422 ": the meteo order string \"" + options.
orderOfMeteo +
"\" does not contain pressure tag "
423 "(P or p); ignoring");
429 ": the meteo order string \"" + options.
orderOfMeteo +
"\" does not contain relative humidity "
430 "tag (H or h); ignoring");
436 ": the meteo order string \"" + options.
orderOfMeteo +
"\" contains more than one temperature "
437 "tag (T or t); ignoring");
443 ": the meteo order string \"" + options.
orderOfMeteo +
"\" contains more than one pressure tag "
444 "(P or p); ignoring");
450 ": the meteo order string \"" + options.
orderOfMeteo +
"\" contains more than one relative "
451 "humidity tag (H or h); ignoring");
458 ": the meteo order string \"" + options.
orderOfMeteo +
"\" is invalid");
475 QSettings *swSettings =
477 if (!swSettings->isWritable())
480 ": cannot write system wide config");
489 ": using an alternative config name, system wide config edit request ignored");
494 if ((rc=startup.exec()) == 0)
517 ": cannot run graphical application.");
527 QRegExp reWrapperFileName(
".*\\.(wrp|wrap)$", Qt::CaseInsensitive);
528 QRegExp reDatabaseName(
"^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}$");
529 QRegExp reDatabaseVersionName(
"^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}_V[0-9]{3}$");
532 if (reWrapperFileName.indexIn(options.
inputArg) != -1)
536 sessionName, version);
539 ": got a session " + sessionName +
" of version " +
540 QString(
"").setNum(version) +
" from \"" + path2wrapperFile +
"\":\"" +
541 wrapperFileName +
"\"");
544 ": cannot figure out a session from the input \"" + options.
inputArg +
"\"");
546 else if (reDatabaseName.exactMatch(options.
inputArg) ||
547 reDatabaseVersionName.exactMatch(options.
inputArg))
551 path2wrapperFile, wrapperFileName, sessionName, version);
554 ": got a wrapper file \"" + wrapperFileName +
555 "\" from \"" + path2wrapperFile +
"\" for the session " + sessionName +
556 " of version " + QString(
"").setNum(version));
559 ": cannot figure out a session from the input \"" + options.
inputArg +
"\"");
564 ": cannot guess input data from \"" + options.
inputArg +
"\"");
580 alHistory =
new SgLogger(0,
false,
"");
581 alHistory->setIsNeedTimeMark(
false);
582 alHistory->setIsMute(
true);
601 QString sLang(
""), sLcAll(
"");
605 sLang = QString(getenv(
"LANG"));
606 setenv(
"LANG",
"C", 1);
607 if (getenv(
"LC_ALL"))
608 sLcAll = QString(getenv(
"LC_ALL"));
609 setenv(
"LC_ALL",
"C", 1);
611 ": the env.variable LANG was set to \"C\"");
613 ": the env.variable LC_ALL was set to \"C\"");
620 ": the vgosDb object has been created");
622 isOk = vgosDb->
init(path2wrapperFile, wrapperFileName);
624 ": initSessionFromOdb(): parsing of wrapper file " + path2wrapperFile +
"/" + wrapperFileName +
625 (isOk?
" complete":
" failed"));
654 ": User command: \"" + userCommand +
"\"");
656 ": Input data : " + path2wrapperFile +
"/" + wrapperFileName);
659 ") has been imported from vgosDb data set");
666 QString sStns(
"all stations");
669 sWhat +=
"cable cal";
671 sWhat +=
", meteorological";
678 sStns =
"selected station(s) ";
679 for (
int i=0; i<options.
stations.size(); i++)
680 sStns += options.
stations.at(i) +
", ";
689 ": the " + sWhat +
" were reset for " + sStns +
" of the session " + session.
getSessionCode() +
690 " (" + session.
getName() +
")");
696 ": clearing the " + sWhat +
" for " + sStns +
" of the session " + session.
getSessionCode() +
697 " (" + session.
getName() +
") failed");
706 ": import of data from station log files has " + (isOk?
"been complete":
"failed"));
715 ": export of data into vgosDb set has " + (isOk?
"been complete":
"failed"));
719 ": nothing to write");
724 ": the elapsed time to process " + QString(
"").setNum(session.
observations().size()) +
725 " observations is: " +
interval2Str(finisEpoch - startEpoch) +
726 " (" + QString(
"").sprintf(
"%.2f", (finisEpoch - startEpoch)*86400.0) +
" sec)",
true);
732 ": vgosDb object has been destroyed.");
736 ": import data of " + path2wrapperFile +
"/" + wrapperFileName +
" failed");
741 setenv(
"LANG", qPrintable(sLang), 1);
742 setenv(
"LC_ALL", qPrintable(sLcAll), 1);
744 ": the env.variable LANG was set to \"" + sLang +
"\"");
746 ": the env.variable LC_ALL was set to \"" + sLcAll +
"\"");
767 settings.value(
"Identities/UserName",
770 settings.value(
"Identities/UserEmailAddress",
773 settings.value(
"Identities/UserDefaultInitials",
776 settings.value(
"Identities/AcFullName",
779 settings.value(
"Identities/AcAbbreviatedName",
782 settings.value(
"Identities/AcShortAbbreviatedName",
788 settings.value(
"Setup/Path2Home",
791 settings.value(
"Setup/Path2SessionFiles",
794 settings.value(
"Setup/Path2VgosDbFiles",
797 settings.value(
"Setup/Path2MasterFiles",
800 settings.value(
"Setup/Path2AuxLogs",
803 settings.value(
"Setup/Have2SavePerSessionLog",
806 settings.value(
"Setup/UseLocalLocale",
811 settings.value(
"Logger/FileName",
812 "vgosDbProcLogs.log").toString());
815 settings.value(
"Logger/Capacity", 400).toInt());
820 logLevel = settings.value(
"Logger/LogLevel", 2).toInt();
827 int size, defaultCableSign;
828 QString stationKey(
""), rinexFileName(
"");
830 if ( (size = settings.beginReadArray(
"Setup/DefaultCableSignByStn")) )
835 for (
int i=0; i<size; ++i)
837 settings.setArrayIndex(i);
838 stationKey = settings.value(
"StationKey").toString().leftJustified(8,
' ');
839 defaultCableSign = settings.value(
"DefaultCableSign", 1).toInt();
845 ": loadSettings(): no DefaultCableSignByStn found, using default set up");
850 if ( (size = settings.beginReadArray(
"Setup/RinexFileNameByStn")) )
855 for (
int i=0; i<size; ++i)
857 settings.setArrayIndex(i);
858 stationKey = settings.value(
"StationKey").toString().leftJustified(8,
' ');
859 rinexFileName = settings.value(
"RinexFileName").toString();
865 ": loadSettings(): no RinexFileNameByStn found, using default set up");
868 if ( (size = settings.beginReadArray(
"Setup/RinexPressureOffsetByStn")) )
873 for (
int i=0; i<size; ++i)
875 settings.setArrayIndex(i);
876 stationKey = settings.value(
"StationKey").toString().leftJustified(8,
' ');
877 dP = settings.value(
"RinexPressureOffset", 0.0).toDouble();
883 ": loadSettings(): no RinexPressureOffsetByStn found, using default set up");
890 void saveSettings(QSettings& settings,
bool shouldInvokeSystemWideWizard)
893 if (!shouldInvokeSystemWideWizard)
895 settings.setValue(
"Identities/UserName",
897 settings.setValue(
"Identities/UserEmailAddress",
899 settings.setValue(
"Identities/UserDefaultInitials",
902 settings.setValue(
"Identities/AcFullName",
904 settings.setValue(
"Identities/AcAbbreviatedName",
906 settings.setValue(
"Identities/AcShortAbbreviatedName",
910 if (!shouldInvokeSystemWideWizard)
912 settings.setValue(
"Setup/Path2Home",
915 settings.setValue(
"Setup/Path2SessionFiles",
917 settings.setValue(
"Setup/Path2VgosDbFiles",
919 settings.setValue(
"Setup/Path2MasterFiles",
921 settings.setValue(
"Setup/Path2AuxLogs",
923 settings.setValue(
"Setup/Have2SavePerSessionLog",
925 settings.setValue(
"Setup/UseLocalLocale",
929 settings.setValue(
"Logger/FileName",
932 settings.setValue(
"Logger/Capacity",
934 settings.setValue(
"Logger/IsStoreInFile",
936 settings.setValue(
"Logger/IsNeedTimeMark",
940 settings.remove(
"Setup/DefaultCableSignByStn");
946 settings.setArrayIndex(idx);
947 settings.setValue(
"StationKey", it.key());
948 settings.setValue(
"DefaultCableSign", it.value());
954 settings.remove(
"Setup/RinexFileNameByStn");
960 settings.setArrayIndex(idx);
961 settings.setValue(
"StationKey", it.key());
962 settings.setValue(
"RinexFileName", it.value());
966 settings.remove(
"Setup/RinexPressureOffsetByStn");
972 settings.setArrayIndex(idx);
973 settings.setValue(
"StationKey", it.key());
974 settings.setValue(
"RinexPressureOffset", it.value());
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)
const QString & getSessionName() const
bool init(const QString path, const QString fileName)
void addHistoryRecord(const QString &, const SgMJD &t)
const QString & getName() const
const QString & getSessionCode() const
bool getDataFromVgosDb(SgVgosDb *vgosDb, bool have2LoadImmatureSession, bool guiExpected)
SgVlbiHistory & contemporaryHistory()
QList< SgVlbiObservation * > & observations()
static bool guessSessionByWrapperFileName(const QString &inputArg, const QString &path2VgosDb, QString &path2wrapperFile, QString &wrapperFileName, QString &sessionName, int &version)
static bool guessWrapperFileNameBySession(const QString &inputArg, const QString &path2VgosDb, const QString &acAbbName, QString &path2wrapperFile, QString &wrapperFileName, QString &sessionName, int &version, bool noYears=false)
void setPath2Masterfile(const QString &)
bool resetDataFromLogFiles(bool doCable, bool doMeteo, bool doTsys, const QList< QString > &stations)
bool importDataFromLogFiles(const QString &path2sessions, const QList< QString > &stations, const QList< QString > &kinds, const QMap< QString, int > *defaultCableSignByStn, const QMap< QString, QString > *rinexFileNameByStn, const QMap< QString, double > *rinexPressureOffsetByStn, bool have2overwriteAntabFile, bool reportAllTsysData, const QString &altPath2InputFiles, const QString &orderOfMeteo)
bool putDataIntoVgosDb(SgVgosDb *vgosDb)
void setPath2MasterFiles(const QString &)
SgIdentities & identities()
const QString & getPath2SessionFiles() const
void setUpBinaryIdentities(const QString &)
const QString & getPath2VgosDbFiles() const
void setUseLocalLocale(bool use)
QMap< QString, double > & rinexPressureOffsetByStn()
void setPath2Home(const QString &)
QMap< QString, int > & defaultCableSignByStn()
void setPath2SessionFiles(const QString &)
const QString & getPath2Home() const
const QString & getPath2AuxLogs() const
bool getUseLocalLocale() const
const QString & getPath2MasterFiles() const
void setPath2AuxLogs(const QString &)
QString path2(const QString &) const
void setHave2SavePerSessionLog(bool)
QMap< QString, QString > & rinexFileNameByStn()
const QMap< QString, double > & getRinexPressureOffsetByStn() const
void setPath2VgosDbFiles(const QString &)
const QMap< QString, int > & getDefaultCableSignByStn() const
const QMap< QString, QString > & getRinexFileNameByStn() const
bool getHave2SavePerSessionLog() const
static int serialNumber()
QString altPath2InputFiles
QMap< QString, int > knownKinds
bool shouldInvokeSystemWideWizard
QList< QString > stations
const QString origAppName("vgosDbProcLogs")
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)
SgVersion vgosDbProcLogsVersion