Posted to tcl by mjanssen at Thu Feb 05 23:58:34 GMT 2009view pretty

# MJ abuse of globals
# brace your expressions always even with catch !!!

proc {Get_Tube_Area_2} {} {

# MJ do these really have to be global

global tubeareafile
global notubeareafile; set notubeareafile 0

global templateopt

# MJ ever heard of arrays?!?!
global Area_tube_1
global Area_tube_2
global Area_tube_3
global Area_tube_4
global Area_tube_5
global Area_tube_6
global Area_tube_7
global Area_tube_8

if [catch {open $tubeareafile r} fileId] {
    set message "Cannot open $tubeareafile\n"
    append message "Please search working directory\n"

    # catch not needed   

    tk_messageBox -type ok -message $message -icon error
    puts "Cannot open $tubeareafile"

    # MJ removed double open
 
    # just return here and forget about the notblabla stuff!!
    set notubeareafile 1
}

# MJ urgh are this coding conventions at work? Only one exit point in a proc
if {$notubeareafile != 1} {
    # WTF, don't open it a third time!!! Three times' a charm? 
    # catch {open $tubeareafile r} fileId
    while {[gets $fileId line] >= 0} {
    if {[string first "---TUBEAREA" $line] >= 0} {

        # MJ urgh
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        gets $fileId line
        set line [string trim $line]
        set entry [parse $line]
    }
    }

    
    # probably a more general way!!
    if {"$templateopt" == "One Row"} {
        set Area_tube_1 [lindex $entry 1]
        set Area_tube_1 [format "%.2f" $Area_tube_1]
    }
    if {"$templateopt" == "Two Rows"} {
        set Area_tube_2 [lindex $entry 1]
        set Area_tube_2 [format "%.2f" $Area_tube_2]
    }
    close $fileId

    # MJ no need to force, it wasn't fixing the bug
    file delete $tubeareafile 
}
}