proc P { str } {
    catch {puts $str ; flush stdout}
}

proc PN { str } {
    catch {puts -nonewline $str ; flush stdout}
}

proc PP { str } {
    P ""
    P $str
    P ""
}

proc PS { } {
    P ""
    P "------------------------------------------------------------"
    P ""
}

proc PE { str } {
    P ""
    P "ERROR: $str"
    P ""
}

proc PH { str } {
    P ""
    P "Test: $str"
    PS
}

proc PF { floatVal { prec 4 } } {
    set fmtStr "%.${prec}f"
    return [format $fmtStr $floatVal]
}

proc PSec { msg sec } {
    P [format "%s: %.4f seconds" $msg $sec]
}

proc PrintMachineInfo {} {
    global tcl_platform

    P "Machine specific information:"
    P  "platform    : $tcl_platform(platform)"
    P  "os          : $tcl_platform(os)"
    P  "osVersion   : $tcl_platform(osVersion)"
    P  "machine     : $tcl_platform(machine)"
    P  "byteOrder   : $tcl_platform(byteOrder)"
    P  "wordSize    : $tcl_platform(wordSize)"
    P  "user        : $tcl_platform(user)"
    P  "hostname    : [info hostname]"
    P  "Tcl version : [info patchlevel]"
    # P  "Visuals     : [winfo visualsavailable .]"
}

proc SetFileTypes { } {
    global fInfo

    set fInfo(suf)   ".tga"
    set fInfo(fmt)   "targa"
    set fInfo(vsn)   "int"
    set fInfo(phFmt) "tga"
}

proc RandomInit { seed } {
    variable randomSeed

    set randomSeed $seed
}

proc Random { } {
    variable randomSeed

    if { ! [info exists randomSeed] } {
        set randomSeed 1
    }
    set randomSeed [expr {($randomSeed * 9301 + 49297) % 233280}]
    return [expr {$randomSeed/double(233280)}]
}

proc RandomRange { range } {
    return [expr {int ([Random]*$range)}]
}

proc DegToRad { phi } {
    return [expr {$phi * 3.1415926535 / 180.0}]
}

proc RadToDeg { rad } {
    return [expr {$rad * 180.0 / 3.1415926535}]
}

proc ArrayToList { arr noElem } {
    upvar $arr a
    set tmpList [list]
    for { set i 0 } { $i < $noElem } { incr i } {
	lappend tmpList $a($i)
    }
    return $tmpList
}
