[POST_VERSION] #DO NOT MOVE OR ALTER THIS LINE# V26.00 P1 E1 W26.00 T1674251131 M26.00 I0 O0
scncpost_revision     := "26.83" # Internal revision number for use by CNC Software only.  Please do not change this number.
scustpost_revision    := "0"  # Revision number for use by Resellers or customers.
# Post Name           : Router.set
# Product             : Router
# Machine Name        : Generic
# Control Name        : Generic
# Description         : Generic setup sheet for Router, outputs detailed operation list
# 4-axis/Axis subs.   : No
# 5-axis              : No
# Executable          : mp.dll
#
# WARNING: THIS POST IS GENERIC AND IS INTENDED FOR MODIFICATION TO
# THE MACHINE TOOL REQUIREMENTS AND PERSONAL PREFERENCE.
#
# --------------------------------------------------------------------------
# Revision log:
# --------------------------------------------------------------------------
# CNC 04/28/05  -  Initial Setup for Version X.
# CNC 11/15/05  -  Modified header section and layout, added new functionality
# CNC 01/20/06  -  Fixed buffer logic to correctly handle null toolchanges
# CNC 02/17/06  -  Added opcomment string reset in pcomment2
#               -  Modified stock to leave to seperate 2D toolpath (XY and Z) from surface
#                    toolpaths (Drive surface and Check surface)
# CNC 02/22/06  -  Added check for "Write NC Operation Information" output error popup if not enabled in CD
#               -  Reworked information output by various tool paths. Added surface machining operation name
# CNC 03/14/06  -  Fixed typo in pwritbuf2. Modified pdrillcyc to use nextdc$ rather than drillcyc$
# CNC 04/10/06  -  Modified output for surface high speed machining operations.
# CNC 06/23/06  -  Initial post update for Mastercam X2
# CNC 08/07/07  -  Fixed CDC Buffer read logic.
# CNC 10/31/07  -  Added sub_level$ override to pprep$
# CNC 12/18/07  -  Modified EOB (End of Block) in pprep$ postblock
# CNC 04/08/08  -  X3 release - Removed check for write_ops
# CNC 01/26/09  -  Initial post update for Mastercam X4
# CNC 02/03/10  -  Initial post update for Mastercam X5
# CNC 08/17/10  -  Removed CD_VAR variables
# CNC 05/20/11  -  Initial post update for Mastercam X6
# CNC 10/16/12  -  Initial post update for Mastercam X7
# CNC 03/22/13  -  Rewrite High Speed String Selector
# CNC 02/06/14  -  Initial post update for Mastercam X8
# CNC 12/23/14  -  Initial post update for Mastercam X9
# CNC 11/09/15  -  Initial post update for Mastercam 2017
# CNC 10/14/16  -  Initial post update for Mastercam 2018
# CNC 04/24/17  -  (20.80) Initial revision number assigned.
#               -  Removed [CTRL_TEXT_END] - Not needed for Mastercam 2018
# CNC 09/13/17  -  (21.80) Initial post update for Mastercam 2019
# CNC 02/14/19  -  (22.80) Initial post update for Mastercam 2020
# CNC 02/19/19  -  (22.81) Modified shmm string selector to match Mastercam 2020's Surface High Speed toolpath types
# CNC 01/10/20  -  (23.81) Initial post update for Mastercam 2021
# CNC 01/30/20  -  (23.82) Revised operation type logic to use tool_op$
# CNC 01/11/21  -  (24.82) Initial post update for Mastercam 2022
# CNC 04/25/22  -  (25.82) Initial post update for Mastercam 2023
# CNC 01/23/23  -  (26.82) Initial post update for Mastercam 2024
# CNC 02/17/23  -  (26.83) Updated tool_op$ values for process hole operation
#
# --------------------------------------------------------------------------
# Features:
# --------------------------------------------------------------------------
# This post supports output for 3 and 4 axis movement.
# It is designed to support the features of Mastercam X Router.
#
# NEW FEATURES FOR X:
# - Supports X comments including machine name, group name and group comment output (see pcomment2)
#     Output of these comments is controlled by setting outputxcom in the Optional Output Settings area.
# - Enhanced output control via post switches (see Optional Output Settings area)
#
# --------------------------------------------------------------------------
# Misc. Values:
# --------------------------------------------------------------------------
# Integers:
#
# mi1 - mi10 (NOT USED)
#
# Reals:
#
# mr1 - mr10 (NOT USED)
#
# --------------------------------------------------------------------------
# Additional Notes:
# --------------------------------------------------------------------------
# File extension (.doc) is set internally in MP.  Use pprep$ postblock to override this setting.
#
# Rapid traverse times are determined by maximum rapid feedrates set in the selected Machine Definition
# Time estimates will be wrong if these settings are incorrect.
#
# END_HEADER$
#
# --------------------------------------------------------------------------
# Debugging and Factory Set Program Switches
# --------------------------------------------------------------------------
# Define constants
m_one        := -1
zero         := 0
one          := 1
two          := 2
three        := 3
four         := 4
five         := 5
c9k          := 9999
m_c9k        := -99999

bug1$        : 2     #0=No display, 1=Generic list box, 2=Editor
bug4$        : 1     #Debug output with the tilde '~'.
                     #A value greater the zero applies the variable formatting with
                     #debug output (default is typically FS 1 but not a guarantee).
                     #A value of zero gets the value directly with NO formatting.

linktolvar$  : 0     #Associate X tolerance variables to V9- variable?
linkplnvar$  : 1     #Associate X plane specific variables to V9- variable?

skp_lead_flgs$ : 0   #Do NOT use v9+ style contour flags
get_1004$    : 0     #Find gcode 1004 with getnextop?
rpd_typ_v7$  : 0     #Use Version 7 style contour flags/processing?
strtool_v7$  : 2     #Use Version 7+ toolname?
tlchng_aft$  : 2     #Delay call to toolchange until move line
cant_tlchng$ : 1     #Ignore cantext entry on move with tlchng_aft
newglobal$   : 1     #Error checking for global variables
getnextop$   : 1     #Build the next variable table
tooltable$   : 3     #Pre-read, call the pwrtt postblock (DO NOT CHANGE!)

# --------------------------------------------------------------------------
# General Output Settings
# --------------------------------------------------------------------------
linarc$      : yes$  #Linearize arcs? (DO NOT CHANGE!)
progname$    : 1     #Use uppercase for program name (sprogname)

# --------------------------------------------------------------------------
# Optional Output Settings
# --------------------------------------------------------------------------
output_comments : yes$  #Output Operation Comments in tool list?

outputxcom   : yes$  #Output new X comments? (Machine name, Group comment, Group name)

xyz_limits   : 3     #Output Max/Min X,Y,Z information?
                     #0 = Do NOT output ANY Max/Min X,Y,Z information.
                     #1 = Output Max/Min X,Y,Z info. ONLY for EACH tool (not Program)
                     #2 = Output Max/Min X,Y,Z info. ONLY for entire Program
                     #3 = Output Max/Min X,Y,Z info. for EACH tool AND Program (if > 1 tool)

# Individual axis output (if xyz_limits > 0)
X_limits     : yes$  #Output Max/Min values for the X axis?
Y_limits     : yes$  #Output Max/Min values for the Y axis?
Z_limits     : yes$  #Output Max/Min values for the Z axis?

# Specific setting to allow tuning the cycle time calculations
# Set the time it takes for machine to do a toolchange
tlchgtime    : 0.1   #Tool Change Time (* in Minutes *)

time_est     : 3     #Output operation and/or cycle times?
                     #0 = Do NOT output time estimates (including det_time estimates below)
                     #1 = Output operation time ONLY for EACH tool (not Program)
                     #2 = Output comeplete cycle time ONLY for entire Program
                     #3 = Output operation time for EACH tool AND cycle time for Program (if > 1 tool)

