1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
|
#!/usr/bin/wish -f
package require BLT
set datafile [lindex $argv 0]
# the Cartesian Coordinate Window
toplevel .rectangular
raise .rectangular
wm title .rectangular "Cartesian Coordianates"
wm geometry .rectangular +50+50
wm iconname .rectangular "Cartesian"
raise .rectangular
lower .
# controls
frame .rectangular.geometry2
frame .rectangular.controls
pack .rectangular.geometry2 .rectangular.controls
#the Cartesian coordinate system
blt::graph .rectangular.cartesian -title "X-Y Power Plane Cartesian Coordinates"
pack .rectangular.cartesian -in .rectangular.geometry2
button .rectangular.controls.postscript -text "Save to Postscript File" -command {
.rectangular.cartesian postscript output "rectangular.ps"
}
button .rectangular.controls.quit -text "quit" -command {exit}
pack .rectangular.controls.postscript .rectangular.controls.quit
###################### now on to the real action
set maxgain 0
set f [open $datafile]
####################### try for impendance and SWR
# We will store them in lists
set taglist {}
set ZRlist {}
set ZIlist {}
set Zlist {}
set SWRlist {}
# first, run through the output looking for the right section
while { [gets $f line ] >= 0 } {
if { [regexp {ANTENNA INPUT} $line ] } {
break
}
}
# we are after the impedance and SWR - skip three lines
gets $f line
gets $f line
gets $f line
# from here, the impedance is buried in the next non-blank lines.
# NEC actually will force us to "count columns" I'm afraid
# the format of the line is
# 2 11-1.00000E+00 0.00000E+00-1.72281E-03 4.25444E-04 5.47085E+02 1.35101E+02 1.72281E-03-4.25444E-04 8.61404E-04
#012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
# tagnumber 0-5
# segment number 6-11
# voltage (real) 12-23
# voltage (imag) 24-35
# current (real) 36-47
# current (imag) 48-59
# impedance (real) 60-71
# impedance (imag) 72-83
# admittance (real) 84-95
# admittance (imag) 96-107
# power 108-119
# all I really need is the tagnumber, the segment number, and the real and imaginary
# impedance
# read the next line
gets $f line
while {[string length $line] > 0 } {
# puts "impedance line $line"
set tagnumber [string range $line 0 5]
lappend taglist $tagnumber
set segmentnumber [string range $line 6 11]
set Zr [string range $line 60 71]
lappend Zrlist $Zr
set Zi [string range $line 73 83]
# puts "Z is $Zr + j * $Zi"
lappend Zilist $Zi
gets $f line
# puts "$tagnumber - $segmentnumber Zr $Zr Zi $Zi"
set normZ [ expr sqrt ( $Zr * $Zr + $Zi * $Zi) ]
lappend Zlist $normZ
# puts "|Z| is $normZ"
set gamma [expr sqrt( (($Zr - 52) *($Zr - 52) + $Zi * $Zi )/( ($Zr + 52) * ($Zr + 52) + $Zi * $Zi ) ) ]
set SWR [expr (1 + $gamma) /(1 - $gamma)]
# puts "SWR is $SWR to 1"
lappend SWRlist $SWR
}
#### end of impedance and SWR section
### on to the radiation patterns
while { [gets $f line ] >= 0 } {
if { [regexp {RADIATION} $line ] } {
break
}
}
# we skip seven lines and then start loading the vectors
gets $f line
gets $f line
gets $f line
gets $f line
gets $f line
gets $f line
gets $f line
# now start the loop again, loading the vectors
# We assume we are doing an azimuth plot and that
# we are using one of our "standard RP cards" so that
# there will be at most 360 entries for gain.
## RP 0 180 1 1001 -90.0 0.0 1.0 0.0 10000.0 0.00E+00
#
# a line consists of several fields ---
# the first is elevation
# the second is azimuth
# the third and fourth are components
# the fifth is gain
# the rest are junk
blt::vector gain(181)
blt::vector angle(181)
# cell counter
set count 0
while { [gets $f line ] >= 0 } {
scan $line "%f %f %f %f %f %f %f %s %f %f %f %f" e0 a0 junk1 junk2 g0 junk3 junk4 junk5 junk6 junk7 junk8 junk9
# if the gain is very small, just set it to about -60
if {$g0 <= -60.0} {
set g0 -60.0
}
set gain($count) $g0
set angle($count) [expr 180 - $count ]
# puts "angle - $angle($count) --- gain : $gain($count)"
# if I find a blank line, I just quit
if {[string length $line] == 0} {
break
}
set count [expr $count + 1]
}
close $f
blt::vector negangle(181)
negangle set [angle - 90 ]
negangle set [negangle * -1]
# a Cartesian graph is easy
.rectangular.cartesian axis configure "x" -step 60.0
set mingain $gain(min)
set maxgain $gain(max)
##########################################################
# we need to find the angles for which maxgain occurs
# maxgain is at these angles -- caution - may be a list
set maxangles [gain search $maxgain]
# maxangles may be a list and we must subtract 90 from each
set fixedmaxangles {}
foreach maxangle $maxangles {
set y [expr $maxangle - 90]
lappend fixedmaxangles $y
}
#puts "list of fixedmaxangles is $fixedmaxangles"
##########################################################
.rectangular.cartesian element create "e1" -label "Cartesian" \
-xdata negangle -ydata gain \
-label "Max Gain is $maxgain" \
-symbol "none"
# we need to scale the gain vector by adding the minimum gain
# to each entry
blt::vector newgain(180)
newgain set [gain - $mingain]
#################################### Polar Coordinates part
# the linear Polar Coordinate Window
toplevel .polar
raise .polar
wm title .polar "Cartesian Coordianates"
wm geometry .polar +100+100
wm iconname .polar "Polar"
raise .polar
blt::graph .polar.graph -title "X-Y Linear Power Polar Graph" -width 600 -height 450
frame .polar.controls
pack .polar.graph .polar.controls
button .polar.controls.quit -text "Quit" -command {exit}
button .polar.controls.postscript -text "Save to Postscript File" -command {
.polar.graph postscript output "polar.ps"
}
pack .polar.controls.postscript .polar.controls.quit
# create two vectors to contain the points
blt::vector x(181) y(181)
# create a unit circle line
blt::vector yDB(181)
blt::vector xDB(181)
for {set i 0} {$i <= 180} {incr i 1} {
set radians [expr $angle($i) * 3.14159/180.0 ]
set x($i) [expr cos($radians) * $newgain($i)]
set y($i) [expr sin($radians) * $newgain($i)]
set xDB($i) cos($radians)
set yDB($i) sin($radians)
}
.polar.graph element create "e1" -label "Gain" \
-xdata x -ydata y \
-color red \
-symbol "none"
################################################
######## put the scales on the graph
# create a 0 DB line
set scale $newgain(max)
set originalscale $scale
blt::vector x0db(181)
blt::vector y0db(181)
y0db set [yDB * $scale]
x0db set [xDB * $scale]
# we need to put radials on the graph
for {set i 0} {$i < 181} {incr i 5} {
blt::vector pgridx${i}(2)
blt::vector pgridy${i}(2)
set pgridx${i}(0) 0
set pgridy${i}(0) 0
set pxlabel [expr $originalscale * $xDB($i)]
set pgridx${i}(1) $pxlabel
set pylabel [expr $originalscale * $yDB($i)]
set pgridy${i}(1) $pylabel
set widthofline 1
if { ($i % 30 ) == 0 } {
set widthofline 2
set textlabel [expr $i - 90]
.polar.graph marker create text -name polar_marker${i} \
-text "$textlabel" -xoffset 10 -yoffset 10 \
-coords { $pxlabel $pylabel}
}
.polar.graph element create "line$i" \
-xdata pgridx${i} -ydata pgridy${i} \
-color cyan \
-label "" \
-symbol "none" -linewidth $widthofline
}
#####################################
# put the data on the graph, with maxgain at 0DB
.polar.graph element create "e2" -label "0 DB reference is $maxgain" \
-xdata x0db -ydata y0db \
-color blue \
-symbol "none"
# bottom half of the circle
blt::vector yref(181)
yref set [y0db * -1]
.polar.graph element create "bottom" -label "" \
-xdata x0db -ydata yref \
-color white \
-symbol "none"
######################### linear log scale here
## build a loop to put each of the grid lines on the graph
set counter 0
while {$scale > 10} {
set counter [expr $counter + 10]
blt::vector x${counter}(181)
blt::vector y${counter}(181)
set scale [expr $scale - 10]
x${counter} set [xDB * $scale]
y${counter} set [yDB * $scale]
.polar.graph element create "e$scale" -label "-$counter DB" \
-xdata x${counter} -ydata y${counter} \
-color blue \
-symbol "none"
}
# end of linear polar coordinate window
#################################### ARRL Polar
# the ARRL Coordinate Window
toplevel .arrl
raise .arrl
wm title .arrl "ARRL Scale Power Polar Coordianates"
wm geometry .arrl +150+150
wm iconname .arrl "arrl"
raise .arrl
blt::graph .arrl.graph -title "X-Y ARRL Power Graph" -width 600 -height 450
frame .arrl.controls
pack .arrl.graph .arrl.controls
button .arrl.controls.quit -text "Quit" -command {exit}
button .arrl.controls.postscript -text "Save to Postscript File" -command {
.arrl.graph postscript output "arrl.ps"
}
pack .arrl.controls.postscript .arrl.controls.quit
lower .
# create two vectors to contain the points
# original data is in newgain vector
blt::vector xarrl(181) yarrl(181)
for {set i 0} {$i <= 180} {incr i 1} {
set radians [expr $angle($i) * 3.14159/180.0 ]
set xarrl($i) [expr cos($radians) * exp(0.43439/0.98*$newgain($i)/10)]
set yarrl($i) [expr sin($radians) * exp(0.43439/0.98*$newgain($i)/10)]
}
.arrl.graph element create "e1" -label "Gain" \
-xdata xarrl -ydata yarrl \
-color red \
-symbol "none"
################################################
######## put the scales on the graph
# create a 0 DB line
set originalscale $newgain(max)
blt::vector x0dbarrl(181)
blt::vector y0dbarrl(181)
blt::vector y0neg(181)
#set up the data on the graph
for {set i 0} {$i <= 180} {incr i 1} {
set y0dbarrl($i) [expr exp(0.43439/0.98*$originalscale/10.0) * $yDB($i)]
set x0dbarrl($i) [expr exp(0.43439/0.98*$originalscale/10.0) * $xDB($i)]
}
y0neg set [y0dbarrl * -1]
#####################################
# put the data on the graph, with maxgain at 0DB
.arrl.graph element create "e2" -label "0 DB reference is $maxgain" \
-xdata x0dbarrl -ydata y0dbarrl \
-color blue \
-symbol "none"
.arrl.graph element create "nege2" -label "" \
-xdata x0dbarrl -ydata y0neg \
-color white \
-symbol "none"
######################### ARRL log scale here
## build a loop to put each of the grid lines on the graph
set counter 0
set arrlsteps {3 6 10 20 30 40 50 60 70 80}
set scale $originalscale
# we need to put radials on the graph
for {set i 0} {$i <= 180} {incr i 5} {
blt::vector gridx${i}(2)
blt::vector gridy${i}(2)
set gridx${i}(0) 0
set gridy${i}(0) 0
set xlabel [expr exp(0.43439/0.98*$originalscale/10.0) * $xDB($i)]
set gridx${i}(1) $xlabel
set ylabel [expr exp(0.43439/0.98*$originalscale/10.0) * $yDB($i)]
set gridy${i}(1) $ylabel
set widthofline 1
if { ($i % 30 ) == 0 } {
set widthofline 2
set textlabel [expr $i - 90]
.arrl.graph marker create text -name first_marker{$i} \
-text "$textlabel" -xoffset 10 -yoffset 10 \
-coords { $xlabel $ylabel}
}
.arrl.graph element create "l$i" \
-xdata gridx${i} -ydata gridy${i} \
-color cyan \
-label "" \
-symbol "none" -linewidth $widthofline
}
#radials
while {$scale > 10} {
set thisstep [lindex $arrlsteps $counter]
set counter [expr $counter + 1]
blt::vector xarrl${counter}(181)
blt::vector yarrl${counter}(181)
set scale [expr $originalscale - $thisstep ]
xarrl${counter} set [yDB * $scale]
yarrl${counter} set [xDB * $scale]
#set up the data on the graph
for {set i 0} {$i <= 180} {incr i 1} {
set yarrl${counter}($i) [expr exp(0.43439/0.98*$scale/10.0) * $yDB($i)]
set xarrl${counter}($i) [expr exp(0.43439/0.98*$scale/10.0) * $xDB($i)]
}
.arrl.graph element create "e$scale" -label "-$thisstep DB" \
-xdata xarrl${counter} -ydata yarrl${counter} \
-color blue \
-symbol "none"
}
# end of linear ARRL coordinate window
##########################################################
################## The Factlist window
toplevel .facts
raise .facts
wm title .facts "Fact List"
wm geometry .facts +200+200
wm iconname .facts "Facts"
raise .facts
lower .
frame .facts.controls
frame .facts.text
pack .facts.text .facts.controls
button .facts.controls.quit -text "Quit" -command {exit }
pack .facts.controls.quit -in .facts.controls
listbox .facts.text.box -width 70 -yscrollcommand ".facts.text.scroller set" \
-background white
scrollbar .facts.text.scroller -command ".facts.text.box yview" \
-background blue
pack .facts.text.box .facts.text.scroller -fill y -in .facts.text -side left
.facts.text.box insert end "Maximum gain is $maxgain"
.facts.text.box insert end ""
.facts.text.box insert end "Maximum gain occurs at these angles: $fixedmaxangles"
.facts.text.box insert end ""
.facts.text.box insert end "Here is a list of the feed points wire tags, with impedances and SWR"
.facts.text.box insert end "tag number complex impedance |Z| SWR"
foreach ofthetag $taglist {
set indexnumber [lsearch $taglist $ofthetag]
set ZR [lindex $Zrlist $indexnumber]
set ZI [lindex $Zilist $indexnumber]
set Zed [lindex $Zlist $indexnumber]
set SWR [lindex $SWRlist $indexnumber]
.facts.text.box insert end "$indexnumber $ZR + $ZI * j $Zed $SWR - 1"
}
|