#!/bin/sh
# \
  exec oagtclsh "$0" "$@"

set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]

# Input files:  /C2/iocs/bpsc/master/opi/adl/bipolar_supply.adl
#               /C2/iocs/bpsc/master/opi/adl/unipolar_supply.adl
#
# Output files: APSU-SR-PS-TopLevel.adl

APSStandardSetup

source adl.tcl



proc MakeTitle {args} {
    APSStrictParseArguments {x y width height text}
    addRectangleObject -x $x -y $y -width $width -height $height -clr 14
    addTextObject -x $x -y [expr round($y + ($height * .1666667))] \
      -width $width -height [expr round ($height * .66667)] \
      -clr 0 -textix $text -alignCentered 1
}

proc DrawGrid {args} {
    APSStrictParseArguments {x y ix iy rows}

    set initx $x
    set height [expr $rows * $iy]
    for {set i 0} {$i <= 40} {incr i} {
        addLineObject -x $x -y $y -width 0 -height $height
        incr x $ix
    }
    set x $initx
    set width [expr 40 * $ix]
    for {set i 0} {$i <= $rows} {incr i} {
        addLineObject -x $x -y $y -width $width -height 0
        incr y $iy
    }
}

proc DrawRawGrid {args} {
    APSStrictParseArguments {x y ix iy rows}

    set initx $x
    set height [expr $rows * $iy]
    addLineObject -x $x -y $y -width 0 -height $height
    incr x $ix
    for {set i 1} {$i <= 39} {incr i 2} {
        addLineObject -x $x -y $y -width 0 -height $height
        incr x $ix
        if {$i != 39} {
            incr x $ix
        }
    }
    addLineObject -x $x -y $y -width 0 -height $height
    set x $initx
    set width [expr 40 * $ix]
    for {set i 0} {$i <= $rows} {incr i} {
        addLineObject -x $x -y $y -width $width -height 0
        incr y $iy
    }
}

