# File Name:    set_machine
# File Purpose: This file is called during the ARM process. It is a c-shell
#               script which is used to manipulate the placement of the panel
#               on the rout machine.
# Written by:   Ian Ticehurst (Autom8 Ltd.)
# Version 1A.:  Date: 27.10.00 - Initial design and development.
# Version 1B.:  Date: 30.11.00 - Addition of X axis central placement for named machines.
# Version 1C.:  Date: 05.12.00 - Removal of "gui" alias and "gui" data and response settings (not used).
# Version 1D.:  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 perform changes
# to the placement of the panel on the rout machine table (and thus the rout output files)
# dependant on the panel size and the settings which are applied when the machine file is
# read and used.
# This script is started with two parameters passed to it. These parameters are a file
# which can be sourced ($1), and the name of an output file which the system will read
# when this program exits ($2). The source file contains details of the panel size and
# its placement on the rout table and this is the information that can be used to define
# any modifications to these parameters. The file contains the following formatted
# information:-
#
#set ncLAYER     = (01-rout )
#set ncSET       = (1       )
#set ncMACHINE   = (m1      )
#set ncTHICKNESS = (0       )
#set ncPNLWIDTH  = (20      )
#set ncPNLHEIGHT = (32      )
#set ncANGLE     = (0       )
#set ncMIRROR    = (0       )
#set ncXOFF      = (2.5     )
#set ncYOFF      = (0.75    )
#set ncXORIGIN   = (10      )
#set ncYORIGIN   = (12      )
#
# The typical method of using this file is to work through the array information and
# make calculations as to panel placement modifications based on this information. It
# may be that no changes are required. The way that changes are made is to define an
# output file (the file name provided as $2) which should contain a single line of
# parameters. This output line must contain the following values:-
#
#    1. the placement angle  (0, 90, 180, 270)
#    2. if mirroring is required (0 = no, 1 = yes)
#    3. offset in X axis
#    4. offset in Y axis
#    5. origin in X axis
#    6. origin in Y axis
#
# This example program has been written as an example only and only makes any changes
# when the following machine files are selected:- schmoll, klingonburg (microtonic 1 and 7),
# and schmoll.
# In these cases a simple calculation is made to place the panel central in the X axis.
# (Note that the machine X axis size is read directly from the machine file. It is expected
# that the only occurrence of "xsize" on a non-comment line will be the machine X axis).
############################## End of notes ################################ 

# 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

# Section to set up general parameters and variables.
# ---------------------------------------------------
# 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'

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

# If current operating system is NT, set alias to call awk95 as "awk".
if ($CURR_OS == "WINDOWS_NT") then
	alias awk '$GENESIS_DIR/e${GENESIS_VER}/nt/bin/awk95'
endif

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

# Source standard parameter file.
source $source_script

if ($ncMACHINE == "schmoll" || $ncMACHINE == "lenz_35" || $ncMACHINE == "klingonburg_microtronic1" || $ncMACHINE == "klingonburg_microtronic7") then
	# Read the X axis size from the machine file and divide by 2.
	set MACH_X = `grep -v "#" $GENESIS_DIR/sys/hooks/ncr/config/machines/$ncMACHINE | grep "xsize" | awk -F'=' '{print ($2 / 2)}'`
	# Calculate X axis centre positioning (half X axis - half panel).
	set HALF_PNX = `echo "$ncPNLWIDTH / 2" | bc`
	set XOFF = `echo "$MACH_X - $HALF_PNX" | bc`

	# Create output file with required parameter values.
	echo "$ncANGLE $ncMIRROR $XOFF $ncYOFF $XOFF $ncYORIGIN" >> $out_file

else
	# Create output file with required parameter values.
	echo "$ncANGLE $ncMIRROR $ncXOFF $ncYOFF $ncXORIGIN $ncYORIGIN" >> $out_file
endif

abort:

exit
