【问题标题】:Terminal path tcl终端路径 tcl
【发布时间】:2014-09-01 10:05:35
【问题描述】:

你好,我试图在终端中调用这个 tcl,但它给了我这个错误

num_nodes is set 0
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
can't read "node_(0)": no such variable
while executing
"$node_(0) set X_ 133.516460138239"
(file "/tmp/mob.tcl" line 4)
invoked from within
"source.orig /tmp/mob.tcl"
("uplevel" body line 1)
invoked from within
"uplevel source.orig [list $fileName]"
invoked from within
"if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
..."
(procedure "source" line 8)
invoked from within
"source  "/tmp/mob.tcl" "
(file "mobilita_source.tcl" line 125)

而tcl文件是

#定义离子

   set val(chan)    Channel/WirelessChannel     ;# channel type
   set val(prop)    Propagation/TwoRayGround    ;# radio-propagation model
   set val(netif)   Phy/WirelessPhy         ;# network interface type

   set val(mac) Mac/802_11           ; # MAC type
     Mac/802_11 set RTSThreshold_ 500  ;            
     Mac/802_11 set dataRate_ 24Mb   ;
     Mac/802_11 set basicRate_ 6Mb   ;
     Mac/802_11 set CWMin_ 31    ;
     Mac/802_11 set CWMAX_ 1023  ;
     Mac/802_11 set SlotTime_ 0.000009 ;    
     Mac/802_11 set SIFS_ 0.000016    ;
     Mac/802_11 set ShortRetryLImit_ 7 ;
     Mac/802_11 set LOngRetryLimit_ 7  ;


     set val(ifq)   Queue/DropTail/PriQueue     ;# interface queue type
     set val(ifqlen)        50              ;# max packet in ifq
     set val(ll)    LL              ;# link layer type
     set val(ant)   Antenna/OmniAntenna     ;# antenna model
     set val(adhocRouting)   AODV           ;# routing protocol


      set val(x)        250             ;# X dimension of the topography
      set val(y)        250             ;# Y dimension of the topography

      set val(tr)       esercizio1.tr       ;# trace file
      set val(rate)           [lindex $argv 0]  ;
      set val(nn)             [lindex $argv 1]        ;# how many nodes are simulated
      set val(stop)     [lindex $argv 3]    ;# simulation time
      set val(seed)     0.0

# 主程序

# Initialize Global Variables

# create simulator instance

 set ns_        [new Simulator]

 # define topology

 set topo   [new Topography]
 $topo load_flatgrid $val(x) $val(y)

 # create trace object for ns and nam

 set tracefd    [open $val(tr) w]

 $ns_ trace-all $tracefd



 $ns_ use-newtrace 



 # Create God

 set god_ [create-god $val(nn)]         

 # define how node should be created

 #global node setting

  $ns_ node-config  -adhocRouting $val(adhocRouting) \
     -llType $val(ll) \
     -macType $val(mac) \
     -ifqType $val(ifq) \
     -ifqLen $val(ifqlen) \
     -antType $val(ant) \
     -propType $val(prop) \
     -phyType $val(netif) \
     -channelType $val(chan) \
     -topoInstance $topo \
     -agentTrace ON \
     -routerTrace ON \
     -macTrace ON


   #  Create the specified number of nodes [$val(nn)] and "attach" them  to the channel

  for {set i 0} {$i < $val(nn) } {incr i} {
  set node_($i) [$ns_ node] 
  }


  # Define node positions

   source  "/tmp/mob.tcl" 

  # Define traffic flows

  source "traffic"

  for {set i 0} {$i < 4 } {incr i} {

  $cbr_($i) set interval_ [ expr 1 /$rate ]

  }




  # Tell nodes when the simulation ends

  for {set i 0} {$i < $val(nn) } {incr i} {
  $ns_ at $val(stop).000000001 "$node_($i) reset";
  }

  $ns_ at $val(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"


  puts "Starting Simulation..."
  $ns_ run

我从终端调用了 ns mobilita_source,但它描述了我,所以我认为它可能是 mobilita_souce.tcl 文件中的路径 /tmp。在 tmp 我注意到该文件存在。

【问题讨论】:

    标签: tcl ns2


    【解决方案1】:

    变量node_(0)没有设置,所以变量不可读。这意味着设置它的代码没有运行,可能是因为变量val(nn) 包含0,或者可能是因为它包含其他值——可能是非数字——排序小于1空字符串就是这样一个值val(nn) 的值来自 lindex $argv 1,因此它是您传递给可执行文件以调用程序的 Tcl 脚本之后的第二个参数(假设它类似于 tclsh)。

    如果参数不足,您将从lindex 获得一个空字符串(出于向后兼容的原因,超出范围的lindex 会生成一个空字符串而不是引发错误)。建议您明确检查是否传入了足够的参数:

    if {[llength $argv] < 4} {
        error "missing arguments, needs: rate, nn, ??, seed"
    }
    

    然后您可以(假设 Tcl 8.5 或 8.6)使用 lassign 将它们写入变量;它比一堆set … [lindex $argv …] 更清晰一点,更容易正确:

    # your posted code ignores one argument...
    lassign $argv val(rate) val(nn) ?? val(seed)
    

    在 8.4 及之前的版本(现在是过时的版本)中,您应该这样做:

    foreach $argv {val(rate) val(nn) ?? val(seed)} break
    

    但这真的不是很清楚。

    【讨论】:

      猜你喜欢
      • 2014-08-30
      • 2016-09-16
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多