Synopsys Sentaurus TCAD系列教程之-Tcl《3》

Tool command language(Tcl)

3. 其它有用的Tcl命令

TCAD Sentaurus工具引入更高级的Tcl命令

3.1文件输入和输出

  • 使用open函数打开文件:

    set FIDw [open Writing.tmp "w"]

    这里以写的方式打开文件Writing.tmp。FIDw是一个常规的Tcl变量,它包含文件标识符。

  • 使用put 命令写入打开的文件:

   puts $FIDw "This is the first line of this file"
   puts $FIDw $ABCList
  • 使用close命令关闭文件:
    close $FIDw
  • 以读的方式打开文件
    set FIDr [open Writing.tmp "r"]
  • gets命令逐行读取文件
	while { [gets $FIDr NewLine] > 0 } {                       #NewLine是固定必须的关键词?
	  	puts $NewLine
	  }
	  close $FIDr
	  #-> This is the first line of this file
	  #-> a b c d e f

这里,while循环检测文件的结尾。gets命令返回读取的字节数。如果gets到达文件末尾,它将返回-1.while循环将测试此条件。

  • 使用read命令将文件作为单个数据块读取
	 set FIDr [open Writing.tmp "r"]
	 set DATA [read $FIDr]
	 puts $DATA
	 close $FIDr
	 #-> This is the first line of this file
	 #-> a b c d e f

包含特殊Tcl字符的文件通常无法逐行读取。read命令没有这些问题。

3.2 格式化输出

使用格式函数控制打印期间变量的格式:

set pi [ expr 2.0*asin(1.0) ]
puts "pi unformated :$pi"
#-> pi unformated: 3.141592

puts "pi with 2 digits :[format %.2f $pi]"
#-> pi with 2 digits : 3.14

puts "pi in exponential format: [format %.4e $pi]"
#-> pi in exponential format: 3.1416e+00

set i 24
puts "Integer with leading zeros: >[format %05d $i]<"
#-> Integer with leading zeros: >00
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值