proc DrawPSIndicators {args} {
    set bts 0
    APSStrictParseArguments {x y ix iy nameList bts}

    if {$bts} {
        set unipolarList "AQ1 AQ2 AQ3 AQ4 AQ5 BQ1 BQ2 BQ3 BQ4 BQ5 CQ1 CQ2 CQ3 BSQ1 BSQ2 BSQ3 BSQ4 BSQ5 BSQ6 DQ1 DQ2 "
#        set dipoleList "AB BX"
#        set unidipoleList "BB1 CB1"
        set dipoleList ""
        set unidipoleList "AB BX BB1 CB1"
        set pulsedList "B:EK B:ES1 B:ES2"
        set pulsedList2 "S38-IES:DK0 S39-IES:IK1 S39-IES:IK2 S39-IES:IK3"
        set pulsedList3 "S39-IES:IS1"
        set correctorList "AH1 AV1 AH2 AV2 AH3 AV3 BH1 BV1 BH2 BV2 BV3"
        set rawList1 "DC1 DC2"
        set rawList2 "RBO RSR"

        set initx $x
        set inity $y
        foreach name $nameList {
            if {$name != ""} {
                set bipolar 0
                set unipolar 0
                set dipole 0
                set unidipole 0
                set pulsed 0
                set pulsed2 0
                set pulsed3 0
                set corrector 0
                set raw1 0
                set raw2 0
                if {[string range $name 0 3] == "BTS:"} {
                    set type [string range $name 4 end]
                    set i [lsearch -exact $unipolarList $type]
                    if {$i != -1} {
                        set unipolar 1
                    } else {
                        set i [lsearch -exact $dipoleList $type]
                        if {$i != -1} {
                            set dipole 1
                        } else {
                            set i [lsearch -exact $unidipoleList $type]
                            if {$i != -1} {
                                set unidipole 1
                            } else {
                                set i [lsearch -exact $correctorList $type]
                                if {$i != -1} {
                                    set corrector 1
                                } else {
                                    set i [lsearch -exact $rawList1 $type]
                                    if {$i != -1} {
                                        set raw1 1
                                    } else {
                                        set i [lsearch -exact $rawList2 $type]
                                        if {$i != -1} {
                                            set raw2 1
                                        } else {
                                            set bipolar 1
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    set i [lsearch -exact $pulsedList $name]
                    if {$i != -1} {
                        set pulsed 1
                    } else {
                        set i [lsearch -exact $pulsedList2 $name]
                        if {$i != -1} {
                            set pulsed2 1
                        } else {
                            set pulsed3 1
                        }
                    }
                }
                #Draw black outline
                addRectangleObject -x $x -y $y \
                  -width $ix -height $iy -clr 14 -fill outline

                #Draw red rectangles that will appear when PS is off
                if {0} {
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] -clr 20
                }
                #Draw green rectangles that will appear when PS is on
                #set onOff ${name}:PS:OnOffStatusM.RVAL
                if {$unipolar || $unidipole || $raw1} {
                    set onOff ${name}:PS:OnOffM
                    if {0} {
                        addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                          -width [expr $ix - 1] -height [expr $iy - 1] \
                          -clr 15 -vis {"if not zero"} -chan $onOff
                    }
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 15 -vis static -alarmPV $onOff
                } elseif {$bipolar} {
                    set onOff ${name}:PS:OnOffStatusM
                    if {0} {
                        addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                          -width [expr $ix - 1] -height [expr $iy - 1] \
                          -clr 15 -vis {"if zero"} -chan $onOff
                    }
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 15 -vis static -alarmPV $onOff
                } elseif {$corrector || $pulsed || $dipole || $raw2} {
                    set onOff ${name}:StatusCALC
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 13 -vis static -alarmPV $onOff
                } elseif {$pulsed2} {
                   set onOff ${name}:PS:EnableM
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 15 -vis static -alarmPV $onOff
                } elseif {$pulsed3} {
                   set onOff ${name}:OnOffM
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 15 -vis static -alarmPV $onOff
                } else {
                    puts "ERROR: $name"
                    exit
                }
                #Draw dark red triangle that will appear when PS fault occurs
                set points "([expr $x + 0],[expr $y + 0])\n([expr $x + $ix],[expr $y + $iy])\n([expr $x + $ix],[expr $y + 0])\n([expr $x + 0],[expr $y + 0])"
                if {$unipolar || $unidipole || $raw1} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 22 -vis {"if not zero"} -chan ${name}:PS:FaultsM -points $points
                }
                #Draw blue triangle that will appear when PS is conditioned
                set points "([expr $x + 0],[expr $y + $iy])\n([expr $x + $ix],[expr $y + $iy])\n([expr $x + $ix],[expr $y + 0])\n([expr $x + 0],[expr $y + $iy])"
                if {$corrector} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 54 -vis {"if not zero"} -chan ${name}:StandardizeSUB.PROC -points $points
                } elseif {$dipole} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 54 -vis {"if not zero"} -chan ${name}:StandardizeDecayBI -points $points
                } elseif {$unipolar || $bipolar || $unidipole || $raw1} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 54 -vis {"if not zero"} -chan ${name}:StandardizeC.PROC -points $points
                } elseif {$pulsed || $pulsed2 || $pulsed3 || $raw2} {
                    
                } else {
                    puts "ERROR: $name"
                    exit
                }
                if {$unipolar || $unidipole || $raw1} {
                    #Draw invisible button to display PS details, button needs to be red for some reason
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/upsc/tdk_unipolar_supply.adl \
                      -display1arguments "P=[string range $name 0 2],R=:${type}"
                }
                if {$bipolar} {
                    #Draw invisible button to display PS details, button needs to be red for some reason
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/bpsc/bipolar_supply.adl \
                      -display1arguments "P=[string range $name 0 3],R=${type}"
                }
                if {$corrector || $pulsed || $dipole} {
                    #Draw invisible button to display PS details, button needs to be red for some reason
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name /usr/local/iocapps/adlsys/booster/psApp/[join [split $name :] ""].adl
                }
                if {$pulsed2} {
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/ies/iesPsStatus.adl \
                      -display1arguments "P=[string range $name 0 7],R=[string range $name 8 end]:"
                }
                if {$pulsed3} {
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/septumps/septumps.adl \
                      -display1arguments "P=$name"
                }
                if {$raw2} {
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name /usr/local/iocapps/adlsys/booster/psApp/[join [split $name ":"] ""].adl
                }
            }
            incr y $iy
        }

    } else {
        set unipolarList "S:M1 S:M2 A:M3 A:M4 A:Q1 A:Q2 A:Q3 A:Q4 A:Q5 A:Q6 A:Q7 A:Q8 A:S1 A:S2 A:S3 B:M1 B:M2 B:M3 B:Q1 B:Q2 B:Q3 B:Q4 B:Q5 B:Q6 B:Q7 B:Q8 B:S1 B:S2 B:S3 "
        for {set i 1} {$i <= 40} {incr i} {
            lappend sectors [format %02d $i]
        }
        if {$nameList == "S36C:FOK1"} {
            set results "S36C:FOK1 0"
        } elseif {($nameList == "S:M1") || ($nameList == "S:M2")} {
            if {[catch {exec cavget -pend=5 -label -list=[join $nameList ,] -list=:StandardizeC} results]} {
                puts "Error"
                exit
            }
        } else {
            if {[catch {exec cavget -pend=5 -label -list=S -list=[join ${sectors} ,] -list=[join $nameList ,] -list=:StandardizeC} results]} {
                puts "Error"
                exit
            }
        }
        set lines [split $results \n]
        set initx $x
        set inity $y
        set lastSector 01
        foreach line $lines {
            set PV [lindex $line 0]
            if {($nameList == "S:M1") || ($nameList == "S:M2")} {
                set sector ""
                set type [string range $line 1 3]
                incr x $ix
                set y $inity
            } elseif {$nameList == "S36C:FOK1"} {
                incr x [expr $ix + 30]
                set y $inity
            } else {
                set sector [string range $line 1 2]
                set type [string range $line 3 end-15]
                if {[string compare $sector $lastSector] != 0} {
                    set lastSector $sector
                    incr x $ix
                    set y $inity
                }
            }
            if {[info exists sector]} {
                if {(($sector == "09") && (($type == "C:H2") || ($type == "C:V2")))} {
                    incr y $iy
                    continue
                }
                if {(($sector == "33") && (($type == "C:H2") || ($type == "C:V2")))} {
                    incr y $iy
                    continue
                }
            }
            if {[lindex $line 1] != "?"} {
                if {($nameList == "S:M1") || ($nameList == "S:M2")} {
                    set unipolar 1
                } elseif {$nameList == "S36C:FOK1"} {
                    set unipolar 0
                } else {
                    set i [lsearch -exact $unipolarList $type]
                    if {$i == -1} {
                        set unipolar 0
                    } else {
                        set unipolar 1
                    }
                }
                #Draw green rectangles that will appear when PS is on
                if {$unipolar} {
                    set onOff S${sector}${type}:PS:OnOffM
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 15 -vis static -alarmPV $onOff
                } elseif {$nameList == "S36C:FOK1"} {
                    set onOff S36C:FOK1:PS:SupplyOnOffM
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -vis static -alarmPV $onOff
                } else {
                    set onOff S${sector}${type}:PS:OnOffStatusM
                    addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -vis static -alarmPV $onOff
                }

                #Draw dark red triangle that will appear when PS fault occurs
                set points "([expr $x + 0],[expr $y + 0])\n([expr $x + $ix],[expr $y + $iy])\n([expr $x + $ix],[expr $y + 0])\n([expr $x + 0],[expr $y + 0])"
                if {$unipolar} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 22 -vis {"if not zero"} -chan S${sector}${type}:PS:FaultsM -points $points
                } elseif {$nameList == "S36C:FOK1"} {
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 22 -vis {"if not zero"} -chan S36C:FOK1:PS:FaultsM -points $points
                }
                #Draw blue triangle that will appear when PS is conditioned
                if {$nameList != "S36C:FOK1"} {
                    set points "([expr $x + 0],[expr $y + $iy])\n([expr $x + $ix],[expr $y + $iy])\n([expr $x + $ix],[expr $y + 0])\n([expr $x + 0],[expr $y + $iy])"
                    addPolygonObject -x [expr $x + 0] -y [expr $y + 0] \
                      -width [expr $ix - 0] -height [expr $iy - 0] \
                      -clr 54 -vis {"if not zero"} -chan ${PV}.PROC -points $points
                }
                #Draw invisible button to display PS details, button needs to be red for some reason
                if {$unipolar} {
                    if {($nameList != "S:M1") && ($nameList != "S:M2")} {
                        addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                          -width [expr $ix - 1] -height [expr $iy - 1] \
                          -clr 20 -bclr 2 -invisible 1 \
                          -display1name iocs/upsc/unipolar_supply.adl \
                          -display1arguments "P=S${sector},R=${type}"
                    } else {
                        addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                          -width [expr $ix - 1] -height [expr $iy - 1] \
                          -clr 20 -bclr 2 -invisible 1 \
                          -display1name iocs/upsc/ocem_unipolar_supply.adl \
                          -display1arguments "P=S,R=${type}"
                    }
                } elseif {$nameList == "S36C:FOK1"} {
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/fokps/fokps.adl \
                      -display1arguments "P=S36C:FOK1:PS"
                } else {
                    addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
                      -width [expr $ix - 1] -height [expr $iy - 1] \
                      -clr 20 -bclr 2 -invisible 1 \
                      -display1name iocs/bpsc/bipolar_supply.adl \
                      -display1arguments "P=S${sector},R=${type}"
                }
            }
            incr y $iy
        }
    }
}

