#!/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/out2 # 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/v0_22.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>=13 {print $0}' 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}'` alpha=`echo $line | awk '{print $3}'` beta=`echo $line | awk '{print $4}'` r0=`echo $line | awk '{print sqrt($5^2+$6^2)/10.0}'` z0=`echo $line | awk '{print $7/10.0}'` w1=`echo $line | awk '{print $8/10.0}'` w2=`echo $line | awk '{print $9/10.0}'` rci1=`echo $line | awk '{print $10*10.0}'` rci2=`echo $line | awk '{print $11*10.0}'` phiw=`echo $line | awk '{print $12}'` phir=`echo $line | awk '{print $13}'` # extract k0 from gray input file k0=`awk 'NR==2 {print $1*8.0*atan2(1,1)/29.9792}' $in/gray0beam.data` k0sqov4=`echo "0.25*$k0^2" | bc -l` # compute w0,d from w,1/Rc w0x=`echo " $w1 /sqrt(1+$k0sqov4*$w1^4*$rci1^2)" | bc -l` d0x=`echo "-($k0sqov4*$rci1*$w1^4) / (1+$k0sqov4*$w1^4*$rci1^2)" | bc -l` w0y=`echo " $w2 /sqrt(1+$k0sqov4*$w2^4*$rci2^2)" | bc -l` d0y=`echo "-($k0sqov4*$rci2*$w2^4) / (1+$k0sqov4*$w2^4*$rci2^2)" | bc -l` awr=$phiw # 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/-w0x-/$w0x/g; s/-w0y-/$w0y/g; \ s/-p0x-/$d0x/g; s/-p0y-/$d0y/g; \ s/-awr-/$awr/g; \ s/-equil-/$base/g; s/-prf-/$base/g" $in/gray0beam.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 -f ${base}.eqdsk ${base}.prf fort.* exit 0 #EOF