Index: trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc	(revision 1583)
@@ -16,8 +16,8 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2002
 !
 !
Index: trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1583)
@@ -211,9 +211,14 @@
 
     *fLog << "Exclude: ";
+
     // Boolean bexcludepix[iMAXNUMPIX];
     for (int i=0; i<iMAXNUMPIX; i++)
-        if (outpars.bdontusepix[i])
+        if (outpars.bexcludepix[i])
+        {
             *fLog << i << " ";
+            fBlinds->SetPixelBlind(i);
+        }
     *fLog << endl;
+
     /* bexcludepix[] is set TRUE (== exclude from pedestal, Laser
      * calibration and the further analysis) when the Mean value
@@ -254,10 +259,9 @@
     // float fypointcorr_deg; // pointing correction (to be added along the camera y axis) e.g. from point run */
     *fLog << "Pointing correction: dx=" << outpars.fxpointcorr_deg << "deg  ";
-    *fLog << "dy=" << outpars.fxpointcorr_deg << "deg" << endl;
-
-    /*
-     fSrcPos->SetXY( outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg(),
-     outpars.fypointcorr_deg/fGeom->GetConvMm2Deg());
-     */
+    *fLog << "dy=" << outpars.fypointcorr_deg << "deg" << endl;
+
+    // FIXME? Is x-y echanged between Mars CT1 geometry and CT1 definition?
+    fSrcPos->SetXY(outpars.fypointcorr_deg/fGeom->GetConvMm2Deg(),
+                   outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg());
 
     /*
@@ -333,6 +337,7 @@
      *         be treated further. */
 
-    if (outpars.bmontecarlo)
-        *fLog << "File is a Monte Carlo file." << endl;
+    *fLog << "File is a ";
+    *fLog << (outpars.bmontecarlo ? "Monte Carlo" : "Real Data");
+    *fLog << " file." << endl;
 
     fIsMcFile = outpars.bmontecarlo==TRUE;
@@ -343,13 +348,21 @@
 // Read CT1 PreProc File Header:
 //
-void MCT1ReadPreProc::ReadHeader()
+Bool_t MCT1ReadPreProc::ReadHeader()
 {
     char cheadertitle[iHEADERTITLELENGTH];
     fIn->read(cheadertitle, iHEADERTITLELENGTH);
 
+    TString s = cheadertitle;
+    TString m = cTITLE_TEMPLATE;
+
+    if (!s.BeginsWith(m(0, m.First('%'))))
+        return kFALSE;
+
     *fLog << cheadertitle << flush;
 
     // cTITLE_TEMPLATE "PREPROC V%f/S%f CT %d RUN %d %d PROCMJD %d\n"
     struct outputpars outpars;
+
+    int dummy;
 
     Float_t fpreprocversion, structversion;
@@ -357,5 +370,5 @@
            &fpreprocversion,    &structversion,
            &outpars.itelescope, &outpars.irunnum,
-           &outpars.eruntype,   &outpars.iproc_mjdate);
+           &dummy/*&outpars.eruntype*/,   &outpars.iproc_mjdate);
 
     if (STRUCT_VERSION != structversion)
@@ -369,17 +382,33 @@
 
     ProcessHeader(outpars);
-}
-
-void MCT1ReadPreProc::ReadFooter()
+
+    return kTRUE;
+}
+
+Bool_t MCT1ReadPreProc::ReadFooter()
 {
     char cheadertitle[iHEADERTITLELENGTH];
     fIn->read(cheadertitle, iHEADERTITLELENGTH);
     /*
-     ssscanf(cheadertitle, cEND_EVENTS_TEMPLATE,
-             &filterres.ifilter_passed_evts);
+     sscanf(cheadertitle, cEND_EVENTS_TEMPLATE,
+     &filterres.ifilter_passed_evts);
      */
 
+    TString s = cheadertitle;
+    TString m = cEND_EVENTS_TEMPLATE;
+    Int_t p = m.First('%');
+
+    if (!s.BeginsWith(m(0,p)))
+        return kFALSE;
+
+    *fLog << inf << cheadertitle << flush;
+
     struct filterresults filterres;
+<<<<<<< MCT1ReadPreProc.cc
+    fIn->read(&filterres, sizeof(struct filterresults));
+
+=======
     fIn->read((Byte_t*)&filterres, sizeof(struct filterresults));
+>>>>>>> 1.2
     /*
      int   imax_alt_arcs;            // maximum altitude reached during the run
@@ -398,4 +427,6 @@
      float fstddev_event_rate_hz;    // standard deviation of the rate before filtering
      */
+
+    return kTRUE;
 }
 
