#!/bin/csh -f
#   The place this command is to be used.  Any place
#  Usage:   iniGlauber Basic_material_file filename
#     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.
#
#   Procedure.
# 1)  First, 'filename.inp' is created in Epcis/Data/Media
#     by referring to
#     basic_media_file and Cosmos/Util/DPM/GlaubIniTemplate.inp
#     This is used to preinitialize the Glauber calculation
#     in the next setp below.
# 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
	echo " Usage: iniGlauber basic_material_file outputfile "
        echo " outputfile may be the same as the name part of the"
        echo " basic_material_file: e.g G5 of Epics/Data/BaseM/G5"
        echo " ******* Provided that it's length is <=8  *********"
        echo " The file is created as Epics/Data/Media/'outputfile'.GLB"
	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/)







