Index: /trunk/FACT++/gui/BasicGlCamera.cc
===================================================================
--- /trunk/FACT++/gui/BasicGlCamera.cc	(revision 12070)
+++ /trunk/FACT++/gui/BasicGlCamera.cc	(revision 12071)
@@ -6,4 +6,7 @@
 #include <sstream>
 #include "src/tools.h"
+
+#include <algorithm>
+#include "src/Time.h"
 
 using namespace std;;
@@ -40,4 +43,6 @@
         fMin = -1;
         fMax = -1;
+        fScaleLimit = -0.5;
+        fTextSize = 0;
         autoRefresh = false;
         logScale = false;
@@ -343,4 +348,11 @@
             updateGL();
     }
+    void BasicGlCamera::setAutoscaleLowerLimit(float val)
+    {
+        fScaleLimit = val;
+        if (isVisible() && autoRefresh)
+            updateGL();
+    }
+
     void BasicGlCamera::SetMax(int64_t max)
     {
@@ -368,5 +380,8 @@
         double rms = 0;
         median = 0;
-        multiset<double> medianSet;
+ //       multiset<double> medianSet;
+        vector<double> medianVec;
+        medianVec.resize(ACTUAL_NUM_PIXELS);
+        auto it = medianVec.begin();
         for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
         {
@@ -377,16 +392,33 @@
             mean += fData[i];
             rms += fData[i]*fData[i];
-            medianSet.insert(fData[i]);
-        }
+            //medianSet.insert(fData[i]);
+            *it = fData[i];
+            it++;
+        }
+
+//        vector<double> medianVec;
+//        medianVec.resize(ACTUAL_NUM_PIXELS);
+//        int iii=0;
+//        for (auto it=medianVec.begin(); it != medianVec.end(); it++) {
+//            *it = fData[iii];
+//            iii++;
+//        }
+        sort(medianVec.begin(), medianVec.end());
+
 
         mean /= ACTUAL_NUM_PIXELS;
         rms = sqrt(rms/ACTUAL_NUM_PIXELS - mean * mean);
 
-        multiset<double>::iterator it = medianSet.begin();
+//       multiset<double>::iterator it = medianSet.begin();
+        auto jt = medianVec.begin();
         for (int i=0;i<(ACTUAL_NUM_PIXELS/2)-1;i++)
-            it++;
-        median = *it;
-        it++;
-        median += *it;
+        {
+//            it++;
+            jt++;
+        }
+        median = *jt;
+ //       cout << *it << " " << *jt << endl;
+        jt++;
+        median += *jt;
         median /= 2;
 
@@ -646,4 +678,7 @@
          }
          glMatrixMode(GL_MODELVIEW);
+
+         fTextSize = (int)(cWidth*12/600); //want a sized 12 font for a window of 600 pixels width
+         setFont(QFont("Monospace", fTextSize));
     }
     void BasicGlCamera::paintGL()
Index: /trunk/FACT++/gui/BasicGlCamera.h
===================================================================
--- /trunk/FACT++/gui/BasicGlCamera.h	(revision 12070)
+++ /trunk/FACT++/gui/BasicGlCamera.h	(revision 12071)
@@ -55,4 +55,8 @@
     int64_t fMin;
     int64_t fMax;
+    float fScaleLimit;
+    void setAutoscaleLowerLimit(float);
+
+    int fTextSize;
 
     static PixelMap fPixelMap;
Index: /trunk/FACT++/gui/QCameraWidget.cc
===================================================================
--- /trunk/FACT++/gui/QCameraWidget.cc	(revision 12070)
+++ /trunk/FACT++/gui/QCameraWidget.cc	(revision 12071)
@@ -88,11 +88,11 @@
 
 
-        int textSize = (int)(height()*14/600);
-        setFont(QFont("Monospace", textSize));
+//        int textSize = (int)(width()*14/600);
+//        setFont(QFont("Monospace", textSize));
         qglColor(QColor(255, 223, 127));
 
         //first let's draw the usual data
         //title
-        renderText(-shownSizex/2.f + 0.01f, shownSizey/2.f - textSize*pixelSize - 0.01f, 0.f, QString(titleText.c_str()));
+        renderText(-shownSizex/2.f + 0.01f, shownSizey/2.f - fTextSize*pixelSize - 0.01f, 0.f, QString(titleText.c_str()));
         //stats
         ostringstream str;
@@ -100,11 +100,11 @@
         str.setf(ios::fixed,ios::floatfield);
         str << "Med " << fmedian;// << unitsText;
-        renderText(3, height()-3-4*textSize-35, QString(str.str().c_str()));
+        renderText(3, height()-3-4*fTextSize-35, QString(str.str().c_str()));
         str.str("");
         str << "Avg " << fmean;// <<  unitsText;
-        renderText(3, height()-3-3*textSize-27, QString(str.str().c_str()));
+        renderText(3, height()-3-3*fTextSize-27, QString(str.str().c_str()));
         str.str("");
         str << "RMS " << frms;// <<  unitsText;
