Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 4755)
+++ trunk/MagicSoft/Mars/Changelog	(revision 4756)
@@ -29,5 +29,4 @@
        been set (e.g. by the macro).
 
-   
 
 
@@ -36,4 +35,5 @@
    * Makefile:
      - added comments how to link statically
+     - added star again
 
    * callisto.cc: 
@@ -69,4 +69,31 @@
        instead of accesing the arrays many times inside the loops.
        Somebody should do the same for logain.
+
+   * mraw/MRawEvtData.cc:
+     - fixed a bug in InitArrays
+
+   * showlog.cc:
+     - added some more functionality
+
+   * star.cc:
+     - changed to use new MJStar
+
+   * mfileio/MChain.cc:
+     - added namespace
+
+   * mfileio/MReadTree.cc:
+     - added a call to ResetTree as first call in PreProcess. Using
+       MReadReports with a tree missing in the file mysteriously
+       crashed because TChain::fTreeNumber was set already by
+       a root-miracle.
+
+   * mjobs/JobsLinkDef.h, mjobs/Makefile:
+     - added MJStar
+
+   * mjobs/MJCalibrateSignal.cc:
+     - replaced MReadMarsFile by MReadReports
+
+   * mmain/MEventDisplay.cc:
+     - fixed reading of resource file
 
 
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 4755)
+++ trunk/MagicSoft/Mars/Makefile	(revision 4756)
@@ -21,5 +21,5 @@
 
 #PROGRAMS = readraw merpp mars test mona status
-PROGRAMS = readdaq readraw merpp mars mona showlog callisto showplot
+PROGRAMS = readdaq readraw merpp mars mona showlog callisto showplot star
 SOLIB    = libmars.so
 CINT     = M
Index: trunk/MagicSoft/Mars/mfileio/MChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MChain.cc	(revision 4755)
+++ trunk/MagicSoft/Mars/mfileio/MChain.cc	(revision 4756)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
@@ -24,13 +24,15 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MChain                                                                  //
-//                                                                         //
-// Helper class for MReadTree                                              //
-//                                                                         //
+//
+// MChain
+//
+// Helper class for MReadTree
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MChain.h"
 
 ClassImp(MChain);
+
+using namespace std;
 
 Int_t MChain::LoadTree(Int_t entry)
Index: trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 4755)
+++ trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 4756)
@@ -609,4 +609,13 @@
 
     //
+    // It seems, that TFile and TTree are not completely independant if
+    // many times the same file is openes (MReadReports) and some of
+    // the files in the chains don't have one tree. TChain::fTreeNumber
+    // is already set before LoadTree from GetFile is called and
+    // it crashes. ResetTree makes sure, that the tree number is -1
+    //
+    fChain->ResetTree();
+
+    //
     // check for files and for the tree!
     //
