# File Name:    out_file
# File Purpose: This file is called during the ARM process. It is a c-shell script
#               which is used to manipulate various parts of the output
#               file dependant on the tool parameters and the machine file being
#               used etc.
# Written by:   Ian Ticehurst (Autom8 Ltd.)
# Version 1A.:  Date: 06.11.00 - Initial design and development.
# Version 1B.:  Date: 09.11.00 - Addition of specific routines to match machine file names.
# Version 1C.:  Date: 30.11.00 - Addition of klingonburg and lenz routines to match machine file names.
# Version 1D.:  Date: 05.12.00 - Removal of "gui" alias and "gui" data and response settings (not used).
# Version 1E.:  Date: 16.01.01 - Add check for NT shell version. Also modify gawk calls dependant on version.
# Version 1E.:  Date: 20.02.01 - Ensure that all "gawk" calls are modified to "awk" and that "awk95" is aliased.

############################# Start of notes ###############################
# This file is located in the hooks/ncr directory and forms part of the Auto Rout
# Manager file set. It is a c-shell script which can be configured to provide user
# and site specific modifications to the rout output files dependant on the different
# parameters allocated to each tool (type, size etc.) and also the machine file being
# used. 
# This script is started with one parameter passed to it. This parameters is a file
# which can be sourced ($1). This source file contains details of the tool table and
# the ARM parameters and this is the information that can be used to define any actions
# required. The file contains the following formatted information:-
#
#set ncREGANGLE    = (0 )
#set ncREGMIRROR   = (0 )
#set ncREGXOFF     = (2 )
#set ncREGYOFF     = (1 )
#set ncREGXORIGIN  = (2 )
#set ncREGYORIGIN  = (1 )
#set ncTRNSXORIGIN = (X2 )
#set ncTRNSYORIGIN = (y1 )
#set ncLAYER       = (rout )
#set ncSET         = (nc1 )
#set ncMACHINE     = (schmoll )
#set ncFORMAT      = (Excellon1 )
#set ncZEROES      = (trailing )
#set ncUNITS       = (mm )
#set ncTOOL_UNITS  = (mm )
#set ncNF          = (2.4 )
#set ncHEADER_PATH  = ('D:/genesis/tmp/genesis18765.263' )
#set ncEOF_PATH     = ('D:/genesis/tmp/genesis18766.263' )
#set ncCCW          = ('0' )
#set ncTYPE         = ('hole'                          'hole'                          'chain'                      )
#set ncSTEP         = ('pcb'                           'pcb'                           'pcb'                        )
#set ncCHAIN        = ('0'                             '0'                             '1'                          )
#set ncCOMP         = ('none'                          'none'                          'right'                      )
#set ncPATH         = ('0'                             '0'                             '13.126'                     )
#set ncCOUNT        = ('12'                            '2'                             '0'                          )
#set ncFLAG         = ('0'                             '0'                             '0'                          )
#set ncCW           = ('0'                             '0'                             '0'                          )
#set ncDUP          = ('0'                             '0'                             '0'                          )
#set ncTOOL_NUM     = ('1'                             '2'                             '3'                          )
#set ncCOMP_NUM     = ('1'                             '1'                             '1'                          )
#set ncCOMP_FACT    = ('0'                             '0'                             '94.488'                     )
#set ncCOMP_FACT2   = ('.000'                          '.000'                          '.094'                       )
#set ncTOOL_SIZE    = ('40'                            '200'                           '94.488'                     )
#set ncTOOL_SIZE2   = ('.040'                          '.200'                          '.094'                       )
#set ncTOOL_SPEED   = ('0'                             '0'                             '0'                          )
#set ncTOOL_FEED    = ('0'                             '0'                             '0'                          )
#set ncTOOL_CHANGE  = ('/genesis/tmp/genesis18767.63' '/genesis/tmp/genesis18768.63' '/genesis/tmp/genesis18769.63' )
#set ncSTART_STEP   = ('/genesis/tmp/genesis1876a.63' '/genesis/tmp/genesis1876b.63' '/genesis/tmp/genesis1876c.63' )
#set ncEND_STEP     = ('/genesis/tmp/genesis1876d.63' '/genesis/tmp/genesis1876e.63' '/genesis/tmp/genesis1876f.63' )
#set ncSR_NAME      = ('pcb'       'pcb'       'pcb'       'pcb'       'pcb'       'pcb'       'pcb'       'panel'  )
#set ncSERIAL       = ('1'         '2'         '3'         '4'         '5'         '6'         '7'         '8'      )
#set ncSR_DX        = ('2.444'     '2.444'     '2.444'     '2.444'     '5.885'     '5.885'     '5.885'     '0'      )
#set ncSR_DY        = ('2.650'     '6.232'     '9.814'     '13.396'    '2.650'     '6.232'     '13.396'    '0'      )
#set ncSR_ANGLE     = ('0'         '0'         '0'         '0'         '0'         '0'         '0'         '0'      )
#set ncSR_MIRROR    = ('0'         '0'         '0'         '0'         '0'         '0'         '0'         '0'      )
#
# This file can control the following parts of the output files:-
# 1. The header.                   --- ncHEADER_PATH 
# 2. The end of file.              --- ncEOF_PATH 
# 3. The tool changes.             --- ncTOOL_CHANGE
# 4. The step and repeat start.    --- ncSTART_STEP
# 5. The step and repeat finish.   --- ncEND_STEP
#
# It should be noted that there is no single output file (as with the set_table hook)
# and the output files are defined by the variables list in notes 1-5 above. These
# variables are only set if the machine file is set to use this out_file program for
# that specific section. Thus, by testing each variable it is possible to know if
# the custom output should be used. It will also be noted that some variables apply
# to the complete output file (ncHEADER_PATH for example) and some apply to each of
# the tool entries being passed.
# If the machine file has any of these sections set to yes, then the program must
# provide that section of the output file. Also, if the machine file has any of these
# sections set to no, the program for that section is ignored.
############################# End of notes ################################ 


