Index: drsdaq/DAQReadout.cc
===================================================================
--- drsdaq/DAQReadout.cc	(revision 63)
+++ drsdaq/DAQReadout.cc	(revision 68)
@@ -15,5 +15,5 @@
 
 static const char* daq_state_str[] = {"active", "stopped"};
-static const char* daq_runtype_str[] = {"data", "pedestal", "test"};
+static const char* daq_runtype_str[] = {"data", "pedestal", "reserved", "test"};
 
 static const struct CL_Struct { const char *Name;    
@@ -121,9 +121,12 @@
   drs->InitialScan();
 
+  // Allocate headers and initialise to zero
   RHeader = new RunHeader;
+  memset(RHeader, 0, sizeof(RunHeader));
   EHeader = new EventHeader;
+  memset(EHeader, 0, sizeof(EventHeader));
+  
+  // Scan for DRS boards
   DRSFreq = new float [drs->GetNumberOfBoards()];
-
-  // Scan for DRS boards
   if (drs->GetNumberOfBoards()==0) PrintMessage("No DRS boards found - check VME crate and configuration file!\n");
 
@@ -139,4 +142,6 @@
   }
   BStruct  = new BoardStructure [NumBoards == 0 ? 1:drs->GetNumberOfBoards()];
+  memset(BStruct, 0, sizeof(BoardStructure)*(NumBoards == 0 ? 1:drs->GetNumberOfBoards()));
+
   WaveForm = new short [NumBoards == 0 ? 1:NumBoards][kNumberOfChips][kNumberOfChannels][kNumberOfBins];
   TriggerCell = new int [NumBoards == 0 ? 1:NumBoards][kNumberOfChips] ();  // Zero initialised
@@ -877,7 +882,10 @@
   char RunDate[MAX_COM_SIZE], Buffer[MAX_COM_SIZE];
   
-  // Write run date to status structure
-  time(&rawtime);   timeinfo = localtime(&rawtime);
-  snprintf(RunDate,sizeof(RunDate), "%d%02d%02d",timeinfo->tm_year+1900,timeinfo->tm_mon + 1,timeinfo->tm_mday);
+  // Write run date to status structure (if after 13:00, use next day)
+  time(&rawtime);
+  timeinfo = gmtime(&rawtime);
+  if(timeinfo->tm_hour>=13) rawtime += 12*60*60;
+  timeinfo = gmtime(&rawtime);
+  snprintf(RunDate,sizeof(RunDate),"%d%02d%02d",timeinfo->tm_year+1900,timeinfo->tm_mon + 1,timeinfo->tm_mday);
 
   // Create direcory if not existing (ignore error if already existing) and change to it
@@ -889,6 +897,6 @@
   
   // Generate filename
-  snprintf(FileName,sizeof(FileName),"%s/%s/%s_%.8u_%s_%c_%d.raw", fRawDataPath, RunDate,
-    RunDate,RunNumber,RHeader->Description,daq_runtype_str[daq_runtype][0],FileNumber);
+  snprintf(FileName,sizeof(FileName),"%s/%s/%s_D1_%.8u.%.3u_%c_%s.raw", fRawDataPath, RunDate,
+    RunDate,RunNumber,FileNumber,toupper(daq_runtype_str[daq_runtype][0]),RHeader->Description);
  
   //  Open file with rwx right for owner and group, never overwrite file
@@ -914,4 +922,5 @@
   RHeader->BoardStructureSize = sizeof(BoardStructure);
 
+  RHeader->Identification = IDENTIFICATION;
   RHeader->Type = daq_runtype;
   RHeader->RunNumber  = RunNumber;
@@ -925,4 +934,5 @@
   RHeader->NChips    = kNumberOfChips;
   RHeader->NChannels = kNumberOfChannels;
+  RHeader->NBytes    = sizeof(short);
 
   RHeader->Offset  = fFirstSample;
@@ -1257,5 +1267,5 @@
 
     m->FileNumber += 1; 
-  } while(m->NumEvents<m->NumEventsRequested && !m->Stop && !WriteError);
+  } while((m->NumEvents<m->NumEventsRequested || m->NumEventsRequested==0) && !m->Stop && !WriteError);
 
   // Print run summary to slow data file and to screen
