#!/bin/csh

########################################
##                                    ##
## csh script to generate scripts     ##
## for converting f19 to root files   ##
##                                    ##
########################################


# initial variables
set Oscar2RootDir = "/home/mrworm/my_star/source/Oscar97Tree"
set RunDir = "$PWD"
set ListFormat = "list_*"
#

# main code

echo "Running in directory $RunDir..."

set counter = 0

foreach iFile (`ls $ListFormat`)
    cat > f19_launch_$counter.sh << EOF
#!/bin/bash

cd $RunDir
ln -s $Oscar2RootDir/Oscar97Tree.C
ln -s $Oscar2RootDir/Oscar97Track_cxx.so
ln -s $Oscar2RootDir/Oscar97Track_cxx.d
ln -s $Oscar2RootDir/Oscar97Event_cxx.so
ln -s $Oscar2RootDir/Oscar97Event_cxx.d
ln -s $Oscar2RootDir/Oscar97Tree_cxx.so
ln -s $Oscar2RootDir/Oscar97Tree_cxx.d

root.exe Oscar97Tree.C\(\"$iFile\",\"out_$counter.root\"\)

EOF

RETRY_QSUB:
    qsub f19_launch_$counter.sh
    if ($? != "0") then
        echo "Failed to submit job $counter, retrying..."
        goto RETRY_QSUB
    endif

    qsub f19_launch_$counter.sh
    @ counter++ 
end