Index: trunk/MagicSoft/Mars/mjobs/MJStar.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 4756)
+++ trunk/MagicSoft/Mars/mjobs/MJStar.cc	(revision 4756)
@@ -0,0 +1,211 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MJStar
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MJStar.h"
+
+#include <TEnv.h>
+#include <TFile.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MDirIter.h"
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MStatusDisplay.h"
+
+#include "MHCamEvent.h"
+
+#include "MReadMarsFile.h"
+#include "MGeomApply.h"
+#include "MImgCleanStd.h"
+#include "MHillasCalc.h"
+#include "MFillH.h"
+#include "MWriteRootFile.h"
+
+ClassImp(MJStar);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
+//
+MJStar::MJStar(const char *name, const char *title) 
+{
+    fName  = name  ? name  : "MJStar";
+    fTitle = title ? title : "Standard analysis and reconstruction";
+}
+
+Bool_t MJStar::WriteResult()
+{
+    if (fPathOut.IsNull())
+    {
+        *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
+        return kTRUE;
+    }
+
+    const TString oname = Form("%s/star%06d.root", (const char*)fPathOut, fSequence.GetSequence());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "RECREATE");
+
+    *fLog << inf << " - MStatusDisplay..." << flush;
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
+        return kFALSE;
+    }
+    *fLog << inf << "ok." << endl;
+
+    return kTRUE;
+}
+
+Bool_t MJStar::ProcessFile()
+{
+    if (!fSequence.IsValid())
+    {
+        *fLog << err << "ERROR - Sequence invalid!" << endl;
+        return kFALSE;
+    }
+
+    //if (!CheckEnv())
+    //    return kFALSE;
+
+    CheckEnv();
+
+    // --------------------------------------------------------------------------------
+
+    *fLog << inf;
+    fLog->Separator(GetDescriptor());
+    *fLog << "Calculate image parameters from sequence ";
+    *fLog << fSequence.GetName() << endl;
+    *fLog << endl;
+
+    // --------------------------------------------------------------------------------
+
+    MDirIter iter;
+    const Int_t n0 = fSequence.SetupDatRuns(iter, fPathData);
+    const Int_t n1 = fSequence.GetNumDatRuns();
+    if (n0==0)
+    {
+        *fLog << err << "ERROR - No input files of sequence found!" << endl;
+        return kFALSE;
+    }
+    if (n0!=n1)
+    {
+        *fLog << err << "ERROR - Number of files found (" << n0 << ") doesn't match number of files in sequence (" << n1 << ")" << endl;
+        return kFALSE;
+    }
+
+    // Setup Parlist
+    MParList plist;
+    plist.AddToList(this); // take care of fDisplay!
+
+    // Setup Tasklist
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MReadMarsFile read("Events");
+    read.DisableAutoScheme();
+    read.AddFiles(iter);
+    //read.AddFiles(fnamein);
+
+    MGeomApply             apply; // Only necessary to craete geometry
+    //MBadPixelsMerge        merge(&badpix);
+    MImgCleanStd           clean; 
+    MHillasCalc            hcalc;
+
+    MHCamEvent evt0("Cleaned");
+    evt0.SetType(0);
+    MFillH fill0(&evt0, "MCerPhotEvt",            "FillCerPhotEvt");
+    MFillH fill1("MHHillas",      "MHillas",      "FillHillas");
+    MFillH fill2("MHHillasExt",   "MHillasExt",   "FillHillasExt");
+    MFillH fill3("MHHillasSrc",   "MHillasSrc",   "FillHillasSrc");
+    MFillH fill4("MHImagePar",    "MImagePar",    "FillImagePar");
+    MFillH fill5("MHNewImagePar", "MNewImagePar", "FillNewImagePar");
+    MFillH fill6("MHCerPhot");
+
+    MWriteRootFile write(2, "images/{s/_Y_/_I_}");
+    write.AddContainer("MMcEvt",        "Events", kFALSE);
+    write.AddContainer("MHillas",       "Events");
+    write.AddContainer("MHillasExt",    "Events");
+    write.AddContainer("MHillasSrc",    "Events");
+    write.AddContainer("MImagePar",     "Events");
+    write.AddContainer("MNewImagePar",  "Events");
+    write.AddContainer("MTime",         "Events");
+    write.AddContainer("MRawEvtHeader", "Events");
+    write.AddContainer("MRawRunHeader", "RunHeaders");
+    write.AddContainer("MBadPixelsCam", "RunHeaders");
+    write.AddContainer("MGeomCam",      "RunHeaders");
+    //write.AddContainer("MObservatory", "RunHeaders");
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&apply);
+    tlist.AddToList(&clean);
+    tlist.AddToList(&fill0);
+    tlist.AddToList(&hcalc);
+    tlist.AddToList(&fill1);
+    tlist.AddToList(&fill2);
+    tlist.AddToList(&fill3);
+    tlist.AddToList(&fill4);
+    tlist.AddToList(&fill5);
+    //tlist.AddToList(&fill6);
+    tlist.AddToList(&write);
+
+    // Create and setup the eventloop
+    MEvtLoop evtloop(fName);
+    evtloop.SetParList(&plist);
+    evtloop.SetDisplay(fDisplay);
+    evtloop.SetLogStream(fLog);
+    if (!SetupEnv(evtloop))
+        return kFALSE;
+
+    // Execute first analysis
+    if (!evtloop.Eventloop(fMaxEvents))
+    {
+        *fLog << err << GetDescriptor() << ": Failed." << endl;
+        return kFALSE;
+    }
+
+    tlist.PrintStatistics();
+
+    if (!WriteResult())
+        return kFALSE;
+
+    *fLog << all << GetDescriptor() << ": Done." << endl;
+    *fLog << endl << endl;
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mjobs/MJStar.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJStar.h	(revision 4756)
+++ trunk/MagicSoft/Mars/mjobs/MJStar.h	(revision 4756)
@@ -0,0 +1,21 @@
+#ifndef MARS_MJStar
+#define MARS_MJStar
+
+#ifndef MARS_MJob
+#include "MJob.h"
+#endif
+
+class MJStar : public MJob
+{
+private:
+    Bool_t WriteResult();
+
+public:
+    MJStar(const char *name=NULL, const char *title=NULL);
+
+    Bool_t ProcessFile();
+
+    ClassDef(MJStar, 0) // Tool to create a pedestal file (MPedestalCam)
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mmain/MEventDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 4755)
+++ trunk/MagicSoft/Mars/mmain/MEventDisplay.cc	(revision 4756)
@@ -37,4 +37,5 @@
 #include <TStyle.h>              // gStyle->SetOptStat
 #include <TCanvas.h>             // TCanvas::cd
