26 #include <sys/types.h>
29 #include <QtCore/QCoreApplication>
30 #include <QtCore/QDir>
31 #include <QtCore/QFile>
32 #include <QtCore/QFileInfo>
33 #include <QtCore/QSettings>
34 #include <QtCore/QString>
35 #include <QtCore/QStringList>
36 #include <QtCore/QRegularExpression>
37 #include <QtCore/QTextStream>
40 #if QT_VERSION >= 0x050000
41 # include <QtWidgets/QApplication>
43 # include <QtGui/QApplication>
64 void saveSettings(QSettings&,
bool shouldInvokeSystemWideWizard);
100 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");
153 if (1 < state->arg_num)
160 if (state->arg_num < 1 &&
165 return ARGP_ERR_UNKNOWN;
176 bool createCalcOnnFile(
const QString& calcOnnFileName,
int fd,
const QString& sessionName,
int version,
177 const QString& acName,
const QString& userName);
188 return new QApplication(argc, argv);
190 return new QCoreApplication(argc, argv);
204 int main(
int argc,
char** argv)
208 const QString path2SystemWideConfig(SWCONFIG
"/xdg");
210 const QString path2SystemWideConfig(
"");
212 QString userCommand(
"");
217 const char *calcMode =
"mark3 ";
231 QCoreApplication::setOrganizationName(
origOrgName);
232 QCoreApplication::setOrganizationDomain(
origDmnName);
236 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
243 for (
int i=0; i<6; i++)
244 mode_.c_mode[i] = *(calcMode + i);
246 memset(
extrnl_.External_inputs, 0,
sizeof(
extrnl_.External_inputs));
265 QString sArg1(argv[1]), sArg2(argv[2]), sArg3(argv[3]), sArg4(argv[4]);
269 nArg1 = sArg1.toInt(&isOk);
271 nArg2 = sArg2.toInt(&isOk);
275 if (!(fi.exists() && fi.isReadable()))
281 if (!(fi.exists() && fi.isReadable()))
291 ": one of the external a priori files is missed, exiting");
304 const char* envDisplay=NULL;
306 isGuiEnabled = (envDisplay=getenv(
"DISPLAY"))!=NULL && 0<strlen(envDisplay);
308 QScopedPointer<QCoreApplication>
310 if (qobject_cast<QApplication *>(app.data()))
325 for (
int i=0; i<argc; i++)
326 userCommand += QString(argv[i]) +
" ";
332 struct argp_option argp_options[] =
334 {0, 0, 0, 0,
"General options:", 10},
335 {
"std-locale",
'l', 0, 0,
336 "Use the standard locale"},
338 {0, 0, 0, 0,
"Configuration control:", 11},
339 {
"alt",
'a',
"STRING", 0,
340 "Use an alternative configuration STRING"},
342 {0, 0, 0, 0,
"Invocation of startup wizard:", 15},
343 {
"sys-wide-wizard",
'W', 0, 0,
344 "Run startup wizard for the system-wide settings"},
345 {
"wizard",
'w', 0, 0,
346 "Force call of the startup wizard"},
348 {0, 0, 0, 0,
"Operation modes:", -1},
349 {
"print-setup",
'p', 0, 0,
350 "Print set up and exit"},
351 {
"dry-mode",
'q', 0, 0,
352 "Process in a \"dry run\" mode: files will not be created, instead names of the files "
354 {
"version",
'V', 0, 0,
355 "Print program version"},
359 QString salute(
"vgosDbCalc is a program that reads vgosDb database, "
360 "calculates theoretical values of delays and rates as well as partials for many parameters and "
361 "stores them in a new version of the database. The mandatory argument DATABASE is a name of a "
362 "database (with or without version part) or a name of wrapper file (absolute or relative to the "
363 "default path of the vgosDb files).\v");
370 QString(
"\n\nThe utility vgosDbCalc is a part of nuSolve package. See the datails in "
371 "\"vgosDbCalc User Guide\", a part of nuSolve distribution. You can get the latest version of "
372 "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
374 struct argp argp={argp_options,
parse_opt,
"DATABASE", salute.toLatin1()};
376 argp_parse (&argp, argc, argv, 0, 0, &options);
380 isFirstRun = options.
settings->allKeys().size()>0 ? false :
true;
388 ": using alternative config name \"" + options.
altSetupName +
"\"");
407 QSettings *swSettings =
409 if (!swSettings->isWritable())
413 ": cannot write system wide config");
422 ": using an alternative config name, system wide config edit request ignored");
427 if (startup.exec() == QDialog::Rejected)
451 ": cannot run graphical application.");
461 ": no input files provided.");
470 ": one of the external a priori files is missed, exiting");
475 QString path2wrapperFile(
"");
476 QString wrapperFileName(
"");
477 QString sessionName(
"");
481 QRegularExpression reOldDbName(
"^(\\d{2}[A-Z]{3}\\d{2}[A-Z0-9]{1,2}).*");
482 QRegularExpression reNewDbName(
"^(\\d{8})-([\\S]{2,12}).*");
487 if (options.
inputArg.right(4) ==
".wrp")
492 else if ( reOldDbName.match(options.
inputArg).hasMatch() ||
493 reNewDbName.match(options.
inputArg).hasMatch() )
499 path2wrapperFile, wrapperFileName, sessionName, version);
504 ": cannot guess input data.");
510 QString calcExtFileName(
"");
511 QString calcOnnFileName(
"");
512 QString userLoginName(
"unkn");
513 QString path2tmpDir(
"/tmp");
516 if (getenv(
"TMPDIR") && strlen(getenv(
"TMPDIR"))>0)
518 path2tmpDir = QString(getenv(
"TMPDIR"));
520 ": the path to tmp dir has been alternated: \"" + path2tmpDir +
"\"");
526 struct passwd *pw=getpwuid(uid);
528 perror(
"getpwuid: ");
530 userLoginName = pw->pw_name;
534 memset(buff, 0,
sizeof(buff));
535 sprintf(buff,
"%s/%s.calcExt.%s-XXXXXX",
536 qPrintable(path2tmpDir),
538 if ((fd=mkstemp(buff)) == -1)
541 ": cannot create calcExt file.");
548 calcExtFileName = buff;
554 memset(buff, 0,
sizeof(buff));
555 sprintf(buff,
"%s/%s.calcOn.%s-XXXXXX",
556 qPrintable(path2tmpDir),
558 if ((fd=mkstemp(buff)) == -1)
561 ": cannot create calcOn file.");
568 calcOnnFileName = buff;
574 QString sLang(
""), sLcAll(
"");
578 sLang = QString(getenv(
"LANG"));
579 setenv(
"LANG",
"C", 1);
580 if (getenv(
"LC_ALL"))
581 sLcAll = QString(getenv(
"LC_ALL"));
582 setenv(
"LC_ALL",
"C", 1);
584 ": the env.variable LANG was set to \"C\"");
586 ": the env.variable LC_ALL was set to \"C\"");
610 alHistory =
new SgLogger(0,
false,
"");
630 ": the vgosDb object has been created");
632 isOk = vgosDb->
init(path2wrapperFile, wrapperFileName);
634 ": parsing of wrapper file " + path2wrapperFile +
"/" + wrapperFileName +
635 (isOk?
" complete":
" failed"));
659 ": User command: \"" + userCommand +
"\"");
661 ": Input data : " + path2wrapperFile +
"/" + wrapperFileName);
664 ": External a priori setup: ");
686 ") has been imported from vgosDb data set");
692 if (sessionName.size()==8)
693 sessionName = sessionName +
' ';
700 QString bandKey(
""), bandList(
"");
704 bands.append(bandKey);
705 bandList = bandKey +
", ";
707 for (
int i=0; i<session.
bands().size(); i++)
708 if (session.
bands().at(i)->getKey() != bandKey)
710 bands.append(session.
bands().at(i)->getKey());
711 bandList += session.
bands().at(i)->getKey() +
", ";
713 if (bandList.size() > 2)
716 ": collected " + QString(
"").setNum(bands.size()) +
" bands: " + bandList);
720 mimicCalcMain2(0, -1, qPrintable(calcOnnFileName), qPrintable(calcExtFileName), bands);
723 ": running observations through CALC has " + (isOk?
"been complete":
"failed"));
734 ": export of data into vgosDB tree has " + (isOk?
"been complete":
"failed"));
740 ": nothing to write");
745 ": import data of " + path2wrapperFile +
"/" + wrapperFileName +
" failed");
757 ": vgosDb object has been destroyed.");
762 ": the elapsed time to process " + QString(
"").setNum(session.
observations().size()) +
763 " observations is: " +
interval2Str(finisEpoch - startEpoch) +
764 " (" + QString(
"").sprintf(
"%.2f", (finisEpoch - startEpoch)*86400.0) +
" sec)",
true);
771 setenv(
"LANG", qPrintable(sLang), 1);
772 setenv(
"LC_ALL", qPrintable(sLcAll), 1);
774 ": the env.variable LANG was set to \"" + sLang +
"\"");
776 ": the env.variable LC_ALL was set to \"" + sLcAll +
"\"");
779 if (QFile::exists(calcExtFileName))
780 QFile::remove(calcExtFileName);
781 if (QFile::exists(calcOnnFileName))
782 QFile::remove(calcOnnFileName);
795 if (!f.open(QIODevice::WriteOnly))
798 "createCalcExtFile(): error opening calcExt file: " + fileName);
805 ts <<
"SITES " << str <<
"\n";
807 ts <<
"Sources " << str <<
"\n";
809 ts <<
"Ocean " << str <<
"\n";
811 ts <<
"EOPs " << str <<
"\n";
813 ts <<
"Tilts " << str <<
"\n";
815 ts <<
"OPTL " << str <<
"\n";
819 "createCalcExtFile(): the external a priori parameters were saved in the file \"" + fileName +
"\"");
826 bool createCalcOnnFile(
const QString& calcOnnFileName,
int fd,
const QString& sessionName,
int version,
827 const QString& acName,
const QString& userName)
829 QFile f(calcOnnFileName);
831 if (!f.open(QIODevice::WriteOnly))
834 "createCalcOnnFile(): error opening calcExt file: " + calcOnnFileName);
840 histIntroRec =
"Calc 11 at " + acName +
" -" + userName +
"-";
842 str.sprintf(
"$%-22s %3d $%-22s", qPrintable(sessionName), version, qPrintable(sessionName));
844 ts << qPrintable(str) <<
"\n"
845 <<
"00000000000000000000000000000000000000000000000000000000000000\n";
850 "createCalcOnnFile(): the CALC control data were saved in the file \"" +
851 calcOnnFileName +
"\"");
864 if (!QFile::exists(fileName))
867 "checkAprioriFiles(): the external a priori file for sites \"" + fileName +
"\" does not exist");
872 if (!QFile::exists(fileName))
875 "checkAprioriFiles(): the external a priori file for sources \"" + fileName +
"\" does not exist");
880 if (!QFile::exists(fileName))
883 "checkAprioriFiles(): the external a priori file for ocean loading \"" + fileName +
884 "\" does not exist");
889 if (!QFile::exists(fileName))
892 "checkAprioriFiles(): the external a priori file for EOPs \"" + fileName +
"\" does not exist");
897 if (!QFile::exists(fileName))
900 "checkAprioriFiles(): the external a priori file for tilts \"" + fileName +
"\" does not exist");
906 if (!QFile::exists(fileName))
909 "checkAprioriFiles(): the external a priori file for ocean pole tide loading \"" + fileName +
910 "\" does not exist");
925 settings.value(
"Identities/UserName",
928 settings.value(
"Identities/UserEmailAddress",
931 settings.value(
"Identities/UserDefaultInitials",
934 settings.value(
"Identities/AcFullName",
937 settings.value(
"Identities/AcAbbreviatedName",
940 settings.value(
"Identities/AcShortAbbreviatedName",
946 settings.value(
"Setup/Path2Home",
949 settings.value(
"Setup/Path2SolveAPrioriFiles",
952 settings.value(
"Setup/Path2VgosDbFiles",
955 settings.value(
"Setup/Path2MasterFiles",
958 settings.value(
"Setup/CalcAprioriFileSites",
961 settings.value(
"Setup/CalcAprioriFileSources",
964 settings.value(
"Setup/CalcAprioriFileOceanLd",
967 settings.value(
"Setup/CalcAprioriFileEops",
970 settings.value(
"Setup/CalcAprioriFileTilts",
973 settings.value(
"Setup/CalcAprioriFileOceanPoleTideLd",
976 settings.value(
"Setup/Path2AuxLogs",
979 settings.value(
"Setup/Have2SavePerSessionLog",
982 settings.value(
"Setup/UseLocalLocale",
987 settings.value(
"Logger/FileName",
988 "vgosDbCalc.log").toString());
991 settings.value(
"Logger/Capacity", 400).toInt());
996 logLevel = settings.value(
"Logger/LogLevel", 2).toInt();
1010 if (!shouldInvokeSystemWideWizard)
1012 settings.setValue(
"Identities/UserName",
1014 settings.setValue(
"Identities/UserEmailAddress",
1016 settings.setValue(
"Identities/UserDefaultInitials",
1019 settings.setValue(
"Identities/AcFullName",
1021 settings.setValue(
"Identities/AcAbbreviatedName",
1023 settings.setValue(
"Identities/AcShortAbbreviatedName",
1027 if (!shouldInvokeSystemWideWizard)
1029 settings.setValue(
"Setup/Path2Home",
1032 settings.setValue(
"Setup/Path2SolveAPrioriFiles",
1034 settings.setValue(
"Setup/Path2VgosDbFiles",
1036 settings.setValue(
"Setup/Path2MasterFiles",
1038 settings.setValue(
"Setup/CalcAprioriFileSites",
1040 settings.setValue(
"Setup/CalcAprioriFileSources",
1042 settings.setValue(
"Setup/CalcAprioriFileOceanLd",
1044 settings.setValue(
"Setup/CalcAprioriFileEops",
1046 settings.setValue(
"Setup/CalcAprioriFileTilts",
1048 settings.setValue(
"Setup/CalcAprioriFileOceanPoleTideLd",
1050 settings.setValue(
"Setup/Path2AuxLogs",
1052 settings.setValue(
"Setup/Have2SavePerSessionLog",
1054 settings.setValue(
"Setup/UseLocalLocale",
1058 settings.setValue(
"Logger/FileName",
1061 settings.setValue(
"Logger/Capacity",
1063 settings.setValue(
"Logger/IsStoreInFile",
1065 settings.setValue(
"Logger/IsNeedTimeMark",
QString interval2Str(double days)
SgVersion libraryVersion("SgLib", 0, 8, 2, "Compton Peak (rc2)", SgMJD(2023, 4, 3, 10, 59))
SgVersion vgosDbCalcVersion("vgosDbCalc", 0, 5, 2, "Fort Windham Rocks (rc2)", SgMJD(2023, 4, 3, 11, 6))
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 QString & getKey() const
const SgMJD & getReleaseEpoch() const
const QString & getSoftwareName() const
QString name(NameFormat fmt=NF_Human) const
void setOperationMode(SgNetCdf::OperationMode om)
bool init(const QString path, const QString fileName)
const QString & getName() const
@ Attr_FF_CALC_DATA_MODIFIED
the theoretical values were modified; //vgosDbCalc
const QString & getSessionCode() const
SgVlbiBand * primaryBand()
bool getDataFromVgosDb(SgVgosDb *vgosDb, bool have2LoadImmatureSession, bool guiExpected)
QList< SgVlbiBand * > & bands()
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 putDataIntoVgosDb(SgVgosDb *vgosDb)
void setWrapperFileName(const QString &)
SgVlbiSession *& session()
void setCalcCallingMode(CalcCallingMode mode)
void setPath2Data(const QString &)
void setInputDbName(const QString &)
void setPath2SolveAprioriFiles(const QString &)
const QString & getAprioriFile4Sources() const
const QString & getAprioriFile4Sites() const
const QString & getAprioriFile4Tilts() const
void setAprioriFile4Tilts(const QString &file)
bool getHave2SavePerSessionLog() const
const QString & getPath2Home() const
const QString & getPath2SolveAprioriFiles() const
void setAprioriFile4OceanPoleTideLd(const QString &file)
void setAprioriFile4Sites(const QString &file)
void setPath2MasterFiles(const QString &)
QString path2(const QString &) const
const QString & getAprioriFile4OceanLd() const
void setPath2AuxLogs(const QString &)
const QString & getPath2VgosDbFiles() const
const QString & getPath2MasterFiles() const
bool getUseLocalLocale() const
void setAprioriFile4Eops(const QString &file)
void setPath2VgosDbFiles(const QString &)
void setUseLocalLocale(bool use)
const QString & getAprioriFile4Eops() const
const QString & getPath2AuxLogs() const
SgIdentities & identities()
const QString & getAprioriFile4OceanPoleTideLd() const
void setHave2SavePerSessionLog(bool)
void setAprioriFile4Sources(const QString &file)
void setPath2Home(const QString &)
void setUpBinaryIdentities(const QString &)
void setAprioriFile4OceanLd(const QString &file)
static int serialNumber()
bool shouldInvokeSystemWideWizard
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)
bool createCalcExtFile(const QString &fileName, int fd)
const QString origAppName("vgosDbCalc")
void saveSettings(QSettings &, bool shouldInvokeSystemWideWizard)
bool createCalcOnnFile(const QString &calcOnnFileName, int fd, const QString &sessionName, int version, const QString &acName, const QString &userName)
void mimicCalcMain(int arg1, int arg2, const char *arg3, const char *arg4)
void mimicCalcMain2(int arg1, int arg2, const char *arg3, const char *arg4, const QList< QString > &bands)