# The 'det_time' switch allows selecting the output of "Detailed Times".
# In addition to the usual 'Cycle Time' you can get the time spent at
# RAPID and at FEEDRATE during the program.
# *IMPORTANT* -
# Note that the Program TOTAL TIME includes the Toolchange time(s),
# so it will be longer than the Total RAPID time + Total FEED time!
det_time     : 3     #Output Rapid/Feedrate times? (Requires time_est > 0)
                     #0 = Do NOT output ANY Rapid/Feedrate time breakdown.
                     #1 = Output Rapid/Feedrate times ONLY for EACH tool (not Program)
                     #2 = Output Rapid/Feedrate times ONLY at end for entire program
                     #3 = Output Rapid/Feedrate times for EACH tool AND Program (if > 1 tool)

fr_limits    : 3     #Output Max/Min Feedrate information?
                     #0 = Do NOT output ANY Max/Min Feedrate information.
                     #1 = Output Max/Min Feedrate info. ONLY for EACH tool (not Program)
                     #2 = Output Max/Min Feedrate info. ONLY at end for entire program
                     #3 = Output Max/Min Feedrate info. for EACH tool AND Program (if > 1 tool)

show_lengths : 3     #Output Feed/Rapid path length information?
                     #0 = Do NOT output ANY Feed/Rapid path length information.
                     #1 = Output Feed/Rapid path length info. ONLY for EACH tool (not Program)
                     #2 = Output Feed/Rapid path length info. ONLY at end for entire program
                     #3 = Output Feed/Rapid path length info. for EACH tool AND Program (if > 1 tool)

stock_info        : yes$  #Display stock material and size/location?
show_tool_mfg     : yes$  #Output the tool definition - 'manufacturer' data?
show_chuck_name   : yes$  #Output the tool definition - 'chuck name' data?
show_tool_details : yes$  #Output tool details information (20000's data)?

# --------------------------------------------------------------------------
# Common User-defined Variable Initializations (not switches!)
# --------------------------------------------------------------------------
drlgsel      : -1     #Selector variable for drill cycle string
tol          : 0.0001 #Tolerence for feed rates set to zero
ttltime      : 0      #Total operation time
tltime       : 0      #Feed time
trtime       : 0      #Rapid time
total        : 0      #Total machine time
tot_ltime    : 0      #Total FEED time
tot_rtime    : 0      #Total RAPID time
len          : 0      #Length for calculation
dx           : 0      #Delta x
dy           : 0      #Delta y
dz           : 0      #Delta z
result       : 0      #Test Variable
comp         : 0      #CDC status from pre-scan (see 'look4comp')
comp_cc      : 0      #CDC status from pre-scan (see 'look4comp')
comp_cc_computer : 0  #CDC status from pre-scan (see 'look4comp')
look4comp    : yes$   #Buffer null toolchanges to search for comp (yes or no)
tool_end     : no$    #End flag when scanning for CDC settings at Null tlchgs
cdc_found    : no$    #Was an active CDC setting found during scan
sof          : 1      #Start of file flag
use_across   : 0      #Use across distance? (True/False)
toolop       : 0      #Modified tool_op$ for string selector lookup
hmm_type     : 0      #High speed machining style

# --------------------------------------------------------------------------
#String and string selector definitions for NC output
# --------------------------------------------------------------------------
#Seperator lines
sepline      : "--------------------------------------------------------------"
sepline2     : "========================================="
sepline3     : "=============================================================="

#Comment strings
snull        : ""     #Null string
smachname    : ""     #Machine name
sgrpcomm     : ""     #Group comment
sgrpname     : ""     #Group name
sopcomment   : ""     #Operation comment

#String variables to hold 'sparameter' string data
stl_mfg_com  : ""     #'tool mfg comment' from tool
stl_chuck_com : ""    #'tool chuck comment' from tool

soptype      : ""     #Operation type

# --------------------------------------------------------------------------
# Lookup tables
# --------------------------------------------------------------------------
flktbl 1     120
     # Note: "Unknown" entries must be made adjacent to known values to prevent flook's closest
     #         match from reporting incorrently on an unknown value
        "Unknown"                                                  0
        "Contour"                                                  1
        "Drilling - 3-Axis Output Format"                          2
        "Pocket"                                                   3
        "Transform"                                                4
        "Multisurface rough parallel"                              5
        "Multisurface rough radial"                                6
        "Multisurface rough project"                               7
        "Multisurface rough flowline"                              8
        "Multisurface rough contour"                               9
        "Multisurface rough pocket"                                10
        "Multisurface finish parallel"                             11
        "Multisurface finish radial"                               12
        "Multisurface finish project"                              13
        "Multisurface finish flowline"                             14
        "Multisurface finish contour"                              15
        "C-Hook created"                                           16
        "Manual entry"                                             17
        "Circle mill - 3-Axis Output Format"                       18
        "Point"                                                    19
        "Trimmed"                                                  20
        "Ruled"                                                    21
        "Revolved"                                                 22
        "Letters"                                                  23
        "Swept 2D"                                                 24
        "Swept 3D"                                                 25
        "Coons"                                                    26
        "Lofted"                                                   27
        "Drilling - 4-Axis or 5-Axis Output Format"                28
        "5-axis curve"                                             29
        "Project toolpath onto a plane"                            30
        "Project toolpath onto a cylinder"                         31
        "Project toolpath onto a sphere"                           32
        "Project toolpath onto a cone"                             33
        "Project toolpath onto a cross section"                    34
        "Project toolpath onto a surface"                          35
        "Non-associative contour"                                  36
        "Non-associative drilling"                                 37
        "Non-associative pocketing"                                38
        "Multisurface finish pencil trace"                         39
        "Multisurface finish leftover stock"                       40
        "Multisurface finish steep"                                41
        "Multisurface finish shallow"                              42
        "Multisurface finish constant scallop"                     43
        "Multisurface rough plunge"                                44
        "Multisurface finish 5-axis flowline"                      45
        "Multisurface finish 4-axis"                               46
        "Merged in ASCII NCI"                                      47
        "5-axis swarf"                                             48
        "5-axis roll die"                                          49
        "Unknown"                                                  50
        "Unknown"                                                  99
        "Thread mill"                                              100
        "Edit common operation parameters"                         101
        "Facing"                                                   102
        "Associative trimmed"                                      103
        "Solid drill control"                                      104
        "Slot mill"                                                105
        "Helix bore"                                               106
        "Multi-surface rough restmill"                             107
        "Associative nesting container"                            108
        "Multi-surface finish blend"                               109
        "Multi-surface 5-axis, rough"                              110
        "Slice 5-axis"                                             111
        "Port 5-axis"                                              112
        "Circle mill - 4-Axis or 5-Axis Output Format"             113
        "Advanced drill"                                           114
        "Chamfer drill"                                            115
        "Process Hole"                                             116
        "Unknown"                                                  129
        "Tab cutoff"                                               130
        "Multi-surface rough pocket, light"                        131
        "High-speed surface toolpaths"                             132
        "Nesting onionskin"                                        133
        "2D hardmill machining/peel mill"                          134
        "Saw"                                                      135
        "FBM drill control"                                        136
        "FBM mill pocket"                                          137
        "FBM mill contour"                                         138
        "Solid model"                                              139
        "2D model chamfer"                                         140
        "Unknown"                                                  141
        "Unknown"                                                  149
        "Probe cycle: probe motion"                                150
        "Probe cycle command block"                                151
        "Probe cycle header"                                       152
        "Probe cycle trailer"                                      153
        "SafetyZone linking or multiaxis linking"                  154
        "SafetyZone for multiaxis drill - only used for link_op$"  155
        "Unknown"                                                  156
        "Unknown"                                                  300
        "Router contour - obsolete"                                301
        "Router pocket - obsolete"                                 302
        "Router circmill - obsolete"                               303
        "Router cutoff - obsolete"                                 304
        "Router surface rough pocket - obsolete"                   305
        "Block drill"                                              306
        "Unknown"                                                  307
        "Unknown"                                                  415
        "Engraving"                                                416
        "Unknown"                                                  417
        "Unknown"                                                  438
        "Art"                                                      439
        "Advanced multiaxis X9 and older"                          440
        "Advanced multiaxis—swarf"                                 441
        "Advanced multiaxis—morph"                                 442
        "Advanced multiaxis—parallel"                              443
        "Advanced multiaxis—along curve"                           444
        "Advanced multiaxis—triangular mesh"                       445
        "Advanced multiaxis—roughing"                              446
        "Advanced multiaxis—project"                               447
        "Convert to 5-axis"                                        448
        "Port Expert"                                              449
        "Blade Expert"                                             450
        "Rotary advanced"                                          451
        "Unknown"                                                  452
        "Unknown"                                                  458
        "Deburr"                                                   459
        "3+2 Automatic roughing"                                   460
        "Unified milling"                                          461

