#!/bin/csh -f

set headname=`echo $1 | awk 'BEGIN{FS="."}{print $1}'`
set fname=$headname.xyz
set outfname="He_"$fname
set count=1

if ($1 == -h || $1 == --help) then
    echo "Ne2He"
    echo " "
    echo "This converts an .xyz file so that the atom type in the first"
    echo "column becomes He, regardless of what the previous atom type"
    echo "was. The output is saved to file He_{file.xyz}, or to file"
    echo "He_i_{file.xyz} where 1<=i<100. If these files exist then no"
    echo "files are written."
    echo " "
    echo "written by Luke Abraham 2005/09/10"
    exit 1
endif

if (-e $outfname) then
    while ($count < 100)
        set  outfname="He_"$count"_"$fname
        if (!(-e $outfname)) then
	    awk '{if (NF == 1) print $0 ; if ($1 == "*") print $0 ; if (NF == 4) printf "He %18.10f %18.10f %18.10f\n", $2,$3,$4 ; if (NF == 5) printf "He %18.10f %18.10f %18.10f %3d\n", $2,$3,$4,$5}' $fname >> $outfname 
	    exit 1
        endif
        @ count = $count + 1
    end
    if ($count == 100) then
	echo "please rename file"
	exit -1
    endif
else 
	awk '{if (NF == 1) print $0 ; if ($1 == "*") print $0 ; if (NF == 4) printf "He %18.10f %18.10f %18.10f\n", $2,$3,$4 ; if (NF == 5) printf "He %18.10f %18.10f %18.10f\n", $2,$3,$4}' $fname >> $outfname 
	exit 1
endif