# Section to set up general parameters and variables.
# ---------------------------------------------------
# Define correct temp. dir. depending on env. vars.
if ($?GENESIS_TMP) then
	set TMP = $GENESIS_TMP
else if ($?GENESIS_DIR) then
	set TMP = $GENESIS_DIR/tmp
else
	set TMP = /genesis/tmp
endif
# Set the INFO alias and the tmp INFO file.
set INFO = $TMP/info
alias DO_INFO 'COM info,out_file=$INFO,write_mode=replace,args=\!:*;source $INFO;rm $INFO'
alias MATH0 'echo "a=((\!:*) + 0.5 );scale=0;a/1" | bc -l'
alias MATH3 'echo "a=((\!:*) + 0.0005 );scale=3;a/1" | bc -l'
alias COMPARE 'echo "if(\!:*) 1;" | bc'

# Detect current operating system.
set CURR_OS = `uname -s`

# Set variable names for parameter file to source and out_file to write to.
set source_script = $1

#cp $1 /wk/ferre/input/xxxxxxxxxx
# Force units to inch.
COM ncrset_units,units=inch

# Source standard parameter file.
source $source_script

# Set myHEADER_PATH for saving export header
# set myHEADER_PATH = `${GENESIS_DIR}/${GENESIS_EDIR}/misc/dbutil path jobs $JOB`
# set myHEADER_PATH = ${myHEADER_PATH}/steps/${STEP}/layers/${ncLAYER}/ncr/${ncSET}
# if (! -d $myHEADER_PATH) mkdir -p $myHEADER_PATH
# set myHEADER_PATH = ${myHEADER_PATH}/header_ken

COM get_user_name
set myNAME = $COMANS

