以下代码
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf[open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute namon the trace file
exec nam–a out.nam&
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
产生此错误
can't read "nffile5": no such variable
while executing
"set nf[open out.nam w]"
(file "Desktop/sample.tcl" line 4)
这是我第一次来 tcl。那么有什么问题。我只是通过以下语句运行它:> ns sample.tcl