Index: /trunk/FACT++/src/Fits.cc
===================================================================
--- /trunk/FACT++/src/Fits.cc	(revision 12034)
+++ /trunk/FACT++/src/Fits.cc	(revision 12035)
@@ -22,4 +22,5 @@
 
 #include <sys/stat.h> //for file stats
+#include <cstdio> // for file rename
 
 using namespace std;
@@ -91,4 +92,5 @@
     fRunNumber = runNumber;
     fMess = out;
+    fFileName = fileName;
 
     if (fFile)
@@ -177,5 +179,22 @@
     return true;
 }
-
+void Fits::MoveFileToCorruptedFile()
+{
+    ostringstream corruptName;
+    struct stat st;
+    int append = 0;
+    corruptName << fFileName << "corrupt" << append;
+    while (stat(corruptName.str().c_str(), &st))
+    {
+        append++;
+        corruptName.str("");
+        corruptName << fFileName << "corrupt" << append;
+    }
+    if (rename(fFileName.c_str(), corruptName.str().c_str()) != 0)
+        fMess->Error("Could not rename file " + fFileName);
+    else
+        fMess->Message("Renamed file " + fFileName + " to " + corruptName.str());
+
+}
 // --------------------------------------------------------------------------
 //
@@ -213,4 +232,5 @@
     {
         Close();
+        MoveFileToCorruptedFile();
         return false;
     }
Index: /trunk/FACT++/src/Fits.h
===================================================================
--- /trunk/FACT++/src/Fits.h	(revision 12034)
+++ /trunk/FACT++/src/Fits.h	(revision 12035)
@@ -18,4 +18,5 @@
 private:
     FitsFile *fFile;
+    string fFileName;
 
     ///Name of the "standard", i.e. data found in every fits file
@@ -48,4 +49,8 @@
     ///Write the FITS header keys
     bool WriteHeaderKeys();
+    //if a write error occurs
+    void MoveFileToCorruptedFile();
+
+
 
 public:
