#! /bin/csh
#set file = '0'
echo "Please enter a file name (common part):"
echo "Expecting name-grad.cube and name-dens.cube"

set file = $<

echo "Please enter range origin:"

set ri = $<

echo "Please enter range edge:"

set rf = $<
set ri = `echo "print $ri*100." | python`
set rf = `echo "print $rf*100." | python`
echo $file, $ri, $rf

paste $file-dens.cube $file-grad.cube >> kk.dat0
#inicio
head -3 $file-grad.cube | tail -1 | awk '{print $1}' > natms.dat0
set nat=( `cat natms.dat0` )
set ni = `echo "print $nat+6" | python`
echo $nat,$ni

#fin
awk 'END{print NR}' $file-grad.cube > nr.dat0
set nr=( `cat nr.dat0` )
set nf = `echo "print $nr-$ni" | python`
echo $nr,$nf


head -$ni $file-grad.cube > head.dat0

tail -$nf kk.dat0 > tail.dat0

awk '{ s=$2; r=$1; if ( (r < '$ri') || (r > '$rf')) s=100.; print s}' tail.dat0 > tail2.dat0
#awk '{ s=$2; r=$1; if ($1<0) r=-$1; if ( (r < '$ri') || (r > '$rf')) s=100.; print s}' tail.dat0 > tail2.dat0
#awk '{ s=$1; if ($1 < '$ri') s=100.; if ($1 > '$rf') s=100. ; print s}' tail.dat0 > tail2.dat0

cp head.dat0 $file-$ri-$rf.cube
paste tail2.dat0 >> $file-$ri-$rf.cube 

rm *.dat0
