#! /bin/csh -f # a filter to scale and translate XTAL contour plot postscript to the # lower left corner of the page. Also the bounding box is adjusted to the # new scaled and translated postscript figure. This is necessary for direct # porting to the Macintosh for use in Microsoft Word documents. # It also enables ready inclusion in a FrameMaker # anchored or floating frame of dimensions $2 (width) $3 (height) in # units of pt (points - 72 per inch). Doug du Boulay (2/2/95). if ( $#argv < 3 ) then # no arguments so quit echo "`basename $0`: A filter for XTAL postscript CONTOUR plots. Filter" echo " scales and translates a ps image to lower left corner" echo " and optimises the bounding box." echo " " echo "Usage: `basename $0` infile width(pt) height(pt) linewidth(optional)" exit 1 endif # # check for optional linewidth argument if ( $#argv < 4 ) then @ linew = 4 else @ linew = $4 endif awk ' /^\%\!/ {exit 2} ' $1 # check for postscript symbol if ( $status != 2 ) then echo " Input file is not postscript " exit 1 endif # file is postscript so check for XTAL CONTOUR PLOT boundary awk ' BEGIN { str1="";str2="";str3="";llx=0} \ /scale / {xscal= $1 ; yscal= $2} \ { str1=str2;str2=str3;str3=$0;k=0;strin=str1 " " str2 " " str3 \ len = split (strin,p,FS) \ while (len-k>=24) \ {if (p[k+1]==p[k+4] && p[k+1]==p[k+8] && p[k+1]==p[k+11] && p[k+1]==p[k+23] && p[k+2]==p[k+5] && p[k+2]==p[k+9] && p[k+2]==p[k+12] && p[k+2]==p[k+15] && p[k+2]==p[k+24]) \ {llx=p[k+11];lly=p[k+12];urx=p[k+17];ury=p[k+18];exit;break}\ else {k++} } \ } \ END {if ( llx != 0 ) \ {pptx= xscal*(urx-llx);ppty= yscal*(ury-lly) \ nxs = xscal*('$2'-'$2'*.025)/pptx;nys = yscal*('$3'-'$3'*.025)/ppty\ if (nxs > nys) {nxs = nys} \ xtra = -nxs*llx+2 ; ytra= -nxs*lly+2 \ bburx= nxs*(urx-llx)+8 ;bbury=nxs*(ury-lly)+8\ printf "%%%%BoundingBox: 0 0 %-4.0f %-4.0f \n",bburx,bbury \ printf "%%%%EndComments \n" \ printf " %-4.0f %-4.0f translate %-1.3f %-1.3f scale \n",xtra,ytra,nxs,nxs}\ else { exit 1 }\ } ' $1 > temp.file.$$ if ( $status == 1 ) then echo " Input file is not an XTAL postscript CONTOUR plot " rm temp.file.$$ exit 1 endif # Create new ammended postscript file awk ' /BoundingBox/ {next } ; /EndComments/ {next} \ /scale / {$1="";$2="";$3="";$4='$linew';print $0;next } {print}' $1 | \ sed -e '/CreationDate/r temp.file.'$$ -e 's/^ / /' # cleanup rm temp.file.$$ ##########################################################