Index: tools/ddd/Functions.cpp
===================================================================
--- tools/ddd/Functions.cpp	(revision 58)
+++ tools/ddd/Functions.cpp	(revision 59)
@@ -2,12 +2,12 @@
 #include "GUI.h"
 
-//-----------------------------------------------------------------------
-//**************************** All functions ****************************
-//-----------------------------------------------------------------------
+//---------------------------------------------------------------------
+//************************ All functions ****************************
+//-------------------------------------------------------------------
 
 // +++ Open file dialog +++
 void ddd::FileDialog(void) {
-  QString Filename = QFileDialog::getOpenFileName(this,
-     "Open raw file", INITIAL_DIRECTORY, "Raw data files (*.raw);; All files (*)");
+QString Filename = QFileDialog::getOpenFileName(this,
+  "Open raw file", INITIAL_DIRECTORY, "Raw data files (*.raw);; All files (*)");
   if (Filename != NULL) {
     FilenameBox->setText(Filename);
@@ -100,4 +100,5 @@
       double* x = new double [RD->RHeader->Samples];
       double* y = new double [RD->RHeader->Samples];
+
       for (unsigned int i=0; i<RD->RHeader->Samples; i++) {
       	x[i] = (double) (i/RD->BStruct[BoardNo->value()].NomFreq);
@@ -108,5 +109,86 @@
       Signal->show();
       Zoomer->setZoomBase(Signal->boundingRect());
-      delete[] x;	delete[] y; 
+
+      double z[6][6];
+
+      for(unsigned int i=0; i<RD->RHeader->NBoards; i++){
+	  for(unsigned int j=0; j<RD->RHeader->NChips; j++){
+	      for(unsigned int k=0; k<RD->RHeader->NChannels; k++) {
+
+		  //only interested in M0 data
+		  if( ( (i==0 || i==1) && (j<=1) && (k<=7) ) || ( (i==2) && (j==0) && (k<=3) ) ) {
+
+		      std::string pixelname = PixMap->DRS_to_Pixel(i,j,k);
+		      char pixelname_copy[256];
+		      memset(pixelname_copy,'\0',256);
+		      pixelname.copy(pixelname_copy, 256);
+		      
+		      //printf("\nboard %d, chip %d, channel %d, pixel %s:\t", i,j,k,pixelname_copy);
+
+		      char delim[] = "-";
+		      char *buffer = NULL;
+		      int module = -1;
+		      int superpixel = -1;
+		      int pixel = -1;
+
+		      //buffer = strtok(const_cast<char*>(pixelname.c_str()), delim);
+		      buffer = strtok(pixelname_copy, delim);
+		      module = atoi(buffer);
+		      buffer = strtok(NULL, delim);
+		      superpixel = atoi(buffer);
+		      buffer = strtok(NULL, delim);
+		      pixel = atoi(buffer);
+
+		      //printf("%d,%d,%d:\t", module, superpixel, pixel);
+		      //printf("%d:\t", (int((superpixel-1)/3)*2));
+		      //printf("%d:\t", int((pixel%4)+1) );
+		      //printf("%d:\t", int((pixel%4)/2) );
+		      //printf("%d:\t", (superpixel-1)%3 );
+
+		      int binx = 5-(int((superpixel-1)/3)*2)-(int((pixel%4)/2));
+		      int biny = 5-(((superpixel-1)%3)*2)-(int((pixel-1)/2));
+
+		      //printf("%d, %d:\t",binx,biny);
+
+		      int StartBin = 100;
+		      int StopBin = 120;
+
+		      for(int l=StartBin; l<(StopBin+1); l++){
+
+			  float sample = RD->Data[i*RD->RHeader->NChips*RD->RHeader->NChannels*RD->RHeader->Samples+
+						  j*RD->RHeader->NChannels*RD->RHeader->Samples+
+						  k*RD->RHeader->Samples+
+						  l]*RD->BStruct[i].ScaleFactor;
+			  
+			  //printf("%.1f ",sample);
+			  
+			  if (sample > z[binx][biny]) {
+			      z[binx][biny]=sample;
+			  }
+			  
+		      }//sample loop
+      
+		  }//only M0 data
+		  
+	      }//channel loop
+	  }//chip loop
+      }//board loop
+
+      /*
+      for (int i=0; i<6; i++){
+	  for (int j=0; j<6; j++){
+	      z[i][j]=i;
+	  }
+      }
+      */
+
+      Signal2D->setData(SpectrogramDataM0(z));
+      Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
+      Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue() );
+      Graph2D->replot();
+      //Signal2D->show();
+
+      delete[] x;	delete[] y;
+
   }
   if(Tmpfile!=NULL) fclose(Tmpfile);
@@ -119,4 +201,12 @@
   else SocketWindow->show();
 }
