#!/usr/bin/perl # 13-Feb-2005 Keith Neufeld # # Convert a gnuplot-style X Y file into a CNC drill file. # drillfile units per inch my $scale = 10000; # figure out input/output filenames my ($xyfile, $drillfile); if (@ARGV == 2) { ($xyfile, $drillfile) = @ARGV; } elsif (@ARGV == 1) { $xyfile = shift; my ($base) = $xyfile =~ /(.*)\.[^.]+/; $base ||= $xyfile; $drillfile = "$base.drill"; } else { die "usage: $0 xyfile.xy [drillfile.drill]\n"; } # open input and output files open(XY, $xyfile) or die "can't open $xyfile for reading: $!\n"; open(DRILL, ">$drillfile") or die "can't open $drillfile for writing: $!\n"; # do the conversion while () { s/\s*#.*//; # toss comments next if /^\s*$/; # skip (now) blank lines if (my ($x, $y) = /^([\d.]+)\t([\d.]+)$/) { print DRILL sprintf("X%06dY%06d\n", $scale * $x, $scale * $y); } else { warn "unknown format at line $.: $_"; } } __END__ ;Holesize 1 = 45.0 PLATED MILS ;Holesize 2 = 0.0 PLATED MILS ;Holesize 3 = 28.0 PLATED MILS M48 INCH T01C0.045 T02C0.000 T03C0.028 % G05 G90 T01 X001000Y010000 X002000Y010000 X003000Y010000 T02 X022000Y002000 X022000Y004000 T03 X014000Y001000 X018000Y001000 M30