-        renderText(3, height()-3-2*textSize-21, QString(str.str().c_str()));
+        renderText(3, height()-3-2*fTextSize-21, QString(str.str().c_str()));
         str.str("");
         str << "Min " << fmin;// << unitsText;
@@ -112,5 +112,5 @@
         str.str("");
         str << "Max " << fmax;// << unitsText;
-        renderText(3, height()-3-1*textSize-8, QString(str.str().c_str()));
+        renderText(3, height()-3-1*fTextSize-8, QString(str.str().c_str()));
         //then draw the values beside the scale
         //the difficulty here is to write the correct min/max besides the scale
@@ -119,15 +119,17 @@
         //real min/max are fmin and fmax (I know, quite confusing... sorry about that)
         //so. first let's see what is the span of one pixel
-        float min = (fMin < 0) ? fmin : fMin;
-        float max = (fMax < 0) ? fmax : fMax;
-        textSize = (int)(height()*12/600);
-        setFont(QFont("Monospace", textSize));
-        float pixelSpan = (height() - textSize - 1)/(max - min);
+        float min = (fMin < fScaleLimit || fMax < fScaleLimit) ? fmin : fMin;
+        float max = (fMin < fScaleLimit || fMax < fScaleLimit) ? fmax : fMax;
+//        textSize = (int)(height()*12/600);
+ //       setFont(QFont("Monospace", textSize));
+        float pixelSpan = (height() - fTextSize - 1)/(max - min);
 
         //draw the scale values
         float value = min;
-        int fontWidth = textSize;
-        if (textSize > 12) fontWidth-=3; else fontWidth -=2;
-        if (textSize < 7) fontWidth++;
+        int fontWidth = fTextSize;
+        if (fTextSize > 12) fontWidth--;
+        if (fTextSize > 10) fontWidth--;
+        if (fTextSize > 7) fontWidth--;//else fontWidth -=1;
+//        if (fTextSize < 7) fontWidth++;
         for (int i=0;i<11;i++)
         {
@@ -149,5 +151,5 @@
             int w = width() - (width()/50) - fontWidth*str.str().size();
             if (i==0 || i==10) w -= width()/50;
-            if (i!=0 && i!=10) h -= textSize/2;
+            if (i!=0 && i!=10) h -= fTextSize/2;
             renderText(w, h, QString(str.str().c_str()));
             value += (max - min)/10;
@@ -171,6 +173,6 @@
         glPopMatrix();
 
-        textSize = (int)(600*14/600);
-        setFont(QFont("Times", textSize));
+//        textSize = (int)(600*14/600);
+//        setFont(QFont("Times", textSize));
     }
     void QCameraWidget::drawPatches()
@@ -399,5 +401,5 @@
      void QCameraWidget::highlightPixel(int idx, bool highlight)
      {
-         if (idx < 0 || idx > ACTUAL_NUM_PIXELS)
+         if (idx < 0 || idx >= ACTUAL_NUM_PIXELS)
          {
            cout << "Error: requested pixel highlight out of bounds" << endl;
@@ -422,5 +424,5 @@
      void QCameraWidget::highlightPatch(int idx, bool highlight)
      {
-         if (idx < 0 || idx > NTMARK)
+         if (idx < 0 || idx >= NTMARK)
          {
              cout << "Error: requested patch highlight out of bounds" << endl;
Index: /trunk/FACT++/src/Fits.h
===================================================================
--- /trunk/FACT++/src/Fits.h	(revision 12070)
+++ /trunk/FACT++/src/Fits.h	(revision 12071)
@@ -56,5 +56,5 @@
 public:
     ///current run number being logged
-    uint32_t fRunNumber;
+    int32_t fRunNumber;
 
     Fits() : fFile(NULL),
Index: /trunk/FACT++/src/datalogger.cc
===================================================================
--- /trunk/FACT++/src/datalogger.cc	(revision 12070)
+++ /trunk/FACT++/src/datalogger.cc	(revision 12071)
@@ -95,5 +95,5 @@
     string reportName;
     ///the actual run number
-    uint32_t runNumber;
+    int32_t runNumber;
     ///the time at which the run number was received
     Time time;
@@ -145,5 +145,5 @@
     shared_ptr<Converter> fConv;
     ///the current run number used by this subscription
-    uint32_t runNumber;
+    int32_t runNumber;
     ///time of the latest received event
     Time lastReceivedEvent;
@@ -515,5 +515,6 @@
     fServiceSubscriptions[server].clear();
     fServiceSubscriptions.erase(server);
-    fRunNumberService = NULL;
+    if (server == "FAD_CONTROL")
+        fRunNumberService = NULL;
     if (fDebugIsOn)
     {
@@ -1241,4 +1242,6 @@
             if (rit->time < cTime) //this is the run number that we want to use
             {
+                if (rit->runNumber <= 0)//take only positive numbers.
+                    break;
                 //Find something better to convert iterator to pointer than the ugly line below....
                 cRunNumber = &(*rit);
