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/QRegularExpression>
37 #include <QtCore/QTextStream>
38 
39 
40 #if QT_VERSION >= 0x050000
41 # include <QtWidgets/QApplication>
42 #else
43 # include <QtGui/QApplication>
44 #endif
45 
46 
47 
48 #include <SgIdentities.h>
49 #include <SgLogger.h>
50 #include <SgVgosDb.h>
51 #include <SgVlbiBand.h>
52 #include <SgVlbiSession.h>
53 
54 
55 
56 #include "vgosDbCalc.h"
57 #include "VcCalc2SessionIfc.h"
58 #include "VcStartupWizard.h"
59 
60 
61 
62 
63 void loadSettings(QSettings&);
64 void saveSettings(QSettings&, bool shouldInvokeSystemWideWizard);
65 
66 
67 
69 
70 const QString origOrgName("NASA GSFC");
71 const QString origDmnName("gsfc.nasa.gov");
72 const QString origAppName("vgosDbCalc");
73 
74 // HOPS's whims:
75 #ifdef OLD_HOPS
76 char progname[80];
77 int msglev = 2;
78 #endif
79 
80 
81 // for ARGP parser:
82 const char *argp_program_bug_address = "Sergei Bolotin <sergei.bolotin@nasa.gov>";
83 
85 {
86  QSettings *settings;
87  QString altSetupName;
88  QString altSetupAppName;
89  QString inputArg;
93  bool isDryRun;
95 };
96 
97 
98 //
99 // a parser for ARGP:
100 static int parse_opt(int key, char *arg, struct argp_state *state)
101 {
102 // int n;
103 // bool isOk;
104  QString str("");
105  struct vdbcOptions *options=(struct vdbcOptions*)state->input;
106  //
107  switch (key)
108  {
109  case 'a':
110  options->altSetupName = QString(arg);
111  if (!options->altSetupName.contains("/..")) // are there any other elements of path that we should avoid?
112  {
113  options->altSetupAppName = origAppName + "-" + options->altSetupName;
114  options->have2UseAltSetup = true;
115  }
116  else
117  {
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");
123  delete options->settings;
124  exit(22);
125  };
126  break;
127  case 'l':
128  options->useStdLocale = true;
129  break;
130  case 'p':
131  loadSettings(*options->settings);
133  exit(0);
134  break;
135  case 'q':
136  options->isDryRun = true;
137  break;
138 
139  //
140  case 'W':
141  options->shouldInvokeSystemWideWizard = true;
142  break;
143  case 'w':
144  options->have2ForceWizard = true;
145  break;
146  //
147  case 'V':
148  std::cout << qPrintable(vgosDbCalcVersion.name(SgVersion::NF_Petrov)) << "\n";
149  exit(0);
150  break;
151  //
152  case ARGP_KEY_ARG:
153  if (1 < state->arg_num)
154  {
155  argp_usage(state);
156  };
157  options->inputArg = QString(arg);
158  break;
159  case ARGP_KEY_END:
160  if (state->arg_num < 1 &&
161  !(options->have2ForceWizard || options->shouldInvokeSystemWideWizard))
162  argp_usage(state);
163  break;
164  default:
165  return ARGP_ERR_UNKNOWN;
166  break;
167  };
168  return 0;
169 };
170 //
171 
172 
173 
174 
175 bool createCalcExtFile(const QString& fileName, int fd);
176 bool createCalcOnnFile(const QString& calcOnnFileName, int fd, const QString& sessionName, int version,
177  const QString& acName, const QString& userName);
178 bool checkAprioriFiles();
179 
180 
181 
182 
183 
184 //
185 QCoreApplication* createApplication(int &argc, char *argv[], bool isGuiEnabled)
186 {
187  if (isGuiEnabled)
188  return new QApplication(argc, argv);
189  else
190  return new QCoreApplication(argc, argv);
191 };
192 
193 
194 
195 
196 
197 
198 /***===================================================================================================*/
204 int main(int argc, char** argv)
205 {
206  struct vdbcOptions options;
207 #ifdef SWCONFIG
208  const QString path2SystemWideConfig(SWCONFIG "/xdg");
209 #else
210  const QString path2SystemWideConfig("");
211 #endif
212  QString userCommand("");
213  bool isFirstRun;
214  bool isOk;
215  SgLogger *alHistory;
216  SgLogger *alDriver;
217  const char *calcMode = "mark3 ";
218  int rc;
219 
220  rc = 0;
221  options.settings = NULL;
222  options.altSetupAppName = QString("");
223  options.altSetupName = QString("");
224  options.inputArg = QString("");
225  options.have2UseAltSetup = false;
226  options.have2ForceWizard = false;
227  options.shouldInvokeSystemWideWizard = false;
228  options.isDryRun = false;
229  options.useStdLocale = false;
230 
231  QCoreApplication::setOrganizationName(origOrgName);
232  QCoreApplication::setOrganizationDomain(origDmnName);
233  QCoreApplication::setApplicationName(origAppName);
234 
235  // set up path to the system wide settings:
236  QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
237  //
238  //
239  options.settings = new QSettings;
240  //
241  // init the external structures:
242  // strncpy(mode_.c_mode, "mark3 ", 6);
243  for (int i=0; i<6; i++)
244  mode_.c_mode[i] = *(calcMode + i);
245  // clear the records:
246  memset(extrnl_.External_inputs, 0, sizeof(extrnl_.External_inputs));
247  memset(extrnl_.Ex_sites, 0, sizeof(extrnl_.Ex_sites));
248  memset(extrnl_.Ex_stars, 0, sizeof(extrnl_.Ex_stars));
249  memset(extrnl_.Ex_ocean, 0, sizeof(extrnl_.Ex_ocean));
250  memset(extrnl_.Ex_EOP, 0, sizeof(extrnl_.Ex_EOP));
251  memset(extrnl_.Ex_tilts, 0, sizeof(extrnl_.Ex_tilts));
252  memset(extrnl_.Ex_OPTL, 0, sizeof(extrnl_.Ex_OPTL));
253  extrnl_.External_aprioris = f_false;
254  extrnl_.Input_sites = f_false;
255  extrnl_.Input_stars = f_false;
256  extrnl_.Input_ocean = f_false;
257  extrnl_.Input_EOP = f_false;
258  extrnl_.Input_tilts = f_false;
259  extrnl_.Input_OPTL = f_false;
260  extrnl_.le4 = f_false;
261 
262  // check for the legacy-style invocation:
263  if (argc==5)
264  {
265  QString sArg1(argv[1]), sArg2(argv[2]), sArg3(argv[3]), sArg4(argv[4]);
266  int nArg1, nArg2;
267  isOk = true;
268  nArg1 = nArg2 = 0;
269  nArg1 = sArg1.toInt(&isOk);
270  if (isOk)
271  nArg2 = sArg2.toInt(&isOk);
272  if (isOk) // check for calcOn file:
273  {
274  QFileInfo fi(sArg3);
275  if (!(fi.exists() && fi.isReadable()))
276  isOk = false;
277  };
278  if (isOk) // check for "external a priori" file:
279  {
280  QFileInfo fi(sArg4);
281  if (!(fi.exists() && fi.isReadable()))
282  isOk = false;
283  };
284  if (isOk) // looks like correct invocation
285  {
286  loadSettings(*options.settings);
287  if (!checkAprioriFiles())
288  {
289  rc = 1;
291  ": one of the external a priori files is missed, exiting");
292  return rc;
293  }
294  else
295  {
297  mimicCalcMain(nArg1, nArg2, argv[3], argv[4]);
298  };
299  };
300  };
301  //
302  // ok, normal calling:
303  bool isGuiEnabled;
304  const char* envDisplay=NULL;
305  //
306  isGuiEnabled = (envDisplay=getenv("DISPLAY"))!=NULL && 0<strlen(envDisplay);
307 
308  QScopedPointer<QCoreApplication>
309  app(createApplication(argc, argv, isGuiEnabled));
310  if (qobject_cast<QApplication *>(app.data()))
311  {
312  // do something with GUI
313  }
314  else
315  {
316  // do something for non-GUI
317  };
318  //
319  // especially for HOPS:
320 #ifdef OLD_HOPS
321  strcpy(progname, qPrintable("HOPS (on behalf of " + vgosDbCalcVersion.getSoftwareName() + ")"));
322 #endif
323  //
324  setup.setUpBinaryIdentities(QString(argv[0]));
325  for (int i=0; i<argc; i++)
326  userCommand += QString(argv[i]) + " ";
327  userCommand.chop(1);
328 
329  //
330  // ARGP setup:
331  //
332  struct argp_option argp_options[] =
333  {
334  {0, 0, 0, 0, "General options:", 10},
335  {"std-locale", 'l', 0, 0,
336  "Use the standard locale"},
337 
338  {0, 0, 0, 0, "Configuration control:", 11},
339  {"alt", 'a', "STRING", 0,
340  "Use an alternative configuration STRING"},
341 
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"},
347 
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 "
353  "will be printed"},
354  {"version", 'V', 0, 0,
355  "Print program version"},
356  //
357  {0}
358  };
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");
364 
365  salute += "The current version is:\n\t" + vgosDbCalcVersion.name() + " released on " +
367  "\n\t" + libraryVersion.name() + " released on " +
369  salute +=
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");
373 
374  struct argp argp={argp_options, parse_opt, "DATABASE", salute.toLatin1()};
375 
376  argp_parse (&argp, argc, argv, 0, 0, &options);
377 
378  //
379  //
380  isFirstRun = options.settings->allKeys().size()>0 ? false : true;
381  //
382  //
383 
384  //
385  if (options.have2UseAltSetup)
386  {
388  ": using alternative config name \"" + options.altSetupName + "\"");
389  QSettings *altSettings=new QSettings(origOrgName, options.altSetupAppName);
390  loadSettings(*altSettings);
391  delete options.settings;
392  options.settings = altSettings;
393  }
394  else
395  loadSettings(*options.settings);
396  //
397  //
398  if (isGuiEnabled)
399  {
400  if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard ||
401  options.settings->value("Version/StartUpWizard", 0).toInt() < VcStartupWizard::serialNumber())
402  {
403  if (options.shouldInvokeSystemWideWizard)
404  {
405  if (!options.have2UseAltSetup)
406  {
407  QSettings *swSettings =
408  new QSettings(QSettings::SystemScope, origOrgName, origAppName);
409  if (!swSettings->isWritable())
410  {
411  rc = 1;
413  ": cannot write system wide config");
414  delete swSettings;
415  return rc;
416  };
417  delete options.settings;
418  options.settings = swSettings;
419  }
420  else
422  ": using an alternative config name, system wide config edit request ignored");
423  };
424  //
425  VcStartupWizard startup(isFirstRun, options.have2ForceWizard,
426  options.shouldInvokeSystemWideWizard, options.settings);
427  if (startup.exec() == QDialog::Rejected)
428  {
429  delete options.settings;
430  logger->clearSpool();
431  return rc; // rc == 0, it is ok
432  };
433  //
434  // save if user pressed "Finish":
435  options.settings->setValue("Version/StartUpWizard", startup.serialNumber());
437  //
438  // it is ok, exitting:
439  if (!options.inputArg.size())
440  {
441  delete options.settings;
442  logger->clearSpool();
443  return rc;
444  };
445  };
446  }
447  else if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard)
448  {
449  rc = 1;
451  ": cannot run graphical application.");
452  delete options.settings;
453  logger->clearSpool();
454  return rc;
455  };
456  //
457  if (!options.inputArg.size())
458  {
459  rc = 1;
461  ": no input files provided.");
462  logger->clearSpool();
463  return rc;
464  };
465  //
466  if (!checkAprioriFiles())
467  {
468  rc = 1;
470  ": one of the external a priori files is missed, exiting");
471  return rc;
472  };
473  //
474  // determine a name of a wrapper file:
475  QString path2wrapperFile("");
476  QString wrapperFileName("");
477  QString sessionName("");
478  int version(0);
479 //QRegExp reDatabaseName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}$");
480 //QRegExp reDatabaseVersionName("^[0-9]{2}[A-Z]{3}[0-9]{2}[A-Z0-9]{1,2}_V[0-9]{3}$");
481  QRegularExpression reOldDbName("^(\\d{2}[A-Z]{3}\\d{2}[A-Z0-9]{1,2}).*");
482  QRegularExpression reNewDbName("^(\\d{8})-([\\S]{2,12}).*");
483 //QRegularExpressionMatch match;
484 
485 
486  // ok, this is a wrapper file name:
487  if (options.inputArg.right(4) == ".wrp")
488  {
490  setup.path2(setup.getPath2VgosDbFiles()), path2wrapperFile, wrapperFileName, sessionName, version);
491  }
492  else if ( reOldDbName.match(options.inputArg).hasMatch() ||
493  reNewDbName.match(options.inputArg).hasMatch() )
494 // else if (reDatabaseName.exactMatch(options.inputArg) ||
495 // reDatabaseVersionName.exactMatch(options.inputArg))
496  {
499  path2wrapperFile, wrapperFileName, sessionName, version);
500  }
501  else
502  {
504  ": cannot guess input data.");
505  isOk = false;
506  rc = 1;
507  };
508 
509  char buff[180];
510  QString calcExtFileName("");
511  QString calcOnnFileName("");
512  QString userLoginName("unkn");
513  QString path2tmpDir("/tmp");
514  int fd;
515 
516  if (getenv("TMPDIR") && strlen(getenv("TMPDIR"))>0)
517  {
518  path2tmpDir = QString(getenv("TMPDIR"));
520  ": the path to tmp dir has been alternated: \"" + path2tmpDir + "\"");
521  };
522 
523 
524  // guess user login name:
525  uid_t uid=geteuid();
526  struct passwd *pw=getpwuid(uid);
527  if (!pw)
528  perror("getpwuid: ");
529  else
530  userLoginName = pw->pw_name;
531 
532  if (isOk)
533  {
534  memset(buff, 0, sizeof(buff));
535  sprintf(buff, "%s/%s.calcExt.%s-XXXXXX",
536  qPrintable(path2tmpDir),
537  qPrintable(vgosDbCalcVersion.getSoftwareName()), qPrintable(userLoginName));
538  if ((fd=mkstemp(buff)) == -1)
539  {
541  ": cannot create calcExt file.");
542  isOk = false;
543  rc = 1;
544  };
545  };
546  if (isOk)
547  {
548  calcExtFileName = buff;
549  isOk = createCalcExtFile(calcExtFileName, fd);
550  };
551  //
552  if (isOk)
553  {
554  memset(buff, 0, sizeof(buff));
555  sprintf(buff, "%s/%s.calcOn.%s-XXXXXX",
556  qPrintable(path2tmpDir),
557  qPrintable(vgosDbCalcVersion.getSoftwareName()), qPrintable(userLoginName));
558  if ((fd=mkstemp(buff)) == -1)
559  {
561  ": cannot create calcOn file.");
562  isOk = false;
563  rc = 1;
564  };
565  };
566  if (isOk)
567  {
568  calcOnnFileName = buff;
569  isOk = createCalcOnnFile(calcOnnFileName, fd, sessionName, version,
571  };
572  //
573  //
574  QString sLang(""), sLcAll("");
575  if (!setup.getUseLocalLocale() || options.useStdLocale)
576  {
577  if (getenv("LANG"))
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\"");
587  };
588  //
589  //
590  if (isOk)
591  {
592  SgMJD startEpoch=SgMJD::currentMJD();
594  ": starting");
595 
596  //
597  alDriver = new SgLogger(800, setup.getHave2SavePerSessionLog(), "drv-unnamed.log");
599  alDriver->setIsNeedTimeMark(true);
600  alDriver->setIsMute(true);
601  alDriver->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
602  alDriver->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
603  alDriver->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
604  alDriver->setLogFacility(SgLogger::DBG, 0);
606  logger->attachSupplementLog("Driver", alDriver);
607  alDriver->setFileName(sessionName + ".log");
608  alDriver->rmLogFile();
609  //
610  alHistory = new SgLogger(0, false, "");
611  alHistory->setIsNeedTimeMark(false);
612  alHistory->setIsMute(true);
613  alHistory->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
614  alHistory->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
615  alHistory->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
616  alHistory->setLogFacility(SgLogger::DBG, 0);
617  // commented out: want logs from calc only
618  // logger->addSupplementLog("History", alHistory);
619  //
620  //
621  SgVgosDb *vgosDb;
622  SgVlbiSession session;
623  //
625  //
626  //
627  //------------------------------------------------------------------------------------------
628  vgosDb = new SgVgosDb(&setup.identities(), &vgosDbCalcVersion);
630  ": the vgosDb object has been created");
631 
632  isOk = vgosDb->init(path2wrapperFile, wrapperFileName);
634  ": parsing of wrapper file " + path2wrapperFile + "/" + wrapperFileName +
635  (isOk?" complete":" failed"));
636 
637  if (isOk && session.getDataFromVgosDb(vgosDb, true, isGuiEnabled))
638  {
639  // collect log entries to save them into the history block of the session:
640  logger->attachSupplementLog("History", alHistory);
641 
643  ": Library ID: " + libraryVersion.name() + " released on " +
646  ": Driver ID: " + vgosDbCalcVersion.name() + " released on " +
648 
650  ": Host ID: " + setup.identities().getMachineNodeName() +
651  " (Hw: " + setup.identities().getMachineMachineName() +
652  "; Sw: " + setup.identities().getMachineRelease() +
653  " version of " + setup.identities().getMachineSysName() + ")");
654 
656  ": User ID: " + setup.identities().getUserName() +
659  ": User command: \"" + userCommand + "\"");
661  ": Input data : " + path2wrapperFile + "/" + wrapperFileName);
662 
664  ": External a priori setup: ");
666  ": SITES : " +
669  ": Sources : " +
672  ": Ocean : " +
675  ": EOPs : " +
678  ": Tilts : " +
681  ": OPTL : " +
683 
685  ": the session " + session.getSessionCode() + " (" + session.getName() +
686  ") has been imported from vgosDb data set");
687 
688  // set up calc2session interface:
690  c2s.session() = &session;
691  c2s.vgosDb() = vgosDb;
692  if (sessionName.size()==8)
693  sessionName = sessionName + ' ';
694  c2s.setInputDbName(sessionName);
695  c2s.setPath2Data(path2wrapperFile);
696  c2s.setWrapperFileName(wrapperFileName);
697 
698  // run calc:
699  QList<QString> bands;
700  QString bandKey(""), bandList("");
701  if (session.primaryBand())
702  {
703  bandKey = session.primaryBand()->getKey();
704  bands.append(bandKey);
705  bandList = bandKey + ", ";
706  };
707  for (int i=0; i<session.bands().size(); i++)
708  if (session.bands().at(i)->getKey() != bandKey)
709  {
710  bands.append(session.bands().at(i)->getKey());
711  bandList += session.bands().at(i)->getKey() + ", ";
712  };
713  if (bandList.size() > 2)
714  bandList.chop(2);
716  ": collected " + QString("").setNum(bands.size()) + " bands: " + bandList);
717  //
718  // call CALC:
719  //
720  mimicCalcMain2(0, -1, qPrintable(calcOnnFileName), qPrintable(calcExtFileName), bands);
721  //
723  ": running observations through CALC has " + (isOk?"been complete":"failed"));
724 
725  // save the session:
726  if (isOk)
727  {
729  if (options.isDryRun)
731 
732  isOk = session.putDataIntoVgosDb(vgosDb);
734  ": export of data into vgosDB tree has " + (isOk?"been complete":"failed"));
735  if (!isOk)
736  rc = 1;
737  }
738  else
740  ": nothing to write");
741  }
742  else
743  {
745  ": import data of " + path2wrapperFile + "/" + wrapperFileName + " failed");
746  rc = 1;
747  };
748  //
749  alDriver->clearSpool();
750  logger->detachSupplementLog("History");
751  logger->detachSupplementLog("Driver");
752  delete alHistory;
753  delete alDriver;
754  //
755  delete vgosDb;
757  ": vgosDb object has been destroyed.");
758 
759  // report elapsed time:
760  SgMJD finisEpoch=SgMJD::currentMJD();
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);
765  }
766  else
767  rc = 1;
768  //
769  if (!setup.getUseLocalLocale() || options.useStdLocale)
770  {
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 + "\"");
777  };
778  //
779  if (QFile::exists(calcExtFileName))
780  QFile::remove(calcExtFileName);
781  if (QFile::exists(calcOnnFileName))
782  QFile::remove(calcOnnFileName);
783 
784  delete options.settings;
785  logger->clearSpool();
786  return rc;
787 };
788 
789 
790 
791 //
792 bool createCalcExtFile(const QString& fileName, int fd)
793 {
794  QFile f(fileName);
795  if (!f.open(QIODevice::WriteOnly))
796  {
798  "createCalcExtFile(): error opening calcExt file: " + fileName);
799  return false;
800  };
801  QTextStream ts(&f);
802  close(fd);
803  QString str;
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";
816  ts.setDevice(NULL);
817  f.close();
819  "createCalcExtFile(): the external a priori parameters were saved in the file \"" + fileName + "\"");
820  return true;
821 };
822 
823 
824 
825 //
826 bool createCalcOnnFile(const QString& calcOnnFileName, int fd, const QString& sessionName, int version,
827  const QString& acName, const QString& userName)
828 {
829  QFile f(calcOnnFileName);
830  QString str("");
831  if (!f.open(QIODevice::WriteOnly))
832  {
834  "createCalcOnnFile(): error opening calcExt file: " + calcOnnFileName);
835  return false;
836  };
837  QTextStream ts(&f);
838  close (fd);
839  // to override the CALC's bug:
840  histIntroRec = "Calc 11 at " + acName + " -" + userName + "-";
841  ts << qPrintable(histIntroRec) << "\n";
842  str.sprintf("$%-22s %3d $%-22s", qPrintable(sessionName), version, qPrintable(sessionName));
843 //str.sprintf("$%-9s %8d $%-9s", qPrintable(sessionName), version, qPrintable(sessionName));
844  ts << qPrintable(str) << "\n"
845  << "00000000000000000000000000000000000000000000000000000000000000\n";
846 
847  ts.setDevice(NULL);
848  f.close();
850  "createCalcOnnFile(): the CALC control data were saved in the file \"" +
851  calcOnnFileName + "\"");
852  return true;
853 };
854 
855 
856 
857 //
859 {
860  bool isOk;
861  QString fileName;
862  isOk = true;
864  if (!QFile::exists(fileName))
865  {
867  "checkAprioriFiles(): the external a priori file for sites \"" + fileName + "\" does not exist");
868  isOk = false;
869  };
870 
872  if (!QFile::exists(fileName))
873  {
875  "checkAprioriFiles(): the external a priori file for sources \"" + fileName + "\" does not exist");
876  isOk = false;
877  };
878 
880  if (!QFile::exists(fileName))
881  {
883  "checkAprioriFiles(): the external a priori file for ocean loading \"" + fileName +
884  "\" does not exist");
885  isOk = false;
886  };
887 
889  if (!QFile::exists(fileName))
890  {
892  "checkAprioriFiles(): the external a priori file for EOPs \"" + fileName + "\" does not exist");
893  isOk = false;
894  };
895 
897  if (!QFile::exists(fileName))
898  {
900  "checkAprioriFiles(): the external a priori file for tilts \"" + fileName + "\" does not exist");
901  isOk = false;
902  };
903 
904  fileName = setup.path2(setup.getPath2SolveAprioriFiles()) + "/" +
906  if (!QFile::exists(fileName))
907  {
909  "checkAprioriFiles(): the external a priori file for ocean pole tide loading \"" + fileName +
910  "\" does not exist");
911  isOk = false;
912  };
913  return isOk;
914 };
915 
916 
917 
918 //
919 void loadSettings(QSettings& settings)
920 {
921  int logLevel;
922  //
923  // setup.identities:
925  settings.value("Identities/UserName",
926  setup.identities().getUserName()).toString());
928  settings.value("Identities/UserEmailAddress",
929  setup.identities().getUserEmailAddress()).toString());
931  settings.value("Identities/UserDefaultInitials",
932  setup.identities().getUserDefaultInitials()).toString());
934  settings.value("Identities/AcFullName",
935  setup.identities().getAcFullName()).toString());
937  settings.value("Identities/AcAbbreviatedName",
938  setup.identities().getAcAbbrevName()).toString());
940  settings.value("Identities/AcShortAbbreviatedName",
941  setup.identities().getAcAbbName()).toString());
942 
943  // setup:
944  // Pathes:
946  settings.value("Setup/Path2Home",
947  setup.getPath2Home()).toString());
949  settings.value("Setup/Path2SolveAPrioriFiles",
950  setup.getPath2SolveAprioriFiles()).toString());
952  settings.value("Setup/Path2VgosDbFiles",
953  setup.getPath2VgosDbFiles()).toString());
955  settings.value("Setup/Path2MasterFiles",
956  setup.getPath2MasterFiles()).toString());
958  settings.value("Setup/CalcAprioriFileSites",
959  setup.getAprioriFile4Sites()).toString());
961  settings.value("Setup/CalcAprioriFileSources",
962  setup.getAprioriFile4Sources()).toString());
964  settings.value("Setup/CalcAprioriFileOceanLd",
965  setup.getAprioriFile4OceanLd()).toString());
967  settings.value("Setup/CalcAprioriFileEops",
968  setup.getAprioriFile4Eops()).toString());
970  settings.value("Setup/CalcAprioriFileTilts",
971  setup.getAprioriFile4Tilts()).toString());
973  settings.value("Setup/CalcAprioriFileOceanPoleTideLd",
974  setup.getAprioriFile4OceanPoleTideLd()).toString());
976  settings.value("Setup/Path2AuxLogs",
977  setup.getPath2AuxLogs()).toString());
979  settings.value("Setup/Have2SavePerSessionLog",
980  setup.getHave2SavePerSessionLog()).toBool());
982  settings.value("Setup/UseLocalLocale",
983  setup.getUseLocalLocale()).toBool());
984  //
985  // adjust the logger:
987  settings.value("Logger/FileName",
988  "vgosDbCalc.log").toString());
991  settings.value("Logger/Capacity", 400).toInt());
993  settings.value("Logger/IsStoreInFile", logger->getIsStoreInFile()).toBool());
995  settings.value("Logger/IsNeedTimeMark", logger->getIsNeedTimeMark()).toBool());
996  logLevel = settings.value("Logger/LogLevel", 2).toInt();
997  logger->setLogFacility(SgLogger::ERR, logLevel>=0?0xFFFFFFFF:0);
998  logger->setLogFacility(SgLogger::WRN, logLevel>=1?0xFFFFFFFF:0);
999  logger->setLogFacility(SgLogger::INF, logLevel>=2?0xFFFFFFFF:0);
1000  logger->setLogFacility(SgLogger::DBG, logLevel==3?0xFFFFFFFF:0);
1001  //
1002 };
1003 
1004 
1005 
1006 //
1007 void saveSettings(QSettings& settings, bool shouldInvokeSystemWideWizard)
1008 {
1009  // setup.identities:
1010  if (!shouldInvokeSystemWideWizard)
1011  {
1012  settings.setValue("Identities/UserName",
1014  settings.setValue("Identities/UserEmailAddress",
1016  settings.setValue("Identities/UserDefaultInitials",
1018  };
1019  settings.setValue("Identities/AcFullName",
1021  settings.setValue("Identities/AcAbbreviatedName",
1023  settings.setValue("Identities/AcShortAbbreviatedName",
1025  // setup:
1026  // Pathes:
1027  if (!shouldInvokeSystemWideWizard)
1028  {
1029  settings.setValue("Setup/Path2Home",
1030  setup.getPath2Home());
1031  };
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",
1056  //
1057  // store logger's config:
1058  settings.setValue("Logger/FileName",
1059  logger->getFileName());
1060  // logger->getDirName();
1061  settings.setValue("Logger/Capacity",
1062  logger->getCapacity());
1063  settings.setValue("Logger/IsStoreInFile",
1065  settings.setValue("Logger/IsNeedTimeMark",
1067  //
1068 };
1069 /*=====================================================================================================*/
1070 
1071 
1072 
1073 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
QString interval2Str(double days)
Definition: SgMJD.cpp:1371
SgVersion libraryVersion("SgLib", 0, 8, 2, "Compton Peak (rc2)", SgMJD(2023, 4, 3, 10, 59))
VcCalc2SessionIfc c2s
SgVersion vgosDbCalcVersion("vgosDbCalc", 0, 5, 2, "Fort Windham Rocks (rc2)", SgMJD(2023, 4, 3, 11, 6))
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:1008
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
@ 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:346
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:538
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:88
QSettings * settings
Definition: vgosDbCalc.cpp:86
bool have2ForceWizard
Definition: vgosDbCalc.cpp:91
QString inputArg
Definition: vgosDbCalc.cpp:89
bool useStdLocale
Definition: vgosDbCalc.cpp:94
bool have2UseAltSetup
Definition: vgosDbCalc.cpp:90
QString altSetupName
Definition: vgosDbCalc.cpp:87
bool shouldInvokeSystemWideWizard
Definition: vgosDbCalc.cpp:92
void loadSettings(QSettings &)
Definition: vgosDbCalc.cpp:919
QCoreApplication * createApplication(int &argc, char *argv[], bool isGuiEnabled)
Definition: vgosDbCalc.cpp:185
const QString origOrgName("NASA GSFC")
int main(int argc, char **argv)
Definition: vgosDbCalc.cpp:204
const QString origDmnName("gsfc.nasa.gov")
const char * argp_program_bug_address
Definition: vgosDbCalc.cpp:82
static int parse_opt(int key, char *arg, struct argp_state *state)
Definition: vgosDbCalc.cpp:100
bool checkAprioriFiles()
Definition: vgosDbCalc.cpp:858
bool createCalcExtFile(const QString &fileName, int fd)
Definition: vgosDbCalc.cpp:792
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)
Definition: vgosDbCalc.cpp:826
VcSetup setup
Definition: vgosDbCalc.cpp:68
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_