# --------------------------------------------------------------------------
# Global assignments
# --------------------------------------------------------------------------
#Define operations to include in the category Drilling
drilling =
      (
      tool_op$ = 2   |  # Drill
      tool_op$ = 28  |  # 5-axis drilling
      tool_op$ = 37  |  # Non-associative drilling
      tool_op$ = 104 |  # Solid drill control operation
      tool_op$ = 114 |  # Advanced drill
      tool_op$ = 116 |  # Process Hole
      tool_op$ = 115 |  # Chamfer drill
      tool_op$ = 136 |  # FBM drill control operation
      tool_op$ = 306    # Block drill
      )

# --------------------------------------------------------------------------
# General String select tables
# --------------------------------------------------------------------------
#Select drill operation note
sdr00   : "SIMPLE"       #drill - no dwell
sdrd0   : "COUNTERBORE"  #drill - with dwell
sdr01   : "PECK"         #peck drill - no dwell
sdrd1   : "PECK"         #peck drill - with dwell
sdr02   : "CHIP BREAK"   #chip break - no dwell
sdrd2   : "CHIP BREAK"   #chip break - with dwell
sdr03   : "TAP"          #tap - right hand
sdrd3   : "TAP"          #tap - left hand
sdr04   : "SIMPLE BORE"  #bore #1 - no dwell
sdrd4   : "BORE W/DWELL" #bore #1 - with dwell
sdr05   : "BORE W/STOP"  #bore #2 - no dwell
sdrd5   : "BORE W/STOP"  #bore #2 - with dwell
sdr06   : "MISC_1"       #misc #1 - no dwell
sdrd6   : "MISC_1"       #misc #1 - with dwell
sdr07   : "MISC_2"       #misc #2 - right hand
sdrd7   : "MISC_2"       #misc #2 - left hand
sdrillcyc : ""           #Target string

fstrsel sdr00 drlgsel sdrillcyc 16 -1
# --------------------------------------------------------------------------
#Select stock orientation note
stk0    : "AT CENTER, Z AT TOP"
stk1    : "UPPER LEFT CORNER, Z AT TOP"
stk2    : "UPPER RIGHT CORNER, Z AT TOP"
stk3    : "LOWER RIGHT CORNER, Z AT TOP"
stk4    : "LOWER LEFT CORNER, Z AT TOP"
stk5    : "UPPER LEFT CORNER, Z AT BOTTOM"
stk6    : "UPPER RIGHT CORNER, Z AT BOTTOM"
stk7    : "LOWER RIGHT CORNER, Z AT BOTTOM"
stk8    : "LOWER LEFT CORNER, Z AT BOTTOM"
stknote : ""         #Target string

fstrsel stk0 stck_crnr$ stknote 9 -1
# --------------------------------------------------------------------------
#Month selector
smon0   : ""
smon1   : "JAN."
smon2   : "FEB."
smon3   : "MAR."
smon4   : "APR."
smon5   : "MAY."
smon6   : "JUN."
smon7   : "JUL."
smon8   : "AUG."
smon9   : "SEP."
smon10  : "OCT."
smon11  : "NOV."
smon12  : "DEC."
smonth  : ""         #Target string

fstrsel smon0 month$ smonth 13 -1
# --------------------------------------------------------------------------
# Format statements - n=nonmodal, l=leading, t=trailing, i=inc, d=delta
# --------------------------------------------------------------------------
fs2  1  0.4 0.3      #Decimal, absolute, 4/3 place, default for initialize (:)
fs2  2  0.4 0.3n     #Decimal, absolute, 4/3 place, non-modal
fs2  3  1 0 1 0n     #Integer, not leading, non-modal
fs2  4  0.2 0.2n     #Decimal, absolute, 2 place, non-modal
fs2  5  1.4 1.3ltn   #Decimal, absolute, 4/3 place, leading&trailing, non-modal
fs2  6 +1.4 1.3ltn   #Decimal, absolute, 4/3 place, leading&trailing with SIGN
fs2  7  0.4 0.3ltn   #Decimal, 4/3 place, trailing, non-modal
fs2  8  0^2 0^2n     #Decimal, 2 place, omit decimal if whole number, non-modal
fs2  9  4 0 4 0l     #Integer, force four leading

# These formats used for 'Date' & 'Time'
fs2 17  1 0 1 0      #Integer, not leading
fs2 18  2.2 2.2lt    #Decimal, force two leading & two trailing (time2)
fs2 19  2 0 2 0t     #Integer, force trailing                   (hour)
fs2 20  0 2 0 2lt    #Integer, force leading & trailing         (min)

