#!/bin/csh -f
set case    = `pwd`
set case    = $case:t
if ($case == "") then
  echo "ERROR: no case.inst-file -> exit"
    exit 1
    endif
    
cat $case.struct | grep NPT > atomlist.temp
sed -e 's/[0-9]*//g' atomlist.temp > atomlist.temp2
sed -e 's/R*=//g' atomlist.temp2 > atomlist.temp
sed -e 's/NPT*//g' atomlist.temp > atomlist.temp2
sed -e 's/Z\:*//g' atomlist.temp2 > atomlist.temp
sed -e 's/RMT*//g' atomlist.temp > atomlist.temp2
sed -e 's/\.//g' atomlist.temp2 > atomlist.temp

if (! -e $case.qtl) then
echo no qtl-file found
exit
endif
if (-z $case.qtl) then
echo no qtl-file found
exit
endif

set lst = `cat atomlist.temp`
echo $lst
if ( -z atomlist.temp ) then
echo "ERROR: no atoms in $case.struct -> exit"
exit 1
endif

rm atomlist.temp*
set i = 1
while ($lst[$i] != "")
set atom = $lst[$i]
echo $i $atom 

if (! -e $case.innes$atom) then
echo no template for $i $atom
goto next
endif
echo "title" > $case.innes
echo "$i , 0" >> $case.innes
tail -n 15 $case.innes$atom >> $case.innes
x initelnes
x tetra
x telnes
cp $case.telnes $case.telnes$atom$i
cp $case.sdlm $case.sdlm$atom$i
cp telnes.error telnes.error$atom$i
cp $case.doslm $case.doslm$atom$i
if (-e spinspectra.txt) then
cp spinspectra.txt spinspectra.txt$atom$i
endif

next:
@ i ++
end



