#!/bin/csh -f
#  convert vertex data for particle tracking for Geomview
#
#  Usage: gettrace  maxcode  tracedata 
#   where 
#   maxcode: is one of 2 to 6.  For example, if
#          2 is given only electron trackes are obtained.
#   tracedata: path to the trace data given by Cosmos.
#
#  To fix the color for each particle code, colortab is used.
#
# ************* fix the next to store the converted data for 
#               Geomview

#set vdir = ../Work
set vdir = /tmp


# *******************************

if( $#argv != 2 ) then
	echo gettrace maxcode tracedata 
	exit 1
endif

foreach code(`echo "2 3 4 5 6"`)
	if( $code <= $1 ) then
		gawk -f first.awk code=$code $2 > $vdir/vertexdata
		set x = `ls -l $vdir/vertexdata` 
		if( $x[5] > 2 ) then
			echo "VECT" > $vdir/ptcl${code}.vect
			gawk -f second.awk $vdir/vertexdata >> $vdir/ptcl${code}.vect
			cat $vdir/vertexdata >> $vdir/ptcl${code}.vect
			gawk 'code==$2 {print $3, $4, $5, $6}' code=$code colortab >> $vdir/ptcl${code}.vect
        else	
		rm -f $vdir/ptcl${code}.vect
        endif	
end