# --------------------------------------------------------------------------
# Format assignments
# --------------------------------------------------------------------------
fmt     9   progno$     #Program number
fmt     3   t$          #Tool number
fmt     7   tldia$      #Tool diameter
fmt     7   tcr$        #Tool corner radius
fmt     3   tloffno$    #Diameter offset number
fmt     3   tlngno$     #Length offset number
fmt     3   ss$         #Spindle speed
fmt     4   fr_pos$     #Feedrate
fmt     2   llen        #Feed cut length
fmt     2   rlen        #Rapid traverse cut length
fmt     2   llen_total  #Feed cut length (program total)
fmt     2   rlen_total  #Rapid traverse cut length (program total)
fmt     2   total       #Total part time
fmt     2   ttltime     #Total operation time
fmt     3   thrs        #Time in hours
fmt     3   tmin        #Time in minutes
fmt     8   tsec        #Time in seconds
fmt     3   tcnt        #Tool Counter
fmt     3   custcycle   #Custom Cycle number
fmt     4   tmax_fr     #Max Feedrate in current Tool
fmt     4   tmin_fr     #Min Feedrate in current Tool
fmt     4   pmax_fr     #Max Feedrate in Program
fmt     4   pmin_fr     #Min Feedrate in Program
fmt  "X" 7  stck_ht$    #X - Stock Height
fmt  "Y" 7  stck_wdth$  #Y - Stock Width
fmt  "Z" 7  stck_thck$  #Z - Stock Thickness
fmt  "X" 2  stck_x$     #X origin of block
fmt  "Y" 2  stck_y$     #Y origin of block
fmt  "Z" 2  stck_z$     #Z origin of block
fmt     2   stck_crnr$  #Origin corner of stock
fmt  "" 3   op_number   #Operation number as seen in the Toolpath Manager
# -------------------------------------------------------------------------
# Variables to hold info read from 'additional parameters'
fmt     2   stock       #Amount of stock to leave
fmt     2   zstock      #Amount of stock to leave
fmt     2   drive_stock #Amount of stock to leave on drive surfaces
fmt     2   check_stock #Amount of stock to leave on check surfaces
fmt     2   wall_stock  #High speed machining - stock to leave on walls
fmt     2   floor_stock #High speed machining - stock to leave on floors
fmt     2   rgh_ang     #Roughing angle
fmt     2   rgh_step    #Roughing step size
fmt     2   num_fin     #Number of finish passes
fmt     2   fin_step    #Finish pass step size
fmt     2   fin_stk     #Finish allowance
fmt     2   across      #Across distance
fmt     2   along       #Along distance
fmt     2   cut_dir     #Cutting direction: 0 = along, 1 = across
fmt     2   use_cdev    #Use chordal deviation (0 = no, 1 = yes)
fmt     2   chdev       #Chordal deviation
fmt     2   total_tol   #Total tolerance - HMM toolpaths
fmt     2   step_down   #Stepdown distance
fmt     2   across_dist   #Across cut: distance
fmt     2   across_height #Across cut: scallop height
# --------------------------------------------------------------------------
# Numeric variables to hold '20004' tool parameters
# Do NOT change the order of these (16) variable definitions!
fmt     2   tl_number
fmt     3   tl_type
fmt     3   tl_material
fmt     3   tl_corner_typ  #0=flat, 1=bullnose, 3=ball
fmt     2   tl_dia
fmt     2   tl_corner_rad
fmt     2   tl_tpi
fmt     2   tl_tip_angle
fmt     3   tl_dia_ofs
fmt     3   tl_len_ofs
fmt     2   tl_feed
fmt     2   tl_plunge_feed
fmt     2   tl_retract_rate
fmt     2   tl_spindle_rpm
fmt     3   tl_coolant
fmt     3   tl_num_flutes
# --------------------------------------------------------------------------
# Numeric variables to hold '20005' DRILL type tool parameters
# Do NOT change the order of these (9) variable definitions !
fmt     3   drl_cycle$
fmt     2   drl_peck1
fmt     2   drl_peck2
fmt     2   drl_peck_clr
fmt     2   drl_chip_brk
fmt     2   drl_dwell
fmt     2   drl_angle
fmt     2   drl_tap_drl_dia
fmt     2   drl_shift
# --------------------------------------------------------------------------
# Numeric variables to hold '20006' MILL type tool parameters
# Do NOT change the order of these (8) variable definitions !
fmt     3   tl_cut_cap
fmt     2   tl_rgh_XY_step
fmt     2   tl_rgh_Z_step
fmt     2   tl_fin_XY_step
fmt     2   tl_fin_Z_step
fmt     2   tl_tip_dia
fmt     2   tl_minor_dia
fmt     2   tl_thrd_mill_angle
# --------------------------------------------------------------------------
# Numeric variables to hold '20007' MILL type tool holder parameters
# Do NOT change the order of these (11) variable definitions !
fmt     2   tl_min_dia_plg
fmt     2   tl_flute_len
fmt     2   tl_overall_len
fmt     2   tl_shld_len
fmt     2   tl_arbor_dia
fmt     2   tl_holder_dia
fmt     2   tl_holder_len
fmt     3   tl_dummy_pos8
fmt     3   tl_dummy_pos9
fmt     3   tl_dummy_pos10
fmt     3   tl_units    #0=inches, 1=metric
# --------------------------------------------------------------------------
#Format the variables used to output the X,Y,Z Max/Min values
fmt     6   max_Xpos
fmt     6   min_Xpos
fmt     6   max_Ypos
fmt     6   min_Ypos
fmt     6   max_Zpos
fmt     6   min_Zpos
# --------------------------------------------------------------------------
fmt     17  year2       #Calculated year value
fmt     18  time2       #Capture 24-hour time value into 'time2' variable
fmt     19  hour        #Hour
fmt     20  min         #Minutes
year2 = year$ + 2000

# --------------------------------------------------------------------------
# Tool Comment / Manual Entry Section
# --------------------------------------------------------------------------
pcomment$        #Comment from manual entry (must call pcomment2)
      pcomment2  #Required if doing boolean 'if' logic testing!

pcomment2        #Output Comment from manual entry
      sopcomment = snull
      scomm$ = ucase(scomm$)
      if gcode$ = 1051, smachname = scomm$   #Machine name
      if gcode$ = 1052, sgrpcomm = scomm$    #Group comment
      if gcode$ = 1053, sgrpname = scomm$    #Group name
      if gcode$ = 1008, sopcomment = scomm$  #Operation comment

pdrillcyc        #Output drillcycle type note if canned cycle was programmed
      if drilling & (nextdc$ >= zero & nextdc$ <=19),
        [
        " - ",
        if nextdc$ = three | nextdc$ = 7, drlgsel = fsg1(-ss$) + nextdc$ * two
        else, drlgsel = fsg2(dwell$) + nextdc$ * two
        if drlgsel > 15,  #Custom canned cycle was programmed
          [
          custcycle = drlgsel - 7  #Shift it
          "CUSTOM CYCLE ", 35, *custcycle
          ]
        else, *sdrillcyc
        ]

pprm_0           #Run parameter table
      if opcode$ = 1 | opcode$ = 2, pprm_1  #2D/3D Contour
      if opcode$ = 4, pprm_4    #Pocket
      if opcode$ = 5, pprm_5    #Ruled
      if opcode$ = 6, pprm_6    #2D Swept
      if opcode$ = 7, pprm_7    #3D Swept
      if opcode$ = 8, pprm_8    #Revolution
      if opcode$ = 9, pprm_9    #Loft
      if opcode$ = 10, pprm_10  #Coons
      if opcode$ = 13, pprm_13  #Surface Finish
      if opcode$ = 14, pprm_14  #Surface Rough
      if opcode$ = 19, pprm_19  #Face

pprm_1           #Output Parameters for 2D/3D Contour
      "STOCK TO LEAVE (XY)= ", *stock, e$
      "STOCK TO LEAVE (Z) = ", *zstock, e$

pprm_4           #Output Parameters for Pocket
      "STOCK TO LEAVE (XY)= ", *stock, e$
      "STOCK TO LEAVE (Z) = ", *zstock, e$
      "ROUGHING ANGLE = ", *rgh_ang, e$
      "ROUGHING STEP SIZE = ", *rgh_step, e$
      "NUMBER OF FINISH PASSES = ", *num_fin, e$
      "FINISH PASS STEP SIZE = ", *fin_step, e$
      "FINISH ALLOWANCE = ", *fin_stk, e$

pprm_5           #Output Parameters for Ruled
      "STOCK TO LEAVE = ", *stock, e$
      "ACROSS DISTANCE = ", *across, e$

pprm_6           #Output Parameters for 2d Swept
      "STOCK TO LEAVE = ", *stock, e$
      "ACROSS DISTANCE = ", *across, e$

pprm_7           #Output Parameters for 3d Swept
      "STOCK TO LEAVE = ", *stock, e$
      "ALONG DISTANCE = ", *along, e$
      "ACROSS DISTANCE = ", *across, e$
      "CUTTING DIRECTION: (0 = ALONG, 1 = ACROSS) = ", *cut_dir, e$

pprm_8           #Output Parameters for Revolved
      "STOCK TO LEAVE = ", *stock, e$
      "STEP SIZE = ", *fin_step, e$

pprm_9           #Output Parameters for Loft
      "STOCK TO LEAVE = ", *stock, e$
      "ALONG CUT DISTANCE = ", *along, e$
      "ACROSS CUT DISTANCE = ", *across, e$

pprm_10          #Output Parameters for Coons
      "STOCK TO LEAVE = ", *stock, e$
      "ALONG CUT DISTANCE = ", *along, e$
      "ACROSS CUT DISTANCE = ", *across, e$
      "CUTTING DIRECTION: (0 = ALONG, 1 = ACROSS) = ", *cut_dir, e$

