Index: trunk/MagicSoft/Mars/datacenter/scripts/buildsequenceentries
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/buildsequenceentries	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/buildsequenceentries	(revision 6934)
@@ -0,0 +1,156 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+
+cd $mars
+
+table=SequenceBuildStatus
+column=fSequenceEntriesBuilt
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column.txt
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/buildsequenceentries/$year
+getstatuslog=$getstatuslogpath/getstatus-buildsequenceentries-$datetime.log
+
+scriptlogpath=$logpath/run/buildsequenceentries/`date +%Y/%m`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/buildsequenceentries-$datetime.log
+
+date >> $scriptlog 2>&1
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+date > $lockpath/lock-buildsequenceentries.txt >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> getting list for callisto is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+
+echo "getting list..." >> $scriptlog 2>&1
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatus.log | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+   1)   echo "check0=$check0 -> everthing ok -> do step" >> $scriptlog 2>&1;;
+   *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+esac
+
+dates=(`cat $todofile`)
+
+if [ "$dates" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile >> $scriptlog 2>&1
+   rm -v $lockpath/lock-buildsequenceentries.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "dates: "${dates[@]} >> $scriptlog 2>&1
+
+for date in ${dates[@]}
+do 
+   echo "building sequence entries for date $date..." >> $scriptlog 2>&1
+   year2=`echo $date | cut -c 1-4`
+   buildsequentriespath=$logpath/$year2
+   if [ ! -d $buildsequentriespath ]
+      then
+      mkdir -pv $buildsequentriespath >> $scriptlog 2>&1
+      if [ ! -d $buildsequentriespath ]
+      then 
+         echo "could not make buildsequentriespath "$buildsequentriespath >> $scriptlog 2>&1
+         continue
+      fi
+   fi
+   check1=`root -q -b $macrospath/buildsequenceentries.C+\("\"$date\""\,kFALSE\) | tee $buildsequentriespath/buildsequenceentries-$date.log | grep int | sed -e 's/(int)//'`
+
+   case $check1 in
+      1)   echo "check1=$check1 -> everthing ok -> setting status..." >> $scriptlog 2>&1
+           setstatuslogpath=$logpath/setstatus/buildsequenceentries/$year2
+           if [ ! -d $setstatuslogpath ]
+           then
+             mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+             if [ ! -d $setstatuslogpath ]
+             then
+                echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+                continue
+             fi
+           fi
+           check2=`root -q -b $macrospath/setstatus.C+\("\"$date\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\)  | tee $setstatuslogpath/setstatus-buildsequenceentries-$date.log | grep int | sed -e 's/(int)//'`
+           case $check2 in
+   	      1)   echo "check2=$check2 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
+   	      *)   echo "check2=$check2 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
+           esac
+   	   ;;
+      *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+done
+
+rm -v $todofile >> $scriptlog 2>&1 
+rm -v $lockpath/lock-buildsequenceentries.txt >> $scriptlog 2>&1 
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/checkfilesforsequenceavail	(revision 6934)
@@ -0,0 +1,144 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+
+table=SequenceProcessStatus
+column=fAllFilesAvail
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column.txt
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/checkfileavail/$year
+getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
+
+scriptlogpath=$logpath/run/checkfilesavail/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/checkfilesforsequenceavail-$datetime.log
+
+date >> $scriptlog 2>&1
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath  >> $scriptlog 2>&1 
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+cd $mars
+
+if [ -e $todofile ]
+then 
+   echo "checkfilesforsequenceavail is already running -> exit" >> $scriptlog 2>&1
+   exit
+fi
+
+echo "getting list..." >> $scriptlog 2>&1
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+   1)   echo "check0=$check0 -> everthing ok -> do step" >> $scriptlog 2>&1 ;;
+   *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1 ;;
+esac
+
+sequences=(`cat $todofile`)
+
+if [ "$sequences" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile >> $scriptlog 2>&1
+   rm -v $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
+
+for sequence in ${sequences[@]}
+do 
+   echo "checking files for sequence $sequence..." >> $scriptlog 2>&1 
+   no=`printf %08d $sequence | cut -c 4`
+   outpath=$logpath/checkfileavail/`printf %04d $no`
+   echo "outpath: "$outpath  >> $scriptlog 2>&1 
+   if [ ! -d $outpath ]
+   then
+     mkdir -pv $outpath  >> $scriptlog 2>&1 
+     if [ ! -d $outpath ]
+     then 
+        echo "could not make outpath $outpath -> continue "  >> $scriptlog 2>&1 
+        continue
+     fi
+   fi
+   check1=`root -q -b $macrospath/checkfileavail.C+\(\""$sequence\""\) | tee $outpath/checkfileavail-$sequence.log | grep int | sed -e 's/(int)//'`
+
+   case $check1 in
+      1)   echo "check1=$check1 -> everthing ok -> setting status..." >> $scriptlog 2>&1 
+           setstatuslogpath=$logpath/setstatus/checkfileavail/`printf %04d $no`
+           if [ ! -d $setstatuslogpath ]
+           then
+             mkdir -pv $setstatuslogpath  >> $scriptlog 2>&1 
+             if [ ! -d $setstatuslogpath ]
+             then
+                echo "could not make setstatuslogpath "$setstatuslogpath  >> $scriptlog 2>&1 
+                continue
+             fi
+           fi
+           check2=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\)  | tee $setstatuslogpath/setstatus-checkfileavail-$sequence.log | grep int | sed -e 's/(int)//'`
+    	   case $check2 in
+   	      1)   echo "check2=$check2 -> everthing ok, status has been set" >> $scriptlog 2>&1 ;;
+   	      *)   echo "check2=$check2 -> ERROR -> step could not be set" >> $scriptlog 2>&1 ;;
+           esac
+   	   ;;
+      *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1 ;;
+   esac
+done
+
+rm -v $todofile  >> $scriptlog 2>&1 
+rm -v $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/copyscript
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/copyscript	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/copyscript	(revision 6934)
@@ -0,0 +1,252 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+# This script handles the subsystem logfiles, which are copied every
+# day automatically from pc15 in La Palma to /data/MAGIC/transfer/ in
+# Wuerzburg
+# The structure in this directory is: subsystem/date/logfile.*
+# The logfiles are from CC (*.rep, CC*.dbg, CC*.rbk, CC*.rep, CC*.run,
+# CC*.run.html) and Cosy (cosy*.log, cosy*.rep, tpoint*.txt/starg*.txt) 
+# AMC (AMC*.log, AMC*.info, AMC*.lut) and CaCo (dc*.txt) are not copied
+# every day automatically
+#
+# the script performs the following steps:
+# ----------------------------------------
+# - filling the information from the *.rbk and *.run files into the DB
+# using the macros filldotrbk.C and filldotrun.C
+# - copying all logfiles to the correct directory:
+# /Period*/subsystem/date/file.*
+# (the period for each date is obtained by the macro getperiod.C) 
+# - filling the sequences for the standard analysis into the database
+# (for each day of which a file was copied) 
+# 
+# 
+# -- to make sure that no file is copied twice there's a textfile
+# (.processed), to which every file, that was processed, is added 
+# .processed is copied to La Palma, so that it is possible to copy
+# only new files
+# -- to make sure that a file was copied completely before it is
+# processed, a file with the checksum of all files is also copied from
+# La Palma and the checksum is checked with this script for each file
+# before processing it. 
+# 
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+transdir=/magic/datacenter/transfer
+extern=MAGIC@virgo:/data/MAGIC/transfer
+datetime=`date +%F-%H-%M-%S`
+
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+
+scriptlogpath=$logpath/run/copyscript/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/copyscript-$datetime.log
+
+date >> $scriptlog 2>&1
+
+date > $lockpath/lock-copyscript.txt >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> copyscript is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+# rsync new dc with virgo
+rsync -av $extern/ $transdir  >> $scriptlog 2>&1 
+
+cd $transdir
+
+#check the checksums, write output into file
+md5sum -c .checksums | tee $transdir/.check  >> $scriptlog 2>&1 
+#md5sum -c $transdir/checksums-test >| $transdir/.check 
+if ! test -e $transdir/.check
+then
+   echo "couldn't create checkfile -> exit script" >> $scriptlog 2>&1
+   rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+else
+   echo "checkfile created" >> $scriptlog 2>&1
+fi
+
+cd $mars 
+
+echo "remove empty directories: "  >> $scriptlog 2>&1 
+rmdir -pv $transdir/*/*  >> $scriptlog 2>&1 
+
+#find all dates in transfer-directory
+#dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_*[0-1][0-9]_*[0-3][0-9] | grep -v '.tgz'`
+dates=`ls $transdir/*/ -1 | grep --regexp=20[0-9][0-9]_[0-1][0-9]_[0-3][0-9] | grep -v '.tgz'` >> $scriptlog 2>&1
+
+if [ "$dates" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "dates found: "$dates  >> $scriptlog 2>&1 
+
+#loop over dates 
+for date in ${dates[@]}
+do 
+   #find all files for this date
+   files=`find $transdir/*/$date/ -name "*.*"`  >> $scriptlog 2>&1
+   if [ "$files" = "" ]
+   then 
+      echo "no files found for $date"  >> $scriptlog 2>&1
+      continue
+   else
+      echo "files found for $date"  >> $scriptlog 2>&1
+   fi
+   
+   date2=`echo $date | sed -e 's/_/\//g'`
+#   echo "date2=$date2"
+   copylogpath=$logpath/copyscript/$date2
+   echo "copylogpath: "$copylogpath >> $scriptlog 2>&1
+   if [ ! -d $copylogpath ]
+   then
+     mkdir -pv $copylogpath >> $scriptlog 2>&1
+     if [ ! -d $copylogpath ]
+     then
+        echo "could not make copylogpath $copylogpath -> continue " >> $scriptlog 2>&1
+        continue
+     fi
+   fi
+   
+   #loop over all files in the directories for this date
+   for file in $files
+   do
+      echo "file: "$file  >> $scriptlog 2>&1 
+      filename=`basename $file`
+#      echo "filename: "$filename
+                        
+      #check for each file whether it has to be processed
+      if grep "$filename: OK" $transdir/.check  >> $scriptlog 2>&1 
+      then
+         newfile=`echo $file | sed -e 's/datacenter\/transfer/subsystemdata/' -e 's/ccdata/cc/' -e 's/drivelogs/drive/' -e 's/_/\//1' -e 's/_/\//1' `
+         echo "file (new path): "$newfile >> $scriptlog 2>&1 
+         newpath=`dirname $newfile`
+#         echo "new path: "$newpath
+         #make sure, that the needed directories are available
+         if [ ! -d $newpath ]
+         then
+            mkdir -pv $newpath >> $scriptlog 2>&1 
+            if [ ! -d $newpath ]
+            then 
+               echo "could not make path $newpath"  >> $scriptlog 2>&1 
+               continue
+            fi
+         fi
+         
+         #run macros if the file is a *.rbk or a *.run file to
+         #fill the information into the db
+         if echo $filename | grep .rbk  >> $scriptlog 2>&1 
+         then
+            echo "found rbk-file $filename"  >> $scriptlog 2>&1 
+            checkfillrbk=`root -q -b $macrospath/filldotrbk.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrbk-$date-log.txt | grep int | sed -e 's/(int)//'`
+            case $checkfillrbk in
+               1) echo "checkfillrbk=$checkfillrbk -> everything ok " >> $scriptlog 2>&1 
+                  echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
+               *) echo "checkfillrbk=$checkfillrbk - Error -> go on with next file" >> $scriptlog 2>&1 
+                  continue;;
+            esac
+         fi
+         if echo $file | grep 'CC_.*.run' >> $scriptlog 2>&1  && ! echo $file | grep .run.html >> $scriptlog 2>&1 
+         then
+            echo "found run-file $filename" >> $scriptlog 2>&1 
+            checkfillrun=`root -q -b $macrospath/filldotrun.C+\("\"$file\""\,kFALSE\) | tee $copylogpath/filldotrun-$date-log.txt  | grep int | sed -e 's/(int)//'`
+            case $checkfillrun in
+               1) echo "checkfillrun=$checkfillrun -> everything ok " >> $scriptlog 2>&1 
+                  echo "-> insert date in SequenceBuildStatus for $date" >> $scriptlog 2>&1 
+#                  date3=`echo $date | sed -e 's/_/-/g'`
+#                  echo "date3=$date3"
+                  checkinsertdate=`root -q -b $macrospath/insertdate.C+\("\"$date\""\) | tee $copylogpath/insertdate-$date-log.txt   | grep int | sed -e 's/(int)//'`
+                  case $checkinsertdate in
+                     1) echo "date inserted" >> $scriptlog 2>&1 ;;
+                     *) echo "checkinsertdate=$checkinsertdate -> ERROR - insert date didn't work" >> $scriptlog 2>&1 
+                        continue;;
+                  esac
+                  echo " -> go on with copying file" >> $scriptlog 2>&1 ;;
+               *) echo "checkfillrun=$checkfillrun Error -> go on with next file" >> $scriptlog 2>&1 
+                  continue;;
+            esac
+         fi
+
+         #copy file
+         if mv -v $file $newpath >> $scriptlog 2>&1 
+         then
+            #add file to donelist
+            echo "$filename processed" >> $transdir/.processed
+            echo $filename" moved and added to .processed" >> $scriptlog 2>&1 
+         else
+            echo $file" couldn't be moved!!!!!" >> $scriptlog 2>&1 
+         fi
+
+      else
+         #if the checksum for the file is not ok or the file was
+         #already processed (entry in donelist) -> go on with next file
+         echo $file": checksum not ok " >> $scriptlog 2>&1 
+      fi
+   done
+done
+
+echo "remove empty directories: "  >> $scriptlog 2>&1 
+rmdir -pv $transdir/*/*  >> $scriptlog 2>&1 
+
+rm -v $transdir/.check >> $scriptlog 2>&1 
+
+rsync -av --delete $transdir/ $extern >> $scriptlog 2>&1 
+
+rm -v $lockpath/lock-copyscript.txt >> $scriptlog 2>&1
+date >> $scriptlog 2>&1
+
+set +C
Index: trunk/MagicSoft/Mars/datacenter/scripts/correcttime
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/correcttime	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/correcttime	(revision 6934)
@@ -0,0 +1,145 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+
+table=RunProcessStatus
+column=fTimingCorrection
+date=NULL
+datetime=`date +%F_%T`
+year=`date +%Y`
+
+listdir=/magic/datacenter/lists
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/correct_raw_time/$year
+getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath 
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath 
+     exit
+  fi
+fi
+
+
+if [ -e $listdir/ToDo-$table-$column.txt ]
+then 
+   echo "correct_raw_time is already running -> exit"
+   exit
+fi
+
+cd $mars
+
+echo "getting list..."
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+   1)   echo "check0=$check0 -> everthing ok -> run correct_raw_time";;
+   *)   echo "check0=$check0 -> ERROR -> step has to be repeated";;
+esac
+
+runs=(`cat $listdir/ToDo-$table-$column.txt`)
+
+if [ "$runs" = "" ]
+then 
+   echo "nothing to do -> exit" 
+   rm -v $listdir/ToDo-$table-$column.txt
+   exit
+fi
+
+echo "runs: "${runs[@]}
+
+for run in ${runs[@]}
+do 
+  echo "getting path for run $run ... "
+  infile=`find /magic/data/rawfiles-wrong-timing/ -name *${run}_[D,C,P,S]_*`
+  echo "infile:"$infile
+  outfile=`echo $infile | sed -e 's/-wrong-timing//g'`
+  echo "outfile:"$outfile
+  outpath=`dirname $outfile`
+  echo "outpath:"$outpath
+  if [ ! -d $outpath ]
+  then
+    mkdir -pv $outpath
+    if [ ! -d $outpath ]
+    then 
+       echo "could not make outpath "$outpath
+       continue
+    fi
+  fi
+  timecorrpath=$outpath"/timecorrlogs"
+  echo "timecorrpath: "$timecorrpath
+  if [ ! -d $timecorrpath ]
+  then
+    mkdir -pv $timecorrpath
+    if [ ! -d $timecorrpath ]
+    then
+       echo "could not make timecorrpath "$timecorrpath
+       continue
+    fi
+  fi
+  
+  check1=0
+  echo "run correct_raw_time..."
+  /home/tape/MagicReadout/correct_raw_time $infile $outfile > $timecorrpath/correct_raw_time-$run.log
+  check1=$?
+
+  case $check1 in
+     1)   echo "check1=$check1 -> everthing ok -> setting status..."
+          no=`printf %08d $run | cut -c 1-5`
+          setstatuspath=$logpath/setstatus/correct_raw_time/$no
+          echo "setstatuspath: "$setstatuspath 
+          if [ ! -d $setstatuspath ]
+          then
+            mkdir -pv $setstatuspath 
+            if [ ! -d $setstatuspath ]
+            then
+               echo "could not make setstatuspath $setstatuspath -> continue " 
+               continue
+            fi
+          fi
+          check2=`root -q -b $macrospath/setstatus.C+\("\"$run\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuspath/setstatus-correct_raw_time-$run.log | grep int | sed -e 's/(int)//'`
+          case $check2 in
+  	     0)   echo "check2=0 -> ERROR -> step could not be set";;
+  	     1)   echo "check2=1 -> everthing ok, status has been set";;
+          esac
+  	;;
+     *)   echo "check1=$check1 -> ERROR -> step has to be repeated";;
+  esac
+done
+
+rm -v $listdir/ToDo-$table-$column.txt
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/doexclusions
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/doexclusions	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/doexclusions	(revision 6934)
@@ -0,0 +1,156 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+
+cd $mars
+
+table=SequenceBuildStatus
+column=fExclusionsDone
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column.txt
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/doexclusions/$year
+getstatuslog=$getstatuslogpath/getstatus-doexcludions-$datetime.log
+
+scriptlogpath=$logpath/run/doexclusions/`date +%Y/%m`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/doexclusions-$datetime.log
+
+date >> $scriptlog 2>&1
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+date > $lockpath/lock-doexclusions.txt >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> getting list for callisto is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+
+echo "getting list..."
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+   1)   echo "check0=$check0 -> everthing ok -> do step";;
+   *)   echo "check0=$check0 -> ERROR -> step has to be repeated";;
+esac
+
+dates=(`cat $todofile`)
+
+if [ "$dates" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile >> $scriptlog 2>&1
+   rm -v $lockpath/lock-doexclusions.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "dates: "${dates[@]} >> $scriptlog 2>&1
+
+for date in ${dates[@]}
+do 
+   echo "do exclusions for date "$date
+   year2=`echo $date | cut -c 1-4`
+   doexclusionspath=$logpath/$year2
+   if [ ! -d $doexclusionspath ]
+      then
+      mkdir -pv $doexclusionspath >> $scriptlog 2>&1
+      if [ ! -d $doexclusionspath ]
+      then 
+         echo "could not make doexclusionspath "$doexclusionspath >> $scriptlog 2>&1
+         continue
+      fi
+   fi
+   check1=`root -q -b $macrospath/doexclusions.C+\("\"$date\""\) | tee $doexclusionspath/doexclusions-$date.log | grep int | sed -e 's/(int)//'`
+
+   case $check1 in
+      1)   echo "check1=1 -> everthing ok -> setting status..."
+           setstatuslogpath=$logpath/setstatus/doexclusions/$year2
+           if [ ! -d $setstatuslogpath ]
+           then
+             mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+             if [ ! -d $setstatuslogpath ]
+             then
+                echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+                continue
+             fi
+           fi
+           check2=`root -q -b $macrospath/setstatus.C+\("\"$date\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\)  | tee $setstatuslogpath/setstatus-doexclusions-$date.log | grep int | sed -e 's/(int)//'`
+     	   case $check2 in
+   	      1)   echo "check2=$check2 -> everthing ok, status has been set";;
+   	      *)   echo "check2=$check2 -> ERROR -> step could not be set";;
+           esac
+   	;;
+      *)   echo "check1=$check1 -> ERROR -> step has to be repeated";;
+   esac
+done
+
+rm -v $todofile >> $scriptlog 2>&1 
+rm -v $lockpath/lock-doexclusions.txt >> $scriptlog 2>&1 
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/filesondisk
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/filesondisk	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/filesondisk	(revision 6934)
@@ -0,0 +1,154 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+
+cd $mars
+date=`date +%F`
+
+subsystemdir=/magic/subsystemdata
+rawdir=/magic/data
+logpath=/magic/datacenter/autologs/filesondisk/`date +%Y`
+
+if [ ! -d $logpath ]
+then
+  mkdir -pv $logpath 
+  if [ ! -d $logpath ]
+  then 
+     echo "could not make directory "$logpath 
+     exit
+  fi
+fi
+
+
+
+echo "checking disk for ccfiles..." 
+
+filename=$logpath/ccfilesondisk-$date.txt
+column=fCCFileAvail
+
+find $subsystemdir/cc/ -name '*_S.rep' | cut -d_ -f2  > $filename
+
+
+echo "resetting runs..."
+check3=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $logpath/resetall-$column-$date.log | grep int | sed -e 's/(int)//'`
+
+case $check3 in 
+   1)   echo "check3=$check3 -> everthing ok -> reset is done";;
+   *)   echo "check3=$check3 -> ERROR -> something went wrong while resetting";;
+esac
+
+
+
+echo "checking disk for cacofiles..." 
+
+filename=$logpath/cacofilesondisk-$date.txt
+column=fCaCoFileAvail
+
+find $subsystemdir/caco/ -name '*.txt' | cut -d_ -f8 | grep [0-9] > $filename
+
+
+echo "resetting runs..."
+check0=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $logpath/resetall-$column-$date.log | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+   1)   echo "check0=$check0 -> everthing ok -> reset is done";;
+   *)   echo "check0=$check0 -> ERROR -> something went wrong while resetting";;
+esac
+
+
+
+echo "checking missing cacofiles..."
+check1=`root -q -b $macrospath/findcacofiles.C+\("\"$date\""\) | tee $logpath/findcacofiles-$date.log | grep int | sed -e 's/(int)//'`
+
+case $check1 in 
+   1)   echo "check1=$check1 -> everthing ok -> missing cacofiles are found";;
+   *)   echo "check1=$check1 -> ERROR -> something went wrong while resetting";;
+esac
+
+missingcacoruns=(`cat $logpath/findcacofiles-$date.txt`)
+
+for missingcacorun in ${missingcacoruns[@]}
+do 
+   runno=$missingcacorun
+   echo "no cacofile found for run "$runno
+   echo "finding cacofile"
+   ccfile=`find $subsystemdir/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep`   
+   echo "ccfile: "$ccfile
+   if [ "$ccfile" = "" ]
+   then
+      echo "no ccfile found for run "$runno
+      continue
+   fi
+   for (( i = 0; i <= 10; i++ ))
+   do 
+      newrun=`echo $runno - $i | bc`
+      path=`dirname $ccfile`
+      path=`echo $path | sed -e 's/cc/caco/'`
+      cacofile=`find $path -name *$newrun*`
+      if [ "$cacofile" = "" ]
+      then
+         continue
+      else
+         echo "inserting cacofile $file for run $missingcacorun..."
+         check2=`root -q -b $macrospath/insertcacofile.C+\("\"$runno\""\,"\"$newrun\""\) | tee $logpath/insertcacofile-$missingcacorun.log | grep int | sed -e 's/(int)//'`
+
+         case $check2 in
+            1)   echo "check2=$check2 -> everthing ok -> insert is done";;
+            *)   echo "check2=$check2 -> ERROR -> something went wrong while inserting run "$missingcacorun;;
+         esac
+         break
+      fi
+   done
+   echo "cacofile: "$cacofile
+
+done
+
+
+
+echo "checking disk for rawfiles..." 
+
+filename=$logpath/rawfilesondisk-$date.txt
+column=fRawFileAvail
+
+find $rawdir -name '*.raw' | cut -d_ -f2 > $filename
+
+echo "resetting runs..."                                    
+check4=`root -q -b $macrospath/resetallruns.C+\("\"$filename\""\,"\"$column\""\) | tee $logpath/resetall-$column-$date.log | grep int | sed -e 's/(int)//'` 
+
+case $check4 in 
+   1)   echo "check4=$check4 -> everthing ok -> reset is done";;
+   *)   echo "check4=$check4 -> ERROR -> something went wrong while resetting";;
+esac
+
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/fillcallisto
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/fillcallisto	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/fillcallisto	(revision 6934)
@@ -0,0 +1,173 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+
+table=SequenceProcessStatus
+column=fFillCallisto
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column.txt
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/fillcallisto/$year
+getstatuslog=$getstatuslogpath/getstatus-fillcallisto-$datetime.log
+
+scriptlogpath=$logpath/run/fillcallisto/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/runfillcallisto-$datetime.log
+
+date >> $scriptlog 2>&1
+
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+cd $mars
+
+date > $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> fillcallisto is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+echo "getting list..." >> $scriptlog 2>&1
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+    1)   echo "check0=$check0 -> everthing ok -> run fillcallisto" >> $scriptlog 2>&1;;
+    *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+esac
+
+sequences=(`cat $todofile`)
+
+if [ "$sequences" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile >> $scriptlog 2>&1
+   rm -v $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
+
+for sequence in ${sequences[@]}
+do 
+   no=`printf %08d $sequence | cut -c 4`
+   path="/magic/data/callisto/"`printf %04d $no`"/"`printf %08d $sequence`
+   signalfile=$path/signal`printf %08d $sequence`.root
+   calibfile=$path/calib`printf %08d $sequence`.root
+   fillcallistologpath=$logpath/fillcallisto/`printf %04d $no`
+   echo "fillcallistologpath: "$fillcallistologpath >> $scriptlog 2>&1
+   if [ ! -d $fillcallistologpath ]
+   then
+     mkdir -pv $fillcallistologpath >> $scriptlog 2>&1
+     if [ ! -d $fillcallistologpath ]
+     then
+        echo "could not make fillcallistologpath $fillcallistologpath -> continue " >> $scriptlog 2>&1
+        continue
+     fi
+   fi
+   fillcaliblog=$fillcallistologpath/fillcalib-$sequence.log
+   fillsignallog=$fillcallistologpath/fillsignal-$sequence.log
+
+   echo "run fillcallisto for sequence $sequence" >> $scriptlog 2>&1
+   echo "run fillcalib..." >> $scriptlog 2>&1
+   check1=`root -q -b $macrospath/fillcalib.C+\("\"$calibfile\""\,kFALSE\) | tee $fillcaliblog | grep int | sed -e 's/(int)//'`
+
+   case $check1 in
+      1)   echo "check1=$check1 -> everthing ok -> run fillsignal " >> $scriptlog 2>&1;;
+      *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+           continue;;
+   esac
+
+   check2=`root -q -b $macrospath/fillsignal.C+\("\"$signalfile\""\,kFALSE\) | tee $fillsignallog | grep int | sed -e 's/(int)//'`
+   case $check2 in
+      1)   echo "check2=$check2 -> everthing ok " >> $scriptlog 2>&1
+           echo "-> inserting the status for fillcallisto for sequence $sequence into the db" >> $scriptlog 2>&1
+           setstatuslogpath=$logpath/setstatus/fillcallisto/`printf %04d $no`
+           if [ ! -d $setstatuslogpath ]
+           then
+             mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+             if [ ! -d $setstatuslogpath ]
+             then
+                echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+                continue
+             fi
+           fi
+           setstatuslog=$setstatuslogpath/setstatus-fillcallisto
+           check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
+           case $check4 in
+   	     1)   echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
+   	     *)   echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
+           esac
+   	  ;;
+      *)   echo "check2=$check2 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+done
+
+rm -v $todofile >> $scriptlog 2>&1
+rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runcallisto
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runcallisto	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runcallisto	(revision 6934)
@@ -0,0 +1,305 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+callistorcnew=/magic/datacenter/setup/callisto/callisto.rc
+
+table=SequenceProcessStatus
+column=fCallisto
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+pno=8 # number of processes, i.e. number of todo-files
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/callisto/$year
+getstatuslog=$getstatuslogpath/getstatus-callisto-$datetime.log
+
+scriptlogpath=$logpath/run/callisto/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/runcallisto-$datetime.log
+
+date >> $scriptlog 2>&1
+
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+cd $mars
+
+date > $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> getting list for callisto is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+echo "checking if other todo-files are there" >> $scriptlog 2>&1
+if  ls $todofile-[1-9].txt >> $scriptlog 2>&1
+then 
+   echo "other file(s) on disk " >> $scriptlog 2>&1
+   echo " -> choose one file and start calibrating" >> $scriptlog 2>&1
+else
+#   echo "run checkfilesforsequenceavail" >> $scriptlog 2>&1
+#   $scriptspath/checkfilesforsequenceavail
+   
+   echo "getting list..." >> $scriptlog 2>&1
+   check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+   
+   case $check0 in 
+       1)   echo "check0=$check0 -> everthing ok -> run callisto" >> $scriptlog 2>&1;;
+       *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+   echo "cutting to-do-file" >> $scriptlog 2>&1
+   echo "getting no of lines" >> $scriptlog 2>&1
+   lines=`cat $todofile.txt | wc -l`
+   echo "number of lines: "$lines >> $scriptlog 2>&1
+   nofiles=`expr $lines / \( $pno - 1 \)`
+   echo "number of files: "$nofiles >> $scriptlog 2>&1
+   echo "deviding todo-file" >> $scriptlog 2>&1
+   for (( j=1 ; j <= $pno ; j++ ))
+   do 
+     begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
+     end=$(echo "$begin + $nofiles - 1" | bc -l)
+     echo "begin: "$begin >> $scriptlog 2>&1
+     echo "end: "$end >> $scriptlog 2>&1
+     file=${todofile}-${j}.txt
+     echo "file: "$file >> $scriptlog 2>&1
+     sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
+   done
+
+   rm -v $todofile.txt >> $scriptlog 2>&1
+fi
+
+rm -v $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
+
+nr=bla
+echo "finding the right todo-file" >> $scriptlog 2>&1
+for (( i = 1; i <= $pno ; i++ ))
+do 
+   if ! ls $todofile-$i.txt >> $scriptlog 2>&1
+   then 
+      echo "file is not on disk -> continue" >> $scriptlog 2>&1
+      continue
+   fi
+   date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
+   checklock=$?
+   case $checklock in 
+       0)   echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
+            nr=${i}
+            break;;
+       1)   echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
+       *)   echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
+   esac
+done
+
+case $nr in
+   bla)      echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
+             date  >> $scriptlog 2>&1
+             exit;;
+   12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
+esac
+
+
+sequences=(`cat $todofile-$nr.txt`)
+
+if [ "$sequences" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile-$nr.txt >> $scriptlog 2>&1
+   rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
+
+for sequence in ${sequences[@]}
+do 
+  no=`printf %08d $sequence | cut -c 4`
+  outpath="/magic/data/callisto/"`printf %04d $no`"/"`printf %08d $sequence`
+  echo "outpath: "$outpath >> $scriptlog 2>&1
+  if [ ! -d $outpath ]
+  then
+    mkdir -pv $outpath >> $scriptlog 2>&1
+    if [ ! -d $outpath ]
+    then 
+       echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
+       continue
+    fi
+  fi
+  sequfile="/magic/sequences/"`printf %04d $no`"/sequence"`printf %08d $sequence`".txt"
+  echo "sequfile: "$sequfile >> $scriptlog 2>&1
+  
+  if [ -e $outpath/callisto.rc ]
+  then
+     echo "found callisto.rc in $outpath -> using this " >> $scriptlog 2>&1
+     callistorcseq=$outpath/callisto.rc
+  else
+     echo "no callisto.rc found in $outpath -> making link " >> $scriptlog 2>&1
+     ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
+     callistorcseq=$outpath/callisto.rc
+  fi
+
+  echo "run callisto..." >> $scriptlog 2>&1
+  ./callisto -b -q -f -raw --log=$outpath/callisto$sequence.log --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null
+  check1=$?
+
+  case $check1 in
+     0)   echo "check1=$check1 -> everthing ok -> doing update..." >> $scriptlog 2>&1
+          echo "finding files to be updated" >> $scriptlog 2>&1
+          calfiles=`find $outpath -name *_Y_* `
+          echo "files to be updated: "$calfiles >> $scriptlog 2>&1
+          if [ "$calfiles" = "" ]
+          then 
+             echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
+             continue
+          fi
+          
+          merpplogpath=$outpath"/merpplogs"
+          if [ ! -d $merpplogpath ]
+          then
+            mkdir -pv $merpplogpath >> $scriptlog 2>&1
+            if [ ! -d $merpplogpath ]
+            then
+               echo "could not make merpplogpath "$merpplogpath >> $scriptlog 2>&1
+               continue
+            fi
+          fi
+          
+          for calfile in ${calfiles[@]}
+          do 
+             echo "calfile: "$calfile >> $scriptlog 2>&1
+             runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
+             ccfile=`find /magic/subsystemdata/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep`
+             cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
+             echo "runno: "$runno >> $scriptlog 2>&1
+             echo "ccfile: "$ccfile >> $scriptlog 2>&1
+             if [ "$ccfile" = "" ]
+             then
+                echo "no ccfile found for run "$runno >> $scriptlog 2>&1
+                break
+             fi
+             echo "cacofile: "$cacofile >> $scriptlog 2>&1
+             if [ "$cacofile" = "" ]
+             then 
+                echo "no cacofile found for run "$runno >> $scriptlog 2>&1
+                echo "finding cacofile..." >> $scriptlog 2>&1
+                for (( i = 0; i <= 10; i++ ))
+                do 
+                   newrun=`echo $runno - $i | bc`
+            #      echo "$missingcacorun + $i = $newrun"
+                   path=`dirname $ccfile`
+                   path=`echo $path | sed -e 's/cc/caco/'`
+                   echo "path: "$path >> $scriptlog 2>&1
+                   cacofile=`find $path -name *$newrun*`
+                   if [ "$cacofile" = "" ]
+                   then
+                      continue
+                   else
+                      break
+                      echo "cacofile: "$cacofile >> $scriptlog 2>&1
+                   fi
+                done
+             fi
+             ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
+             check2=$?
+             case $check2 in
+                     0)   echo "check2=$check2 -> everthing ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
+         	     *)   echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
+                          continue 2 ;;
+             esac
+             ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
+             check3=$?
+             case $check3 in
+                     0)   echo "check3=$check3 -> everthing ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
+         	     *)   echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
+                          continue 2 ;;
+             esac
+          done
+          
+          echo "inserting the status for callisto for sequence $sequence into the db" >> $scriptlog 2>&1
+          setstatuslogpath=$logpath/setstatus/callisto/`printf %04d $no`
+          if [ ! -d $setstatuslogpath ]
+          then
+            mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+            if [ ! -d $setstatuslogpath ]
+            then 
+               echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+               continue
+            fi
+          fi
+          setstatuslog=$setstatuslogpath/setstatus-callisto
+          check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
+          case $check4 in
+  	     1)   echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
+  	     *)   echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
+          esac
+  	  ;;
+     *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+  esac
+done
+
+rm -v $todofile-$nr.txt >> $scriptlog 2>&1
+rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runstar
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runstar	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runstar	(revision 6934)
@@ -0,0 +1,222 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+
+table=SequenceProcessStatus
+column=fStar
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+pno=8 # number of processes, i.e. number of todo-files
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/star/$year
+getstatuslog=$getstatuslogpath/getstatus-star-$datetime.log
+
+scriptlogpath=$logpath/run/star/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/runstar-$datetime.log
+
+date >> $scriptlog 2>&1
+
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+cd $mars
+
+date > $lockpath/lock-getting-star-list.txt >> $scriptlog 2>&1
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> getting list for star is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+echo "checking if other todo-files are there" >> $scriptlog 2>&1
+if  ls $todofile-[1-9].txt >> $scriptlog 2>&1
+then 
+   echo "other file(s) on disk " >> $scriptlog 2>&1
+   echo " -> choose one file and start calculation of image parameter" >> $scriptlog 2>&1
+else
+   echo "getting list..." >> $scriptlog 2>&1
+   check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+   
+   case $check0 in 
+       1)   echo "check0=$check0 -> everthing ok -> run star" >> $scriptlog 2>&1;;
+       *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+   echo "cutting to-do-file" >> $scriptlog 2>&1
+   echo "getting no of lines" >> $scriptlog 2>&1
+   lines=`cat $todofile.txt | wc -l`
+   echo "number of lines: "$lines >> $scriptlog 2>&1
+   nofiles=`expr $lines / \( $pno - 1 \)`
+   echo "number of files: "$nofiles >> $scriptlog 2>&1
+   echo "deviding todo-file" >> $scriptlog 2>&1
+   for (( j=1 ; j <= $pno ; j++ ))
+   do 
+     begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
+     end=$(echo "$begin + $nofiles - 1" | bc -l)
+     echo "begin: "$begin >> $scriptlog 2>&1
+     echo "end: "$end >> $scriptlog 2>&1
+     file=${todofile}-${j}.txt
+     echo "file: "$file >> $scriptlog 2>&1
+     sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
+   done
+
+   rm -v $todofile.txt >> $scriptlog 2>&1
+fi
+
+rm -v $lockpath/lock-getting-star-list.txt >> $scriptlog 2>&1
+
+nr=bla
+echo "finding the right todo-file" >> $scriptlog 2>&1
+for (( i = 1; i <= $pno ; i++ ))
+do 
+   if ! ls $todofile-$i.txt >> $scriptlog 2>&1
+   then 
+      echo "file is not on disk -> continue" >> $scriptlog 2>&1
+      continue
+   fi
+   date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1 
+   checklock=$?
+   case $checklock in 
+       0)   echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
+            nr=${i}
+            break;;
+       1)   echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
+       *)   echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
+   esac
+done
+
+case $nr in
+   bla)      echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
+             date  >> $scriptlog 2>&1
+             exit;;
+   12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
+esac
+
+
+sequences=(`cat $todofile-$nr.txt`)
+
+if [ "$sequences" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile-$nr.txt >> $scriptlog 2>&1
+   rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
+
+for sequence in ${sequences[@]}
+do 
+  no=`printf %08d $sequence | cut -c 4`
+  outpath="/magic/data/star/"`printf %04d $no`"/"`printf %08d $sequence`
+  inpath=`echo $outpath | sed -e 's/star/callisto/'`
+  echo "inpath: "$inpath >> $scriptlog 2>&1
+  echo "outpath: "$outpath >> $scriptlog 2>&1
+  if [ ! -d $outpath ]
+  then
+    mkdir -pv $outpath >> $scriptlog 2>&1
+    if [ ! -d $outpath ]
+    then 
+       echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
+       continue
+    fi
+  fi
+  sequfile="/magic/sequences/"`printf %04d $no`"/sequence"`printf %08d $sequence`".txt"
+  echo "sequfile: "$sequfile >> $scriptlog 2>&1
+  
+  echo "run star..." >> $scriptlog 2>&1
+  ./star -b -q -f --log=$outpath/star$sequence.log --ind=$inpath --out=$outpath $sequfile  2>> $scriptlog> /dev/null
+  check1=$?
+
+  case $check1 in
+     0)   echo "check1=$check1 -> everthing ok " >> $scriptlog 2>&1
+          echo "-> inserting the status for star for sequence $sequence into the db" >> $scriptlog 2>&1
+          setstatuslogpath=$logpath/setstatus/star/`printf %04d $no`
+          if [ ! -d $setstatuslogpath ]
+          then
+            mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+            if [ ! -d $setstatuslogpath ]
+            then 
+               echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+               continue
+            fi
+          fi
+          setstatuslog=$setstatuslogpath/setstatus-star
+          check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
+          case $check4 in
+  	     1)   echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
+  	     *)   echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
+          esac
+  	  ;;
+     *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+  esac
+done
+
+rm -v $todofile-$nr.txt >> $scriptlog 2>&1
+rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/writesequencefiles
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/writesequencefiles	(revision 6934)
+++ trunk/MagicSoft/Mars/datacenter/scripts/writesequencefiles	(revision 6934)
@@ -0,0 +1,159 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * 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): Daniela Dorner  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+export ROOTSYS=/opt/root_v3.10.02
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+set -C
+
+mars=/home/operator/Mars
+macrospath=$mars/datacenter/macros
+scriptspath=$mars/datacenter/scripts
+
+table=SequenceProcessStatus
+column=fSequenceFileWritten
+date=NULL
+datetime=`date +%F-%H-%M-%S`
+year=`date +%Y`
+
+todofile=/magic/datacenter/lists/ToDo-$table-$column.txt
+lockpath=/magic/datacenter/locks
+logpath=/magic/datacenter/autologs
+getstatuslogpath=$logpath/getstatus/writesequencefiles/$year
+getstatuslog=$getstatuslogpath/getstatus-writesequencefiles-$datetime.log
+
+scriptlogpath=$logpath/run/writesequencefiles/`date +%Y/%m/%d`
+if [ ! -d $scriptlogpath ]
+then
+  mkdir -pv $scriptlogpath 
+  if [ ! -d $scriptlogpath ]
+  then 
+     echo "could not make scriptlogpath "$scriptlogpath 
+     exit
+  fi
+fi
+
+scriptlog=$scriptlogpath/runwritesequencefiles-$datetime.log
+
+date >> $scriptlog 2>&1
+
+
+if [ ! -d $getstatuslogpath ]
+then
+  mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
+  if [ ! -d $getstatuslogpath ]
+  then 
+     echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
+     date  >> $scriptlog 2>&1
+     exit
+  fi
+fi
+
+cd $mars
+
+date > $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> writesequencefiles is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+echo "getting list..." >> $scriptlog 2>&1
+check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
+
+case $check0 in 
+    1)   echo "check0=$check0 -> everthing ok -> run writesequencefiles" >> $scriptlog 2>&1;;
+    *)   echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+esac
+
+sequences=(`cat $todofile`)
+
+if [ "$sequences" = "" ]
+then 
+   echo "nothing to do -> exit"  >> $scriptlog 2>&1
+   rm -v $todofile >> $scriptlog 2>&1
+   rm -v $lockpath/lock-$table-$column.txt >> $scriptlog 2>&1
+   date  >> $scriptlog 2>&1
+   exit
+fi
+
+echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
+
+for sequence in ${sequences[@]}
+do 
+   no=`printf %08d $sequence | cut -c 4`
+   writesequencefilelogpath=$logpath/writesequencefile/`printf %04d $no`
+   echo "writesequencefilelogpath: "$writesequencefilelogpath >> $scriptlog 2>&1
+   if [ ! -d $writesequencefilelogpath ]
+   then
+     mkdir -pv $writesequencefilelogpath >> $scriptlog 2>&1
+     if [ ! -d $writesequencefilelogpath ]
+     then
+        echo "could not make writesequencefilelogpath $writesequencefilelogpath -> continue " >> $scriptlog 2>&1
+        continue
+     fi
+   fi
+
+   echo "write sequencefile for sequence $sequence" >> $scriptlog 2>&1
+   check2=`root -q -b $macrospath/writesequencefile.C+\($sequence\) | tee $writesequencefilelogpath/writesequencefile-$sequence.log | grep int | sed -e 's/(int)//'`
+   case $check2 in
+      1)   echo "check2=$check2 -> everthing ok " >> $scriptlog 2>&1
+           echo "-> inserting the status for writesequencefile for sequence $sequence into the db" >> $scriptlog 2>&1
+           setstatuslogpath=$logpath/setstatus/writesequencefile/`printf %04d $no`
+           if [ ! -d $setstatuslogpath ]
+           then
+             mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
+             if [ ! -d $setstatuslogpath ]
+             then
+                echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
+                continue
+             fi
+           fi
+           setstatuslog=$setstatuslogpath/setstatus-writesequencefile
+           check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
+           case $check4 in
+   	     1)   echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
+   	     *)   echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
+           esac
+   	  ;;
+      *)   echo "check2=$check2 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+done
+
+rm -v $todofile >> $scriptlog 2>&1
+rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
