o <circular_pocket> sub
    ; front end for slot_pocket
    ; current as of 2017-11-25 1100
    ; input
    ;    #<_CoolantFinish>
    ;    #<_CoolantEndRough>
    ;    #<_CoolantSideRough>
    ;    #<_Diameter>
    ;    #<_DOCFinish>
    ;    #<_DOCEndRough>
    ;    #<_DOCSideRough>
    ;    #<_FeedFinish>
    ;    #<_FeedEndRough>
    ;    #<_FeedSideRough>
    ;    #<_MinutesHere>
    ;    #<_OldA>
    ;    #<_PreDrilledDiameter>  optional
    ;    #<_RampAngle>           from options
    ;    #<_RampFeedFactor>      from options
    ;    #<_ShowProgress>
    ;    #<_SpeedEndRough>
    ;    #<_SpeedFinish>
    ;    #<_SpeedSideRough>
    ;    #<_StepOverFraction>    from options
    ;    #<_ToolOD>              from <set_tool>
    ;    #<_Trepanning>
    ;    #<_ToolRadius>          from <set_tool>
    ;    #<_TotalMinutes>
    ;    #<_WOCFinish>
    ;    #<_WOCEndRough>
    ;    #<_WOCSideRough>
    ;    #<_XCenter>
    ;    #<_YCenter>
    ;    #<_ZBottom>
    ;    #<_ZClear>
    ;    #<_ZTop>

