#!/usr/local/bin/perl # # makehole.perl : make CAMM-3 data from drill file # require "getopts.pl"; $#="%6.0f"; $opt_n="[0-9]+"; $opt_x=1; $opt_z="2000:-2000"; $opt_v="1"; $opt_p="1,1>1,1;-1,-1>-1,-1"; &Getopts('xyrhz:v:p:'); if($opt_h){ print <U1,V1;X2,Y2>U2,V2 : specifies mapping from drill hole coordinates (X,Y) to CAMM coordinates (U,V) (default is X,Y=U,V) X2,Y2>U2,V2 may omitted -p X,Y>U,V : specifies only offset (hole coordinates X,Y is translated to CAMM coordinates U,V) -p U,V : specifies only offset (hole coordinates 0,0 is translated to CAMM coordinates U,V) -x : output is sorted by X coordinates (default) -y : output is sorted by Y coordinates -r : reverse order (bigger to smaller) -z UP:DOWN : specifies z coord of pen up/down (default is +2000:-2000 (um)) -v SPD : specifies velocity of pen down (default is 1 (mm/s)) Coord unit is measured by micrometer. EOF exit; } $opt_z=~/([0-9.\-]+)\:([0-9.\-]+)/; $zu=$1/10; $zd=$2/10; die "z position option is illegal ($zd > $zu)\n" if($zd>$zu); if($opt_p=~/([0-9.\-]+)\,([0-9.\-]+)>([0-9.\-]+)\,([0-9.\-]+)\;([0-9.\-]+)\,([0-9.\-]+)>([0-9.\-]+)\,([0-9.\-]+)/){ $dx=$5-$1;$dy=$6-$2;$du=$7-$3;$dv=$8-$4; $transa=($du*$dx+$dv*$dy)/($dx*$dx+$dy*$dy); $transb=($du*$dy-$dv*$dx)/($dx*$dx+$dy*$dy); $ofsx=$1;$ofsy=$2; $ofsu=$3;$ofsv=$4; } elsif($opt_p=~/([0-9.\-]+)\,([0-9.\-]+)>([0-9.\-]+)\,([0-9.\-]+)/){ $transa=1;$transb=1; $ofsx=$1;$ofsy=$2; $ofsu=$3;$ofsv=$4; } elsif($opt_p=~/([0-9.\-]+)\,([0-9.\-]+)/){ $transa=1;$transb=1; $ofsx=0;$ofsy=0; $ofsu=$3;$ofsv=$4; } print STDERR "Trans matrix a=$transa b=$transb ofs=$ofsx,$ofsy->$ofsu,$ofsv\n"; sub trans{ local($x,$y,$u,$v)=@_; $x=$x-$ofsx; $y=$y-$ofsy; $u=$transa*$x+$transb*$y+$ofsu; $v=-$transb*$x+$transa*$y+$ofsv; $u=int($u/10+0.5); $v=int($v/10+0.5); return "$u,$v"; } $vd=$opt_v; $i=0; @dd=(); # DATA ( X,Y,N ) unit is um while(<>){ if(/^\s*([0-9.-]+)\s*\,\s*([0-9.-]+)/){ push(@dd,&trans($1,$2)); } } @ddsort=sort byx @dd; sub byx{ local($px,$py,$qx,$qy,$ans); $a=~/^([0-9.-]+),([0-9.-]+)/;$px=$1;$py=$2; $b=~/^([0-9.-]+),([0-9.-]+)/;$qx=$1;$qy=$2; if($opt_y){ $ans=($py<=>$qy); $ans=($px<=>$qx) if($ans==0); } else{ $ans=($px<=>$qx); $ans=($py<=>$qy) if($ans==0); } if($opt_r){ $ans=-$ans; } return $ans; } print "\@$zd,$zu;v$vd;!1;m0,0;\n"; foreach (@ddsort){ /^([^,]+)\,([^,]+)/; printf "m$1,$2;d;m;\n"; } print "m0,0;!0;";