# Header definition section.
# --------------------------
if ($ncHEADER_PATH != "") then
	# Layer type definition
	# --------------------------
	set myTYPE = ""
	if ( $ncLAYER =~ *bo ) then
		set myTYPE = "BO"
	else if ( $ncLAYER =~ *co ) then
		set myTYPE = "CO"
	else if ( $ncLAYER =~ *gb ) then
		set myTYPE = "GB"
	else if ( $ncLAYER =~ *kb ) then
		set myTYPE = "KB"
	else if ($ncLAYER =~ *coup) then
		set myTYPE = "COUP"
	else if ($ncLAYER =~ *x) then
		set myTYPE = "SEPX"
	else if ($ncLAYER =~ *y) then
		set myTYPE = "SEPY"
	endif
	echo "xxxxxxxxxxxxxxxxxxx"
	echo $ncLAYER
	echo $myTYPE

	echo "M48" > $ncHEADER_PATH
	echo "FMAT,1" >> $ncHEADER_PATH
    	echo "METRIC,000.000" >> $ncHEADER_PATH

	set i = 1
	foreach TOOL ($ncTOOL_NUM)
		set size = `echo ${ncTOOL_SIZE2[$i]} | awk -F' ' '{printf("%.2f",$1)}'`
		if ($i < 10) then
			if ( ${ncTYPE[$i]} == 'chain' ) then
				if (${size} == 0.89 || ${size} == 0.90) then
					echo "T0${i}C${size}(W14)" >> $ncHEADER_PATH
				else
					echo "T0${i}C-${size}" >> $ncHEADER_PATH
				endif
			else
				echo "T0${i}C${size}" >> $ncHEADER_PATH
			endif
		else
			if ( ${ncTYPE[$i]} == 'chain' ) then
				if (${size} == 0.89 || ${size} == 0.90) then
					echo "T${i}C${size}(W14)" >> $ncHEADER_PATH
				else
					echo "T${i}C-${size}" >> $ncHEADER_PATH
				endif
			else
				echo "T${i}C${size}" >> $ncHEADER_PATH
			endif		
		endif
		@ i ++
	end
        
	if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
		echo "T06C5.00" >> $ncHEADER_PATH	
	else if ($myTYPE == "BO") then
		echo "T05C3.00" >> $ncHEADER_PATH
		echo "T06C4.60" >> $ncHEADER_PATH
	else if ($myTYPE == "COUP") then
		echo "T50C1.50" >> $ncHEADER_PATH
	else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
		echo "T50C1.50" >> $ncHEADER_PATH
	else
		echo "T50C1.50" >> $ncHEADER_PATH
	endif	        
	
	
	set i = 1
	foreach TOOL ($ncTOOL_NUM)
		if ($ncTYPE[$i] == "chain") then
			set size = `echo ${ncTOOL_SIZE2[$i]} | awk -F' ' '{printf("%.2f",$1)}'`
			set routFlag = `echo ${ncTOOL_SIZE2[$i]} - $size | bc`
			if ( $routFlag == 0.001 ) then 
				set size = `echo $size + 0.04 | bc`
			else if ( $routFlag == 0.002 ) then 
				set size = `echo $size - 0.01 | bc`
			else if ( $routFlag == 0.003 ) then 
				set size = `echo $size - 0.03 | bc`
			endif
			echo "CP,${ncCOMP_NUM[$i]},${size}" >> $ncHEADER_PATH
		endif
		@ i ++
	end
                
    	echo '%' >> $ncHEADER_PATH

	
	

