Index: trunk/BNC/src/bncclockrinex.cpp
===================================================================
--- trunk/BNC/src/bncclockrinex.cpp	(revision 11227)
+++ trunk/BNC/src/bncclockrinex.cpp	(revision 11228)
@@ -103,5 +103,4 @@
 
   _out << "     3.00           C                                       "  << "RINEX VERSION / TYPE" << endl;
- ;
   _out << QString("BNC v%1").arg(BNCVERSION).leftJustified(40, ' ', true).toLatin1().data()
        << datTim.toString("yyyyMMdd hhmmss").leftJustified(20, ' ', true).toLatin1().data()
@@ -114,20 +113,28 @@
        << "ANALYSIS CENTER" << endl;
 
-  _out << "   177                                                      "
+  // Satellites that may be contained in the file (the header is written
+  // before the first epoch); number and list are derived from the same ranges
+  // -------------------------------------------------------------------------
+  QStringList prnList;
+  const struct { char sys; int first; int last; } ranges[] = {
+    {'G', 1, 32}, {'R', 1, 26}, {'E', 1, 36}, {'C', 1, 63}, {'J', 1, 4}, {'I', 1, 7}
+  };
+  for (unsigned ir = 0; ir < sizeof(ranges) / sizeof(ranges[0]); ir++) {
+    for (int nn = ranges[ir].first; nn <= ranges[ir].last; nn++) {
+      prnList << QString("%1%2").arg(ranges[ir].sys).arg(nn, 2, 10, QChar('0'));
+    }
+  }
+  const int sbas[] = {20, 24, 27, 28, 29, 33, 35, 37, 38};
+  for (unsigned ii = 0; ii < sizeof(sbas) / sizeof(sbas[0]); ii++) {
+    prnList << QString("S%1").arg(sbas[ii], 2, 10, QChar('0'));
+  }
+
+  _out << QString("%1").arg(prnList.size(), 6).leftJustified(60, ' ').toLatin1().data()
        << "# OF SOLN SATS" << endl;
 
-  _out << "G01 G02 G03 G04 G05 G06 G07 G08 G09 G10 G11 G12 G13 G14 G15 PRN LIST" << endl;
-  _out << "G16 G17 G18 G19 G20 G21 G22 G23 G25 G26 G27 G28 G29 G30 G31 PRN LIST" << endl;
-  _out << "G32 R01 R02 R03 R05 R06 R07 R08 R09 R10 R11 R12 R13 R14 R15 PRN LIST" << endl;
-  _out << "R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 E01 E02 E03 E04 PRN LIST" << endl;
-  _out << "R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 E01 E02 E03 E04 PRN LIST" << endl;
-  _out << "E05 E06 E07 E08 E09 E10 E11 E12 E13 E14 E15 E16 E17 E18 E19 PRN LIST" << endl;
-  _out << "E20 E21 E22 E23 E24 E25 E26 E27 E28 E29 E30 E31 E32 E33 E34 PRN LIST" << endl;
-  _out << "E35 E36 C01 C02 C03 C04 C05 C06 C07 C08 C09 C10 C11 C12 C13 PRN LIST" << endl;
-  _out << "C14 C15 C16 C17 C18 C19 C20 C21 C22 C23 C24 C25 C26 C27 C28 PRN LIST" << endl;
-  _out << "C29 C30 C31 C32 C33 C34 C35 C36 C37 C38 C39 C40 C41 C42 C43 PRN LIST" << endl;
-  _out << "C44 C45 C46 C47 C48 C49 C50 C51 C52 C53 C54 C55 C56 C57 C58 PRN LIST" << endl;
-  _out << "C59 C60 C61 C62 C63 J01 J02 J03 J04 I01 I02 I03 I04 I05 I06 PRN LIST" << endl;
-  _out << "I07 S20 S24 S27 S28 S29 S33 S35 S37 S38                     PRN LIST" << endl;
+  for (int ii = 0; ii < prnList.size(); ii += 15) {
+    _out << QStringList(prnList.mid(ii, 15)).join(" ").leftJustified(60, ' ').toLatin1().data()
+         << "PRN LIST" << endl;
+  }
 
   _out << "     0    IGS20                                             "