@@ -441,31 +472,44 @@
 
     *fLog << inf << "-----------------------------------------------------------------------" << endl;
-    const Int_t sizef = sizeof(struct filterresults)+iHEADERTITLELENGTH;
-    const Int_t sizeh = sizeof(struct outputpars)   +iHEADERTITLELENGTH;
-
-    fIn->seekg(0, ios::end);
-    const Int_t filesize = fIn->tellg();
-
-    fIn->seekg(filesize-sizef, ios::beg);
-    ReadFooter();
-    fIn->seekg(0, ios::beg);
-    ReadHeader();
-
-    struct eventrecord event;
-    const int size1   = sizeof(event)-sizeof(event.spixsig_10thphot);
-    const int size2   = sizeof(event.spixsig_10thphot[0])*fNumPixels;
-    const int evtsize = size1+size2;
-
-    *fLog << "Storage for events: " << filesize-sizef-sizeh << "b" << endl;
-    *fLog << "Size of one Event:  " << evtsize << "b" << endl;
-
-    fNumEvents = (filesize-sizef-sizeh)/evtsize-1;
-    fNumEvent = 0;
-
-    *fLog << "Calculated Number of Events: " << (float)(filesize-sizef-sizeh)/evtsize << " " <<  (filesize-sizef-sizeh)%evtsize << endl;
-
-    *fLog << "-----------------------------------------------------------------------" << endl;
-
-    return kTRUE;
+
+    //*fLog << "File contains " << GetNumEvents() << " events." << endl;
+
+    Bool_t rc = ReadHeader();
+
+    if (!rc)
+        *fLog << warn << "Unable to read header... skipping file." << endl;
+
+    return rc;
+}
+
+Int_t MCT1ReadPreProc::GetNumEvents()
+{
+    Int_t n = 0;
+
+    while (!fIn->eof())
+    {
+        if (fIn->get()!=cEND_EVENTS_TEMPLATE[0])
+            continue;
+
+        char cheadertitle[iHEADERTITLELENGTH];
+        fIn->read(cheadertitle, iHEADERTITLELENGTH-1);
+
+        TString s = cheadertitle;
+        TString m = cEND_EVENTS_TEMPLATE;
+        Int_t p = m.First('%');
+
+        if (!s.BeginsWith(m(1,p-1)))
+            continue;
+
+        int num;
+
+        sscanf(cheadertitle, &cEND_EVENTS_TEMPLATE[1], &num);
+
+        n += num;
+    }
+
+    fIn->seekg(0);
+
+    return n;
 }
 
@@ -526,10 +570,4 @@
     fMcTrig = (MMcTrig*)pList->FindCreateObj("MMcTrig");
     if (!fMcTrig)
-        return kFALSE;
-
-    //
-    // Try to open at least one (the first) file
-    //
-    if (!OpenNextFile())
         return kFALSE;
 
@@ -549,6 +587,4 @@
      int   isecfrac_200ns;     // fractional part of isecs_since_midday
      short snot_ok_flags;      // the bits in these two bytes are flags for additional information on the event: Everything OK =: all Bits = 0
-     int   ialt_arcs;          // altitude (arcseconds)
-     int   iaz_arcs;           // azimuth (arcseconds)
      int   ipreproc_alt_arcs;  // "should be" alt according to preproc (arcseconds)
      int   ipreproc_az_arcs;   // "should be" az according to preproc (arcseconds)