#	# Set ZUT
#	# --------------------------
#	if ($myTYPE == "BO") then
#		set z_value = 0.5
#	else if ($myTYPE == "CO" || $myTYPE == "GB") then
#		set z_value = 8.5
#	else if ($myTYPE == "COUP" || $myTYPE =~ "SEP*" || $myTYPE =~ "RO*") then
#		set z_value = 11.2
#	else
#		set gui_out = /tmp/gui_out.$$
#		set gui_in  = /tmp/gui_in.$$
#		alias GUIOUT 'echo \!:* >> $gui_in'
#		if ($GENESIS_EDIR == "release") then
#			alias DOGUI '${GENESIS_DIR}/${GENESIS_EDIR}/utils/gui < $gui_in > $gui_out; source $gui_out;rm -f $gui_in;rm -f $gui_out'
#		else
#			alias DOGUI '${GENESIS_DIR}/${GENESIS_EDIR}/all/gui < $gui_in > $gui_out; source $gui_out;rm -f $gui_in;rm -f $gui_out'
#		endif		
#		set blue   = 000099
#		set sky    = 006899
#		set red    = 990000
#		set white  = 999988
#		set z = "22.0"
#		set rout_type = ""		
#		Loop_InputZ:
#		GUIOUT WIN 900 200
#		GUIOUT FG $white
#		GUIOUT BG $sky
#		GUIOUT LABEL "     "
#		GUIOUT LABEL "Select Routing Type For This Layer ${ncLAYER}"
#		GUIOUT LABEL "     "
#		GUIOUT BG $blue
#		GUIOUT LABEL "     "
#		GUIOUT RADIO rout_type "Rout_Type:" h 1 $red
#		GUIOUT 'ROUT/COUP/SEP(z=11.2)'
#		GUIOUT 'CO/GB(z=8.5)'
#		GUIOUT 'BO(z=0.5)'
#		GUIOUT 'Other(z=?)'
#		GUIOUT END
#		GUIOUT LABEL "     "
#		GUIOUT FORM rout_type 4
#		GUIOUT TEXT z "Z_Value:"
#		GUIOUT DTEXT z $z
#		GUIOUT ENDFORM
#		GUIOUT LABEL "     "
#		GUIOUT BG $sky
#		GUIOUT LABEL "     "
#		GUIOUT END
#		DOGUI
#		
#		if ($rout_type == 1) then
#			set z = '11.2'
#		else if ($rout_type == 2) then
#			set z = '8.5'
#		else if ($rout_type == 3) then
#			set z = '0.5'
#		else if ($rout_type == 4) then
#			set z = `echo $z | sed 's/ \{1,\}//g'`
#		    if ($z == "") then
#           	GUIOUT WIN 900 200
#		    	GUIOUT FG $red
#				GUIOUT BG $blue
#		      	GUIOUT LABEL "     "
#		      	GUIOUT LABEL "     "
#		      	GUIOUT LABEL "You don't input a z_value, please input again\!"
#		      	GUIOUT LABEL "     "
#		      	GUIOUT LABEL "     "
#		      	GUIOUT FG $white
#		      	GUIOUT END
#		        DOGUI
#		        goto Loop_InputZ
#			else
#		        set q = 1
#                while ($q < `echo $z | wc -c`)
#                	if (`echo $z | cut -c${q}` !~ [0-9,.]) then
#                    	GUIOUT WIN 900 200
#		        		GUIOUT FG $red
#						GUIOUT BG $blue
#						GUIOUT LABEL "     "
#						GUIOUT LABEL "     "
#						GUIOUT LABEL "$z is not a valid z_value, please input again\!"
#						GUIOUT LABEL "     "
#						GUIOUT LABEL "     "
#						GUIOUT FG $white
#						GUIOUT END
#						DOGUI
#						goto Loop_InputZ
#					endif
#					@ q++
#				end
#			endif
#		endif
#		set z_value = $z
#	endif
#	
#	echo "Z${z_value}" >> $ncHEADER_PATH
	#########
	if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
		echo "Z8.5" >> $ncHEADER_PATH	
	else if ($myTYPE == "BO") then
		echo "Z0.5" >> $ncHEADER_PATH	
	else if ($myTYPE == "COUP") then
		echo 'M47,\P:M00' >> $ncHEADER_PATH
		echo "Z11.2" >> $ncHEADER_PATH
	else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
		echo 'M47,\P:M00' >> $ncHEADER_PATH
		echo "Z11.2" >> $ncHEADER_PATH
	else
		echo 'M47,\P:M00' >> $ncHEADER_PATH
		echo "Z11.2" >> $ncHEADER_PATH
	endif	        
	


	######calculate maxheight
	set i = 1
	set maxHeight = "21.0"
	while ($i <= $#ncTOOL_NUM) 
		if ($ncTYPE[$i] == "chain") then
			if ( `COMPARE ${ncTOOL_SIZE2[$i]} < 1.0`  || `COMPARE ${ncTOOL_SIZE2[$i]} == 1.0` ) then
				set maxHeight = "18.5"
				break
			endif
		endif
		@ i ++
	end

	#########
	if ($ncMACHINE == '18') then
		echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
		echo "G93X-24.Y33." >> $ncHEADER_PATH
		echo "M71" >> $ncHEADER_PATH
		echo "T50" >> $ncHEADER_PATH
		echo "X-439.322Y216.955" >> $ncHEADER_PATH
		echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
	else if ($ncMACHINE == '20') then
		echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
		echo "G93X0Y33." >> $ncHEADER_PATH
		echo "M71" >> $ncHEADER_PATH
		echo "T50" >> $ncHEADER_PATH
		echo "X-490.122Y216.955" >> $ncHEADER_PATH
		echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
	else if ($ncMACHINE == '21') then
		echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
		echo "G93X12.Y33." >> $ncHEADER_PATH
		echo "M71" >> $ncHEADER_PATH
		echo "T50" >> $ncHEADER_PATH
		echo "X-514.506Y217.02" >> $ncHEADER_PATH
		echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
	else if ($ncMACHINE == 'n18x24') then
		if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
			echo "T06" >> $ncHEADER_PATH
			echo "X-304.52Y-59.227" >> $ncHEADER_PATH
			echo "X-229.52Y-59.227" >> $ncHEADER_PATH
			echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "BO") then
			echo "T05" >> $ncHEADER_PATH
			echo "X-225.0Y556.0" >> $ncHEADER_PATH
			echo "X-275.0" >> $ncHEADER_PATH
			echo "Y-96.0" >> $ncHEADER_PATH
			echo "X-225.0" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X-304.52Y-59.227" >> $ncHEADER_PATH
			echo "X-229.52Y-59.227" >> $ncHEADER_PATH
			echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "COUP") then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X444.402Y292.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X444.402Y286.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		else
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X12.798Y316.802" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		endif	
	else if ($ncMACHINE == 'n18.3x24.25') then
		echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
		echo "G93X-476.120Y-66.847" >> $ncHEADER_PATH
		echo "M71" >> $ncHEADER_PATH
		echo "T50" >> $ncHEADER_PATH
		echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
	else if ($ncMACHINE == 'n20x22.7') then
		echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
		echo "G93X-502.920Y-50.337" >> $ncHEADER_PATH
		echo "M71" >> $ncHEADER_PATH
		echo "T50" >> $ncHEADER_PATH
		echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
	else if ($ncMACHINE == 'n20x24') then
		if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
			echo "G93X-502.920Y-66.847" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X197.002Y7.620" >> $ncHEADER_PATH
			echo "X272.001Y7.620" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "BO") then
			echo "T05" >> $ncHEADER_PATH
			echo "X-225.0Y556.0" >> $ncHEADER_PATH
			echo "X-275.0" >> $ncHEADER_PATH
			echo "Y-96.0" >> $ncHEADER_PATH
			echo "X-225.0" >> $ncHEADER_PATH
			echo "G93X-502.920Y-66.847" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X197.002Y7.620" >> $ncHEADER_PATH
			echo "X272.001Y7.620" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "COUP") then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-502.920Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X498.702Y292.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-502.920Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X498.702Y286.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		else
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-502.920Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X9.298Y314.801" >> $ncHEADER_PATH	
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		endif	
	else if ($ncMACHINE == 'n21x24') then
		if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
			echo "T06" >> $ncHEADER_PATH
			echo "X-306.112Y-59.227" >> $ncHEADER_PATH
			echo "X-231.112Y-59.227" >> $ncHEADER_PATH
			echo "G93X-515.304Y-66.847" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "BO") then
			echo "T05" >> $ncHEADER_PATH
			echo "X-225.0Y556.0" >> $ncHEADER_PATH
			echo "X-275.0" >> $ncHEADER_PATH
			echo "Y-96.0" >> $ncHEADER_PATH
			echo "X-225.0" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X-306.112Y-59.227" >> $ncHEADER_PATH
			echo "X-231.112Y-59.227" >> $ncHEADER_PATH
			echo "G93X-515.304Y-66.847" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "COUP") then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-515.304Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X519.586Y292.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-515.304Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X519.586Y286.804" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		else
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-515.304Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X12.798Y316.802" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		endif
	else if ($ncMACHINE == 'n21.3x24.25') then
		if ($myTYPE == "CO" || $myTYPE == "GB" || $myTYPE == "KB") then
			echo "G93X-518.000Y-66.847" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X213.512Y7.620" >> $ncHEADER_PATH
			echo "X288.511Y7.620" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "BO") then
			echo "T05" >> $ncHEADER_PATH
			echo "X-225.0Y556.0" >> $ncHEADER_PATH
			echo "X-275.0" >> $ncHEADER_PATH
			echo "Y-96.0" >> $ncHEADER_PATH
			echo "X-225.0" >> $ncHEADER_PATH
			echo "G93X-518.000Y-66.847" >> $ncHEADER_PATH
			echo "T06" >> $ncHEADER_PATH
			echo "X213.512Y7.620" >> $ncHEADER_PATH
			echo "X288.511Y7.620" >> $ncHEADER_PATH
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
		else if ($myTYPE == "COUP") then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-518.000Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X528.222Y295.979" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		else if ($myTYPE == "SEPX" || $myTYPE == "SEPY" ) then
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-518.000Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X528.222Y289.979" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH
		else
			echo "M100,ZOT-MaxHeight ${maxHeight}" >> $ncHEADER_PATH
			echo "G93X-518.000Y-66.847" >> $ncHEADER_PATH
			echo "M71" >> $ncHEADER_PATH
			echo "T50" >> $ncHEADER_PATH
			echo "X12.798Y319.976" >> $ncHEADER_PATH
			echo "M47,CHECK\!\!\!\!" >> $ncHEADER_PATH	
		endif	
	endif
