#!/bin/csh
#--------------------------------------
#	$(HOME)/bin/run_mcv3k
#--------------------------------------
#
#	shell script to run the MCV3K Monte Carlo program by Werner
#	Jacobs for the simulation of energy loss, energy straggling
#	and multiple scattering. Via xlsbatch it can be run in batch
#	mode on the Digital Unix farm at PSI. After calculation data
#	can be written to Ntuple file to be analyzed using PAW.
#
#	Environment variables must be defined with
#       source ~/mc/mcv3k/define_mcv3k or by putting this line into the
#	.login script.
#
#	Needs up to three input variables:
#
#	$1 : the input filename without extension, expected to be located
#            in mc_inp, with extension .in.
#	$2 : the number of fortan file with unformatted output, for example,
#	     40, this will assume an existing file fort.40 in mc_out.
#	$3 : the number of fortran file with the formatted stop distribution.
#
#------------------------------------------------------------------------------
#
#	TP, 13-Sep-2000,	PSI
#
#------------------------------------------------------------------------------
#

#source $HOME/bin/define_mcv3k

if ( $1 == "") then
	echo " "
	echo " MCV3K-E- You have to enter at least the input filename !"
	echo " "
	exit
endif
#
set infile  = $mcv3k_inp/$1.in
set outfile = $mcv3k_out/$1.out
set datfile = $mcv3k_out/$1.dat
set stofile = $mcv3k_out/$1.stop
#
#	check if file exists
#
if ( ! -e $infile ) then
	echo " "
	echo " MCV3K-E- file $infile does not exist ! "
	echo " "
	exit
endif
#
#	now we are ready to run MCV3K; standard input will be re-directed
#	to infile, standard output will be re-directed to outfile
#
cd $mcv3k_out
$mcv3k_bin/mcv3k < $infile > $outfile
#
# 	the simulation finished, now look, if we shall create a NT file
#
if ( $2 != "") then
 mv fort.$2 $datfile
 $mcv3k_bin/read_mcv3k_out_nt <<end
$datfile:r
end
#
# <<end means: read input from script file until end
# $datfile:r means: filename until period; the read_mcv3knt programs
# requires filenames without extension, it expects .dat
#
endif
#
if ( $3 != "") then
 mv fort.$3 $stofile
endif
#
exit