Index: trunk/BNC/src/bnchelp.html
===================================================================
--- trunk/BNC/src/bnchelp.html	(revision 11227)
+++ trunk/BNC/src/bnchelp.html	(revision 11228)
@@ -143,6 +143,7 @@
     &nbsp; &nbsp; &nbsp; 2.7 <a href="#sp3comp"><b>SP3 Comparison</b></a><br>
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.1 <a href="#sp3input">Input SP3 Files</a><br>
-    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.2 <a href="#sp3exclude">Exclude Satellites</a><br>
-    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.3 <a href="#sp3log">Logfile</a><br>
+    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.2 <a href="#sp3clk">Input Clock RINEX Files</a><br>
+    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.3 <a href="#sp3exclude">Exclude Satellites</a><br>
+    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.7.4 <a href="#sp3log">Logfile</a><br>
     &nbsp; &nbsp; &nbsp; 2.8 <a href="#correct"><b>Broadcast Corrections</b></a><br>
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.8.1 <a href="#corrdir">Directory, ASCII</a><br>
@@ -457,5 +458,5 @@
       <td>Graphical results from an example comparison of two SP3 files with satellite orbit and clock data using BNC
       </td>
-      <td>2.7.3</td>
+      <td>2.7.4</td>
     </tr>
     <tr>
@@ -4532,5 +4533,5 @@
     If so, then BNC only compares records for identical epochs. BNC accepts that a specific GNSS system
     or a specific satellite is only available from one of the SP3 files.
-    Note that BNC does not interpolate orbits when comparing SP3 files.
+    Orbits are not interpolated, unless clock RINEX files are given (see 'Input Clock RINEX Files').
   </p>
   <p>
@@ -4565,5 +4566,32 @@
 
   <p>
-  <h4 id="sp3exclude">2.7.2 Exclude Satellites - optional</h4>
+  <h4 id="sp3clk">2.7.2 Input Clock RINEX Files - optional</h4>
+  </p>
+  <p>
+    Rapid and final products often provide the satellite clocks with a higher sampling in clock RINEX files
+    (e.g. 30 seconds) than in their SP3 files (e.g. 5 minutes). Comparing the SP3 files only at their common epochs
+    then misses short clock events, e.g. jumps lasting less than the SP3 sampling interval. You may therefore
+    specify the full paths of clock RINEX files, separated by comma and in the order of the SP3 files. A single file
+    refers to the first SP3 file; enter '-' for an SP3 file without clock RINEX file. Example:
+  </p>
+  <p>
+    <code>GBM0MGXRAP_20263290000_01D_30S_CLK.CLK</code> (clock RINEX file of SP3 file 1)<br>
+    <code>-,BKG0MGXRTS_20263290000_01D_30S_CLK.CLK</code> (clock RINEX file of SP3 file 2 only)
+  </p>
+  <p>
+    The satellite clocks of a clock RINEX file ('AS' records) replace those of the corresponding SP3 file. The clocks
+    and the signal-in-space differences are then compared at all epochs common to the two clock sources. Where such
+    an epoch is not an SP3 epoch, the orbit is interpolated with a Lagrange polynomial through ten consecutive SP3
+    epochs (no extrapolation, no data gaps; interpolation error about 1 mm for 5-minute GNSS orbits). The orbit
+    statistics ('radialRMS' to 'nOrb') refer to the common SP3 epochs only, while 'nClk' counts the clock epochs.
+    A 30-second SP3 file written by BNC already contains the clocks of its clock RINEX file, so for the comparison of
+    BNC products with a rapid product a clock RINEX file of the rapid product is sufficient.
+  </p>
+  <p>
+    Default is an empty option field, meaning that the clocks of the SP3 files are compared.
+  </p>
+
+  <p>
+  <h4 id="sp3exclude">2.7.3 Exclude Satellites - optional</h4>
   </p>
   <p>
@@ -4584,5 +4612,5 @@
 
   <p>
-  <h4 id="sp3log">2.7.3 Logfile - mandatory if 'Input SP3 Files' is set</h4>
+  <h4 id="sp3log">2.7.4 Logfile - mandatory if 'Input SP3 Files' is set</h4>
   </p>
   <p>