endif

# End of file (EOF) definition section.
# -------------------------------------
if ($ncEOF_PATH != "") then
    echo "M83,ZOT0.0" > $ncEOF_PATH
    echo "M30" >> $ncEOF_PATH
endif

# Tool change definition section.
# -------------------------------
set i = 1
while ($i <= $#ncTOOL_NUM) 
	if ($ncTOOL_CHANGE[$i] != "") then
		if ($i < 10) then
			set TL_STR = `echo "T0"`
		else
			set TL_STR = `echo "T"`
		endif
		if ($ncTYPE[$i] == "chain") then
			if ($ncCOMP_NUM[$i] < 10) then
				echo "${TL_STR}${i}0${ncCOMP_NUM[$i]}" > $ncTOOL_CHANGE[$i]
			else
				echo "${TL_STR}${i}${ncCOMP_NUM[$i]}" > $ncTOOL_CHANGE[$i]
			endif
		else
			echo "${TL_STR}${i}" > $ncTOOL_CHANGE[$i]
		endif
	endif
	@ i ++
end

# Step and repeat start definition section.
# ----------------------------------------------
set i = 1
while ($i <= $#ncSTART_STEP) 
	if ($ncSTART_STEP[$i] != "") then
		echo "M25" > $ncSTART_STEP[$i]
	endif
   	@ i ++
end

# Step and repeat end definition section.
# --------------------------------------------
set i = 1
while ($i <= $#ncEND_STEP) 
	if ($ncEND_STEP[$i] != "") then
		echo "M26" > $ncEND_STEP[$i]
		echo "M27" >> $ncEND_STEP[$i]
	endif
	@ i ++
end




exit