Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7452)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7453)
@@ -23,6 +23,14 @@
      - fixed condition for removing lock-file
 
+   * datacenter/scripts/dowebplots:
+     - improved new procedure
+     - added removing of old files
+     - added documentation
+
    * datacenter/scripts/linkmc:
      - improved handling of directories
+     - added new mode
+     - added documentation
+     - simplyfied check for C and P link
 
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/dowebplots
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/dowebplots	(revision 7452)
+++ trunk/MagicSoft/Mars/datacenter/scripts/dowebplots	(revision 7453)
@@ -35,4 +35,5 @@
 
 datetime=`date +%F-%H-%M-%S`
+webdir=/www/htdocs/datacenter
 
 scriptlogpath=$logpath/run/dowebplots/`date +%Y/%m/%d`
@@ -56,7 +57,9 @@
 
 
+#finding all rootfiles in the webdirectory 
+#this are all statusdisplays 
+rootfiles=`find $webdir/{sinope,callisto,star,ganymed}/ -name '*.root' -maxdepth 10 | grep -v '_I_' | grep -v '_Y_' | grep -v 'subsystemdata' | grep -v 'star_lapalma'`
 
-rootfiles=`find /www/htdocs/datacenter/ -name '*.root' -maxdepth 10 | grep -v '_I_' | grep -v '_Y_' | grep -v 'subsystemdata' | grep -v 'star_lapalma'`
-
+#exit if no rootfiles are found
 if [ "$rootfiles" = "" ]
 then 
@@ -67,13 +70,18 @@
 fi
 
-echo "rootfiles: "${rootfiles[@]} >> $scriptlog 2>&1
 
+#produce plots for each rootfile
 for rootfile in ${rootfiles[@]}
 do 
    date >> $scriptlog 2>&1
-   psfile=`echo $file | sed -e 's/.root$/.ps/g'`
+   #get names of the psfile and the 
+   #pngfiles (1 per tab in the statusdiplay)
+   psfile=`echo $rootfile | sed -e 's/.root$/.ps/g'`
+   tabfile=`echo $rootfile | sed -e 's/.root$/-tab/g'`
    echo "rootfile: $rootfile" >> $scriptlog 2>&1
-   echo "psfile:   $psfile" >> $scriptlog 2>&1
+   echo "psfile:   $psfile"   >> $scriptlog 2>&1
+   echo "tabfile:  $tabfile"  >> $scriptlog 2>&1
    
+   #get date of root- and psfile
    daterootfile=`date +%Y%m%d -r $rootfile` >> $scriptlog 2>&1
    datepsfile=`date +%Y%m%d -r $psfile` >> $scriptlog 2>&1
@@ -89,4 +97,6 @@
    echo "date of psfile:   $datepsfile"   >> $scriptlog 2>&1
 
+   #if the psfile is newer than the rootfile
+   #no plots have to be done -> continue
    if [ "$datepsfile" -gt "$daterootfile" ] >> $scriptlog 2>&1
    then
@@ -99,5 +109,39 @@
 
    echo "converting plots to png..." >> $scriptlog 2>&1
