// Fred G. Martin, UMass Lowell Computer Science // Fri Mar 28 17:56:48 2003 import java.io.*; public class NCDrill { static String fname; static File fIn, fOut; static BufferedReader brIn; static PrintWriter out; public static void main(String args[]) { usage(args); filecheck(args[0]); parse(); } public static void parse() { String line; char c; int xMils, yMils; int yIndex; String xString, yString; int xSteps, ySteps; try { while (brIn.ready() == true) { line = brIn.readLine(); c = line.charAt(0); if (c == 'T') { System.out.println("doing tool " + line.substring(1)); if (out != null) { out.println(); out.close(); } fOut = new File(fname + "_" + line.toLowerCase() + ".plt"); try { out = new PrintWriter(new BufferedWriter(new FileWriter(fOut))); } catch (Exception e) { System.out.println("Unable to open output file " + fOut); e.printStackTrace(); } out.print("IN;SP1;PA;"); } else if (c == 'X') { yIndex = line.indexOf("Y"); xString = line.substring(1, yIndex); yString = line.substring(yIndex + 1); xMils = java.lang.Integer.parseInt(xString); yMils = java.lang.Integer.parseInt(yString); xSteps = (xMils * 1016) / 10000; ySteps = (yMils * 1016) / 10000; out.print("PU"); out.print(xSteps); out.print(","); out.print(ySteps); out.print(";"); out.print("PD"); out.print(xSteps); out.print(","); out.print(ySteps); out.print(";"); } } } catch (Exception e) { e.printStackTrace(); } out.println(); out.close(); } static void usage(String args[]) { if (args.length < 1) { System.out.println("Usage: NCDrill filename.drd"); System.out.println(" Converts NCD drill file to HPGL .plt file"); System.out.println(" Generate the .drd file from EAGLE using the Excellon CAM tool;"); System.out.println(" Make sure to set output units to mils."); System.exit(0); } } static void filecheck(String name) { if (!(name.endsWith(".drd"))) name = name + ".drd"; fIn = new File(name); fname = name.substring(0, name.length() - 4); if (!fIn.exists()) { System.out.println("Sorry, file " + fIn + " does not exist!"); System.exit(1); } if (!fIn.canRead()) { System.out.println("Sorry, I do not have read permissions for file " + fIn + "."); System.exit(1); } try { brIn = new BufferedReader(new FileReader(fIn)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }