proc set_coordinate_system { name } {
	if { $name == "" || $name == "global" } {
		command "unset coordinate_system"
	} else {
		command "set coordinate_system $name"
	}
}
proc list_coordinate_systems { } {
	global all_lines
	command "list_coordinate_systems"
	set csystems ""
	foreach line $all_lines {
# Do this first
		append csystems "$line "
	}
	return $csystems
}
proc csystem_select_point { how var_name { base_var_name "" } } {
	global last_line button_instructions 
	global [lindex [split $var_name (] 0]
	global $base_var_name

	if { $base_var_name != "" } {
	    set base_var [ set $base_var_name ]
	    if { $base_var == "" } {
		user_error "the variable $base_var_name must be set first"
		return
	    }
	} else {
		set base_var ""
	}
	if { $how == "graphic" } {
	    banner \
        "Please select the transform about point $button_instructions"
            command graphics_loc
            banner ""
	    if { $base_var == "" } {
            	set $var_name $last_line
	    } else {
# subtract coordinates
		if { [ llength $base_var ] == 3 } {
		    set del ""
		    foreach i { 0 1 2 } {
			set x1 [ lindex $last_line $i ]
			set x2 [ lindex $base_var $i ]
			set d [ expr $x1 - $x2 ]
			mess " $x1 - $x2 -> $d \n"
			append del "$d "
		    }
		    set $var_name $del
		} else {
		    set $var_name " { $last_line } - $base_var"
		}
	    }
	} elseif { $how == "pre_point" } {
	    set p1 [ select_point "Please select the point" ]
	    puts "setting $var_name"
            if { $p1 == "" } return
	    if { $base_var != "" } {
	    	set $var_name "$p1 - $base_var"
	    } else {
		set $var_name $p1
	    }
	} else {
	    error "illegal value how == $how"
	}
}
proc create_coordinate_system { type name center xaxis yaxis zaxis } {
	if { $name == "" || $name == "global" } {
	    user_error "illegal coordinate system name $name"
	    return
	}
	global tetin_save_needed
        set tetin_save_needed 1
	set cmd "define_coordinate_system type $type name $name \
		origin $center"
	if { $xaxis != "" } { append cmd " xaxis $xaxis" }
	if { $yaxis != "" } { append cmd " yaxis $yaxis" }
	if { $zaxis != "" } { append cmd " zaxis $zaxis" }
	command $cmd
}
proc delete_coordinate_system { name } {
	global tetin_save_needed
	set tetin_save_needed 1
	command "delete_coordinate_system $name"
}
proc get_coordinate_system { name } {
	global last_line
	command "print_coordinate_system $name"
	if { [ lindex $last_line 0 ] != "define_coordinate_system" } {
		return ""
	} else {
		return $last_line
	}
}

set button_instructions \
	"left button = select; middle = accept, right = back up / cancel."