proc DrawRawPSIndicators {args} {
    APSStrictParseArguments {x y ix iy nameList}

    set initx $x
    foreach type "R1 R2 R3 R4" {
        set x $initx
        set sectors "40:1 2:3 4:5 6:7 8:9 10:11 12:13 14:15 16:17 18:19 20:21 22:23 24:25 26:27 28:29 30:31 32:33 34:35 36:37 38:39 40:1"
        set ssectors "4001 0203 0405 0607 0809 1011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 3233 3435 3637 3839 4001"
        
        foreach sector $sectors ssector $ssectors {
            if {$sector != "40:1"} {
                set width [expr $ix + $ix]
            } else {
                set width $ix
            }
            set onOff S${sector}:${type}:StatusCALC

            addRectangleObject -x [expr $x + 1] -y [expr $y + 1] \
              -width [expr $width - 1] -height [expr $iy - 1] -clr 13 \
              -vis static -alarmPV $onOff

            addRelatedDisplay -x [expr $x + 1] -y [expr $y + 1] \
              -width [expr $width - 1] -height [expr $iy - 1] \
              -clr 20 -bclr 2 -invisible 1 \
              -display1name iocs/rawps/S${ssector}${type}.adl

            incr x $width
        }

        incr y $iy
    }
}


proc MakePSGrid {args} {
    APSStrictParseArguments {group x y ix iy}
    if {$group == "fastcorrectors"} {
        set nameList "A:FH1 A:FV1 A:FH2 A:FV2 B:FH2 B:FV2 B:FH1 B:FV1"
        set title "SR Fast Corrector Power Supplies"
    } elseif {$group == "correctors"} {
        set nameList "A:H1 A:V1 A:H7 A:V7 A:V8 B:V8 B:H7 B:V7 B:H1 B:V1 C:H2 C:V2"
        set title "SR Corrector Power Supplies"
    } elseif {$group == "quadrupoles"} {
        set nameList "A:Q1 A:Q2 A:Q3 A:Q6 A:Q7 B:Q7 B:Q6 B:Q3 B:Q2 B:Q1"
        set title "SR Quadrupole Power Supplies"
    } elseif {$group == "skewquadrupoles"} {
        set nameList "A:SQ1 A:SQ2 B:SQ2 B:SQ1"
        set title "SR Skew Quadrupole Power Supplies"
    } elseif {$group == "sextupoles"} {
        set nameList "A:S1 A:S2 A:S3 B:S3 B:S2 B:S1"
        set title "SR Sextupole Power Supplies"
    } elseif {$group == "dipoles"} {
        set nameList "A:M3 A:M3T A:M4 A:M4T A:Q4 A:Q4T A:Q5 A:Q5T A:Q8 A:Q8T B:Q8 B:Q8T B:Q5 B:Q5T B:Q4 B:Q4T B:M3 B:M3T C:M1 C:M2"
        set title "SR Dipole and Dipole Trim Power Supplies"
    }

    set titleHeight 30
    set textHeight 12
    set labelWidth 35

    set initx $x
    set inity $y

    MakeTitle -x $x -y $y -width [expr $labelWidth + (40 * $ix) + 2] -height $titleHeight -text $title
    incr y $titleHeight
    
    incr x $labelWidth
    set yNudge 4
    incr y [expr $yNudge]
    for {set i 0} {$i <= 4} {incr i} {
        for {set j 0} {$j <= 9} {incr j} {
            if {($i == 0) && ($j == 0)} continue
            if {($i == 4) && ($j != 0)} continue
            if {($i == 1) || ($i == 3)} {
                addRectangleObject -x $x -y [expr $y - $yNudge] -width $ix -height [expr $textHeight * 2 + $yNudge] -clr 4
            }
            addTextObject -x $x -y $y -width $ix -height $textHeight -textix $i -alignCentered 1
            addTextObject -x $x -y [expr $y + $textHeight] -width $ix -height $textHeight -textix $j -alignCentered 1
            incr x $ix
        }
    }

    set x $initx
    set y $inity
    incr x $labelWidth
    set rows [llength $nameList]
    incr y [expr ($rows + 2) * $iy + $yNudge + $titleHeight]
    for {set i 0} {$i <= 4} {incr i} {
        for {set j 0} {$j <= 9} {incr j} {
            if {($i == 0) && ($j == 0)} continue
            if {($i == 4) && ($j != 0)} continue
            if {($i == 1) || ($i == 3)} {
                addRectangleObject -x $x -y [expr $y - $yNudge] -width $ix -height [expr $textHeight * 2 + $yNudge] -clr 4
            }
            addTextObject -x $x -y $y -width $ix -height $textHeight -textix $i -alignCentered 1
            addTextObject -x $x -y [expr $y + $textHeight] -width $ix -height $textHeight -textix $j -alignCentered 1
            incr x $ix
        }
    }

    set x $initx
    set y $inity
    set yNudge 2
    incr y [expr $iy * 2 + $yNudge + $titleHeight]
    foreach name $nameList {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
    }

    set x $initx
    set y $inity
    incr x $labelWidth
    incr y [expr $iy * 2 + $titleHeight]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList
    DrawGrid -x $x -y $y -ix $ix -iy $iy -rows [llength $nameList]

    if {$group == "dipoles"} {
        MakeMainDipoleGrid -x [expr $initx + $labelWidth] -y [expr $inity + 30 + (($rows + 4) * $iy) + 8] -ix $ix -iy $iy 
    }
}

