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/QRegularExpression>
34 #include <QtCore/QSettings>
35 #include <QtCore/QString>
36 #include <QtCore/QStringList>
37 
38 
39 #if QT_VERSION >= 0x050000
40 # include <QtWidgets/QApplication>
41 #else
42 # include <QtGui/QApplication>
43 #endif
44 
45 
46 #include <SgIdentities.h>
47 #include <SgKombFormat.h>
48 #include <SgLogger.h>
49 #include <SgVgosDb.h>
50 #include <SgVlbiSession.h>
51 
52 
53 
54 #include "vgosDbProcLogs.h"
55 #include "VpStartupWizard.h"
56 
57 
58 
59 
60 void loadSettings(QSettings&);
61 void saveSettings(QSettings&, bool shouldInvokeSystemWideWizard);
62 
63 
64 
66 
67 const QString origOrgName("NASA GSFC");
68 const QString origDmnName("gsfc.nasa.gov");
69 const QString origAppName("vgosDbProcLogs");
70 
71 
72 // HOPS's whims:
73 #ifdef OLD_HOPS
74 char progname[80];
75 int msglev = 2;
76 #endif
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  QString orderOfMeteo;
91  QMap<QString, int> knownKinds;
95  bool isDryRun;
100 };
101 
102 
103 //
104 // a parser for ARGP:
105 static int parse_opt(int key, char *arg, struct argp_state *state)
106 {
107  QString str("");
108  struct vdbpOptions *options=(struct vdbpOptions*)state->input;
109  //
110  switch (key)
111  {
112  case 'a':
113  options->altSetupName = QString(arg);
114  if (!options->altSetupName.contains("/..")) // are there any other elements of path that we should avoid?
115  {
116  options->altSetupAppName = origAppName + "-" + options->altSetupName;
117  options->have2UseAltSetup = true;
118  }
119  else
120  {
122  ": parse_opt(): it is dangerous to use a string \"" + options->altSetupName +
123  "\" as an alternative config name");
125  ": parse_opt(): you can overwrite another file (un)intentionally");
126  delete options->settings;
127  exit(22);
128  };
129  break;
130  case 'd':
131  options->altPath2InputFiles = QString(arg);
132  break;
133  case 'k':
134  str = QString(arg);
135  if (options->knownKinds.contains(str))
136  options->kinds.append(str);
137  else
139  ": parse_opt(): got an unknown kind \"" + str + "\", ignoring");
140  break;
141  case 'l':
142  options->useStdLocale = true;
143  break;
144  case 'o':
145  options->orderOfMeteo = QString(arg).toUpper();
146  break;
147  case 'p':
148  loadSettings(*options->settings);
150  exit(0);
151  break;
152  case 'q':
153  options->isDryRun = true;
154  break;
155  case 's':
156  str = QString(arg);
157  options->stations.append(str);
159  ": parse_opt(): the station \"" + str + "\" is added to the process list");
160  break;
161  case 'z':
162  if (strcmp(arg, "c") == 0)
163  options->have2clearCableData = true;
164  else if (strcmp(arg, "m") == 0)
165  options->have2clearMeteoData = true;
166  else if (strcmp(arg, "t") == 0)
167  options->have2clearTsysData = true;
168  else
169  {
171  ": parse_opt(): unrecognized argument \"" + arg + "\" of \"-z\" option; "
172  "expected: \"c\", \"m\" or \"t\"");
173  };
174  break;
175 
176  //
177  case 'W':
178  options->shouldInvokeSystemWideWizard = true;
179  break;
180  case 'w':
181  options->have2ForceWizard = true;
182  break;
183  //
184  case 'V':
185  std::cout << qPrintable(vgosDbProcLogsVersion.name(SgVersion::NF_Petrov)) << "\n";
186  exit(0);
187  break;
188  //
189  case ARGP_KEY_ARG:
190  if (1 < state->arg_num)
191  {
192  argp_usage(state);
193  };
194  options->inputArg = QString(arg);
195  break;
196  case ARGP_KEY_END:
197  if (state->arg_num < 1 &&
198  !(options->have2ForceWizard || options->shouldInvokeSystemWideWizard))
199  argp_usage(state);
200  break;
201  default:
202  return ARGP_ERR_UNKNOWN;
203  break;
204  };
205  return 0;
206 };
207 //
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 //
223 QCoreApplication* createApplication(int &argc, char *argv[], bool isGuiEnabled)
224 {
225  if (isGuiEnabled)
226  return new QApplication(argc, argv);
227  else
228  return new QCoreApplication(argc, argv);
229 };
230 
231 
232 
233 /***===================================================================================================*/
239 int main(int argc, char** argv)
240 {
241  struct vdbpOptions options;
242  SgLogger *alHistory;
243  SgLogger *alDriver;
244 
245  QString sessionName("");
246  QString path2wrapperFile("");
247  QString wrapperFileName("");
248  QString userCommand("");
249 
250 
251 #ifdef SWCONFIG
252  const QString path2SystemWideConfig(SWCONFIG "/xdg");
253 #else
254  const QString path2SystemWideConfig("");
255 #endif
256  int rc;
257  bool isOk;
258  bool isFirstRun;
259  bool isGuiEnabled;
260  const char* envDisplay=NULL;
261 
262  rc = 0;
263  options.settings = NULL;
264  options.altSetupAppName = QString("");
265  options.altSetupName = QString("");
266  options.inputArg = QString("");
267  options.altPath2InputFiles = QString("");
268  options.orderOfMeteo = QString("");
269  options.stations.clear();
270  options.kinds.clear();
271  options.knownKinds.clear();
272  options.have2UseAltSetup = false;
273  options.have2ForceWizard = false;
274  options.shouldInvokeSystemWideWizard = false;
275  options.isDryRun = false;
276  options.useStdLocale = false;
277  options.have2clearCableData = false;
278  options.have2clearMeteoData = false;
279  options.have2clearTsysData = false;
280 
281  options.knownKinds.insert("log", 0);
282  options.knownKinds.insert("cdms", 1);
283  options.knownKinds.insert("pcmt", 2);
284  options.knownKinds.insert("met", 3);
285 
286  //
287  // init:
288  QCoreApplication::setOrganizationName(origOrgName);
289  QCoreApplication::setOrganizationDomain(origDmnName);
290  QCoreApplication::setApplicationName(origAppName);
291 
292  // set up path to the system wide settings:
293  QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, path2SystemWideConfig);
294  //
295  options.settings = new QSettings;
296  //
297  isGuiEnabled = (envDisplay=getenv("DISPLAY"))!=NULL && 0<strlen(envDisplay);
298  //
299  QScopedPointer<QCoreApplication>
300  app(createApplication(argc, argv, isGuiEnabled));
301  if (qobject_cast<QApplication *>(app.data()))
302  {
303  // do something with GUI
304  }
305  else
306  {
307  // do something for non-GUI
308  };
309  //
310  // especially for HOPS:
311 #ifdef OLD_HOPS
312  strcpy(progname, qPrintable("HOPS (on behalf of " + vgosDbProcLogsVersion.getSoftwareName() + ")"));
313 #endif
314  //
315  setup.setUpBinaryIdentities(QString(argv[0]));
316  for (int i=0; i<argc; i++)
317  userCommand += QString(argv[i]) + " ";
318  userCommand.chop(1);
319 
320 
321  //
322  // ARGP setup:
323  //
324  struct argp_option argp_options[] =
325  {
326  {0, 0, 0, 0, "General options:", 10},
327  {"input-dir", 'd', "STRING", 0,
328  "Use an alternative path STRING to search for input files"},
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, "Data processing control:", 13},
337  {"kind", 'k', "STRING", 0,
338  "Use only the specified by STRING kind of input. Known kinds are: log (FS log files), "
339  "cdms (files with CDMS values), "
340  "pcmt (files with PCMT values), "
341  "met (files with meteorological data). "
342  "There can be more than one \"-k\" option"},
343  {"meteo-order", 'o', "STRING", 0,
344  "An order of meteo parameters in /wx/ record of a log file. STRING is a string with at least 3 "
345  "characters: T (temperature), P (pressure) and H (relative humidity). The order of the chars in "
346  "STRING determines the order of data in a log file. The default is TPH. The values are case "
347  "insensitive. The argument is supposed to be used with \"-s\" option, otherwise change of the "
348  "order will affect all stations."},
349  {"station", 's', "STRING", 0,
350  "Use only station STRING (STRING can be either two-char station code or 8-chars station name). "
351  "There can be more than one \"-s\" option"},
352  {"zerofy", 'z', "CHAR", 0,
353  "Reset data type CHAR. CHAR can be \"c\" (cable calibration), "
354  "\"m\" (meteorological data) or \"t\" (tsys). There can be more than one \"-z\" option"},
355 
356  {0, 0, 0, 0, "Invocation of startup wizard:", 25},
357  {"sys-wide-wizard", 'W', 0, 0,
358  "Run startup wizard for the system-wide settings"},
359  {"wizard", 'w', 0, 0,
360  "Force call of the startup wizard"},
361 
362  {0, 0, 0, 0, "Operation modes:", -1},
363  {"print-setup", 'p', 0, 0,
364  "Print set up and exit"},
365  {"dry-mode", 'q', 0, 0,
366  "Process in a \"dry run\" mode: files will not be created, instead names of the files "
367  "will be printed"},
368  {"version", 'V', 0, 0,
369  "Print program version"},
370  //
371  {0}
372  };
373  QString salute("vgosDbProcLogs is a program that extracts data from filed "
374  "system log files and stores obtained info in vgosDb database. The mandatory argument DATABASE is "
375  "a name of a database (with or without version part) or a name of wrapper file (absolute or "
376  "relative to the default path of the vgosDb files).\v");
377 
378  salute += "The current version is:\n\t" + vgosDbProcLogsVersion.name() + " released on " +
380  "\n\t" + libraryVersion.name() + " released on " +
382  salute +=
383  QString("\n\nThe utility vgosDbProcLogs is a part of nuSolve package. See the datails in "
384  "\"vgosDbProcLogs User Guide\", a part of nuSolve distribution. You can get the latest version of "
385  "nuSolve at\n\t\thttps://sourceforge.net/projects/nusolve");
386 
387  struct argp argp={argp_options, parse_opt, "DATABASE", salute.toLatin1()};
388 
389  argp_parse (&argp, argc, argv, 0, 0, &options);
390  //
391  //
392  isFirstRun = options.settings->allKeys().size()>0 ? false : true;
393  //
394  //
395  if (options.have2UseAltSetup)
396  {
398  ": using alternative config name \"" + options.altSetupName + "\"");
399  QSettings *altSettings=new QSettings(origOrgName, options.altSetupAppName);
400  loadSettings(*altSettings);
401  delete options.settings;
402  options.settings = altSettings;
403  }
404  else
405  loadSettings(*options.settings);
406  //
407  if (options.orderOfMeteo.size()) // check user input:
408  {
409  isOk = true;
410  if (options.orderOfMeteo.size() < 3)
411  {
413  ": the size of meteo order string (" + QString("").setNum(options.orderOfMeteo.size()) +
414  ") is less than 3; ignoring");
415  isOk = false;
416  }
417  else if (options.orderOfMeteo.count('T') < 1)
418  {
420  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain temperature tag "
421  "(T or t); ignoring");
422  isOk = false;
423  }
424  else if (options.orderOfMeteo.count('P') < 1)
425  {
427  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain pressure tag "
428  "(P or p); ignoring");
429  isOk = false;
430  }
431  else if (options.orderOfMeteo.count('H') < 1)
432  {
434  ": the meteo order string \"" + options.orderOfMeteo + "\" does not contain relative humidity "
435  "tag (H or h); ignoring");
436  isOk = false;
437  }
438  else if (1 < options.orderOfMeteo.count('T'))
439  {
441  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one temperature "
442  "tag (T or t); ignoring");
443  isOk = false;
444  }
445  else if (1 < options.orderOfMeteo.count('P'))
446  {
448  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one pressure tag "
449  "(P or p); ignoring");
450  isOk = false;
451  }
452  else if (1 < options.orderOfMeteo.count('H'))
453  {
455  ": the meteo order string \"" + options.orderOfMeteo + "\" contains more than one relative "
456  "humidity tag (H or h); ignoring");
457  isOk = false;
458  };
459  //
460  if (!isOk) // reset the string:
461  {
463  ": the meteo order string \"" + options.orderOfMeteo + "\" is invalid");
464  options.orderOfMeteo = QString("");
465  };
466  };
467 
468  //
469  //
470  //
471  if (isGuiEnabled)
472  {
473  if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard ||
474  options.settings->value("Version/StartUpWizard", 0).toInt() < VpStartupWizard::serialNumber())
475  {
476  if (options.shouldInvokeSystemWideWizard)
477  {
478  if (!options.have2UseAltSetup)
479  {
480  QSettings *swSettings =
481  new QSettings(QSettings::SystemScope, origOrgName, origAppName);
482  if (!swSettings->isWritable())
483  {
484  rc = 1;
486  ": cannot write system wide config");
487  delete swSettings;
488  return rc;
489  };
490  delete options.settings;
491  options.settings = swSettings;
492  }
493  else
495  ": using an alternative config name, system wide config edit request ignored");
496  };
497  //
498  VpStartupWizard startup(isFirstRun, options.have2ForceWizard,
499  options.shouldInvokeSystemWideWizard, options.settings);
500  if (startup.exec() == QDialog::Rejected)
501  {
502  delete options.settings;
503  logger->clearSpool();
504  return rc;
505  };
506  //
507  // save if user pressed "Finish":
508  options.settings->setValue("Version/StartUpWizard", startup.serialNumber());
510  //
511  // it is ok, exitting:
512  if (!options.inputArg.size())
513  {
514  delete options.settings;
515  logger->clearSpool();
516  return rc;
517  };
518  };
519  }
520  else if (options.have2ForceWizard || options.shouldInvokeSystemWideWizard)
521  {
522  rc = 1;
524  ": cannot run graphical application.");
525  delete options.settings;
526  logger->clearSpool();
527  return rc;
528  };
529 
530  //
531  // determine a name of a wrapper file:
532  //
533  int version(0);
534  QRegularExpression reWrapperFileName(".*\\.(wrp|wrap)$",
535  QRegularExpression::CaseInsensitiveOption);
536  QRegularExpression reOldDbName("^(\\d{2}[A-Z]{3}\\d{2}[A-Z0-9]{1,2}).*");
537  QRegularExpression reNewDbName("^(\\d{8})-([\\S]{2,12}).*");
538 
539  //
540  // ok, this is a wrapper file name:
541  if (reWrapperFileName.match(options.inputArg).hasMatch())
542  {
544  setup.path2(setup.getPath2VgosDbFiles()), path2wrapperFile, wrapperFileName,
545  sessionName, version);
546  if (isOk)
548  ": got a session " + sessionName + " of version " +
549  QString("").setNum(version) + " from \"" + path2wrapperFile + "\":\"" +
550  wrapperFileName + "\"");
551  else
552  {
553  rc = 1;
555  ": cannot figure out a session from the input \"" + options.inputArg + "\"");
556  };
557  }
558  else if ( reOldDbName.match(options.inputArg).hasMatch() ||
559  reNewDbName.match(options.inputArg).hasMatch() )
560  {
563  path2wrapperFile, wrapperFileName, sessionName, version);
564  if (isOk)
566  ": got a wrapper file \"" + wrapperFileName +
567  "\" from \"" + path2wrapperFile + "\" for the session " + sessionName +
568  " of version " + QString("").setNum(version));
569  else
570  {
571  rc = 1;
573  ": cannot figure out a session from the input \"" + options.inputArg + "\"");
574  };
575  }
576  else
577  {
579  ": cannot guess input data from \"" + options.inputArg + "\"");
580  rc = 1;
581  };
582  //
583  //
584  //
585  alDriver = new SgLogger(800, setup.getHave2SavePerSessionLog(), "drv-unnamed.log");
587  alDriver->setIsNeedTimeMark(true);
588  alDriver->setIsMute(true);
589  alDriver->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
590  alDriver->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
591  alDriver->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
592  alDriver->setLogFacility(SgLogger::DBG, 0);
594  logger->attachSupplementLog("Driver", alDriver);
595  //
596  alHistory = new SgLogger(0, false, "");
597  alHistory->setIsNeedTimeMark(false);
598  alHistory->setIsMute(true);
599  alHistory->setLogFacility(SgLogger::ERR, 0xFFFFFFFF);
600  alHistory->setLogFacility(SgLogger::WRN, 0xFFFFFFFF);
601  alHistory->setLogFacility(SgLogger::INF, 0xFFFFFFFF);
602  alHistory->setLogFacility(SgLogger::DBG, 0);
603  //
604  //
605  //
606  isOk = false;
607  SgVgosDb *vgosDb;
608  SgVlbiSession session;
609  //
611  ": starting");
613  //
614  //
615  //------------------------------------------------------------------------------------------
616  //
617  QString sLang(""), sLcAll("");
618  if (!setup.getUseLocalLocale() || options.useStdLocale)
619  {
620  if (getenv("LANG"))
621  sLang = QString(getenv("LANG"));
622  setenv("LANG", "C", 1);
623  if (getenv("LC_ALL"))
624  sLcAll = QString(getenv("LC_ALL"));
625  setenv("LC_ALL", "C", 1);
627  ": the env.variable LANG was set to \"C\"");
629  ": the env.variable LC_ALL was set to \"C\"");
630  };
631  //
632  SgMJD startEpoch=SgMJD::currentMJD();
633 
634  vgosDb = new SgVgosDb(&setup.identities(), &vgosDbProcLogsVersion);
636  ": the vgosDb object has been created");
637 
638  isOk = vgosDb->init(path2wrapperFile, wrapperFileName);
640  ": initSessionFromOdb(): parsing of wrapper file " + path2wrapperFile + "/" + wrapperFileName +
641  (isOk?" complete":" failed"));
642 
643  if (vgosDb->getSessionName().size())
644  alDriver->setFileName(vgosDb->getSessionName() + ".log");
645  else
646  alDriver->setFileName(sessionName + ".log");
647  alDriver->rmLogFile();
648 
649  if (isOk && session.getDataFromVgosDb(vgosDb, false, isGuiEnabled))
650  {
651  logger->attachSupplementLog("History", alHistory);
652 
654  ": Library ID: " + libraryVersion.name() + " released on " +
657  ": Driver ID: " + vgosDbProcLogsVersion.name() + " released on " +
659 
661  ": Host ID: " + setup.identities().getMachineNodeName() +
662  " (Hw: " + setup.identities().getMachineMachineName() +
663  "; Sw: " + setup.identities().getMachineRelease() +
664  " version of " + setup.identities().getMachineSysName() + ")");
665 
667  ": User ID: " + setup.identities().getUserName() +
670  ": User command: \"" + userCommand + "\"");
672  ": Input data : " + path2wrapperFile + "/" + wrapperFileName);
674  ": the session " + session.getSessionCode() + " (" + session.getName() +
675  ") has been imported from vgosDb data set");
676 
677  //
678  // clear data if necessary:
679  if (options.have2clearCableData || options.have2clearMeteoData || options.have2clearTsysData)
680  {
681  QString sWhat("");
682  QString sStns("all stations");
683 
684  if (options.have2clearCableData)
685  sWhat += "cable cal";
686  if (options.have2clearMeteoData)
687  sWhat += ", meteorological";
688  if (options.have2clearTsysData)
689  sWhat += ", tsys";
690  sWhat += " data";
691 
692  if (options.stations.size())
693  {
694  sStns = "selected station(s) ";
695  for (int i=0; i<options.stations.size(); i++)
696  sStns += options.stations.at(i) + ", ";
697  sStns.chop(2);
698  };
699  //
700  if (session.resetDataFromLogFiles(options.have2clearCableData, options.have2clearMeteoData,
701  options.have2clearTsysData, options.stations))
702  {
703  //
705  ": the " + sWhat + " were reset for " + sStns + " of the session " + session.getSessionCode() +
706  " (" + session.getName() + ")");
707  session.contemporaryHistory().addHistoryRecord("The " + sWhat + " were reset for " + sStns,
708  SgMJD::currentMJD().toUtc());
709  }
710  else
712  ": clearing the " + sWhat + " for " + sStns + " of the session " + session.getSessionCode() +
713  " (" + session.getName() + ") failed");
714  };
715  //
716  // parse log files and absorb the data:
718  options.stations, options.kinds, &setup.getDefaultCableSignByStn(),
720  false, false, options.altPath2InputFiles, options.orderOfMeteo);
721  //
723  ": import of data from station log files has " + (isOk?"been complete":"failed"));
724  // save the session:
725  if (isOk)
726  {
727  if (options.isDryRun)
729  if (!(isOk=session.putDataIntoVgosDb(vgosDb)))
730  rc = 1;
732  ": export of data into vgosDb set has " + (isOk?"been complete":"failed"));
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  else
742  {
743  rc = 1;
745  ": no new data were acquired");
746  };
747  //
748  delete vgosDb;
750  ": vgosDb object has been destroyed.");
751  }
752  else
753  {
754  rc = 1;
756  ": import data of " + path2wrapperFile + "/" + wrapperFileName + " failed");
757  };
758 
759  //
760  if (!setup.getUseLocalLocale() || options.useStdLocale)
761  {
762  setenv("LANG", qPrintable(sLang), 1);
763  setenv("LC_ALL", qPrintable(sLcAll), 1);
765  ": the env.variable LANG was set to \"" + sLang + "\"");
767  ": the env.variable LC_ALL was set to \"" + sLcAll + "\"");
768  };
769 
770  alDriver->clearSpool();
771  logger->detachSupplementLog("Driver");
772  logger->detachSupplementLog("History");
773  delete alHistory;
774  delete alDriver;
775  delete options.settings;
776  logger->clearSpool();
777  return rc;
778 };
779 
780 
781 //
782 void loadSettings(QSettings& settings)
783 {
784  int logLevel;
785  //
786  // setup.identities:
788  settings.value("Identities/UserName",
789  setup.identities().getUserName()).toString());
791  settings.value("Identities/UserEmailAddress",
792  setup.identities().getUserEmailAddress()).toString());
794  settings.value("Identities/UserDefaultInitials",
795  setup.identities().getUserDefaultInitials()).toString());
797  settings.value("Identities/AcFullName",
798  setup.identities().getAcFullName()).toString());
800  settings.value("Identities/AcAbbreviatedName",
801  setup.identities().getAcAbbrevName()).toString());
803  settings.value("Identities/AcShortAbbreviatedName",
804  setup.identities().getAcAbbName()).toString());
805 
806  // setup:
807  // Pathes:
809  settings.value("Setup/Path2Home",
810  setup.getPath2Home()).toString());
812  settings.value("Setup/Path2SessionFiles",
813  setup.getPath2SessionFiles()).toString());
815  settings.value("Setup/Path2VgosDbFiles",
816  setup.getPath2VgosDbFiles()).toString());
818  settings.value("Setup/Path2MasterFiles",
819  setup.getPath2MasterFiles()).toString());
821  settings.value("Setup/Path2AuxLogs",
822  setup.getPath2AuxLogs()).toString());
824  settings.value("Setup/Have2SavePerSessionLog",
825  setup.getHave2SavePerSessionLog()).toBool());
827  settings.value("Setup/UseLocalLocale",
828  setup.getUseLocalLocale()).toBool());
829  //
830  // adjust the logger:
832  settings.value("Logger/FileName",
833  "vgosDbProcLogs.log").toString());
836  settings.value("Logger/Capacity", 400).toInt());
838  settings.value("Logger/IsStoreInFile", logger->getIsStoreInFile()).toBool());
840  settings.value("Logger/IsNeedTimeMark", logger->getIsNeedTimeMark()).toBool());
841  logLevel = settings.value("Logger/LogLevel", 2).toInt();
842  logger->setLogFacility(SgLogger::ERR, logLevel>=0?0xFFFFFFFF:0);
843  logger->setLogFacility(SgLogger::WRN, logLevel>=1?0xFFFFFFFF:0);
844  logger->setLogFacility(SgLogger::INF, logLevel>=2?0xFFFFFFFF:0);
845  logger->setLogFacility(SgLogger::DBG, logLevel==3?0xFFFFFFFF:0);
846  //
847  //
848  int size, defaultCableSign;
849  QString stationKey(""), rinexFileName("");
850  double dP;
851  if ( (size = settings.beginReadArray("Setup/DefaultCableSignByStn")) )
852  {
853  // remove default set up:
854  setup.defaultCableSignByStn().clear();
855  // load saved data:
856  for (int i=0; i<size; ++i)
857  {
858  settings.setArrayIndex(i);
859  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
860  defaultCableSign = settings.value("DefaultCableSign", 1).toInt();
861  setup.defaultCableSignByStn().insert(stationKey, defaultCableSign);
862  };
863  }
864  else
866  ": loadSettings(): no DefaultCableSignByStn found, using default set up");
867  settings.endArray();
868  //
869  // RINEX stuff:
870  // file names:
871  if ( (size = settings.beginReadArray("Setup/RinexFileNameByStn")) )
872  {
873  // remove default set up:
874  setup.rinexFileNameByStn().clear();
875  // load saved data:
876  for (int i=0; i<size; ++i)
877  {
878  settings.setArrayIndex(i);
879  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
880  rinexFileName = settings.value("RinexFileName").toString();
881  setup.rinexFileNameByStn().insert(stationKey, rinexFileName);
882  };
883  }
884  else
886  ": loadSettings(): no RinexFileNameByStn found, using default set up");
887  settings.endArray();
888  // pressure offset:
889  if ( (size = settings.beginReadArray("Setup/RinexPressureOffsetByStn")) )
890  {
891  // remove default set up:
893  // load saved data:
894  for (int i=0; i<size; ++i)
895  {
896  settings.setArrayIndex(i);
897  stationKey = settings.value("StationKey").toString().leftJustified(8, ' ');
898  dP = settings.value("RinexPressureOffset", 0.0).toDouble();
899  setup.rinexPressureOffsetByStn().insert(stationKey, dP);
900  };
901  }
902  else
904  ": loadSettings(): no RinexPressureOffsetByStn found, using default set up");
905  settings.endArray();
906 };
907 
908 
909 
910 //
911 void saveSettings(QSettings& settings, bool shouldInvokeSystemWideWizard)
912 {
913  // setup.identities:
914  if (!shouldInvokeSystemWideWizard)
915  {
916  settings.setValue("Identities/UserName",
918  settings.setValue("Identities/UserEmailAddress",
920  settings.setValue("Identities/UserDefaultInitials",
922  };
923  settings.setValue("Identities/AcFullName",
925  settings.setValue("Identities/AcAbbreviatedName",
927  settings.setValue("Identities/AcShortAbbreviatedName",
929  // setup:
930  // Pathes:
931  if (!shouldInvokeSystemWideWizard)
932  {
933  settings.setValue("Setup/Path2Home",
934  setup.getPath2Home());
935  };
936  settings.setValue("Setup/Path2SessionFiles",
938  settings.setValue("Setup/Path2VgosDbFiles",
940  settings.setValue("Setup/Path2MasterFiles",
942  settings.setValue("Setup/Path2AuxLogs",
944  settings.setValue("Setup/Have2SavePerSessionLog",
946  settings.setValue("Setup/UseLocalLocale",
948  //
949  // store logger's config:
950  settings.setValue("Logger/FileName",
951  logger->getFileName());
952  // logger->getDirName();
953  settings.setValue("Logger/Capacity",
954  logger->getCapacity());
955  settings.setValue("Logger/IsStoreInFile",
957  settings.setValue("Logger/IsNeedTimeMark",
959  //
960  //
961  settings.remove("Setup/DefaultCableSignByStn");
962  settings.beginWriteArray("Setup/DefaultCableSignByStn", setup.getDefaultCableSignByStn().size());
963  int idx(0);
964  for (QMap<QString, int>::const_iterator it=setup.getDefaultCableSignByStn().begin();
965  it!=setup.getDefaultCableSignByStn().end(); ++it, ++idx)
966  {
967  settings.setArrayIndex(idx);
968  settings.setValue("StationKey", it.key());
969  settings.setValue("DefaultCableSign", it.value());
970  };
971  settings.endArray();
972  //
973  // RINEX stuff:
974  // RINEX file names:
975  settings.remove("Setup/RinexFileNameByStn");
976  settings.beginWriteArray("Setup/RinexFileNameByStn", setup.getRinexFileNameByStn().size());
977  idx = 0;
978  for (QMap<QString, QString>::const_iterator it=setup.getRinexFileNameByStn().begin();
979  it!=setup.getRinexFileNameByStn().end(); ++it, ++idx)
980  {
981  settings.setArrayIndex(idx);
982  settings.setValue("StationKey", it.key());
983  settings.setValue("RinexFileName", it.value());
984  };
985  settings.endArray();
986  // pressure offset:
987  settings.remove("Setup/RinexPressureOffsetByStn");
988  settings.beginWriteArray("Setup/RinexPressureOffsetByStn", setup.getRinexPressureOffsetByStn().size());
989  idx = 0;
990  for (QMap<QString, double>::const_iterator it=setup.getRinexPressureOffsetByStn().begin();
991  it!=setup.getRinexPressureOffsetByStn().end(); ++it, ++idx)
992  {
993  settings.setArrayIndex(idx);
994  settings.setValue("StationKey", it.key());
995  settings.setValue("RinexPressureOffset", it.value());
996  };
997  settings.endArray();
998 
999 };
1000 /*=====================================================================================================*/
1001 
1002 
1003 
1004 
1005 
1006 /*=====================================================================================================*/
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))
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:1008
static SgMJD currentMJD()
Definition: SgMJD.cpp:119
@ 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:346
const QString & getSessionName() const
Definition: SgVgosDb.h:268
bool init(const QString path, const QString fileName)
Definition: SgVgosDb.cpp:538
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")
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)
VpSetup setup
void saveSettings(QSettings &, bool shouldInvokeSystemWideWizard)
SgVersion vgosDbProcLogsVersion