2015-12-17 47 views
0

我試圖運行一個Tcl腳本,它從輸入文件(其中幾何體被定義)創建一個幾何文件。該腳本可以像script.tcl inputfile那樣運行。 當我使用任何願望或命令tclsh的運行它(在Mac和Linux上),我得到這個錯誤:Tcl腳本無法讀取「startreg(1)」:沒有這樣的變量

 can't read "startreg(1)": no such variable 
     while executing 
    "if { $startreg($i)==0 && $stopreg($i)==0 } { 
      # All are material 1, change nothing 
      } else { 
      for {set iz $startz($i)} {$iz<=$stopz($i)} {incr i..." 
     invoked from within 
    "if [string compare $descrip regions]==0 { 
     # Get the mednum, start and stop regions 
     seek $fileid $startpos start 
     while { [eof $fileid] != 1 } { 
      ..." 
     (procedure "read_inputfile" line 214) 
     invoked from within 
    "read_inputfile " 
     invoked from within 
    "if [file exists $inputfile]==1 { 
     read_inputfile 
    } else { 
     puts "The file $inputfile doesn't exist!" 
     exit 
    }" 
     (file "~/EGS_Windows/preview3d.tcl" line 580) 

任何幫助/建議將不勝感激! TA

回答

2

你顯然沒有初始化那個變量。

% array set startreg {} 
% puts $startreg(1) 
can't read "startreg(1)": no such element in array 
% unset startreg 
% puts $startreg(1) 
can't read "startreg(1)": no such variable 

startreg一個全局變量,你在一個進程忘了global startreg


我發現另一個錯誤的堆棧跟蹤

if [string compare $descrip regions]==0 { 

你肯定希望周圍的狀況牙套,所以,當你希望執行它,則執行測試:

if {[string compare $descrip regions]==0} { 

這適用於所有if表達式,以及所有expr會話。見本維基頁面:http://wiki.tcl.tk/10225

在這種情況下,if {$descrip eq "regions"}更清晰。

+0

感謝@glennjackman的回覆,我不熟悉Tcl腳本,這是我第一次。 – TUA

+0

我強烈建議通過[Tcl教程](http://tcl.tk/man/tcl8.5/tutorial/tcltutorial.html) –

+0

謝謝@glennjackman,我下載了該腳本,我認爲它已準備好沒有任何修改。 – TUA

相關問題