pprm_13          #Output Parameters for Msurf Finish
      if tool_op$ = 132,  #Surface High Speed
        [
        "STOCK TO LEAVE ON WALLS = ", *wall_stock, e$
        "STOCK TO LEAVE ON FLOORS = ", *floor_stock, e$
        "TOTAL TOLERANCE = ", *total_tol, e$
        ]
      else,
        [
        "STOCK TO LEAVE ON DRIVE SURFACES = ", *drive_stock, e$
        "STOCK TO LEAVE ON CHECK SURFACES = ", *check_stock, e$
        "TOTAL TOLERANCE = ", *chdev, e$
        ]
      #Parallel, Parallel Steep, Shallow, Leftover, Scallop or Blend
      if tool_op$ = 11 | tool_op$ = 41 | tool_op$ = 42 | tool_op$ = 40 |
        tool_op$ = 43 | tool_op$ = 109, "MAXIMUM STEPOVER DISTANCE = ", *fin_step, e$
      if tool_op$ = 14,  #Flowline
        [
        if use_across, "STEPOVER DISTANCE = ", *across_dist, e$
        else, "SCALLOP HEIGHT = ", *across_height, e$
        ]
      if tool_op$ = 15, "MAXIMUM STEPDOWN DISTANCE = ", *step_down, e$  #Contour

pprm_14          #Output Parameters for Msurf Rough
      "STOCK TO LEAVE ON DRIVE SURFACES = ", *drive_stock, e$
      "STOCK TO LEAVE ON CHECK SURFACES = ", *check_stock, e$
      "TOTAL TOLERANCE = ", *chdev, e$
      #Parallel or Plunge
      if tool_op$ = 5 | tool_op$ = 44, "MAXIMUM STEPOVER DISTANCE = ", *rgh_step, e$
      #Parallel, Restmill or Pocket
      if tool_op$ = 5 | tool_op$ = 107 | tool_op$ = 10,
        "STEPOVER DISTANCE = ", *rgh_step, e$
      if tool_op$ = 8,  #Flowline
        [
        if use_across, "STEPOVER DISTANCE = ", *across_dist, e$
        else, "SCALLOP HEIGHT = ", *across_height, e$
        ]
      "MAXIMUM STEPDOWN DISTANCE = ", *step_down, e$

pprm_19          #Output Parameters for Facing
      "STOCK TO LEAVE = ", *stock, e$
      "STEP SIZE = ", *fin_step, e$

ptool_details    #Output requested tool details (20004, 20005, 20006, 20007 type)
      # 20004 = tool definition - 'tool parameters' data
      # 20005 = tool definition - 'DRILL type tool' parameters
      # 20006 = tool definition - 'MILL type tool' parameters
      # 20007 = tool definition - 'MILL type tool HOLDER' parameters
      if not(drilling), "NUMBER OF FLUTES = ", *tl_num_flutes, e$  #If NOT a canned cycle (drill) type toolpath
      else, "DRILL TIP ANGLE = ", *tl_tip_angle, e$  # If IS a canned cycle (drill) type toolpath
      "FLUTE LEN.    = ", *tl_flute_len, e$
      "OVERALL LEN.  = ", *tl_overall_len, e$
      "SHOULDER LEN. = ", *tl_shld_len, e$
      "ARBOR DIA.    = ", *tl_arbor_dia, e$
      "HOLDER DIA.   = ", *tl_holder_dia, e$

# --------------------------------------------------------------------------
# Start of File and Toolchange Setup
# --------------------------------------------------------------------------
ptimecalc        #Convert 24-hour time format into 12-hour AM/PM format
      if time$ >= 13, time2 = (time$ - 12)
      else, time2 = time$
      hour = int(time2), min = frac(time2)
      *hour, ":", *min,
      if time$ > 12, " PM"
      else, " AM"

pheader$         #Call before start of file
      if pst_rpd_fr$ <= 0, pst_rpd_fr$ = 300  #Make it greater than ZERO !
      tmax_fr = fr_pos$  #Initialize (max fr used in current tool)
      tmin_fr = fr_pos$  #Initialize (min fr used in current tool)
      pmax_fr = fr_pos$  #Initialize (max fr used in program)
      pmin_fr = fr_pos$  #Initialize (min fr used in program)
      "CUSTOMIZABLE ROUTER SETUP SHEET - ROUTER.SET", e$
      sepline2, e$
      " ", e$  #Blank line
      "PROGRAM NAME   = ", *sprogname$, e$
      if progno$ > zero, "PROGRAM NUMBER = ", *progno$, e$
      #Date/Time output
      #"DATE PROCESSED = ", month$, "-", day$, "-", year$, e$   #Date output as month,day,year - Ex. 02-12-05
      "DATE PROCESSED = ", *smonth, " ", day$, " ", *year2, e$  #Date output as month,day,year - Ex. Feb. 12 2005
      #"DATE PROCESSED (DD-MM-YY) = ", date$, " TIME(HH:MM) = ", time$, e$  #Date and time output Ex. 12-02-05 15:52
      #"TIME           = ", time$, e$                           #24 hour time output - Ex. 15:52
      "TIME           = ", ptimecalc, e$                        #12 hour time output 3:52 PM
      pstock_info  #Stock information output

psof0$           #Start of file for tool zero
      psof$

psof$            #Start of file for non-zero tool number
      psetup   #Call for toolchange info output
      sof = 0  #Reset start of file flag
      !op_id$

ptlchg0$         #Call from NCI null tool change (tool number repeats)
      !gcode$
      if op_id$ <> prv_op_id$, ptlchg$
      !op_id$

ptlchg$          #Tool change - Output of time calculations for the last tool run
      if op_id$ = prv_op_id$, ex$
      ptooldata          #Total ending data for tool (Path Length and Times)
      tmax_fr = fr_pos$  #Initialize (max fr used in current tool)
      tmin_fr = fr_pos$  #Initialize (min fr used in current tool)
      psetup             #Call for toolchange info output
      !op_id$

peof0$           #End of file for tool zero
      peof$

peof$            #End of file for non-zero tool - Output of time calculations for the last tool and total time
      ptooldata  #Total ending data for tool (Path Length and Times)
      #Supress Program totals if only one tool or no output selected
      if tcnt > one & (fr_limits | xyz_limits | show_lengths | time_est),
        [
        " ", e$  #Blank line
        sepline3, e$
        "PROGRAM TOTALS (", *tcnt, " TOOLS):", e$
        " ", e$ # Blank line

        #Output Max/Min Feedrate information
        if fr_limits = two | fr_limits = three,
          [
          "FEEDRATES: MAX = ", *pmax_fr, " MIN = ", *pmin_fr, e$
          #sepline, e$  #Output the separator '----' line
          ]

        #Output Max/Min X,Y,Z information
        if xyz_limits = two | xyz_limits = three,
          [
          preadbuf1e   #Read Buffer 1 (get X,Y,Z extents of entire program)
          pMaxMin      #Output Max/Min X,Y,Z coords for entire program
          #sepline, e$  #Output the separator '----' line
          ]

        #Output Feed/Rapid path lengths
        if show_lengths = two | show_lengths = three,
          [
          "TOTAL FEED CUT LENGTH = ", *llen_total, e$
          "TOTAL RAPID TRAVERSE LENGTH = ", *rlen_total, e$
          #sepline, e$  #Output the separator '----' line
          ]

        #Output Rapid/Feedrate times
        if time_est > 0 & (det_time = two | det_time = three),
          [
          ttltime = tot_rtime
          "TOTAL RAPID TIME = ", ptimeout, e$
          ttltime = tot_ltime
          "TOTAL FEED TIME = ", ptimeout, e$
          #sepline, e$  #Output the separator '----' line
          ]

        #Output Cycle Time information
        if time_est = two | time_est = three,
          [
          ttltime = total                #Transfer TOTAL program time
          "CYCLE TIME:  ", ptimeout, e$  #Program Total time output
          ]
        ]

