source /home/ventana/source/submenu/analog_input_list2.tcl
source /home/ventana/source/submenu/digital_input_list2.tcl
source /home/ventana/source/submenu/serial_input_list2.tcl
source /home/ventana/source/submenu/analog_output_list2.tcl


#-------------------------------
# Initialize and set variable
#-------------------------------
set pilot2 .auto_pilot_popup2


proc auto_pilot_popup2 { } {

    global pilot2 depth_trans_input dvl_input

    if [winfo exists $pilot2] {destroy $pilot2}

    global env
    set env(DISPLAY) :0.1
    toplevel $pilot2 -width 28c -height 18c
    wm title $pilot2 "Auto Pilot"

    label $pilot2.lab34 \
        -foreground #0000da -relief ridge -text {Auto Pilot} -width 553
    frame $pilot2.input_surface \
        -borderwidth 2 -height 235 -relief groove -width 330
    label $pilot2.input_surface.lab37 \
        -text Foreaft
    label $pilot2.input_surface.lab39 \
        -height 0 -text Turns
    label $pilot2.input_surface.lab41 \
        -text AutoHead
    label $pilot2.input_surface.lab45 \
        -text AutoDepth
    label $pilot2.input_surface.lab46 \
        -text AutoAltitude
    label $pilot2.input_surface.lab47 \
        -text AutoCruise
    label $pilot2.input_surface.lab48 \
        -text {Depth Jog Up}
    label $pilot2.input_surface.lab49 \
        -text {Depth Jog Down}
    entry $pilot2.input_surface.foreaft \
        -background white -textvariable foreaft_input -state disabled
    entry $pilot2.input_surface.turns \
        -background white -textvariable turns_input -state disabled
    entry $pilot2.input_surface.auto_head \
        -background white -textvariable auto_head_input -state disabled
    entry $pilot2.input_surface.auto_depth \
        -background white -textvariable auto_depth_input  -state disabled
    entry $pilot2.input_surface.auto_altitude \
        -background white -textvariable auto_altitude_input -state disabled
    entry $pilot2.input_surface.auto_cruise \
        -background white -textvariable auto_cruise_input -state disabled
    entry $pilot2.input_surface.depth_jogup \
        -background white -textvariable depth_jog_up_input  -state disabled
    entry $pilot2.input_surface.depth_jogdown \
        -background white -textvariable depth_jog_down_input -state disabled
    button $pilot2.input_surface.but87 \
        -command { surf_analog_input_list2 .auto_pilot_popup2.input_surface.foreaft } -height 21 -text v -width 27
    button $pilot2.input_surface.but88 \
        -command { surf_analog_input_list2 .auto_pilot_popup2.input_surface.turns } -height 21 -text v -width 27
    button $pilot2.input_surface.but89 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.auto_head } -height 21 -text v -width 27
    button $pilot2.input_surface.but90 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.auto_depth } -height 21 -text v -width 27
    button $pilot2.input_surface.but91 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.auto_altitude } -height 21 -text v -width 27
    button $pilot2.input_surface.but92 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.auto_cruise } -height 21 -text v -width 27
    button $pilot2.input_surface.but93 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.depth_jogup } -height 21 -text v -width 27
    button $pilot2.input_surface.but94 \
        -command { digital_input_list2 .auto_pilot_popup2.input_surface.depth_jogdown } -height 21 -text v -width 27
    frame $pilot2.output \
        -borderwidth 2 -height 235 -relief groove -width 215
    label $pilot2.output.lab74 \
        -text {Port Thruster}
    label $pilot2.output.lab75 \
        -text {STBD Thruster}
    label $pilot2.output.lab76 \
        -text {Vertical Thruster}
    label $pilot2.output.lab77 \
        -text {Lateral Thruster}
    entry $pilot2.output.port_thrust \
        -background white -textvariable port_thrust_output -state disabled
    entry $pilot2.output.stbd_thrust \
        -background white -textvariable stbd_thrust_output -state disabled
    entry $pilot2.output.vert_thrust \
        -background white -textvariable vert_thrust_output  -state disabled
    entry $pilot2.output.lat_thrust \
        -background white -textvariable lat_thrust_output -state disabled
    button $pilot2.output.but104 \
        -command { analog_output_list2 .auto_pilot_popup2.output.port_thrust } -height 21 -text v -width 27
    button $pilot2.output.but105 \
        -command { analog_output_list2 .auto_pilot_popup2.output.stbd_thrust } -height 21 -text v -width 27
    button $pilot2.output.but106 \
        -command { analog_output_list2 .auto_pilot_popup2.output.vert_thrust } -height 21 -text v -width 27
    button $pilot2.output.but107 \
        -command { analog_output_list2 .auto_pilot_popup2.output.lat_thrust } -height 21 -text v -width 27

    #-------------------------- PID ------------------------------

    frame $pilot2.pid \
        -borderwidth 2 -relief groove

    # AUTOHEAD
    frame $pilot2.pid.autohead \
        -borderwidth 2 -height 95 -width 225
    label $pilot2.pid.autohead.lab35 \
        -text P
    label $pilot2.pid.autohead.lab36 \
        -text I
    label $pilot2.pid.autohead.lab37 \
        -text D
    entry $pilot2.pid.autohead.p \
        -background white -textvariable head_p
    entry $pilot2.pid.autohead.i \
        -background white -textvariable head_i
    entry $pilot2.pid.autohead.d \
        -background white -textvariable head_d
    label $pilot2.pid.autohead.lab41 \
        -text AutoHead

    # AUTODEPTH
    frame $pilot2.pid.autodepth \
        -borderwidth 2 -height 95 -width 225
    label $pilot2.pid.autodepth.lab35 \
        -text P
    label $pilot2.pid.autodepth.lab36 \
        -text I
    label $pilot2.pid.autodepth.lab37 \
        -text D
    entry $pilot2.pid.autodepth.p \
        -background white -textvariable depth_p
    entry $pilot2.pid.autodepth.i \
        -background white -textvariable depth_i
    entry $pilot2.pid.autodepth.d \
        -background white -textvariable depth_d
    label $pilot2.pid.autodepth.lab41 \
        -text AutoDepth

    # AUTOALTITUDE
    frame $pilot2.pid.autoaltitude \
        -borderwidth 2 -height 95 -width 225
    label $pilot2.pid.autoaltitude.lab35 \
        -text P
    label $pilot2.pid.autoaltitude.lab36 \
        -text I
    label $pilot2.pid.autoaltitude.lab37 \
        -text D
    entry $pilot2.pid.autoaltitude.p \
        -background white -textvariable altitude_p
    entry $pilot2.pid.autoaltitude.i \
        -background white -textvariable altitude_i
    entry $pilot2.pid.autoaltitude.d \
        -background white -textvariable altitude_d
    label $pilot2.pid.autoaltitude.lab41 \
        -text AutoAltitude -width 78

    # AUTOCRUISE
    frame $pilot2.pid.autocruise \
        -borderwidth 2 -height 95 -width 225
    label $pilot2.pid.autocruise.lab35 \
        -text P
    label $pilot2.pid.autocruise.lab36 \
        -text I
    label $pilot2.pid.autocruise.lab37 \
        -text D
    entry $pilot2.pid.autocruise.p \
        -background white -textvariable cruise_p
    entry $pilot2.pid.autocruise.i \
        -background white -textvariable cruise_i
    entry $pilot2.pid.autocruise.d \
        -background white -textvariable cruise_d
    label $pilot2.pid.autocruise.lab41 \
        -text AutoCruise -width 73


    # --------------- INPUT, OUTPUT, PID --------------------
    label $pilot2.lab58 \
        -height 0 -relief groove -text INPUT -width 329
    label $pilot2.lab60 \
        -relief groove -text OUTPUT -width 213
    label $pilot2.lab61 \
        -height 0 -relief groove -text PID -width 329



    label $pilot2.lab59 \
        -foreground #009000 -height 0 -text Surface

    frame $pilot2.subsea_input \
        -borderwidth 2 -height 165 -relief groove -width 330
    label $pilot2.subsea_input.lab63 \
        -text {Primary Heading}
    label $pilot2.subsea_input.sec_head_lab \
        -text {Secondary Heading}
    label $pilot2.subsea_input.lab64 \
        -text {Depth Transducer}
    label $pilot2.subsea_input.lab65 \
        -text {Altitude}
    label $pilot2.subsea_input.dvl_label \
        -text {DVL Input}

    entry $pilot2.subsea_input.head_source \
        -background white -textvariable head_source_input -state disabled
    button $pilot2.subsea_input.but95 \
        -command { head_input_list2 .auto_pilot_popup2.subsea_input.head_source } -height 21 -text v -width 27

    entry $pilot2.subsea_input.sec_head_source \
        -background white -textvariable sec_head_source_input -state disabled
    button $pilot2.subsea_input.but96 \
        -command { head_input_list2 .auto_pilot_popup2.subsea_input.sec_head_source } -height 21 -text v -width 27


    entry $pilot2.subsea_input.depth_trans \
        -background white -textvariable depth_trans_input -state disabled

    entry $pilot2.subsea_input.alti1 \
        -background white -textvariable altimeter_input -state disabled
    button $pilot2.subsea_input.alti_but -text v  \
        -command {altitude_list2 $pilot2.subsea_input.alti1}

    entry $pilot2.subsea_input.dvl \
        -background white -textvariable dvl_input -state disabled
    label $pilot2.lab62 \
        -foreground #009000 -text Subsea
    button $pilot2.but108  -text Ok \
        -command {send_down_auto_pilot2; destroy $pilot2}
    button $pilot2.but109 \
        -command {destroy $pilot2} -text Close



    ###################
    # SETTING GEOMETRY
    ###################
    place $pilot2.lab34 \
        -x 30 -y 10 -width 770 -height 20 -anchor nw -bordermode ignore
    place $pilot2.input_surface \
        -x 25 -y 80 -width 330 -height 235 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab37 \
        -x 70 -y 20 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab39 \
        -x 80 -y 45 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab41 \
        -x 55 -y 70 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab45 \
        -x 50 -y 95 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab46 \
        -x 40 -y 120 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab47 \
        -x 45 -y 145 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab48 \
        -x 30 -y 170 -anchor nw -bordermode ignore
    place $pilot2.input_surface.lab49 \
        -x 15 -y 195 -anchor nw -bordermode ignore
    place $pilot2.input_surface.foreaft \
        -x 130 -y 20 -anchor nw -bordermode ignore
    place $pilot2.input_surface.turns \
        -x 130 -y 45 -anchor nw -bordermode ignore
    place $pilot2.input_surface.auto_head \
        -x 130 -y 70 -anchor nw -bordermode ignore
    place $pilot2.input_surface.auto_depth \
        -x 130 -y 95 -anchor nw -bordermode ignore
    place $pilot2.input_surface.auto_altitude \
        -x 130 -y 120 -anchor nw -bordermode ignore
    place $pilot2.input_surface.auto_cruise \
        -x 130 -y 145 -anchor nw -bordermode ignore
    place $pilot2.input_surface.depth_jogup \
        -x 130 -y 170 -anchor nw -bordermode ignore
    place $pilot2.input_surface.depth_jogdown \
        -x 130 -y 195 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but87 \
        -x 285 -y 20 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but88 \
        -x 285 -y 45 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but89 \
        -x 285 -y 71 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but90 \
        -x 285 -y 97 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but91 \
        -x 285 -y 120 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but92 \
        -x 285 -y 145 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but93 \
        -x 285 -y 171 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.input_surface.but94 \
        -x 285 -y 195 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.output \
        -x 590 -y 80 -width 215 -height 235 -anchor nw -bordermode ignore
    place $pilot2.output.lab74 \
        -x 15 -y 20 -anchor nw -bordermode ignore
    place $pilot2.output.lab75 \
        -x 15 -y 70 -anchor nw -bordermode ignore
    place $pilot2.output.lab76 \
        -x 15 -y 120 -anchor nw -bordermode ignore
    place $pilot2.output.lab77 \
        -x 15 -y 170 -anchor nw -bordermode ignore
    place $pilot2.output.port_thrust \
        -x 15 -y 40 -anchor nw -bordermode ignore
    place $pilot2.output.stbd_thrust \
        -x 15 -y 90 -anchor nw -bordermode ignore
    place $pilot2.output.vert_thrust \
        -x 15 -y 140 -anchor nw -bordermode ignore
    place $pilot2.output.lat_thrust \
        -x 15 -y 190 -anchor nw -bordermode ignore
    place $pilot2.output.but104 \
        -x 170 -y 40 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.output.but105 \
        -x 170 -y 89 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.output.but106 \
        -x 170 -y 140 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.output.but107 \
        -x 170 -y 189 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.lab59 \
        -x 25 -y 60 -anchor nw -bordermode ignore


    #---------------------- INPUT, OUTPUT, PID position  --------------------------
    place $pilot2.lab58 \
        -x 25 -y 40 -width 329 -height 20 -anchor nw -bordermode ignore
    # OUTPUT label
    place $pilot2.lab60 \
        -x 590 -y 40 -width 213 -height 20 -anchor nw -bordermode ignore
    # PID label
    place $pilot2.lab61 \
        -x 365 -y 40 -width 213 -height 20 -anchor nw -bordermode ignore

    #------------------------- PID ---------------------------

    place $pilot2.pid \
        -x 365 -y 80 -width 215 -height 435 -anchor nw -bordermode ignore

    # AUTOHEAD
    place $pilot2.pid.autohead \
        -x 2 -y 5 -width 200 -height 95 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.lab35 \
        -x 25 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.lab36 \
        -x 25 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.lab37 \
        -x 25 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.p \
        -x 45 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.i \
        -x 45 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.d \
        -x 45 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autohead.lab41 \
        -x 25 -y 5 -width 63 -height 20 -anchor nw -bordermode ignore

    # AUTODEPTH
    place $pilot2.pid.autodepth \
        -x 2 -y 100 -width 200 -height 95 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.lab35 \
        -x 25 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.lab36 \
        -x 25 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.lab37 \
        -x 25 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.p \
        -x 45 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.i \
        -x 45 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.d \
        -x 45 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autodepth.lab41 \
        -x 25 -y 5 -width 63 -height 20 -anchor nw -bordermode ignore

    # AUTOALTITUDE
    place $pilot2.pid.autoaltitude \
        -x 2 -y 210 -width 200 -height 95 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.lab35 \
        -x 25 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.lab36 \
        -x 25 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.lab37 \
        -x 25 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.p \
        -x 45 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.i \
        -x 45 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.d \
        -x 45 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autoaltitude.lab41 \
        -x 25 -y 5 -width 78 -height 20 -anchor nw -bordermode ignore

    # AUTOCRUISE
    place $pilot2.pid.autocruise \
        -x 2 -y 320 -width 200 -height 95 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.lab35 \
        -x 25 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.lab36 \
        -x 25 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.lab37 \
        -x 25 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.p \
        -x 45 -y 25 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.i \
        -x 45 -y 45 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.d \
        -x 45 -y 65 -anchor nw -bordermode ignore
    place $pilot2.pid.autocruise.lab41 \
        -x 25 -y 5 -width 73 -height 20 -anchor nw -bordermode ignore









    #------------------------------------------------------------------------

    place $pilot2.subsea_input \
        -x 25 -y 350 -width 330 -height 165 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.lab63 \
        -x 5 -y 20 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.sec_head_lab \
        -x 5 -y 45 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.lab64 \
        -x 5 -y 70 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.lab65 \
        -x 40 -y 95 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.dvl_label \
        -x 50 -y 120 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.head_source \
        -x 130 -y 20 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.sec_head_source \
        -x 130 -y 45 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.depth_trans \
        -x 130 -y 70 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.alti1 \
        -x 130 -y 95 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.dvl \
        -x 130 -y 120 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.but95 \
        -x 285 -y 20 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.but96 \
        -x 285 -y 45 -width 27 -height 21 -anchor nw -bordermode ignore
    place $pilot2.lab62 \
        -x 25 -y 325 -anchor nw -bordermode ignore
    place $pilot2.subsea_input.alti_but \
        -x 285 -y 95 -width 27 -height 21 -anchor nw -bordermode ignore


    #----------- OK, CLOSE button position --------------

    # Ok
    place $pilot2.but108 \
        -x 600 -y 350 -anchor nw -bordermode ignore
    # Close
  #  place $pilot2.but109 \
        -x 660 -y 350 -anchor nw -bordermode ignore
        
        

    #--------- Bind the Auto Head PID ---------------------- 	bind $pilot2.pid.autohead.p <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autohead.i <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autohead.d <Return> { send_down_auto_pilot2 }
	
    #--------- Bind the Auto Depth PID ----------------------
 	bind $pilot2.pid.autodepth.p <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autodepth.i <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autodepth.d <Return> { send_down_auto_pilot2 }
	
    #--------- Bind the Auto Altitude PID ----------------------
 	bind $pilot2.pid.autoaltitude.p <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autoaltitude.i <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autoaltitude.d <Return> { send_down_auto_pilot2 }
		
    #--------- Bind the Auto Cruise PID ----------------------
 	bind $pilot2.pid.autocruise.p <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autocruise.i <Return> { send_down_auto_pilot2 }
	bind $pilot2.pid.autocruise.d <Return> { send_down_auto_pilot2 }
		
    #--------- Bind the Auto Inputs ----------------------
 	bind $pilot2.subsea_input.head_source <Return> { send_down_auto_pilot2 }
	#bind $pilot2.subsea_input.sec_head_source <Return> { send_down_auto_pilot2 }
	bind $pilot2.subsea_input.dvl <Return> { send_down_auto_pilot2 }
	bind $pilot2.subsea_input.depth_trans <Return> { send_down_auto_pilot2 }	
	bind $pilot2.subsea_input.alti1 <Return> { send_down_auto_pilot2 }

