Index: trunk/BNC/RTCM3/RTCM3Decoder.cpp
===================================================================
--- trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 1087)
+++ trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 1095)
@@ -68,6 +68,27 @@
   QSettings settings;
   _checkMountPoint = settings.value("messTypes").toString();
-  _corrLate = settings.value("corrLate").toInt();
   _staID = staID;
+
+  // Latency
+  _numLat = 0;
+  _minLat = 1000.;
+  _maxLat = -1000.;
+  _sumLat = 0.;
+  _sumLatQ = 0.;
+  _followSec = false;
+  _meanDiff = 0.;
+  _diffSecGPS= 0.;
+  _numGaps = 0;
+  _oldSecGPS = 0.;
+  _newSecGPS = 0.;
+  _curLat = 0.;
+  _perfIntr = 86400;
+  if ( settings.value("perfIntr").toString().isEmpty() ) { _perfIntr = 0; }
+  if ( settings.value("perfIntr").toString().indexOf("1 min") != -1 ) { _perfIntr = 60; }
+  if ( settings.value("perfIntr").toString().indexOf("5 min") != -1 ) { _perfIntr = 300; }
+  if ( settings.value("perfIntr").toString().indexOf("15 min") != -1 ) { _perfIntr = 900; }
+  if ( settings.value("perfIntr").toString().indexOf("1 hour") != -1 ) { _perfIntr = 3600; }
+  if ( settings.value("perfIntr").toString().indexOf("6 hours") != -1 ) { _perfIntr = 21600; }
+  if ( settings.value("perfIntr").toString().indexOf("1 day") != -1 ) { _perfIntr = 86400; }
 
   // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
@@ -113,17 +134,17 @@
       decoded = true;
 
-      // Latency, Weber
+      // Latency
       // -------
