#!/bin/sh
# Reference: Unix Power Tools 9.14, p.143
# Usage:
# ftpfile machine file
# set -x
mcleanup
rm -f *.dat
rm -f *.rz
rm -f *.gz

#/scratch10/data00/ 30150 30409
year=00
n1=150
n2=409
s=10
base=30000
while [ $n1 -lt $n2 ]
do
r0=`expr $n1 + $base`
r1=`expr $r0 + 1`
r2=`expr $r0 + 2`
r3=`expr $r0 + 3`
r4=`expr $r0 + 4`
r5=`expr $r0 + 5`
r6=`expr $r0 + 6`
r7=`expr $r0 + 7`
r8=`expr $r0 + 8`
r9=`expr $r0 + 9`
F0=run$r0.mid
F1=run$r1.mid
F2=run$r2.mid
F3=run$r3.mid
F4=run$r4.mid
F5=run$r5.mid
F6=run$r6.mid
F7=run$r7.mid
F8=run$r8.mid
F9=run$r9.mid
echo $r0
echo $r9
echo $F0
echo $F9

echo analyzer1 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}/data$year/run%5d.mid -o run$r0.rz

analyzer1 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}/data$year/run%5d.mid -o run$r0.rz

gzip *.dat

ssh node15 <<EOF

mv -f $HOME/analyzer$year/random.dat.gz /sm_local/pb_dst7/random/data/rand$r0.dat.gz
mv -f $HOME/analyzer$year/pibeta.dat.gz /sm_local/pb_dst7/pibeta/data/pb$r0.dat.gz
mv -f $HOME/analyzer$year/pienu.dat.gz /sm_local/pb_dst7/pienu/data/pienu$r0.dat.gz
mv -f $HOME/analyzer$year/pienug.dat.gz /sm_local/pb_dst7/rp/data/rp$r0.dat.gz
mv -f $HOME/analyzer$year/rmichel.dat.gz /sm_local/pb_dst7/rm/data/rm$r0.dat.gz
mv -f $HOME/analyzer$year/dalitz.dat.gz /sm_local/pb_dst7/dalitz/data/dal$r0.dat.gz
mv -f $HOME/analyzer$year/pibeam.dat.gz /sm_local/pb_dst7/beam/data/beam$r0.dat.gz
mv -f $HOME/analyzer$year/prompt.dat.gz /sm_local/pb_dst7/prompt/data/prompt$r0.dat.gz
mv -f $HOME/analyzer$year/michel.dat.gz /sm_local/pb_dst7/michel/data/mich$r0.dat.gz
mv -f $HOME/analyzer$year/mueee.dat.gz /sm_local/pb_dst7/mueee/data/mueee$r0.dat.gz
mv -f $HOME/analyzer$year/lfv.dat.gz /sm_local/pb_dst7/lfv/data/lfv$r0.dat.gz
mv -f $HOME/analyzer$year/mueg.dat.gz /sm_local/pb_dst7/mueg/data/mueg$r0.dat.gz
mv -f $HOME/analyzer$year/cosm.dat.gz /sm_local/pb_dst7/cosmics/data/cosm$r0.dat.gz

mv -f $HOME/analyzer$year/chamber_reso.dat.gz /sm_local/pb_dst7/chamber_reso/data/chamber_reso$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_all.dat.gz /sm_local/pb_dst7/tomo/data/tomo_all$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_pienu.dat.gz /sm_local/pb_dst7/tomo/data/tomo_pienu$r0.dat.gz
mv -f $HOME/analyzer$year/run$r0.rz /sm_local/pb_dst7/rz/data/run$r0.rz

exit
EOF
n1=`expr $n1 + 10`
date
sleep 1s
echo -----------------------------------------------
done

#/scratch10l/data00 35980 36130

year=00

n1=5980
n2=6130
s=10
base=30000
while [ $n1 -lt $n2 ]
do
r0=`expr $n1 + $base`
r1=`expr $r0 + 1`
r2=`expr $r0 + 2`
r3=`expr $r0 + 3`
r4=`expr $r0 + 4`
r5=`expr $r0 + 5`
r6=`expr $r0 + 6`
r7=`expr $r0 + 7`
r8=`expr $r0 + 8`
r9=`expr $r0 + 9`
F0=run$r0.mid
F1=run$r1.mid
F2=run$r2.mid
F3=run$r3.mid
F4=run$r4.mid
F5=run$r5.mid
F6=run$r6.mid
F7=run$r7.mid
F8=run$r8.mid
F9=run$r9.mid
echo $r0
echo $r9
echo $F0
echo $F9

echo analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}l/data$year/run%5d.mid -o run$r0.rz

analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}l/data$year/run%5d.mid -o run$r0.rz

gzip *.dat

ssh node15 <<EOF