@@ -11424,4 +11452,5 @@
 SP3 Comparison Panel keys:
    sp3CompFile        {SP3 input files, full path [character string, comma separated list in quotation marks]}
+   sp3CompClkFile     {Optional clock RINEX files for SP3 file 1 and 2, full path [character string, comma separated list in quotation marks, '-' for none]}
    sp3CompExclude     {Satellite exclusion list [character string, comma separated list in quotation marks, example: G04,G31,R]}
    sp3CompOutLogFile  {Output logfile, full path [character string]}
Index: trunk/BNC/src/bncmain.cpp
===================================================================
--- trunk/BNC/src/bncmain.cpp	(revision 11227)
+++ trunk/BNC/src/bncmain.cpp	(revision 11228)
@@ -215,4 +215,5 @@
         "SP3 Comparison Panel keys:\n"
         "   sp3CompFile        {SP3 input files, full path [character string, comma separated list in quotation marks]}\n"
+        "   sp3CompClkFile     {Optional clock RINEX files for SP3 file 1 and 2, full path [character string, comma separated list in quotation marks, '-' for none]}\n"
         "   sp3CompExclude     {Satellite exclusion list [character string, comma separated list in quotation marks, example: G04,G31,R]}\n"
         "   sp3CompOutLogFile  {Output logfile, full path [character string]}\n"
Index: trunk/BNC/src/bncsettings.cpp
===================================================================
--- trunk/BNC/src/bncsettings.cpp	(revision 11227)
+++ trunk/BNC/src/bncsettings.cpp	(revision 11228)
@@ -138,4 +138,5 @@
         // SP3
         setValue_p("sp3CompFile", "");
+        setValue_p("sp3CompClkFile", "");
         setValue_p("sp3CompExclude", "");
         setValue_p("sp3CompOutLogFile", "");
Index: trunk/BNC/src/bncwindow.cpp
===================================================================
--- trunk/BNC/src/bncwindow.cpp	(revision 11227)
+++ trunk/BNC/src/bncwindow.cpp	(revision 11228)
@@ -1401,4 +1401,8 @@
   _sp3CompFileChooser->setMaximumWidth(40 * ww);
 
+  _sp3CompClkLineEdit = new QLineEdit(settings.value("sp3CompClkFile").toString());
+  _sp3CompClkLineEdit->setMinimumWidth(15 * ww);
+  _sp3CompClkLineEdit->setMaximumWidth(40 * ww);
+
   _sp3CompExclude = new QLineEdit(settings.value("sp3CompExclude").toString());
   _sp3CompExclude->setMinimumWidth(18 * ww);
@@ -1417,4 +1421,7 @@
   sp3CompLayout->addWidget(new QLabel("Input SP3 files (full path)"), ir, 0, Qt::AlignLeft);
   sp3CompLayout->addWidget(_sp3CompFileChooser, ir, 1, 1, 20);
+  ++ir;
+  sp3CompLayout->addWidget(new QLabel("Input clock RINEX files (optional)"), ir, 0, Qt::AlignLeft);
+  sp3CompLayout->addWidget(_sp3CompClkLineEdit, ir, 1, 1, 20);
   ++ir;
   sp3CompLayout->addWidget(new QLabel("Exclude satellites"), ir, 0, Qt::AlignLeft);
@@ -1635,4 +1642,5 @@
   // -------------------------
   _sp3CompFileChooser->setWhatsThis(tr("<p>BNC can compare two SP3 files containing GNSS satellite orbit and clock information.</p></p>Specify the full path to two files with orbits and clocks in SP3 format, separate them by comma. <i>[key: sp3CompFile]</i></p>"));
