# ---------------------------------------------------------------------- # ComputeHistogram proc ComputeHistogram {varName histogramArrayName noDataCounterName lowerBound upperBound numberOfInterval noData} { upvar $varName var upvar $histogramArrayName histogramArray upvar $noDataCounterName noDataCounter # set noDataCounter 0 set intervalSize [expr ($upperBound - $lowerBound)/$numberOfInterval] foreach value $var { # if [string equal $noData $value] {incr noDataCounter; continue} if [expr $value == $noData] {incr noDataCounter; continue} ;# -9999.0 == -9999 incr histogramArray([expr int(($value - $lowerBound)/$intervalSize)]) } # return [list [array get histogramArray] $noDataCounter] } # ComputeHistogram - end # ---------------------------------------------------------------------- if $argv { # usage examples set argv 0 console show set initial [clock milliseconds] set switchNumber 4 switch $switchNumber 1 { set filePath ./image/arquivoTeste.txt set lowerBound 0 set upperBound 3552.935059 set numberOfInterval 20 set noData -9.999000000e+003 } 2 { set filePath ./image/distCanaArAbertaAguaMB2016F5x5_GRR.txt set lowerBound 0 set upperBound 22660.839844 set numberOfInterval 20 set noData -9.999000000e+003 } 3 { set filePath ./image/MCP_masc-dist-agua-aberta-cana_GRR.txt ;# 19220 ms set lowerBound 0 set upperBound 161935.890625 set upperBound 8096.8 set upperBound 3148.8 set numberOfInterval 20 set numberOfInterval 18 set numberOfInterval 20 set noData -9.999000000e+003 } 4 { set imageDirectory ../../../../../urlib.net/www/2021/07.14.21.56/doc set resultRepository urlib.net/www/2021/07.14.21.56 set filePath $imageDirectory/MCP_mascara-porcentagem-formacao-florestal-F7x7_32723(corner_taken)(160,660).asc set lowerBound 0 set upperBound 100 set numberOfInterval 10 set noData -9999 } source LoadBigImage.tcl LoadBigImage $filePath data # array set histogramArray {} if [info exists histogramArray] {unset histogramArray} for {set i 0} {$i <= $numberOfInterval} {incr i} { set histogramArray($i) 0 ;# some interval might stay empty } set noDataCounter 0 # set output [ComputeHistogram data $lowerBound $upperBound $numberOfInterval] # foreach {histogram noDataCounter} $output {break} ComputeHistogram data histogramArray noDataCounter $lowerBound $upperBound $numberOfInterval $noData set final [clock milliseconds] puts "processing time = [expr $final - $initial] ms" puts "noDataCounter = $noDataCounter" # array set histogramArray $histogram set intervalSize [expr ($upperBound - $lowerBound)/$numberOfInterval] set upperBoundLength [string length [expr int($upperBound)].0] set histogramIntegral 0 for {set i 0} {$i <= $numberOfInterval} {incr i} { incr histogramIntegral $histogramArray($i) } # puts $histogramIntegral set histogramIntegralLength [string length $histogramIntegral] # set total [expr [llength $data] - $noDataCounter] for {set i 0} {$i <= $numberOfInterval} {incr i} { puts "[format "%3s %${histogramIntegralLength}s %5.1f" $i $histogramArray($i) [expr 100*$histogramArray($i)/$histogramIntegral.]]% [format "\[%$upperBoundLength.1f, %$upperBoundLength.1f\[" [expr $i*$intervalSize] [expr ($i + 1)*$intervalSize]]" } # processing time = 358981 ms # noDataCounter = 48061904 # 0 22446380 52.8% [ 0.0, 8096.8[ # 1 2409807 5.7% [ 8096.8, 16193.6[ # 2 2250293 5.3% [ 16193.6, 24290.4[ # 3 1778691 4.2% [ 24290.4, 32387.2[ # 4 1428324 3.4% [ 32387.2, 40484.0[ # 5 1338965 3.1% [ 40484.0, 48580.8[ # 6 1352132 3.2% [ 48580.8, 56677.6[ # 7 1338281 3.1% [ 56677.6, 64774.4[ # 8 1288902 3.0% [ 64774.4, 72871.2[ # 9 1251246 2.9% [ 72871.2, 80967.9[ # 10 1216446 2.9% [ 80967.9, 89064.7[ # 11 1184354 2.8% [ 89064.7, 97161.5[ # 12 1162761 2.7% [ 97161.5, 105258.3[ # 13 1117570 2.6% [105258.3, 113355.1[ # 14 726987 1.7% [113355.1, 121451.9[ # 15 238983 0.6% [121451.9, 129548.7[ # 16 5237 0.0% [129548.7, 137645.5[ # 17 1681 0.0% [137645.5, 145742.3[ # 18 907 0.0% [145742.3, 153839.1[ # 19 852 0.0% [153839.1, 161935.9[ # 20 1 0.0% [161935.9, 170032.7[ # processing time = 192760 ms # noDataCounter = 48061904 # 0 2531801 11.2% [ 0.0, 449.8[ # 1 3457463 15.3% [ 449.8, 899.6[ # 2 3482668 15.4% [ 899.6, 1349.5[ # 3 3071550 13.6% [1349.5, 1799.3[ # 4 2489991 11.0% [1799.3, 2249.1[ # 5 1921157 8.5% [2249.1, 2698.9[ # 6 1405057 6.2% [2698.9, 3148.8[ # 7 1012777 4.5% [3148.8, 3598.6[ # 8 744415 3.3% [3598.6, 4048.4[ # 9 532958 2.4% [4048.4, 4498.2[ # 10 377964 1.7% [4498.2, 4948.0[ # 11 295413 1.3% [4948.0, 5397.9[ # 12 248790 1.1% [5397.9, 5847.7[ # 13 214526 0.9% [5847.7, 6297.5[ # 14 183064 0.8% [6297.5, 6747.3[ # 15 168869 0.7% [6747.3, 7197.2[ # 16 158590 0.7% [7197.2, 7647.0[ # 17 149347 0.7% [7647.0, 8096.8[ # 18 139934 0.6% [8096.8, 8546.6[ # processing time = 336098 ms # noDataCounter = 48061904 # 0 707579 3.8% [ 0.0, 157.4[ # 1 929081 5.0% [ 157.4, 314.9[ # 2 1070863 5.7% [ 314.9, 472.3[ # 3 1159812 6.2% [ 472.3, 629.8[ # 4 1232849 6.6% [ 629.8, 787.2[ # 5 1242328 6.6% [ 787.2, 944.6[ # 6 1250655 6.7% [ 944.6, 1102.1[ # 7 1198119 6.4% [1102.1, 1259.5[ # 8 1180865 6.3% [1259.5, 1417.0[ # 9 1107221 5.9% [1417.0, 1574.4[ # 10 1040883 5.6% [1574.4, 1731.8[ # 11 965781 5.1% [1731.8, 1889.3[ # 12 892900 4.8% [1889.3, 2046.7[ # 13 827538 4.4% [2046.7, 2204.2[ # 14 761247 4.1% [2204.2, 2361.6[ # 15 688941 3.7% [2361.6, 2519.0[ # 16 614604 3.3% [2519.0, 2676.5[ # 17 552697 2.9% [2676.5, 2833.9[ # 18 491384 2.6% [2833.9, 2991.4[ # 19 445178 2.4% [2991.4, 3148.8[ # 20 392618 2.1% [3148.8, 3306.2[ }