2008/07/10

執行 nam 時出現 "Missing required flag" error

Reference: http://mailman.isi.edu/pipermail/ns-users/2003-April/031477.html

Problem: ns2 在執行 nam 在模擬結束時出現出現以下錯誤


Missing required flag -x in: W -t 5.0

Missing required flag -y in: W -t 5.0

Parsing error in event.



Solution:
發生的原因是因為找不到 nam 檔寫入
也就是說寫了關閉 nam 檔後
仍然有資料要寫入 nam 檔
因此要解決就是關閉 nam 檔前
tcl 要先執行到 $ns at $opt(stop) "$ns nam-end-wireless $opt(stop)"

關閉模擬的 example:
[code]set opt(stop) 5.0 ;# time of simulation end

# Create a ns simulator
set ns [new Simulator]

# ...

# Open the NS trace file
$ns use-newtrace
set tracefile [open out.tr w]
$ns trace-all $tracefile

# Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $opt(x) $opt(y)

# ...

#===================================
# Termination
#===================================

# Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile opt
$ns at $opt(stop) "$ns nam-end-wireless $opt(stop)"
$ns flush-trace
close $tracefile
close $namfile

puts "done"
$ns halt

puts "running nam..."
exec nam out.nam &
exit 0
}
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns at $opt(stop) "$node($i) reset"
}
$ns at $opt(stop) "finish"

puts "Starting Simulation..."
$ns run[/code]

No comments:

Post a Comment