gray/scripts/beta-alpha_beam.sh

126 lines
3.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2012-09-26 11:11:27 +02:00
# set input/working/output folders
2014-02-25 18:05:31 +01:00
in=/Users/daniela/Desktop/runs2014/case008/case008_data
work=/Users/daniela/Desktop/runs2014/case008/sc8work
out=/Users/daniela/Desktop/runs2014/case008/case008-mappe-ab-beam
2014-02-25 18:05:31 +01:00
scen='008'
uideq='267QBX'
uidprf='265AZT'
tt='10'
2012-09-26 11:11:27 +02:00
# launching mirrors
mirror=( "USM" "LSM" )
r0=( 699.871 705.392 )
z0=( 441.441 417.821 )
w0=( 2.9 2.1)
d0=( 213.4 162.0)
# steering range
amin=20
amax=70
da=1
bmin=15
bmax=25
db=1
# 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
2014-02-25 18:05:31 +01:00
tplus=`echo "${tt}+10000" | bc`
eqfile=$in/F4E_Equil_${tplus}_case${scen}_${uideq}.eqdsk
prfile=$in/F4E_Equil_${tplus}_case${scen}_${uidprf}.prf
echo $eqfile $prfile
2012-09-26 11:11:27 +02:00
# look for time value in equil file
2014-02-25 18:05:31 +01:00
baseq=`basename $eqfile .eqdsk`
basep=`basename $prfile .prf`
tstr=`echo $baseq | grep "[[:digit:]]\{5\}" -o`
2012-09-26 11:11:27 +02:00
t=`echo "$tstr-10000" | bc`
# copy input files in working folder
2014-02-25 18:05:31 +01:00
cp $eqfile ${baseq}.eqdsk
cp $prfile ${basep}.prf
2012-09-26 11:11:27 +02:00
#loop on USM/LSM mirrors
for i in 0 1; do
# set output file names
id="${mirror[i]}_Scen${scen}_t$t"
f7file=$out/ECCD_vs_ba_${id}.txt
2012-12-03 17:00:30 +01:00
f48file=$out/f48_${id}.txt
2012-09-26 11:11:27 +02:00
rm -f $out/log_${id}.txt
# add header in output file
echo "# =============================" > $f7file
echo "# `date`" >> $f7file
echo "# ${mirror[i]}: R0=${r0[i]} z0=${z0[i]}" >> $f7file
2014-02-25 18:05:31 +01:00
echo "# Case ${scen} time=$t" >> $f7file
2012-09-26 11:11:27 +02:00
echo "# =============================" >> $f7file
2012-12-03 17:00:30 +01:00
cp $f7file $f48file
2012-09-26 11:11:27 +02:00
appendheader=0
#loop on beta
for (( beta=$bmin; beta<=$bmax ; beta=beta+db )); do
#loop on alpha
for (( alpha=$amin; alpha<=$amax ; alpha=alpha+da )); do
# replace dummy values in template for gray.data
sed "s/-alfa-/$alpha/g; \
s/-beta-/$beta/g; \
s/-x0-/${r0[i]}/g; \
s/-z0-/${z0[i]}/g; \
s/-w0-/${w0[i]}/g; \
s/-d0-/${d0[i]}/g; \
2014-02-25 18:05:31 +01:00
s/-equil-/$baseq/g; \
s/-prf-/$basep/g" $in/gray0_beam.data > gray.data
2012-09-26 11:11:27 +02:00
# 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
2012-12-03 17:00:30 +01:00
cat headers.txt >> $f48file
2012-09-26 11:11:27 +02:00
echo "#beta alpha`head -n 1 fort.7 | sed 's/#//'`" >> $f7file
2012-12-03 17:00:30 +01:00
echo "#beta alpha`head -n 1 fort.48 | sed 's/#//'`" >> $f48file
2014-02-25 18:05:31 +01:00
echo "#beta alpha`head -n 1 fort.9 | sed 's/#//'`" > test9.txt
2012-09-26 11:11:27 +02:00
appendheader=1
fi
# add time and alpha values in first two columns
awk 'NR>1 {print '$beta','$alpha',$0}' fort.7 >> $f7file
2012-12-03 17:00:30 +01:00
awk 'NR>1 {print '$beta','$alpha',$0}' fort.48 >> $f48file
2014-02-25 18:05:31 +01:00
awk 'NR>1 {if (NF>1) print '$beta','$alpha',$0; else print $0}' fort.9 >> test9.txt
2012-12-03 17:00:30 +01:00
echo "" >> $f48file
2014-02-25 18:05:31 +01:00
echo "" >> test9.txt
2012-09-26 11:11:27 +02:00
done
#end of alpha loop
echo " " >> $f7file
2012-12-03 17:00:30 +01:00
echo "" >> $f48file
2014-02-25 18:05:31 +01:00
echo "" >> test9.txt
2012-09-26 11:11:27 +02:00
done
#end of beta loop
done
#end of mirrors loop
# remove files from working folder
2014-02-25 18:05:31 +01:00
rm ${baseq}.eqdsk ${basep}.prf fort.*
2012-09-26 11:11:27 +02:00
#EOF