# ---------------------------------------------------------------------- # GetHeader # return a list of lines that comprise the header proc GetHeader {filePath {translation {auto}}} { 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] set penultimate [lindex $lineList end-1] 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 } elseif {[regexp -nocase {^NODATA_value} $penultimate]} { # 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] } else { set header {} } close $fileId return $header } # GetHeader - end # ---------------------------------------------------------------------- # ProcessRecursively (2) # 5 108 929 pixel # 58 701 000 B disc 58.7 MB # 4165 - 3487 = 678 # 4880 - 4241 = 639 # 639 000 000 B RAM # expr 4500*58.7/650 # => 406 MB # expr 400000000/8000 # => 50000 proc ProcessRecursively {filePath action {translation {auto}}} { if ![file exists $filePath] { return } # headerLines set headerLines [GetHeader $filePath] # header set header [join $headerLines \n] # headerLength set headerLength [string length $header] # Execute action set numChars 8000 ;# 19220 ms using MCP_masc-dist-agua-aberta-cana_GRR.txt # set numRead 50000 ;# too big - doesn't work with 2 characters pixel value (ex: 25) set numRead 10000 set fileId [open $filePath r] fconfigure $fileId -translation $translation set headerContent [read $fileId $headerLength] set var {} set savedVar {} ;# used in TurnCellSquareRecursively, TakeUpperLeftCornerRecursively, ExtractValidLineRecursively and ExtractRandomSampleRecursively set i 0 set readContent [read $fileId $numChars] while {![string equal {} $readContent]} { append var $readContent if {$i < $numRead} { incr i } else { set c [string index $readContent end] while {![regexp {\s|\t|\n|^$} $c]} { set c [read $fileId 1] append var $c } # incr varSize [llength $var] # GetSize var varSize if [eval $action] {close $fileId; return} set var {} set i 0 } set readContent [read $fileId $numChars] } if {$i < [expr $numRead + 1]} { # incr varSize [llength $var] # GetSize var varSize eval $action } close $fileId # Execute action - end } # ProcessRecursively - end # ---------------------------------------------------------------------- # DisplayProcessingTime # processingTime value is the processing time in milliseconds proc DisplayProcessingTime {processingTime} { if {$processingTime < 1000} { return "processing time = $processingTime ms" } else { set seconds [expr $processingTime/1000] if {$seconds < 60} { return "processing time = $seconds s" } else { set minutes [expr $seconds/60] set seconds [expr $seconds%60] return "processing time = $minutes mn and $seconds s" } } } # DisplayProcessingTime - end # ---------------------------------------------------------------------- # GetSizeRecursively (3) proc GetSizeRecursively {varSizeName} { upvar var var upvar 2 $varSizeName varSize incr varSize [llength $var] return 0 } # GetSizeRecursively - end # ---------------------------------------------------------------------- # GetSize (1) proc GetSize {filePath resultRepository} { set argv 0 set initial [clock milliseconds] set filePath0 ../../../../../$resultRepository/doc/[file rootname [file tail $filePath]](size).txt file delete $filePath0 set contentType {} lappend contentType "date = [clock format [clock seconds] -format %Y-%m-%d]" lappend contentType "localtime = [clock format [clock seconds] -format %H:%M:%S]" lappend contentType "file path = $filePath" lappend contentType "action = GetSizeRecursively" source ../../../../../urlib.net/www/2021/07.02.22.22/doc/GetSizeRecursively.tcl set varSize 0 set action {GetSizeRecursively varSize} ProcessRecursively $filePath $action set final [clock milliseconds] lappend contentType [DisplayProcessingTime [expr $final - $initial]] lappend contentType "image size = $varSize" set contentType [join $contentType \n] puts $contentType Store contentType $filePath0 } # GetSize - end # ---------------------------------------------------------------------- if $argv { # usage examples console show source ../../../../../dpi.inpe.br/banon/1998/08.02.08.56/doc/utilities1.tcl ;# Store and StoreArray set imageDirectory ../../../../../urlib.net/www/2021/07.14.21.56/doc set resultRepository urlib.net/www/2021/07.14.21.56 set switchNumber 7 switch $switchNumber 0 { set filePath $imageDirectory/MCP_mascara-distancia-presenca-agua-area-aberta-cana-F5x5_32723(0).asc puts "file path = $filePath" puts [GetHeader $filePath] return } 1 { set filePath $imageDirectory/arquivo_masc-Teste_.txt ;# data } 2 { set filePath $imageDirectory/_masc_distCanaArAbertaAgua_MB2016F5x5_GRR.txt } 3 { set filePath $imageDirectory/MCP_masc-dist-agua-aberta-cana_GRR.txt ;# 14 s } 4 { set filePath $imageDirectory/SP_masc-dist-agua-aberta-cana_GRR.txt ;# 1 mn and 59 s - 731581396 } 5 { set filePath $imageDirectory/MCP_mascara-distancia-presenca-agua-area-aberta-cana-F5x5_32723.asc ;# processing time = 15 s; image size = 90600705 set filePath $imageDirectory/MCP_mascara-distancia-presenca-agua-area-aberta-cana-F5x5_32723(square_pixel).asc } 6 { set filePath $imageDirectory/MPO_mascara25-uniao-hidrografia-area-aberta-MapBiomas_32723.asc ;# processing time = 15 s; image size = 90600705 } 7 { # set filePath $imageDirectory/MCP_mascara-porcentagem-formacao-florestal-F7x7_32723(corner_taken)(160,549).asc set filePath $imageDirectory/MCP_mascara-porcentagem-formacao-florestal-F7x7_32723(corner_taken)(160,660).asc } GetSize $filePath $resultRepository } # Previous textual results if 0 { file path = ../../../../../urlib.net/www/2021/07.14.21.56/doc/SP_masc-dist-agua-aberta-cana_GRR.txt action = GetSizeRecursively # image size = -645592108 processing time = 1 mn and 59 s image size = 731581396 ### NCOLS -30722 NROWS 21014 XLLCORNER -351770.902100 YLLCORNER 7170512.909200 CELLSIZE 26.990000 NODATA_VALUE -9.999000000e+003 No. de colunas = 34814 No. de linhas = 21014 expr 21014*34814 # => 731581396 }