# fitrslt.nsc written by S. ISHIZAKA. 1999/04
#
# This script generates a legend box. 
# 
# Please edit the following X, Y, and WIDTH variables as you like.
#
X=5000      # top-left of the legend to be inserted.
Y=5000      # top-left of the legend to be inserted.

filenum=`object file -instance`
fitdata=""
num=0
i=0
while [ $i -lt $filenum ]
do
	if [ `get file:$i -field type` = "fit" ]
	then
		if [	${file::fit} != "" ]
		then 
			num=`iexpr $num+1`
			fitdata=${fitdata}" $i"
		fi
	fi
	i=`iexpr $i+1`
done
if [ $num != 0 ]
then
        DATALIST=${system:0:temp_file}
        echo $num > "$DATALIST"
	for i in $fitdata
	do
		if [ `get file:$i -field type` = "fit" ]
		then
			if [	${file::fit} != "" ]
			then 
                                get file: -field id file >> "$DATALIST"
				get ${file::fit} -field id type poly_dimension user_func %00 %01 %02 %03 %04 %05 %06 %07 %08 %09 >> "$DATALIST"
			fi
		fi
	done
        SCRIPT=${system:0:temp_file}
        wish ${NGRAPHLIB}/fitrslt.tcl -x ${X} -y ${Y} "$DATALIST" "$SCRIPT"
	if [ -f "$SCRIPT" ];
	then
		new shell
		shell::shell "$SCRIPT"
		del shell
	fi
        system:0:unlink_temp_file "$SCRIPT"
        system:0:unlink_temp_file "$DATALIST"
        gra::clear
	gra::draw
	gra::flush
else
	new dialog
	dialog::beep
	dialog::message "No fitting data."
	del dialog
fi
