#!/bin/csh # shell script to feed user-defined dither positions to NEWFIRM # by Pieter van Dokkum, Mar 19 2007 # usage: replace_offsets orgfile newdithers newfile # orgfile = script produced by telescope (.sh extension) # newdithers = list of desired absolute x,y dithers # newfile = output script which can be fed back to the telescope # NOTE: make sure that number of positions in newdithers equals the number # of positions in orgfile -- EXCLUDING the return to home at the end # first change absolute offsets to relative offsets; end with return # to home (note that _reloffset has n+1 positions because of this) grep -v "#" $2 | awk '{x[NR]=$1;y[NR]=$2}END{for(i=1;i<=NR;i++) {if(i==1) \ print x[i],y[i]; else print (x[i]-x[i-1]),(y[i]-y[i-1])}; \ print -1*x[NR],-1*y[NR]}' > _reloffset # work on _tmp - otherwise original file would be overwritten cp $1 _tmp # bug (?) in awk - does not work right on first entry of file, so start # with a dummy line that is later removed with the 'tail' command echo "dummy" > _tmp1 # next line is to get list of offsets from input file grep ntcs_offset _tmp | grep Argument >> _tmp1 # create script to replace offsets with desired offsets awk '{FS="\""; print "sed \"s/"$2"/"}' _tmp1 | tail +2 > _tmp2 paste -d"\0" _tmp2 _reloffset | awk '{print $0"/g\" _tmp > _tmp3; mv _tmp3 _tmp"}' > _tmp4 # run script that does the replacement - output is _tmp source _tmp4 # rename to desired output file name mv _tmp $3 # cleanup rm _tmp* _reloffset