# ---------------------------------------------------------------------- # LoadBigImage proc LoadBigImage {filePath varName {translation {auto}}} { upvar $varName var set var {} if ![file exists $filePath] { return } set numChars 8000 ;# 19220 ms using MCP_masc-dist-agua-aberta-cana_GRR.txt # Get the .txt header set fileId [open $filePath r] fconfigure $fileId -translation $translation set readContent [read $fileId 200] # set header [join [lrange [split $readContent \n] 0 5] \n] set lineList [lrange [split $readContent \n] 0 6] set lastLine [lindex $lineList end] if [regexp -nocase {^NODATA_value} $lastLine] { # ncols 10352 # nrows 8752 # xllcorner 146927.389199999947 # yllcorner 7334093.340900002047 # dx 27.230000000000 # dy 30.230000000000 # NODATA_value -9999 set header $lineList } else { # NCOLS 32 # NROWS 32 # XLLCORNER 265895.921875 # YLLCORNER 7465461.250000 # CELLSIZE 30.000000 # NODATA_VALUE 3.402823466e+038 # 1957.082031 1927.082031 1897.082031 1867.082031 1837.082031 1807.082031 1 set header [lrange $lineList 0 5] } set header [join $header \n] # => # NCOLS 10352 # NROWS 8752 # XLLCORNER 146927.389200 # YLLCORNER 7334093.340900 # CELLSIZE 27.230000 # NODATA_VALUE -9.999000000e+003 set headerLength [string length $header] # incr headerLength -1 close $fileId # Get the .txt header - end # Load the big Image set fileId [open $filePath r] fconfigure $fileId -translation $translation set headerContent [read $fileId $headerLength] # array set headerArray $headerContent # set totalSize [expr $headerArray(NROWS) * $headerArray(NCOLS)] set readContent [read $fileId $numChars] while {![string equal {} $readContent]} { append var $readContent set readContent [read $fileId $numChars] } close $fileId # Load the big Image - end } # LoadBigImage - end # ---------------------------------------------------------------------- if $argv { # usage examples set argv 0 console show set initial [clock milliseconds] set switchNumber 3 switch $switchNumber 1 { set filePath ./image/arquivoTeste.txt } 2 { set filePath ./image/distCanaArAbertaAguaMB2016F5x5_GRR.txt } 3 { set filePath ./image/MCP_masc-dist-agua-aberta-cana_GRR.txt ;# 19220 ms } LoadBigImage $filePath data set final [clock milliseconds] puts "processing time = [expr $final - $initial] ms" puts "data size = [llength $data]" }