@@ -573,6 +609,4 @@
     /*
      *fLog << event.isecs_since_midday << "s ";
-     *fLog << event.ialt_arcs << "s ";
-     *fLog << event.iaz_arcs << "s ";
      *fLog << event.ipreproc_alt_arcs << "s ";
      *fLog << event.ipreproc_az_arcs << "s ";
@@ -597,4 +631,7 @@
     }
 
+    fMcEvt->SetTheta(TMath::Pi()*(0.5-1./180*event.ialt_arcs/3600));   // altitude (arcseconds)
+    fMcEvt->SetPhi(TMath::Pi()/180*event.iaz_arcs/3600);               // azimuth (arcseconds)
+
     if (!fIsMcFile)
         return;
@@ -611,4 +648,68 @@
 // --------------------------------------------------------------------------
 //
+// Because of the file format of the preproc output we have to check at any
+// event where in the file stream we are...
+//
+Bool_t MCT1ReadPreProc::CheckFilePosition()
+{
+    //
+    // Means: If no file is open (first call) try to open the first file
+    //
+    if (!fIn)
+        return kFALSE;
+
+    //
+    // If the first character isn't the first of the footer it must be
+    // an event
+    //
+    if (fIn->peek()!=cEND_EVENTS_TEMPLATE[0])
+        return kTRUE;
+
+    //
+    // Remember the current position if the first character faked a
+    // footer
+    //
+    const Int_t pos = fIn->tellg();
+
+    //
+    // Try reading the footer. If it isn't succefull jump back...
+    // must be an event
+    //
+    if (!ReadFooter())
+    {
+        fIn->seekg(pos, ios::beg);
+        return kTRUE;
+    }
+
+    *fLog << inf << "Footer found." << endl;
+
+    //
+    // No after reading the footer check if we reached the end of the file
+    //
+    if (fIn->eof())
+    {
+        *fLog << "End of file." << endl;
+        return kFALSE;
+    }
+
+    //
+    // If the eof isn't reached a new header must follow. Check for it.
+    //
+    if (fIn->peek()!=cTITLE_TEMPLATE[0])
+    {
+        *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl;
+        return kFALSE;
+    }
+
+    *fLog << "-----------------------------------------------------------------------" << endl;
+    if (ReadHeader())
+        return kTRUE;
+
+    *fLog << inf << "Error reading run header in file... skipping rest of file." << endl;
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Check for the event number and depending on this number decide if
 // pedestals or event data has to be read.
@@ -620,9 +721,10 @@
 {
     //
-    // check if we are done. Try to open the next file in chain.
-    // If it was possible start reading. If not break the event loop
-    //
-    if (fNumEvent++==fNumEvents-1)
-        return OpenNextFile() ? kCONTINUE : kFALSE;
+    // Check where in the file we are. If neither a new event, nor a
+    // footer/header combination is detected go to the next file.
+    //
+    if (!CheckFilePosition())
+        if (!OpenNextFile())
+            return kFALSE;
 
     // event data to be read from the file
@@ -637,4 +739,6 @@
     ProcessEvent(event);
 
+    fNumEvent++;
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1583)
@@ -39,9 +39,12 @@
     Bool_t OpenNextFile();
 
-    void ReadPedestals();
-    void ReadHeader();
-    void ReadFooter();
-    void ProcessHeader(const struct outputpars &outpars);
-    void ProcessEvent(const struct eventrecord &event);
+    Int_t  GetNumEvents();
+
+    void   ReadPedestals();
+    Bool_t ReadHeader();
+    Bool_t ReadFooter();
+    Bool_t CheckFilePosition();
+    void   ProcessHeader(const struct outputpars &outpars);
+    void   ProcessEvent(const struct eventrecord &event);
 
 public:
Index: trunk/MagicSoft/Mars/mfileio/MChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MChain.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MChain.cc	(revision 1583)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
Index: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1583)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
Index: trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1583)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
Index: trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.cc	(revision 1583)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
Index: trunk/MagicSoft/Mars/mfileio/MWriteFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteFile.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MWriteFile.cc	(revision 1583)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Copyright: MAGIC Software Development, 2000-2002
 !
 !
Index: trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1583)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@uni-sw.gwdg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz  06/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
 !
 !
Index: trunk/MagicSoft/Mars/mfileio/structures.h
===================================================================
--- trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1575)
+++ trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1583)
@@ -102,4 +102,7 @@
   /* file name) */
   enum onoroff eruntype;
+#ifdef LINUX
+  int dummy;
+#endif
   /* indicates if the */
   /* run is on- or off source (from runfile cross checked with */
@@ -122,5 +125,5 @@
   float   fpixdiameter_deg;
   /* smallest pixel diameter (degrees) (from parameters file) */ 
-  axes ese1_is;
+  enum axes ese1_is;
   /* name of the axis to which shaft encoder 1 is attached */
   /* (implies the type of mount) */
@@ -218,4 +221,7 @@
   /* tracking mode (for ALT/AZ CTs) */
   int     iproc_evts;
+#ifdef LINUX
+  int dummy2;
+#endif
   /* number of events processed */
   double  dactual_sourcera_hours;
@@ -867,6 +873,4 @@
   /* y position relative to the central CT for each CT */
 }; 
-
-
 #endif
 