+#include <TSystem.h>             // TSystem::BaseName
 
 //
@@ -245,9 +246,4 @@
         plist->AddToList(ccam);
 
-    fEvtLoop = new MEvtLoop;
-    fEvtLoop->SetOwner();
-    fEvtLoop->SetParList(plist);
-    fEvtLoop->ReadEnv("mars.rc");
-
     MHEvent *evt01 = new MHEvent(MHEvent::kEvtSignalRaw);
     MHEvent *evt02 = new MHEvent(MHEvent::kEvtSignalRaw);
@@ -391,5 +387,10 @@
     // Now distribute Display to all tasks
     //
-    tlist->SetDisplay(this);
+    fEvtLoop = new MEvtLoop(Form("Mars %s", gSystem->BaseName(fname)));
+    fEvtLoop->SetOwner();
+    fEvtLoop->SetParList(plist);
+    fEvtLoop->SetDisplay(this);
+    fEvtLoop->ReadEnv("mars.rc");
+
 }
 
Index: trunk/MagicSoft/Mars/showlog.cc
===================================================================
--- trunk/MagicSoft/Mars/showlog.cc	(revision 4755)
+++ trunk/MagicSoft/Mars/showlog.cc	(revision 4756)
@@ -2,5 +2,8 @@
 #include <fstream>
 
+#include "MArgs.h"
+
 #include "MLog.h"
+#include "MLogManip.h"
 
 using namespace std;
@@ -10,10 +13,15 @@
     gLog << endl;
     gLog << "Sorry the usage is:" << endl;
-    gLog << "   showlog filename" << endl;
+    gLog << "   showlog [options] filename" << endl;
     gLog << " or" << endl;
-    gLog << "   showlog < filename" << endl << endl;
-    gLog << " This program converts colored output made with ansi codes" << endl;
-    gLog << " (like it is done by MLog) and redirected into a file back" << endl;
+    gLog << "   showlog [options] < filename" << endl << endl;
+    gLog << "   -?, -h, --help            This help" << endl << endl;
+    gLog << endl;
+    gLog << " This program converts colored output  made with ansi codes" << endl;
+    gLog << " (like it is done by MLog)  and redirected into a file back" << endl;
     gLog << " into colored output." << endl << endl;
+    gLog << " It cannot be used to get rid of the Ansi codes. To display" << endl;
+    gLog << " colored output with less use the option -R, eg." << endl;
+    gLog << "   less -R logfile.log" << endl << endl;
 }
 