psetup           #Output of toolchange information
      !gcode$
      tcnt = tcnt + one  #Tool Counter
      if look4comp = yes$, preadbuf2 #Look for CDC settings @ Null tlchgs
      else,  #Load CDC setting for the current tool change
        [
        comp_cc = cc$                    #Capture CDC in control setting
        comp_cc_computer = cc_computer$  #Capture CDC in computer setting
        ]
      comment$
      if sof & outputxcom,  #If start of file and outputxcom = yes$
        [
        if smachname <> snull, "MACHINE NAME   = ", smachname, e$  #Machine name
        if sgrpcomm <> snull, "GROUP COMMENT  = ", sgrpcomm, e$    #Group comment
        if sgrpname <> snull, "GROUP NAME     = ", sgrpname, e$    #Group name
        ]
      " ", e$  #Blank Line
      sepline, e$  #Output the separator '----' line
      op_number = opinfo(15240, 0)  # Get the operation number that's displayed in the Toolpath manager
      "OPERATION NUMBER = ", *op_number, e$
      soptype = flook(1, tool_op$)  # Get the operation type from lookup table number 1
      "OPERATION TYPE = ", soptype, pdrillcyc, e$
      if output_comments & sopcomment <> snull, "OPERATION COMMENT = " sopcomment, e$  #Operation comment
      if ra_type$,  #If aggregate head or block drill
        [
        "TOOL TYPE = "
        if ra_type$ = one, "RIGHT ANGLE AGGREGATE", e$
        if ra_type$ = two, "COMPOUND ANGLE AGGREGATE", e$
        if ra_type$ = three, "BLOCK DRILL", e$
        ]
      "TOOL NAME = ", *strtool$, e$
      if ra_type$ <> three,  #If NOT block drill
        [
        if show_tool_mfg & strlen(stl_mfg_com) > zero & stl_mfg_com <> " ",
          "TOOL DEF. (MANUFACTURER) = ", stl_mfg_com, e$
        if show_chuck_name & strlen(stl_mfg_com) > zero & stl_mfg_com <> " ",
          "TOOL DEF. (CHUCK) = ", stl_chuck_com, e$
        "TOOL NUM. = ", *t$, e$
        "TOOL DIA. = ", *tldia$, e$
        if show_tool_details, ptool_details
        if tcr$ > zero, "TOOL CORNER RAD. = ", *tcr$, e$
        "DIA. OFFSET = ", *tloffno$, e$
        "LEN. OFFSET = ", *tlngno$, e$
        if ss$ = zero, "SPINDLE OFF", e$
        if ss$ > zero, "SPINDLE = ", *ss$, e$
        if ss$ < zero,
          [
          ss$ = abs(ss$)
          "SPINDLE (*REVERSE*) = ", *ss$, e$
          ]
        ]
      if fr_pos$ = zero, "*ERROR* - THE FEEDRATE WAS SET TO ZERO", e$
      else, "FEEDRATE = ", *fr_pos$, e$
      # Show Cutter Diameter Compensation settings
      if not(drilling) & opcode$ < 13,  #If NOT a canned cycle (drill) or surface machining, output CDC setting
        [
        if comp_cc = zero & comp_cc_computer = zero, "CUTTER COMP. = OFF", e$
        if comp_cc <> zero & comp_cc_computer = zero,
          [
          "CUTTER COMP. (CONTROL) = "
          if comp_cc = 41, "LEFT", e$
          if comp_cc = 42, "RIGHT", e$
          ]
        if comp_cc = zero & comp_cc_computer <> zero,
          [
          "CUTTER COMP. (COMPUTER) = "
          if comp_cc_computer = 41, "LEFT", e$
          if comp_cc_computer = 42, "RIGHT", e$
          ]
        if comp_cc <> zero & comp_cc_computer <> zero,
          [
          if comp_cc = comp_cc_computer, "CUTTER COMP. (WEAR, IN CONTROL) = "
          else, "CUTTER COMP. (REVERSE WEAR, IN CONTROL) = "
          if comp_cc = 41, "LEFT", e$
          if comp_cc = 42, "RIGHT", e$
          ]
        ]
      if result = 1, pprm_0 # Output 'additional parameter' information
      #else, "*** NO ADDITIONAL PARAMETER' INFORMATION AVAILABLE ", e
      llen = zero     #Reset counter for next tool
      rlen = zero     #Reset counter for next tool
      tltime = zero   #Reset counter for next tool
      trtime = zero   #Reset counter for next tool
      ttltime = zero  #Reset counter for next tool
      x$ = xh$, y$ = yh$, z$ = zh$
      !x$, !y$, !z$, !fr_pos$  #Update previous [prv_?] variables

ptooldata        #Total ending data for tool (Path Length and Times)
      #Output Max/Min Feedrate used during prior toolpath
      if not(drilling) & (fr_limits = one | fr_limits = three),
        [
        "FEEDRATES: MAX = ", tmax_fr, " MIN = ", tmin_fr, e$
        #"MAX FEEDRATE IN TOOLPATH = ", tmax_fr, e
        #"MIN FEEDRATE IN TOOLPATH = ", tmin_fr, e
        #sepline, e$  #Output the separator '----' line
        ]

      #Output Max/Min X,Y,Z information
      if xyz_limits = one | xyz_limits = three,
        [
        preadbuf1t   #Read the data from the Buffer 1
        pMaxMin      #Output Max/Min X,Y,Z coords during this tool operation
        #sepline, e$  #Output the separator '----' line
        ]

      #Output Feed/Rapid path lengths
      if show_lengths = one | show_lengths = three,
        [
        "TOOL FEED CUT LENGTH = ", *llen, e$
        "TOOL RAPID TRAVERSE LENGTH = ", *rlen, e$
        #sepline, e$  #Output the separator '----' line
        ]
      llen_total = llen_total + llen  #Keep running total for Program
      rlen_total = rlen_total + rlen  #Keep running total for Program

      #Output Rapid/Feedrate times
      if time_est > 0 & (det_time = one | det_time = three),
        [
        ttltime = trtime
        "RAPID TIME = ", ptimeout, e$  #Time at RAPID RATE (for last tool)
        ttltime = tltime
        "FEED TIME  = ", ptimeout, e$  #Time at FEEDRATE (for last tool)
        #sepline, e$  #Output the separator '----' line
        ]

      pttltime  #Total tool times
      #Output Cycle Time information
      if time_est = one | time_est = three,
        [
        "OPERATION TIME = ", ptimeout, e$  #This operations time output
        #sepline, e$  #Output the separator '----' line
        ]

pthrminsec       #Convert minutes to hr/min/sec format
      thrs = int(ttltime / 60)
      tmin = int(ttltime - thrs * 60)
      tsec = (ttltime - thrs * 60 - tmin) * 60

pttltime         #Total tool times and total program time
      tot_ltime = tot_ltime + tltime      #Total FEED time
      tot_rtime = tot_rtime + trtime      #Total RAPID time
      ttltime = tltime + trtime           #Calc. current Tool Time
      total = ttltime + total + tlchgtime #Calc. total Program Time

ptimeout         #Output "times"
      pthrminsec  #Convert minutes to hr/min/sec format
      #Output 'HOURS'
      if thrs = one, *thrs, " HOUR, "
      if thrs > one, *thrs, " HOURS, "
      #Output 'MINUTES'
      if tmin = one, *tmin, " MINUTE, "
      if tmin > one, *tmin, " MINUTES, "
      #Output 'SECONDS'
      if tsec > zero, *tsec, " SECONDS"

ptimer           #Rapid time and length calc
      rlen = rlen + len            #Running total RAPID length
      trtime = rlen / pst_rpd_fr$  #Running total RAPID time

ptimel           #Feed time and length calc
      if fr_pos$ < zero, fr_pos$ = prv_fr_pos$
      if fr_pos$ < tol, fr_pos$ = tol
      llen = llen + len
      tltime = tltime + len / fr_pos$