+  _sp3CompClkLineEdit->setWhatsThis(tr("<p>Optionally specify the full path to clock RINEX files with the satellite clocks of the SP3 files, separated by comma and in the order of the SP3 files. A single file refers to the first SP3 file; enter '-' for an SP3 file without clock RINEX file. Example:<p>GBM0MGXRAP_20263290000_01D_30S_CLK.CLK</p><p>The clocks of a clock RINEX file replace those of the corresponding SP3 file. Clocks and signal-in-space differences are then compared at all common epochs of the clocks (e.g. every 30 sec instead of every 5 min), the orbits being interpolated between the SP3 epochs where necessary. The orbit statistics refer to the common SP3 epochs only.</p><p>Default is an empty option field, meaning that the clocks of the SP3 files are compared. <i>[key: sp3CompClkFile]</i></p>"));
   _sp3CompExclude->setWhatsThis(tr("<p>Specify satellites to exclude them from orbit and clock comparison. Example:<p>G04,G31,R</p><p>This excludes GPS satellites PRN 4 and 31 as well as all GLONASS satellites from the comparison.</p><p>Default is an empty option field, meaning that no satellite is excluded from the comparison. <i>[key: sp3CompExclude]</i></p>"));
   _sp3CompLogLineEdit->setWhatsThis(tr("<p>Specify the full path to a logfile saving comparison results.</p><p>Specifying a logfile is mandatory. Comparing SP3 files and not saving comparison results on disk would be useless. <i>[key: sp3CompOutLogFile]</i></p>"));
@@ -2001,4 +2009,5 @@
   delete _reqcEditOptionButton;
   delete _sp3CompFileChooser;
+  delete _sp3CompClkLineEdit;
   delete _sp3CompExclude;
   delete _sp3CompLogLineEdit;
@@ -2517,4 +2526,5 @@
   // SP3 Comparison
   settings.setValue("sp3CompFile", _sp3CompFileChooser->fileName());
+  settings.setValue("sp3CompClkFile", _sp3CompClkLineEdit->text());
   settings.setValue("sp3CompExclude", _sp3CompExclude->text());
   settings.setValue("sp3CompOutLogFile", _sp3CompLogLineEdit->text());
@@ -3162,4 +3172,5 @@
     enable = !_sp3CompFileChooser->fileName().isEmpty();
     enableWidget(enable, _sp3CompLogLineEdit);
+    enableWidget(enable, _sp3CompClkLineEdit);
     enableWidget(enable, _sp3CompExclude);
     enableWidget(enable, _sp3CompSummaryOnly);
Index: trunk/BNC/src/bncwindow.h
===================================================================
--- trunk/BNC/src/bncwindow.h	(revision 11227)
+++ trunk/BNC/src/bncwindow.h	(revision 11228)
@@ -172,4 +172,5 @@
 
     qtFileChooser* _sp3CompFileChooser;
+    QLineEdit* _sp3CompClkLineEdit;
     QLineEdit* _sp3CompExclude;
     QLineEdit* _sp3CompLogLineEdit;
Index: trunk/BNC/src/orbComp/sp3Comp.cpp
===================================================================
--- trunk/BNC/src/orbComp/sp3Comp.cpp	(revision 11227)
+++ trunk/BNC/src/orbComp/sp3Comp.cpp	(revision 11228)
@@ -35,5 +35,7 @@
  * Created:    24-Nov-2014
  *
- * Changes:
+ * Changes:    26-Nov-2026: optional clock RINEX files (sp3CompClkFile): clocks
+ *                           and SIS at the epochs of the clock files, orbits
+ *                           interpolated between the SP3 epochs
  *
  * -----------------------------------------------------------------------*/
@@ -41,5 +43,7 @@
 #include <QRegularExpression>
 #include <iostream>
+#include <fstream>
 #include <iomanip>
+#include <algorithm>
 #include "sp3Comp.h"
 #include "bnccore.h"
@@ -58,4 +62,17 @@
   for (int ii = 0; ii < _sp3FileNames.size(); ii++) {
     expandEnvVar(_sp3FileNames[ii]);
+  }
+  // Clock RINEX files, in the order of the SP3 files; one name refers to
+  // SP3 file 1, an empty entry or "-" to no clock file
+  QString clkFiles = settings.value("sp3CompClkFile").toString().trimmed();
+  if (!clkFiles.isEmpty()) {
+    _clkFileNames = clkFiles.split(",", Qt::KeepEmptyParts);
+    for (int ii = 0; ii < _clkFileNames.size(); ii++) {
+      _clkFileNames[ii] = _clkFileNames[ii].trimmed();
+      if (_clkFileNames[ii] == "-") {
+        _clkFileNames[ii].clear();
+      }
+      expandEnvVar(_clkFileNames[ii]);
+    }
   }
   _logFileName = settings.value("sp3CompOutLogFile").toString(); expandEnvVar(_logFileName);
