Index: trunk/MagicSoft/Mars/mbase/MRunIter.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MRunIter.cc	(revision 3825)
+++ trunk/MagicSoft/Mars/mbase/MRunIter.cc	(revision 3874)
@@ -17,4 +17,5 @@
 !
 !   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Javier Rico,  4/2004 <mailto:jrico@ifae.es>
 !
 !   Copyright: MAGIC Software Development, 2000-2004
@@ -35,4 +36,5 @@
 
 #include <TSystem.h>
+#include <iostream>
 
 ClassImp(MRunIter);
@@ -60,2 +62,58 @@
     return AddDirectory(gSystem->DirName(name), gSystem->BaseName(name), -1);
 }
+
+// --------------------------------------------------------------------------
+//
+// Add runs specified in a character chain with the format:
+// run1,run2-run3,run4-run5,...
+// e.g  if runrange="100,105-107,110-112,115" 
+// runs 100,105,106,107,110,111,112 and 115 are included in the iterator list
+//
+Int_t MRunIter::AddRuns(const char* runrange, const char* path)
+{ 
+  char* last;
+  char  chcopy[100];
+  Int_t lowrun=-1;
+  Int_t upprun;
+  Int_t totdir=0;
+
+  //  cout << "Analyzing chain " << runrange << " in path " << path << endl;
+
+  sprintf(chcopy,"%s",runrange);
+  last=&chcopy[0];
+
+  // loop over the elements of the character chain (break inside the loop)
+  for(char* cp=last;cp;cp++)
+    {
+      // look for a digit, a '-' or a ',' or end of string
+      char c=*cp;
+      if(! ((c>='0' && c<='9') || c=='-' || c==',' || c=='\0'))
+	return totdir;
+      
+      // if '-' is found, save the previous number as initial run
+      if(c=='-' && lowrun<0)
+	{
+	  char chrun[100];
+	  strncpy(chrun,last,cp-last);
+	  lowrun=atoi(chrun);	  	  
+	  last=cp+1;
+	}
+      // if ',' or the end of the string are found, save the previous run or run range
+      if(c==',' || c=='\0')
+	{
+	  char chrun[100];
+	  strncpy(chrun,last,cp-last);
+	  upprun=atoi(chrun);
+	  if(lowrun>=0 && lowrun<=upprun)
+	    totdir+=AddRuns(lowrun,upprun,path);
+	  else if(lowrun<0)
+	    totdir+=AddRun(upprun,path);	  
+	  
+	  if(c=='\0')
+	    break;
+	  lowrun=-1;
+	  last=cp+1;
+	}
+    }
+  return totdir;
+}
Index: trunk/MagicSoft/Mars/mbase/MRunIter.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MRunIter.h	(revision 3825)
+++ trunk/MagicSoft/Mars/mbase/MRunIter.h	(revision 3874)
@@ -42,4 +42,5 @@
 
     Int_t AddRun(UInt_t run, const char *path=0);
+    Int_t AddRuns(const char* runrange, const char *path=0);
     Int_t AddRuns(UInt_t from, UInt_t to, const char *path=0)
     {