ptime            #Distance calculations
      dx = x$ - prv_x$
      dy = y$ - prv_y$
      dz = z$ - prv_z$
      len = sqrt(dx^2 + dy^2 + dz^2)
      if gcode$ = zero, ptimer  #RAPID time and length calc
      if gcode$ = one, ptimel   #FEED  time and length calc
      !x$, !y$, !z$, !fr_pos$   #Update previous [prv_?] variables
      if fr_limits, pfrcheck    #Track MAX/MIN Feedrates if requested

pfrcheck         #Track Feedrates (Max/Min)
      if fr_pos$ > zero,
        [
        if fr_pos$ < tmin_fr, tmin_fr = fr_pos$  #Tool MIN
        if fr_pos$ > tmax_fr, tmax_fr = fr_pos$  #Tool MAX
        if fr_pos$ < pmin_fr, pmin_fr = fr_pos$  #Program MIN
        if fr_pos$ > pmax_fr, pmax_fr = fr_pos$  #Program MAX
        ]

pstock_info      #Output stock information if requested
      if stock_info,
        [
        "MATERIAL TYPE  = "
        if stck_matl$ = "NONE" | stck_matl$ = "", "*NOT DEFINED*", e$  #No material type was selected
        else, stck_matl$, e$
        #" ", e$ # Blank line
        ]
      if stock_info & tlplnno$ <= one, #ONLY if in TOP plane
        [
        #If any stock values are empty, disable don't output
        if stck_ht$ > 0 & stck_wdth$ > 0 & stck_thck$ > 0,
          [
          "STOCK SIZE     = ", stck_ht$, " ", stck_wdth$, " ", stck_thck$, e$
          "STOCK ORIGIN   = ", stck_x$, " ", stck_y$, " ", stck_z$, "(", *stknote, ")", e$
          #" ", e$ # Blank line
          ]
        ]

pMaxMin          #Output Max/Min X,Y, Z coordinates
      #Output MAX/MIN positions in the X,Y and Z axis
      if X_limits = yes$, "MAX_X = ", *max_Xpos, "  MIN_X = ", *min_Xpos, e$
      if Y_limits = yes$, "MAX_Y = ", *max_Ypos, "  MIN_Y = ", *min_Ypos, e$
      if Z_limits = yes$, "MAX_Z = ", *max_Zpos, "  MIN_Z = ", *min_Zpos, e$

# --------------------------------------------------------------------------
# Motion NC output
# --------------------------------------------------------------------------
prapid$          #Output to NC of linear movement - rapid
      ptime

pzrapid$         #Output to NC of linear movement - rapid Z only
      ptime

plin$            #Output to NC of linear movement - feed
      ptime

pz$              #Output to NC of linear movement - feed Z only
      ptime

# --------------------------------------------------------------------------
# Parameter read postblocks:
# --------------------------------------------------------------------------
pprep$           #Pre-process postblock
#Allows post instructions after the post is parsed but before the NC and NCI file are opened.
#DO NOT ATTEMPT TO OUTPUT TO THE NC FILE IN THIS POSTBLOCK (OR ANY POSTBLOCKS YOU MAY CALL FROM HERE)
#BECAUSE THE NC OUTPUT FILE IS NOT YET OPENED!
#      rd_mch_ent_no$ = 0  #Read only the machine base parameters (use to collect common parameters from CNC_MACHINE_TYPE)
#      rd_md$       #Read machine definition parameters
      rd_cd$       #Read CD Parameters
      sub_level$ = 0     #Force subs off
      subout$ = 0        #Force output stream to NC file
      comm_filter$ = 0   #Allow output of all comments
      #sextnc$ = ".doc"  #Uncomment and change extension here to override
      #Force longhand drilling cycles for proper time estimate
      usecandrill$ = no$   #Use canned cycle for drill
      usecanpeck$  = no$   #Use canned cycle for Peck
      usecanchip$  = no$   #Use canned cycle for Chip Break
      usecantap$   = no$   #Use canned cycle for Tap
      usecanbore1$ = no$   #Use canned cycle for Bore1
      usecanbore2$ = no$   #Use canned cycle for Bore2
      usecanmisc1$ = no$   #Use canned cycle for Misc1
      usecanmisc2$ = no$   #Use canned cycle for Misc2
      spaces$ = 0
      use_alt_eob$ = no$

pwrtt$           #Pre-read NCI file
      pwritbuf1  #Write MAX/MIN X,Y,Z values to Buffer 1
      pwritbuf2  #Write COMP data to Buffer 2
      !op_id$

pparameter$      #Read operation parameters
      #rd_params is used to call pparameter postblock and read the parameters of the operation specified in rd_param_op_no
      #"pparameter", ~prmcode$, ~sparameter$, e$
      #Read tool definition data
      if prmcode$ = 20002, stl_mfg_com = sparameter$              #'manufacturer' data
      if prmcode$ = 20003, stl_chuck_com = sparameter$            #'chuck name' data
      if prmcode$ = 20004, tl_number = rpar(sparameter$, 16)      #'tool parameters' data
      if prmcode$ = 20005, drl_cycle$ = rpar(sparameter$, 9)      #'DRILL type tool' parameters
      if prmcode$ = 20006, tl_cut_cap = rpar(sparameter$, 8)      #'MILL type tool' parameters
      if prmcode$ = 20007, tl_min_dia_plg = rpar(sparameter$, 11) #'MILL type tool HOLDER' parameters
      result = fprm(opcode$)  #Run the parameter table for current OPCODE

# --------------------------------------------------------------------------
# Parameter lookup tables - You must adjust the size value if you add any parameters to these tables!
# --------------------------------------------------------------------------
fprmtbl 1       2   #2D Contour
        10010   stock     #XY stock to leave
        10068   zstock    #Z stock to leave

fprmtbl 2       2   #3D Contour
        10010   stock     #XY stock to leave
        10068   zstock    #Z stock to leave

fprmtbl 4       7   #Pocket
        10010   stock     #XY stock to leave
        10068   zstock    #Z stock to leave
        10301   rgh_ang   #Roughing angle
        10302   rgh_step  #Roughing step size
        10304   num_fin   #Number of finish passes
        10305   fin_step  #Finish pass step size
        10314   fin_stk   #Finish allowance

fprmtbl 5       2   #Ruled
        10010   stock     #Stock to leave
        12217   across    #Across distance

fprmtbl 6       2   #2d Swept
        10010   stock     #Stock to leave
        12239   across    #Across distance

fprmtbl 7       4   #3d Swept
        10010   stock     #Stock to leave
        12238   along     #Along distance
        12239   across    #Across distance
        12240   cut_dir   #Cutting direction: 0 = along, 1 = across

fprmtbl 8       2   #Revolution
        10010   stock     #Stock to leave
        12054   fin_step  #Step size

fprmtbl 9       3   #Loft
        10010   stock     #Stock to leave
        12238   along     #Along cut distance
        12239   across    #Across cut distance

fprmtbl 10      4   #Coons
        10010   stock     #Stock to leave
        12238   along     #Along cut distance
        12239   across    #Across cut distance
        12240   cut_dir   #Cutting direction: 0 = along, 1 = across

fprmtbl 13      13  #Multisurface Finish & HMM toolpaths
        10010   drive_stock   #Stock to leave on drive surfaces
        10227   check_stock   #Stock to leave on check surfaces
        10204   chdev         #Cut tolerance
        10205   fin_step      #Stepover distance
        12411   step_down     #Stepdown distance
        12117   use_across    #Use across cut distance (True/False)
        12118   across_dist   #Across cut: distance
        12119   across_height #Across cut: scallop height
        12302   fin_step      #Finish blend max stepover
        12628   hmm_type      #High speed machining style
        12665   wall_stock    #High speed machining - stock to leave on walls
        12666   floor_stock   #High speed machining - stock to leave on floors
        12593   total_tol     #Total cut tolerance - High speed machnining

