General Purpose Geodetic Library
vgosDbProcLogs.cpp
Go to the documentation of this file.
1 /*
2  * This file is a part of vgosDbProcLogs. vgosDbProcLogs is a part of
3  * CALC/SOLVE system and is designed to extract data, meteo parameters
4  * and cable calibrations, from stations log files and store them in
5  * the vgosDb format.
6  * Copyright (C) 2015-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 
24 #include <argp.h>
25 #include <unistd.h>
26 
27 
28 
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>
36 
37 
38 #if QT_VERSION >= 0x050000
39 # include <QtWidgets/QApplication>
40 #else
41 # include <QtGui/QApplication>
42 #endif
43 
44 
45 #include <SgIdentities.h>
46 #include <SgKombFormat.h>
47 #include <SgLogger.h>
48 #include <SgVgosDb.h>
49 #include <SgVlbiSession.h>
50 
51 
52 
53 #include "vgosDbProcLogs.h"
54 #include "VpStartupWizard.h"
55 
56 
57 
58 
59 void loadSettings(QSettings&);
60 void saveSettings(QSettings&, bool shouldInvokeSystemWideWizard);
61 
62 
63 
65 
66 const QString origOrgName("NASA GSFC");
67 const QString origDmnName("gsfc.nasa.gov");
68 const QString origAppName("vgosDbProcLogs");
69 
70 
71 // HOPS's whims:
72 char progname[80];
73 int msglev = 2;
74 
75 // for ARGP parser:
76 const char *argp_program_bug_address = "Sergei Bolotin <sergei.bolotin@nasa.gov>";
77 
79 {
80  QSettings *settings;
81  QString altSetupName;
82  QString altSetupAppName;
83  QString inputArg;
87  QString orderOfMeteo;
88  QMap<QString, int> knownKinds;
92  bool isDryRun;
97 };
98 
99 
100 //
101 // a parser for ARGP:
102 static int parse_opt(int key, char *arg, struct argp_state *state)
103 {
104  QString str("");
105  struct vdbpOptions *options=(struct vdbpOptions*)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 'd':
128  options->altPath2InputFiles = QString(arg);
129  break;
130  case 'k':
131  str = QString(arg);
132  if (options->knownKinds.contains(str))
133  options->kinds.append(str);
134  else
136  ": parse_opt(): got an unknown kind \"" + str + "\", ignoring");
137  break;
138  case 'l':
139  options->useStdLocale = true;
140  break;
141  case 'o':
142  options->orderOfMeteo = QString(arg).toUpper();
143  break;
144  case 'p':
145  loadSettings(*options->settings);
147  exit(0);
148  break;
149  case 'q':
150  options->isDryRun = true;
151  break;
152  case 's':
153  str = QString(arg);
154  options->stations.append(str);
156  ": parse_opt(): the station \"" + str + "\" is added to the process list");
157  break;
158  case 'z':
159  if (strcmp(arg, "c") == 0)
160  options->have2clearCableData = true;
161  else if (strcmp(arg, "m") == 0)
162  options->have2clearMeteoData = true;
163  else if (strcmp(arg, "t") == 0)
164  options->have2clearTsysData = true;
165  else
166  {
168  ": parse_opt(): unrecognized argument \"" + arg + "\" of \"-z\" option; "
169  "expected: \"c\", \"m\" or \"t\"");
170  };
171  break;
172 
173  //
174  case 'W':
175  options->shouldInvokeSystemWideWizard = true;
176  break;
177  case 'w':
178  options->have2ForceWizard = true;
179  break;
180  //
181  case 'V':
182  std::cout << qPrintable(vgosDbProcLogsVersion.name(SgVersion::NF_Petrov)) << "\n";
183  exit(0);
184  break;
185  //
186  case ARGP_KEY_ARG:
187  if (1 < state->arg_num)
188  {
189  argp_usage(state);
190  };
191  options->inputArg = QString(arg);
192  break;
193  case ARGP_KEY_END:
194  if (state->arg_num < 1 &&
195  !(options->have2ForceWizard || options->shouldInvokeSystemWideWizard))
196  argp_usage(state);
197  break;
198  default:
199  return ARGP_ERR_UNKNOWN;
200  break;
201  };
202  return 0;
203 };
204 //
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 //
220 QCoreApplication* createApplication(int &argc, char *argv[], bool isGuiEnabled)
221 {
222  if (isGuiEnabled)
223  return new QApplication(argc, argv);
224  else
225  return new QCoreApplication(argc, argv);
226 };
227 
228 
229 
230 /***===================================================================================================*/
236 int main(int argc, char** argv)
237 {
238  struct vdbpOptions options;
239  SgLogger *alHistory;
240  SgLogger *alDriver;
241 
242  QString sessionName("");
243  QString path2wrapperFile("");
244  QString wrapperFileName("");
245  QString userCommand("");
246 
247 
248 #ifdef SWCONFIG
249  const QString path2SystemWideConfig(SWCONFIG "/xdg");
250 #else
251  const QString path2SystemWideConfig("");
252 #endif
253  int rc;
254  bool isOk;
255  bool isFirstRun;
256  bool isGuiEnabled;
257  const char* envDisplay=NULL;
258 
259  rc = 0;
260  options.settings = NULL;
261  options.altSetupAppName = QString("");
262  options.altSetupName = QString("");
263  options.inputArg = QString("");
264  options.altPath2InputFiles = QString("");
265  options.orderOfMeteo = QString("");
266  options.stations.clear();
267  options.kinds.clear();
268  options.knownKinds.clear();
269  options.have2UseAltSetup = false;
270  options.have2ForceWizard = false;
271  options.shouldInvokeSystemWideWizard = false;
272  options.isDryRun = false;
273  options.useStdLocale = false;
274  options.have2clearCableData = false;
275  options.have2clearMeteoData = false;
276  options.have2clearTsysData = false;
277 
278  options.knownKinds.insert("log", 0);
279  options.knownKinds.insert("cdms", 1);
280  options.knownKinds.insert("pcmt", 2);
281  options.knownKinds.insert("met", 3);
282 
283  //
284  // init:
285  QCoreApplication::setOrganizationName(origOrgName);
286  QCoreApplication::setOrganizationDomain(origDmnName);
287  QCoreApplication::setApplicationName(origAppName);
288 
289  // set up path to the system wide settings:
290  QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
291  //
292  options.settings = new QSettings;
293  //
294  isGuiEnabled = (envDisplay=getenv("DISPLAY"))!=NULL && 0<strlen(envDisplay);
295  //
296  QScopedPointer<QCoreApplication>
297  app(createApplication(argc, argv, isGuiEnabled));
298  if (qobject_cast<QApplication *>(app.data()))
299  {
300  // do something with GUI
301  }
302  else
303  {
304  // do something for non-GUI
305  };
306  //
307  // especially for HOPS:
308  strcpy(progname, qPrintable("HOPS (on behalf of " + vgosDbProcLogsVersion.getSoftwareName() + ")"));
309  //
310  setup.setUpBinaryIdentities(QString(argv[0]));
311  for (int i=0; i<argc; i++)
312  userCommand += QString(argv[i]) + " ";
313  userCommand.chop(1);
314 
315 
316  //
317  // ARGP setup:
318  //
319  struct argp_option argp_options[] =
320  {
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"},
326 
327  {0, 0, 0, 0, "Configuration control:", 11},
328  {"alt", 'a', "STRING", 0,
329  "Use an alternative configuration STRING"},
330 
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"},
350 
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"},
356 
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 "
362  "will be printed"},
363  {"version", 'V', 0, 0,
364  "Print program version"},
365  //
366  {0}
367  };
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");
372 
373  salute += "The current version is:\n\t" + vgosDbProcLogsVersion.name() + " released on " +
375  "\n\t" + libraryVersion.name() + " released on " +
377  salute +=
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");
381 
382  struct argp argp={argp_options, parse_opt, "DATABASE", salute.toLatin1()};
383 
384  argp_parse (&argp, argc, argv, 0, 0, &options);
385  //
386  //
387  isFirstRun = options.settings->allKeys().size()>0 ? false : true;
388  //
389  //
390  if (options.have2UseAltSetup)
391  {
393  ": using alternative config name \"" + options.altSetupName + "\"");
394  QSettings *altSettings=new QSettings(origOrgName, options.altSetupAppName);
395  loadSettings(*altSettings);
396  delete options.settings;
397  options.settings = altSettings;
398  }
399  else
400  loadSettings(*options.settings);
401  //
402  if (options.orderOfMeteo.size()) // check user input:
403  {
404  isOk = true;
405  if (options.orderOfMeteo.size() < 3)
406  {
408  ": the size of meteo order string (" + QString("").setNum(options.orderOfMeteo.size()) +
409  ") is less than 3; ignoring");
410  isOk = false;
411  }
412  else if (options.orderOfMeteo.count('T') < 1)
413  {
415  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain temperature tag "
416  "(T or t); ignoring");
417  isOk = false;
418  }
419  else if (options.orderOfMeteo.count('P') < 1)
420  {
422  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain pressure tag "
423  "(P or p); ignoring");
424  isOk = false;
425  }
426  else if (options.orderOfMeteo.count('H') < 1)
427  {
429  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain relative humidity "
430  "tag (H or h); ignoring");
431  isOk = false;
432  }
433  else if (1 < options.orderOfMeteo.count('T'))
434  {
436  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one temperature "
437  "tag (T or t); ignoring");
438  isOk = false;
439  }
440  else if (1 < options.orderOfMeteo.count('P'))
441  {
443  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one pressure tag "
444  "(P or p); ignoring");
445  isOk = false;
446  }
447  else if (1 < options.orderOfMeteo.count('H'))
448  {
450  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one relative "
451  "humidity tag (H or h); ignoring");
452  isOk = false;
453  };
454  //
455  if (!isOk) // reset the string:
456  {
458  ": the meteo order string \"" + options.orderOfMeteo + "\" is invalid");
459  options.orderOfMeteo = QString("");
460  };
461  };
462 
463  //
464  //
465  //
466  if (isGuiEnabled)
467  {
468  if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard ||
469  options.settings->value("Version/StartUpWizard", 0).toInt() < VpStartupWizard::serialNumber())
470  {
471  if (options.shouldInvokeSystemWideWizard)
472  {
473  if (!options.have2UseAltSetup)
474  {
475  QSettings *swSettings =
476  new QSettings(QSettings::SystemScope, origOrgName, origAppName);
477  if (!swSettings->isWritable())
478  {
480  ": cannot write system wide config");
481  delete swSettings;
482  return 2;
483  };
484  delete options.settings;
485  options.settings = swSettings;
486  }
487  else
489  ": using an alternative config name, system wide config edit request ignored");
490  };
491  //
492  VpStartupWizard startup(isFirstRun, options.have2ForceWizard,
493  options.shouldInvokeSystemWideWizard, options.settings);
494  if ((rc=startup.exec()) == 0)
495  {
496  delete options.settings;
497  logger->clearSpool();
498  return rc;
499  };
500  //
501  // save if user pressed "Finish":
502  options.settings->setValue("Version/StartUpWizard", startup.serialNumber());
504  //
505  // it is ok, exitting:
506  if (!options.inputArg.size())
507  {
508  delete options.settings;
509  logger->clearSpool();
510  return 0;
511  };
512  };
513  }
514  else if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard)
515  {
517  ": cannot run graphical application.");
518  delete options.settings;
519  logger->clearSpool();
520  return 1;
521  };
522 
523  //
524  // determine a name of a wrapper file:
525  //
526  int version(0);
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}$");
530  //
531  // ok, this is a wrapper file name:
532  if (reWrapperFileName.indexIn(options.inputArg) != -1)
533  {
535  setup.path2(setup.getPath2VgosDbFiles()), path2wrapperFile, wrapperFileName,
536  sessionName, version);
537  if (isOk)
539  ": got a session " + sessionName + " of version " +
540  QString("").setNum(version) + " from \"" + path2wrapperFile + "\":\"" +
541  wrapperFileName + "\"");
542  else
544  ": cannot figure out a session from the input \"" + options.inputArg + "\"");
545  }
546  else if (reDatabaseName.exactMatch(options.inputArg) ||
547  reDatabaseVersionName.exactMatch(options.inputArg))
548  {
551  path2wrapperFile, wrapperFileName, sessionName, version);
552  if (isOk)
554  ": got a wrapper file \"" + wrapperFileName +
555  "\" from \"" + path2wrapperFile + "\" for the session " + sessionName +
556  " of version " + QString("").setNum(version));
557  else
559  ": cannot figure out a session from the input \"" + options.inputArg + "\"");
560  }
561  else
562  {
564  ": cannot guess input data from \"" + options.inputArg + "\"");
565  };
566  //
567  //
568  //
569  alDriver = new SgLogger(800, setup.getHave2SavePerSessionLog(), "drv-unnamed.log");
571  alDriver->setIsNeedTimeMark(true);
572  alDriver->setIsMute(true);
573  alDriver->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
574  alDriver->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
575  alDriver->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
576  alDriver->setLogFacility(SgLogger::DBG, 0);
578  logger->attachSupplementLog("Driver", alDriver);
579  //
580  alHistory = new SgLogger(0, false, "");
581  alHistory->setIsNeedTimeMark(false);
582  alHistory->setIsMute(true);
583  alHistory->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
584  alHistory->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
585  alHistory->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
586  alHistory->setLogFacility(SgLogger::DBG, 0);
587  //
588  //
589  //
590  isOk = false;
591  SgVgosDb *vgosDb;
592  SgVlbiSession session;
593  //
595  ": starting");
597  //
598  //
599  //------------------------------------------------------------------------------------------
600  //
601  QString sLang(""), sLcAll("");
602  if (!setup.getUseLocalLocale() || options.useStdLocale)
603  {
604  if (getenv("LANG"))
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\"");
614  };
615  //
616  SgMJD startEpoch=SgMJD::currentMJD();
617 
618  vgosDb = new SgVgosDb(&setup.identities(), &vgosDbProcLogsVersion);
620  ": the vgosDb object has been created");
621 
622  isOk = vgosDb->init(path2wrapperFile, wrapperFileName);
624  ": initSessionFromOdb(): parsing of wrapper file " + path2wrapperFile + "/" + wrapperFileName +
625  (isOk?" complete":" failed"));
626 
627  if (vgosDb->getSessionName().size())
628  alDriver->setFileName(vgosDb->getSessionName() + ".log");
629  else
630  alDriver->setFileName(sessionName + ".log");
631  alDriver->rmLogFile();
632 
633  if (isOk && session.getDataFromVgosDb(vgosDb, false, isGuiEnabled))
634  {
635  logger->attachSupplementLog("History", alHistory);
636 
638  ": Library ID: " + libraryVersion.name() + " released on " +
641  ": Driver ID: " + vgosDbProcLogsVersion.name() + " released on " +
643 
645  ": Host ID: " + setup.identities().getMachineNodeName() +
646  " (Hw: " + setup.identities().getMachineMachineName() +
647  "; Sw: " + setup.identities().getMachineRelease() +
648  " version of " + setup.identities().getMachineSysName() + ")");
649 
651  ": User ID: " + setup.identities().getUserName() +
654  ": User command: \"" + userCommand + "\"");
656  ": Input data : " + path2wrapperFile + "/" + wrapperFileName);
658  ": the session " + session.getSessionCode() + " (" + session.getName() +
659  ") has been imported from vgosDb data set");
660 
661  //
662  // clear data if necessary:
663  if (options.have2clearCableData || options.have2clearMeteoData || options.have2clearTsysData)
664  {
665  QString sWhat("");
666  QString sStns("all stations");
667 
668  if (options.have2clearCableData)
669  sWhat += "cable cal";
670  if (options.have2clearMeteoData)
671  sWhat += ", meteorological";
672  if (options.have2clearTsysData)
673  sWhat += ", tsys";
674  sWhat += " data";
675 
676  if (options.stations.size())
677  {
678  sStns = "selected station(s) ";
679  for (int i=0; i<options.stations.size(); i++)
680  sStns += options.stations.at(i) + ", ";
681  sStns.chop(2);
682  };
683  //
684  if (session.resetDataFromLogFiles(options.have2clearCableData, options.have2clearMeteoData,
685  options.have2clearTsysData, options.stations))
686  {
687  //
689  ": the " + sWhat + " were reset for " + sStns + " of the session " + session.getSessionCode() +
690  " (" + session.getName() + ")");
691  session.contemporaryHistory().addHistoryRecord("The " + sWhat + " were reset for " + sStns,
692  SgMJD::currentMJD().toUtc());
693  }
694  else
696  ": clearing the " + sWhat + " for " + sStns + " of the session " + session.getSessionCode() +
697  " (" + session.getName() + ") failed");
698  };
699  //
700  // parse log files and absorb the data:
702  options.stations, options.kinds, &setup.getDefaultCableSignByStn(),
704  false, false, options.altPath2InputFiles, options.orderOfMeteo);
706  ": import of data from station log files has " + (isOk?"been complete":"failed"));
707 
708  // save the session:
709  if (isOk)
710  {
711  if (options.isDryRun)
713  isOk = session.putDataIntoVgosDb(vgosDb);
715  ": export of data into vgosDb set has " + (isOk?"been complete":"failed"));
716  }
717  else
719  ": nothing to write");
720 
721  // report elapsed time:
722  SgMJD finisEpoch=SgMJD::currentMJD();
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);
727 // ": elapsed time is: " + interval2Str(finisEpoch - startEpoch) + " (" +
728 // QString("").sprintf("%.2f", (finisEpoch - startEpoch)*86400.0) + " sec)", true);
729 
730  delete vgosDb;
732  ": vgosDb object has been destroyed.");
733  }
734  else
736  ": import data of " + path2wrapperFile + "/" + wrapperFileName + " failed");
737 
738  //
739  if (!setup.getUseLocalLocale() || options.useStdLocale)
740  {
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 + "\"");
747  };
748 
749  alDriver->clearSpool();
750  logger->detachSupplementLog("Driver");
751  logger->detachSupplementLog("History");
752  delete alHistory;
753  delete alDriver;
754  delete options.settings;
755  logger->clearSpool();
756  return rc;
757 };
758 
759 
760 //
761 void loadSettings(QSettings& settings)
762 {
763  int logLevel;
764  //
765  // setup.identities:
767  settings.value("Identities/UserName",
768  setup.identities().getUserName()).toString());
770  settings.value("Identities/UserEmailAddress",
771  setup.identities().getUserEmailAddress()).toString());
773  settings.value("Identities/UserDefaultInitials",
774  setup.identities().getUserDefaultInitials()).toString());
776  settings.value("Identities/AcFullName",
777  setup.identities().getAcFullName()).toString());
779  settings.value("Identities/AcAbbreviatedName",
780  setup.identities().getAcAbbrevName()).toString());
782  settings.value("Identities/AcShortAbbreviatedName",
783  setup.identities().getAcAbbName()).toString());
784 
785  // setup:
786  // Pathes:
788  settings.value("Setup/Path2Home",
789  setup.getPath2Home()).toString());
791  settings.value("Setup/Path2SessionFiles",
792  setup.getPath2SessionFiles()).toString());
794  settings.value("Setup/Path2VgosDbFiles",
795  setup.getPath2VgosDbFiles()).toString());
797  settings.value("Setup/Path2MasterFiles",
798  setup.getPath2MasterFiles()).toString());
800  settings.value("Setup/Path2AuxLogs",
801  setup.getPath2AuxLogs()).toString());
803  settings.value("Setup/Have2SavePerSessionLog",
804  setup.getHave2SavePerSessionLog()).toBool());
806  settings.value("Setup/UseLocalLocale",
807  setup.getUseLocalLocale()).toBool());
808  //
809  // adjust the logger:
811  settings.value("Logger/FileName",
812  "vgosDbProcLogs.log").toString());
815  settings.value("Logger/Capacity", 400).toInt());
817  settings.value("Logger/IsStoreInFile", logger->getIsStoreInFile()).toBool());
819  settings.value("Logger/IsNeedTimeMark", logger->getIsNeedTimeMark()).toBool());
820  logLevel = settings.value("Logger/LogLevel", 2).toInt();
821  logger->setLogFacility(SgLogger::ERR, logLevel>=0?0xFFFFFFFF:0);
822  logger->setLogFacility(SgLogger::WRN, logLevel>=1?0xFFFFFFFF:0);
823  logger->setLogFacility(SgLogger::INF, logLevel>=2?0xFFFFFFFF:0);
824  logger->setLogFacility(SgLogger::DBG, logLevel==3?0xFFFFFFFF:0);
825  //
826  //
827  int size, defaultCableSign;
828  QString stationKey(""), rinexFileName("");
829  double dP;
830  if ( (size = settings.beginReadArray("Setup/DefaultCableSignByStn")) )
831  {
832  // remove default set up:
833  setup.defaultCableSignByStn().clear();
834  // load saved data:
835  for (int i=0; i<size; ++i)
836  {
837  settings.setArrayIndex(i);
838  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
839  defaultCableSign = settings.value("DefaultCableSign", 1).toInt();
840  setup.defaultCableSignByStn().insert(stationKey, defaultCableSign);
841  };
842  }
843  else
845  ": loadSettings(): no DefaultCableSignByStn found, using default set up");
846  settings.endArray();
847  //
848  // RINEX stuff:
849  // file names:
850  if ( (size = settings.beginReadArray("Setup/RinexFileNameByStn")) )
851  {
852  // remove default set up:
853  setup.rinexFileNameByStn().clear();
854  // load saved data:
855  for (int i=0; i<size; ++i)
856  {
857  settings.setArrayIndex(i);
858  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
859  rinexFileName = settings.value("RinexFileName").toString();
860  setup.rinexFileNameByStn().insert(stationKey, rinexFileName);
861  };
862  }
863  else
865  ": loadSettings(): no RinexFileNameByStn found, using default set up");
866  settings.endArray();
867  // pressure offset:
868  if ( (size = settings.beginReadArray("Setup/RinexPressureOffsetByStn")) )
869  {
870  // remove default set up:
872  // load saved data:
873  for (int i=0; i<size; ++i)
874  {
875  settings.setArrayIndex(i);
876  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
877  dP = settings.value("RinexPressureOffset", 0.0).toDouble();
878  setup.rinexPressureOffsetByStn().insert(stationKey, dP);
879  };
880  }
881  else
883  ": loadSettings(): no RinexPressureOffsetByStn found, using default set up");
884  settings.endArray();
885 };
886 
887 
888 
889 //
890 void saveSettings(QSettings& settings, bool shouldInvokeSystemWideWizard)
891 {
892  // setup.identities:
893  if (!shouldInvokeSystemWideWizard)
894  {
895  settings.setValue("Identities/UserName",
897  settings.setValue("Identities/UserEmailAddress",
899  settings.setValue("Identities/UserDefaultInitials",
901  };
902  settings.setValue("Identities/AcFullName",
904  settings.setValue("Identities/AcAbbreviatedName",
906  settings.setValue("Identities/AcShortAbbreviatedName",
908  // setup:
909  // Pathes:
910  if (!shouldInvokeSystemWideWizard)
911  {
912  settings.setValue("Setup/Path2Home",
913  setup.getPath2Home());
914  };
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",
927  //
928  // store logger's config:
929  settings.setValue("Logger/FileName",
930  logger->getFileName());
931  // logger->getDirName();
932  settings.setValue("Logger/Capacity",
933  logger->getCapacity());
934  settings.setValue("Logger/IsStoreInFile",
936  settings.setValue("Logger/IsNeedTimeMark",
938  //
939  //
940  settings.remove("Setup/DefaultCableSignByStn");
941  settings.beginWriteArray("Setup/DefaultCableSignByStn", setup.getDefaultCableSignByStn().size());
942  int idx(0);
943  for (QMap<QString, int>::const_iterator it=setup.getDefaultCableSignByStn().begin();
944  it!=setup.getDefaultCableSignByStn().end(); ++it, ++idx)
945  {
946  settings.setArrayIndex(idx);
947  settings.setValue("StationKey", it.key());
948  settings.setValue("DefaultCableSign", it.value());
949  };
950  settings.endArray();
951  //
952  // RINEX stuff:
953  // RINEX file names:
954  settings.remove("Setup/RinexFileNameByStn");
955  settings.beginWriteArray("Setup/RinexFileNameByStn", setup.getRinexFileNameByStn().size());
956  idx = 0;
957  for (QMap<QString, QString>::const_iterator it=setup.getRinexFileNameByStn().begin();
958  it!=setup.getRinexFileNameByStn().end(); ++it, ++idx)
959  {
960  settings.setArrayIndex(idx);
961  settings.setValue("StationKey", it.key());
962  settings.setValue("RinexFileName", it.value());
963  };
964  settings.endArray();
965  // pressure offset:
966  settings.remove("Setup/RinexPressureOffsetByStn");
967  settings.beginWriteArray("Setup/RinexPressureOffsetByStn", setup.getRinexPressureOffsetByStn().size());
968  idx = 0;
969  for (QMap<QString, double>::const_iterator it=setup.getRinexPressureOffsetByStn().begin();
970  it!=setup.getRinexPressureOffsetByStn().end(); ++it, ++idx)
971  {
972  settings.setArrayIndex(idx);
973  settings.setValue("StationKey", it.key());
974  settings.setValue("RinexPressureOffset", it.value());
975  };
976  settings.endArray();
977 
978 };
979 /*=====================================================================================================*/
980 
981 
982 
983 
984 
985 /*=====================================================================================================*/
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))
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
@ CONFIG
Definition: SgLogger.h:93
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
@ 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
const QString & getSessionName() const
Definition: SgVgosDb.h:268
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:533
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 &)
Definition: VpSetup.h:300
SgIdentities & identities()
Definition: VpSetup.h:266
const QString & getPath2SessionFiles() const
Definition: VpSetup.h:226
void setUpBinaryIdentities(const QString &)
Definition: VpSetup.cpp:77
const QString & getPath2VgosDbFiles() const
Definition: VpSetup.h:218
void setUseLocalLocale(bool use)
Definition: VpSetup.h:136
QMap< QString, double > & rinexPressureOffsetByStn()
Definition: VpSetup.h:146
void setPath2Home(const QString &)
Definition: VpSetup.h:276
QMap< QString, int > & defaultCableSignByStn()
Definition: VpSetup.h:142
void setPath2SessionFiles(const QString &)
Definition: VpSetup.h:292
const QString & getPath2Home() const
Definition: VpSetup.h:210
const QString & getPath2AuxLogs() const
Definition: VpSetup.h:242
bool getUseLocalLocale() const
Definition: VpSetup.h:92
const QString & getPath2MasterFiles() const
Definition: VpSetup.h:234
void print2stdOut()
Definition: VpSetup.cpp:89
void setPath2AuxLogs(const QString &)
Definition: VpSetup.h:308
QString path2(const QString &) const
Definition: VpSetup.h:332
void setHave2SavePerSessionLog(bool)
Definition: VpSetup.h:316
QMap< QString, QString > & rinexFileNameByStn()
Definition: VpSetup.h:144
const QMap< QString, double > & getRinexPressureOffsetByStn() const
Definition: VpSetup.h:106
void setPath2VgosDbFiles(const QString &)
Definition: VpSetup.h:284
const QMap< QString, int > & getDefaultCableSignByStn() const
Definition: VpSetup.h:102
const QMap< QString, QString > & getRinexFileNameByStn() const
Definition: VpSetup.h:104
bool getHave2SavePerSessionLog() const
Definition: VpSetup.h:250
static int serialNumber()
QString altSetupAppName
QList< QString > kinds
QSettings * settings
QString altSetupName
QString altPath2InputFiles
bool have2clearMeteoData
QMap< QString, int > knownKinds
bool have2clearTsysData
bool shouldInvokeSystemWideWizard
QString orderOfMeteo
QString inputArg
QList< QString > stations
bool have2clearCableData
const QString origAppName("vgosDbProcLogs")
void loadSettings(QSettings &)
QCoreApplication * createApplication(int &argc, char *argv[], bool isGuiEnabled)
const QString origOrgName("NASA GSFC")
char progname[80]
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)
int msglev
VpSetup setup
void saveSettings(QSettings &, bool shouldInvokeSystemWideWizard)
SgVersion vgosDbProcLogsVersion