proc MakeRawPSGrid {args} {
    APSStrictParseArguments {group x y ix iy}
    set nameList "R1 R2 R3 R4"
    set title "Raw Power Supplies"

    set titleHeight 30
    set textHeight 12
    set labelWidth 35

    set initx $x
    set inity $y

    MakeTitle -x $x -y $y -width [expr $labelWidth + (40 * $ix) + 2] -height $titleHeight -text $title
    incr y $titleHeight
    
    incr x $labelWidth
    set yNudge 4
    incr y [expr $yNudge]
    for {set i 0} {$i <= 4} {incr i} {
        for {set j 0} {$j <= 9} {incr j} {
            if {($i == 0) && ($j == 0)} continue
            if {($i == 4) && ($j != 0)} continue
            if {($i == 1) || ($i == 3)} {
                addRectangleObject -x $x -y [expr $y - $yNudge] -width $ix -height [expr $textHeight * 2 + $yNudge] -clr 4
            }
            addTextObject -x $x -y $y -width $ix -height $textHeight -textix $i -alignCentered 1
            addTextObject -x $x -y [expr $y + $textHeight] -width $ix -height $textHeight -textix $j -alignCentered 1
            incr x $ix
        }
    }
    set x $initx
    set y $inity
    incr x $labelWidth
    set rows [llength $nameList]
    incr y [expr ($rows + 2) * $iy + $yNudge + $titleHeight]
    for {set i 0} {$i <= 4} {incr i} {
        for {set j 0} {$j <= 9} {incr j} {
            if {($i == 0) && ($j == 0)} continue
            if {($i == 4) && ($j != 0)} continue
            if {($i == 1) || ($i == 3)} {
                addRectangleObject -x $x -y [expr $y - $yNudge] -width $ix -height [expr $textHeight * 2 + $yNudge] -clr 4
            }
            addTextObject -x $x -y $y -width $ix -height $textHeight -textix $i -alignCentered 1
            addTextObject -x $x -y [expr $y + $textHeight] -width $ix -height $textHeight -textix $j -alignCentered 1
            incr x $ix
        }
    }

    set x $initx
    set y $inity
    set yNudge 2
    incr y [expr $iy * 2 + $yNudge + $titleHeight]
    foreach name $nameList {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
    }

    set x $initx
    set y $inity
    incr x $labelWidth
    incr y [expr $iy * 2 + $titleHeight]
    DrawRawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList
    DrawRawGrid -x $x -y $y -ix $ix -iy $iy -rows [llength $nameList]
}