@@ -94,6 +111,15 @@
     *_log << "! SP3 File " << ii+1 << ": " << _sp3FileNames[ii] << "\n";
   }
+  for (int ii = 0; ii < _clkFileNames.size(); ii++) {
+    if (!_clkFileNames[ii].isEmpty()) {
+      *_log << "! CLK File " << ii+1 << ": " << _clkFileNames[ii] << "\n";
+    }
+  }
   if (_sp3FileNames.size() != 2) {
     *_log << "ERROR: sp3Comp requires two input SP3 files" << "\n";
+    goto end;
+  }
+  if (_clkFileNames.size() > 2) {
+    *_log << "ERROR: sp3Comp accepts at most two clock RINEX files" << "\n";
     goto end;
   }
@@ -280,36 +306,47 @@
 void t_sp3Comp::compare(ostringstream& out) const {
 
-  // Synchronize reading of two sp3 files
-  // ------------------------------------
-  bncSP3 in1(_sp3FileNames[0]); in1.nextEpoch();
-  bncSP3 in2(_sp3FileNames[1]); in2.nextEpoch();
+  // Read the SP3 files (and clock RINEX files)
+  // -------------------------------------------
+  t_sp3Data sp3[2];
+  map<bncTime, map<t_prn, double> > clk[2];
+  bool withClkFiles = false;
+  for (int ii = 0; ii < 2; ii++) {
+    readSp3(_sp3FileNames[ii], sp3[ii]);
+    if (ii < _clkFileNames.size() && !_clkFileNames[ii].isEmpty()) {
+      readClk(_clkFileNames[ii], clk[ii]);
+      withClkFiles = true;
+      if (clk[ii].empty()) {
+        throw "t_sp3Comp: no clocks in clock RINEX file " + string(_clkFileNames[ii].toLatin1().data());
+      }
+    }
+    else {
+      clk[ii] = sp3[ii]._clk;
+    }
+  }
 
   vector<t_epoch*> epochs;
-  while (in1.currEpoch() && in2.currEpoch()) {
-    bncTime t1 = in1.currEpoch()->_tt;
-    bncTime t2 = in2.currEpoch()->_tt;
-    if      (t1 < t2) {
-      in1.nextEpoch();
-    }
-    else if (t1 > t2) {
-      in2.nextEpoch();
-    }
-    else if (t1 == t2) {
-      t_epoch* epo = new t_epoch; epo->_tt = t1;
-      bool epochOK = false;
-      for (int i1 = 0; i1 < in1.currEpoch()->_sp3Sat.size(); i1++) {
-        bncSP3::t_sp3Sat* sat1 = in1.currEpoch()->_sp3Sat[i1];
-        for (int i2 = 0; i2 < in2.currEpoch()->_sp3Sat.size(); i2++) {
-          bncSP3::t_sp3Sat* sat2 = in2.currEpoch()->_sp3Sat[i2];
-          if (sat1->_prn == sat2->_prn &&
-              sat1->_clkValid && sat2->_clkValid) {
-            epochOK = true;
-            epo->_dr[sat1->_prn]  = sat1->_xyz - sat2->_xyz;
-            epo->_xyz[sat1->_prn] = sat1->_xyz;
-            epo->_dc[sat1->_prn]  = sat1->_clk - sat2->_clk;
-          }
-        }
-      }
-      if (epochOK) {
+  if (!withClkFiles) {
+    // Common epochs of the two SP3 files, satellites with valid clocks in both
+    // -------------------------------------------------------------------------
+    map<bncTime, map<t_prn, ColumnVector> >::const_iterator it1;
+    for (it1 = sp3[0]._xyz.begin(); it1 != sp3[0]._xyz.end(); it1++) {
+      const bncTime& tt = it1->first;
+      map<bncTime, map<t_prn, ColumnVector> >::const_iterator it2 = sp3[1]._xyz.find(tt);
+      if (it2 == sp3[1]._xyz.end()) {
+        continue;
+      }
+      const map<t_prn, double>& c1 = clk[0][tt];
+      const map<t_prn, double>& c2 = clk[1][tt];
+      t_epoch* epo = new t_epoch; epo->_tt = tt;
+      for (map<t_prn, ColumnVector>::const_iterator is = it1->second.begin(); is != it1->second.end(); is++) {
+        const t_prn& prn = is->first;
+        map<t_prn, ColumnVector>::const_iterator jj = it2->second.find(prn);
+        if (jj != it2->second.end() && c1.find(prn) != c1.end() && c2.find(prn) != c2.end()) {
+          epo->_dr[prn]  = is->second - jj->second;
+          epo->_xyz[prn] = is->second;
+          epo->_dc[prn]  = c1.find(prn)->second - c2.find(prn)->second;
+        }
+      }
+      if (epo->_dc.size() > 0) {
         epochs.push_back(epo);
       }
@@ -317,6 +354,43 @@
         delete epo;
       }
-      in1.nextEpoch();
-      in2.nextEpoch();
+    }
+  }
+  else {
+    // Common epochs of the two clock sources; the orbits are interpolated
+    // between the SP3 epochs where necessary and then used for the clock
+    // comparison and the SIS only (orbit statistics: common SP3 epochs)
+    // ---------------------------------------------------------------------
+    map<bncTime, map<t_prn, double> >::const_iterator it1;
+    for (it1 = clk[0].begin(); it1 != clk[0].end(); it1++) {
+      const bncTime& tt = it1->first;
+      map<bncTime, map<t_prn, double> >::const_iterator it2 = clk[1].find(tt);
+      if (it2 == clk[1].end()) {
+        continue;
+      }
+      t_epoch* epo = new t_epoch; epo->_tt = tt;
+      for (map<t_prn, double>::const_iterator is = it1->second.begin(); is != it1->second.end(); is++) {
+        const t_prn& prn = is->first;
+        map<t_prn, double>::const_iterator jj = it2->second.find(prn);
+        if (jj == it2->second.end()) {
+          continue;
+        }
+        ColumnVector xyz1, xyz2;
+        bool interp1, interp2;
+        if (!orbit(sp3[0], prn, tt, xyz1, interp1) || !orbit(sp3[1], prn, tt, xyz2, interp2)) {
+          continue;
+        }
+        epo->_dr[prn]  = xyz1 - xyz2;
+        epo->_xyz[prn] = xyz1;
+        epo->_dc[prn]  = is->second - jj->second;
+        if (interp1 || interp2) {
+          epo->_orbInterp.insert(prn);
+        }
+      }
+      if (epo->_dc.size() > 0) {
+        epochs.push_back(epo);
+      }
+      else {
+        delete epo;
+      }
     }
   }
@@ -413,8 +487,10 @@
               << setw(7) << setprecision(4) << rao[2] << "    ";
         }
-        stat[prn.toString()]._rao += SP(rao, rao); // Schur product
-        stat[all.str()     ]._rao += SP(rao, rao);
-        stat[prn.toString()]._nr  += 1;
-        stat[all.str()     ]._nr  += 1;
+        if (epo->_orbInterp.find(prn) == epo->_orbInterp.end()) {
+          stat[prn.toString()]._rao += SP(rao, rao); // Schur product
+          stat[all.str()     ]._rao += SP(rao, rao);
+          stat[prn.toString()]._nr  += 1;
+          stat[all.str()     ]._nr  += 1;
+        }
         if (dc.find(prn) != dc.end() && dcRed.find(prn) != dc.end()) {
           double clkRes    = dc.find(prn)->second;
@@ -482,9 +558,11 @@
     char sys = prn[0];
     stringstream all; all << sys << 99;
-    if (stat._nr > 0) {
-      stat._rao[0] = sqrt(stat._rao[0] / stat._nr);
-      stat._rao[1] = sqrt(stat._rao[1] / stat._nr);
-      stat._rao[2] = sqrt(stat._rao[2] / stat._nr);
-      stat._rao3DRMS = stat._rao.NormFrobenius();
+    if (stat._nr > 0 || stat._nc > 0) {
+      if (stat._nr > 0) {
+        stat._rao[0] = sqrt(stat._rao[0] / stat._nr);
+        stat._rao[1] = sqrt(stat._rao[1] / stat._nr);
+        stat._rao[2] = sqrt(stat._rao[2] / stat._nr);
+        stat._rao3DRMS = stat._rao.NormFrobenius();
+      }
       // orbit values in millimeter
       if (prn != all.str()) {
@@ -529,4 +607,139 @@
 }
 
+// Read an SP3 file (positions, valid clocks, orbit series per satellite)
+////////////////////////////////////////////////////////////////////////////
+void t_sp3Comp::readSp3(const QString& fileName, t_sp3Data& data) const {
+  bncSP3 in(fileName);
+  bncTime lastTime;
+  while (const bncSP3::t_sp3Epoch* epo = in.nextEpoch()) {
+    const bncTime& tt = epo->_tt;
+    if (lastTime.valid()) {
+      double dt = tt - lastTime;
+      if (dt > 0.0 && (data._sampl == 0.0 || dt < data._sampl)) {
+        data._sampl = dt;
+      }
+    }
+    lastTime = tt;
+    map<t_prn, ColumnVector>& xyz = data._xyz[tt];
+    for (int ii = 0; ii < epo->_sp3Sat.size(); ii++) {
+      const bncSP3::t_sp3Sat* sat = epo->_sp3Sat[ii];
+      xyz[sat->_prn] = sat->_xyz;
+      if (sat->_clkValid) {
+        data._clk[tt][sat->_prn] = sat->_clk;
+      }
+    }
+  }
+  map<bncTime, map<t_prn, ColumnVector> >::const_iterator it;
+  for (it = data._xyz.begin(); it != data._xyz.end(); it++) {
+    map<t_prn, ColumnVector>::const_iterator is;
+    for (is = it->second.begin(); is != it->second.end(); is++) {
+      t_orbSeries& series = data._series[is->first];
+      series._tt.push_back(it->first);
+      series._xyz.push_back(is->second);
+    }
+  }
+}
+
+// Read the satellite clocks (AS records) of a clock RINEX file [m]
+////////////////////////////////////////////////////////////////////////////
+void t_sp3Comp::readClk(const QString& fileName,
+                        map<bncTime, map<t_prn, double> >& clk) const {
+  ifstream in(fileName.toLocal8Bit().data());
+  if (!in.good()) {
+    throw "t_sp3Comp: cannot open clock RINEX file " + string(fileName.toLatin1().data());
+  }
+  string line;
+  bool header = true;
+  while (getline(in, line)) {
+    if (header) {
+      if (line.find("END OF HEADER") != string::npos) {
+        header = false;
+      }
+      continue;
+    }
+    if (line.compare(0, 3, "AS ") != 0) {   // other records, continuation lines
+      continue;
+    }
+    replace(line.begin(), line.end(), 'D', 'E');   // Fortran exponent
+    replace(line.begin(), line.end(), 'd', 'E');
+    istringstream inLine(line.substr(3));
+    string prnStr;
+    int    YY, MM, DD, hh, mm, numValues;
+    double ss, value;
+    inLine >> prnStr >> YY >> MM >> DD >> hh >> mm >> ss >> numValues >> value;
+    if (inLine.fail() || numValues < 1 || prnStr.size() < 3) {
+      continue;
+    }
+    t_prn prn;
+    try {
+      prn.set(prnStr);
+    }
+    catch (...) {        // satellite system not supported
+      continue;
+    }
+    if (prn.number() == 0) {
+      continue;
+    }
+    bncTime tt; tt.set(YY, MM, DD, hh, mm, ss);
+    clk[tt][prn] = value * t_CST::c;
+  }
+}
+
+// Satellite position at epoch tt: the SP3 position if tt is an SP3 epoch,
+// otherwise Lagrange interpolation with 10 consecutive SP3 epochs around tt
+// (no extrapolation, no data gaps longer than 1.5 sampling intervals)
+////////////////////////////////////////////////////////////////////////////
+bool t_sp3Comp::orbit(const t_sp3Data& data, const t_prn& prn, const bncTime& tt,
+                      ColumnVector& xyz, bool& interpolated) const {
+  const unsigned NUMNODES = 10;
+  interpolated = false;
+  map<t_prn, t_orbSeries>::const_iterator itS = data._series.find(prn);
+  if (itS == data._series.end()) {
+    return false;
+  }
+  const t_orbSeries& series = itS->second;
+  const vector<bncTime>& times = series._tt;
+  vector<bncTime>::const_iterator it = lower_bound(times.begin(), times.end(), tt);
+  if (it != times.end() && *it == tt) {
+    xyz = series._xyz[it - times.begin()];
+    return true;
+  }
+  if (it == times.begin() || it == times.end() || data._sampl <= 0.0) {
+    return false;
+  }
+  const double maxGap = 1.5 * data._sampl;
+  int lo = (it - times.begin()) - 1;
+  int hi = lo + 1;
+  if (times[hi] - times[lo] > maxGap) {
+    return false;
+  }
+  // extend the window alternately to both sides
+  while (unsigned(hi - lo + 1) < NUMNODES) {
+    bool left  = (lo > 0 && times[lo] - times[lo-1] <= maxGap);
+    bool right = (hi < int(times.size()) - 1 && times[hi+1] - times[hi] <= maxGap);
+    if (!left && !right) {
+      return false;
+    }
+    if (left && (!right || (tt - times[lo]) <= (times[hi] - tt))) {
+      --lo;
+    }
+    else {
+      ++hi;
+    }
+  }
+  xyz.ReSize(3); xyz = 0.0;
+  for (int ii = lo; ii <= hi; ii++) {
+    double weight = 1.0;
+    for (int jj = lo; jj <= hi; jj++) {
+      if (jj != ii) {
+        weight *= (tt - times[jj]) / (times[ii] - times[jj]);
+      }
+    }
+    xyz += weight * series._xyz[ii];
+  }
+  interpolated = true;
+  return true;
+}
+
 //
 ////////////////////////////////////////////////////////////////////////////
Index: trunk/BNC/src/orbComp/sp3Comp.h
===================================================================
--- trunk/BNC/src/orbComp/sp3Comp.h	(revision 11227)
+++ trunk/BNC/src/orbComp/sp3Comp.h	(revision 11228)
@@ -62,4 +62,22 @@
     std::map<t_prn, double>       _dcRed;
     std::map<t_prn, double>       _sis;   // radial - clock, epoch-wise clock offset removed only
+    std::set<t_prn>               _orbInterp; // orbit of at least one file interpolated
+  };
+
+  // Orbit positions of one satellite (one SP3 file), sorted by time
+  class t_orbSeries {
+   public:
+    std::vector<bncTime>      _tt;
+    std::vector<ColumnVector> _xyz;
+  };
+
+  // Contents of one SP3 file
+  class t_sp3Data {
+   public:
+    t_sp3Data() : _sampl(0.0) {}
+    std::map<bncTime, std::map<t_prn, ColumnVector> > _xyz;  // all positions
+    std::map<bncTime, std::map<t_prn, double> >       _clk;  // valid clocks [m]
+    std::map<t_prn, t_orbSeries>                      _series;
+    double                                            _sampl; // smallest epoch interval [s]
   };
 
@@ -99,6 +117,12 @@
   void compare(std::ostringstream& out) const;
   bool excludeSat(const t_prn& prn) const;
+  void readSp3(const QString& fileName, t_sp3Data& data) const;
+  void readClk(const QString& fileName,
+               std::map<bncTime, std::map<t_prn, double> >& clk) const;
+  bool orbit(const t_sp3Data& data, const t_prn& prn, const bncTime& tt,
+             ColumnVector& xyz, bool& interpolated) const;
 
   QStringList  _sp3FileNames;
+  QStringList  _clkFileNames;   // clock RINEX files for SP3 file 1 and 2 (empty: none)
   QString      _logFileName;
   QFile*       _logFile;