# end of proc "auto_pilot_popup2"
}




proc send_down_auto_pilot2 { } {

        global pilot2
        global foreaft_input turns_input auto_head_input auto_depth_input
        global auto_altitude_input auto_cruise_input  depth_jog_up_input depth_jog_down_input
        global head_source_input altimeter_input
        global head_p head_i head_d depth_p depth_i depth_d altitude_p altitude_i altitude_d cruise_p cruise_i cruise_d
        global port_thrust_output stbd_thrust_output vert_thrust_output lat_thrust_output

        #--------#
        # Initially     #
        #--------#
        set b1 ""
        set b3 ""
        set d1 ""
        set d2 ""
        set d3 ""
        set d4 ""


        set a1 [lindex $foreaft_input 2]
        set a2 [lindex $turns_input 2]
        set a3 [lindex $auto_head_input 2]
        set a4 [lindex $auto_depth_input 2]
        set a5 [lindex $auto_altitude_input 2]
        set a6 [lindex $auto_cruise_input 2]
        set a7 [lindex $depth_jog_up_input 2]
        set a8 [lindex $depth_jog_down_input 2]

        if {$head_source_input == "FOG GYRO" } {
        	set b1 0
        } elseif {$head_source_input == "BACKUP COMPASS" } {
        	set b1 1
        } elseif {$head_source_input == "DVL" } {
        	set b1 2
        }

        # Depth Transducer -> Paroscientific
        set b2 -1

        if {$altimeter_input == "MESOTECH"} {
        	set b3 0
        } elseif {$altimeter_input == "TRITECH"} {
        	set b3 1
        } elseif {$altimeter_input == "DVL"} {
        	set b3 2
        }

        # DVL Input
        set b4 -1


        set d1 [lindex $port_thrust_output 2]
        set d2 [lindex $stbd_thrust_output 2]
        set d3 [lindex $vert_thrust_output 2]
        set d4 [lindex $lat_thrust_output 2]

        #---------------------------------#
        # Error checking if one of the field is empty      #
        #---------------------------------#

        if { $a1 == "" || $a2 == "" || $a3 == "" || $a4 == ""  || $a5 == ""  || $a6 == "" || $a7 == "" \
        	|| $a8 == "" || $b1 == ""  || $b3 == "" || $d1 == "" || $d2 == "" || $d3 == "" || $d4 == "" \
        	|| $head_p == "" || $head_i == "" || $head_d == "" || $depth_p == "" || $depth_i == "" || $depth_d == "" \
        	|| $altitude_p == "" || $altitude_i == "" || $altitude_d == "" || $cruise_p == "" || $cruise_i == "" || $cruise_d == ""  } {
        	
        		
        	      	set status [tk_dialog  .pilot_warning2 { } {Some of the fields are empty.  Close the Auto Pilot window anyway ?} warning 0 {Yes } { No} ]
       		switch $status {   0 {destroy $pilot2; return }
       				1 {return} }


        }

        # The following is a bit recursive but we need to save the data in 3 places
        # 1) The new parameters have to be sent to the sub
        # 2) The new parameters have to be saved in the vehicle class database
        # 3) The new parameters have to be formatted into a string which is compatable with the
        #    configuration file.

        # Save the new values in database and transmitt to the vehicle
        set_autopilot $a1 $a2 $a3 $a4 $a5 $a6 $a7 $a8 $b1 $b2 $b3 $b4 $head_p $head_i $head_d $depth_p $depth_i $depth_d $altitude_p $altitude_i $altitude_d $cruise_p $cruise_i $cruise_d $d1 $d2 $d3 $d4

        # save all the information as a single string so it's easier when we want to write it to
	# configuration file
	set auto_pilot_string "$a1|$a2|$a3|$a4|$a5|$a6|$a7|$a8|$b1|$b2|$b3|$b4|$head_p|$head_i|$head_d|$depth_p|$depth_i|$depth_d|$altitude_p|$altitude_i|$altitude_d|$cruise_p|$cruise_i|$cruise_d|$d1|$d2|$d3|$d4"
        saving_auto_pilot_string $auto_pilot_string

 }