+
+// +++ Open sub window for M0 Display +++
+void ddd::OpenM0Window() {
+
+  if(M0Window->isVisible()) M0Window->hide();
+  else M0Window->show();
+}
+
 
 // +++ Acquire data through socket (acquire botton only available if socket exists) +++
Index: tools/ddd/GUI.cpp
===================================================================
--- tools/ddd/GUI.cpp	(revision 58)
+++ tools/ddd/GUI.cpp	(revision 59)
@@ -74,4 +74,10 @@
   connect(SocketButton, SIGNAL(clicked()), this, SLOT(OpenSocketWindow()));
   SocketButton->setToolTip("Open window for socket communication");
+
+  // M0 display button
+  M0Display = new QPushButton("M0 Display",Central);
+  M0Display->setFont(QFont("Times", 10, QFont::Bold));
+  connect(M0Display, SIGNAL(clicked()), this, SLOT(OpenM0Window()));
+  M0Display->setToolTip("Open window for M0 display");
 
   // Acquire button and Continuous check box
@@ -101,5 +107,5 @@
   Signal->attach(Graph);
   Signal->setStyle(QwtPlotCurve::Steps);
-      
+
   // Text boxes for run and event header
   RunHeaderDisplay = new QPlainTextEdit(Central);
@@ -133,4 +139,5 @@
   MainLayout->addLayout(FormLayout, 2, 0);
   MainLayout->addWidget(SocketButton, 6,0);
+  MainLayout->addWidget(M0Display, 3,0);
   MainLayout->addWidget(GetButton, 4,0);
   MainLayout->addWidget(ContinuousBox, 5,0);
@@ -162,5 +169,5 @@
   SocketWindow = new QWidget();
   SocketWindow->setWindowTitle("ddd - Socket Interface");
-  
+ 
   // Edit box for IP Address  
   IPAddress = new QLineEdit(SocketWindow);
@@ -197,5 +204,5 @@
   SocketOutput->setMaximumBlockCount(MAX_OUTPUT_LINES);
   SocketOutput->setToolTip("Output of socket server");
-  
+
   // Layout of all widgets
   SocketLayout = new QGridLayout(SocketWindow);
@@ -204,5 +211,44 @@
   SocketLayout->addWidget(Connect, 0, 3);
   SocketLayout->addLayout(CommandLayout, 1, 0, 1, 4);
-  SocketLayout->addWidget(SocketOutput, 2, 0, 4, 4);  
+  SocketLayout->addWidget(SocketOutput, 2, 0, 4, 4);
+
+  //-----------------------------------------------------------------------
+  //**************************** M0 window ****************************
+  //-----------------------------------------------------------------------
+   
+  M0Window = new QWidget();
+  M0Window->setWindowTitle("ddd - M0 Display");
+
+  Graph2D = new QwtPlot(M0Window);
+  Graph2D->setAutoReplot(true);
+  Graph2D->setCanvasBackground(QColor(Qt::white));
+
+  M0Layout = new QGridLayout(M0Window);
+  M0Layout->addWidget(Graph2D, 1,1,3,3);
+
+  Signal2D = new QwtPlotSpectrogram;
+  Signal2D->attach(Graph2D);
+
+  //initialize raster
+  double z[6][6];
+  for (int i=0; i<6; i++){
+      for (int j=0; j<6; j++){
+	  z[i][j]=i+j;
+      }
+  }
+  Signal2D->setData(SpectrogramDataM0(z));
+
+  colorMap = QwtLinearColorMap(Qt::yellow, Qt::red);  
+  Signal2D->setColorMap(colorMap);
+
+  //Graph2D->axisWidget(QwtPlot::yRight)->setTitle("Yo!");
+  Graph2D->axisWidget(QwtPlot::yRight)->setColorBarEnabled(true);
+  Graph2D->axisWidget(QwtPlot::yRight)->setColorMap(Signal2D->data().range(),Signal2D->colorMap());
+
+  Graph2D->setAxisScale(QwtPlot::yRight,Signal2D->data().range().minValue(),Signal2D->data().range().maxValue());
+  Graph2D->enableAxis(QwtPlot::yRight);
+  Graph2D->plotLayout()->setAlignCanvasToScales(true);
+  Graph2D->replot();
+
 }
 
