# File Name: drill_size.awk # File Purpose: This file is an awk program that is called by the drill_size # script. The drill_size script passes the nominal drill size # and this program searches through a drill table file and finds # the nearest available drill bit. # Written by: Ian Ticehurst (Autom8 Ltd.) # Version 1A.: Date: 15.08.00 - Initial design and development. ############################# Start of notes ############################### # This program is additional to the standard system hooks. It has been added in # order to provide an easy method of drill bit selection. This program is called # by the drill_size script as part of a pipeline command that has the drill table # passed through. This program is also given variables of the nominal drill size # and if the hole is press fit. # This program then reads all the drill table into memory (using arrays) and then # looks through each table entry to find the nearest drill bit size to the nominal # size (that has been calculated by the drill_size program). It is then able to return # the drill bit size in both mils. and mm to the drill_size program. # Note that this program only looks at the first two columns in the drill table (the # bit size in mils. and mm), the other columns are added as examples only. # (A similar program to this, or indeed a modification to this could be used to find # (for example) the spindle speed and feed rate for a certain drill bit). ############################# End of notes ############################### { # Set array element counter (used to load table data into array). counter = 1 # Read the drill_size.tab (the drill table) file into memory (designator and size only). do { designator[counter]=$2; size[counter]=$1; counter++; } while ( getline ); # Set search counter for "prev_bit" (start at line "1"). prev_bit=1; # Set search counter for "next_bit" (start at line "2"). next_bit=2; # Search through all drill sizes until either exact match is found, or until next bit is larger than nominal drill size. # Note that as the loop progresses through the table entries, previous bit will always be one entry below next bit. do { if (size[next_bit]<(DRILL)) { # Smaller hole size found on previous bit increment entry pointers (i.e. look at next entries in table). prev_bit++; next_bit++; } else if (size[next_bit]==(DRILL)) { # Exact hole size found, break out of this loop. break; } else if (size[next_bit]>(DRILL)) { # Larger hole found, break out of this loop (nominal drill size is between previous bit and next bit size). break; } } while (next_bit <= counter); # Calculate the difference in size between the next drill bit and the nominal drill size. diff = size[next_bit] - DRILL; # Output actual drill bit sizes (note that the 0.95 mils can be adjusted slightly to move the point at which round up/down occurs). if (diff <= 0.95) # The difference is less then 0.95 mils. it is closer to the next bit size and should round up. { print size[next_bit]" "designator[next_bit]; } else if (PFT == 1) # The difference is more then 0.95 mils. but as this is a press fit hole, it is already on bottom tolerance limit and must round up. { print size[next_bit]" "designator[next_bit]; } else # The difference is more then 0.95 mils. it is closer to the previous bit size and should round down. { print size[prev_bit]" "designator[prev_bit]; } exit 0 }