proc MakeBTSPanel {args} {
    APSStrictParseArguments {x y ix iy}
    set nameList1 "BTS:AH1 BTS:AV1 BTS:AH2 BTS:AV2 BTS:AH3 BTS:AV3"
    set nameList2 "BTS:AQ1 BTS:AQ2 BTS:AQ3 BTS:AQ4 BTS:AQ5"
    set nameList3 "BTS:BH1 BTS:BV1 BTS:BH2 BTS:BV2 BTS:BV3 BTS:BSQ1H BTS:BSQ2V BTS:BSQ5H BTS:BSQ6V BTS:CQ1H BTS:CQ2V BTS:CQ3H BTS:DQ1H BTS:DQ2V"
    set nameList4 "BTS:BQ1 BTS:BQ2 BTS:BQ3 BTS:BQ4 BTS:BQ5 BTS:CQ1 BTS:CQ2 BTS:CQ3 BTS:DQ1 BTS:DQ2"
    set nameList5 "BTS:BSQ1 BTS:BSQ2 BTS:BSQ3 BTS:BSQ4 BTS:BSQ5 BTS:BSQ6"
    set nameList6 "BTS:BB1 BTS:CB1 S38-IES:DK0 S39-IES:IS1 S39-IES:IK1 S39-IES:IK2 S39-IES:IK3"
    set nameList7 "B:EK B:ES1 B:ES2"
    set nameList8 "BTS:AB BTS:BX"
    set nameList9 "BTS:DC1 BTS:DC2"
    set nameList10 "BTS:RBO BTS:RSR"
 
    #Dipoles
    #B:ES1 B:ES2 BTS:AB BTS:BB1 BTS:CB1 S39-IES:IS1 S39-IES:IK1 S39-IES:IK2 S39-IES:IK3

    #Quads
    #AQ1 AQ2 AQ3 AQ4 AQ5 BQ1 BQ2 BQ3 BQ4 BQ5 CQ1 CQ2 CQ3 DQ1 DQ2

    #SkewQuad
    #BSQ1 BSQ2 BSQ3 BSQ4 BSQ5 BSQ6

    #Correctors
    #AH1 AV1 AH2 AH2 AH3 AV3 BH1 BV1 BH2 BV2 BV3

    set title "BTS PS"

    set titleHeight 30
    set titleWidth 186
    set textHeight 12
    set subTitleWidth 80
    set subTitleHeight 18

    set initx $x
    set inity $y

    MakeTitle -x $x -y $y -width $titleWidth -height $titleHeight -text $title
    incr y $titleHeight

    #Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr $titleWidth - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width $titleWidth \
      -height $textHeight \
      -textix "Booster Side" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Sub-Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr round($titleWidth / 2.0)] -height [expr $textHeight + 2] -clr 14 -fill outline
    addRectangleObject -x [expr $x + round($titleWidth / 2.0)] -y $y -width [expr round($titleWidth / 2.0) - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Correctors" -alignCentered 1
    addTextObject -x [expr $x + round($titleWidth / 2.0)] -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Quadrupoles" -alignCentered 1
    incr y [expr $textHeight + 2]

    set ymax $y
    
    #A Correctors
    set labelWidth 62
    set yNudge 2
    incr y [expr $textHeight + $yNudge]
    set ytmp $y
    set x [expr $initx + 25]
    foreach name $nameList1 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList1 -bts 1

    #A Quads
    set labelWidth 62
    set y $ytmp
    set x [expr $initx + round($titleWidth / 2.0) + 25]
    foreach name $nameList2 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + round($titleWidth / 2.0) + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList2 -bts 1
    
    #Add space
    set x $initx
    set y [expr $ymax + $iy]

    #Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr $titleWidth - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width $titleWidth \
      -height $textHeight \
      -textix "Booster Side" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Sub-Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr round($titleWidth / 2.0)] -height [expr $textHeight + 2] -clr 14 -fill outline
    addRectangleObject -x [expr $x + round($titleWidth / 2.0)] -y $y -width [expr round($titleWidth / 2.0) - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Kicker/Septum" -alignCentered 1
    addTextObject -x [expr $x + round($titleWidth / 2.0)] -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Dipoles" -alignCentered 1
    incr y [expr $textHeight + 2]

    #BTS side kickers/septums
    set labelWidth 62
    set yNudge 2
    incr y [expr $textHeight + $yNudge]
    set ytmp $y
    set x [expr $initx + 25]
    foreach name $nameList7 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList7 -bts 1

    #BTS side dipoles
    set labelWidth 62
    set y $ytmp
    set x [expr $initx + round($titleWidth / 2.0) + 25]
    foreach name $nameList8 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + round($titleWidth / 2.0) + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList8 -bts 1

    #Add space
    set x $initx
    set y [expr $ymax + $iy]

    #Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr $titleWidth - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width $titleWidth \
      -height $textHeight \
      -textix "SR Side" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Sub-Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr round($titleWidth / 2.0)] -height [expr $textHeight + 2] -clr 14 -fill outline
    addRectangleObject -x [expr $x + round($titleWidth / 2.0)] -y $y -width [expr round($titleWidth / 2.0) - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Correctors" -alignCentered 1
    addTextObject -x [expr $x + round($titleWidth / 2.0)] -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Quadrupoles" -alignCentered 1
    incr y [expr $textHeight + 2]

    #B Correctors
    set labelWidth 62
    set yNudge 2
    incr y [expr $textHeight + $yNudge]
    set ytmp $y
    set x [expr $initx + 25]
    foreach name $nameList3 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList3 -bts 1

    #B Quads
    set labelWidth 62
    set y $ytmp
    set x [expr $initx + round($titleWidth / 2.0) + 25]
    foreach name $nameList4 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + round($titleWidth / 2.0) + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList4 -bts 1
    
    #Add space
    set x $initx
    set y [expr $ymax + $iy]

    #Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr $titleWidth - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width $titleWidth \
      -height $textHeight \
      -textix "SR Side" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Sub-Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr round($titleWidth / 2.0)] -height [expr $textHeight + 2] -clr 14 -fill outline
    addRectangleObject -x [expr $x + round($titleWidth / 2.0)] -y $y -width [expr round($titleWidth / 2.0) - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Skew Quads" -alignCentered 1
    addTextObject -x [expr $x + round($titleWidth / 2.0)] -y [expr round($y + ($textHeight * .1666667))] \
      -width [expr round($titleWidth / 2.0)] \
      -height $textHeight \
      -textix "Dipoles etc" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Skew Quads
    set labelWidth 62
    set yNudge 2
    incr y [expr $textHeight + $yNudge]
    set ytmp $y
    set x [expr $initx + 25]
    foreach name $nameList5 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList5 -bts 1

    #Dipole
    set labelWidth 62
    set y $ytmp
    set x [expr $initx + round($titleWidth / 2.0) + 25]
    foreach name $nameList6 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + round($titleWidth / 2.0) + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList6 -bts 1
    
    #Add space
    set x $initx
    set y [expr $ymax + $iy]

    #Sub title
    addRectangleObject -x $x -y $y -width $titleWidth -height [expr $textHeight + 2] -clr 4
    addRectangleObject -x $x -y $y -width [expr $titleWidth - 1] -height [expr $textHeight + 2] -clr 14 -fill outline
    addTextObject -x $x -y [expr round($y + ($textHeight * .1666667))] \
      -width $titleWidth \
      -height $textHeight \
      -textix "Raw Supplies" -alignCentered 1
    incr y [expr $textHeight + 2]

    #Raw
    set labelWidth 62
    set yNudge 2
    incr y [expr $textHeight + $yNudge]
    set ytmp $y
    set x [expr $initx + 25]
    foreach name $nameList9 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList9 -bts 1

    #More Raw
    set labelWidth 62
    set y $ytmp
    set x [expr $initx + round($titleWidth / 2.0) + 25]
    foreach name $nameList10 {
        addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix $name
        incr y $iy
        if {$y > $ymax} {
            set ymax $y
        }
    }
    set x [expr $initx + round($titleWidth / 2.0) + 5]
    set y [expr $ytmp - $yNudge]
    DrawPSIndicators -x $x -y $y -ix $ix -iy $iy -nameList $nameList10 -bts 1

    addRectangleObject -x $initx -y $inity -width [expr $titleWidth - 1] -height $ymax -clr 14 -fill outline

}

proc MakeMainDipoleGrid {args} {
    APSStrictParseArguments {x y ix iy}
    set nameList "S:M1 S:M2"

    set textHeight 12
    set labelWidth 30

    set initx $x
    set inity $y
    
    addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix S:M1
    DrawPSIndicators -x [expr $x + 16] -y $y -ix $ix -iy $iy -nameList S:M1
    addRectangleObject -x [expr $x + $labelWidth] -y $y \
      -width $ix -height $iy -clr 14 -fill outline
    incr x 70
    
    addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix S:M2
    DrawPSIndicators -x [expr $x + 16] -y $y -ix $ix -iy $iy -nameList S:M2
    addRectangleObject -x [expr $x + $labelWidth] -y $y \
      -width $ix -height $iy -clr 14 -fill outline
    incr x 70

    addTextObject -x $x -y $y -width $labelWidth -height $textHeight -textix S36C:FOK1
    DrawPSIndicators -x [expr $x + 16] -y $y -ix $ix -iy $iy -nameList S36C:FOK1
    addRectangleObject -x [expr $x + $labelWidth + 30] -y $y \
      -width $ix -height $iy -clr 14 -fill outline

}

proc writeAdlFile {args} {
    global adlOutput
    set name newDisplay.adl
    APSStrictParseArguments {name}

    set fid [open $name w]
    puts $fid $adlOutput
    close $fid
}