@@ -210,4 +256,5 @@
   // Qwt items
   delete Grid;			delete Signal;
+  delete Signal2D;
   // Layout items
   delete PortLayout;		delete CommandLayout;
@@ -216,4 +263,5 @@
   // Other items 		
   delete SocketWindow;
+  delete M0Window;
   delete PixMap;		delete RD;
 }
Index: tools/ddd/GUI.h
===================================================================
--- tools/ddd/GUI.h	(revision 58)
+++ tools/ddd/GUI.h	(revision 59)
@@ -10,4 +10,9 @@
 #include <qwt_plot_zoomer.h>
 #include <qwt_plot_panner.h>
+#include <qwt_plot_spectrogram.h>
+#include <qwt_raster_data.h>
+#include <qwt_scale_widget.h>
+#include <qwt_plot_layout.h>
+#include <qwt_color_map.h>
 
 #include "../../drsdaq/RawDataCTX.h"
@@ -22,6 +27,6 @@
 class ddd : public QMainWindow {
     Q_OBJECT
-    
-    QPushButton *GetButton, *SocketButton, *Connect;
+
+    QPushButton *GetButton, *SocketButton, *Connect, *M0Display;
     QCheckBox *ContinuousBox;
     QToolButton *LoadButton;
@@ -31,15 +36,17 @@
     QTabWidget *TabWidget;
     QTcpSocket *Socket;
-    QWidget *SocketWindow, *Central;
+    QWidget *SocketWindow, *Central, *M0Window;
     QAction *OpenAction, *ConnectAction;
-    QGridLayout *SocketLayout, *MainLayout;
+    QGridLayout *SocketLayout, *MainLayout, *M0Layout;
     QFormLayout *CommandLayout, *PortLayout, *AddressLayout, *FormLayout, *SpinLayout;
     
-    QwtPlot *Graph;
+    QwtPlot *Graph, *Graph2D;
     QwtPlotZoomer *Zoomer;
     QwtPlotCurve *Signal;
     QwtPlotPanner *Panner;
     QwtPlotGrid *Grid;
-
+    QwtPlotSpectrogram *Signal2D;
+    QwtLinearColorMap colorMap;
+    
     void closeEvent(QCloseEvent *); 
 
@@ -58,4 +65,5 @@
     void FileDialog();
     void OpenSocketWindow();
+    void OpenM0Window();
     void GetSignalFromSocket();
     void MakeConnection();
@@ -71,2 +79,45 @@
 };
 
+//class for 2D spectrogram data
+class SpectrogramDataM0: public QwtRasterData {
+
+private:
+
+    double _z[6][6];
+    double _zmin;
+    double _zmax;
+
+public:
+    
+    SpectrogramDataM0(const double z[6][6]): QwtRasterData(QwtDoubleRect(0, 0, 6, 6)) {
+	for (int i = 0; i<6; i++){
+	  for (int j = 0; j<6; j++){
+	      _z[i][j] = z[i][j];
+	      if (z[i][j] > _zmax) _zmax = z[i][j];
+	      if (z[i][j] < _zmin) _zmin = z[i][j];
+	   }
+	}
+    }
+
+    virtual QwtRasterData *copy() const {
+	return new SpectrogramDataM0(_z);
+    }
+
+    virtual QwtDoubleInterval range() const {
+        return QwtDoubleInterval(_zmin, _zmax);
+    }
+
+    virtual void initRaster(const QwtDoubleRect = QwtDoubleRect(0, 0, 6, 6),
+			    const QSize =QSize(1,1)) {};	 
+	 	
+    virtual double value(double x, double y) const {
+
+	unsigned int first = (unsigned int)x;
+	unsigned int second = (unsigned int)y;
+
+	const double v = _z[first][second];
+        return v;
+
+    }
+
+};