fprmtbl 14      10  #Multisurface Rough
        10010   drive_stock   #Stock to leave on drive surfaces
        10227   check_stock   #Stock to leave on check surfaces
        10204   chdev         #Cut tolerance
        10205   rgh_step      #Stepover distance
        12411   step_down     #Stepdown distance
        12117   use_across    #Use across cut distance (True/False)
        12118   across_dist   #Across cut: distance
        12119   across_height #Across cut: scallop height
        12124   rgh_step      #Restmill stepover distance
        10302   rgh_step      #Rough pocket stepover distance

fprmtbl 19      2   #Face
        10010   stock     #Stock to leave
        12054   fin_step  #Step size

# --------------------------------------------------------------------------
# Machine Definition Parameters
fprmtbl 17000  0    #Table Number, Size
#       Param   Variable to load value into

# Control Definition Parameters
fprmtbl 18000  0    #Table Number, Size
#       Param   Variable to load value into

# Toolpath Group Parameters
fprmtbl 19000  0    #Table Number, Size
#       Param   Variable to load value into

# --------------------------------------------------------------------------
# Machine definition and control definition parameter capture:
# --------------------------------------------------------------------------
pmachineinfo$   #Machine information parameters postblock
      #rd_md is used to call pmachineinfo postblock and read the parameters of the selected axis
      #combination machine entity set in rd_mch_ent_no
      #rd_cd is used to call pmachineinfo postblock and read the active control definition parameters
      #rd_tlpathgrp is used to call pmachineinfo postblock and read the active toolpath group parameters
      #"-->pmachineinfo", ~prmcode$, "  ", ~sparameter$, e$  #Do not uncomment if being called from pprep$ - see pprep comment

      #Read parameter lookup tables -
      #Leave lines below commented until you enter values in related lookup tables
      #if prmcode$ >= 17000 & prmcode$ < 18000, result = fprm(17000) #Run the parameter table for Machine Definition Parameters
      #if prmcode$ >= 18000 & prmcode$ < 19000, result = fprm(18000) #Run the parameter table for Control Definition Parameters
      #if prmcode$ >= 19000 & prmcode$ < 19900, result = fprm(19000) #Run the parameter table for Toolpath Group Parameters

# --------------------------------------------------------------------------
# Buffer 1 definition (for Max/Min X,Y,Z storage)
# --------------------------------------------------------------------------
rc1          : 2     #Buffer1 READ pointer (YES, '2' is correct for this case!)
wc1          : 1     #Buffer1 WRITE pointer
size1        : 0     #To hold 'size' of Buffer 1

b1_gcode     : 0     #Stored in Buffer #1
b1_tcode     : 0     #        "
b1_xmax      : 0     #        "
b1_xmin      : 0     #        "
b1_ymax      : 0     #        "
b1_ymin      : 0     #        "
b1_zmax      : 0     #        "
b1_zmin      : 0     #        "

fbuf 1 0 8 0 0       #Declare Buffer1 to hold Min/Max X,Y,Z axis info.

# --------------------------------------------------------------------------
# Buffer 1  Read / Write Routines
# --------------------------------------------------------------------------
pinit            #Initialize the limit checking variables
      max_Xpos = m_c9k  #Initialize
      min_Xpos = c9k    #     "
      max_Ypos = m_c9k  #     "
      min_Ypos = c9k    #     "
      max_Zpos = m_c9k  #     "
      min_Zpos = c9k    #     "

plimits          #Check for NEW X,Y,Z limits
      if b1_xmax > max_Xpos, max_Xpos = b1_xmax
      if b1_xmin < min_Xpos, min_Xpos = b1_xmin
      if b1_ymax > max_Ypos, max_Ypos = b1_ymax
      if b1_ymin < min_Ypos, min_Ypos = b1_ymin
      if b1_zmax > max_Zpos, max_Zpos = b1_zmax
      if b1_zmin < min_Zpos, min_Zpos = b1_zmin

pwritbuf1        #Write Buffer 1
      b1_gcode = gcode$
      if gcode$ = 1002 & op_id$ = prv_op_id$, b1_gcode = 1000
      if gcode$ = 1000 & op_id$ <> prv_op_id$, b1_gcode = 1002
      b1_tcode = t$
      b1_xmax  = x_max$
      b1_xmin  = x_min$
      b1_ymax  = y_max$
      b1_ymin  = y_min$
      b1_zmax  = z_max$
      b1_zmin  = z_min$
      b1_gcode = wbuf(one, wc1)  #Write the record

preadbuf1t       #Read Buffer 1 (at the toolchanges for X,Y,Z limits)
      pinit                      #Initialize the limit checking variables
      b1_gcode = rbuf(one, rc1)  #Read a record from the Buffer
      plimits                    #Check for NEW limits

      #Loop thru possible NULL toolchanges
      while b1_gcode = 1000,  #Find the next NON-NULL toolchange
        [
        b1_gcode = rbuf(one, rc1)  #Read the next record from the Buffer
        plimits                    #Check for NEW limits
        ]

preadbuf1e       #Read Buffer 1 (at the END of Program for X,Y,Z limits)
      pinit                    #Initialize the limit checking variables
      size1 = rbuf(one, zero)  #Get the size of the Buffer 1
      rc1 = two                #Reset read pointer (SKIP 1st record!)
      while rc1 <= size1,      #Loop thru entire program
        [
        b1_gcode = rbuf(one, rc1)  #Read a record from the Buffer
        plimits                    #Check for NEW limits
        ]

# --------------------------------------------------------------------------
# Buffer 2 definition (for CDC settings storage)
# --------------------------------------------------------------------------
rc2          : 1     #Buffer2 READ pointer
wc2          : 1     #Buffer2 WRITE pointer
size2        : 0     #To hold 'size' of Buffer 2

b2_gcode     : 0     #Data stored in Buffer 2
b2_ccomp     : 0     #Data stored in Buffer 2
b2_cc        : 0     #Data stored in Buffer 2 (comp. in control setting)
b2_cc_computer : 0   #Data stored in Buffer 2 (comp. in computer setting)

fbuf 2 0 4 0 0       #Declare Buffer2 to hold cutter dia. comp. settings

# --------------------------------------------------------------------------
# Buffer 2  Read / Write Routines
# --------------------------------------------------------------------------
pwritbuf2        #Write Buffer 2
      b2_gcode = gcode$
      if gcode$ = 1002 & op_id$ = prv_op_id$, b2_gcode = 1000
      if gcode$ = 1000 & op_id$ <> prv_op_id$, b2_gcode = 1002
      b2_ccomp = ccomp$
      b2_cc = cc$
      b2_cc_computer = cc_computer$
      b2_gcode = wbuf(two, wc2)  #Write the record

preadbuf2        #Read Buffer 2 (at the toolchanges for cutter comp setting)
      #Reset flags
      size2 = rbuf(2,0) # Get the number of records on Buffer 2
      comp_cc = zero
      comp_cc_computer = zero
      cdc_found = no$
      tool_end = no$

      b2_gcode = rbuf(two, rc2)  #Read a record from the Buffer
      if b2_cc <> zero | b2_cc_computer <> zero,  #Tool change has active CDC
        [
        cdc_found = yes$
        comp_cc = b2_cc
        comp_cc_computer = b2_cc_computer
        ]
      while rc2 <= size2 & tool_end = no$,  #Loop thru to next tool change
        [
        b2_gcode = rbuf(two, rc2)  #Read the next record
        if b2_gcode = 1000,  #If Null tool change encountered
          [
          if cdc_found = no$,  #There was no CDC setting on the tool change
            [
            if b2_cc <> zero | b2_cc_computer <> zero,  #Null tool change has active CDC
              [
              cdc_found = yes$  #Report the CDC from the Null tool change
              comp_cc = b2_cc
              comp_cc_computer = b2_cc_computer
              ]
            ]
          ]
        else, tool_end = yes$  #End of tool encountered break out of loop
        ]
      rc2 = rc2 - one  #Back up 1 record

# --------------------------------------------------------------------------