proc ModifyDefaultIndividualPSScreens {args} {
    file copy  -force /C2/iocs/bpsc/master/opi/adl/bipolar_supply.adl bipolar_supply_mod.adl
    file copy  -force /C2/iocs/upsc/master/opi/adl/unipolar_detail.adl unipolar_supply_mod.adl
    exec chmod ug+w bipolar_supply_mod.adl
    exec chmod ug+w unipolar_supply_mod.adl
    
    set fid [open bipolar_supply_mod.adl a]
    puts $fid "\"related display\" \{"
    puts $fid "  object \{"
    puts $fid "    x=400"
    puts $fid "    y=329"
    puts $fid "    width=140"
    puts $fid "    height=21"
    puts $fid "  \}"
    puts $fid "  display\[0\] \{"
    puts $fid "    label=\"Degauss Settings\""
    puts $fid "    name=\"APSU-TriDegauss-Settings.adl\""
    puts $fid "    args=\"P=\$(P),R=\$(R)\""
    puts $fid "  \}"
    puts $fid "  clr=14"
    puts $fid "  bclr=51"
    puts $fid "  label=\"Degauss Settings\""
    puts $fid "\}"
    close $fid

    if {0} {
        set fid [open unipolar_supply_mod.adl a]
        puts $fid "\"related display\" \{"
        puts $fid "  object \{"
        puts $fid "    x=12"
        puts $fid "    y=630"
        puts $fid "    width=160"
        puts $fid "    height=21"
        puts $fid "  \}"
        puts $fid "  display\[0\] \{"
        puts $fid "    label=\"Standardize Settings\""
        puts $fid "    name=\"APSU-StandardizeDwell-Settings.adl\""
        puts $fid "    args=\"P=\$(P),R=\$(R)\""
        puts $fid "  \}"
        puts $fid "  clr=14"
        puts $fid "  bclr=51"
        puts $fid "  label=\"Standardize Settings\""
        puts $fid "\}"
        close $fid
    }
}