-   pstoimg -antialias -flip r270 -density 100 -type png -multipage $psfile >> $scriptlog 2>&1
+   pstoimg -antialias -flip r270 -density 100 -type png -multipage -out=$tabfile$psfile >> $scriptlog 2>&1
+done
+
+echo "removing old files" >> $scriptlog 2>&1 
+#make sure, that old plots of files, that are already removed from disk, 
+#  are deleted also in the webdirectory
+#this has to be done, as ps and png files are excluded from rsync, 
+#as rsync is done with --delete option (script /home/operator/condor/webupdate
+
+#find all directories with plots
+dirs=`find $webdir/{star,callisto,ganymed,sinope}/* -type d | grep -v merpplogs`
+
+for dir in ${dir[@]}
+do
+   #find psfiles in directory
+   psfiles=`ls $dir/*.ps`
+   #continue, if there are no psfiles
+   if [ "$psfiles" == "" ]
+   then 
+      continue
+   fi
+   
+   for psfile in ${psfiles[@]}
+   do
+      #create name of corresponding rootfile
+      rootfile=`echo $psfile | sed -e 's/.ps$/.root/g'`
+      #delete ps and pngfiles if rootfile is not existing
+      if ! ls $rootfile >> $scriptlog 2>&1 
+      then 
+         echo "deleting old plots for $rootfile..." >> $scriptlog 2>&1 
+         path=`dirname $psfile`
+         rm -v $psfile >> $scriptlog 2>&1 
+         rm -v $path/*.png >> $scriptlog 2>&1 
+      fi
+   done
 done
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/linkmc
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/linkmc	(revision 7452)
+++ trunk/MagicSoft/Mars/datacenter/scripts/linkmc	(revision 7453)
@@ -53,8 +53,7 @@
 mccampath=/montecarlo/camera
 mcpath=/montecarlo/rawfiles
-next=$mcpath/.next
-processed=$mcpath/.processed
-processeddir=$mcpath/.processed.dir
-readme=$mcpath/README.txt
+next=$mcpath/.next #in .next the next runno is stored
+processed=$mcpath/.processed #in .processed the linked files are stored
+readme=$mcpath/README.txt #file in which the information about the modes is redirected to have always an updated explanation
 
 if ! ls $next >> $scriptlog 2>&1
@@ -68,5 +67,8 @@
 
 
-modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Proton" "DiffuseGamma" )
+modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Gammadiffuse0" "Protonnowobble0" )
+
+#be carful: 
+# w- not yet foreseen in this script
 
 echo "" >> $readme 2>&1
@@ -101,31 +103,35 @@
 
 
+#get runnumber
 runno=`cat $next`
 
+#get files, which have to be linked
 camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
 
 for camfile in ${camfiles[@]}
 do 
+   #continue, if file is already linked 
    if grep $camfile $processed >> $scriptlog 2>&1
    then 
       continue
    fi
-   file=`basename $camfile`
-   no=`printf %08d $runno | cut -c 0-5`
-#   no2=`printf %08d $runno`
+   file=`basename $camfile` #filename
+   no=`printf %08d $runno | cut -c 0-5` #first 5 digits of a 8digit runno -> for path
+#   no2=`printf %08d $runno` #runno with 8 digits
 # workaround due to 5digit runnumber for data with runnumber < 35487
    no2=`printf %05d $runno`
-   zbin=`echo $file | cut -d_ -f2 | cut -c 5-6`
-   zbin=`printf %02d $zbin`
-   wobble=`echo $file | cut -d_ -f6 | cut -c 2`
-   particle=`echo $file | cut -d_ -f1`
-   psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8`
-   
-   particledir=`echo $camfile | cut -d/ -f4`
-   wobbledir=`echo $camfile | cut -d/ -f6`
-   
+   zbin=`echo $file | cut -d_ -f2 | cut -c 5-6` #zbin from filename 
+   zbin=`printf %02d $zbin` #2digit
+   wobble=`echo $file | cut -d_ -f6 | cut -c 2` #mode from filename
+   particle=`echo $file | cut -d_ -f1` #particle type from filename
+   psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8` #psf from path
+   
+   particledir=`echo $camfile | cut -d/ -f4` #particletype from path
+   wobbledir=`echo $camfile | cut -d/ -f6` #mode from path
+   
+   #build mode name
    testmode=$particle$wobbledir$wobble 
-#   echo "testmode:"$testmode >> $scriptlog 2>&1
-
+
+   #get mode extension for filename
    case $wobble in 
        0)   wobblemode="";;
@@ -136,9 +142,9 @@
    esac
    
+   #get no of mode from array $modes
    for (( i=1 ; i <= 12 ; i++ )) 
    do 
        if [ "${modes[$i]}" == "$testmode" ]
        then 
-#          echo "modes[$i]=${modes[$i]}" >> $scriptlog 2>&1
           totalmode=$i
           break
@@ -146,16 +152,18 @@
    done
 
-   totalmode=`printf %02d $totalmode`
-#   echo "totalmode: "$totalmode >> $scriptlog 2>&1
-
-   project=${particle}${zbin}${wobblemode}
+   totalmode=`printf %02d $totalmode` #2 digits
+
+   project=${particle}${zbin}${wobblemode} #build project name
+   #create new filename
    newfile="$mcpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
    newdir=`dirname $newfile`
    makedir $newdir >> $scriptlog 2>&1
 
-   runno=`expr $runno + 1`
+   runno=`expr $runno + 1` #next runnumber
    echo $runno >| $next 
 
-   ln -sv $camfile $newfile >> $scriptlog 2>&1
+   #link file
+   ln -sv $camfile $newfile >> $scriptlog 2>&1 
+   #add filename to processed file
    echo $camfile >> $processed
 
@@ -163,8 +171,10 @@
 
 echo "linking cal and ped file" >> $scriptlog 2>&1
+#get files
 pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
 calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
 echo "calfile"$calfile >> $scriptlog 2>&1
 echo "pedfile"$pedfile >> $scriptlog 2>&1
+#check number of files
 numfiles=`echo $pedfile $calfile | wc -w`
 if [ "$numfiles" != "2" ]
@@ -175,13 +185,17 @@
 fi
 
+#get all directories in the linked structure
 dirs=`find $mcpath -type d`
 
 for dir in ${dirs[@]}
 do 
-   if grep $dir $processeddir >> $scriptlog 2>&1
+   #continue, if directory has already linked C and P run
+   $cont=`ls $dir/*_0000[12]_[CP]_MonteCarlo_E.root | wc -w`
+   if [ "$cont" == "2" ] >> $scriptlog 2>&1
    then 
       continue
    fi
 
+   #continue, if directory is not at the lowest level of the structure
    cont=`echo $dir | cut -d/ -f6`
    if [ "$cont" == "" ]
@@ -190,5 +204,8 @@
    fi
 
+   #get date for filename from directory name
    date=`echo $dir | cut -c 22-25,27,28,30,31`
+   
+   #create new filenames and link files
 # workaround due to 5digit runnumber for data with runnumber < 35487
 #   newcalfile="${dir}/${date}_00000001_C_MonteCarlo_E.root"
@@ -199,5 +216,4 @@
    newpedfile="${dir}/${date}_00002_P_MonteCarlo_E.root"
    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
-   echo $dir >> $processeddir
 done
 
