# Ngraph initialization script
new menu
system:0:login_shell=menu:0:menu
#
if [ -f "${NGRAPHHOME}/.Ngraph.ngp" ]; then
        . "${NGRAPHHOME}/.Ngraph.ngp"
elif [ -f "${NGRAPHLIB}/.Ngraph.ngp" ]; then
        . "${NGRAPHLIB}/.Ngraph.ngp"
fi
#
XCOLUMN=1
YCOLUMN=2
PLOTTYPE=mark
MARKTYPE=0
MARKSIZE=200
LINESTYLE=
LINEWIDTH=40
COLORR=0
COLORG=0
COLORB=0
COLORR2=255
COLORG2=255
COLORB2=255
HEADSKIP=0
READSTEP=1
FINALLINE=-1
AVERAGEX=0
AVERAGEY=0
MATHX=
MATHY=
LOADSETTINGS=0
#
while [ "$1" ]
do
	case $1 in
	*.prm|*.PRM|*.ngp|*.NGP)
		system:0:login_shell="menu:0:menu $1"
	;;
	*.gra|*.GRA)
		for drawable in `derive -instance draw`
		do
			del $drawable:0-!
		done
		new merge file:"$1"
	;;
	-x)
		shift
		XCOLUMN=$1
	;;
	-y)
		shift
		YCOLUMN=$1
	;;
	-d)
		shift
		PLOTTYPE=$1
	;;
	-m)
		shift
		MARKTYPE=$1
	;;
	-o)
		shift
		MARKSIZE=$1
	;;
	-l)
		shift
		LINESTYLE=$1
	;;
	-w)
		shift
		LINEWIDTH=$1
	;;
	-c)
		shift
		COLORR=$1
		shift
		COLORG=$1
		shift
		COLORB=$1
	;;
	-C)
		shift
		COLORR2=$1
		shift
		COLORG2=$1
		shift
		COLORB2=$1
	;;
	-s)
		shift
		HEADSKIP=$1
	;;
	-r)
		shift
		READSTEP=$1
	;;
	-f)
		shift
		FINALLINE=$1
	;;
	-vx)
		shift
		AVERAGEX=$1
	;;
	-vy)
		shift
		AVERAGEY=$1
	;;
	-mx)
		shift
		MATHX=$1
	;;
	-my)
		shift
		MATHY=$1
	;;
	-ex)
		shift
		axis:0:type=$1
	;;
	-ey)
		shift
		axis:1:type=$1
	;;
	-zx)
		shift
		axis:0:min=$1
		shift
		axis:0:max=$1
		shift
		axis:0:inc=$1
	;;
	-zy)
		shift
		axis:1:min=$1
		shift
		axis:1:max=$1
		shift
		axis:1:inc=$1
	;;
	-g)
		LOADSETTINGS=1
	;;
	-h|-help)
		echo ${system::name} version ${system::version}
		echo ${system::copyright}
		echo 'Usage: ngraph [ options ] [ data | NGP | PRM ]'
		echo 'valid options:'
		echo ' -x column         data column (abscissas)'
		echo ' -y column         data column (ordinates)'
		echo ' -d type           plot type'
		echo ' -m type           mark type'
		echo ' -o size           mark size'
		echo ' -l style          line style'
		echo ' -w width          line width'
		echo ' -c R G B          plot color'
		echo ' -C R G B          plot color (2nd)'
		echo ' -s line           head skip'
		echo ' -r step           read step'
		echo ' -f line           finale line'
		echo ' -vx num           neighbour average (abscissas)'
		echo ' -vy num           neighbour average (ordinates)'
		echo ' -mx math          transformation (abscissas)'
		echo ' -my math          transformation (ordinates)'
		echo ' -ex type          scale type (abscissas)'
		echo ' -ey type          scale type (ordinates)'
		echo ' -zx min max inc   scale type (abscissas)'
		echo ' -zy min max inc   scale type (ordinates)'
		echo ' -g                load settings from data file'
		del system:0
	;;
	*)
		new file file:$1
		file::x=$XCOLUMN
		file::y=$YCOLUMN
		file::type=$PLOTTYPE
		file::mark_type=$MARKTYPE
		file::mark_size=$MARKSIZE
		file::line_style=$LINESTYLE
		file::line_width=$LINEWIDTH
		file::R=$COLORR
		file::G=$COLORG
		file::B=$COLORB
		file::R2=$COLORR2
		file::G2=$COLORG2
		file::B2=$COLORB2
		file::head_skip=$HEADSKIP
		file::read_step=$READSTEP
		file::final_line=$FINALLINE
		file::smooth_x=$AVERAGEX
		file::smooth_y=$AVERAGEY
		file::math_x=$MATHX
		file::math_y=$MATHY
		file::axis_x=axis:0
		file::axis_y=axis:1
		if [ $LOADSETTINGS = 1 ]; then
			file::load_settings
		fi
	esac
	shift
done