mv -f $HOME/analyzer$year/random.dat.gz /sm_local/pb_dst7/random/data/rand$r0.dat.gz
mv -f $HOME/analyzer$year/pibeta.dat.gz /sm_local/pb_dst7/pibeta/data/pb$r0.dat.gz
mv -f $HOME/analyzer$year/pienu.dat.gz /sm_local/pb_dst7/pienu/data/pienu$r0.dat.gz
mv -f $HOME/analyzer$year/pienug.dat.gz /sm_local/pb_dst7/rp/data/rp$r0.dat.gz
mv -f $HOME/analyzer$year/rmichel.dat.gz /sm_local/pb_dst7/rm/data/rm$r0.dat.gz
mv -f $HOME/analyzer$year/dalitz.dat.gz /sm_local/pb_dst7/dalitz/data/dal$r0.dat.gz
mv -f $HOME/analyzer$year/pibeam.dat.gz /sm_local/pb_dst7/beam/data/beam$r0.dat.gz
mv -f $HOME/analyzer$year/prompt.dat.gz /sm_local/pb_dst7/prompt/data/prompt$r0.dat.gz
mv -f $HOME/analyzer$year/michel.dat.gz /sm_local/pb_dst7/michel/data/mich$r0.dat.gz
mv -f $HOME/analyzer$year/mueee.dat.gz /sm_local/pb_dst7/mueee/data/mueee$r0.dat.gz
mv -f $HOME/analyzer$year/lfv.dat.gz /sm_local/pb_dst7/lfv/data/lfv$r0.dat.gz
mv -f $HOME/analyzer$year/mueg.dat.gz /sm_local/pb_dst7/mueg/datamueg$r0.dat.gz
mv -f $HOME/analyzer$year/cosm.dat.gz /sm_local/pb_dst7/cosmics/data/cosm$r0.dat.gz

mv -f $HOME/analyzer$year/chamber_reso.dat.gz /sm_local/pb_dst7/chamber_reso/data/chamber_reso$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_all.dat.gz /sm_local/pb_dst7/tomo/data/tomo_all$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_pienu.dat.gz /sm_local/pb_dst7/tomo/data/tomo_pienu$r0.dat.gz
mv -f $HOME/analyzer$year/run$r0.rz /sm_local/pb_dst7/rz/data/run$r0.rz

exit
EOF
n1=`expr $n1 + 10`
date
sleep 1s
echo -----------------------------------------------
done

###########################################################
#/scratch10l/data00/longruns/ 361133 361169

year=00

n1=61130
n2=61169
s=10
base=300000
while [ $n1 -lt $n2 ]
do
r0=`expr $n1 + $base`
r1=`expr $r0 + 1`
r2=`expr $r0 + 2`
r3=`expr $r0 + 3`
r4=`expr $r0 + 4`
r5=`expr $r0 + 5`
r6=`expr $r0 + 6`
r7=`expr $r0 + 7`
r8=`expr $r0 + 8`
r9=`expr $r0 + 9`
F0=run$r0.mid
F1=run$r1.mid
F2=run$r2.mid
F3=run$r3.mid
F4=run$r4.mid
F5=run$r5.mid
F6=run$r6.mid
F7=run$r7.mid
F8=run$r8.mid
F9=run$r9.mid
echo $r0
echo $r9
echo $F0
echo $F9

echo analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}l/data$year/longruns/run%5d.mid -o run$r0.rz

analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}l/data$year/longruns/run%5d.mid -o run$r0.rz

gzip *.dat

ssh node15 <<EOF

mv -f $HOME/analyzer$year/random.dat.gz /sm_local/pb_dst7/random/data/rand$r0.dat.gz
mv -f $HOME/analyzer$year/pibeta.dat.gz /sm_local/pb_dst7/pibeta/data/pb$r0.dat.gz
mv -f $HOME/analyzer$year/pienu.dat.gz /sm_local/pb_dst7/pienu/data/pienu$r0.dat.gz
mv -f $HOME/analyzer$year/pienug.dat.gz /sm_local/pb_dst7/rp/data/rp$r0.dat.gz
mv -f $HOME/analyzer$year/rmichel.dat.gz /sm_local/pb_dst7/rm/data/rm$r0.dat.gz
mv -f $HOME/analyzer$year/dalitz.dat.gz /sm_local/pb_dst7/dalitz/data/dal$r0.dat.gz
mv -f $HOME/analyzer$year/pibeam.dat.gz /sm_local/pb_dst7/beam/data/beam$r0.dat.gz
mv -f $HOME/analyzer$year/prompt.dat.gz /sm_local/pb_dst7/prompt/data/prompt$r0.dat.gz
mv -f $HOME/analyzer$year/michel.dat.gz /sm_local/pb_dst7/michel/data/mich$r0.dat.gz
mv -f $HOME/analyzer$year/mueee.dat.gz /sm_local/pb_dst7/mueee/data/mueee$r0.dat.gz
mv -f $HOME/analyzer$year/lfv.dat.gz /sm_local/pb_dst7/lfv/data/lfv$r0.dat.gz
mv -f $HOME/analyzer$year/mueg.dat.gz /sm_local/pb_dst7/mueg/datamueg$r0.dat.gz
mv -f $HOME/analyzer$year/cosm.dat.gz /sm_local/pb_dst7/cosmics/data/cosm$r0.dat.gz

