#!/bin/csh

set DST_PATH = "/mnt/pool/rhic/4/parfenovpeter/mpd_data/7.7gev_READY/reco/mpddst_reduced_9781283_[0-2][0-9].root"
set MAX_DST_PER_JOB = 5

set MASK_LIST = "dstList"
set MASK_JOB  = "job"
set MASK_OUT  = "out"

set DST_COUNTER = 0
set JOB_COUNTER = 0

set QUERY = "short"

foreach dstFile ( $DST_PATH )
    @ DST_COUNTER = $DST_COUNTER + 1
    echo "$dstFile" >> "${MASK_LIST}_${JOB_COUNTER}.list"
    if ( $DST_COUNTER == $MAX_DST_PER_JOB ) then
        set DST_COUNTER = 0
        @ JOB_COUNTER = $JOB_COUNTER + 1
        cat > "${MASK_JOB}_${JOB_COUNTER}.sh" << EOF
#!/bin/bash
cd $PWD
root.exe -b -q RealFlow.C\(\"${MASK_LIST}_${JOB_COUNTER}.list\",\"${MASK_OUT}_${JOB_COUNTER}.root\"\)
EOF
    qsub -q $QUERY "${MASK_JOB}_${JOB_COUNTER}.sh"
    endif
end
