Index: /trunk/FACT++/src/Fits.cc
===================================================================
--- /trunk/FACT++/src/Fits.cc	(revision 12535)
+++ /trunk/FACT++/src/Fits.cc	(revision 12536)
@@ -362,4 +362,11 @@
 }
 
+void Fits::Flush()
+{
+    if (!fFile)
+        return;
+
+    fFile->Flush();
+}
 // --------------------------------------------------------------------------
 //! Returns the size on the disk of the Fits file being written.
Index: /trunk/FACT++/src/Fits.h
===================================================================
--- /trunk/FACT++/src/Fits.h	(revision 12535)
+++ /trunk/FACT++/src/Fits.h	(revision 12536)
@@ -91,4 +91,7 @@
     void Close();
 
+    ///Flush the currently opened file to disk.
+    void Flush();
+
     ///Get the size currently written on the disk
     int GetWrittenSize() const;
Index: /trunk/FACT++/src/FitsFile.cc
===================================================================
--- /trunk/FACT++/src/FitsFile.cc	(revision 12535)
+++ /trunk/FACT++/src/FitsFile.cc	(revision 12536)
@@ -403,4 +403,22 @@
 }
 
+void FitsFile::Flush()
+{
+    if (!fFile)
+        return;
+
+    int status = 0;
+    fits_flush_file(fFile->fitsPointer(), &status);
+
+    if (status)
+    {
+        char text[30];
+        fits_get_errstatus(status, text);
+
+        ostringstream str;
+        str << "Flushing file " << fFile->name() << " failed: " << text << " (fits_flush_file, rc=" << status << ")";
+        Error(str);
+    }
+}
 size_t FitsFile::GetDataSize() const
 {
Index: /trunk/FACT++/src/FitsFile.h
===================================================================
--- /trunk/FACT++/src/FitsFile.h	(revision 12535)
+++ /trunk/FACT++/src/FitsFile.h	(revision 12536)
@@ -93,4 +93,6 @@
     void Close();
 
+    void Flush();
+
     bool IsOpen() const { return fFile && fTable; }
 
Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 12535)
+++ /trunk/FACT++/src/datalogger.cc	(revision 12536)
@@ -1172,24 +1172,6 @@
     //
     // Check whether we should close and reopen daily text files or not
-    //
-    // This should work in any case base of the following:
-    //  - fDailyFileDayChangedAlready is initialized to true. So if the
-    //    dataLogger is started around noon, no file will be closed
-    //  - fDailyFileDayChangedAlready is set to false if (time != 12), so
-    //    the file will be closed and reopened only if the logger runs since
-    //    before noon (which is the required behavior)
-    //
-    // This only applies to text files. Fits are closed and reopened based on
-    // the last and current service received time.
-    // This was not applicable to text files, because as they gather several
-    // services, we have no guarantee that the received time will be greater
-    // than the previous one, which could lead to several close/reopen instead
-    // of only one.
-    //
-    // Last but not least, the datalogger MUST receive at least one service update during
-    // noon otherwise this is skipped (which is not good). Thus I would suggest that the datalogger
-    // should always subscribe to at least its statistics services.
-    //
-    //calculate time "centered" around noon instead of midnight
+    // calculate time "centered" around noon instead of midnight
+    // if number of days has changed, then files should be closed and reopenned.
     const Time timeNow;
     const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
@@ -1923,4 +1905,5 @@
                 return;
             }
+            sub.nightlyFile.Flush();
          }
 