mv -f $HOME/analyzer$year/chamber_reso.dat.gz /sm_local/pb_dst7/chamber_reso/data/chamber_reso$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_all.dat.gz /sm_local/pb_dst7/tomo/data/tomo_all$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_pienu.dat.gz /sm_local/pb_dst7/tomo/data/tomo_pienu$r0.dat.gz
mv -f $HOME/analyzer$year/run$r0.rz /sm_local/pb_dst7/rz/data/run$r0.rz

exit
EOF
n1=`expr $n1 + 10`
date
sleep 1s
echo -----------------------------------------------
done

##############################################################################
#/scratch10m/data00 36720 36949

year=00

n1=6720
n2=6949
s=10
base=30000
while [ $n1 -lt $n2 ]
do
r0=`expr $n1 + $base`
r1=`expr $r0 + 1`
r2=`expr $r0 + 2`
r3=`expr $r0 + 3`
r4=`expr $r0 + 4`
r5=`expr $r0 + 5`
r6=`expr $r0 + 6`
r7=`expr $r0 + 7`
r8=`expr $r0 + 8`
r9=`expr $r0 + 9`
F0=run$r0.mid
F1=run$r1.mid
F2=run$r2.mid
F3=run$r3.mid
F4=run$r4.mid
F5=run$r5.mid
F6=run$r6.mid
F7=run$r7.mid
F8=run$r8.mid
F9=run$r9.mid
echo $r0
echo $r9
echo $F0
echo $F9

echo analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}m/data$year/run%5d.mid -o run$r0.rz

analyzer2 -c /home/pibeta/data/config_replay.odb -r $r0 $r9 -i /scratch${s}m/data$year/run%5d.mid -o run$r0.rz

gzip *.dat

ssh node15 <<EOF

mv -f $HOME/analyzer$year/random.dat.gz /sm_local/pb_dst7/random/data/rand$r0.dat.gz
mv -f $HOME/analyzer$year/pibeta.dat.gz /sm_local/pb_dst7/pibeta/data/pb$r0.dat.gz
mv -f $HOME/analyzer$year/pienu.dat.gz /sm_local/pb_dst7/pienu/data/pienu$r0.dat.gz
mv -f $HOME/analyzer$year/pienug.dat.gz /sm_local/pb_dst7/rp/data/rp$r0.dat.gz
mv -f $HOME/analyzer$year/rmichel.dat.gz /sm_local/pb_dst7/rm/data/rm$r0.dat.gz
mv -f $HOME/analyzer$year/dalitz.dat.gz /sm_local/pb_dst7/dalitz/data/dal$r0.dat.gz
mv -f $HOME/analyzer$year/pibeam.dat.gz /sm_local/pb_dst7/beam/data/beam$r0.dat.gz
mv -f $HOME/analyzer$year/prompt.dat.gz /sm_local/pb_dst7/prompt/data/prompt$r0.dat.gz
mv -f $HOME/analyzer$year/michel.dat.gz /sm_local/pb_dst7/michel/data/mich$r0.dat.gz
mv -f $HOME/analyzer$year/mueee.dat.gz /sm_local/pb_dst7/mueee/data/mueee$r0.dat.gz
mv -f $HOME/analyzer$year/lfv.dat.gz /sm_local/pb_dst7/lfv/data/lfv$r0.dat.gz
mv -f $HOME/analyzer$year/mueg.dat.gz /sm_local/pb_dst7/mueg/datamueg$r0.dat.gz
mv -f $HOME/analyzer$year/cosm.dat.gz /sm_local/pb_dst7/cosmics/data/cosm$r0.dat.gz

mv -f $HOME/analyzer$year/chamber_reso.dat.gz /sm_local/pb_dst7/chamber_reso/data/chamber_reso$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_all.dat.gz /sm_local/pb_dst7/tomo/data/tomo_all$r0.dat.gz
mv -f $HOME/analyzer$year/tomo_pienu.dat.gz /sm_local/pb_dst7/tomo/data/tomo_pienu$r0.dat.gz
mv -f $HOME/analyzer$year/run$r0.rz /sm_local/pb_dst7/rz/data/run$r0.rz

exit
EOF
n1=`expr $n1 + 10`
date
sleep 1s
echo -----------------------------------------------
done