-      if ( _corrLate == 2 ) {
+      if (_perfIntr>0) {
         if (0<_coDecoder->_epochList.size()) {
           for (int ii=0;ii<_coDecoder->_epochList.size();ii++) {
             int week;
             double sec;
-            double secGPS = _coDecoder->_epochList[ii];
+            _newSecGPS = _coDecoder->_epochList[ii];
             leapsecGPSWeeks(week, sec);
-            double dt = fabs(sec - secGPS);
+            double dt = fabs(sec - _newSecGPS);
             const double secPerWeek = 7.0 * 24.0 * 3600.0;
             if (dt > 0.5 * secPerWeek) {
-              if (sec > secGPS) {
+              if (sec > _newSecGPS) {
                 sec  -= secPerWeek;
               } else {
@@ -131,8 +152,52 @@
               }
             }
-            QString late;
-            late = QString("%1 ").arg(int((sec - secGPS)*100.)/100.);
-            if (late != "") {
-              emit(newMessage(QString(_staID + ": Latency " + late + "sec").toAscii() ) );
+            if (_newSecGPS != _oldSecGPS) {
+              if (int(_newSecGPS) % _perfIntr < int(_oldSecGPS) % _perfIntr) {
+                if (_numLat>0) {
+                  QString late;
+                  if (_meanDiff>0.) {
+                    late = QString(": Mean latency %1 sec, min %2, max %3, rms %4, %5 epochs, %6 gaps")
+                    .arg(int(_sumLat/_numLat*100)/100.)
+                    .arg(int(_minLat*100)/100.)
+                    .arg(int(_maxLat*100)/100.)
+                    .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
+                    .arg(_numLat)
+                    .arg(_numGaps);
+                    emit(newMessage(QString(_staID + late ).toAscii() ) );
+                  } else {
+                  late = QString(": Mean latency %1 sec, min %2, max %3, rms %4, %5 epochs")
+                    .arg(int(_sumLat/_numLat*100)/100.)
+                    .arg(int(_minLat*100)/100.)
+                    .arg(int(_maxLat*100)/100.)
+                    .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
+                    .arg(_numLat);
+                  emit(newMessage(QString(_staID + late ).toAscii() ) );
+                  }
+                }
+                _meanDiff = int(_diffSecGPS)/_numLat;
+                _diffSecGPS = 0.;
+                _numGaps = 0;
+                _sumLat = 0.;
+                _sumLatQ = 0.;
+                _numLat = 0;
+                _minLat = 1000.;
+                _maxLat = -1000.;
+              }
+              if (_followSec) {
+                _diffSecGPS += _newSecGPS - _oldSecGPS;
+                if (_meanDiff>0.) {
+                  if (_newSecGPS - _oldSecGPS > 1.5 * _meanDiff) {
+                    _numGaps += 1;
+                  }
+                }
+              }
+              _curLat = sec - _newSecGPS;
+              _sumLat += _curLat;
+              _sumLatQ += _curLat * _curLat;
+              if (_curLat < _minLat) {_minLat = _curLat;}
+              if (_curLat >= _maxLat) {_maxLat = _curLat;}
+              _numLat += 1;
+              _oldSecGPS = _newSecGPS;
+              _followSec = true;
             }
           }
Index: trunk/BNC/RTCM3/RTCM3Decoder.h
===================================================================
--- trunk/BNC/RTCM3/RTCM3Decoder.h	(revision 1087)
+++ trunk/BNC/RTCM3/RTCM3Decoder.h	(revision 1095)
@@ -50,8 +50,20 @@
   QString                _staID;
   QString                _checkMountPoint;
-  int                    _corrLate;
   struct RTCM3ParserData _Parser;
   RTCM3coDecoder*        _coDecoder; 
   t_mode                 _mode;
+  int _perfIntr;
+  int _numLat;
+  int _numGaps;
+  bool _followSec;
+  double _curLat;
+  double _sumLat;
+  double _sumLatQ;
+  double _minLat;
+  double _maxLat;
+  double _newSecGPS;
+  double _oldSecGPS;
+  double _diffSecGPS;
+  double _meanDiff;
 } ;
 
Index: trunk/BNC/bnchelp.html
===================================================================
--- trunk/BNC/bnchelp.html	(revision 1087)
+++ trunk/BNC/bnchelp.html	(revision 1095)
@@ -95,5 +95,4 @@
 &nbsp; &nbsp; &nbsp; 3.8.3. <a href=#corrport>Port</a><br>
 &nbsp; &nbsp; &nbsp; 3.8.4. <a href=#corrwait>Wait for Full Epoch</a><br>
-&nbsp; &nbsp; &nbsp; 3.8.5. <a href=#corrlate>Latency Log</a><br>
 3.9. <a href=#advnote>Monitor</a><br>
 &nbsp; &nbsp; &nbsp; 3.9.1. <a href=#obsrate>Observation Rate</a><br>
@@ -479,8 +478,4 @@
 When feeding a real-time GNSS engine waiting epoch by epoch for synchronized Ephemeris Corrections, BNC drops (only concering IP port output) whatever is received later than 'Wait for full epoch' seconds. A value of 2 to 5 seconds could be an appropriate choice for that, depending on the latency of the incoming Ephemeris Corrections stream and the delay acceptable by your application. A message such as "COCK1: Correction overaged by 5 sec" shows up in BNC's logfile if 'Wait for full epoch' is exceeded.
 </p>
-<p><a name="corrlate"><h4>3.8.5 Latency Log - optional</h4></p>
-<p>
-Message latencies are logged for streams carrying orbit and clock corrections to Broadcast Ephemeris if option 'Latency log' is ticked.
-</p>
 
 <p><a name="advnote"><h4>3.9. Monitor</h4></p>
@@ -564,10 +559,10 @@
     UTC time provided by BNC's host
   - GPS time of currently processed epoch
-  + Leap seconds between UTC and GPS time, hard-coded to 14
+  + Leap seconds between UTC and GPS time
   --------------
   = Latency
 </pre>
 <p>
- BNC can average the latencies of observations per stream over a certain period of GPS time, the 'Performance log' interval. Mean latencies are calculated from the individual latencies of at most one (first incoming) observation per second. Note that computing correct latencies requires the clock of the host computer to be properly synchronized.
+ BNC can average the latencies per stream over a certain period of GPS time, the 'Performance log' interval. Mean latencies are calculated from the individual latencies of at most one (first incoming) observation or correction to Broadcast Ephemeris per second. Note that computing correct latencies requires the clock of the host computer to be properly synchronized.
 </p>
 <p>
@@ -575,5 +570,5 @@
 </p>
 <p>
-Latencies of observations and statistical information can be recorded in the Log file/section at the end of each 'Performance log' interval. A typical output from a 1 hour 'Performance log' interval would be:
+Latencies of observations or corrections to Broadcast Ephemeris and statistical information can be recorded in the Log file/section at the end of each 'Performance log' interval. A typical output from a 1 hour 'Performance log' interval would be:
 </p>
 <pre>
Index: trunk/BNC/bncmain.cpp
===================================================================
--- trunk/BNC/bncmain.cpp	(revision 1087)
+++ trunk/BNC/bncmain.cpp	(revision 1095)
@@ -89,5 +89,4 @@
     settings.setValue("corrTime",   "5");
     settings.setValue("messTypes",  "");
-    settings.setValue("corrLate",   0);
   }
 
Index: trunk/BNC/bncwindow.cpp
===================================================================
--- trunk/BNC/bncwindow.cpp	(revision 1087)
+++ trunk/BNC/bncwindow.cpp	(revision 1095)
@@ -127,7 +127,4 @@
   _ephPathLineEdit    = new QLineEdit(settings.value("ephPath").toString());
   _corrPathLineEdit    = new QLineEdit(settings.value("corrPath").toString());
-  _corrLateCheckBox  = new QCheckBox();
-  _corrLateCheckBox->setCheckState(Qt::CheckState(
-                                    settings.value("corrLate").toInt()));
 
   _rnxV3CheckBox = new QCheckBox();
@@ -315,5 +312,4 @@
   _rnxScrpLineEdit->setWhatsThis(tr("<p>Whenever a RINEX Observation file is saved, you might want to compress, copy or upload it immediately via FTP. BNC allows you to execute a script/batch file to carry out these operations. To do that specify the full path of the script/batch file here. BNC will pass the full RINEX Observation file path to the script as a command line parameter (%1 on Windows systems, $1 onUnix/Linux systems).</p><p>The triggering event for calling the script or batch file is the end of a RINEX Observation file 'Interval'. If that is overridden by a stream outage, the triggering event is the stream reconnection.</p>"));
   _rnxSkelLineEdit->setWhatsThis(tr("<p>Whenever BNC starts generating RINEX Observation files (and then once every day at midnight), it first tries to retrieve information needed for RINEX headers from so-called public RINEX header skeleton files which are derived from sitelogs. However, sometimes public RINEX header skeleton files are not available, its contents is not up to date, or you need to put additional/optional records in the RINEX header.</p><p>For that BNC allows using personal skeleton files that contain the header records you would like to include. You can derive a personal RINEX header skeleton file from the information given in an up to date sitelog. A file in the RINEX 'Directory' with the RINEX 'Skeleton extension' is interpreted by BNC as a personal RINEX header skeleton file for the corresponding stream.</p>"));
-  _corrLateCheckBox->setWhatsThis(tr("<p>Log latency of Broadcast Ephemeris Corrections.</p>"));
   _rnxAppendCheckBox->setWhatsThis(tr("<p>When BNC is started, new files are created by default and any existing files with the same name will be overwritten. However, users might want to append already existing files following a restart of BNC, a system crash or when BNC crashed. Tick 'Append files' to continue with existing files and keep what has been recorded so far.</p>"));
   _rnxIntrComboBox->setWhatsThis(tr("<p>Select the length of the RINEX Observation file.</p>"));
@@ -328,5 +324,5 @@
   _logFileLineEdit->setWhatsThis(tr("Records of BNC's activities are shown in the Log section on the bottom of this window. They can be saved into a file when a valid path is specified in the 'Logfile (full path)' field."));
   _adviseScriptLineEdit->setWhatsThis(tr("<p>Specify the full path to a script or batch file to handle advisory notes generated in the event of corrupted streams or stream outages. The affected mountpoint and one of the comments 'Begin_Outage', 'End_Outage', 'Begin_Corrupted', or 'End_Corrupted' are passed on to the script as command line parameters.</p><p>The script can be configured to send an email to BNC's operator and/or to the affected stream provider. An empty option field (default) or invalid path means that you don't want to use this option.</p><p> Note that for using this function you need to specify the 'Observation rate'.</p>"));
-  _perfIntrComboBox->setWhatsThis(tr("<p>BNC can average all observation latencies per stream over a certain period of GPS time. The resulting mean latencies of observations are recorded in the Log file/section at the end of each 'Performance log' interval together with results of a statistical evaluation (approximate number of covered epochs, data gaps).</p><p>Select a 'Performance log' interval or select the empty option field if you do not want BNC to log latencies and statistical information.</p>"));
+  _perfIntrComboBox->setWhatsThis(tr("<p>BNC can average latencies per stream over a certain period of GPS time. The resulting mean latencies are recorded in the Log file/section at the end of each 'Performance log' interval together with results of a statistical evaluation (approximate number of covered epochs, data gaps).</p><p>Select a 'Performance log' interval or select the empty option field if you do not want BNC to log latencies and statistical information.</p>"));
   _mountPointsTable->setWhatsThis(tr("<p>Streams selected for retrieval are listed in the 'Mountpoints' section. Clicking on 'Add Mountpoints' button will open a window that allows the user to select data streams from an NTRIP broadcaster according to their mountpoints. To remove a stream from the 'Mountpoints' list, highlight it by clicking on it and hit the 'Delete Mountpoints' button. You can also remove multiple mountpoints by highlighting them using +Shift and +Ctrl.</p><p>BNC automatically allocates one of its internal decoders to a stream based on the stream's 'format' and 'format-details' as given in the sourcetable. However, there might be cases where you need to override the automatic selection due to incorrect sourcetable for example. BNC allows users to manually select the required decoder by editing the decoder string. Double click on the 'decoder' field, enter your preferred decoder and then hit Enter. The accepted decoder strings are 'RTCM_2.x', 'RTCM_3.x', and 'RTIGS'.</p><p>In case you need to log the raw data as is, BNC allows users to by-pass its decoders and and directly save the input in daily log files. To do this specify the decoder string as 'ZERO'.</p><p>BNC can also retrieve streams from virtual reference stations (VRS). To initiate these streams, an approximate rover position needs to be sent in NMEA GGA message to the NTRIP broadcaster. In return, a user-specific data stream is generated, typically by a Network-RTK software. This stream is customized to the exact latitude and longitude as shown in the 'lat' and 'long' columns under 'Mountpoints'. These VRS streams are indicated by a 'yes' in the 'nmea' column under 'Mountpoints' as well as in the sourcetable. The default 'lat' and 'long' values are taken from the sourcetable. However, in most cases you would probably want to change this according to your requirement. Double click on 'lat' and 'long' fields, enter the values you wish to send and then hit Enter. The format is in positive north latitude degrees (e.g. for northern hemisphere: 52.436, for southern hemisphere: -24.567) and eastern longitude degrees (e.g.: 358.872 or -1.128). Only mountpoints with a 'yes' in its 'nmea' column can be edited. The position should preferably be a point within the coverage of the network.</p>"));
   _log->setWhatsThis(tr("Records of BNC's activities are shown in the Log section. The message log covers the communication status between BNC and the NTRIP broadcaster as well as any problems that occur in the communication link, stream availability, stream delay, stream conversion etc."));
@@ -466,7 +462,6 @@
   cLayout->addWidget(new QLabel("Wait for full epoch"),           3, 0);
   cLayout->addWidget(_corrTimeSpinBox,                            3, 1);
-  cLayout->addWidget(new QLabel("Latency log"),                   4, 0);
-  cLayout->addWidget(_corrLateCheckBox,                           4, 1);
-  cLayout->addWidget(new QLabel("Saving Broadcast Ephemeris correction files and correction output through IP port."),5,0,1,2,Qt::AlignLeft);
+  cLayout->addWidget(new QLabel("Saving Broadcast Ephemeris correction files and correction output through IP port."),4,0,1,2,Qt::AlignLeft);
+  cLayout->addWidget(new QLabel("    "),5,0);
   cgroup->setLayout(cLayout);
 
@@ -624,5 +619,4 @@
   settings.setValue("rnxSkel",     _rnxSkelLineEdit->text());
   settings.setValue("rnxAppend",   _rnxAppendCheckBox->checkState());
-  settings.setValue("corrLate",    _corrLateCheckBox->checkState());
   settings.setValue("rnxV3",       _rnxV3CheckBox->checkState());
   settings.setValue("ephV3",       _ephV3CheckBox->checkState());
Index: trunk/BNC/bncwindow.h
===================================================================
--- trunk/BNC/bncwindow.h	(revision 1087)
+++ trunk/BNC/bncwindow.h	(revision 1095)
@@ -116,5 +116,4 @@
     QSpinBox*  _binSamplSpinBox;
     QCheckBox* _rnxAppendCheckBox;
-    QCheckBox* _corrLateCheckBox;
     QCheckBox* _makePauseCheckBox;
     QSpinBox*  _waitTimeSpinBox;
