Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2266)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2267)
@@ -63,4 +63,17 @@
    * mraw/MRawEvtHeader.cc:
      - calculate time from clock ticks
+
+   * mbase/MArgs.[h,cc]:
+     - added
+
+   * mbase/Makefile:
+     - MArgs.cc added
+
+   * mbase/BaseLinkDef.h:
+     - MArgs, MArgsEntry added
+
+   * merpp.cc:
+     - added '-v' option
+     - changes to use MArgs
 
 
Index: /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 2266)
+++ /trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 2267)
@@ -45,3 +45,6 @@
 #pragma link C++ class MTime+;
 
+#pragma link C++ class MArgs+;
+#pragma link C++ class MArgsEntry+;
+
 #endif
Index: /trunk/MagicSoft/Mars/mbase/MArgs.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MArgs.cc	(revision 2267)
+++ /trunk/MagicSoft/Mars/mbase/MArgs.cc	(revision 2267)
@@ -0,0 +1,175 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 7/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2003
+!
+!
+\* ======================================================================== */
+
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MArgs
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MArgs.h"
+
+#include <stdlib.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MArgsEntry);
+ClassImp(MArgs);
+
+void MArgsEntry::Print(const Option_t *o) const
+{
+    gLog << all << *this << endl;
+}
+
+MArgs::MArgs(int argc, const char **argv) : fArgc(argc), fArgv()
+{
+    fName = argv[0];
+
+    fArgv.SetOwner();
+
+    for (int i=1; i<argc; i++)
+    {
+        MArgsEntry &o = *new MArgsEntry(argv[i]);
+        dynamic_cast<TString&>(o) = o.Strip(TString::kBoth);
+        fArgv.Add(&o);
+    }
+}
+
+void MArgs::Print(const Option_t *o) const
+{
+    gLog << all << underline << fName << ":" << endl;
+    fArgv.Print();
+}
+
+Int_t MArgs::GetInt(const TString name) const
+{
+    return atoi(GetString(name));
+}
+
+Double_t MArgs::GetFloat(const TString name) const
+{
+    return atof(GetString(name));
+}
+
+TString MArgs::GetString(const TString name) const
+{
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+        if (s->BeginsWith(name))
+            return s->Data()+s->Index(name)+name.Length();
+    return 0;
+}
+
+Int_t MArgs::GetIntAndRemove(const TString name)
+{
+    return atoi(GetStringAndRemove(name));
+}
+
+Double_t MArgs::GetFloatAndRemove(const TString name)
+{
+    return atof(GetStringAndRemove(name));
+}
+
+TString MArgs::GetStringAndRemove(const TString n)
+{
+    const TString name = n.Strip(TString::kBoth);
+
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+        if (s->BeginsWith(name))
+        {
+            TString str = s->Data()+s->Index(name)+name.Length();
+            delete fArgv.Remove(dynamic_cast<TObject*>(s));
+            return str;
+        }
+    return 0;
+}
+
+Int_t MArgs::GetArgumentInt(Int_t i) const
+{
+    return atoi(GetArgumentStr(i));
+}
+
+Float_t MArgs::GetArgumentFloat(Int_t i) const
+{
+    return atof(GetArgumentStr(i));
+}
+
+TString MArgs::GetArgumentStr(Int_t i) const
+{
+    Int_t num = 0;
+
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+    {
+        if (s->BeginsWith("-"))
+            continue;
+
+        if (i==num++)
+            return *s;
+    }
+
+    return "";
+}
+
+Int_t MArgs::GetNumArguments() const
+{
+    Int_t num = 0;
+
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+        if (!s->BeginsWith("-"))
+            num++;
+
+    return num;
+}
+
+Bool_t MArgs::Has(const TString n) const
+{
+    const TString name = n.Strip(TString::kBoth);
+
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+        if (s->BeginsWith(name))
+            return kTRUE;
+    return kFALSE;
+}
+
+Bool_t MArgs::HasOption(const TString n) const
+{
+    const TString name = n.Strip(TString::kBoth);
+
+    TIter Next(&fArgv);
+    TString *s = NULL;
+    while ((s=dynamic_cast<TString*>(Next())))
+        if (s->BeginsWith(name) && s->Length()>name.Length())
+            return kTRUE;
+    return kFALSE;
+}
Index: /trunk/MagicSoft/Mars/mbase/MArgs.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MArgs.h	(revision 2267)
+++ /trunk/MagicSoft/Mars/mbase/MArgs.h	(revision 2267)
@@ -0,0 +1,56 @@
+#ifndef MARS_MArgs
+#define MARS_MArgs
+
+#ifndef MARS_MAGIC
+#include "MAGIC.h"
+#endif
+
+#ifndef ROOT_TNamed
+#include <TNamed.h>
+#endif
+
+#ifndef ROOT_TList
+#include <TList.h>
+#endif
+
+class MArgsEntry : public TString, public TObject
+{
+public:
+    MArgsEntry(const char *c) : TString(c), TObject() {}
+
+    void Print(const Option_t *o) const;
+
+    ClassDef(MArgsEntry, 0)
+};
+
+class MArgs : public TNamed
+{
+private:
+    Int_t fArgc;
+    TList fArgv;
+
+public:
+    MArgs(int argc, const char **argv);
+
+    void Print(const Option_t *o="") const;
+
+    Int_t    GetInt(const TString name) const;
+    Double_t GetFloat(const TString name) const;
+    TString  GetString(const TString name) const;
+
+    Int_t    GetIntAndRemove(const TString name);
+    Double_t GetFloatAndRemove(const TString name);
+    TString  GetStringAndRemove(const TString name);
+
+    Bool_t Has(const TString name) const;
+    Bool_t HasOption(const TString name) const;
+
+    TString GetArgumentStr(Int_t i) const;
+    Int_t   GetArgumentInt(Int_t i) const;
+    Float_t GetArgumentFloat(Int_t i) const;
+    Int_t   GetNumArguments() const;
+
+    ClassDef(MArgs, 0)  //Class to parse command line arguments
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mbase/Makefile	(revision 2266)
+++ /trunk/MagicSoft/Mars/mbase/Makefile	(revision 2267)
@@ -34,4 +34,5 @@
 SRCFILES = MLogo.cc \
 	   MLog.cc \
+           MArgs.cc \
 	   MParContainer.cc \
 	   MParList.cc \
Index: /trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- /trunk/MagicSoft/Mars/merpp.cc	(revision 2266)
+++ /trunk/MagicSoft/Mars/merpp.cc	(revision 2267)
@@ -9,4 +9,7 @@
 
 #include "MLog.h"
+#include "MLogManip.h"
+
+#include "MArgs.h"
 #include "MTime.h"
 #include "MArray.h"
@@ -15,5 +18,4 @@
 #include "MRawEvtHeader.h"
 #include "MRawCrateArray.h"
-#include "MInputStreamID.h"
 
 using namespace std;
@@ -34,6 +36,19 @@
 //////////////////////////////////////////////////////////////////////////////
 
+void Usage()
+{
+    gLog << "Sorry the usage is:" << endl;
+    gLog << "   merpp [-vn] inputfile outputfile [compression level]" << endl << endl;
+    gLog << "     input file:   Magic DAQ binary file." << endl;
+    gLog << "     ouput file:   Merpped root file." << endl;
+    gLog << "     compr. level: 1..9 [default=1]" << endl;
+    gLog << "     -vn: Verbosity level n [default=2]" << endl << endl;
+}
+
 int main(const int argc, const char **argv)
 {
+    MArgs arg(argc, argv);
+    arg.Print();
+
     gLog << "==================================================" << endl ;
     gLog << "                   MERPP v0.1" << endl;
@@ -47,11 +62,7 @@
     // check for the right usage of the program
     //
-    if (argc<3 || argc>4)
+    if (arg.GetNumArguments()<2 || arg.GetNumArguments()>3)
     {
-        gLog << "Sorry the usage is:" << endl;
-        gLog << "   merpp inputfile outputfile [compression level]" << endl << endl;
-        gLog << "     input file:   Magic DAQ binary file." << endl;
-        gLog << "     ouput file:   Merpped root file." << endl;
-        gLog << "     compr. level: 1..9 [default=1]" << endl << endl;
+        Usage();
         return -1;
     }
@@ -60,17 +71,18 @@
     // Set verbosity to highest level.
     //
-    gLog.SetDebugLevel(2);
+    gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetInt("-v") : 2);
 
     //
     // This is to make argv[i] more readable insidethe code
     //
-    const char *kNamein   = argv[1];
-    const char *kNameout  = argv[2];
-    const int   kComprlvl = argc==4 ? atoi(argv[3]) : 1;
+    const char *kNamein   = arg.GetArgumentStr(0);
+    const char *kNameout  = arg.GetArgumentStr(1);
+    const int   kComprlvl = arg.GetNumArguments()==3 ? arg.GetArgumentInt(2) : 1;
 
     //
     //     initialize ROOT  (this is obligatory here)
     //
-    TROOT simple("merpp", "Mars - Merging and Preprocessing Program");
+    TROOT merpp("merpp", "Mars - Merging and Preprocessing Program");
+    merpp.SetBatch();
 
     //
@@ -79,14 +91,14 @@
     if (gSystem->AccessPathName(kNamein, kFileExists))
     {
-        gLog << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
+        gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
         return -1;
     }
 
     if (!gSystem->AccessPathName(kNameout, kFileExists))
-        gLog << "Warning: A file '" << kNameout << "' exists." << endl;
+        gLog << warn << "Warning: A file '" << kNameout << "' exists." << endl;
     else
         if (!gSystem->AccessPathName(kNameout, kWritePermission))
         {
-            gLog << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
+            gLog << err << "Sorry, you don't have write permission for '" << kNameout << "'." << endl;
             return -1;
         }
@@ -148,9 +160,9 @@
     if (!magic.Eventloop())
     {
-        gLog << "ERROR: Merging and preprocessing failed!" << endl;
+        gLog << err << "ERROR: Merging and preprocessing failed!" << endl;
         return -1;
     }
 
-    gLog << "Merpp finished successfull!" << endl;
+    gLog << all << "Merpp finished successfull!" << endl;
     return 0;
 }
