Index: trunk/FACT++/src/Fits.cc
===================================================================
--- trunk/FACT++/src/Fits.cc	(revision 14714)
+++ trunk/FACT++/src/Fits.cc	(revision 14715)
@@ -125,5 +125,5 @@
     {//if we arrived here, this means that the columns descriptions could not be parsed
         ostringstream str;
-        str << "Expected " << dataFormat.size() << " descriptions of columns, got " << desc.size()-1 << " for service: ";
+        str << "Expected " << dataFormat.size() << " descriptions of columns, got " << (int)(desc.size())-1 << " for service: ";
         if (desc.size() > 0)
             str << desc[0].name;
@@ -208,9 +208,68 @@
         {
             Close();
-            return false;
+            //if the file already exist, then the column names must have changed
+            //let's move the file and try to open it again.
+            string fileNameWithoutFits = fFileName.substr(0, fileName.size()-4);
+            int counter = 0;
+            while (counter < 100)
+            {
+                ostringstream newFileName;
+                newFileName << fileNameWithoutFits << counter << ".fits";
+                ifstream testStream(newFileName.str().c_str());
+                if (!testStream)
+                {
+                    if (rename(fFileName.c_str(), newFileName.str().c_str()))
+                        return false;
+                    break;
+                }
+                counter++;
+            }
+            if (counter == 100)
+                return false;
+            //now we open it again.
+            fFile = new FitsFile(*fMess);
+            if (file == NULL)
+            {
+                if (!fFile->OpenFile(fileName, true))
+                    return false;
+                fNumOpenFitsFiles = fitsCounter;
+                (*fNumOpenFitsFiles)++;
+            }
+            else
+            {
+                if (!fFile->SetFile(file))
+                    return false;
+            }
+            //YES, we must also redo that thing here...
+            //concatenate the standard and data columns
+            //do it the inneficient way first: its easier and faster to code.
+            for (unsigned int i=0;i<fStandardColDesc.size();i++)
+            {
+                fFile->AddColumn(fStandardColDesc[i].name, fStandardFormats[i],
+                                 fStandardColDesc[i].unit);
+            }
+
+            for (unsigned int i=0; i<fDataColDesc.size(); i++)
+            {
+                string name = fDataColDesc[i].name;
+                if (name.empty())
+                {
+                    ostringstream stt;
+                    stt << "Data" << i;
+                    name = stt.str();
+                }
+        //cout << endl << "#####adding column: " << name << " " << fDataFormats[i] << " " << fDataColDesc[i].unit << endl << endl;
+                fFile->AddColumn(name, fDataFormats[i], fDataColDesc[i].unit);
+            }
+            if (!fFile->OpenNewTable(tableName, 100))
+            {
+                Close();
+                return false;
+            }
         }
 
         fCopyBuffer.resize(fFile->GetDataSize());
 //write header comments
+
         ostringstream str;
         for (unsigned int i=0;i<fStandardColDesc.size();i++)
@@ -240,4 +299,5 @@
             fFile->WriteKeyNT(str.str(), fDataColDesc[i].comment, "");
         }
+
         fFile->WriteKeyNT("COMMENT", fTableDesc, "");
 
@@ -250,8 +310,10 @@
             fEndMjD = Time().Mjd();
         }
+
         return fFile->GetNumRows()==0 ? WriteHeaderKeys() : true;
     }
     catch (const CCfits::FitsException &e)
     {
+        cout << "Exception !" << endl;
         fMess->Error("Opening or creating table '"+tableName+"' in '"+fileName+"': "+e.message());
 
@@ -323,5 +385,4 @@
         shift += fStandardNumBytes[i];
     }
-
     try
     {
@@ -339,5 +400,4 @@
     // This is not necessary, is it?
     // fFile->fTable->makeThisCurrent();
-
     if (!fFile->AddRow())
     {
@@ -346,5 +406,4 @@
         return false;
     }
-
     if (!fFile->WriteData(fCopyBuffer))
     {
@@ -352,5 +411,4 @@
         return false;
     }
-
     const double tm = *reinterpret_cast<double*>(fStandardPointers[0]);
 
@@ -385,5 +443,4 @@
     if (!fFile)
         return;
-
     if (fFile->IsOpen() && fFile->IsOwner())
     {
@@ -395,5 +452,4 @@
                           "Time when last event received");
     }
-
     if (fFile->IsOwner())
     {
@@ -401,12 +457,8 @@
             (*fNumOpenFitsFiles)--;
     }
-
     const string name = fFile->GetName();
-
     delete fFile;
     fFile = NULL;
-
     fMess->Info("Closed: "+name);
-
 //    fMess = NULL;
 }
Index: trunk/FACT++/src/FitsFile.cc
===================================================================
--- trunk/FACT++/src/FitsFile.cc	(revision 14714)
+++ trunk/FACT++/src/FitsFile.cc	(revision 14715)
@@ -99,5 +99,4 @@
         return false;
     }
-
     // fFileName = fileName;
     if (!allow_open && access(filename.c_str(), F_OK)==0)
@@ -106,5 +105,4 @@
         return false;
     }
-
     //create the FITS object
     try
@@ -117,5 +115,4 @@
         return false;
     }
