#!/bin/csh -f
#   The place this command is to be used.  Any place
#  Usage:   iniGlauber Basic_material_file filename  projFlag
#     where basic_material_file is the file name  typically in
#     Epics/Data/BaseM.
#    "filename" is a max of 8 char. filename which is
#     to contain a Glauber calculation result (as 'filename'.GLB)
#     This is stored in  Epics/Data/Media directory.
#     "projFlag"  1--> max projectile (A,Z) =(56,26)
#                 2--> max projectile (A,Z) =(207,82)
#          (defined in  Cosmos/Util/DPM/GlaubIniTemplateX.inp)
#   Procedure.
# 1)  First, 'filename.inp' is created in Epcis/Data/MediaX (X=projFlag)
#     by referring to
#     basic_media_file and Cosmos/Util/DPM/GlaubIniTemplateX.inp
#     This is used to preinitialize the Glauber calculation
#     in the next setp below.
#   Note:  Media1 is alias of Media.
# 2)  Second, using filename.inp,  preinitialization 
#     of Glanuber calculation is performed. This will create
#     'filename".GLB file to be used at the simulation
#     Preinitialization  program is in Cosmos/Util/DPM
#

if( $#argv != 2 ) then
    cat <<EOF
	 Usage: iniGlauber basic_material_file outputfile
    basic_material_file:  such as Epics/Data/BaseM/G5
    outputfile:            may be the same as the name part of the
         basic_material_file: e.g G5 of Epics/Data/BaseM/G5
         ******* Provided that it's length is <=8  *********
xxx    projFlag:  1 or 2.  1--> max projectile (A,Z)=(56,26) (i.e, Fe) 
xxx                        2--> //             (A,Z)=(207,82) (i.e,Pb)
         The file is created as Epics/Data/Media/'outputfile'.GLB
xxx	 where X= projFlag.
EOF
	exit
endif	

if( ! -f $1 ) then
	echo $1 not exists
	exit
endif
set leng = `echo $2 | awk '{print length($1)}' -`


if ( $leng > 8 ) then
   echo $2 must be 8 char. length or less.
   exit
endif
awk -f $EPICSTOP/Scrpt/iniGlauber.awk BaseM=$1 filename=$2 $1 $COSMOSTOP/Util/DPM/GlaubIniTemplate.inp  > $EPICSTOP/Data/Media/$2.inp

set ARCH = `awk '$1=="ARCH" {print $3}' $EPICSTOP/site.config`

(cd $COSMOSTOP/Util/DPM; make clean; make -f mkglauber.mk ; echo "$EPICSTOP/Data/Media/$2.inp" |  ./mkglauber$ARCH; mv $2.GLB $EPICSTOP/Data/Media/)

#   (cd $COSMOSTOP/Util/DPM;  echo "$EPICSTOP/Data/Media/$2.inp" |  ./mkglauber$ARCH; mv $2.GLB $EPICSTOP/Data/Media/)