@@ -22,5 +30,23 @@
 int main(int argc, char **argv)
 {
-    if (argc>2)
+    MArgs arg(argc, argv);
+
+    if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
+    {
+        Usage();
+        return -1;
+    }
+
+    if (arg.GetNumOptions()>0)
+    {
+        gLog << warn << "WARNING - Unknown commandline options..." << endl;
+        arg.Print("options");
+        gLog << endl;
+    }
+
+    //
+    // check for the right usage of the program
+    //
+    if (arg.GetNumArguments()>1)
     {
         Usage();
@@ -29,8 +55,8 @@
 
     // casts necessary for gcc 2.95.3
-    istream *in = argc==2 ? (istream*)new ifstream(argv[1]) : (istream*)&cin;
+    istream *in = arg.GetNumArguments()==1 ? (istream*)new ifstream(arg.GetArgumentStr(0)) : (istream*)&cin;
     if (!*in)
     {
-        gLog << "Cannot open file " << argv[1] << ": " << strerror(errno) << endl;
+        gLog << "Cannot open file " << arg.GetArgumentStr(0) << ": " << strerror(errno) << endl;
         return -1;
     }
Index: trunk/MagicSoft/Mars/star.cc
===================================================================
--- trunk/MagicSoft/Mars/star.cc	(revision 4755)
+++ trunk/MagicSoft/Mars/star.cc	(revision 4756)
@@ -1,40 +1,21 @@
+#include <TROOT.h>
+#include <TClass.h>
 #include <TSystem.h>
-
-#include "MParList.h"
-#include "MTaskList.h"
-#include "MEvtLoop.h"
-/*'
+#include <TGClient.h>
+#include <TApplication.h>
+
 #include "MLog.h"
- */
 #include "MLogManip.h"
 
 #include "MArgs.h"
-
 #include "MArray.h"
-#include "MReadMarsFile.h"
-#include "MGeomApply.h"
-#include "MMcPedestalCopy.h"
-#include "MMcPedestalNSBAdd.h"
-#include "MCerPhotCalc.h"
-#include "MCerPhotAnal2.h"
-#include "MSigmabarCalc.h"
-#include "MImgCleanStd.h"
-#include "MHillasCalc.h"
-#include "MHillasSrcCalc.h"
-#include "MWriteRootFile.h"
-#include "MFDataMember.h"
-#include "MFillH.h"
-#include "MReportDrive.h"    // PRELIMINARY:
-//#include "MPointingPos.h"    // PRELIMINARY:
-//#include "MPointingPosCalc.h"
+#include "MDirIter.h"
+
+#include "MStatusDisplay.h"
+
+#include "MSequence.h"
+#include "MJStar.h"
 
 using namespace std;
-
-//////////////////////////////////////////////////////////////////////////////
-//
-// This is an easy implementation of the Star process
-// (as compilable prog)
-//
-//////////////////////////////////////////////////////////////////////////////
 
 static void StartUpMessage()
@@ -42,12 +23,12 @@
     gLog << all << endl;
 
-    //                1         2         3         4         5
-    //       12345678901234567890123456789012345678901234567890
-    gLog << "==================================================" << endl;
-    gLog << "                 STAR - MARS V" << MARSVER          << endl;
-    gLog << "   MARS - STandard Analysis and Reconstruction"     << endl;
-    gLog << "            Compiled on <" << __DATE__ << ">"       << endl;
-    gLog << "               Using ROOT v" << ROOTVER             << endl;
-    gLog << "==================================================" << endl;
+    //                1         2         3         4         5         6
+    //       123456789012345678901234567890123456789012345678901234567890
+    gLog << "========================================================" << endl;
+    gLog << "                   Star - MARS V" << MARSVER              << endl;
+    gLog << "      MARS -- STandard Analysis and Reconstruction"       << endl;
+    gLog << "               Compiled on <" << __DATE__ << ">"          << endl;
+    gLog << "                  Using ROOT v" << ROOTVER                << endl;
+    gLog << "========================================================" << endl;
     gLog << endl;
 }
@@ -55,223 +36,32 @@
 static void Usage()
 {
+    //                1         2         3         4         5         6         7         8
+    //       12345678901234567890123456789012345678901234567890123456789012345678901234567890
     gLog << all << endl;
     gLog << "Sorry the usage is:" << endl;
-    gLog << "   star [-a0] [-vn] [-cn] inputfile[.root] outputfile[.root]" << endl << endl;
-    gLog << "     input file: Merpped or MC root file." << endl;
-    gLog << "     ouput file: Star-file (image parameter file)" << endl;
-    gLog << "     -a0: Do not use Ansii codes." << endl;
-    gLog << "     -cn: Compression level n=1..9 [default=2]" << endl;
-    gLog << "     -vn: Verbosity level n [default=2]" << endl;
-    gLog << "     -u1: Update File (instead of Recreate)" << endl;
-    gLog << "     -tn: Telescope Serial Number n [default=0]" << endl << endl;
-    gLog << " -> Further setup is not possible at the moment, please use" << endl;
-    gLog << "    the star.C root macro instead. Using an input card will" << endl;
-    gLog << "    be implemented in the future." << endl << endl;
+    gLog << " star [options] sequence.txt" << endl << endl;
+    gLog << " Arguments:" << endl;
+    gLog << "   sequence.txt:             An ascii file defining a sequence of runs" << endl;
+    gLog << " Root Options:" << endl;
+    gLog << "   -b                        Batch mode (no graphical output to screen)" << endl<<endl;
+    gLog << " Options:" << endl;
+    gLog.Usage();
+    gLog << "   --debug-env               Debug setting resources from file" << endl << endl;
+    gLog << endl;
+    gLog << "   -f                        Force overwrite of existing files" << endl;
+    gLog << "   -ff                       Force execution if not all files found" << endl;
+    gLog << "   --ind=path                Path where to search for the calibrated data (Y)" << endl;
+    gLog << "                             [default=standard path in datacenter]" << endl;
+    gLog << "   --out=path                Path to write the all results to [def=local path]" << endl;
+    gLog << "                             (overwrites --outc and --outy)" << endl;
+    gLog << "   --print-seq               Print Sequence information" << endl;
+    gLog << "   --print-files             Print Files taken from Sequence" << endl;
+    gLog << "   --print-only              Do not excute anything except print" << endl;
+    gLog << "   --config=star.rc          Resource file [default=star.rc]" << endl;
+    gLog << endl;
+    gLog << "   -?, -h, --help            This help" << endl << endl;
 }
 
-class MJStar : public MParContainer
-{
-private:
-    TString fInputFile;
-    TString fOutputFile;
-
-    Bool_t fIsUpdate;
-    Byte_t fComprLevel;
-
-    Byte_t fSerialIdx;
-
-    Bool_t CheckFiles()
-    {
-        if (fOutputFile.IsNull())
-        {
-            fOutputFile = fInputFile;
-
-            if (fOutputFile.EndsWith(".raw"))
-                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
-
-            if (fOutputFile.EndsWith(".rep"))
-                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
-
-            if (fOutputFile.EndsWith(".txt"))
-                fOutputFile = fOutputFile(0, fOutputFile.Length()-4);
-        }
-
-        if (fInputFile.IsNull())
-        {
-            *fLog << err << "Sorry, no input file." << endl;
-            return kFALSE;
-        }
-
-        if (fOutputFile.IsNull())
-        {
-            *fLog << err << "Sorry, no output file." << endl;
-            return kFALSE;
-        }
-
-        if (!fInputFile.EndsWith(".root"))
-            fInputFile += ".root";
-
-        if (!fOutputFile.EndsWith(".root"))
-            fOutputFile += ".root";
-
-        //
-        // check whether the given files are OK.
-        //
-        if (gSystem->AccessPathName(fInputFile, kFileExists))
-        {
-            *fLog << err << "Sorry, the input file '" << fInputFile << "' doesn't exist." << endl;
-            return kFALSE;
-        }
-
-        if (!gSystem->AccessPathName(fOutputFile, kFileExists))
-        {
-            if (fIsUpdate)
-                gLog << warn << "Warning: File doesn't '" << fOutputFile << "' exist... recreating." << endl;
-        }
-
-        if (fIsUpdate || gSystem->AccessPathName(fOutputFile, kFileExists))
-            if (!gSystem->AccessPathName(fOutputFile, kWritePermission))
-        {
-            gLog << err << "Sorry, you don't have write permission for '" << fOutputFile << "'." << endl;
-            return kFALSE;
-        }
-        return kTRUE;
-    }
-
-public:
-    MJStar(const char *name=0, const char *title=0)
-        : fIsUpdate(kFALSE), fComprLevel(1), fSerialIdx(0)
-    {
-        fName  = name;
-        fTitle = title;
-    }
-
-    void SetInputFile(const char *f)  { fInputFile  = f; }
-    void SetOutputFile(const char *f) { fOutputFile = f; }
-    void SetSerialIdx(Byte_t i)       { fSerialIdx  = i; }
-    void SetComprLevel(Byte_t l)      { fComprLevel = l; }
-    void SetUpdate(Bool_t u=kTRUE)    { fIsUpdate   = u; }
-
-    Bool_t Process()
-    {
-        if (!CheckFiles())
-            return kFALSE;
-
-        //
-        // Create a empty Parameter List and an empty Task List
-        // The tasklist is identified in the eventloop by its name
-        //
-        MParList plist;
-
-        MTaskList tlist;
-        plist.AddToList(&tlist);
-
-        // PRELIMINARY:
-        /*
-         MReportDrive rep;
-         plist.AddToList(&rep);
-         MPointingPos pos;
-         plist.AddToList(&pos);
-         */
-
-        //
-        // Now setup the tasks and tasklist:
-        // ---------------------------------
-        //
-        MReadMarsFile read("Events", fInputFile);
-        read.DisableAutoScheme();
-
-        MGeomApply        apply;
-        MMcPedestalCopy   pcopy;
-        MMcPedestalNSBAdd pnsb;
-
-        //MPointingPosCalc  pcalc;
-
-        MCerPhotCalc      ncalc;
-        MCerPhotAnal2     nanal;
-
-        MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
-        MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
-
-        ncalc.SetFilter(&f1);
-        nanal.SetFilter(&f2);
-
-        MSigmabarCalc     sgcal;
-        //MFillH            fills("MHSigmaTheta",  "", "FillSigmaTheta");
-        //MFillH            fillb("MHBlindPixels", "", "FillBlindPixels");
-        MImgCleanStd      clean;
-        MHillasCalc       hcalc;
-        MHillasSrcCalc    scalc; // !!Preliminary!! Will be removed later!
-        MWriteRootFile    write(fOutputFile, fIsUpdate?"UPDATE":"RECREATE", "Star output", fComprLevel);
-
-        tlist.AddToList(&read);
-        tlist.AddToList(&f1);
-        tlist.AddToList(&f2);
-        tlist.AddToList(&apply);
-        tlist.AddToList(&pcopy);
-        tlist.AddToList(&pnsb);
-        //tlist.AddToList(&pcalc);
-        tlist.AddToList(&ncalc);
-        tlist.AddToList(&nanal);
-        tlist.AddToList(&sgcal);
-        //tlist.AddToList(&fills);
-        //tlist.AddToList(&fillb);
-        tlist.AddToList(&clean);
-        tlist.AddToList(&hcalc);
-        tlist.AddToList(&scalc);
-        tlist.AddToList(&write);
-
-        //
-        // Set the serial number for all tasks in the current tasklist
-        //
-        tlist.SetSerialNumber(fSerialIdx);
-
-        //
-        // Setup tasks
-        //
-        write.AddContainer(write.AddSerialNumber("MMcEvt"),       "Events", kFALSE);
-        write.AddContainer(write.AddSerialNumber("MSigmabar"),    "Events");
-        write.AddContainer(write.AddSerialNumber("MHillas"),      "Events");
-        write.AddContainer(write.AddSerialNumber("MHillasExt"),   "Events");
-        write.AddContainer(write.AddSerialNumber("MHillasSrc"),   "Events");
-        write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
-        write.AddContainer(write.AddSerialNumber("MSrcPosCam"),   "RunHeaders");
-        //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
-        if (!fIsUpdate)
-        {
-            write.AddContainer("MRawRunHeader", "RunHeaders");
-            write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
-        }
-
-        //
-        // Create and set up the eventloop
-        //
-        MEvtLoop evtloop;
-        evtloop.SetParList(&plist);
-
-        //
-        // Execute your analysis
-        //
-        if (!evtloop.Eventloop())
-        {
-            gLog << err << "ERROR: Star eventloop failed!" << endl;
-            return kFALSE;
-        }
-
-        tlist.PrintStatistics();
-
-        //plist.FindObject("MHSigmaTheta")->Write();
-
-        gLog << all << "Star finished successfull!" << endl;
-
-        return kTRUE;
-    }
-//    ClassDef(MJStar, 0)
-};
-
-//ClassImp(MJStar);
-
-
-int main(const int argc, char **argv)
+int main(int argc, char **argv)
 {
     StartUpMessage();
@@ -282,20 +72,36 @@
     MArgs arg(argc, argv);
 
-    //
-    // Set verbosity to highest level.
-    //
-    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
-
-    if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
-        gLog.SetNoColors();
-
-    const int  kComprlvl = arg.HasOption("-c") ? arg.GetIntAndRemove("-c") : 1;
-    const int  kTelIndex = arg.HasOption("-t") ? arg.GetIntAndRemove("-t") : 0;
-    const bool kUpdate   = arg.HasOption("-u") && arg.GetIntAndRemove("-u")==1;
+    if (arg.HasOnly("-?") || arg.HasOnly("-h") || arg.HasOnly("--help"))
+    {
+        Usage();
+        return -1;
+    }
+
+    gLog.Setup(arg);
+
+    const TString kConfig     = arg.GetStringAndRemove("--config=", "star.rc");
+
+    const Bool_t  kPrintSeq   = arg.HasOnlyAndRemove("--print-seq");
+    const Bool_t  kPrintFiles = arg.HasOnlyAndRemove("--print-files");
+    const Bool_t  kPrintOnly  = arg.HasOnlyAndRemove("--print-only");
+    const Bool_t  kDebugEnv   = arg.HasOnlyAndRemove("--debug-env");
+
+    const Bool_t  kOverwrite  = arg.HasOnlyAndRemove("-f");
+    const Bool_t  kForceExec  = arg.HasOnlyAndRemove("-ff");
+
+    const TString kInpath     = arg.GetStringAndRemove("--in=",  "");
+    const TString kOutpath    = arg.GetStringAndRemove("--out=", ".");
+
+    if (arg.GetNumOptions()>0)
+    {
+        gLog << warn << "WARNING - Unknown commandline options..." << endl;
+        arg.Print("options");
+        gLog << endl;
+    }
 
     //
     // check for the right usage of the program
     //
-    if (arg.GetNumArguments()!=2)
+    if (arg.GetNumArguments()!=1)
     {
         Usage();
@@ -304,167 +110,118 @@
 
     //
-    // Initialize Non-GUI (batch) mode
-    //
-    gROOT->SetBatch();
-
+    // Setup sequence file and check for its existance
+    //
+    const TString kSequence = arg.GetArgumentStr(0);
+
+    if (gSystem->AccessPathName(kSequence, kFileExists))
+    {
+        gLog << err << "Sorry, sequence file '" << kSequence << "' doesn't exist." << endl;
+        return -1;
+    }
+
+    //
+    // Setup sequence and check its validity
+    //
+    MSequence seq(kSequence);
+    if (kPrintSeq)
+    {
+        gLog << all;
+        gLog.Separator(kSequence);
+        seq.Print();
+        gLog << endl;
+    }
+    if (!seq.IsValid())
+    {
+        gLog << err << "Sequence read but not valid!" << endl << endl;
+        return -1;
+    }
+
+    //
+    // Process print options
+    //
+    MDirIter iter;
+    seq.SetupDatRuns(iter, kInpath);
+
+    const Int_t n0 = seq.SetupDatRuns(iter, kInpath);
+    const Int_t n1 = seq.GetNumDatRuns();
+
+    if (kPrintFiles)
+    {
+        gLog << all;
+        gLog.Separator("Data Files");
+        iter.Print("all");
+        gLog << endl;
+    }
+
+    //
+    // Check for existance of all files
+    //
+    if (n0 != n1)
+    {
+        if (kForceExec)
+            gLog << warn << "WARNING";
+        else
+            gLog << err << "ERROR";
+        gLog << " - " << n1 << " files in sequence defined, but " << n0 << " found in ";
+        gLog << (kInpath.IsNull() ? "<defaultpath>" : kInpath.Data()) << endl;
+        if (!kForceExec)
+            return -1;
+    }
+
+    if (kPrintOnly)
+        return 0;
+
+    //
+    // Initialize root
+    //
     MArray::Class()->IgnoreTObjectStreamer();
     MParContainer::Class()->IgnoreTObjectStreamer();
 
-    MJStar star;
-    star.SetInputFile(arg.GetArgumentStr(0));
-    star.SetOutputFile(arg.GetArgumentStr(1));
-    star.SetComprLevel(kComprlvl);
-    star.SetSerialIdx(kTelIndex);
-    star.SetUpdate(kUpdate);
-
-    if (!star.Process())
-    {
-        gLog << err << "Star failed!" << endl;
-        return -1;
-    }
-
-    gLog << inf << "Star finished successfull!" << endl;
-
+    TApplication app("Star", &argc, argv);
+    if (gROOT->IsBatch() || !gClient)
+    {
+        gLog << err << "Bombing... maybe your DISPLAY variable is not set correctly!" << endl;
+        return 1;
+    }
+
+    //
+    // Update frequency by default = 1Hz
+    //
+    MStatusDisplay *d = new MStatusDisplay;
+
+    // From now on each 'Exit' means: Terminate the application
+    d->SetBit(MStatusDisplay::kExitLoopOnExit);
+    d->SetTitle(kSequence);
+
+    //
+    // Do calibration
+    //
+    MJStar job(Form("MJStar #%d", seq.GetSequence()));
+    job.SetSequence(seq);
+    job.SetEnv(kConfig);
+    job.SetEnvDebug(kDebugEnv);
+    job.SetDisplay(d);;
+    job.SetOverwrite(kOverwrite);
+    job.SetPathOut(kOutpath);
+    job.SetPathData(kInpath);
+    // job.SetPathIn(kInpath); // not yet needed
+
+    if (!job.ProcessFile())
+    {
+        gLog << err << "Calculation of image parameters failed." << endl << endl;
+        return -1;
+    }
+
+    if (!job.GetDisplay())
+    {
+        gLog << warn << "Display closed by user... execution aborted." << endl << endl;
+        return 1;
+    }
+
+    // From now on each 'Close' means: Terminate the application
+    d->SetBit(MStatusDisplay::kExitLoopOnClose);
+
+    // Wait until the user decides to exit the application
+    app.Run(kFALSE);
     return 0;
-/*
-    //
-    // This is to make argv[i] more readable inside the code
-    //
-    TString kNamein  = arg.GetArgumentStr(0);
-    TString kNameout = arg.GetArgumentStr(1);
-
-    if (!kNamein.EndsWith(".root"))
-        kNamein += ".root";
-
-    if (!kNameout.EndsWith(".root"))
-        kNameout += ".root";
-
-    //
-    // check whether the given files are OK.
-    //
-    if (gSystem->AccessPathName(kNamein, kFileExists))
-    {
-        gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
-        return -1;
-    }
-
-    if (!gSystem->AccessPathName(kNameout, kFileExists))
-    {
-        if (kUpdate)
-            gLog << warn << "Warning: File doesn't '" << kNameout << "' exist... recreating." << endl;
-    }
-
-    if (kUpdate || gSystem->AccessPathName(kNameout, kFileExists))
-        if (!gSystem->AccessPathName(kNameout, kWritePermission))
-        {
-            gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
-            return -1;
-        }
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
-    //
-    MParList plist;
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    // PRELIMINARY:
-    // MReportDrive rep;
-    // plist.AddToList(&rep);
-    // MPointingPos pos;
-    // plist.AddToList(&pos);
-
-    //
-    // Now setup the tasks and tasklist:
-    // ---------------------------------
-    //
-    MReadMarsFile read("Events", kNamein);
-    read.DisableAutoScheme();
-
-    MGeomApply        apply;
-    MMcPedestalCopy   pcopy;
-    MMcPedestalNSBAdd pnsb;
-
-    //MPointingPosCalc  pcalc;
-
-    MCerPhotCalc      ncalc;
-    MCerPhotAnal2     nanal;
-
-    MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);
-    MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);
-
-    ncalc.SetFilter(&f1);
-    nanal.SetFilter(&f2);
-
-    MSigmabarCalc     sgcal;
-    //MFillH            fills("MHSigmaTheta",  "", "FillSigmaTheta");
-    MImgCleanStd      clean;
-    MHillasCalc       hcalc;
-    MHillasSrcCalc    scalc; // !!Preliminary!! Will be removed later!
-    MWriteRootFile    write(kNameout, kUpdate?"UPDATE":"RECREATE", "Star output", kComprlvl);
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&f1);
-    tlist.AddToList(&f2);
-    tlist.AddToList(&apply);
-    tlist.AddToList(&pcopy);
-    tlist.AddToList(&pnsb);
-    //tlist.AddToList(&pcalc);
-    tlist.AddToList(&ncalc);
-    tlist.AddToList(&nanal);
-    tlist.AddToList(&sgcal);
-    //tlist.AddToList(&fills);
-    //tlist.AddToList(&fillb);
-    tlist.AddToList(&clean);
-    tlist.AddToList(&hcalc);
-    tlist.AddToList(&scalc);
-    tlist.AddToList(&write);
-
-    //
-    // Set the serial number for all tasks in the current tasklist
-    //
-    tlist.SetSerialNumber(kTelIndex);
-
-    //
-    // Setup tasks
-    //
-
-    write.AddContainer(write.AddSerialNumber("MMcEvt"),       "Events", kFALSE);
-    write.AddContainer(write.AddSerialNumber("MSigmabar"),    "Events");
-    write.AddContainer(write.AddSerialNumber("MHillas"),      "Events");
-    write.AddContainer(write.AddSerialNumber("MHillasExt"),   "Events");
-    write.AddContainer(write.AddSerialNumber("MHillasSrc"),   "Events");
-    write.AddContainer(write.AddSerialNumber("MNewImagePar"), "Events");
-    write.AddContainer(write.AddSerialNumber("MSrcPosCam"),   "RunHeaders");
-    //write.AddContainer(write.AddSerialNumber("MHSigmaTheta"), "RunHeaders");
-    if (!kUpdate)
-    {
-        write.AddContainer("MRawRunHeader", "RunHeaders");
-        write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
-    }
-
-    //
-    // Create and set up the eventloop
-    //
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-
-    //
-    // Execute your analysis
-    //
-    if (!evtloop.Eventloop())
-    {
-        gLog << err << "ERROR: Star eventloop failed!" << endl;
-        return -1;
-    }
-
-    tlist.PrintStatistics();
-
-    //plist.FindObject("MHSigmaTheta")->Write();
-
-    gLog << all << "Star finished successfull!" << endl;
-    return 0;
-    */
 }
