545,780 active members*
2,245 visitors online*
Register for free
Login
IndustryArena Forum > CAM Software > Mastercam > Post Processors for MC > Mastercam post for Fagor 8055M
Results 1 to 20 of 20
  1. #1
    Registered
    Join Date
    Nov 2005
    Posts
    8

    Exclamation Mastercam post for Fagor 8055M

    I am running Mastercam 9, I downloaded a post from emastercam, but I can't post directly to the machine, I have to go through the Fagor dnc program then upload it to the machine into programs. When I start the program I get get an error message: 0002 Improper data. N114 G43 D1 Z50 if I delete the line from the program it then runs through the rest of the program which at the moment seem to be fine, at the end of the program the machine returns to its home position, but likewise if I delete the line from the program it stops at the end without returning to its home position. Can anyone help me modify my post so that I don't have to do this? Or help me post directly to the machine?

  2. #2
    Member
    Join Date
    Jul 2003
    Posts
    1220
    jaangi
    I don't have MC but do use a Fagor 8055M
    I believe your line N114 G43 D1 Z50 should have Z before the D.
    eg: N114 G43 Z50 D1
    Not sure why your machine returns to home at the end.

  3. #3
    Registered
    Join Date
    Apr 2003
    Posts
    1876
    If you're looking to modify your post, you need to post the code you're getting, the code you want, and we should be able to get the post working for you.

    As for getting the file to the machine, there are, as with many aspects of MC, many options to do it. Your best bet might be to call the transfer program from the post after it finishes posting, or call the post from a script then launch the transfer program from the script.
    Matt
    San Diego, Ca

    ___ o o o_
    [l_,[_____],
    l---L - □lllllll□-
    ( )_) ( )_)--)_)

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  4. #4
    Registered
    Join Date
    Nov 2005
    Posts
    8
    Thanks. I changed the line so that the Z is before the D and that worked I also have to delete the next line which is G53 and G53 X0 Y0 Z0 at the end of the program to stop the machine returning to its home position. How and what do I need to do to mod my post so that it will work without having to do this?

  5. #5
    Registered
    Join Date
    Apr 2003
    Posts
    1876
    Should be in the PEOF function somewhere. Make a backup before you start editing.

    HTML Code:
    peof            #End of file for non-zero tool
          iseof = 1
          pretract
          iseof = 0
          spaces=0
          comment
          spaces=sav_spc
          #Remove pound character to output first tool with staged tools
          #if stagetool = one, pbld, n, *first_tool, e
          n, "G52", "X-40.", e
          if stagetool <> 0, pbld, n, "M06", e
          #if t <> first_tool, n, first_tool, "M06", e
          if sav_mi3 = 1, n, "M33", e
          n, "M30", e
          mergesub
          clearsub
          mergeaux
          clearaux
          "%", e
    Matt
    San Diego, Ca

    ___ o o o_
    [l_,[_____],
    l---L - □lllllll□-
    ( )_) ( )_)--)_)

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  6. #6
    Registered
    Join Date
    Nov 2005
    Posts
    8
    Hi Matt

    I tried to edit my post but came with an iseof error, I have probably done something wrong, perhaps if you could take a look at my post below you could advise me?
    Thanks
    Mike
    Code:
    # Post Name           : MASTER_FAGOR
    # Product             : MILL
    # Machine Name        : MACHINE
    # Control Name        : FAGOR 8050/8055 M CNC
    # Description         : IHS MASTER GENERIC MILL G-CODE POST
    # Associated Post     : NONE
    # Mill/Turn           : NO
    # 4-axis/Axis subs.   : YES
    # 5-axis              : NO
    # Subprograms         : YES
    # Executable          : MP v9.05
    #
    # WARNING: THIS POST IS GENERIC AND IS INTENDED FOR MODIFICATION TO
    # THE MACHINE TOOL REQUIREMENTS AND PERSONAL PREFERENCE.
    #
    # --------------------------------------------------------------------------
    # Revision log:
    # --------------------------------------------------------------------------
    # Programmers Note:
    # IHS 01/30/02  -  Mpmaster based on CNC Software's V8/V9 Mpfan, dat
    # IHS 01/30/02  -  Initial post update for V9, dat
    # IHS 04/01/02  -  Comments repeated in translational subs, dat
    # IHS 05/01/02  -  lock_codes logic tweak, dat
    # IHS 05/07/02  -  arccheck set to 3, dat
    # IHS 05/17/02  -  Removed null comment from subs, dat
    # IHS 05/24/02  -  Rotary subprograms mod, dat
    # IHS 07/17/02  -  Incremental drilling calculation mod, dat
    # IHS 07/25/02  -  Switch added to control rotary index move retracts, dat
    # XXX MM/DD/02  -  Written for Company X from Mpmaster, xxx
    #
    # --------------------------------------------------------------------------
    # Features:     
    # --------------------------------------------------------------------------
    # This post supports Generic Fagor code output for 3 and 4 axis milling.
    # It is designed to support the features of Mastercam Mill V9.
    # 
    # Following Misc. Integers are used:
    # mi2 - Absolute or Incremental positioning at top level
    #        0 = absolute
    #        1 = incremental
    #
    # mi9 - Lock on First WCS - Set in first operation
    #        0 = No
    #        1 = Yes
    #
    # mi10 - M00 before operation
    #         0 = No
    #         1 = Yes
    #
    # Work offsets:
    # wcstype - Work coordinate system 
    #            0 = Reference return is generated and G92 with the 
    #                X, Y and Z home positions at file head.
    #            1 = Reference return is generated and G92 with the 
    #                X, Y and Z home positions at each tool.
    #            2 = WCS of G54, G55.... based on Mastercam settings.
    #                0 thru 5 = The WCS of G54 thru G59 respectively.
    #                6 and up = The WCS of G54.1 P1 and up.
    #            3 = Off
    #
    #Canned text:
    #    Entering cantext on a contour point from within Mastercam allows the
    #    following functions to enable/disable.
    #    Cantext value:
    #    1 = Stop = output the "M00" stop code
    #    2 = Ostop =  output the "M01" optional stop code
    #    3 = Bld on = turn on block delete codes in NC lines
    #    4 = bLd off = turn off block delete codes in NC lines
    #    5 = Dwell = Input G04 K100 command
    #
    #Milling toolpaths (4 axis)
    #Layout:
    # The term "Reference View" refers to the coordinate system associated
    # with the Top view (Alt-F9, the upper gnomon of the three displayed).
    # Create the part drawing with the axis of rotation about the axis
    # of the "Reference View" according to the setting you entered for
    # 'vmc' (vertical or horizontal) and 'rot_on_x' (machine relative
    # axis of rotation).
    # vmc = 1 (vertical machine) uses the top toolplane as the base machine
    # view.
    # vmc = 0 (horizontal machine) uses the front toolplane as the base machine
    # view.
    # Relative to the machine matrix -
    # Rotation zero position is on the Z axis for rotation on X axis.
    # Rotation zero position is on the Z axis for rotation on Y axis.
    # Rotation zero position is on the X axis for rotation on Z axis.
    # The machine view rotated about the selected axis as a "single axis
    # rotation" are the only legal views for 4 axis milling.  Rotation
    # direction around the part is positive in the CCW direction when
    # viewed from the plus direction of the rotating axis.  Set the variable 
    # 'rot_ccw_pos' to indicate the signed direction.  Always set the work
    # origin at the center of rotation.
    #
    #Toolplane Positioning:
    # Create the Cplane and Tplane as the rotation of the machine view about 
    # the selected axis of rotation.  The toolplane is used to calculate
    # the position of the rotary axis.  This is the default setting.
    #
    #3 Axis Rotary (Polar)
    # Polar positioning is offered in Mastercam 3 axis toolpaths through the 
    # rotary axis options dialog.  The selected toolpath is converted to angle
    # and radius position.  The axis of rotation is forced to zero.
    #
    #Axis substitution:
    # Use the Rotary axis substitution by drawing the geometry flattened
    # from the cylinder.  The rotary axis button must be active for axis
    # substitution information to be output to the NCI file. The radius of
    # the rotary diameter is added to all the Z positions at output.  
    #
    #Simultaneous 4 Axis (11 gcode):
    # Full 4 axis toolpaths can be generated from various toolpaths under the 
    # 'multi-axis' selection (i.e. Rotary 4 axis). All 5 axis paths are
    # converted to 4 axis paths where only the angle about the rotation axis
    # is resolved. 
    #
    #Drill:
    # All drill methods are supported in the post.  See Simultaneous 4 Axis.
    #
    #Additional Notes:
    # 1) Disable 4 axis by setting the numbered question 164. to 'n'.
    # 2) G54 calls are generated where the work offset entry of 0 = G54,
    #    1 = G55, etc.
    # 3) Metric is applied from the NCI met_tool variable.
    # 4) Incremental mode calculates motion from home position at toolchanges.
    #    The home position is used to define the last position of the tool
    #    for all toolchanges.  
    # 5) The variable 'absinc' is now pre-defined, set mi2 (Misc. Integer) for
    #    the 'top level' absolute/incremental program output.  Subprograms are
    #    updated through the Mastercam dialog settings for sub-programs.
    # 6) Always avoid machining to the center of rotation with rotary axis!
    # 7) Transform subprograms are intended for use with G54.. workshifts. 
    #
    # --------------------------------------------------------------------------
    # General Output Settings
    # --------------------------------------------------------------------------
    spaces      : 1     #Number of spaces to add between fields
    omitseq     : no    #Omit sequence numbers?
    seqmax      : 9999  #Max. sequence number
    arcoutput   : 0     #0 = IJK, 1 = R no sign, 2 = R signed neg. over 180
    arctype     : 2     #Arc center 1=abs, 2=St-Ctr, 3=Ctr-St, 4=unsigned inc.
    breakarcs   : 2     #Break arcs, 0 = no, 1 = quadrants, 2 = 180deg. max arcs
    do_full_arc : 0     #Allow full circle output? 0=no, 1=yes
    helix_arc   : 1     #Support helix arc output, 0=no, 1=all planes, 2=XY plane only
    maxrad      : 999   #Maximum arc radius
    hel_2100    : no    #Acramatic 2100 style helical moves, 0=no, 1=yes 
    usecanned   : yes   #Use canned drilling cycles?  Set to no for long output.
    wcstype     : 2     #0 = G92 at start, 1 = G92 at toolchanges, 2 = G54, 3 = Off
    force_wcs   : yes   #Force WCS output at every toolchange?
    stagetool   : 0     #0 = Do not pre-stage tools, 1 = Stage tools
    tool_table  : 1     #Tool table, 0=no, 1=yes, 2=Predator VCNC, 3=MetaCut View
    output_z    : yes   #Output Z Min and Z Max values (yes or no)
    cool_zmove  : yes   #Coolant off with last move
    use_pitch   : 0     #0 = Use feed for tapping, 1 = Use pitch for tapping
    maxfeedpm   : 500   #Limit for feed in inch/min
    maxfeedpm_m : 10000 #Limit for feed in mm/min
    use_gear    : 0     #Output gear selection code, 0=no, 1=yes 
    max_speed   : 10000 #Maximum spindle speed
    min_speed   : 50    #Minimum spindle speed
    sextnc      .PIM    #NC extension override
    
    # --------------------------------------------------------------------------
    # Rotary Axis Settings
    # --------------------------------------------------------------------------
    # Typical Vertical
    srotary     "A"     #Rotary axis prefix
    vmc         : 1     #0 = Horizontal Machine, 1 = Vertical Mill 
    rot_on_x    : 1     #Default Rotary Axis Orientation, See ques. 164.
                        #0 = Off, 1 = About X, 2 = About Y, 3 = About Z 
    # Typical Horizontal
    #srotary     "B"     #Rotary axis prefix
    #vmc         : 0     #0 = Horizontal Machine, 1 = Vertical Mill 
    #rot_on_x    : 2     #Default Rotary Axis Orientation, See ques. 164.
    #                    #0 = Off, 1 = About X, 2 = About Y, 3 = About Z 
    rot_ccw_pos : 1     #Axis signed dir, 0 = CW positive, 1 = CCW positive
    ret_on_indx : 1     #Machine home retract on rotary index moves, (0 = no, 1 = yes)
    index       : 0     #Use index positioning, 0 = Full Rotary, 1 = Index only
    ctable      : 5     #Degrees for each index step with indexing spindle
    one_rev     : 0     #Limit rotary indexing between 0 and 360? (0 = No, 1 = Yes)
    lock_codes  : 0     #Use rotary axis unlock/lock M-Codes? (0 = No, 1 = Yes)
    use_frinv   : 0     #Use Inverse Time Feedrates in 4 Axis, (0 = no, 1 = yes)
    rot_feed    : 1     #Use calculated rotary feed values, (0 = no, 1 = yes)
    maxfrdeg    : 2000  #Limit for feed in deg/min
    maxfrinv    : 999.99#Limit for feed inverse time
    frc_cinit   : 1     #Force C axis reset at toolchange
    ctol        : 225   #Tolerance in deg. before rev flag changes
    ixtol       : .01   #Tolerance in deg. for index error
    frdegstp    : 10    #Step limit for rotary feed in deg/min
    
    # --------------------------------------------------------------------------
    # Debugging and Factory Set Program Switches  
    # --------------------------------------------------------------------------
    fastmode    : yes   #Posting speed optimizition
    bug1        : 2     #0=No display, 1=Generic list box, 2=Editor
    bug2        : 60    #Append postline labels, non-zero is column position? 
    bug3        : 0     #Append whatline no. to each NC line?
    bug4        : 0     #Append NCI line no. to each NC line?
    whatno      : yes   #Do not perform whatline branches? (leave as yes)
    
    # --------------------------------------------------------------------------
    # Additional General Output Settings
    # --------------------------------------------------------------------------
    ldrcode   : 0      # Leader character dec. equiv. (fleader outputs code)
    ncldr     : 20     # No. of leader characters (fleader outputs code)
    nobrk     : no     # Omit breakup of x/y & z rapid moves LEAVE AS NO!!!
    omitcrlf  : no     # Omit CR/LF
    #eob       : 42    # End of block 
    
    nobrk       : no    #Omit breakup of x, y & z rapid moves
    progname    : 1     #Use uppercase for program name (sprogname)
    sub_level   : 1     #Enable automatic subprogram support
    sub_seq_typ : 1     #Enable subprogram sequence number reset at sub call
    arccheck    : 3     #Check for small arcs, convert to linear
    atol        : .01   #Angularity tolerance for arccheck = 2
    ltol        : .002  #Length tolerance for arccheck = 1
    vtol        : .0001 #System tolerance
    ltol_m      : .05   #Length tolerance for arccheck = 1, metric
    vtol_m      : .0025 #System tolerance, metric
    tooltable   : 1     #Read for tool table and pwrtt - use tool_table to disable
    
    m_one       : -1    #Define constant
    zero        : 0     #Define constant
    one         : 1     #Define constant
    two         : 2     #Define constant
    three       : 3     #Define constant 
    four        : 4     #Define constant 
    five        : 5     #Define constant
    c9k         : 9999  #Define constant
    
    get_1004    : 1     #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
    error_msg   : 1     #0=file and prompt, 1=to screen, 2=one to screen
    err_file    : 1     #0=fatal, 1=all errors, 2=inc mprint, 3=inc prompts, 4=always
    
    # --------------------------------------------------------------------------
    # Enable Canned Drill Cycle Switches
    # --------------------------------------------------------------------------
    usecandrill : yes   #Use canned cycle for drill
    usecanpeck  : yes   #Use canned cycle for Peck
    usecanchip  : yes   #Use canned cycle for Chip Break
    usecantap   : yes   #Use canned cycle for Tap
    usecanbore1 : yes   #Use canned cycle for Bore1
    usecanbore2 : yes   #Use canned cycle for Bore2
    usecanmisc1 : yes   #Use canned cycle for Misc1
    usecanmisc2 : yes   #Use canned cycle for Misc2
    
    # --------------------------------------------------------------------------
    # Common User-defined Variable Initializations (not switches!)
    # --------------------------------------------------------------------------
    xia         : 0     #Formated absolute value for X incremental calculations
    yia         : 0     #Formated absolute value for Y incremental calculations
    zia         : 0     #Formated absolute value for Z incremental calculations
    cia         : 0     #Formated absolute value for C incremental calculations
    
    cuttype     : 0     #Cut type flag
                        #0 = Tool Plane, 1 = Axis Subs,  2 = Polar, 3 = 4/5 axis
    bld         : 0     #Block delete active
    result      : 0     #Return value for functions
    sav_spc     : 0     #Save spaces
    sav_gcode   : 0     #Gcode saved 
    sav_absinc  : 0     #Absolute/Incremental Saved Value
    sav_coolant : 0     #Coolant saved 
    sav_workofs : 0     #Saved work offset
    sav_frc_wcs : 0     #Force work offset flag saved
    sav_progno  : 0     #Saved program number
    #sav_n1      : 0     #Saved sequence number
    #sav_n2      : 0     #Saved sequence number
    sav_rot_on_x : 0    #Rotary configuration saved
    toolchng    : 1     #On a toolchange flag 
    spdir2      : 1     #Copy for safe spindle direction calculation 
    
    #Drill variables
    drlgsel     : -1    #Drill Select Initialize
    drillref    : 0     #Select drill reference
    peckacel    : 0     #Fractional percent to reduce peck2 when usecan.. : no
    drlgcode    : 0     #Save Gcode in drill   
    sav_dgcode  : 0     #Drill gcode saved 
    
    #Subprogram variables
    mr_rt_actv  : 0     #Flag to indicate if G51/G68 is active                     
                        #0=Off, 1=Toolchange, 2=Subprogram call/start, G68
                        #3=Absolute start, both
    rt_csav     : 0     #C saved value
    end_sub_mny : 0     #Many tool setting captured at transform sub end
    
    #Rotary/Index variables
    csav        : 0     #C saved value
    prvcabs     : 0     #Saved cabs from pe_inc_calc,
                        #Used for rotary feed and direction calculations
    cdelta      : 0     #Calculation for angle change
    rev         : 0     #Calculation for deg/min
    sav_rev     : 0     #Saved revolution counter
    indx_out    : c9k   #Rotation direction calculation
    fmt     16  indx_mc #Rotation direction calculation
    
    #Vector Constants for Rotatary Calculations
    aaxisx      : 1     #A axis rotation vector constant
    aaxisy      : 0     #A axis rotation vector constant
    aaxisz      : 0     #A axis rotation vector constant
    baxisx      : 0     #B axis rotation vector constant
    baxisy      : 1     #B axis rotation vector constant
    baxisz      : 0     #B axis rotation vector constant
    caxisx      : 0     #C axis rotation vector constant
    caxisy      : 0     #C axis rotation vector constant
    caxisz      : 1     #C axis rotation vector constant
    
    #Feedrate calculation variables
    frdelta     : 0     #Calculation for deg/min
    frinv       : 0     #Feedrate inverse time
    frdeg       : 0     #Feedrate deg/min actual
    prvfrdeg    : 0     #Feedrate deg/min actual
    ldelta      : 0     #Calculation for deg/min, linear
    cldelta     : 0     #Calculation for deg/min, linear and rotary
    circum      : 0     #Calculation for deg/min
    ipr_type    : 0     #Feedrate for Rotary, 0 = UPM, 1 = DPM, 2 = Inverse 
    
    #Misc variables
    tcnt       : 0     # Count the number of tool changes
    toolcount  : 1     # Tool counter for logic control
    toolcountn : 0     # Next tool counter for logic control
    toolcountp : 0     # Previous tool counter for logic control
    tooltotal  : 0     # Tool tool count
    nexttool   : 0     # Next actual tool
    nexttp     : 0     # Next tool plane
    prvtp      : 0     # Previous tool plane
    counter    : 0     # Counter
    nstrlen    : 0     # Length of string
    last_op_id : 0     # Previous internal operation id
    last_cuttype : 0   # Previous cuttype
    stock_typ  : 0     # Predator Stock Type
    cyl_typ    : 0     # Predator Cyl Stock Type
    z_min      : 99999 # Min Z
    z_tmin     : 99999 # Overall min Z
    z_max      : -99999# Max Z
    z_tmax     : -99999# Overall max Z
    tapflg     : 0     # Flag for tap cycle
    sav_mi9    : 0     # Saved mi9 value
    numpeck    : 0     # Number of pecks
    
    # --------------------------------------------------------------------------
    # FORMULAS - global formulas
    # --------------------------------------------------------------------------
    toolcountn = toolcount + 1   # Index!
    toolcountp = toolcount - 1   # Index!
    
    # --------------------------------------------------------------------------
    # Format statements - n=nonmodal, l=leading, t=trailing, i=inc, d=delta
    # --------------------------------------------------------------------------
    #Default english/metric position format statements
    fs2 1   0.7 0.6     #Decimal, absolute, 7 place, default for initialize (:)
    fs2 2   0.4 0.3     #Decimal, absolute, 4/3 place
    fs2 3   0.4 0.3d    #Decimal, delta, 4/3 place
    #Common format statements
    fs2 4   1 0 1 0     #Integer, not leading
    fs2 5   2 0 2 0l    #Integer, force two leading
    fs2 6   3 0 3 0l    #Integer, force three leading
    fs2 7   4 0 4 0l    #Integer, force four leading
    fs2 8   5 0 5 0l    #Integer, force five leading
    fs2 9   0.1 0.1     #Decimal, absolute, 1 place
    fs2 10  0.2 0.2     #Decimal, absolute, 2 place
    fs2 11  0.3 0.3     #Decimal, absolute, 3 place
    fs2 12  0.4 0.4     #Decimal, absolute, 4 place
    fs2 13  0.5 0.5     #Decimal, absolute, 5 place
    fs2 14  0.3 0.3d    #Decimal, delta, 3 place
    fs2 15  0.2 0.1     #Decimal, absolute, 2/1 place
    fs2 16  1 0 1 0n    #Integer, forced output
    fs  17  1.4lt       #Decimal, absolute, four trailing
    
    # --------------------------------------------------------------------------
    #String and string selector definitions for NC output
    # --------------------------------------------------------------------------
    #Numbered question 164. string to detect Rotary axis y/n
    sq164
    
    #Address string definitions
    stri        "I"
    strj        "J"
    strk        "K"
    strm        "M"
    strn        "N"
    stro        "O"
    strp        "P"
    srad        "R"
    srminus     "R-"
    sblank
    
    #Cantext string definitions (spaces must be padded here)
    sm00        "M00"
    sm01        "M01"
    scant5      "G04 P1"
    strtextno
    strcantext
    
    #Transform mirror and rotate codes
    strns_mir_on     "G51.1" #Programmable mirror image code
    strns_mir_off    "G50.1" #Programmable mirror image cancel code
    strns_rot_on     "G68"   #Coordinate System Rotation
    strns_rot_off    "G69"   #Coordinate System Rotation Cancel
    
    # --------------------------------------------------------------------------
    # Error messages
    # --------------------------------------------------------------------------
    saxiswarn   "WARNING-POST ROTARY AXIS ASSIGNMENT ('rot_on_x') OVERWRITTEN BY OPERATION"
    saxisoff    "ERROR-POST ROTARY AXIS ASSIGNMENT ('rot_on_x') IS DISABLED"
    saxiserror  "ERROR-INVALID ROTARY AXIS ASSIGNMENT ('rot_on_x') FOR CURRENT OPERATION"
    sindxerror  "WARNING-INDEX ANGLE DOES NOT MATCH POST SETTING ('ctable')"
    stlorgerr   "ERROR-TOOL ORIGIN DOES NOT MATCH CENTER OF ROTATION IN POLAR MILLING"
    shomeserror "ERROR-G92 WORK OFFSET ('wcstype') DOES NOT SUPPORT TRANSFORM SUBPROGRAM" 
    sprgnerror  "ERROR-SUBPROGRAM NUMBER MATCHES THE MAIN PROGRAM NUMBER"
    
    # --------------------------------------------------------------------------
    # Misc strings
    # --------------------------------------------------------------------------
    snull     ""       # Null character string
    sdot      "."      # dot string
    stest1    ""       # Test string 1
    stilde    "~"      # Tidle string
    snocomm   "DEFINE TOOL NAMES"
    stoper    ""       # String for tool notes
    spostname ""       # Post name
    snullop   "UNDEFINED OPERATION"
    slicense  "IN-HOUSE SOLUTIONS"
    
    # ------------------------------------------------------------------------
    # Parameter Tables
    # ------------------------------------------------------------------------
    fprmtbl 13      2         # Multisurf Finish
            10010   stock     # Amount of stock to leave on drive surfs
            10227   check     # Amount of stock to leave on check surfs
            
    fprmtbl 14      2         # Multisurf Rough
            10010   stock     # Amount of stock to leave on drive surfs
            10227   check     # Amount of stock to leave on check surfs
    
    # --------------------------------------------------------------------------
    # Buffer 3 - Holds the variable 'tlplnno' for each toolpath segment
    # --------------------------------------------------------------------------
    rc3 : 1
    wc3 : 1
    fbuf 3 0 1 0    # Buffer 3
    
    # --------------------------------------------------------------------------
    # Buffer 4 - Holds the variable 't' for each toolpath segment
    # --------------------------------------------------------------------------
    rc4 : 1
    wc4 : 1
    fbuf 4 0 1 0    # Buffer 4
    
    # --------------------------------------------------------------------------
    # Buffer 5 - Min / Max
    # --------------------------------------------------------------------------
    b5_gcode : 0
    b5_zmin  : 0
    b5_zmax  : 0
    rc5     : 2
    wc5     : 1
    size5   : 0
    
    fbuf 5 0 3 0            #Min / Max
    
    # --------------------------------------------------------------------------
    # Question format statements
    # --------------------------------------------------------------------------
    fq 1 stock_typ Predator Stock [0=Box,1=Cylindrical]
    fq 2 cyl_typ Cylindrical Stock Axis [1=X,2=Y,3=Z]
    
    # --------------------------------------------------------------------------
    # Strings - String labels must start with 's' - they are not pre-assigned
    # --------------------------------------------------------------------------
    #Select operation note
    sop00   "NULL......."      # String definition
    sop01   "CONTOUR...."      #    "       "
    sop02   "CONTOUR...."      #    "       "
    sop03   "DRILL/MISC."      #    "       "
    sop04   "POCKET....."      #    "       "
    sop05   "RULED......"      #    "       "
    sop06   "2D-SWEPT..."      #    "       "
    sop07   "3D-SWEPT..."      #    "       "
    sop08   "REVOLVED..."      #    "       "
    sop09   "LOFT......."      #    "       "
    sop10   "COONS......"      #    "       "
    sop11   "FILLET....."      #    "       "
    sop12   "FLOWLINE..."      #    "       "
    sop13   "M.FINISH..."      #    "       "
    sop14   "M.ROUGH...."      #    "       "
    sop15   "POINT......"      #    "       "
    sop16   "DRILL5AX..."      #    "       "
    sop17   "CURVE5AX..."      #    "       "
    sop18   "SWARF5AX..."      #    "       "
    sop19   "FACING....."      #    "       "
    sop20   "OP20......."      #    "       "
    
    sopnote                    # Target string
    fstrsel  sop00 opcode sopnote
    
    # --------------------------------------------------------------------------
    #Select operation note
    sdr00   "DRILL/CBORE"    # String definition
    sdr01   "PECK DRILL."    #    "       "
    sdr02   "CHIP BREAK."    #    "       "
    sdr03   "TAP........"    #    "       "
    sdr04   "BORE 1....."    #    "       "
    sdr05   "BORE 2....."    #    "       "
    sdr06   "FINE BORE.."    #    "       "
    sdr07   "MISC 2....."    #    "       "
    sdr08   "CUST 9....."    #    "       "
    sdr09   "CUST 10...."    #    "       "
    sdr10   "CUST 11...."    #    "       "
    sdr11   "CUST 12...."    #    "       "
    sdr12   "CUST 13...."    #    "       "
    sdr13   "CUST 14...."    #    "       "
    sdr14   "CUST 15...."    #    "       "
    sdr15   "CUST 16...."    #    "       "
    sdr16   "CUST 17...."    #    "       "
    sdr17   "CUST 18...."    #    "       "
    sdr18   "CUST 19...."    #    "       "
    sdr19   "CUST 20...."    #    "       "
    
    sdrnote                  # Target string
    
    fstrsel  sdr00 nextdc sdrnote
    
    # --------------------------------------------------------------------------
    # Select month
    smon00        ""
    smon01        "JAN"
    smon02        "FEB"
    smon03        "MAR"
    smon04        "APR"
    smon05        "MAY"
    smon06        "JUN"
    smon07        "JUL"
    smon08        "AUG"
    smon09        "SEP"
    smon10        "OCT"
    smon11        "NOV"
    smon12        "DEC"
    smonth
    
    fstrsel smon00 month smonth
    
    # --------------------------------------------------------------------------
    # General G and M Code String select tables
    # --------------------------------------------------------------------------
    # Motion G code selection
    sg00    G00     #Rapid
    sg01    G01     #Linear feed
    sg02    G02     #Circular interpolation CW 
    sg03    G03     #Circular interpolation CCW 
    sg04    G04     #Dwell
    sgcode          #Target for string
    
    fstrsel sg00 gcode sgcode    
    # --------------------------------------------------------------------------
    # Select work plane G code
    sg17    G17     #XY plane code 
    sg19    G19     #YZ plane code 
    sg18    G18     #XZ plane code 
    sgplane         #Target string
    
    fstrsel sg17 plane sgplane      
    # --------------------------------------------------------------------------
    #Select english/metric code 
    sg20    G70     #Inch code
    sg21    G71     #Metric code
    smetric         #Target string  
    
    fstrsel sg20 met_tool smetric    
    # --------------------------------------------------------------------------
    # Cutter compensation G code selection
    scc0    G40     #Cancel cutter compensation
    scc1    G41     #Cutter compensation left
    scc2    G42     #Cutter compensation right
    sccomp          #Target for string
    
    fstrsel scc0 cc_pos sccomp
    # --------------------------------------------------------------------------
    # Canned drill cycle string select
    sg81    G81     #drill      - no dwell 
    sg81d   G82     #drill      - with dwell 
    sg83    G83     #peck drill - no dwell 
    sg83d   G83     #peck drill - with dwell 
    sg73    G69     #chip break - no dwell 
    sg73d   G69     #chip break - with dwell 
    sg84    G84     #tap        - right hand
    sg84d   G84     #tap        - left hand
    sg85    G89     #bore #1    - no dwell 
    sg85d   G89     #bore #1    - with dwell 
    sg86    G86     #bore #2    - no dwell 
    sg86d   G86     #bore #2    - with dwell 
    sgm1    G85     #misc #1    - no dwell
    sgm1d   G85     #misc #1    - with dwell
    sgm2    G81     #misc #2    - no dwell
    sgm2d   G82     #misc #2    - with dwell
    sgc9    G81     #custom #9  - no dwell
    sgc9d   G82     #custom #9  - with dwell
    sgdrill         #Target for string
                      
    fstrsel sg81 drlgsel sgdrill        
    # --------------------------------------------------------------------------
    # Select incremental or absolute G code 
    sg90    G90     #Absolute code
    sg91    G91     #Incremental code
    sgabsinc        #Target string  
    
    fstrsel sg90 absinc sgabsinc    
    # --------------------------------------------------------------------------
    # Feed mode G code selection
    sg94    G94     #UPM
    sg94d   G94     #DPM, See pfcalc_deg if you use another gcode
    sg93    G93     #Inverse
    sgfeed          #Target for string
    
    fstrsel sg94 ipr_type sgfeed
    # -------------------------------------------------------------------------- 
    #Canned drill cycle reference height
    sg98    G98     #Reference at initht
    sg99    G99     #Reference at refht     
    sgdrlref        #Target for string
                      
    fstrsel sg98 drillref sgdrlref        # Drill cycle G string select
    # --------------------------------------------------------------------------
    # Generate string for spindle 
    sm04    M04     #Spindle reverse 
    sm05    M05     #Spindle off     
    sm03    M03     #Spindle forward 
    spindle         #Target for string
    
    fstrsel sm04 spdir2 spindle
    # --------------------------------------------------------------------------
    # Coolant M code selection
    sm09    M09     #Coolant Off (Use sm09_0 through sm09_2)
    sm08    M08     #Coolant Flood 
    sm08_1  M07     #Coolant Mist
    sm08_2  M08     #Coolant Tool
    sm09_0  M09     #Coolant Flood Off
    sm09_1  M09     #Coolant Mist Off
    sm09_2  M09     #Coolant Tool Off
    scoolant        #Target for string
    
    fstrsel sm09 coolant scoolant
    # --------------------------------------------------------------------------
    # Table unlock and lock codes
    slock   M10     #Axis lock
    sunlock M11     #Axis unlock
    # --------------------------------------------------------------------------
    # Table rotation direction 
    # Table rotation direction, index 
    sindx_cw   M22  #Rotate CW code 
    sindx_ccw  M21  #Rotate CCW code
    sindx_mc        #Target for string
    
    fstrsel sindx_cw indx_mc sindx_mc  
    # --------------------------------------------------------------------------
    # Define the gear selection code
    flktbl  1       3       #Lookup table definition - table no. - no. entries
            40      0       #Low gear range
            41      400     #Med gear range
            42      2250    #Hi gear range
    
    # --------------------------------------------------------------------------
    # Toolchange / NC output Variable Formats
    # --------------------------------------------------------------------------
    fmt  T  4   t           #Tool No
    fmt  T  4   first_tool  #First Tool Used 
    fmt  T  4   next_tool   #Next Tool Used  
    fmt  D  4   tloffno     #Diameter Offset No
    fmt  D  4   tlngno      #Length Offset No
    fmt  G  4   g_wcs       #WCS G address
    fmt  P  4   p_wcs       #WCS P address
    fmt  S  4   speed       #Spindle Speed
    fmt  M  4   gear        #Gear range
    # --------------------------------------------------------------------------
    fmt  N  4   n           #Sequence number
    fmt  X  2   xabs        #X position output
    fmt  Y  2   yabs        #Y position output
    fmt  Z  2   zabs        #Z position output
    fmt  X  3   xinc        #X position output
    fmt  Y  3   yinc        #Y position output
    fmt  Z  3   zinc        #Z position output
    fmt  A  11  cabs        #C axis position
    fmt  A  14  cinc        #C axis position
    fmt  A  4   indx_out    #Index position
    fmt  R  14  rt_cinc     #C axis position, G68
    fmt  I  3   i           #Arc center description in X
    fmt  J  3   j           #Arc center description in Y
    fmt  K  3   k           #Arc center description in Z
    fmt  K  2   lead        #Helical lead
    fmt  R  2   arcrad      #Arc Radius
    fmt  F  15  feed        #Feedrate
    fmt  K  4   dwell       #Dwell
    fmt  K  4   dwell_out   #Dwell
    fmt  M  5   cantext     #Canned text
    # --------------------------------------------------------------------------
    #Move comment (pound) to output colon with program numbers
    fmt     8   progno      #Program number
    fmt     4   main_prg_no #Program number
    fmt     4   sub_prg_no  #Program number
    fmt     4   sub_prg_call#Program number
    fmt  X  2   sub_trnsx   #Rotation point
    fmt  Y  2   sub_trnsy   #Rotation point
    fmt  Z  2   sub_trnsz   #Rotation point
    # --------------------------------------------------------------------------
    fmt  I  2   peck1       #First peck increment (positive)
    fmt  R  2   peck2       #Second or last peck (positive)
    fmt  C  2   peckclr     #Safety distance
    fmt  H  2   retr        #Retract height
    fmt  J  4   shftdrl     #Fine bore tool shift
    fmt  Z  2   zdrl        #Depth of drill point
    fmt  Z  2   tosz        #Drilling top of stock
    fmt  N  4   n_tap_thds  #Number of threads per inch (tpi)
    fmt  F  2   pitch       #Tap pitch (inches per thread)
    fmt  Z  2   refht_a     #Reference height
    fmt  Z  2   refht_i     #Reference height
    fmt  J  4   numpeckint  #Number of pecks
    fmt  B  2   bval        #Peck value
    fmt  D  2   dval        #Refht to zdrl
    # --------------------------------------------------------------------------
    fmt "TOOL - "       4   tnote       # Note format
    fmt " DIA. OFF. - " 4   toffnote    # Note format
    fmt " LEN. - "      4   tlngnote    # Note format
    fmt " DIA. - "      1   tldianote   # Note format
    # --------------------------------------------------------------------------
    fmt  D 17 tldia                   # Note format
    fmt  R 17 tcr                     # Note format
    fmt  D  2 tldia_pred              # Predator VCNC format
    fmt  C  2 tcr_pred                # Predator VCNC format
    
    fmt  D  2 tldia_meta              # MetaCut View format
    fmt  R  2 tcr_meta                # MetaCut View format
    fmt  F  2 flute_meta              # MetaCut View format
    fmt  L  2 oa_meta                 # MetaCut View format
    fmt  A  2 ta_meta                 # MetaCut View format
    fmt TD  2 td_meta                 # MetaCut View format
    fmt CD  2 cd_meta                 # MetaCut View format
    fmt CL  2 cl_meta                 # MetaCut View format
    fmt SD  2 sd_meta                 # MetaCut View format
    fmt  C  4 tipcomp                 # MetaCut View format
     
    fmt     2 slot                    # 20004 Parameter line
    fmt     2 tool_type
    fmt     2 matl_type
    fmt     2 corner_rad_type
    fmt     2 diameter
    fmt     2 corner_rad
    fmt     2 threads
    fmt  A  2 tip_angle
    fmt     2 dia_off
    fmt     2 len_off
    fmt     2 tool_feed
    fmt     2 plunge
    fmt     2 retract
    fmt     2 rpm
    fmt     2 coolant1
    fmt     2 n_flutes1
    fmt  A  2 tip_angle_ch
    
    fmt     2 cut_ability             # 20006 Parameter line
    fmt     2 step_r_xy
    fmt     2 step_r_z
    fmt     2 step_f_xy
    fmt     2 step_f_z
    fmt     2 tip_dia
    fmt     2 min_dia
    fmt     2 thd_ang
    
    fmt     2 pilot_dia               # 20007 Parameter line
    fmt  H  2 flute_len
    fmt     2 oa_len
    fmt     2 shldr_len
    fmt     2 arbor_dia
    fmt     2 hldr_dia
    fmt     2 hldr_len
    fmt     2 spindle_ccw
    fmt     2 sfm
    fmt     2 fpt
    fmt     2 metric
    
    fmt    2 stock      # Amount of Stock left on drive surfs
    fmt    2 check      # Amount of Stock left on check surfs
    fmt  S 4 cyl_typ    # Predator Cylindral Stock Type
    fmt  L 2 stck_ht
    fmt  W 2 stck_wdth
    fmt  H 2 stck_thck
    fmt  D 2 stck_diam
    fmt  X 2 stck_x
    fmt  Y 2 stck_y
    fmt  Z 2 stck_z
    fmt  X 2 stck_x_min
    fmt  Y 2 stck_y_min
    fmt  Z 2 stck_z_min
    
    fmt  X 2 stck_meta_ht
    fmt  Y 2 stck_meta_wdth
    fmt  Z 2 stck_meta_thck
    fmt OX 2 stck_meta_ox
    fmt OY 2 stck_meta_oy
    fmt OZ 2 stck_meta_oz
    
    fmt  X 2 x_tmin     # Total x_min
    fmt  X 2 x_tmax     # Total x_max
    fmt  Y 2 y_tmin     # Total y_min
    fmt  Y 2 y_tmax     # Total y_max
    fmt  Z 2 z_tmin     # Total z_min
    fmt  Z 2 z_tmax     # Total z_max
    fmt  Z 2 min_depth  # Tool z_min
    fmt  Z 2 max_depth  # Tool z_max
    
    fmt    2 vers_no     # Mastercam version
    fmt    2 m_vers_no   # Minor version number
    
    # --------------------------------------------------------------------------
    # Tool Comment / Manual Entry Section
    # --------------------------------------------------------------------------
    ptoolcomment    #Comment for tool
          tnote = t 
          toffnote = tloffno
          tlngnote = tlngno
          tldianote = tldia
          ";", pstrtool, *tnote, *toffnote, *tlngnote, *tldianote, e  
    
    pstrtool        #Comment for tool
          if strtool <> sblank,
            [
            strtool = ucase(strtool)
            *strtool, " "
            ]
            
    pcomment        #Comment from manual entry (must call pcomment2 if booleans)
          pcomment2
    
    pcomment2       #Comment from manual entry
          spaces = 0
          scomm = ucase (scomm)
          #1005 - Comment option 1
          #1006 - Comment option 2
          #1007 - Define comment with output line
          #1008 - Define NC parameter comment
          #1026 - ?
          if gcode = 1005, pbld, n, pspc, ";", scomm
          if gcode = 1006, pbld, n, pspc, ";", scomm  #Comments
          #if gcode = 1006, pbld, n, pspc, scomm  #Codes
          if gcode = 1007, ";", scomm
          if gcode = 1008, pbld, n, pspc, ";", scomm
          if gcode = 1026, pbld, scomm
          if gcode <> 1007 & gcode <> 1026, e
          spaces = sav_spc
               
    ptoolcomm  # Comments from tool library
               spaces = 0
               strtool=ucase(strtool)
               if strtool<>snull, pspc1, ";", *strtool, e
               else, pspc1, ";", "DEFINE TOOL NAMES", e
               spaces = sav_spc
    
    plistcomm  # Comments from tool library
               strtool=ucase(strtool)
               if strtool<>snull, *strtool
               else, "DEFINE TOOL NAMES"
                  
               if strtool=snull, stest1=snocomm+stilde
               else, stest1=strtool+stilde
               nstrlen = strstr(stilde,stest1)-1
               counter = 1
               while counter <= (25-nstrlen), pspace
    
    pmetacomm  # Comments from tool library
               strtool=ucase(strtool)
               if strtool<>snull, *strtool
               else, "DEFINE TOOL NAMES"
                 
    pspace     # Creates spaces based on tool comment length
               " "
               counter = counter + 1             
    
    ptspace    # Creates spaces based on tool number
               if t<10, " "
    
    phspace    # Creates spaces based on length offset number
               if tlngno<10, " "
                 
    pdspace    # Creates spaces based on diameter offset number
               if tloffno<10, " "
    
    pdiamspc   # Creates spaces based on diameter offset number
               if tldia<10, " "
                 
    pspc       # Creates spaces based tool level setting
               if sav_spc = one & omitseq = no, " "
               
    pspc1      # Creates spaces based tool level setting
               if sav_spc = one, " "
    
    popnote    # Operation note for tool table
               if opcode = 3, *sdrnote
               else, *sopnote
                                             
    pstock     # Comment amount of stock to leave
               spaces=0
               if (opcode=13 | opcode=14),
                 [
                 pbld, n, pspc, ";TOOLPATH - ", *stoper, e
                 pbld, n, pspc, ";STOCK LEFT ON DRIVE SURFS = ", *stock, e
                 if check<>0, pbld, n, pspc, ";STOCK LEFT ON CHECK SURFS = ", *check, e
                 ]
               spaces=sav_spc
    
    ppredstck  # Predator stock
               spaces=0
               q1
               if stock_typ = 1, 
                 [
                 cyl_typ = rot_on_x
                 q2
                 ]
               if stock_typ = 0, ppredbox
               if stock_typ = 1,
                 [
                 if cyl_typ = 1, ppredcylx
                 if cyl_typ = 2, ppredcyly
                 if cyl_typ = 3, ppredcylz
                 ]
               spaces=sav_spc
    
    ppredbox   # Predator Box Stock
               if stck_crnr = 0,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 1 | stck_crnr = 5,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y - stck_wdth
                 ]
               if stck_crnr = 2 | stck_crnr = 6,
                 [
                 stck_x_min = stck_x - stck_ht
                 stck_y_min = stck_y - stck_wdth
                 ]
               if stck_crnr = 3 | stck_crnr = 7,
                 [
                 stck_x_min = stck_x - stck_ht
                 stck_y_min = stck_y
                 ]
               if stck_crnr = 4 | stck_crnr = 8,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y
                 ]
               if stck_crnr <= 4, stck_z_min = stck_z - stck_thck
               else, stck_z_min = stck_z
    
               "(SBOX ", *stck_x_min, " ", *stck_y_min, " ", *stck_z_min, " ", *stck_ht, " ", *stck_wdth, " ", *stck_thck, ")"
    
    ppredcylx  # Predator Cyl-X Stock
               if stck_crnr = 0,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y
                 ]
               if stck_crnr = 1 | stck_crnr = 5,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 2 | stck_crnr = 6,
                 [
                 stck_x_min = stck_x - stck_ht
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 3 | stck_crnr = 7,
                 [
                 stck_x_min = stck_x - stck_ht
                 stck_y_min = stck_y + stck_wdth/2
                 ]
               if stck_crnr = 4 | stck_crnr = 8,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y + stck_wdth/2
                 ]
               if stck_crnr <= 4, stck_z_min = stck_z - stck_thck/2
               else, stck_z_min = stck_z + stck_thck/2
    
               stck_diam = stck_wdth
               if stck_thck > stck_wdth, stck_diam = stck_thck
               stck_ht = stck_ht
               "(SCYL ", *cyl_typ, " ", *stck_x_min, " ", *stck_y_min, " ", *stck_z_min, " ", *stck_diam, " ", *stck_ht, ")"
    
    ppredcyly  # Predator Cyl-Y Stock
               if stck_crnr = 0,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 1 | stck_crnr = 5,
                 [
                 stck_x_min = stck_x + stck_ht/2
                 stck_y_min = stck_y - stck_wdth
                 ]
               if stck_crnr = 2 | stck_crnr = 6,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y - stck_wdth
                 ]
               if stck_crnr = 3 | stck_crnr = 7,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y
                 ]
               if stck_crnr = 4 | stck_crnr = 8,
                 [
                 stck_x_min = stck_x + stck_ht/2
                 stck_y_min = stck_y
                 ]
               if stck_crnr <= 4, stck_z_min = stck_z - stck_thck/2
               else, stck_z_min = stck_z + stck_thck/2
    
               stck_diam = stck_ht
               if stck_thck > stck_ht, stck_diam = stck_thck
               stck_ht = stck_wdth
               "(SCYL ", *cyl_typ, " ", *stck_x_min, " ", *stck_y_min, " ", *stck_z_min, " ", *stck_diam, " ", *stck_ht, ")"
    
    ppredcylz  # Predator Cyl-Z Stock
               if stck_crnr = 0,
                 [
                 stck_x_min = stck_x
                 stck_y_min = stck_y
                 ]
               if stck_crnr = 1 | stck_crnr = 5,
                 [
                 stck_x_min = stck_x + stck_ht/2
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 2 | stck_crnr = 6,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y - stck_wdth/2
                 ]
               if stck_crnr = 3 | stck_crnr = 7,
                 [
                 stck_x_min = stck_x - stck_ht/2
                 stck_y_min = stck_y + stck_wdth/2
                 ]
               if stck_crnr = 4 | stck_crnr = 8,
                 [
                 stck_x_min = stck_x + stck_ht/2
                 stck_y_min = stck_y + stck_wdth/2
                 ]
               if stck_crnr <= 4, stck_z_min = stck_z - stck_thck
               else, stck_z_min = stck_z
    
               stck_diam = stck_ht
               if stck_wdth > stck_ht, stck_diam = stck_wdth
               stck_ht = stck_thck
               "(SCYL ", *cyl_typ, " ", *stck_x_min, " ", *stck_y_min, " ", *stck_z_min, " ", *stck_diam, " ", *stck_ht, ")"
               
    pmetastck  # MetaCut View stock
               if stck_crnr = 0,
                 [
                 stck_meta_ox = stck_x * m_one - (tox * m_one)
                 stck_meta_oy = stck_y * m_one - (toy * m_one)
                 ]
               if stck_crnr = 1 | stck_crnr = 5,
                 [
                 stck_meta_ox = (stck_x + stck_ht/2) * m_one - (tox * m_one)
                 stck_meta_oy = (stck_y - stck_wdth/2) * m_one - (toy * m_one)
                 ]
               if stck_crnr = 2 | stck_crnr = 6,
                 [
                 stck_meta_ox = (stck_x - stck_ht/2) * m_one - (tox * m_one)
                 stck_meta_oy = (stck_y - stck_wdth/2) * m_one - (toy * m_one)
                 ]
               if stck_crnr = 3 | stck_crnr = 7,
                 [
                 stck_meta_ox = (stck_x - stck_ht/2) * m_one - (tox * m_one)
                 stck_meta_oy = (stck_y + stck_wdth/2) * m_one - (toy * m_one)
                 ]
               if stck_crnr = 4 | stck_crnr = 8,
                 [
                 stck_meta_ox = (stck_x + stck_ht/2) * m_one - (tox * m_one)
                 stck_meta_oy = (stck_y + stck_wdth/2) * m_one - (toy * m_one)
                 ]
               if stck_crnr <= 4, stck_meta_oz = stck_z * m_one - (toz * m_one)
               else, stck_meta_oz = (stck_z + stck_thck) * m_one - (toz * m_one)
    
               stck_meta_ht = stck_ht
               stck_meta_wdth = stck_wdth
               stck_meta_thck = stck_thck
    
               #(NWDSTOCK X8. Y8. Z1.25 OTC OX-4. OY-4. OZ0.)
               spaces=0
               "(NWDSTOCK ", *stck_meta_ht, " ", *stck_meta_wdth, " ", *stck_meta_thck,
               " OTC ", *stck_meta_ox, " ", *stck_meta_oy, " ", *stck_meta_oz, ")"
               spaces=sav_spc
    
    pstop      # Stop routine
               pretract
               pcom_moveb
               if mi10=one, n, *sm00, e
               pbld, n, pwcs, e
               sav_absinc = absinc
               if wcstype > one, absinc = zero
               if lock_codes = 1 & not(index) & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
               pcan1, pbld, n, *sgcode, *sgabsinc, pfxout, pfyout, 
                 pfcout, *speed, *spindle, pgear, strcantext, e
               if lock_codes = 1 & not(index) & rot_on_x & cuttype = 0, pbld, n, *slock, ";LOCK", e
               pbld, n, "G43", *tlngno, pfzout, scoolant, next_tool, e
               sav_coolant = coolant
               if coolant = 1, sm09 = sm09_0
               if coolant = 2, sm09 = sm09_1
               if coolant = 3, sm09 = sm09_2
               absinc = sav_absinc
    
    # --------------------------------------------------------------------------
    # Misc. Output
    # --------------------------------------------------------------------------
    pparameter # Run parameter table
               if opcode=13 | opcode=14, result = fprm (opcode)
               if prmcode = 10000, stoper = ucase(sparameter)
               if prmcode = 10055, spostname = ucase(sparameter)
               if stoper=snull, stoper = snullop
               
    pwrttparam #Information from parameters
               if prmcode = 20004, slot = rpar(sparameter, 16)
               if prmcode = 20006, cut_ability = rpar(sparameter,8)
               if prmcode = 20007, pilot_dia = rpar(sparameter, 11)
    
    # --------------------------------------------------------------------------
    # Start of File and Toolchange Setup
    # --------------------------------------------------------------------------
    psof0           #Start of file for tool zero                        
          psof
    
    psof            #Start of file for non-zero tool number
          ptravel
          pwritbuf5
          pcuttype
          toolchng = one 
          if ntools = one,
            [
            #skip single tool outputs, stagetool must be on
            #stagetool = m_one
            !next_tool
            ]
          tooltotal = rbuf(4,0)  #Reads total tool and null tool changes
          if toolcountn <= tooltotal, nexttool = rbuf(4,toolcountn)
          else, nexttool = first_tool
    
          if tool_table = 2, ppredstck
          if tool_table = 3, pmetastck
                 
          spaces=0
          if output_z = yes & tcnt > 1,
            [
            ";OVERALL MAX : ", *z_tmax, e
            ";OVERALL MIN : ", *z_tmin, e
            ]
          spaces=sav_spc
          
          if plane < 0, plane = 0
          pbld, n, *sgcode, *sgplane, "G40", "G44", *smetric, "G80", *sgabsinc, e
          sav_absinc = absinc
          if wcstype <= one, #Work coordinate system
            [
            absinc = one
            pfbld, n, sgabsinc, "G28", "Z0.", e
            pfbld, n, "G28", "X0.", "Y0.", e
            pfbld, n, "G92", *xh, *yh, *zh, e
            absinc = sav_absinc
            ]
          sav_mi9 = mi9
          sav_workofs = workofs
          if sav_workofs < 0, sav_workofs = 0
          ptlchg_com
          
    ptlchg_com      #Tool change common blocks
          pcom_moveb
          c_mmlt #Multiple tool subprogram call
          #ptoolcomment
          comment
          pcan
          if plane < 0, plane = 0
          if stagetool >= zero, 
            [
            pbld, n, *t, ptoolcomm, e
            pbld, n, "M06", e
            ]
          spaces=0
          if output_z = yes,
            [
            preadbuf5
            if (opcode > 0 & opcode < 16) | opcode = 19,
              [
              n, pspc, ";", "MAX : ", *max_depth, e
              n, pspc, ";", "MIN : ", *min_depth, e
              ]
            ]
          spaces=sav_spc
          pstock
          pindex
          pbld, n, pwcs, e
          sav_absinc = absinc
          if wcstype > one, absinc = zero
          if lock_codes = 1 & not(index) & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
          pcan1, pbld, n, *sgcode, *sgabsinc, pfxout, pfyout, 
            pfcout, *speed, *spindle, pgear, strcantext, e
          if lock_codes = 1 & not(index) & rot_on_x & cuttype = 0, pbld, n, *slock, ";LOCK", e
          pbld, n, "G43", *tlngno, pfzout, scoolant, next_tool, e
          sav_coolant = coolant
          if coolant = 1, sm09 = sm09_0
          if coolant = 2, sm09 = sm09_1
          if coolant = 3, sm09 = sm09_2
          absinc = sav_absinc
          pcom_movea
          toolchng = zero 
          c_msng #Single tool subprogram call
          last_op_id = op_id
          last_cuttype = cuttype
                  
    ptlchg0         #Call from NCI null tool change (tool number repeats)
          pcuttype
          pcom_moveb
          toolcount = toolcount + 1
          prvtp = rbuf(3,toolcountp)
          if toolcountn <= tooltotal, nexttool = rbuf(4,toolcountn)
          else, nexttool = first_tool
          if mi10=one & op_id<>last_op_id | (tlplnno <> prvtp & ret_on_indx), pstop
          c_mmlt #Multiple tool subprogram call
          comment
          pcan
          if plane < 0, plane = 0
          pbld, n, sgplane, e       
          pspindchng
          if coolant <> 0 & coolant <> sav_coolant, pbld, n, sm09, e
          pbld, n, scoolant, e
          sav_coolant = coolant
          if coolant = 1, sm09 = sm09_0
          if coolant = 2, sm09 = sm09_1
          if coolant = 3, sm09 = sm09_2
          if op_id<>last_op_id, pstock
          if sav_mi9 = 1, workofs = sav_workofs
          if (wcstype > one & workofs <> prv_workofs) | (tlplnno <> prvtp & ret_on_indx),
            [
            pbld, n, pwcs, e
            sav_absinc = absinc
            absinc = zero
            if fmtrnd(prv_cabs) <> fmtrnd(cabs),
              [ 
              if lock_codes = 1 & not(index) & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
              pbld, n, sgabsinc, pfxout, pfyout, pfzout, pfcout, e
              if lock_codes = 1 & not(index) & rot_on_x & cuttype = 0, pbld, n, *slock, ";LOCK", e
              ]
            else,
              [
              pbld, n, sgabsinc, pfxout, pfyout, pfzout, pcout, e
              ]
            pe_inc_calc
            ps_inc_calc
            absinc = sav_absinc
            ]
          if lock_codes = 1 & cuttype <> last_cuttype & cuttype > 0, pbld, n, *sunlock, ";UNLOCK", e
          if cuttype = zero, ppos_cax_lin
          if lock_codes = 1 & cuttype <> last_cuttype & cuttype = 0 & fmtrnd(prv_cabs) = fmtrnd(cabs), pbld, n, *slock, ";LOCK", e
          if gcode = one, plinout
          else, prapidout
          pcom_movea
          c_msng #Single tool subprogram call
          last_op_id = op_id
          last_cuttype = cuttype
          
    ptlchg          #Tool change                                        
          pcuttype
          toolchng = one
          toolcount = toolcount + 1
          if toolcountn <= tooltotal, nexttool = rbuf(4,toolcountn)
          else, nexttool = first_tool
          if wcstype = one, #Work coordinate system
            [
            pfbld, n, "G28", "X0.", "Y0.", e
            pfbld, n, "G92", *xh, *yh, *zh, e
            ]
          pbld, n, *sm01, e
          if mi10=one, n, *sm00, e
          ptlchg_com
    
    pretract        #End of tool path, toolchange              
          sav_absinc = absinc       
          absinc = zero
          sav_coolant = coolant
          coolant = zero
          #cc_pos is reset in the toolchange here
          cc_pos = zero 
          gcode = zero
          pcan
          pbld, n, sccomp, *sm05, psub_end_mny, e
          pcan1, pbld, n, sgabsinc, sgcode, "G44", "G53", "Z0.", scoolant, strcantext, e      
          #if lock_codes = 1 & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
          #pbld, n, "G53", "X0.", "Y0.", protretinc, e
          #if lock_codes = 1 & rot_on_x & cuttype = 0, pbld, n, *slock, ";LOCK", e
          if abs(cabs) > 360 & nextop <> 1003, 
           [
           if lock_codes = 1, pbld, n, *sunlock, ";UNLOCK", e
           pbld, n, 'G53', protretinc, e
           if lock_codes = 1 & cuttype = 0, pbld, n, *slock, ";LOCK", e
           ]
          pcan2
          absinc = sav_absinc
          coolant = sav_coolant
            
    protretinc      #Reset the C axis revolution counter
          if frc_cinit & rot_on_x,
            [
            rev = zero
            sav_rev = zero
            cabs = zero
            csav = zero
            indx_out = zero
            if index, e, pindxcalc, pindex
            else, *cabs
            prvcabs = zero
            !csav, !cabs
            ]
    
    peof0           #End of file for tool zero               
          peof
    
    peof            #End of file for non-zero tool           
          pretract
          if lock_codes = 1 & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
          pbld, n, "G53", "X0.", "Y0.", protretinc, e
          if lock_codes = 1 & rot_on_x, pbld, n, *slock, ";LOCK", e
          comment
          #Remove pound character to output first tool with staged tools
          #if stagetool = one, pbld, n, *first_tool, e
          n, *sg90, e
          n, "M30", e  
          mergesub
          clearsub
          mergeaux
          clearaux
          27  #ESC Escape Character
          #26  #EOF Enf of File Character
          #128 #Reported to work by Jax Mold
          #4  #EOT End of Tape Character
          #fleader  #Outputs 20 Null Characters if needed
    
    pwcs            #G54+ coordinate setting at toolchange
          if wcstype = two | wcstype > three,
            [
            sav_frc_wcs = force_wcs
            if sub_level, force_wcs = zero
            if sav_mi9 = 1, workofs = sav_workofs
            if workofs < 0, workofs = 0
            if workofs <> prv_workofs | (force_wcs & toolchng),
              [
              if workofs < 6,
                [
                g_wcs = workofs + 54
                *g_wcs
                ]
              else,
                [
                p_wcs = workofs - five
                "G54.1", *p_wcs
                ]  
              ]
            force_wcs = sav_frc_wcs
            !workofs
            ]
            
    pgear           #Find spindle gear from lookup table
          if use_gear = one,
            [
            gear = frange (one, speed)
            *gear
            ]
    
    #Toolchange setup
    pspindchng      #Spindle speed change 
          if prv_spdir2 <> spdir2 & prv_speed <> zero, pbld, n, *sm05, e
          if prv_speed <> speed | prv_spdir2 <> spdir2,
            [
            if speed, pbld, n, *speed, *spindle, pgear, e 
            ]
          !speed, !spdir2
    
    pspindle        #Spindle speed calculations for RPM
          speed = abs(ss)
          if maxss = zero | maxss > max_speed, maxss = max_speed
          #zero indicates spindle off (not a mistake)
          if speed,
            [
            if speed > max_speed, speed = maxss 
            if speed < min_speed, speed = min_speed 
            ]
          spdir2 = fsg3(spdir) 
    
    pq              #Setup post based on switch settings
          sav_spc = spaces
          if stagetool = one, bldnxtool = one
          #Rotaxtyp = 1 sets initial matrix to top
          #Rotaxtyp = -2 sets initial matrix to front
          if vmc, rotaxtyp = one
          else, rotaxtyp = -2
          #Shut off rotary axis if, Q164. Enable Rotary Axis button? n
          if ucase(sq164) = strn, rot_on_x = zero
          if arctype = one | arctype = four,
            [
            result = newfs(two, i)
            result = newfs(two, j)
            result = newfs(two, k)
            ]
          else,
            [
            result = newfs(three, i)
            result = newfs(three, j)
            result = newfs(three, k)
            ]
          if usecanned = yes, pusecannedyes
          else, pusecannedno
    
    pheader         #Call before start of file                         
          if met_tool = one, #Metric constants and variable adjustments
            [
            ltol = ltol_m 
            vtol = vtol_m
            maxfeedpm = maxfeedpm_m    
            ]
          result = nwadrs(srotary, cabs)
          result = nwadrs(srotary, cinc)
          result = nwadrs(srotary, indx_out)
    
          spaces=0
          #"%99996"
          #if progno = 0, progno = 99999           
          #"%", *progno, e
          "%", *progname, ",MX,", e
          spathnc = ucase(spathnc)
          smcname = ucase(smcname)
          #";PROGRAM NAME - ", sprogname, e
          #";DATE=DD-MM-YY - ", date, " TIME=HH:MM - ", time, e
          ";MASTERCAM - V", *vers_no, e
          ";MC9 FILE  - ", smcpath, smcname, smcext, e
          ";POST      - ", spostname, e
          stck_matl = ucase(stck_matl)
          ";MATERIAL  - ", stck_matl, e
          ";PROGRAM   - ", sprogname, sextnc, e
          ";DATE      - ", *smonth, "-", *day, "-", *year, e
          ";TIME      - ", *time, e
          ";POST DEV  - ", *slicense, e
          spaces=sav_spc
    
          if seqno = 0, omitseq = yes
          sav_rot_on_x = rot_on_x
          rot_on_x = 0
          sav_progno = progno
    
          #seqno = 10
          #seqinc = 10
          #n = seqno
    
    ptoolend        #End of tool path, before reading new tool data               
          !speed, !spdir2
    
    ptlchg1002      #Call at actual toolchange, end last path here                        
          if op_id <> last_op_id, 
            [
            sav_rev = rev #Axis Sub does not update to rev
            if one_rev = one, sav_rev = 0
            ]
          pspindle
          whatline = four #Required for vector toolpaths
          if gcode = 1000,
            [
            #Null toolchange
            ]
          else,
            [
            #Toolchange and Start of file
            if gcode = 1002,
              [
              #Actual toolchange
              pretract
              ]
            if stagetool = one, prv_next_tool = m_one
            prv_xia = vequ(xh)
            prv_feed = c9k
            ]
    
    # --------------------------------------------------------------------------
    # Motion NC output
    # --------------------------------------------------------------------------
    #The variables for absolute output are xabs, yabs, zabs.
    #The variables for incremental output are xinc, yinc, zinc.
    # --------------------------------------------------------------------------
    prapidout       #Output to NC of linear movement - rapid               
          pcan1, pbld, n, sgplane, `sgcode, sgabsinc, pccdia,
            pxout, pyout, pzout, pcout, strcantext, scoolant, e
    
    plinout         #Output to NC of linear movement - feed                    
          pcan1, pbld, n, sgfeed, sgplane, `sgcode, sgabsinc, pccdia,
            pxout, pyout, pzout, pcout, `feed, strcantext, scoolant, e
    
    pcirout         #Output to NC of circular interpolation
          if hel_2100 = one, pcirout2
          else, pcirout1
    
    pcirout1        #Output to NC of circular interpolation
          pcan1, pbld, n, `sgfeed, sgplane, sgcode, sgabsinc, pccdia,
            pxout, pyout, pzout, pcout, parc, feed, strcantext, scoolant, e 
    
    pcirout2        #Output to NC of circular interpolation
          if (plane = zero & abs(zinc)>=0.0005)
           | (plane =  one & abs(xinc)>=0.0005)
           | (plane =  two & abs(yinc)>=0.0005), phelout
          else, pcirout1
    
    phelout         #Output to NC of helical interpolation
          lead = abs(zinc/sweep*360)
          if plane = zero, result = nwadrs(strk, lead)
          if plane = one,  result = nwadrs(stri, lead)
          if plane = two,  result = nwadrs(strj, lead)
          pcan1, pbld, n, `sgfeed, sgplane, sgcode, sgabsinc, pccdia,
            pxout, pyout, pzout, *lead, pcout, parc, feed, strcantext, scoolant, e
    
    pcom_moveb      #Common motion preparation routines, before              
          pxyzcout
          ps_inc_calc
          
    pncoutput       #Movement output
          pcom_moveb
          comment
          if coolant <> 0 & coolant <> sav_coolant, 
            [
            pbld, n, sm09, e
            sav_coolant = coolant        
            ]
          if coolant = 1, sm09 = sm09_0
          if coolant = 2, sm09 = sm09_1
          if coolant = 3, sm09 = sm09_2
          if cool_zmove = yes & (nextop=1003 | (nextop=1011 & t<>abs(nexttool))), coolant = zero
          pcan
          if cuttype = zero, ppos_cax_lin #Toolplane rotary positioning
          if gcode = zero, prapidout
          if gcode = one, plinout
          if gcode > one & gcode < four, pcirout
          if mr_rt_actv, #Restore absolute/incremental for G51/G68
            [
            absinc = sav_absinc
            mr_rt_actv = zero
            ]
          pcom_movea
                
    pcom_movea      #Common motion preparation routines, after              
          pcan2
          pe_inc_calc
    
    pdwl_spd        #Call from NCI gcode 4
          pspindle
          comment
          pspindchng
          pcan
          if fmtrnd(dwell), pcan1, pbld, n, *sgcode, *dwell, strcantext, e
          else, pcan1, pbld, n, strcantext, e 
          pcan2
    
    prapid          #Output to NC of linear movement - rapid               
          pncoutput
                  
    pzrapid         #Output to NC of linear movement - rapid Z only    
          pncoutput
                  
    plin            #Output to NC of linear movement - feed                    
          pncoutput
    
    pz              #Output to NC of linear movement - feed Z only          
          pncoutput
    
    pmx             #Output to NC of vector NCI          
          pncoutput
            
    pcir            #Output to NC of circular interpolation                                
          pncoutput
    
    #Pre-process rotary motion control flags
    pmx0            #5 axis gcode setup
          if drillcur = zero,
            [
            if fr = -2, gcode = zero
            else, gcode = one
            ]
              
    plin0           #Linear movement, mill motion test                                
          pmotion_su
    
    pcir0           #Circular interpolation, mill arc motion test                                
          pmotion_su
    
    # --------------------------------------------------------------------------
    # Motion output components
    # --------------------------------------------------------------------------
    pbld            #Canned text - block delete
          if bld, '/'
                  
    pfbld           #Force - block delete
          "/"  
    
    pccdia          #Cutter Compensation
          #Force Dxx#   
          if prv_cc_pos <> cc_pos & cc_pos, prv_tloffno = c9k
          sccomp
          if cc_pos, tloffno
            
    pfxout          #Force X axis output
          if absinc = zero, *xabs, !xinc
          else, *xinc, !xabs
            
    pxout           #X output
          if absinc = zero, xabs, !xinc
          else, xinc, !xabs
    
    pfyout          #Force Y axis output
          if absinc = zero, *yabs, !yinc
          else, *yinc, !yabs
                  
    pyout           #Y output
          if absinc = zero, yabs, !yinc
          else, yinc, !yabs
    
    pfzout          #Force Z axis output
          if absinc = zero, *zabs, !zinc
          else, *zinc, !zabs
                  
    pzout           #Z output
          if absinc = zero, zabs, !zinc
          else, zinc, !zabs
    
    pfcout          #Force C axis output 
          if index = zero & rot_on_x,
            [
            if absinc = zero, *cabs, !cinc
            else, *cinc, !cabs
            ]
    
    pcout           #C axis output
          if index = zero & rot_on_x,
            [
            if absinc = zero, cabs, !cinc
            else, cinc, !cabs
            ]
    
    pindex          #Index output
          if index & rot_on_x,
            [
            if fmtrnd(prv_indx_out) <> fmtrnd(indx_out),
              [
              if lock_codes = 1, pbld, n, *sunlock, ";UNLOCK", e
              pbld, n, `sindx_mc, indx_out, e
              if lock_codes = 1 & cuttype = 0, pbld, n, *slock, ";LOCK", e
              ]
            !cabs, !cinc
            ]
                  
    parc            #Select the arc output
          if arcoutput = zero | full_arc_flg | arc_pitch,
            [
            #Arc output for IJK
            # If you do NOT want to force out the I,J,K values,
            # remove the "*" asterisks on the *i, *j, *k 's below...
            if plane = zero, *i, *j, k  #XY plane code - G17
            if plane = one, i, *j, *k   #YZ plane code - G19
            if plane = two, *i, j, *k   #XZ plane code - G18
            ]
          else,
            [
            #Arc output for R
            if abs(sweep)<=180 | arcoutput=one, result = nwadrs(srad, arcrad)
            else, result = nwadrs(srminus, arcrad)
            *arcrad
            ]
    
    ppos_cax_lin    #Position the rotary axis before move - rapid
          if index, pindex
          else,
            [
            if fmtrnd(prv_cabs) <> fmtrnd(cabs) & rot_on_x,
              [
              sav_gcode = gcode
              gcode = zero
              if lock_codes = 1 & not(index), pbld, n, *sunlock, ";UNLOCK", e
              pbld, n, sgcode, pcout, e
              if lock_codes = 1 & not(index) & cuttype = 0, pbld, n, *slock, ";LOCK", e
              !cia
              ps_cinc_calc
              gcode = sav_gcode
              ]
            ]
            
    # --------------------------------------------------------------------------
    # Drilling
    # --------------------------------------------------------------------------
    pdrill0         #Pre-process before drill call
          sav_dgcode = gcode #Capture gcode for 5 axis drill
    
    pdrlcommonb     #Canned Drill Cycle common call, before
          if sav_dgcode = 81,
            [
            result = newfs (two, zinc)
            if drillcyc = three, drlgsel = fsg1(-ss) + drillcyc * two
            else, drlgsel = fsg2(dwell) + drillcyc * two 
            if initht <> refht, drillref = zero           
            else, drillref = one
            prv_refht_a = c9k
            prv_refht_i = c9k
            prv_dwell = zero
            ]
          if cuttype = three, sav_dgcode = gcode
          else, z = depth
          if cuttype = one, prv_zia = initht + (rotdia/two)
          else, prv_zia = refht  #Fanuc style - G91 Z depth from R level
          #else, prv_zia = initht  #G91 Z depth from initial height
          feed = fr_pos
          pcom_moveb
          comment
          pcan
          #5 axis must map the true Z, correct Z calculation here
          if cuttype = three,
            [
            prv_zia = zabs + (-depth) + initht
            zia = fmtrnd(zabs)
            zinc = zia - prv_zia
            ]
          else, zinc = depth - refht
          result = nwadrs(stri, zabs)
          result = nwadrs(stri, zinc)
          dwell_out = dwell * 100
    
    prdrlout        #R drill position
          if cuttype = one, refht_a = refht + (rotdia / two))
          else, refht_a = refht
          refht_i = refht - initht
          if cuttype = three, refht_a = w
          if absinc = zero, refht_a, !refht_i
          else, refht_i, !refht_a
    
    pdrill          #Canned Drill Cycle
          pdrlcommonb
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            dwell_out, *feed, strcantext, e
          pcom_movea
    
    ppeck           #Canned Peck Drill Cycle
          pdrlcommonb
          numpeck = abs((depth - refht)/peck1)
          if frac(numpeck)<>0, numpeck=numpeck+1
          numpeckint = int(numpeck)
          peck1 = (depth - refht)/numpeckint
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, !zabs, !zinc, pcout, 
            *peck1, *numpeckint, *feed, strcantext, e  
          pcom_movea
    
    pchpbrk         #Canned Chip Break Cycle
          if peck2 = 0, peck2 = 1
          if shftdrl = 0, shftdrl = 1
          bval = peck1
          dval = refht - zdrl
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            *bval, *peckclr, *dval, *retr, *peck2, *shftdrl, dwell_out, *feed, strcantext, e
          pcom_movea
    
    
    ptap            #Canned Tap Cycle
          pdrlcommonb
          #tool_typ = 4 - RH, 5 - LH
          feed = speed/n_tap_thds  #Override V8.1 parameter feed
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            prigid, *feed, strcantext, e
          pcom_movea
          tapflg = 1
          
    prigid          #Rigid Tap Cycle Toggle
          if peck1=1, "R1"
          else, "R0"
    
    pbore1          #Canned Bore #1 Cycle
          pdrlcommonb
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            dwell_out, *feed, strcantext, e  
          pcom_movea
    
    pbore2          #Canned Bore #2 Cycle
          pdrlcommonb
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            dwell_out, *feed, strcantext, e  
          pcom_movea
    
    pmisc1          #Canned Misc #1 Cycle
          pdrlcommonb
          pcan1, pbld, n, *sgdrill, *sgdrlref, pxout, pyout, prdrlout, pfzout, pcout, 
            dwell_out, *feed, strcantext, e 
          pcom_movea
    
    pmisc2          #Canned Misc #2 Cycle (User Option)
          pdrill
    
    pdrill_2        #Canned Drill Cycle, additional points
          pdrlcommonb
          pcan1, pbld, n, pxout, pyout, prdrlout, pzout, pcout, dwell_out,
            feed, strcantext, e  
          pcom_movea
    
    ppeck_2         #Canned Peck Drill Cycle
          pdrill_2
    
    pchpbrk_2       #Canned Chip Break Cycle
          pdrill_2
    
    ptap_2          #Canned Tap Cycle
          pdrill_2
    
    pbore1_2        #Canned Bore #1 Cycle
          pdrill_2
           
    pbore2_2        #Canned Bore #2 Cycle
          pdrill_2
    
    pmisc1_2        #Canned Misc #1 Cycle
          pdrill_2
    
    pmisc2_2        #Canned Misc #2 Cycle
          pdrill_2
    
    pdrlcst         #Custom drill cycles 8 - 19 (user option)
          #Use this postblock to customize drilling cycles 8 - 19
          pdrlcommonb
          #if drillcyc = 8, pcan1, pbld, n, *sgdrlref, *sgdrill, pxout, pyout, pfzout, pcout, 
          #  prdrlout, dwell, *feed, strcantext, e
          if drillcyc = 8,
            [
            sub_prg_call = peck1
            pcan1, pbld, n, *sg00, *sgabsinc, pfxout, pfyout, strcantext, e
            spaces = 0
            pbld, n, pspc, "(", "CALL ", *sub_prg_call, ")", e
            spaces = sav_spc
            ]
          else, "CUSTOMIZABLE DRILL CYCLE ", pfxout, pfyout, pfzout, pfcout, e
          pcom_movea
    
    pdrlcst_2       #Custom drill cycles 8 - 19, additional points (user option)     
          #Use this postblock to customize drilling cycles 8 - 19
          pdrlcommonb
          #if drillcyc = 8, pcan1, pbld, n, pxout, pyout, pzout, pcout, prdrlout, dwell,
          #  feed, strcantext, e  
          if drillcyc = 8,
            [
            sub_prg_call = peck1
            pcan1, pbld, n, *sg00, *sgabsinc, pfxout, pfyout, strcantext, e
            spaces = 0
            pbld, n, pspc, "(", "CALL ", *sub_prg_call, ")", e
            spaces = sav_spc
            ]
          else, "CUSTOMIZABLE DRILL CYCLE ", pfxout, pfyout, pfzout, pfcout, e
          pcom_movea
    
    pcanceldc       #Cancel canned drill cycle
          result = newfs (three, zinc)
          z = initht
          if cuttype = one, prv_zia = initht + (rotdia/two)
          else, prv_zia = initht
          pxyzcout
          !zabs, !zinc
          prv_gcode = zero
          if cool_zmove = yes & (nextop=1003 | (nextop=1011 & t<>abs(nexttool))), coolant = zero
          pcan
          if drillcyc <> 8, pcan1, pbld, n, "G80", scoolant, strcantext, e
          if use_pitch & tapflg = 1, pbld, n, "G94", e
          pcan2
          tapflg = 0
    
    # --------------------------------------------------------------------------
    #Subprogram postblocks
    #sub_trnstyp - 0=mirror, 1=rotate, 2=scale, 3=translate
    #sub_trnmthd (mirror) - 0=X axis, 1=Y axis, 2=line
    #sub_trnmthd (rotate) - 0=tplane, 1=tplane origin only, 2=coordinates
    # --------------------------------------------------------------------------
    psub_call_m     #Call to main level, single tool
          psub_call_trans
    
    psub_call_mm    #Call to main level, multiple tools
          psub_call_trans
    
    psub_call_trans #Translate level calls from toolchange, user
          if wcstype <= one, result = mprint(shomeserror)
          sav_absinc = absinc
          pindex
          #Mirror or Rotate Coord's
          if sub_trnstyp = zero | (sub_trnstyp = one & mr_rt_actv),
            [ 
            #The original pattern is not mirrored or rotated
            if sub_sec_no,
              [
              absinc = zero
              if sub_trnstyp, psub_rotate
              else, psub_mirror
              ]
            mr_rt_actv = three
            ]
          else, #Translate
            [
            if sub_mny_t,
              [
              pbld, n, pwcs, e
              if wcstype > one, absinc = zero
              if lock_codes = 1 & not(index) & rot_on_x, pbld, n, *sunlock, ";UNLOCK", e
              pbld, n, *sgcode, *sgabsinc, pfxout, pfyout, pfzout,
                pfcout, e
              if lock_codes = 1 & not(index) & rot_on_x & cuttype = 0, pbld, n, *slock, ";LOCK", e
              pe_inc_calc
              ps_inc_calc
              ]
            ]
          absinc = sav_absinc
          result = nwadrs(snull, main_prg_no)      
          main_prg_no = main_prg_no + sav_progno #Add sub number offset
          if sav_progno = main_prg_no, result = mprint(sprgnerror)
          spaces = 0
          pbld, n, pspc, "(", "CALL ", *main_prg_no, ")", e
          spaces = sav_spc
          prv_feed = c9k #Force feed in sub
    
    psub_mirror     #Mirror start code, user
          #Mirror Y axis
          if sub_trnmthd, pbld, n, *sgabsinc, strns_mir_on, *sub_trnsx, e
          #Mirror X axis
          else, pbld, n, *sgabsinc, strns_mir_on, *sub_trnsy, e
    
    psub_rotate     #Rotate start code, user
          pbld, n, *sgcode, *sgabsinc, strns_rot_on, *sub_trnsx, *sub_trnsy,
            [absinc = one], *sgabsinc, *rt_cinc, e
    
    psub_st_m       #Header in main level
          result = nwadrs(snull, main_prg_no)
          #sav_n1 = n
          #n = seqno
          " ", e
          spaces = 0
          #*main_prg_no, ",MX,", e
          "(SUB ", *main_prg_no, ")", e      
          if scomm0 <> snull, ";", *scomm0, e
          spaces = sav_spc
          #G51/G68 requires absolute position on first move
          if mr_rt_actv & absinc = one, 
            [
            sav_absinc = absinc
            absinc = zero
            prv_absinc = m_one
            prv_xabs = m_one
            prv_yabs = m_one
            ]
          else, pbld, n, sgabsinc, e
    
    psub_end_m      #End in main level
          "(RET)", e
          prv_absinc = -1
          #n = sav_n1
          #Reset update variables for subs at main level
          #Mirror or Rotate cancel, output is forced
          if (sub_trnstyp = zero & esub_sec_no > zero)
            | (sub_trnstyp = one & esub_sec_no = esub_totl_no-one
            & sub_trnmthd = two), 
            [
            subout = zero
            no_nc_out = m_one
            sav_absinc = absinc     
            #Mirror cancel
            if sub_trnstyp = zero,
              [
              absinc = zero 
              pbld, n, *sgabsinc, strns_mir_off, *sub_trnsx, *sub_trnsy, e 
              ]
            else, #Rotate cancel
              [
              pbld, n, strns_rot_off, e 
              ]
            absinc = sav_absinc
            no_nc_out = zero
            ]
          end_sub_mny = sub_mny_t
    
    psub_end_mny    #End in main level for many tools sub, user
          #Check for coming out of xform with stage tool.
          if end_sub_mny & stagetool = one,
            [
            *t
            end_sub_mny = zero
            ]
            
    psub_call_s     #Call to sub level
          result = nwadrs(snull, sub_prg_no)
          sub_prg_no = sub_prg_no + sav_progno + 1000 #Add sub number offset
          if sav_progno = sub_prg_no, result = mprint(sprgnerror)
          spaces = 0
          pbld, n, pspc, "(", "CALL ", *sub_prg_no, ")", e
          spaces = sav_spc
    
    psub_st_s       #Header in sub level
          result = nwadrs(snull, sub_prg_no)
          #sav_n2 = n
          #n = seqno
          " ", e
          spaces = 0
          #*sub_prg_no, ",MX,", e
          "(SUB ", *sub_prg_no, ")", e
          if scomm0 <> snull, ";", *scomm0, e      
          spaces = sav_spc
          pbld, n, sgabsinc, e
    
    psub_end_s      #End in sub level
          "(RET)", e
          prv_absinc = -1
          #n = sav_n2
          
    # --------------------------------------------------------------------------
    # Canned Text 
    # --------------------------------------------------------------------------
    pcan            #Canned text - before output call
          strcantext = sblank
          if cant_no > zero,
            [
            if cant_pos1 = zero, pcant_1
            if cant_pos2 = zero, pcant_2
            if cant_pos3 = zero, pcant_3
            if cant_pos4 = zero, pcant_4
            if cant_pos5 = zero, pcant_5
            if cant_pos6 = zero, pcant_6
            if cant_pos7 = zero, pcant_7
            if cant_pos8 = zero, pcant_8
            if cant_pos9 = zero, pcant_9
            if cant_pos10 = zero, pcant_10
            pbld, n, strcantext, e
            strcantext = sblank
            ]
    
    pcan1           #Canned text - with move
          strcantext = sblank
          if cant_no > zero,
            [
            if cant_pos1 = one, pcant_1
            if cant_pos2 = one, pcant_2
            if cant_pos3 = one, pcant_3
            if cant_pos4 = one, pcant_4
            if cant_pos5 = one, pcant_5
            if cant_pos6 = one, pcant_6
            if cant_pos7 = one, pcant_7
            if cant_pos8 = one, pcant_8
            if cant_pos9 = one, pcant_9
            if cant_pos10 = one, pcant_10
            ]
          if cstop, strcantext = strcantext + sm00
          if cgstop, strcantext = strcantext + sm01
          #Output of strcantext occurs at the end of the output line 
    
    pcan2           #Canned text - after output call
          strcantext = sblank
          if cant_no > zero,
            [
            if cant_pos1 = two, pcant_1
            if cant_pos2 = two, pcant_2
            if cant_pos3 = two, pcant_3
            if cant_pos4 = two, pcant_4
            if cant_pos5 = two, pcant_5
            if cant_pos6 = two, pcant_6
            if cant_pos7 = two, pcant_7
            if cant_pos8 = two, pcant_8
            if cant_pos9 = two, pcant_9
            if cant_pos10 = two, pcant_10
            pbld, n, strcantext, e
            strcantext = sblank
            ]
    
    pcant_1         #Canned text - output call
          cantext = cant_val1
          pcant_out
    
    pcant_2         #Canned text - output call
          cantext = cant_val2
          pcant_out
    
    pcant_3         #Canned text - output call
          cantext = cant_val3
          pcant_out
    
    pcant_4         #Canned text - output call
          cantext = cant_val4
          pcant_out
    
    pcant_5         #Canned text - output call
          cantext = cant_val5
          pcant_out
    
    pcant_6         #Canned text - output call
          cantext = cant_val6
          pcant_out
    
    pcant_7         #Canned text - output call
          cantext = cant_val7
          pcant_out
    
    pcant_8         #Canned text - output call
          cantext = cant_val8
          pcant_out
    
    pcant_9         #Canned text - output call
          cantext = cant_val9
          pcant_out
    
    pcant_10        #Canned text - output call
          cantext = cant_val10
          pcant_out
    
    pcant_out       #Canned text - build the string for output
          #Assign string select type outputs
          if cantext = three, bld = one
          if cantext = four, bld = zero
          #Build the cantext string
          if cantext = one, strcantext = strcantext + sm00
          if cantext = two, strcantext = strcantext + sm01
          if cantext > four,
            [
            strtextno = no2str(cantext)
            strcantext = strcantext + strm + strtextno
            ] 
    
    # --------------------------------------------------------------------------
    # Position calculations, generally these do not need to be modified
    # --------------------------------------------------------------------------
    pmiscint        #Capture the top level absinc for subprograms
          if sub_level <= zero, absinc = mi2
          #Disable cutpos2 if not 4 axis, saves time
          if rot_on_x = zero, cutpos2 = m_one
    
    pusecannedyes # Use canned drilling cycles
                 usecandrill = yes  # Use canned cycle for drill
                 usecanpeck  = yes  # Use canned cycle for Peck
                 usecanchip  = yes  # Use canned cycle for Chip Break
                 usecantap   = yes  # Use canned cycle for Tap
                 usecanbore1 = yes  # Use canned cycle for Bore1
                 usecanbore2 = yes  # Use canned cycle for Bore2
                 usecanmisc1 = yes  # Use canned cycle for Misc1
                 usecanmisc2 = yes  # Use canned cycle for Misc2
                 
    pusecannedno # Use canned drilling cycles
                 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
    
    pmotion_su      #Motion Setup (Set brklinestype & linarc)
          brklinestype = zero
          linarc = zero
          if rot_on_x,
            [
            if cuttype = one, linarc = one  #Axis subs
            if cuttype = two, #Polar
              [
              brklinestype = rotary_axis + three
              linarc = one
              ]
            ]
    
    pcuttype   #Determine the cut type
          #cuttype (0 = Tool Plane, 1 = Axis Subs,  2 = Polar, 3 = 4/5 axis)
          cuttype = rotary_type
          if cuttype = three, cuttype = zero
          if mill5,
            [
            if rot_on_x = zero, result = mprint(saxisoff)
            cuttype = three                    
            ]
          if rotary_axis,
            [ 
            if rotary_axis <> rot_on_x, result = mprint(saxiswarn)
            rot_on_x = rotary_axis
            ]
          #Check for Tool Origin in Polar Milling
          if cuttype = two & (tox | toy | toz), result = mprint(stlorgerr)
          #Transform Rotate, set mr_rt_actv if user selected 'coordinates' 
          if sub_trnstyp = one & sub_trnmthd = two,
            [
            #Calculate the rotation incremental angle for G68
            rt_csav = atan2(sub_m2, sub_m1)
            rt_cinc = prv_rt_csav - rt_csav
            while rt_cinc > 180, rt_cinc = rt_cinc - 360
            while rt_cinc < -180, rt_cinc = rt_cinc + 360
            if rot_ccw_pos = one, rt_cinc = -rt_cinc
            !rt_csav
            if sub_sec_no, mr_rt_actv = two
            else, mr_rt_actv = one
            ]
          else, mr_rt_actv = zero
          pfcalc_u_min
          pmotion_su
    
    pxyzcout        #Map coordinates
          if rot_on_x,
            [
            if cuttype = zero, pxyzcout0    #Toolplane Positioning
            if cuttype = one, pxyzcout1     #Axis Substitution
            if cuttype = two, pxyzcout2     #Polar Conversion
            if cuttype = three, pxyzcout3   #Simulatneous 4 axis (Multi-axis)
            if rot_ccw_pos = one, csav = -csav
            if mr_rt_actv <> two,
              [
              pcoutrev
              if index, pindxcalc
              pfcalc
              ]
            else, feed = fr_pos  
            ]
          else,
            [
            xabs = vequ (x)               
            feed = fr_pos
            ]  
    
    pxyzcout0       #Toolplane Positioning
          xabs = vequ (x)               
          if cuttype = 2 & rot_on_x = two & vmc, c = atan2(vtoolx,-vtooly)
          if rot_on_x = two, csav = -c     
          else, csav = c
             
    pxyzcout1       #Axis substitution
          if rot_on_x = one, #X axis substitution
            [
            xabs = x
            yabs = zero
            zabs = z + (rotdia / two)
            csav =  y * (360 / (pi * rotdia))
            ]
          else, #Y axis substitution
            [
            xabs = zero
            yabs = y
            zabs = z + (rotdia / two)
            csav = -x * (360 / (pi * rotdia))
            ]
          if c <> 0,
            [
            if rot_on_x = two, csav = -c
            else, csav = c
            ]
    
    pxyzcout2       #polar interpolation
          #Drill polar is toolplane drilling toward center
          #if not a coincident axis
          #Also, Capture initial index position for Polar Milling
          if (opcode = three & rot_on_x <> three), pxyzcout0
          else,
            [
            if rot_on_x = one, #X axis rotation
              [
              csav = atan2(y, z)   #Z+ zero
              axisx = vequ(aaxisx)
              xabs = rotp(csav, x)
              ] 
            if rot_on_x = two, #Y axis rotation
              [
              csav = atan2(-x, z)   #Z+ zero
              axisx = vequ(baxisx)
              xabs = rotp(csav, x)
              ] 
            if rot_on_x = three, #Z axis rotation
              [
              csav = atan2(-y, x)   #X+ zero 
              axisx = vequ(caxisx)
              xabs = rotp(csav, x)
              ] 
            csav = csav + c
            ]
    
    pxyzcout3       #Multisurf rotary axis motion
          if rot_on_x = one, #Multisurf Rotary about X
            [
            csav = atan2 (vtooly, vtoolz)     
            axisx = vequ (aaxisx)               
            ]
          if rot_on_x = two, #Multisurf Rotary about Y
            [
            csav = atan2 (-vtoolx, vtoolz)     
            axisx = vequ (baxisx)               
            ]
          xabs = rotp (csav, x)           
          u = rotp (csav, u)
          csav = csav + c
    
    pcoutrev        #Rotary axis revolution calculation (Modify for wind-up)
          cdelta = -(csav - prv_csav)
          while abs(cdelta) > ctol, #If motion exceeds ctol, add wind-up
            [
            if cdelta > zero,
              [
              rev = rev - one
              cdelta = cdelta - 360 
              ]
            else, 
              [
              rev = rev + one
              cdelta = cdelta + 360 
              ]
            ]
          if cuttype <> one, cabs = rev * 360 + csav
          else, cabs = sav_rev * 360 + csav
          if (cuttype = zero | opcode = 3 | (gcode = 0 & cuttype <> one)) & one_rev = one,
            [
            while fmtrnd(cabs) >= 360,
              [
              cabs = cabs - 360
              rev = rev - 1
              ]
            while fmtrnd(cabs) < 0,
              [
              cabs = cabs + 360
              rev = rev + 1
              ]
            #while fmtrnd(cabs) < -360,
            #  [
            #  cabs = cabs + 720
            #  rev = rev + 2
            #  ]
            if abs(cdelta) >= 0.0005, prv_cabs = c9k
            ]   
          !csav
    
    pindxcalc       #Index move calculations, direction is shortest
          #Check if in tolerance
          cdelta = frac(abs(csav)/ctable)
          if cdelta > ixtol & cdelta < 1-ixtol,
            result = mprint(sindxerror)
          cdelta = prvcabs - cabs
          #Phase shift delta 10 revolutions, check odd/even
          if frac(int((cdelta + 3600)/180)/two), indx_mc = one
          else, indx_mc = zero
          #Set range 0-360
          indx_out = csav  
          while indx_out < 0, indx_out = indx_out + 360
          while indx_out > 360, indx_out = indx_out - 360
          
    #Feedrate calculations
    pfcalc          #Feedrate calculations, gcode 0 does not evaluate
          if gcode <> zero,
            [
            if abs(fmtrnd(cabs)-prvcabs) <= 0.001 | index | not(rot_feed) | opcode = 3, pfcalc_u_min
            else,
              [
              #if cuttype = one & (cutpos2 <= one),  #Proposed change
              if cuttype = one & (cutpos2 <= one | cutpos2 = four & (opcode < 5 & opcode > 12)),
              pfcalc_u_min
              else, pfclc_deg_inv
              ]
            if ipr_type <> prv_ipr_type, prv_feed = c9k
            ]
    
    pfcalc_u_min    #Feedrate unit/min
          ipr_type = zero
          feed = fr_pos
          if feed > maxfeedpm, feed = maxfeedpm
          prvfrdeg = feed
    
    pfclc_deg_inv   #Feedrate deg/min
          circum = zabs * two * pi 
          if circum = zero, circum = c9k          #Don't allow Zero
          ldelta = sqrt((xabs-prv_xabs)^2+(yabs-prv_yabs)^2+(zabs-prv_zabs)^2)
          cdelta = ((abs(cabs - prvcabs))/360)*circum
          if ldelta = zero, cldelta = cdelta
          else, cldelta = sqrt(cdelta^two + ldelta^two)
          if cldelta = zero, cldelta = c9k
          if use_frinv, 
            [
            #Feedrate inverse calculation
            ipr_type = two              
            prv_feed = c9k #Always force feed
            frinv = fr_pos/cldelta
            if rot_feed & opcode <> 3,
              [
              if frinv > maxfrinv, frinv = maxfrinv
              feed = frinv
              ]
            ]
          else, 
            [
            #Feedrate deg/min control and calculation
            ipr_type = zero  #Change to ipr_type = one to force new DPM
            frdeg = abs(cdelta/cldelta) * abs(fr_pos * (360/circum))
            if abs(frdeg - prvfrdeg) > frdegstp | ipr_type <> prv_ipr_type, 
              [
              #Control output of frdeg
              if rot_feed & opcode <> 3,
                [
                prvfrdeg = frdeg
                feed = frdeg
                ]
              ]
            if frdeg > maxfrdeg & rot_feed, feed = maxfrdeg
            ]
    
    #Incremental calculations
    ps_inc_calc     #Incremental calculations, start              
          xia = fmtrnd(xabs)
          yia = fmtrnd(yabs)
          zia = fmtrnd(zabs)
          xinc = vsub (xia, prv_xia)
          ps_cinc_calc
          
    ps_cinc_calc    #Incremental calculations, start rotary              
          cia = fmtrnd(cabs)
          cinc = cia - prv_cia
    
    pe_inc_calc     #Incremental calculations, end              
          prvcabs = fmtrnd(cabs) #Avoid updating until called explicitly
          !xia, !yia, !zia, !cia
          !x, !y, !z
    
    # --------------------------------------------------------------------------
    # Tooltable Output
    # --------------------------------------------------------------------------
    pwrtt      # Write tool table, scans entire file, null tools are negative
               if rotaxis > 0 | rotary_type > 0 | mill5 <> 0,
                 [
                 rot_on_x = sav_rot_on_x
                 output_z = no
                 ]
               #if vmc = 0 & tlplnno <> 2, rot_on_x = sav_rot_on_x
               #if vmc = 1 & tlplnno > 1, rot_on_x = sav_rot_on_x
               if tlplnno > 1, rot_on_x = sav_rot_on_x
               tlplnno = wbuf(3,wc3)  #Buffers out tool plane values
               t = wbuf(4,wc4)        #Buffers out tool number values
               if tool_table = 1, ptooltable
               if tool_table = 2, ppredtool
               if tool_table = 3, pmetatool
               if t >= zero, tcnt = tcnt + one           
               ptravel
               pwritbuf5
               
    ptooltable # Write tool table, scans entire file, null tools are negative
               tnote = t 
               toffnote = tloffno
               tlngnote = tlngno
               spaces=0
               if t >= zero, ";", *t, ptspace, " : ", plistcomm, " : ", *tldia, punit, " : ", popnote
               #if t >= zero,
               #  [
               #  if tcr>0, ";", *t, ptspace, " : ", plistcomm, " : ", *tlngno, phspace, " : ", *tloffno, pdspace, " : ", *tldia, punit, " : ", *tcr, " : ", popnote
               #  if tcr=0, ";", *t, ptspace, " : ", plistcomm, " : ", *tlngno, phspace, " : ", *tloffno, pdspace, " : ", *tldia, punit, " : ", "        : ", popnote
               #  ]
               #if t >= zero,
               #  [
               #  if tcr>0, ";", *tnote, "  ", *toffnote, "  ", *tlngnote, "  ", *tldia, "  ", *tcr, "  ", popnote
               #  if tcr=0, ";", *tnote, "  ", *toffnote, "  ", *tlngnote, "  ", *tldia, "  ", popnote
               #  ]
               spaces=sav_spc
               
    punit      # Tool unit
               if met_tool, "mm", pdiamspc
               else, 34, pdiamspc
    
    ptravel    # Tool travel limit calculation
               if x_min < x_tmin, x_tmin = x_min
               if x_max > x_tmax, x_tmax = x_max
               if y_min < y_tmin, y_tmin = y_min
               if y_max > y_tmax, y_tmax = y_max
               if z_min < z_tmin, z_tmin = z_min
               if z_max > z_tmax, z_tmax = z_max
               
    ppredtool  # Write tool setup info for Predator Virtual CNC
               #if tool_typ =  1, styp1    # CENTER DRILL     1 - NTG/S4
               #if tool_typ =  2, styp2    # SPOT DRILL       2 - S4
               #if tool_typ =  3, styp3    # DRILL            3 - S4
               #if tool_typ =  4, styp4    # TAP-RH           4 - S4 - MAX 179 ANGLE
               #if tool_typ =  5, styp5    # TAP-LH           5 - S4 - MAX 179 ANGLE
               #if tool_typ =  6, styp6    # REAMER           6 - S3/S1/S2
               #if tool_typ =  7, styp7    # BORING BAR       7 - S3/S1/S2
               #if tool_typ =  8, styp8    # COUNTER BORE     8 - NTG
               #if tool_typ =  9, styp9    # COUNTER SINK     9 - NTG/S4
               #if tool_typ = 10, styp10   # END MILL FLAT   10 - S1
               #if tool_typ = 11, styp11   # END MILL SPHERE 11 - S2
               #if tool_typ = 12, styp12   # CHAMFER MILL    12 - S7/NTG
               #if tool_typ = 13, styp13   # FACE MILL       13 - S7/S9/NTG
               #if tool_typ = 14, styp14   # SLOT MILL       14 - NTG/S1
               #if tool_typ = 15, styp15   # CORNER RAD MILL 15 - S5/FLAT
               #if tool_typ = 16, styp16   # DOVETAIL MILL   16 - DOVETAIL/NTG
               #if tool_typ = 17, styp17   # TAPER MILL      17 - S7/S9/S10
               #if tool_typ = 18, styp18   # LOLLIPOP MILL   18 - S6
               #if tool_typ = 19, styp19   # END MILL BULL   19 - S3
               
               tcr_pred = tcr
               tldia_pred = tldia
               tip_angle_ch = tip_angle*2
               spaces=0
               
               if t >= zero,
                 [
                 # CENTER DRILL
                 if tool_typ = 1, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                 # SPOT DRILL
                 if tool_typ = 2, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                 # DRILL
                 if tool_typ = 3, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                 # TAP-RH
                 if tool_typ = 4,
                   [
                   if tip_angle <= 179, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                   else, "(MTOOL ", *t, " ", *tldia_pred, " ", "A179.", " ", *flute_len, " S4)"
                   ]
                 # TAP-LH
                 if tool_typ = 5,
                   [
                   if tip_angle <= 179, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                   else, "(MTOOL ", *t, " ", *tldia_pred, " ", "A179.", " ", *flute_len, " S4)"
                   ]
                 # REAMER
                 if tool_typ = 6,
                   [
                   if tcr = 0, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                   if tcr = tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S2)"
                   if tcr > 0 & tcr < tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *flute_len, " S3)"
                   ]
                 # BORING BAR
                 if tool_typ = 7,
                   [
                   if tcr = 0, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                   if tcr = tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S2)"
                   if tcr > 0 & tcr < tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *flute_len, " S3)"
                   ]
                 # COUNTER BORE
                 if tool_typ = 8,
                   [
                   if tcr = 0, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                   if tcr = tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S2)"
                   if tcr > 0 & tcr < tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *flute_len, " S3)"
                   ]
                 # COUNTER SINK
                 if tool_typ = 9, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S4)"
                 # END MILL FLAT
                 if tool_typ = 10, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                 # END MILL SPHERE
                 if tool_typ = 11, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S2)"
                 # CHAMFER MILL
                 if tool_typ = 12, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle_ch, " ", *flute_len, " S7)"
                 # FACE MILL
                 if tool_typ = 13, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                 # SLOT MILL
                 if tool_typ = 14, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                 # CORNER RAD MILL
                 if tool_typ = 15,
                   [
                   if tcr = 0, "(MTOOL ", *t, " ", *tldia_pred, " ", *flute_len, " S1)"
                   else, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *flute_len, " S5)"
                   ]
                 # DOVETAIL MILL
                 if tool_typ = 16, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S8)"
                 # TAPER MILL
                 if tool_typ = 17,
                   [
                   if tcr = 0, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S7)"
                   if tcr = tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *tip_angle, " ", *flute_len, " S9)"
                   if tcr > 0 & tcr < tlrad, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *tip_angle, " ", *flute_len, " S10)"
                   ]
                 # LOLLIPOP MILL
                 if tool_typ = 18, "(MTOOL ", *t, " ", *tldia_pred, " S6)"
                 # END MILL BULL
                 if tool_typ = 19, "(MTOOL ", *t, " ", *tldia_pred, " ", *tcr_pred, " ", *flute_len, " S3)"
                 ]
               spaces=sav_spc
               
    pmetatool  # Write tool setup info for MetaCut View 
               tcr_meta = tcr
               if tool_typ = 13 | tool_typ = 17, tldia_meta = tldia + (2 *(flute_len * tan(tip_angle))
               else, tldia_meta = tldia
               if cctotip = 0, tipcomp = 1
               else, tipcomp = 0
               if tool_typ = 10 | opcode = 3, tipcomp = 0
               if tool_typ = 12, td_meta = tip_dia
               else, td_meta = 0
               if tool_typ = 13 | tool_typ = 17, td_meta = tldia
               flute_meta = flute_len
               oa_meta = oa_len
               ta_meta = tip_angle
               cd_meta = hldr_dia
               cl_meta = hldr_len
               sd_meta = cd_meta
    
               #(NWDTOOL NAME"1/2 CHAMFER MILL" T1 D.5 R0. F2. L3. A45. TD.06 CD2. CL1. SD2. C0)           
               # N = "Tool name"
               # T = Tool No.
               # D = Tool Dia.
               # R = Corner Radius
               # F = Flute Length
               # L = Tool over all length
               # A = Tip angle or Taper angle
               # TD = Tip Dia.
               # CD = Colllet/Holder Dia.
               # CL = Collet/Holder Height
               # SD = Spindle Dia. (set equal to Collet Diameter)
               # C = tip or center 0 = tip 1 = center
               
               spaces=0
               if t >= zero, "(NWDTOOL N", 34, pmetacomm, 34, " ", *t, " ", *tldia_meta, " ",
                              [if tcr_meta > 0, *tcr_meta, " "], *flute_meta, " ", *oa_meta, " ",
                              [if ta_meta<>180, *ta_meta, " "], [if td_meta > 0, *td_meta, " "],
                              *cd_meta, " ", *cl_meta, " ", *sd_meta, " ", *tipcomp, ")"
               spaces=sav_spc
               
    # --------------------------------------------------------------------------
    # Buffer 5  Read / Write Routines
    # --------------------------------------------------------------------------
    pwritbuf5   # Write Buffer 1
                b5_gcode = gcode
                b5_zmin = z_min
                b5_zmax = z_max
                b5_gcode = wbuf(5, wc5)
    
    preadbuf5   # Read Buffer 1
                size5 = rbuf(5,0)
                b5_gcode = 1000
                min_depth = 99999
                max_depth = -99999
                while rc5 <= size5 & b5_gcode = 1000,
                  [
                  if rc5 <= size5, b5_gcode = rbuf(5,rc5)
                  if b5_zmin < min_depth, min_depth = b5_zmin
                  if b5_zmax > max_depth, max_depth = b5_zmax
                  ]
    
    # --------------------------------------------------------------------------
    # Numbered questions for Mastercam
    # --------------------------------------------------------------------------
    38. Rapid feedrate? 300.0
    1538. Rapid feedrate (metric)? 10000.0
    #76. Configuration file name? 
    80. Communications port number for receive and transmit (1 or 2) ? 2
    81. Data rate (110,150,300,600,1200,2400,4800,9600,14400,19200,38400)? 9600
    82. Parity (E/O/N)? E
    83. Data bits (7 or 8)? 7
    84. Stop bits (1 or 2)? 2
    85. Strip line feeds? N
    86. Delay after end of line (seconds)? 0
    87. Ascii, Eia, or Binary (A/E/B)? A
    88. Echo keyboard to screen in terminal emulation? n
    89. Strip carriage returns? N
    90. Drive and subdirectory for NC files? 
    91. Name of executable post processor? MP
    92. Name of reverse post processor? RP
    93. Reverse post PST file name? RPFAN
    100. Number of places BEFORE the decimal point for sequence numbers? 0
    101. Number of places AFTER the decimal point for sequence numbers? 0
    103. Maximum spindle speed? 10000
    107. Average time for tool change (seconds)? 2.0
    161. Enable Home Position button? y
    162. Enable Reference Point button? y
    163. Enable Misc. Values button? y
    164. Enable Rotary Axis button? y
    165. Enable Tool Plane button? y
    166. Enable Construction Plane button? y
    167. Enable Tool Display button? y
    168. Check tplane during automatic work origin creation? y
    
    # --------------------------------------------------------------------------
    # Default Miscellaneous Real Values
    # --------------------------------------------------------------------------
    201. Default miscellaneous real variable 1 (mr1)? 0.0
    202. Default miscellaneous real variable 2 (mr2)? 0.0
    203. Default miscellaneous real variable 3 (mr3)? 0.0
    204. Default miscellaneous real variable 4 (mr4)? 0.0
    205. Default miscellaneous real variable 5 (mr5)? 0.0
    206. Default miscellaneous real variable 6 (mr6)? 0.0
    207. Default miscellaneous real variable 7 (mr7)? 0.0
    208. Default miscellaneous real variable 8 (mr8)? 0.0
    209. Default miscellaneous real variable 9 (mr9)? 0.0
    210. Default miscellaneous real variable 10 (mr10)? 0.0
    
    # --------------------------------------------------------------------------
    # Default Miscellaneous Real Values (METRIC)
    # --------------------------------------------------------------------------
    1601. Default miscellaneous real variable 1 (mr1) (metric)? 0.0
    1602. Default miscellaneous real variable 2 (mr2) (metric)? 0.0
    1603. Default miscellaneous real variable 3 (mr3) (metric)? 0.0
    1604. Default miscellaneous real variable 4 (mr4) (metric)? 0.0
    1605. Default miscellaneous real variable 5 (mr5) (metric)? 0.0
    1606. Default miscellaneous real variable 6 (mr6) (metric)? 0.0
    1607. Default miscellaneous real variable 7 (mr7) (metric)? 0.0
    1608. Default miscellaneous real variable 8 (mr8) (metric)? 0.0
    1609. Default miscellaneous real variable 9 (mr9) (metric)? 0.0
    1610. Default miscellaneous real variable 10 (mr10) (metric)? 0.0
    
    # --------------------------------------------------------------------------
    # Enable/Disable Miscellaneous Real Variable switches
    # --------------------------------------------------------------------------
    1611. Enable miscellaneous real variable 1? y
    1612. Enable miscellaneous real variable 2? y
    1613. Enable miscellaneous real variable 3? y
    1614. Enable miscellaneous real variable 4? y
    1615. Enable miscellaneous real variable 5? y
    1616. Enable miscellaneous real variable 6? y
    1617. Enable miscellaneous real variable 7? y
    1618. Enable miscellaneous real variable 8? y
    1619. Enable miscellaneous real variable 9? y
    1620. Enable miscellaneous real variable 10? y
    
    # --------------------------------------------------------------------------
    # Default Miscellaneous Integer Values
    # --------------------------------------------------------------------------
    301. Miscellaneous integer variable 1 (mi1)? 0
    302. Absolute or Incremental [0=ABS,1=INC] (mi2)? 0
    303. Miscellaneous integer variable 3 (mi3)? 0
    304. Miscellaneous integer variable 4 (mi4)? 0
    305. Miscellaneous integer variable 5 (mi5)? 0
    306. Miscellaneous integer variable 6 (mi6)? 0
    307. Miscellaneous integer variable 7 (mi7)? 0
    308. Miscellaneous integer variable 8 (mi8)? 0
    309. Lock on First WCS [0=No,1=Yes] (mi9)? 0
    310. M00 before operation [0=No,1=Yes] (mi10)? 0
    
    # --------------------------------------------------------------------------
    # Enable/Disable Miscellaneous Integer Variable switches
    # --------------------------------------------------------------------------
    1621. Enable miscellaneous integer variable 1? y
    1622. Enable miscellaneous integer variable 2? y
    1623. Enable miscellaneous integer variable 3? y
    1624. Enable miscellaneous integer variable 4? y
    1625. Enable miscellaneous integer variable 5? y
    1626. Enable miscellaneous integer variable 6? y
    1627. Enable miscellaneous integer variable 7? y
    1628. Enable miscellaneous integer variable 8? y
    1629. Enable miscellaneous integer variable 9? y
    1630. Enable miscellaneous integer variable 10? y
    
    # --------------------------------------------------------------------------
    # Configuration File association parameters (default is "y")
    # --------------------------------------------------------------------------
    #400. Name of associated cfg file? 
    401. Read SYSTEM COLORS section? y
    402. Read ALLOCATIONS section? y
    403. Read TOLERANCES section? y
    404. Read DATA PATHS section? y
    405. Read COMMUNICATIONS section? y
    406. Read DRAFT SETTINGS section? y
    407. Read MISCELLANEOUS section? y
    408. Read NC SETTINGS section? y
    409. Read DIALOG SCRIPTS section? y
    410. Read DESIGN SETTINGS section? y
    411. Read PLOTTER SETTINGS section? y
    412. Read ALT-KEY ASSIGNMENTS section? y
    413. Read CAD section? y
    414. Read START/EXIT section? y
    415. Read SCREEN section? y
    416. Read FILE NAMES section? y
    
    1500. Chook to execute from 'Misc. values' button?
    1501. Insert parameter information in the ascii NCI? n
    1502. Write operation information to binary file (.ops)? y
    
    1520. Display a warning when cutter compensation in control simulation finds an error? n
    
    # Do NOT manually change the answer for Q.1999 !
    1999. Product major version number that post supports? 9
    
    3001. Machine acceleration? 2
    3002. timing size? .1

  7. #7
    Registered
    Join Date
    Mar 2005
    Posts
    215
    I sent you a pm

  8. #8
    Registered
    Join Date
    Mar 2007
    Posts
    2
    i have the same problem with my machine so i modified the post i can send you a copy i took of the line giving the problem also the g54 added a look ahead g51 a255 e0.05 buffer becuase i do a lot of 3d machining and removed the go home command at the end

  9. #9
    Registered
    Join Date
    Mar 2007
    Posts
    2
    heres the post for fagor 8055m its renamed felipe

  10. #10
    Registered
    Join Date
    Dec 2007
    Posts
    617
    Here's mine, works great.
    regards
    Attached Files Attached Files
    ----------------
    Can't Fix Stupid

  11. #11
    Registered
    Join Date
    Sep 2009
    Posts
    2
    Hi there!
    I'm working with mastercam v8 and his post doesn't work well with the drill cycles in fagor 8055 M. Could you help me to change my post or could you give me another one that works well with drill cycles. Thanks!

  12. #12
    Registered
    Join Date
    Jul 2010
    Posts
    0

    Help editing only one line in post

    Quote Originally Posted by cam1 View Post
    Here's mine, works great.
    regards
    I have edited this post hoping to get it work with my machine with Fagor 8055 controller, but I have one problem, because I don't know how and where to add a line in a post to get "start clearance" at the beginning of the NC code (see line N160 in 1000.pim). See atachments:
    • 1000.pim shows how posted NC should look like
    • 1009.pim is the NC which is posted with this modified post
    • FAGOR_8055.pst is edited post which still needs editing


    So as you noticed I only need a line N160 (in 1000.pim) to be posted with this post. If someone will please help me with this one or at least point me in the right direction! Thank you!
    Attached Files Attached Files

  13. #13
    Registered
    Join Date
    Jul 2010
    Posts
    0
    *BUMP*

  14. #14
    Registered
    Join Date
    Mar 2013
    Posts
    0
    hi there
    can u send me the fagor 3 axis mill 8055 post plz i didnt do a backup and a network virus destroyed my post plz plz plz
    thx

  15. #15
    Registered
    Join Date
    Aug 2015
    Posts
    3

    Re: Mastercam post for Fagor 8055M

    Hi,
    I have syntax error on following code for 3 axis milling machine:
    G03 X-0.8075 Y0.75 I-0.75 J0.75
    the error code is:
    CNC:1084 Circular path programmed incorrectly
    Anyone having same problem? How should circular interpolation be written?
    Thank you, Ivan

  16. #16
    Member
    Join Date
    Jul 2003
    Posts
    1220

    Re: Mastercam post for Fagor 8055M

    You will need to post the previous line. (the start point of the arc)

  17. #17
    Registered
    Join Date
    Oct 2016
    Posts
    1

    Re: Mastercam post for Fagor 8055M

    Hi, Cam1. I tried the post you submitted but I get a ( Variable not defined SMC path) error Post line number 1456. I changed the file to be a .PST file. Do I also need a text file with this post?
    Any help would be appreciated.
    Rager

  18. #18
    Member
    Join Date
    Sep 2008
    Posts
    12

    Re: Mastercam post for Fagor 8055M

    i am looking for fagor 8055 m mastercam post prosser

  19. #19
    Member
    Join Date
    Sep 2008
    Posts
    12

    Re: Mastercam post for Fagor 8055M

    HI IAM LOOKING FOR A MASTERCAM POST FOR FAGOR
    8055 M

  20. #20
    Member
    Join Date
    May 2018
    Posts
    15

    Re: Mastercam post for Fagor 8055M

    do you guys have anything that would work for ESPRIT?

Similar Threads

  1. New to G-Code; Using Bobcad V26 with Fagor 8055M
    By PJameson in forum G-Code Programing
    Replies: 2
    Last Post: 04-03-2014, 08:37 PM
  2. FAGOR 8055M post-processor
    By Aionerv in forum BobCad-Cam
    Replies: 1
    Last Post: 02-06-2013, 08:21 PM
  3. FAGOR 8055M MASTERCAM V8 POST
    By NIKEIME in forum Post Processors for MC
    Replies: 2
    Last Post: 08-06-2012, 10:39 AM
  4. Drive Error with Fagor 8055M
    By Kiwi in forum Fagor Automation
    Replies: 24
    Last Post: 08-06-2012, 09:53 AM
  5. Fagor 8055m and renishaw sp2-1
    By mwyss in forum Fagor Automation
    Replies: 0
    Last Post: 05-13-2011, 10:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •