calcRL_compare.tcl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. proc calcRL_compare { file1 file2 log } {
  2. #--------------------------------------------------------------
  3. # Open the first first file for the camparison.
  4. #--------------------------------------------------------------
  5. if { [catch { set f1 [open $file1 r] } result ] } {
  6. puts stderr "Could not open $file1"
  7. puts $log "Could not open $file1"
  8. return 1
  9. }
  10. #--------------------------------------------------------------
  11. # Get the data from the file.
  12. #--------------------------------------------------------------
  13. set data1 [ read $f1]
  14. close $f1
  15. #--------------------------------------------------------------
  16. # Open the second file for the comparison.
  17. #--------------------------------------------------------------
  18. if { [catch { set f2 [open $file2 r] } result ] } {
  19. puts stderr "Could not open $file2"
  20. puts $log "Could not open $file2"
  21. return 1
  22. }
  23. #--------------------------------------------------------------
  24. # Get the data from the file.
  25. #--------------------------------------------------------------
  26. set data2 [read $f2]
  27. close $f2
  28. set isCS 0
  29. set isResult 0
  30. #-------------------------------------------------------
  31. # Check if this is a result file.
  32. #-------------------------------------------------------
  33. if { [ string first "out" $file1] > 1 } {
  34. set indx [string first "equency" $data1]
  35. if { $indx < 1 } {
  36. puts stderr "The comparison failed!"
  37. puts $log "The comparison failed!"
  38. return 1
  39. }
  40. set data1 [string range $data1 [expr {$indx + 9}] \
  41. [string length $data1]]
  42. set indx [string first "requency" $data2]
  43. if { $indx < 1 } {
  44. puts stderr "The comparison failed!"
  45. puts $log "The comparison failed!"
  46. return 1
  47. }
  48. set data2 [string range $data2 [expr {$indx + 9}] \
  49. [string length $data2]]
  50. }
  51. #----------------------------------------------------------------------
  52. # Initialize.
  53. #----------------------------------------------------------------------
  54. set maxDiff 0
  55. set maxNum1 0
  56. set maxNum2 0
  57. set indx 0
  58. set total1 0
  59. set total2 0
  60. set cnt1 0
  61. foreach itm $data1 {
  62. #-------------------------------------------------------------------
  63. # Only process the items that are numbers.
  64. #-------------------------------------------------------------------
  65. if { [scan $itm {%f} num1 ] == 1 } {
  66. puts "$itm .. [lindex $data2 $indx]"
  67. update
  68. #---------------------------------------------------------------
  69. # Check that this index in the second data-set is also a number.
  70. #---------------------------------------------------------------
  71. if { [scan [lindex $data2 $indx] {%f} num2] < 1 } {
  72. break
  73. }
  74. if { $num1 != 0 } {
  75. set diff [expr { abs ( ($num1 - $num2) / $num1 ) * 100.0 }]
  76. set total1 [expr { $total1 + $diff }]
  77. incr cnt1
  78. #------------------------------------------------------------
  79. # Save the maximum diff from the comparisons.
  80. #------------------------------------------------------------
  81. if { $diff > $maxDiff } {
  82. set maxDiff $diff
  83. set maxNum1 $num1
  84. set maxNum2 $num2
  85. }
  86. }
  87. }
  88. incr indx
  89. }
  90. set total1 [expr { $total1 / $cnt1 }]
  91. puts stderr "-------------------------------------------------------------"
  92. puts stderr "Comparing:\t$file1\n \t$file2"
  93. set strg [format " Max Diff: %7.3f%s (%s : %s)" $maxDiff "\%" \
  94. $maxNum1 $maxNum2]
  95. puts stderr $strg
  96. if { ! $isCS } {
  97. set strg [format " Average Diff: %7.3f%s" $total1 "\%"]
  98. puts stderr $strg
  99. if { $isResult } {
  100. set total2 [expr { $total2 / $cnt2 }]
  101. set strg [format "(I - Rdc) Average Diff: %7.3f%s" $total2 "\%"]
  102. puts stderr $strg
  103. set strg [format " Total Average Diff: %7.3f%s" \
  104. [expr { $total1 + $total2 }] "\%"]
  105. puts stderr $strg
  106. }
  107. }
  108. puts $log "-------------------------------------------------------------"
  109. puts $log "Comparing:\t$file1\n \t$file2"
  110. set strg [format " Max Diff: %5.3f%s (%s : %s)" $maxDiff "\%" \
  111. $maxNum1 $maxNum2]
  112. puts $log $strg
  113. if { ! $isCS } {
  114. set strg [format " Average Diff: %7.3f%s" $total1 "\%"]
  115. puts $log $strg
  116. }
  117. return 0
  118. }