Added first version of script for reading table of launching conditions
This commit is contained in:
parent
cec09f3953
commit
e18281ad87
110
scripts/gamma-singleray.sh
Executable file
110
scripts/gamma-singleray.sh
Executable file
@ -0,0 +1,110 @@
|
||||
#!/bin/bash
|
||||
|
||||
# set input/working/output folders
|
||||
in=/Users/lorenzo/Desktop/scenario_001
|
||||
work=/Users/lorenzo/Desktop/scenario_001/tmp
|
||||
out=/Users/lorenzo/Desktop/scenario_001/out
|
||||
|
||||
# check if working folder exists, otherwise create it
|
||||
if [[ ! -e $work ]]; then
|
||||
mkdir $work
|
||||
else
|
||||
if [[ ! -d $work ]]; then
|
||||
echo $work is not a folder.
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# move to working folder
|
||||
cd $work
|
||||
if [[ $? != 0 ]]; then
|
||||
echo Cannot move to $work
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check if output folder exists, otherwise create it
|
||||
if [[ ! -e $out ]]; then
|
||||
mkdir $out
|
||||
else
|
||||
if [[ ! -d $out ]]; then
|
||||
echo $out is not a folder.
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
listfile=$in/alpha-beta-vs-gamma.txt
|
||||
# count number of lines in input file
|
||||
nlines=`wc -l $listfile | awk '{print $1}'`
|
||||
|
||||
eqfile=$in/F4E_Equil_10520.eqdsk
|
||||
# look for time value in equil file
|
||||
base=`basename $eqfile .eqdsk`
|
||||
tstr=`echo $base | grep "[[:digit:]]\{5\}" -o`
|
||||
t=`echo "$tstr-10000" | bc`
|
||||
# copy input files in working folder
|
||||
cp $eqfile ${base}.eqdsk
|
||||
cp $in/${base}.prf ${base}.prf
|
||||
|
||||
# set output file names
|
||||
id=${base}_8beams_gammascan
|
||||
f7file=$out/f7_${id}.txt
|
||||
f48file=$out/f48_${id}.txt
|
||||
rm -f $out/log_${id}.txt
|
||||
# add header in output files
|
||||
echo "# =============================" > $f7file
|
||||
echo "# `date`" >> $f7file
|
||||
echo "# Launching conditions: `basename $listfile`" >> $f7file
|
||||
echo "# time=$t" >> $f7file
|
||||
echo "# =============================" >> $f7file
|
||||
cp $f7file $f48file
|
||||
appendheader=0
|
||||
|
||||
#loop on lines of launching conditions table
|
||||
for (( iline=1; iline<=$nlines+1; iline++ )); do
|
||||
# search full, non-commented lines
|
||||
awkcommand='NR=='$iline' && NF>=6 {print $1, $2, $3, $4, $5, $6}'
|
||||
line=`sed 's/#.*$//' $listfile | awk "$awkcommand"`
|
||||
if (( `echo $line | wc -w`>0 )); then
|
||||
# if valid line extract values
|
||||
ibeam=`echo $line | awk '{print $1}'`
|
||||
gamma=`echo $line | awk '{print $2}'`
|
||||
r0=`echo $line | awk '{print $3/10.0}'`
|
||||
z0=`echo $line | awk '{print $4/10.0}'`
|
||||
alpha=`echo $line | awk '{print $5}'`
|
||||
beta=`echo $line | awk '{print $6}'`
|
||||
# replace dummy values in template for gray.data
|
||||
sed "s/-alfa-/$alpha/g; \
|
||||
s/-beta-/$beta/g; \
|
||||
s/-x0-/$r0/g; \
|
||||
s/-z0-/$z0/g; \
|
||||
s/-equil-/$base/g; \
|
||||
s/-prf-/$base/g" $in/gray0.data > gray.data
|
||||
# run gray
|
||||
gray >> $out/log_${id}.txt
|
||||
if (( $appendheader==0 )); then
|
||||
# append parameters to header if first run of the loop
|
||||
cat headers.txt >> $f7file
|
||||
cat headers.txt >> $f48file
|
||||
echo "#beam dgamma`head -n 1 fort.7 | sed 's/#//'`" >> $f7file
|
||||
echo "#beam dgamma`head -n 1 fort.48 | sed 's/#//'`" >> $f48file
|
||||
appendheader=1
|
||||
fi
|
||||
# add beam number and gamma values in first two columns
|
||||
awk 'NR>1 {print '$ibeam','$gamma',$0}' fort.7 >> $f7file
|
||||
awk 'NR>1 {print '$ibeam','$gamma',$0}' fort.48 >> $f48file
|
||||
echo "" >> $f48file
|
||||
else
|
||||
# if first block of data has already been written
|
||||
if (( $appendheader==1 )); then
|
||||
# write blank line in output when invalid (blank) line is found in input
|
||||
echo "" >> $f7file
|
||||
echo "" >> $f48file
|
||||
fi
|
||||
fi
|
||||
done
|
||||
#end of launching conditions loop
|
||||
|
||||
# remove files from working folder
|
||||
rm ${base}.eqdsk ${base}.prf fort.*
|
||||
|
||||
exit 0
|
||||
#EOF
|
Loading…
Reference in New Issue
Block a user