DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Parse Data-File And Do Some Maths (Alternate)
An alternate (but SLOW) way to proceed tabular data from a textfile
This one uses fileutil for proceeding the file.
#!/usr/bin/tclsh
#
# fileutils.tcl
#
# An alternate (but SLOW) way to proceed tabular data from a textfile
# This one uses fileutil for proceeding the file
#
#
#
package require Tcl 8.4
package require fileutil
package require textutil
package require math::statistics
namespace import ::fileutil::*
namespace import ::textutil::*
namespace import ::math::statistics::*
set filename "data.dat"
puts "Reading file $filename"
foreachLine line $filename {
set vdata [ splitx $line "\t"]
lappend x [ lindex $vdata 0]
lappend y [ lindex $vdata 1]
}
puts "Lines read:"
puts [llength $x]
puts "Calculating statistics"
#puts "\nx-column:"
#foreach dx $x { puts $dx }
#puts "\ny-column:"
#foreach dy $y { puts $dy }
set meany [mean $y]
set vary [var $y]
set stdevy [stdev $y]
puts "Mean y: $meany, Var x: $vary, StDev x: $stdevy"





