Subprogram – a named part of the program containing the description of a specific set of actions that commonly performs a logically separate task. Sub can be repeatedly called from different parts of the program. Sub initially appeared to optimize the program in terms of memory consumption. They allowed not to repeat the program identical blocks of code, and describe them once and call as needed. Currently, this function of routines has become an auxiliary, their main purpose - structuring programs to ease its understanding and support.

Isolation of a set of actions in the sub and call it as needed allows you to logically allocate coherent subtask, which is a model solution. This action is another advantage (in addition to saving memory) over the repetition of similar acts: any change (error correction, optimization, and expansion of functionality), made in the sub-program is automatically reflected in all its calls, while at duplicating each change should be maintained in each occurrence of a variable code.

Even in cases where in subroutine allocated once performed a set of actions is justified, since it allows to reduce the size of entire blocks of program code, that is to make the program more understandable and transparent.

Postprocessors generator subprograms are coded the same programming language as the technology command programs. They are called from the program by using the <CALL> statement (it is possible to call a subprogram from itself (recursion), although developer must be careful to avoid endless loops). Start the subprogram code with the <SUB> keyword followed by the subprogram name, to specify the end of the subprogram use the <SUBEND> keyword. The name of the subprogram can be any legal literal excluding already used names, keywords and technology command names. To pass parameters to the subprogram specify the formal parameter list at the header of the sub. Parameters are passed by reference if you cide a variable as an actual parameter, or by value if the actual parameter is an expression.

Subprogram definition syntax:


SUB <SubName>{(<Parameter1, Parameter2,...>)}


< Subprogram code >




Use mathematical functions and numeric expressions, input/output operators, conditional operators, cycles, jump operators, subprogram calls, операторы NC-code forming operators in the subprogram code.

The following is an example of a subprogram that calculates cylindrical linear X coordinate and angular C coordinate for the X and Y plane coordinates.




sub ConvertXYtoXC(XIn, YIn, COut: Real)

  HalfX: Real


  HalfX = XIn * 0.5 ! Radial value of X

  if abs(YIn)>0.000001 then begin

    if YIn>0 then begin

      COut = atn(-HalfX/YIn) + 180

    end else begin

      if XIn>=0 then COut = atn(-HalfX/YIn)

                else COut = atn(-HalfX/YIn) + 360


  end else begin

    if HalfX>=0 then COut = 90

                else COut = 270