General Purpose Geodetic Library
vgosDbCalc.cpp
Go to the documentation of this file.
1 /*
2  * This file is a part of vgosDbCalc. vgosDbCalc is a part of CALC/SOLVE
3  * system and is designed to calculate theoretical values and store them
4  * in the vgosDb format.
5  * Copyright (C) 2016-2020 Sergei Bolotin.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 
23 #include <argp.h>
24 #include <signal.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <pwd.h>
28 
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/QTextStream>
37 
38 
39 #if QT_VERSION >= 0x050000
40 # include <QtWidgets/QApplication>
41 #else
42 # include <QtGui/QApplication>
43 #endif
44 
45 
46 
47 #include <SgIdentities.h>
48 #include <SgLogger.h>
49 #include <SgVgosDb.h>
50 #include <SgVlbiBand.h>
51 #include <SgVlbiSession.h>
52 
53 
54 
55 #include "vgosDbCalc.h"
56 #include "VcCalc2SessionIfc.h"
57 #include "VcStartupWizard.h"
58 
59 
60 
61 
62 void loadSettings(QSettings&);
63 void saveSettings(QSettings&, bool shouldInvokeSystemWideWizard);
64 
65 
66 
68 
69 const QString origOrgName("NASA GSFC");
70 const QString origDmnName("gsfc.nasa.gov");
71 const QString origAppName("vgosDbCalc");
72 
73 // HOPS's whims:
74 char progname[80];
75 int msglev = 2;
76 
77 
78 // for ARGP parser:
79 const char *argp_program_bug_address = "Sergei Bolotin <sergei.bolotin@nasa.gov>";
80 
82 {
83  QSettings *settings;
84  QString altSetupName;
85  QString altSetupAppName;
86  QString inputArg;
90  bool isDryRun;
92 };
93 
94 
95 //
96 // a parser for ARGP:
97 static int parse_opt(int key, char *arg, struct argp_state *state)
98 {
99 // int n;
100 // bool isOk;
101  QString str("");
102  struct vdbcOptions *options=(struct vdbcOptions*)state->input;
103  //
104  switch (key)
105  {
106  case 'a':
107  options->altSetupName = QString(arg);
108  if (!options->altSetupName.contains("/..")) // are there any other elements of path that we should avoid?
109  {
110  options->altSetupAppName = origAppName + "-" + options->altSetupName;
111  options->have2UseAltSetup = true;
112  }
113  else
114  {
116  ": parse_opt(): it is dangerous to use a string \"" + options->altSetupName +
117  "\" as an alternative config name");
119  ": parse_opt(): you can overwrite another file (un)intentionally");
120  delete options->settings;
121  exit(22);
122  };
123  break;
124  case 'l':
125  options->useStdLocale = true;
126  break;
127  case 'p':
128  loadSettings(*options->settings);
130  exit(0);
131  break;
132  case 'q':
133  options->isDryRun = true;
134  break;
135 
136  //
137  case 'W':
138  options->shouldInvokeSystemWideWizard = true;
139  break;
140  case 'w':
141  options->have2ForceWizard = true;
142  break;
143  //
144  case 'V':
145  std::cout << qPrintable(vgosDbCalcVersion.name(SgVersion::NF_Petrov)) << "\n";
146  exit(0);
147  break;
148  //
149  case ARGP_KEY_ARG:
150  if (1 < state->arg_num)
151  {
152  argp_usage(state);
153  };
154  options->inputArg = QString(arg);
155  break;
156  case ARGP_KEY_END:
157  if (state->arg_num < 1 &&
158  !(options->have2ForceWizard || options->shouldInvokeSystemWideWizard))
159  argp_usage(state);
160  break;
161  default:
162  return ARGP_ERR_UNKNOWN;
163  break;
164  };
165  return 0;
166 };
167 //
168 
169 
170 
171 
172 bool createCalcExtFile(const QString& fileName, int fd);
173 bool createCalcOnnFile(const QString& calcOnnFileName, int fd, const QString& sessionName, int version,
174  const QString& acName, const QString& userName);
175 bool checkAprioriFiles();
176 
177 
178 
179 
180 
181 //
182 QCoreApplication* createApplication(int &argc, char *argv[], bool isGuiEnabled)
183 {
184  if (isGuiEnabled)
185  return new QApplication(argc, argv);
186  else
187  return new QCoreApplication(argc, argv);
188 };
189 
190 
191 
192 
193 
194 
195 /***===================================================================================================*/
201 int main(int argc, char** argv)
202 {
203  struct vdbcOptions options;
204 #ifdef SWCONFIG
205  const QString path2SystemWideConfig(SWCONFIG "/xdg");
206 #else
207  const QString path2SystemWideConfig("");
208 #endif
209  QString userCommand("");
210  bool isFirstRun;
211  bool isOk;
212  SgLogger *alHistory;
213  SgLogger *alDriver;
214  const char *calcMode = "mark3 ";
215  int rc;
216 
217  rc = 0;
218  options.settings = NULL;
219  options.altSetupAppName = QString("");
220  options.altSetupName = QString("");
221  options.inputArg = QString("");
222  options.have2UseAltSetup = false;
223  options.have2ForceWizard = false;
224  options.shouldInvokeSystemWideWizard = false;
225  options.isDryRun = false;
226  options.useStdLocale = false;
227 
228  QCoreApplication::setOrganizationName(origOrgName);
229  QCoreApplication::setOrganizationDomain(origDmnName);
230  QCoreApplication::setApplicationName(origAppName);
231 
232  // set up path to the system wide settings:
233  QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
234  //
235  //
236  options.settings = new QSettings;
237  //
238  // init the external structures:
239  // strncpy(mode_.c_mode, "mark3 ", 6);
240  for (int i=0; i<6; i++)
241  mode_.c_mode[i] = *(calcMode + i);
242  // clear the records:
243  memset(extrnl_.External_inputs, 0, sizeof(extrnl_.External_inputs));
244  memset(extrnl_.Ex_sites, 0, sizeof(extrnl_.Ex_sites));
245  memset(extrnl_.Ex_stars, 0, sizeof(extrnl_.Ex_stars));
246  memset(extrnl_.Ex_ocean, 0, sizeof(extrnl_.Ex_ocean));
247  memset(extrnl_.Ex_EOP, 0, sizeof(extrnl_.Ex_EOP));
248  memset(extrnl_.Ex_tilts, 0, sizeof(extrnl_.Ex_tilts));
249  memset(extrnl_.Ex_OPTL, 0, sizeof(extrnl_.Ex_OPTL));
250  extrnl_.External_aprioris = f_false;
251  extrnl_.Input_sites = f_false;
252  extrnl_.Input_stars = f_false;
253  extrnl_.Input_ocean = f_false;
254  extrnl_.Input_EOP = f_false;
255  extrnl_.Input_tilts = f_false;
256  extrnl_.Input_OPTL = f_false;
257  extrnl_.le4 = f_false;
258 
259  // check for the legacy-style invocation:
260  if (argc==5)
261  {
262  QString sArg1(argv[1]), sArg2(argv[2]), sArg3(argv[3]), sArg4(argv[4]);
263  int nArg1, nArg2;
264  isOk = true;
265  nArg1 = nArg2 = 0;
266  nArg1 = sArg1.toInt(&isOk);
267  if (isOk)
268  nArg2 = sArg2.toInt(&isOk);
269  if (isOk) // check for calcOn file:
270  {
271  QFileInfo fi(sArg3);
272  if (!(fi.exists() && fi.isReadable()))
273  isOk = false;
274  };
275  if (isOk) // check for "external a priori" file:
276  {
277  QFileInfo fi(sArg4);
278  if (!(fi.exists() && fi.isReadable()))
279  isOk = false;
280  };
281  if (isOk) // looks like correct invocation
282  {
283  loadSettings(*options.settings);
284  if (!checkAprioriFiles())
285  {
287  ": one of the external a priori files is missed, exiting");
288  return 1;
289  }
290  else
291  {
293  mimicCalcMain(nArg1, nArg2, argv[3], argv[4]);
294  };
295  };
296  };
297  //
298  // ok, normal calling:
299  bool isGuiEnabled;
300  const char* envDisplay=NULL;
301  //
302  isGuiEnabled = (envDisplay=getenv("DISPLAY"))!=NULL && 0<strlen(envDisplay);
303 
304  QScopedPointer<QCoreApplication>
305  app(createApplication(argc, argv, isGuiEnabled));
306  if (qobject_cast<QApplication *>(app.data()))
307  {
308  // do something with GUI
309  }
310  else
311  {
312  // do something for non-GUI
313  };
314  //
315  // especially for HOPS:
316  strcpy(progname, qPrintable("HOPS (on behalf of " + vgosDbCalcVersion.getSoftwareName() + ")"));
317  //
318  setup.setUpBinaryIdentities(QString(argv[0]));
319  for (int i=0; i<argc; i++)
320  userCommand += QString(argv[i]) + " ";
321  userCommand.chop(1);
322 
323  //
324  // ARGP setup:
325  //
326  struct argp_option argp_options[] =
327  {
328  {0, 0, 0, 0, "General options:", 10},
329  {"std-locale", 'l', 0, 0,
330  "Use the standard locale"},
331 
332  {0, 0, 0, 0, "Configuration control:", 11},
333  {"alt", 'a', "STRING", 0,
334  "Use an alternative configuration STRING"},
335 
336  {0, 0, 0, 0, "Invocation of startup wizard:", 15},
337  {"sys-wide-wizard", 'W', 0, 0,
338  "Run startup wizard for the system-wide settings"},
339  {"wizard", 'w', 0, 0,
340  "Force call of the startup wizard"},
341 
342  {0, 0, 0, 0, "Operation modes:", -1},
343  {"print-setup", 'p', 0, 0,
344  "Print set up and exit"},
345  {"dry-mode", 'q', 0, 0,
346  "Process in a \"dry run\" mode: files will not be created, instead names of the files "
347  "will be printed"},
348  {"version", 'V', 0, 0,
349  "Print program version"},
350  //
351  {0}
352  };
353  QString salute("vgosDbCalc is a program that reads vgosDb database, "
354  "calculates theoretical values of delays and rates as well as partials for many parameters and "
355  "stores them in a new version of the database. The mandatory argument DATABASE is a name of a "
356  "database (with or without version part) or a name of wrapper file (absolute or relative to the "
357  "default path of the vgosDb files).\v");
358 
359  salute += "The current version is:\n\t" + vgosDbCalcVersion.name() + " released on " +
361  "\n\t" + libraryVersion.name() + " released on " +
363  salute +=
364  QString("\n\nThe utility vgosDbCalc is a part of nuSolve package. See the datails in "
365  "\"vgosDbCalc User Guide\", a part of nuSolve distribution. You can get the latest version of "
366  "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
367 
368  struct argp argp={argp_options, parse_opt, "DATABASE", salute.toLatin1()};
369 
370  argp_parse (&argp, argc, argv, 0, 0, &options);
371 
372  //
373  //
374  isFirstRun = options.settings->allKeys().size()>0 ? false : true;
375  //
376  //
377 
378  //
379  if (options.have2UseAltSetup)
380  {
382  ": using alternative config name \"" + options.altSetupName + "\"");
383  QSettings *altSettings=new QSettings(origOrgName, options.altSetupAppName);
384  loadSettings(*altSettings);
385  delete options.settings;
386  options.settings = altSettings;
387  }
388  else
389  loadSettings(*options.settings);
390  //
391  //
392  if (isGuiEnabled)
393  {
394  if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard ||
395  options.settings->value("Version/StartUpWizard", 0).toInt() < VcStartupWizard::serialNumber())
396  {
397  if (options.shouldInvokeSystemWideWizard)
398  {
399  if (!options.have2UseAltSetup)
400  {
401  QSettings *swSettings =
402  new QSettings(QSettings::SystemScope, origOrgName, origAppName);
403  if (!swSettings->isWritable())
404  {
406  ": cannot write system wide config");
407  delete swSettings;
408  return 2;
409  };
410  delete options.settings;
411  options.settings = swSettings;
412  }
413  else
415  ": using an alternative config name, system wide config edit request ignored");
416  };
417  //
418  VcStartupWizard startup(isFirstRun, options.have2ForceWizard,
419  options.shouldInvokeSystemWideWizard, options.settings);
420  if ((rc=startup.exec())==0)
421  {
422  delete options.settings;
423  logger->clearSpool();
424  return rc;
425  };
426  //
427  // save if user pressed "Finish":
428  options.settings->setValue("Version/StartUpWizard", startup.serialNumber());
430  //
431  // it is ok, exitting:
432  if (!options.inputArg.size())
433  {
434  delete options.settings;
435  logger->clearSpool();
436  return 0;
437  };
438  };
439  }
440  else if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard)
441  {
443  ": cannot run graphical application.");
444  delete options.settings;
445  logger->clearSpool();
446  return 1;
447  };
448  //
449  if (!options.inputArg.size())
450  {
452  ": no input files provided.");
453  logger->clearSpool();
454  return 1;
455  };
456  //
457  if (!checkAprioriFiles())
458  {
460  ": one of the external a priori files is missed, exiting");
461  return 1;
462  };
463  //
464  // determine a name of a wrapper file:
465  QString path2wrapperFile("");
466  QString wrapperFileName("");
467  QString sessionName("");
468  int version(0);
469  QRegExp reDatabaseName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}$");
470  QRegExp reDatabaseVersionName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}_V[0-9]{3}$");
471  // ok, this is a wrapper file name:
472  if (options.inputArg.right(4) == ".wrp")
473  {
475  setup.path2(setup.getPath2VgosDbFiles()), path2wrapperFile, wrapperFileName, sessionName, version);
476  }
477  else if (reDatabaseName.exactMatch(options.inputArg) ||
478  reDatabaseVersionName.exactMatch(options.inputArg))
479  {
482  path2wrapperFile, wrapperFileName, sessionName, version);
483  }
484  else
485  {
487  ": cannot guess input data.");
488  };
489 
490  char buff[180];
491  QString calcExtFileName("");
492  QString calcOnnFileName("");
493  QString userLoginName("unkn");
494  QString path2tmpDir("/tmp");
495  int fd;
496 
497 
498  if (getenv("TMPDIR") && strlen(getenv("TMPDIR"))>0)
499  {
500  path2tmpDir = QString(getenv("TMPDIR"));
502  ": the path to tmp dir has been alternated: \"" + path2tmpDir + "\"");
503  };
504 
505 
506  // guess user login name:
507  uid_t uid=geteuid();
508  struct passwd *pw=getpwuid(uid);
509  if (!pw)
510  perror("getpwuid: ");
511  else
512  userLoginName = pw->pw_name;
513 
514  if (isOk)
515  {
516  memset(buff, 0, sizeof(buff));
517  sprintf(buff, "%s/%s.calcExt.%s-XXXXXX",
518  qPrintable(path2tmpDir),
519  qPrintable(vgosDbCalcVersion.getSoftwareName()), qPrintable(userLoginName));
520  if ((fd=mkstemp(buff)) == -1)
521  {
523  ": cannot create calcExt file.");
524  isOk = false;
525  };
526  };
527  if (isOk)
528  {
529  calcExtFileName = buff;
530  isOk = createCalcExtFile(calcExtFileName, fd);
531  };
532  //
533  if (isOk)
534  {
535  memset(buff, 0, sizeof(buff));
536  sprintf(buff, "%s/%s.calcOn.%s-XXXXXX",
537  qPrintable(path2tmpDir),
538  qPrintable(vgosDbCalcVersion.getSoftwareName()), qPrintable(userLoginName));
539  if ((fd=mkstemp(buff)) == -1)
540  {
542  ": cannot create calcOn file.");
543  isOk = false;
544  };
545  };
546  if (isOk)
547  {
548  calcOnnFileName = buff;
549  isOk = createCalcOnnFile(calcOnnFileName, fd, sessionName, version,
551  };
552  //
553  //
554  QString sLang(""), sLcAll("");
555  if (!setup.getUseLocalLocale() || options.useStdLocale)
556  {
557  if (getenv("LANG"))
558  sLang = QString(getenv("LANG"));
559  setenv("LANG", "C", 1);
560  if (getenv("LC_ALL"))
561  sLcAll = QString(getenv("LC_ALL"));
562  setenv("LC_ALL", "C", 1);
564  ": the env.variable LANG was set to \"C\"");
566  ": the env.variable LC_ALL was set to \"C\"");
567  };
568  //
569  //
570  if (isOk)
571  {
572  SgMJD startEpoch=SgMJD::currentMJD();
574  ": starting");
575 
576  //
577  alDriver = new SgLogger(800, setup.getHave2SavePerSessionLog(), "drv-unnamed.log");
579  alDriver->setIsNeedTimeMark(true);
580  alDriver->setIsMute(true);
581  alDriver->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
582  alDriver->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
583  alDriver->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
584  alDriver->setLogFacility(SgLogger::DBG, 0);
586  logger->attachSupplementLog("Driver", alDriver);
587  alDriver->setFileName(sessionName + ".log");
588  alDriver->rmLogFile();
589  //
590  alHistory = new SgLogger(0, false, "");
591  alHistory->setIsNeedTimeMark(false);
592  alHistory->setIsMute(true);
593  alHistory->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
594  alHistory->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
595  alHistory->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
596  alHistory->setLogFacility(SgLogger::DBG, 0);
597  // commented out: want logs from calc only
598  // logger->addSupplementLog("History", alHistory);
599  //
600  //
601  SgVgosDb *vgosDb;
602  SgVlbiSession session;
603  //
605  //
606  //
607  //------------------------------------------------------------------------------------------
608  vgosDb = new SgVgosDb(&setup.identities(), &vgosDbCalcVersion);
610  ": the vgosDb object has been created");
611 
612  isOk = vgosDb->init(path2wrapperFile, wrapperFileName);
614  ": parsing of wrapper file " + path2wrapperFile + "/" + wrapperFileName +
615  (isOk?" complete":" failed"));
616 
617  if (isOk && session.getDataFromVgosDb(vgosDb, true, isGuiEnabled))
618  {
619  // collect log entries to save them into the history block of the session:
620  logger->attachSupplementLog("History", alHistory);
621 
623  ": Library ID: " + libraryVersion.name() + " released on " +
626  ": Driver ID: " + vgosDbCalcVersion.name() + " released on " +
628 
630  ": Host ID: " + setup.identities().getMachineNodeName() +
631  " (Hw: " + setup.identities().getMachineMachineName() +
632  "; Sw: " + setup.identities().getMachineRelease() +
633  " version of " + setup.identities().getMachineSysName() + ")");
634 
636  ": User ID: " + setup.identities().getUserName() +
639  ": User command: \"" + userCommand + "\"");
641  ": Input data : " + path2wrapperFile + "/" + wrapperFileName);
642 
644  ": External a priori setup: ");
646  ": SITES : " +
649  ": Sources : " +
652  ": Ocean : " +
655  ": EOPs : " +
658  ": Tilts : " +
661  ": OPTL : " +
663 
665  ": the session " + session.getSessionCode() + " (" + session.getName() +
666  ") has been imported from vgosDb data set");
667 
668  // set up calc2session interface:
670  c2s.session() = &session;
671  c2s.vgosDb() = vgosDb;
672  if (sessionName.size()==8)
673  sessionName = sessionName + ' ';
674  c2s.setInputDbName(sessionName);
675  c2s.setPath2Data(path2wrapperFile);
676  c2s.setWrapperFileName(wrapperFileName);
677 
678  // run calc:
679  QList<QString> bands;
680  QString bandKey(""), bandList("");
681  if (session.primaryBand())
682  {
683  bandKey = session.primaryBand()->getKey();
684  bands.append(bandKey);
685  bandList = bandKey + ", ";
686  };
687  for (int i=0; i<session.bands().size(); i++)
688  if (session.bands().at(i)->getKey() != bandKey)
689  {
690  bands.append(session.bands().at(i)->getKey());
691  bandList += session.bands().at(i)->getKey() + ", ";
692  };
693  if (bandList.size() > 2)
694  bandList.chop(2);
696  ": collected " + QString("").setNum(bands.size()) + " bands: " + bandList);
697  //
698  // call CALC:
699  //
700  mimicCalcMain2(0, -1, qPrintable(calcOnnFileName), qPrintable(calcExtFileName), bands);
701  //
703  ": running observations through CALC has " + (isOk?"been complete":"failed"));
704 
705  // save the session:
706  if (isOk)
707  {
709  if (options.isDryRun)
711 
712  isOk = session.putDataIntoVgosDb(vgosDb);
714  ": export of data into vgosDB tree has " + (isOk?"been complete":"failed"));
715  }
716  else
718  ": nothing to write");
719  }
720  else
722  ": import data of " + path2wrapperFile + "/" + wrapperFileName + " failed");
723  //
724  alDriver->clearSpool();
725  logger->detachSupplementLog("History");
726  logger->detachSupplementLog("Driver");
727  delete alHistory;
728  delete alDriver;
729  //
730  delete vgosDb;
732  ": vgosDb object has been destroyed.");
733 
734  // report elapsed time:
735  SgMJD finisEpoch=SgMJD::currentMJD();
737  ": the elapsed time to process " + QString("").setNum(session.observations().size()) +
738  " observations is: " + interval2Str(finisEpoch - startEpoch) +
739  " (" + QString("").sprintf("%.2f", (finisEpoch - startEpoch)*86400.0) + " sec)", true);
740  };
741  //
742  if (!setup.getUseLocalLocale() || options.useStdLocale)
743  {
744  setenv("LANG", qPrintable(sLang), 1);
745  setenv("LC_ALL", qPrintable(sLcAll), 1);
747  ": the env.variable LANG was set to \"" + sLang + "\"");
749  ": the env.variable LC_ALL was set to \"" + sLcAll + "\"");
750  };
751  //
752  if (QFile::exists(calcExtFileName))
753  QFile::remove(calcExtFileName);
754  if (QFile::exists(calcOnnFileName))
755  QFile::remove(calcOnnFileName);
756 
757  delete options.settings;
758  logger->clearSpool();
759  return rc;
760 };
761 
762 
763 
764 //
765 bool createCalcExtFile(const QString& fileName, int fd)
766 {
767  QFile f(fileName);
768  if (!f.open(QIODevice::WriteOnly))
769  {
771  "createCalcExtFile(): error opening calcExt file: " + fileName);
772  return false;
773  };
774  QTextStream ts(&f);
775  close(fd);
776  QString str;
778  ts << "SITES " << str << "\n";
780  ts << "Sources " << str << "\n";
782  ts << "Ocean " << str << "\n";
784  ts << "EOPs " << str << "\n";
786  ts << "Tilts " << str << "\n";
788  ts << "OPTL " << str << "\n";
789  ts.setDevice(NULL);
790  f.close();
792  "createCalcExtFile(): the external a priori parameters were saved in the file \"" + fileName + "\"");
793  return true;
794 };
795 
796 
797 
798 //
799 bool createCalcOnnFile(const QString& calcOnnFileName, int fd, const QString& sessionName, int version,
800  const QString& acName, const QString& userName)
801 {
802  QFile f(calcOnnFileName);
803  QString str("");
804  if (!f.open(QIODevice::WriteOnly))
805  {
807  "createCalcOnnFile(): error opening calcExt file: " + calcOnnFileName);
808  return false;
809  };
810  QTextStream ts(&f);
811  close (fd);
812  // to override the CALC's bug:
813  histIntroRec = "Calc 11 at " + acName + " -" + userName + "-";
814  ts << qPrintable(histIntroRec) << "\n";
815  str.sprintf("$%-9s %8d $%-9s", qPrintable(sessionName), version, qPrintable(sessionName));
816  ts << qPrintable(str) << "\n"
817  << "00000000000000000000000000000000000000000000000000000000000000\n";
818 
819  ts.setDevice(NULL);
820  f.close();
822  "createCalcOnnFile(): the CALC control data were saved in the file \"" +
823  calcOnnFileName + "\"");
824  return true;
825 };
826 
827 
828 
829 //
831 {
832  bool isOk;
833  QString fileName;
834  isOk = true;
836  if (!QFile::exists(fileName))
837  {
839  "checkAprioriFiles(): the external a priori file for sites \"" + fileName + "\" does not exist");
840  isOk = false;
841  };
842 
844  if (!QFile::exists(fileName))
845  {
847  "checkAprioriFiles(): the external a priori file for sources \"" + fileName + "\" does not exist");
848  isOk = false;
849  };
850 
852  if (!QFile::exists(fileName))
853  {
855  "checkAprioriFiles(): the external a priori file for ocean loading \"" + fileName +
856  "\" does not exist");
857  isOk = false;
858  };
859 
861  if (!QFile::exists(fileName))
862  {
864  "checkAprioriFiles(): the external a priori file for EOPs \"" + fileName + "\" does not exist");
865  isOk = false;
866  };
867 
869  if (!QFile::exists(fileName))
870  {
872  "checkAprioriFiles(): the external a priori file for tilts \"" + fileName + "\" does not exist");
873  isOk = false;
874  };
875 
876  fileName = setup.path2(setup.getPath2SolveAprioriFiles()) + "/" +
878  if (!QFile::exists(fileName))
879  {
881  "checkAprioriFiles(): the external a priori file for ocean pole tide loading \"" + fileName +
882  "\" does not exist");
883  isOk = false;
884  };
885  return isOk;
886 };
887 
888 
889 
890 //
891 void loadSettings(QSettings& settings)
892 {
893  int logLevel;
894  //
895  // setup.identities:
897  settings.value("Identities/UserName",
898  setup.identities().getUserName()).toString());
900  settings.value("Identities/UserEmailAddress",
901  setup.identities().getUserEmailAddress()).toString());
903  settings.value("Identities/UserDefaultInitials",
904  setup.identities().getUserDefaultInitials()).toString());
906  settings.value("Identities/AcFullName",
907  setup.identities().getAcFullName()).toString());
909  settings.value("Identities/AcAbbreviatedName",
910  setup.identities().getAcAbbrevName()).toString());
912  settings.value("Identities/AcShortAbbreviatedName",
913  setup.identities().getAcAbbName()).toString());
914 
915  // setup:
916  // Pathes:
918  settings.value("Setup/Path2Home",
919  setup.getPath2Home()).toString());
921  settings.value("Setup/Path2SolveAPrioriFiles",
922  setup.getPath2SolveAprioriFiles()).toString());
924  settings.value("Setup/Path2VgosDbFiles",
925  setup.getPath2VgosDbFiles()).toString());
927  settings.value("Setup/Path2MasterFiles",
928  setup.getPath2MasterFiles()).toString());
930  settings.value("Setup/CalcAprioriFileSites",
931  setup.getAprioriFile4Sites()).toString());
933  settings.value("Setup/CalcAprioriFileSources",
934  setup.getAprioriFile4Sources()).toString());
936  settings.value("Setup/CalcAprioriFileOceanLd",
937  setup.getAprioriFile4OceanLd()).toString());
939  settings.value("Setup/CalcAprioriFileEops",
940  setup.getAprioriFile4Eops()).toString());
942  settings.value("Setup/CalcAprioriFileTilts",
943  setup.getAprioriFile4Tilts()).toString());
945  settings.value("Setup/CalcAprioriFileOceanPoleTideLd",
946  setup.getAprioriFile4OceanPoleTideLd()).toString());
948  settings.value("Setup/Path2AuxLogs",
949  setup.getPath2AuxLogs()).toString());
951  settings.value("Setup/Have2SavePerSessionLog",
952  setup.getHave2SavePerSessionLog()).toBool());
954  settings.value("Setup/UseLocalLocale",
955  setup.getUseLocalLocale()).toBool());
956  //
957  // adjust the logger:
959  settings.value("Logger/FileName",
960  "vgosDbCalc.log").toString());
963  settings.value("Logger/Capacity", 400).toInt());
965  settings.value("Logger/IsStoreInFile", logger->getIsStoreInFile()).toBool());
967  settings.value("Logger/IsNeedTimeMark", logger->getIsNeedTimeMark()).toBool());
968  logLevel = settings.value("Logger/LogLevel", 2).toInt();
969  logger->setLogFacility(SgLogger::ERR, logLevel>=0?0xFFFFFFFF:0);
970  logger->setLogFacility(SgLogger::WRN, logLevel>=1?0xFFFFFFFF:0);
971  logger->setLogFacility(SgLogger::INF, logLevel>=2?0xFFFFFFFF:0);
972  logger->setLogFacility(SgLogger::DBG, logLevel==3?0xFFFFFFFF:0);
973  //
974 };
975 
976 
977 
978 //
979 void saveSettings(QSettings& settings, bool shouldInvokeSystemWideWizard)
980 {
981  // setup.identities:
982  if (!shouldInvokeSystemWideWizard)
983  {
984  settings.setValue("Identities/UserName",
986  settings.setValue("Identities/UserEmailAddress",
988  settings.setValue("Identities/UserDefaultInitials",
990  };
991  settings.setValue("Identities/AcFullName",
993  settings.setValue("Identities/AcAbbreviatedName",
995  settings.setValue("Identities/AcShortAbbreviatedName",
997  // setup:
998  // Pathes:
999  if (!shouldInvokeSystemWideWizard)
1000  {
1001  settings.setValue("Setup/Path2Home",
1002  setup.getPath2Home());
1003  };
1004  settings.setValue("Setup/Path2SolveAPrioriFiles",
1006  settings.setValue("Setup/Path2VgosDbFiles",
1008  settings.setValue("Setup/Path2MasterFiles",
1010  settings.setValue("Setup/CalcAprioriFileSites",
1012  settings.setValue("Setup/CalcAprioriFileSources",
1014  settings.setValue("Setup/CalcAprioriFileOceanLd",
1016  settings.setValue("Setup/CalcAprioriFileEops",
1018  settings.setValue("Setup/CalcAprioriFileTilts",
1020  settings.setValue("Setup/CalcAprioriFileOceanPoleTideLd",
1022  settings.setValue("Setup/Path2AuxLogs",
1024  settings.setValue("Setup/Have2SavePerSessionLog",
1026  settings.setValue("Setup/UseLocalLocale",
1028  //
1029  // store logger's config:
1030  settings.setValue("Logger/FileName",
1031  logger->getFileName());
1032  // logger->getDirName();
1033  settings.setValue("Logger/Capacity",
1034  logger->getCapacity());
1035  settings.setValue("Logger/IsStoreInFile",
1037  settings.setValue("Logger/IsNeedTimeMark",
1039  //
1040 };
1041 /*=====================================================================================================*/
1042 
1043 
1044 
1045 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
QString interval2Str(double days)
Definition: SgMJD.cpp:1370
SgVersion libraryVersion("SgLib", 0, 7, 5, "Tuscarora (rc1)", SgMJD(2022, 2, 18, 17, 34))
VcCalc2SessionIfc c2s
SgVersion vgosDbCalcVersion("vgosDbCalc", 0, 4, 4, "Tabler Run", SgMJD(2022, 2, 27, 16, 28))
void addAttr(uint a)
Definition: SgAttribute.h:202
const QString & getAcAbbrevName() const
Definition: SgIdentities.h:247
const QString & getAcAbbName() const
Definition: SgIdentities.h:255
void setAcAbbrevName(const QString &)
Definition: SgIdentities.h:367
void setAcFullName(const QString &)
Definition: SgIdentities.h:359
const QString & getUserEmailAddress() const
Definition: SgIdentities.h:223
void setAcAbbName(const QString &)
Definition: SgIdentities.h:375
const QString & getMachineMachineName() const
Definition: SgIdentities.h:303
const QString & getMachineRelease() const
Definition: SgIdentities.h:319
const QString & getMachineNodeName() const
Definition: SgIdentities.h:295
const QString & getUserDefaultInitials() const
Definition: SgIdentities.h:231
const QString & getAcFullName() const
Definition: SgIdentities.h:239
void setUserDefaultInitials(const QString &)
Definition: SgIdentities.h:351
void setUserEmailAddress(const QString &)
Definition: SgIdentities.h:343
void setUserName(const QString &)
Definition: SgIdentities.h:335
const QString & getUserName() const
Definition: SgIdentities.h:215
const QString & getMachineSysName() const
Definition: SgIdentities.h:311
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
bool getIsStoreInFile() const
Definition: SgLogger.h:137
void attachSupplementLog(const QString &name, SgLogger *auxLogger)
Definition: SgLogger.cpp:172
void setIsStoreInFile(bool isStoreInFile)
Definition: SgLogger.h:127
void setLogFacility(LogLevel lvl, quint32 f)
Definition: SgLogger.h:131
void setFileName(const QString &fileName)
Definition: SgLogger.h:125
void setIsNeedTimeMark(bool isNeedTimeMark)
Definition: SgLogger.h:129
void setDirName(const QString &dirName)
Definition: SgLogger.h:124
@ SESSION
Definition: SgLogger.h:77
virtual void clearSpool()
Definition: SgLogger.cpp:116
void setCapacity(int capacity)
Definition: SgLogger.h:126
bool getIsNeedTimeMark() const
Definition: SgLogger.h:139
const QString & getFileName() const
Definition: SgLogger.h:135
int getCapacity() const
Definition: SgLogger.h:136
void setIsMute(bool is)
Definition: SgLogger.h:130
void detachSupplementLog(const QString &name)
Definition: SgLogger.cpp:187
void rmLogFile()
Definition: SgLogger.cpp:148
Definition: SgMJD.h:59
@ F_DDMonYYYY
Date: 2010 Apr 02.
Definition: SgMJD.h:87
QString toString(Format format=F_Verbose) const
Definition: SgMJD.cpp:1007
static SgMJD currentMJD()
Definition: SgMJD.cpp:118
@ OM_DRY_RUN
Definition: SgNetCdf.h:325
const QString & getKey() const
Definition: SgObjectInfo.h:319
@ NF_Petrov
Definition: SgVersion.h:59
const SgMJD & getReleaseEpoch() const
Definition: SgVersion.h:294
const QString & getSoftwareName() const
Definition: SgVersion.h:254
QString name(NameFormat fmt=NF_Human) const
Definition: SgVersion.cpp:54
void setOperationMode(SgNetCdf::OperationMode om)
Definition: SgVgosDb.h:344
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:533
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 &)
SgVgosDb *& vgosDb()
void setPath2SolveAprioriFiles(const QString &)
Definition: VcSetup.h:289
const QString & getAprioriFile4Sources() const
Definition: VcSetup.h:81
const QString & getAprioriFile4Sites() const
Definition: VcSetup.h:80
const QString & getAprioriFile4Tilts() const
Definition: VcSetup.h:84
void setAprioriFile4Tilts(const QString &file)
Definition: VcSetup.h:131
bool getHave2SavePerSessionLog() const
Definition: VcSetup.h:247
const QString & getPath2Home() const
Definition: VcSetup.h:207
const QString & getPath2SolveAprioriFiles() const
Definition: VcSetup.h:223
void setAprioriFile4OceanPoleTideLd(const QString &file)
Definition: VcSetup.h:132
void setAprioriFile4Sites(const QString &file)
Definition: VcSetup.h:127
void setPath2MasterFiles(const QString &)
Definition: VcSetup.h:297
QString path2(const QString &) const
Definition: VcSetup.h:329
const QString & getAprioriFile4OceanLd() const
Definition: VcSetup.h:82
void setPath2AuxLogs(const QString &)
Definition: VcSetup.h:305
const QString & getPath2VgosDbFiles() const
Definition: VcSetup.h:215
const QString & getPath2MasterFiles() const
Definition: VcSetup.h:231
bool getUseLocalLocale() const
Definition: VcSetup.h:97
void setAprioriFile4Eops(const QString &file)
Definition: VcSetup.h:130
void setPath2VgosDbFiles(const QString &)
Definition: VcSetup.h:281
void setUseLocalLocale(bool use)
Definition: VcSetup.h:138
const QString & getAprioriFile4Eops() const
Definition: VcSetup.h:83
const QString & getPath2AuxLogs() const
Definition: VcSetup.h:239
SgIdentities & identities()
Definition: VcSetup.h:263
const QString & getAprioriFile4OceanPoleTideLd() const
Definition: VcSetup.h:85
void setHave2SavePerSessionLog(bool)
Definition: VcSetup.h:313
void setAprioriFile4Sources(const QString &file)
Definition: VcSetup.h:128
void setPath2Home(const QString &)
Definition: VcSetup.h:273
void setUpBinaryIdentities(const QString &)
Definition: VcSetup.cpp:74
void setAprioriFile4OceanLd(const QString &file)
Definition: VcSetup.h:129
void print2stdOut()
Definition: VcSetup.cpp:86
static int serialNumber()
QString altSetupAppName
Definition: vgosDbCalc.cpp:85
QSettings * settings
Definition: vgosDbCalc.cpp:83
bool have2ForceWizard
Definition: vgosDbCalc.cpp:88
QString inputArg
Definition: vgosDbCalc.cpp:86
bool useStdLocale
Definition: vgosDbCalc.cpp:91
bool have2UseAltSetup
Definition: vgosDbCalc.cpp:87
QString altSetupName
Definition: vgosDbCalc.cpp:84
bool shouldInvokeSystemWideWizard
Definition: vgosDbCalc.cpp:89
void loadSettings(QSettings &)
Definition: vgosDbCalc.cpp:891
QCoreApplication * createApplication(int &argc, char *argv[], bool isGuiEnabled)
Definition: vgosDbCalc.cpp:182
const QString origOrgName("NASA GSFC")
char progname[80]
Definition: vgosDbCalc.cpp:74
int main(int argc, char **argv)
Definition: vgosDbCalc.cpp:201
const QString origDmnName("gsfc.nasa.gov")
const char * argp_program_bug_address
Definition: vgosDbCalc.cpp:79
static int parse_opt(int key, char *arg, struct argp_state *state)
Definition: vgosDbCalc.cpp:97
bool checkAprioriFiles()
Definition: vgosDbCalc.cpp:830
bool createCalcExtFile(const QString &fileName, int fd)
Definition: vgosDbCalc.cpp:765
int msglev
Definition: vgosDbCalc.cpp:75
const QString origAppName("vgosDbCalc")
void saveSettings(QSettings &, bool shouldInvokeSystemWideWizard)
Definition: vgosDbCalc.cpp:979
bool createCalcOnnFile(const QString &calcOnnFileName, int fd, const QString &sessionName, int version, const QString &acName, const QString &userName)
Definition: vgosDbCalc.cpp:799
VcSetup setup
Definition: vgosDbCalc.cpp:67
QString histIntroRec
#define f_false
Definition: vgosDbCalc.h:42
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)
struct @0 mode_
struct @1 extrnl_