Index: trunk/BNC/src/bncclockrinex.cpp
===================================================================
--- trunk/BNC/src/bncclockrinex.cpp	(revision 10607)
+++ trunk/BNC/src/bncclockrinex.cpp	(revision 10608)
@@ -47,33 +47,44 @@
   if (reopen(GPSweek, GPSweeks) == success) {
 
-      QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
-      double sec = fmod(GPSweeks, 60.0);
+    bncTime epoTime(GPSweek, GPSweeks);
 
-      int numValues = 1;
-      if (clkRnxSig && clkRnxRate && clkRnxRateSig) {
-        numValues += 3;
-      }
-      if (clkRnxAcc && clkRnxAccSig) {
-        numValues += 2;
+    if (epoTime != _lastEpoTime) {
+
+      // print out epoch before
+      if (_lastEpoTime.valid()) {
+        _out << _oStr.str();
+        if (_lastEpoTime.daysec() != 0.0) {
+          _oStr.str(std::string());
+        }
       }
 
-      _out << "AS " << prn.toLatin1().data()
-           << datTim.toString("  yyyy MM dd hh mm").toLatin1().data()
-           << fixed      << setw(10) << setprecision(6)  << sec
-           << "  " << numValues << "   "
-           << fortranFormat(clkRnx, 19, 12).toLatin1().data();
+      _lastEpoTime = epoTime;
+    }
 
-      if (numValues >=2) {
-        _out << " " << fortranFormat(clkRnxSig, 19, 12).toLatin1().data() << endl;
-      }
-      if (numValues == 4) {
-        _out << fortranFormat(clkRnxRate, 19, 12).toLatin1().data() << " ";
-        _out << fortranFormat(clkRnxRateSig, 19, 12).toLatin1().data() << " ";
-      }
-      if (numValues == 6) {
-        _out << fortranFormat(clkRnxAcc, 19, 12).toLatin1().data() << " ";
-        _out << " " << fortranFormat(clkRnxAccSig, 19, 12).toLatin1().data();
-      }
-      _out << endl;
+    int numValues = 1;
+    if (clkRnxSig && clkRnxRate && clkRnxRateSig) {
+      numValues += 3;
+    }
+    if (clkRnxAcc && clkRnxAccSig) {
+      numValues += 2;
+    }
+
+    _oStr << "AS " << prn.toLatin1().data()
+         << "  " <<  epoTime.datestr(' ') << ' ' << epoTime.timestr(6, ' ')
+         << "  " << numValues << "   "
+         << fortranFormat(clkRnx, 19, 12).toLatin1().data();
+
+    if (numValues >=2) {
+      _oStr << " " << fortranFormat(clkRnxSig, 19, 12).toLatin1().data() << endl;
+    }
+    if (numValues == 4) {
+      _oStr << fortranFormat(clkRnxRate, 19, 12).toLatin1().data() << " ";
+      _oStr << fortranFormat(clkRnxRateSig, 19, 12).toLatin1().data() << " ";
+    }
+    if (numValues == 6) {
+      _oStr << fortranFormat(clkRnxAcc, 19, 12).toLatin1().data() << " ";
+      _oStr << " " << fortranFormat(clkRnxAccSig, 19, 12).toLatin1().data();
+    }
+    _oStr << endl;
 
     return success;
Index: trunk/BNC/src/bncclockrinex.h
===================================================================
--- trunk/BNC/src/bncclockrinex.h	(revision 10607)
+++ trunk/BNC/src/bncclockrinex.h	(revision 10608)
@@ -18,4 +18,6 @@
  private:
   virtual void writeHeader(const QDateTime& datTim);
+  std::ostringstream _oStr;
+  bncTime            _lastEpoTime;
 };
 
Index: trunk/BNC/src/bncoutf.cpp
===================================================================
--- trunk/BNC/src/bncoutf.cpp	(revision 10607)
+++ trunk/BNC/src/bncoutf.cpp	(revision 10608)
@@ -187,7 +187,15 @@
   QString newFileName = resolveFileName(GPSweek, datTim);
 
+  bool wait = false;
+  if (isProductFile() &&
+      datTim.time().hour()   == 0 &&
+      datTim.time().minute() == 0 &&
+      (datTim.time().second() == 0.0 ||  datTim.time().second() == _sampl)) {
+    wait = true;
+  }
+
   // Close the file
   // --------------
-  if (newFileName != _fName) {
+  if (newFileName != _fName && !wait) {
     closeFile();
     _headerWritten = false;
@@ -226,2 +234,19 @@
   return QString("%1").arg(_sklBaseName.left(3));
 }
+
+// Files with epoch 00:00:00 at begin and end
+////////////////////////////////////////////////////////////////////////////
+bool bncoutf::isProductFile() {
+ bool isProduct = false;
+
+ if (_extension.contains("SP3")) {
+   isProduct = true;
+ }
+ if (_extension.contains("CLK")) {
+   isProduct = true;
+ }
+
+  return isProduct;
+}
+
+
Index: trunk/BNC/src/bncoutf.h
===================================================================
--- trunk/BNC/src/bncoutf.h	(revision 10607)
+++ trunk/BNC/src/bncoutf.h	(revision 10608)
@@ -15,4 +15,5 @@
   t_irc write(int GPSweek, double GPSweeks, const QString& str);
   QString agencyFromFileName();
+  bool isProductFile();
  protected:
   virtual t_irc reopen(int GPSweek, double GPSweeks);
Index: trunk/BNC/src/bncsp3.cpp
===================================================================
--- trunk/BNC/src/bncsp3.cpp	(revision 10607)
+++ trunk/BNC/src/bncsp3.cpp	(revision 10608)
@@ -74,9 +74,16 @@
     if (epoTime != _lastEpoTime) {
 
-      // Check the sampling interval (print empty epochs)
-      // ------------------------------------------------
-      if (_lastEpoTime.valid() && _sampl > 0) {
-        for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
-          _out << "\n*  " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ');
+      // print out epoch before
+      if (_lastEpoTime.valid()) {
+        _out << _oStr.str();
+        if (_lastEpoTime.daysec() != 0.0) {
+          _oStr.str(std::string());
+        }
+        // Check the sampling interval (print empty epochs)
+        // ------------------------------------------------
+        if (_sampl > 0) {
+          for (bncTime ep = _lastEpoTime +_sampl; ep < epoTime; ep = ep +_sampl) {
+            _oStr << "\n*  " << ep.datestr(' ') << ' ' << ep.timestr(8, ' ');
+          }
         }
       }
@@ -84,10 +91,10 @@
       // Print the new epoch
       // -------------------
-      _out << "\n*  " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ');
+      _oStr << "\n*  " << epoTime.datestr(' ') << ' ' << epoTime.timestr(8, ' ');
 
       _lastEpoTime = epoTime;
     }
 
-    _out << "\nP" << prn.toLatin1().data()
+    _oStr << "\nP" << prn.toLatin1().data()
          << setw(14) << setprecision(6) << xCoM(1) / 1000.0 // [km]
          << setw(14) << setprecision(6) << xCoM(2) / 1000.0 // [km]
@@ -96,5 +103,5 @@
 
     if (sp3ClkRate) {
-      _out << "\nV" << prn.toLatin1().data()
+      _oStr << "\nV" << prn.toLatin1().data()
            << setw(14) << setprecision(6) << v(1) * 10.0      // [dm/s]
            << setw(14) << setprecision(6) << v(2) * 10.0      // [dm/s]
@@ -177,5 +184,5 @@
        << "/*                                                          \n"
        << "/*                                                          \n"
-       << "/*                                                          \n";
+       << "/*                                                          ";
 }
 
Index: trunk/BNC/src/bncsp3.h
===================================================================
--- trunk/BNC/src/bncsp3.h	(revision 10607)
+++ trunk/BNC/src/bncsp3.h	(revision 10608)
@@ -56,10 +56,11 @@
   virtual void closeFile();
 
-  e_inpOut      _inpOut;
-  bncTime       _lastEpoTime;
-  std::ifstream _stream;
-  std::string   _lastLine;
-  t_sp3Epoch*   _currEpoch;
-  t_sp3Epoch*   _prevEpoch;
+  e_inpOut           _inpOut;
+  bncTime            _lastEpoTime;
+  std::ifstream      _stream;
+  std::string        _lastLine;
+  t_sp3Epoch*        _currEpoch;
+  t_sp3Epoch*        _prevEpoch;
+  std::ostringstream _oStr;
 };
 
