Index: trunk/BNC/src/bncoutf.cpp
===================================================================
--- trunk/BNC/src/bncoutf.cpp	(revision 10608)
+++ trunk/BNC/src/bncoutf.cpp	(revision 11179)
@@ -187,15 +187,7 @@
   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 && !wait) {
+  if (newFileName != _fName) {
     closeFile();
     _headerWritten = false;
@@ -206,17 +198,39 @@
   // --------------------------
   if (!_headerWritten) {
+    _out.clear();
+    _out.width(0);
     _out.setf(ios::showpoint | ios::fixed);
-    if (_append && QFile::exists(_fName)) {
-      _out.open(_fName.toLatin1().data(), ios::out | ios::app);
-    }
-    else {
-      _out.open(_fName.toLatin1().data());
+    bool appended = _append && QFile::exists(_fName);
+    _out.open(_fName.toLatin1().data(), appended ? ios::out | ios::app : ios::out);
+    if (!_out.is_open()) {
+      return failure;
+    }
+    if (!appended) {
       writeHeader(datTim);
     }
-    if (_out.is_open()) {
-      _headerWritten = true;
-    }
-  }
-
+    _headerWritten = true;
+  }
+
+  return success;
+}
+
+// Write a complete epoch (product files): an epoch at the start of a file
+// period (e.g. 00:00:00 for daily files) is written as last epoch into the
+// file of the period before, too
+////////////////////////////////////////////////////////////////////////////
+t_irc bncoutf::writeEpoch(const bncTime& epoTime, const std::string& str) {
+  if (_out.is_open() && isProductFile()) {
+    bncTime   before   = epoTime - 1.0;
+    QDateTime datTim   = dateAndTimeFromGPSweek(epoTime.gpsw(), epoTime.gpssec());
+    QDateTime datTimBf = dateAndTimeFromGPSweek(before.gpsw(), before.gpssec());
+    if (resolveFileName(epoTime.gpsw(), datTim) != _fName &&
+        resolveFileName(before.gpsw(), datTimBf) == _fName) {
+      _out << str;
+    }
+  }
+  if (reopen(epoTime.gpsw(), epoTime.gpssec()) != success) {
+    return failure;
+  }
+  _out << str;
   return success;
 }