proc AddPEMCommands {} {
    global adlOutput
    append adlOutput "\"shell command\" \{\n"
    append adlOutput "  object \{\n"
    append adlOutput "    x=1250\n"
    append adlOutput "    y=800\n"
    append adlOutput "    width=90\n"
    append adlOutput "    height=16\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[0\] \{\n"
    append adlOutput "    label=\"SR PS On+Condition\"\n"
    append adlOutput "    name=\"runProcGUI APSMpSRUpDoubleSector &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[1\] \{\n"
    append adlOutput "    label=\"SR PS Off\"\n"
    append adlOutput "    name=\"runProcGUI APSMpSRDownDoubleSector &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[2\] \{\n"
    append adlOutput "    label=\"SR Kickers/Septums On\"\n"
    append adlOutput "    name=\"runProcGUI APSMpSRTurnOnKickers &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[3\] \{\n"
    append adlOutput "    label=\"SR Kickers/Septums Off\"\n"
    append adlOutput "    name=\"runProcGUI APSMpSRTurnOffKickers &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[4\] \{\n"
    append adlOutput "    label=\"BTS PS On+Condition\"\n"
    append adlOutput "    name=\"runProcGUI APSMpBTSConditionPowerSupplies &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[5\] \{\n"
    append adlOutput "    label=\"BTS PS Off\"\n"
    append adlOutput "    name=\"runProcGUI APSMpBTSTurnOffPS &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[6\] \{\n"
    append adlOutput "    label=\"Booster Kickers/Septums On\"\n"
    append adlOutput "    name=\"runProcGUI APSMpBPSTurnOnPulsedSupplies &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  command\[7\] \{\n"
    append adlOutput "    label=\"Booster Kickers/Septums Off\"\n"
    append adlOutput "    name=\"runProcGUI APSMpBPSTurnOffPulsedSupplies &\"\n"
    append adlOutput "  \}\n"
    append adlOutput "  clr=14\n"
    append adlOutput "  bclr=51\n"
    append adlOutput "  label=\"    PEMs\"\n"
    append adlOutput "\}\n"


}

#ModifyDefaultIndividualPSScreens


set adlOutput ""
addFileObject -name APSU-SR-PS-TopLevel.adl
addDisplayObject -x 10 -y 10 -width 1440 -height 900 -clr 14 -bclr 2
addColorMapObject
MakePSGrid -group fastcorrectors  -x 10  -y 10  -ix 14 -iy 14
MakePSGrid -group correctors      -x 10  -y 250 -ix 14 -iy 14
MakePSGrid -group quadrupoles     -x 10  -y 550 -ix 14 -iy 14
MakePSGrid -group dipoles         -x 630 -y 10  -ix 14 -iy 14
MakePSGrid -group skewquadrupoles -x 630 -y 410 -ix 14 -iy 14
MakePSGrid -group sextupoles      -x 630 -y 560 -ix 14 -iy 14
MakeRawPSGrid -group raws            -x 630 -y 740 -ix 14 -iy 14
MakeBTSPanel -x 1250 -y 10 -ix 14 -iy 14
addRelatedDisplay -x 1250 -y 755 -width 90 -height 18 -label "-Legend" \
  -display1name /usr/local/iocapps/adlsys/booster/psApp/psLegend.adl -display1label "Legend" -clr 14 -bclr 51
addRelatedDisplay -x 1340 -y 755 -width 90 -height 18 -label "Controllers" \
  -display1name /C2/screens/adl/iocs/upsc/UPSC_controllers.adl -display1label "UPSC Controllers" \
  -display2name /C2/screens/adl/iocs/bpsc/BPSC_controllers.adl -display2label "BPSC Controllers" -clr 14 -bclr 51
addShellCommand -x 1340 -y 780 -width 90 -height 16 -label "BTS-DCPS" -command "BTS-DCPS &" -clr 14 -bclr 51
addShellCommand -x 1340 -y 800 -width 90 -height 16 -label "SR-DCPS" -command "SR-DCPS &" -clr 14 -bclr 51
addShellCommand -x 1250 -y 780 -width 90 -height 16 -label "SR-RPS" -command "SR-RPS &" -clr 14 -bclr 51
AddPEMCommands
writeAdlFile -name APSU-SR-PS-TopLevel.adl

set adlOutput ""
addFileObject -name APSU-BTS-PS-TopLevel.adl
addDisplayObject -x 10 -y 10 -width 202 -height 815 -clr 14 -bclr 2
addColorMapObject
MakeBTSPanel -x 10 -y 10 -ix 14 -iy 14
addRelatedDisplay -x 10 -y 755 -width 90 -height 18 -label "Controllers" \
  -display1name /C2/screens/adl/iocs/upsc/UPSC_controllers.adl -display1label "UPSC Controllers" \
  -display2name /C2/screens/adl/iocs/bpsc/BPSC_controllers.adl -display2label "BPSC Controllers" -clr 14 -bclr 51
addShellCommand -x 10 -y 780 -width 90 -height 16 -label "BTS-DCPS" -command "BTS-DCPS &" -clr 14 -bclr 51
writeAdlFile -name APSU-BTS-PS-TopLevel.adl