;    plan (Oh 910-990)
;      ramp to ZBottom EndRough
;      flatten base of ramp EndRough
;      flatten base of ramp finish
;      radial passes of <= WOCSideRough to radius = ToolRadius - stepover
;        downward passes of <= DOCSideRough
;        flatten bottom by FinishDOC
;      finish rim
    o 909 if [exists[#<_PreDrilledDiameter>] EQ 0]
        #<_PreDrilledDiameter> = 0
    o 909 endif

    #<_Radius> = [#<_Diameter> / 2]
    #<_FinishRimRadius> = [#<_Radius> - #<_ToolRadius>]
    #<_RampPathRadius> = [#<_FinishRimRadius> - #<_WOCFinish>]
    #<TotalRoughDOC> = [#<_ZTop> - #<_ZBottom> - #<_DOCFinish>]

    ; ****** ramp computation ***********************************
    #<RampCircumference> = [2 * 3.14159 * #<_RampPathRadius>]
    #<DepthPerTurn> = [#<RampCircumference> * tan[#<_RampAngle>]]
    #<_RampTurns> = 0
    #<RampInches> = 0
    o 910 if [#<TotalRoughDOC> GT 0]  ; not at ZBottom + DOCFinish
        #<_RampTurns> = [fup[#<TotalRoughDOC> / #<DepthPerTurn>]]
        #<RampInches> = [#<TotalRoughDOC> / sin[#<_RampAngle>]]
    o 910 endif
    ; (debug, ramp circumference = #<RampCircumference>)

    ; ****** radial passes ********************************************
    #<StepOver> = [#<_StepOverFraction> * #<_ToolOD>]
    #<FinalRadius> = [#<_ToolRadius> - #<StepOver> + #<_PreDrilledDiameter> / 2]
    o 911 if [#<FinalRadius> LT 0]
        #<FinalRadius> = [#<StepOver>]
    o 911 endif
    o 912 if [#<FinalRadius> GT #<_RampPathRadius>]
        #<FinalRadius> = [#<_RampPathRadius>]
    o 912 endif
    #<TotalRoughWOC> = [#<_RampPathRadius> - #<FinalRadius>]
    #<_VerticalPasses> = 0
    #<_WOC> = 0
    #<_DOC> = 0
    #<_RadialPasses> = 0
    o 915 if [[#<TotalRoughWOC> GT 0] AND [#<_Trepanning> EQ 0]]
        #<_RadialPasses> = [fup[#<TotalRoughWOC> / #<_WOCSideRough>]]
        #<_WOC> = [#<TotalRoughWOC> / #<_RadialPasses>]
        o 9151 if [#<TotalRoughDOC> GT 0]
          #<_VerticalPasses> = [fup[#<TotalRoughDOC> / #<_DOCSideRough>]]
          #<_DOC> = [#<TotalRoughDOC> / #<_VerticalPasses>]
        o 9151 endif
    o 915 endif

    ; ****** progress computation **************************************
    #<ProgressHere> = 0
    o 920 if [#<_ShowProgress>]                                                ; progress increments
        #<ProgressHere> = [100 * #<_MinutesHere> / #<_TotalMinutes>]      ; ..
    o 920 endif

    #<RampCircuits>          = [#<_RampTurns>]
    #<RampBaseCircuits>      = 2                                 ; rough & finishing
    #<CircuitsPerRadialPass> = [#<_VerticalPasses> + 1]          ; ..
    #<RadialCircuits>        = [#<_RadialPasses> * #<CircuitsPerRadialPass>]
    #<FinishRimCircuits>     = 1
    #<TotalCircuits>         = [#<RampCircuits> + #<RampBaseCircuits> + #<RadialCircuits> + #<FinishRimCircuits>]
    #<_ProgPerCircuit>       = [#<ProgressHere> / #<TotalCircuits>]
    #<_ProgRamp>             = [#<RampCircuits> * #<_ProgPerCircuit>]

; ********** action ***********************************************************
;
    S [#<_SpeedEndRough>] F [#<_FeedEndRough>]    ; must say something
    M3                                            ; spindle on
    o 930 if [#<_RampTurns> GT 0]                 ; * not already close to ZBottom
        M98 P940                                  ; .. ramp
    o 930 endif                                   ; ..
    o 931 if [#<_RadialPasses> GT 0]              ; * not already near desired radius
        ;(msg, spiral in)
        M98 P950                                  ; .. radial passes inward
    o 931 endif                                   ; ..
    o 932 if [#<_WOCFinish> GT 0]                 ; * must finish the rim
        ;(msg, finish rim)
        M98 P960                                  ; ..
    o 932 endif                                   ; ..
    G00 Z [#<_ZClear>]                            ; neutral position
    M5 M9                                         ; spindle & coolant off
o <circular_pocket> endsub                          ; return to caller

; ********** end action ***********************************************************

    o 940 ; ********************** ramp
        ; uses
        ;   ProgRamp
        ;   ProgRampBase
        ;   RampPathRadius
        ;   RampTurns
        ; starts unknown
        G00 Z [#<_ZClear>]                                        ; define position
        G00 X [#<_XCenter> + #<_RampPathRadius>] Y [#<_YCenter>]  ; .. above 3 o'clock
        S [#<_SpeedEndRough>]                                     ; .. roughing
        F [#<_RampFeedFactor> * #<_FeedEndRough>]                 ; ..
        o <coolant> call [#<_CoolantEndRough>]                    ; ..
        #<_OldA> = [#<_OldA> + #<_ProgRamp>]                      ; progress
        G00 Z [#<_ZTop>]                                          ; start at top
        G02 X [#<_XCenter> + #<_RampPathRadius>] Z [#<_ZBottom> + #<_DOCFinish>] I [-#<_RampPathRadius>] P [#<_RampTurns>] A [#<_OldA>]

        F [#<_FeedEndRough>]                                      ; flatten ramp bottom
        #<_OldA> = [#<_OldA> + #<_ProgPerCircuit>]                ; progress
        G02 X [#<_XCenter> + #<_RampPathRadius>] I [-#<_RampPathRadius>] A [#<_OldA>]
        S [#<_SpeedFinish>] F [#<_FeedFinish>]                    ; finishing base of ramp
        o <coolant> call [#<_CoolantFinish>]                      ; ..
        G01 Z [#<_ZBottom>]                                       ; dig in
        #<_OldA> = [#<_OldA> + #<_ProgPerCircuit>]                  ; flatten ramp bottom
        G02 X [#<_XCenter> + #<_RampPathRadius>] I [-#<_RampPathRadius>] A [#<_OldA>]
        M99                                                       ; return to caller

    o 950 ; ********************** radial passes
        ; uses
        ;    DOC
        ;    ProgVertical
        ;    RadialPasses
        ;    RampPathRadius
        ;    VerticalPasses
        ;    WOC
        ; starts undefined or at bottom of ramp

        G00 Z [#<_ZClear>]                                 ; define position
        #<CutRadius> = [#<_RampPathRadius>]                ; ..
        G00 X [#<_XCenter> + #<CutRadius>] Y [#<_YCenter>] ; .. above 3 o'clock
        o 952 repeat [#<_RadialPasses>]                    ; next inward pass
           #<CutRadius> = [#<CutRadius> - #<_WOC>]         ; ..
           o 9521 if [#<_VerticalPasses> GT 0]             ; (not ready for FinishDOC)
             S [#<_SpeedSideRough>] F [#<_FeedSideRough>]  ; .. roughing
             o <coolant> call [#<_CoolantSideRough>]       ; ..
             #<ZCut> = [#<_ZTop>]                          ; old cut
             G00 Z [#<ZCut>]                               ; rapid through old cut
             o 95211 repeat [#<_VerticalPasses>]           ;
               #<ZCut> = [#<ZCut> - #<_DOC>]               ; .. new depth
               G01 Z [#<ZCut>]                             ; dig in
               #<_OldA> = [#<_OldA> + #<_ProgPerCircuit>]    ; progress
               G02 X [#<_XCenter> + #<CutRadius>] I [-#<CutRadius>] A [#<_OldA>]
             o 95211 endrepeat                             ; end of one vertical pass
           o 9521 endif                                    ; end of vertical roughing
           S [#<_SpeedFinish>] F [#<_FeedFinish>]          ; finishing bottom of radial pass
           o <coolant> call [#<_CoolantFinish>]            ; ..
           G01 Z [#<_ZBottom>]                             ; dig in
           #<_OldA> = [#<_OldA> + #<_ProgPerCircuit>]        ; progress
           G02 X [#<_XCenter> + #<CutRadius>] I [-#<CutRadius>] A [#<_OldA>]
       o 952 endrepeat                                     ; end of radial passes
       M99                                                 ; return to caller

    o 960 ; ********************** finish the rim
        ; uses
        ;    ProgFinish
        ;    Radius
        ; starts undefined or at bottom somewhere

        S [#<_SpeedFinish>] F [#<_FeedFinish>]             ; finishing
        o <coolant> call [#<_CoolantFinish>]               ; ..
        #<CutRadius> = [#<_FinishRimRadius>]               ; cut at target surface
        G00 Z [#<_ZClear>]                                 ; rapid through old cut
        G00 X [#<_XCenter> + #<CutRadius>] Y [#<_YCenter>] ; ..
        G00 Z [#<_ZBottom> + #<_DOCFinish>]                ; ..
        G01 Z [#<_ZBottom>]                                ; dig in
        #<_OldA> = [#<_OldA> + #<_ProgPerCircuit>]         ; progress
        G03 X [#<_XCenter> + #<CutRadius>] I [-#<CutRadius>] A [#<_OldA>]
        M99

