Bash

crtl - a beginning of line
crtl - e end of line
crtl - w cut last word
crtl - u cut everything before cursor
crtl - k cut everything after cursor
crtl - y paste last thing cut
crtl - _ undo

program called redshift.bash

run by typing:

bash redshift.bash 1608.4511

the output is:

Redshifted Value: 5322.49
Blue chip, order 67

Which tells me the redshift, the chip, and the echelle order.

#!/bin/bash

# prints Redshifted Value
awk "BEGIN { print $* ; }" | 
awk '{print "Redshifted Value: ", $1 * 3.30908 ; }'

# prints the Order that it appears
awk "BEGIN { print $* ; }" | 
awk '{observed = $1 * 3.30908 ; }
END{ 
if(observed < 4765){ print "outside all orders"}
if(observed < 7823 && observed > 7688 ){print "Green chip, order", 46}
if(observed < 7656 && observed > 7525 ){print "Green chip, order", 47}
if(observed < 7497 && observed > 7368 ){print "Green chip, order", 48}
if(observed < 7344 && observed > 7218 ){print "Green chip, order", 49}
if(observed < 7197 && observed > 7073 ){print "Green chip, order", 50}
if(observed < 7056 && observed > 6934 ){print "Green chip, order", 51}
if(observed < 6920 && observed > 6801 ){print "Green chip, order", 52}
if(observed < 6789 && observed > 6673 ){print "Green chip, order", 53}
if(observed < 6664 && observed > 6549 ){print "Green chip, order", 54}
if(observed < 6543 && observed > 6430 ){print "Green chip, order", 55}
if(observed < 6426 && observed > 6315 ){print "Green chip, order", 56}
if(observed < 6313 && observed > 6273 ){print "Green chip, order", 57}

if(observed < 6204 && observed > 6098 ){print "Blue chip, order", 58}
if(observed < 6099 && observed > 5994 ){print "Blue chip, order", 59}
if(observed < 5997 && observed > 5894 ){print "Blue chip, order", 60}
if(observed < 5899 && observed > 5798 ){print "Blue chip, order", 61}
if(observed < 5804 && observed > 5704 ){print "Blue chip, order", 62}
if(observed < 5712 && observed > 5614 ){print "Blue chip, order", 63}
if(observed < 5622 && observed > 5526 ){print "Blue chip, order", 64}
if(observed < 5536 && observed > 5441 ){print "Blue chip, order", 65}
if(observed < 5452 && observed > 5359 ){print "Blue chip, order", 66}
if(observed < 5371 && observed > 5279 ){print "Blue chip, order", 67}
if(observed < 5292 && observed > 5201 ){print "Blue chip, order", 68}
if(observed < 5215 && observed > 5126 ){print "Blue chip, order", 69}
if(observed < 5140 && observed > 5053 ){print "Blue chip, order", 70}
if(observed < 5068 && observed > 4981 ){print "Blue chip, order", 71}
if(observed < 4997 && observed > 4912 ){print "Blue chip, order", 72}
if(observed < 4929 && observed > 4845 ){print "Blue chip, order", 73}
if(observed < 4862 && observed > 4780 ){print "Blue chip, order", 74}
if(observed < 4797 && observed > 4766 ){print "Blue chip, order", 75}
if(observed > 7823){ print "outside all orders"}
}'
#!/bin/bash

gcc convolution.c -lm -o convolve

for order in 62
do
    ./convolve $order
    for sizeofbin in 1 2 4 5 6 8
    do
        echo 'Order: '$order', Sums for bin size: '$sizeofbin' working...'
        awk '{
            line++;
            for(i=1;i<=NF;i++){Q[line,i]=$i;}
            columns=NF;
        }
        END{    
            numberoflines=line;
            sizeofbins='$sizeofbin';
            first = 2;
            bin=0;
            for(i=2;i<=numberoflines;i++){ #go through all Q
                if (Q[i,1] - Q[first,1] > sizeofbins){
                    bin++;
                    for(k=2;k<=columns;k++){
                        for(j=first;j<=i;j++){
                            sum[bin,k]+=Q[j,k];
                        }
                    }
                    sum[bin,1]=(Q[first,1]+Q[i,1])/2.;
                    first=i;
                }
            }
            for(i=1;i<=bin;i++){
                print "#", sum[i,1];
                for(j=1;j<=columns+1;j++){
                    print Q[1,j+1], sum[i,j+1];
                }
            }
        }' Output/calculation_$order.ascii > Chi$order/binsum_$order.$sizeofbin.ascii

        echo 'finished summing.'
        awk '{
        if(FILENAME=="'Chi$order/binsum_$order.$sizeofbin.ascii'"){    
            line++;
            for(i=1;i<=NF;i++){Q[line,i]=$i;}
            columns=NF;
        }
        if(FILENAME=="'Output/calculation_$order.ascii'"){     
            line2++; 
                for(i=1;i<=NF;i++){Q2[line2,i]=$i;} 
                columns2=NF;
        }
        }
        END{
                numberoflines=line2;
                sizeofbins='$sizeofbin';
                first = 2;
                bin=0;
                for(i=2;i<=numberoflines;i++){
                        if (Q2[i,1] - Q2[first,1] > sizeofbins){
                                bin++;
                                sum[bin,1]=(Q2[first,1]+Q2[i,1])/2.;
                                first=i;
                }
            }
        print "set fit errorvariables"
        for(i=1;i<=bin;i++){
                printf("a%i=600.; b%i=-70.;c%i=2.8\n",i,i,i);
                printf("w%i(x) = a%i*x*x + b%i*x + c%i\n",i,i,i,i);
                printf("fit w%i(x) \"'Chi$order/binsum_$order.$sizeofbin.ascii'\" index %i via a%i,b%i,c%i\n",i,i-1,i,i,i);
        }
        print "set print \"'Plotting/plot.$order.$sizeofbin.ascii'\""
        print "set title \"Order: '$order'; Bin Size: '$sizeofbin'\""
        print "set xlabel \"Wavelength of the bin\""
        print "set ylabel \"Shift in Angstroms\""

        for(i=1;i<=bin;i++){
                   printf("print %f, -b%i/(2.*a%i), sqrt((b%i_err/b%i)*(b%i_err/b%i)+",sum[i,1],i,i,i,i,i,i);
            printf("(a%i_err/a%i)*(a%i_err/a%i))\n",i,i,i,i);
        }
        printf("set print\n");
        }' Chi$order/binsum_$order.$sizeofbin.ascii Output/calculation_$order.ascii > Gnuplot_scripting/gnuplot.$order.$sizeofbin.p

        gnuplot 'Gnuplot_scripting/gnuplot.'$order'.'$sizeofbin'.p'
    done
done

Bash script that figures out the min chi squared for a range within an order and with a given bin size…

#!/bin/bash

awk '{
        line++;
        for(i=1;i<=NF;i++){Q[line,i]=$i;}
        columns=NF;
}
END{
        delchisq=1.;
        for (i=1;i<=NR;i++){
                if ( Q[i,1] == "#") {
                        j++;
                        hash[j] = Q[i,2];
                        numofpounds=j;
                        locationofpounds[j]=i;
                }
        }
        linespersection = locationofpounds[2]-locationofpounds[1]-2;
        for(i=1;i<=numofpounds;i++){
                min = 1000.;
                for(j=locationofpounds[i]+1;j<locationofpounds[i]+linespersection;j++){
                        if(min > Q[j,2]){
                                min = Q[j,2];
                                minlocation = j;
                        }
                }
                x[i] = Q[minlocation,1];
                y[i] = Q[minlocation,2];
                locationarray[i] = minlocation;
        }
        for(i=1;i<=numofpounds;i++){
                j=locationarray[i];
                while(Q[j,2] < Q[locationarray[i],2]+delchisq){
                        j++;
                }
                positiveerror[i]=Q[j,1]-Q[locationarray[i],1];
                j=locationarray[i];
                while(Q[j,2] < Q[locationarray[i],2]+delchisq){
                        j--;
                }
                negativeerror[i]=Q[locationarray[i],1]-Q[j,1];
        }
        for(i=1;i<=numofpounds;i++){
                print hash[i],x[i],positiveerror[i],negativeerror[i];
        }
}'

when running you can feed it in other files — up to 9, where the file is called w/in the bash script as the corresponding #

So, bash example.bash inputfile.1 inputfile.2 inputfile.3

is read and the variable in the following for-loop is set via:

#!/bin/bash
for order in $(cat $3) 
do
echo "Order $order"
for expo in $(cat $1) comb 
do
echo "Exposure $expo"

done
done

Which assigns the variable "order" to be the contents on the first line of inputfile.3; likewise with "expo"

#!/bin/bash

/home/jonathan/Desktop/VPFIT/./vpfit -<<EOF
/home/jonathan/Desktop/VPFIT/atom.dat

f

$input
n
n
EOF

cat f26.9p4* > output.$input

runs the program and the -« tells the bash script to enter the next line in the code at prompting of the program, in this case, vpfit.

It inputs commands until, in this case, EOF is reached.

Then it acts as a normal bash script.

This effectively does a "for loop"

#!/bin/bash

COUNTER=0
while [ $COUNTER -lt 100 ]; do
echo "openW,lun,'marc.00$COUNTER',/Get_Lun"
echo "printf,lun,headfits('hires00$COUNTER.fits.gz')"
echo "free_lun,lun"
let COUNTER=COUNTER+1;
done

1 line awesome rename:

for i in $(ls);do echo "mv $i $(ls $i | awk -F _ '{print $5"."$6"."$7}')";done

remove echo " " after verifying happy results

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.