-
     /*
      "SIMPLE  =                    T / file does conform to FITS standard             "
@@ -299,4 +296,49 @@
             // Go through the fTable instead as colName is empty (yes, it is !)
             const map<string,CCfits::Column*> &cMap = table->column();
+
+            //check that the existing columns are the same as the ones we want to write
+            for (map<string, CCfits::Column*>::const_iterator mapIt = cMap.begin(); mapIt != cMap.end(); mapIt++)
+            {
+                bool found = false;
+                for (unsigned int ii=0;ii<fColNames.size();ii++)
+                {
+                    if (mapIt->first == fColNames[ii])
+                    {
+                        found = true;
+                        if (mapIt->second->format() != fColTypes[ii])
+                        {
+                            Error("Column "+fColNames[ii]+" has wrong format ("+fColTypes[ii]+" vs "+mapIt->second->format()+" in file)");
+                            return false;
+                        }
+                    }
+                }
+                if (!found)
+                {
+                    Error("Column "+mapIt->first+" only exist in written file");
+                    return false;
+                }
+            }
+            //now we know that all the file's columns are requested. Let's do it the other way around
+            for (unsigned int ii=0;ii<fColNames.size();ii++)
+            {
+                bool found = false;
+                for (map<string, CCfits::Column*>::const_iterator mapIt = cMap.begin(); mapIt != cMap.end(); mapIt++)
+                {
+                    if (fColNames[ii] == mapIt->first)
+                    {
+                        found = true;
+                        if (fColTypes[ii] != mapIt->second->format())
+                        {
+                            Error("Column "+fColNames[ii]+" has wrong format ("+fColTypes[ii]+" vs "+mapIt->second->format()+" in file)");
+                            return false;
+                        }
+                    }
+                }
+                if (!found)
+                {
+                    Error("Column "+fColNames[ii]+" only exist in requested description");
+                    return false;
+                }
+            }
 
             for (map<string,CCfits::Column*>::const_iterator cMapIt = cMap.begin();
Index: trunk/FACT++/src/datalogger.cc
===================================================================
--- trunk/FACT++/src/datalogger.cc	(revision 14714)
+++ trunk/FACT++/src/datalogger.cc	(revision 14715)
@@ -131,4 +131,6 @@
     ///the converter for outputting the data according to the format
     shared_ptr<Converter> fConv;
+    ///the original format string. So that we can check if format is changing over time
+    string format;
     ///the current run number used by this subscription
     int32_t runNumber;
@@ -500,5 +502,9 @@
 void DataLogger::AddService(const Service& svc)
 {
-    const string& server = svc.server;
+    const string& serverr = svc.server;
+    //FIX in order to get rid of the '+' that sometimes makes it all the way to me
+    string server = serverr;
+    if (server.size() > 0 && server[0] == '+')
+        Error("Got a service beginning with +. This is not supposed to happen");
     const string& service = svc.service;
     const bool isCmd = svc.iscmd;
@@ -518,5 +524,40 @@
     if (list.find(service) != list.end())
     {
-  //      Error("Service " + server + "/" + service + " is already in the dataLogger's list... ignoring update.");
+        if (list[service].format != svc.format)
+        {
+            cout << "Format has changed ! taking appropriate measures" << endl;
+            if (list[service].nightlyFile.IsOpen())
+            {
+                string fileName = list[service].nightlyFile.GetName();
+                if (fileName == "")
+                {
+                    cout << "Something went wrong." << endl;
+                    return;
+                }
+                list[service].nightlyFile.Close();
+                string fileNameWithoutFits = fileName.substr(0, fileName.size()-4);
+                int counter=0;
+                while (counter < 100)
+                {
+                    ostringstream newFileName;
+                    newFileName << fileNameWithoutFits << counter << ".fits";
+                    ifstream testStream(newFileName.str());
+                    if (!testStream) //fileName available
+                    {
+                        rename(fileName.c_str(), newFileName.str().c_str());
+                        break;
+                    }
+                    counter++;
+                }
+                if (counter==100)
+                    Error("Tried to find a replacement file for 100 trials. Aborting");
+                //reallocate the fits buffer...
+                list[service].fitsBufferAllocated = false;
+            }
+            list[service].fConv = shared_ptr<Converter>(new Converter(Out(), svc.format));
+            list[service].format = svc.format;
+        }
+        if (fDebugIsOn)
+            Debug("Service " + server + "/" + service + " is already in the dataLogger's list... ignoring update.");
         return;
     }
@@ -529,4 +570,5 @@
     list[service].server  = server;
     list[service].service = service;
+    list[service].format = svc.format;
     list[service].index = servicesCounter;
     fNumSubAndFitsData.numSubscriptions++;
@@ -1106,8 +1148,10 @@
     fRunNumber.back().time = time;
 
-    ostringstream str;
-    str << "The new run number is: " << fRunNumber.back().runNumber;
-    Message(str);
-
+    if (fDebugIsOn)
+    {
+        ostringstream str;
+        str << "The new run number is: " << fRunNumber.back().runNumber;
+        Debug(str);
+    }
     if (GetCurrentState() != kSM_Logging && GetCurrentState() != kSM_WaitingRun )
         return;
@@ -1241,14 +1285,5 @@
     const Time cTime(evt.GetTime());
     fQuality = evt.GetQoS();
-/*    //I had strange surprises with the quality from Dim before. Double check that the value is indeed valid.
-    if (fQuality != kMessage &&
-        fQuality != kInfo &&
-        fQuality != kWarn &&
-        fQuality != kError &&
-        fQuality != kFatal &&
-        fQuality != kComment &&
-        fQuality != kDebug)
-        fQuality = kError;
-*/
+
     fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0;
 
