#! /bin/csh -f # # edit the header of ADSC (SMV) image files # # foreach image ( $* ) # make this a local file set newimage = new_`basename $image` # extract the header head -c 512 $image >&! header.txt # now actually edit the header cat header.txt |\ awk -F "=" '/^PHI/{printf "%s=%.3f;\n", $1, $2%360; next}\ /[\}]/{print "}"; next} {print}' |\ cat >! newheader.txt # now strip off the old header pad cat newheader.txt |\ awk 'NF!=0 && ! /[\}]/{print}' |\ cat >! shortheader.txt # now pad the header up to exactly 512 bytes with spaces echo "}\f" >> shortheader.txt set size = `ls -l shortheader.txt | awk '{print $5}'` while ( $size < 512 ) echo -n " " >> shortheader.txt @ size = ( $size + 1 ) end # start creating the new image by copying the header cat shortheader.txt >! $newimage # transfer over the image data set datasize = `ls -l $image | awk '{print $5-512}'` tail -c $datasize $image >> $newimage end