Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8233)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8234)
@@ -20,5 +20,5 @@
  2006/12/13 Thomas Bretz, Daniela Dorner, Stefan Ruegamer
  
-   * scripts/movingrawfiles:
+   * datacenter/scripts/movingrawfiles:
      - added check if the number of rawfiles in the database matches the
        number of rawfiles in the fromlapalma/RAW/-folder. If not, the
Index: trunk/MagicSoft/Mars/datacenter/scripts/movingrawfiles
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/movingrawfiles	(revision 8233)
+++ trunk/MagicSoft/Mars/datacenter/scripts/movingrawfiles	(revision 8234)
@@ -25,6 +25,6 @@
 # ========================================================================
 #
-# This script is moving the rawfiles from the directory 
-# /magic/datacenter/fromtape/rawdata to the structure 
+# This script is moving the rawfiles from the directory
+# /magic/datacenter/fromtape/rawdata to the structure
 # /magic/data/rawfiles/YYYY/MM/DD
 # 
@@ -40,21 +40,64 @@
 date >> $scriptlog 2>&1
 
-# check if script is already running
+# check whether script is already running
 lockfile=$lockpath/lock-$program.txt
 checklock  >> $scriptlog 2>&1
 
-# change permission for files 
+# change permission for files
 ssh tape@dc07 chmod -R g+w /magic/datacenter/fromtape/rawdata/* >> $scriptlog 2>&1
 # output for chmod with -v or -c (only changes)
 
 printprocesslog "INFO moving directories from fromlapalma to fromtape"
-#find directories, which have to be copied
+#find directories which have to be copied
 dirs=`ls /magic/datacenter/fromlapalma/RAWchk/*/*.finished | sed -e 's/RAWchk/RAW/g' | cut -d/ -f1-6`
 if [ ! "$dirs" == "" ]
 then
-   # change permission for this dirctories
-   ssh lapalma@apollo chmod -R g+w $dirs >> $scriptlog 2>&1
-   # move directories to the tapedirectory
-   mv -v $dirs /magic/datacenter/fromtape/rawdata/ >> $scriptlog 2>&1 
+   for dir in $dirs
+   do
+      # get number of *.raw files from directory
+      numfiles=`find $dir -type f -name "*.raw" | wc -l`
+      
+      # skip empty directories
+      if [ "$numfiles" == "0" ]
+      then
+         continue
+      fi
+
+      # get date from directory name
+      curdate=`echo $dir | cut -d/ -f6- | sed -e 's/_/-/g'`
+      
+      getdbsetup
+      # get number of runs on this date from db
+      query="select COUNT(*) from RunData where ADDDATE(fRunStart, Interval 12 hour) like '$curdate %'"
+
+      if ! numruns=`mysql -s -u $us --password=$pw --host=hercules $db -e "$query" | tail -1`
+      then
+         echo "ERROR could not query number of runs from rundb -> continue" >> $scriptlog 2>&1 
+         printprocesslog "ERROR could not query number of runs for $curdate from rundb"
+         continue
+      fi
+
+      # Check if number of runs matches. If not, skip this directory
+      if ! [ $numfiles -eq $numruns ]
+      then
+         echo "WARNING" >> $scriptlog 2>&1 
+         echo "Expecting $numruns raw-files for $curdate but found only $numfiles" >> $scriptlog 2>&1 
+         continue
+      fi
+
+      # check for non-raw-files
+      nonraw=`find $dir -type f ! -name "*.raw"`
+      if [ ! "$nonraw" == "" ]
+      then
+         echo "non-raw-files found in $dir" >> $scriptlog 2>&1 
+         printprocesslog "WARNING non-raw-files found in $dir"
+      fi
+
+      # change permission for this directory
+      ssh lapalma@apollo chmod -R g+w $dir >> $scriptlog 2>&1
+      # move directories to the tapedirectory
+      mv -v $dir /magic/datacenter/fromtape/rawdata/ >> $scriptlog 2>&1 
+
+   done
 fi
 