Index: drsdaq/DAQReadout.h
===================================================================
--- drsdaq/DAQReadout.h	(revision 63)
+++ drsdaq/DAQReadout.h	(revision 68)
@@ -19,4 +19,5 @@
 
 #define RUN_NUM_FILE "/ct3data/LastRunNumber"
+
 #define MAX_PATH 256		// also used for filename length
 #define MAX_COM_SIZE 10000
@@ -28,5 +29,5 @@
 
 enum state_enum {active, stopped};
-enum runtype_enum {data, pedestal, test};
+enum runtype_enum {data, pedestal, reserved, test};
 
 class DAQReadout {
Index: drsdaq/History.txt
===================================================================
--- drsdaq/History.txt	(revision 63)
+++ drsdaq/History.txt	(revision 68)
@@ -39,3 +39,6 @@
 16/6/2009   Data is not rotated by copying in memory, but by saving to disk in
     	    correct order using writev() (10% gain in rate)
+18/6/2009   Introduced dummy, zero-initialized elements in raw data format to
+    	    align ordering to MAGIC format. Run date is now calculated with a
+	    change to the next date on 13:00 UTC.
 	    
Index: drsdaq/RawDataCTX.cc
===================================================================
--- drsdaq/RawDataCTX.cc	(revision 63)
+++ drsdaq/RawDataCTX.cc	(revision 68)
@@ -93,4 +93,5 @@
 
     fprintf(fptr, "Description:      %s\n", RHeader->Description);
+    fprintf(fptr, "Identification:   %u\n", RHeader->Identification);
     fprintf(fptr, "Run type:         %u\n", RHeader->Type);
     fprintf(fptr, "Run number:       %u\n", RHeader->RunNumber);
@@ -99,8 +100,9 @@
     fprintf(fptr, "Events:           %u\n", RHeader->Events);
     fprintf(fptr, "Boards:  	     %u\n", RHeader->NBoards);
-    fprintf(fptr, "DRS chips:        %u\n", RHeader->NChips);
+    fprintf(fptr, "Chips/board:      %u\n", RHeader->NChips);
     fprintf(fptr, "Channels/chip:    %u\n", RHeader->NChannels);
     fprintf(fptr, "Samples:          %u\n", RHeader->Samples);
     fprintf(fptr, "Offset:           %u\n", RHeader->Offset);
+    fprintf(fptr, "Bytes/sample:     %u\n", RHeader->NBytes);
 
     fprintf(fptr, "Start second:     %u - UTC %s", RHeader->StartSecond, asctime(gmtime((time_t *) &RHeader->StartSecond)));
Index: drsdaq/RawDataCTX.h
===================================================================
--- drsdaq/RawDataCTX.h	(revision 63)
+++ drsdaq/RawDataCTX.h	(revision 68)
@@ -1,11 +1,11 @@
 /* Data organisation on disk:
 
-                      Board 1      Board 2      ...     Board 1      Board 2      ...
-   RH  BS1 BS2 ... EH C1 C2 C3 ... C1 C2 C3 ... ...  EH C1 C2 C3 ... C1 C2 C3 ... ...
+                                  Board 1      Board 2      ...     Board 1      Board 2      ...
+   RH  BS1 BS2 ... EH TC1 TC2 ... C1 C2 C3 ... C1 C2 C3 ... ...  EH C1 C2 C3 ... C1 C2 C3 ... ...
                    --------------------------------  --------------------------------
                    Event 1                           Event 2
 
-  RH Run header   BSx Board structures   EV Event header   Cx Channel (0-19 for 2 chips)
-  Channel data are written as shorts, lenght of channel data is in the run header
+  RH Run header   BSx Board structures   EV Event header   TCx Trigger cell of chip x (int)
+  Cx Channel (0-19 for 2 chips), Channel data are written as shorts, length of event data is in event header
 
   Structures are defined using #pragma pack (1) to not include any padding. Note that
@@ -15,4 +15,5 @@
   The convention for the header structure is that exisitng structure entries
   should never be deleted. New items may only be added at the end.
+  Items named _res are introduced for compatibility with the MAGIC data format and are set to zero. 
 */
 
@@ -24,4 +25,6 @@
 
 #define DATA_FORMAT 1
+#define IDENTIFICATION 1    // Raw data file identification
+
 
 typedef char I8;
@@ -30,11 +33,12 @@
 typedef float F32;
 
-#define MAGICNUM_OPEN 0xe0e1    // Magic number for run header while file open
-#define MAGICNUM_CLOSED 0xe0e0  //    ... and when file is closed
-#define MAGICNUM_ERROR 0xe0e2   //    ... and when an error occurred
+#define MAGICNUM_OPEN 0xc0c1    // Magic number for run header while file open
+#define MAGICNUM_CLOSED 0xc0c0  //    ... and when file is closed
+#define MAGICNUM_ERROR 0xc0c2   //    ... and when an error occurred
 
 // Error codes
 enum CTX_ErrCode {CTX_OK, CTX_FOPEN, CTX_FCLOSE, CTX_NOTOPEN, CTX_RHEADER,
     	    	  CTX_BSTRUCT, CTX_EHEADER, CTX_DATA, CTX_SEEK, CTX_EOF, CTX_VERSION};
+
 
 #pragma pack (1)  // Switch padding off
@@ -44,5 +48,4 @@
   U32 MagicNum;
   U32 DataFormat;       // Increasing whenever format changes
-  I32 SoftwareRevision;	// Subversion revision number (negative for modified working copy)
 
   U32 RunHeaderSize;
@@ -50,17 +53,28 @@
   U32 BoardStructureSize;
 
-  I8  Description[48];
-  U32 Type;          	// Run type: 0=pedestal, 1=data, 2=test
+  I32 SoftwareRevision;	// Subversion revision number (negative for modified working copy)
 
+  U32 _res1[2];
+  U32 Identification;
+  U32 Type;          	// Run type: 0=data, 1=pedestal, 3=test
   U32 RunNumber;
   U32 FileNumber;
-    
-  U32 Events;           // Number of events in the file 
+
+  I8  Description[100];
+  I8  _res2[140];
+  U32 _res3[6];
+       
   U32 NBoards;	    	// Number of used mezzanine boards
   U32 NChips;		// Number of DRS chips per board
   U32 NChannels;	// Number of channels per chip
+
   U32 Samples;          // Number of samples
-  U32 Offset;           // Offset from first sample
+  U32 Offset;           // Offset from trigger
 
+  U32 Events;           // Number of events in the file
+  U32  _res4;
+  U32 NBytes;
+  I8  _res5[20];
+  
   U32 StartSecond;  	// Opening and closing time of the file
   U32 StartMicrosecond;
@@ -71,4 +85,5 @@
 // Board structure
 typedef struct {
+  I8  _res[17];
   I32 SerialNo;     // Board serial number
   F32 NomFreq;	    // Nominal sampling frequency [GHz]
@@ -82,4 +97,5 @@
   U32 Second;          // Event time stamp (result of gettimeofday())
   U32 Microsecond;
+  U32 _res[4];
   U32 TriggerType;
   U32 EventSize; 	// Size of following data in bytes
Index: drsdaq/SlowData.cc
===================================================================
--- drsdaq/SlowData.cc	(revision 63)
+++ drsdaq/SlowData.cc	(revision 68)
@@ -27,5 +27,8 @@
   InternalCall = false;
   
-  time(&rawtime);   timeinfo = localtime(&rawtime);
+  time(&rawtime);
+  timeinfo = gmtime(&rawtime);
+  if(timeinfo->tm_hour>=13) rawtime += 12*60*60;
+  timeinfo = gmtime(&rawtime);
   snprintf(Filename,sizeof(Filename),"%s/%s_%d%02d%02d.slow",Direcory,Issuer,timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday);
 
@@ -55,5 +58,5 @@
   gettimeofday(&Time, NULL);
   InternalCall = true;
-  NewEntryCalled = AddToEntry("\n%s-%s %lu %lu %d-%d-%dT%d:%d:%d ", Issuer, Variable, Time.tv_sec, Time.tv_usec, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec);
+  NewEntryCalled = AddToEntry("\n%s %s %d %d %d %d %d %d %d %lu %lu", Issuer, Variable, TM->tm_year+1900,TM->tm_mon+1,TM->tm_mday,TM->tm_hour,TM->tm_min,TM->tm_sec, Time.tv_usec/1000, Time.tv_sec, Time.tv_usec);
   InternalCall = false;
   return NewEntryCalled;
