吹泡泡的小鱼的个人空间 https://blog.eetop.cn/layoutart [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

SKILL语言的输入与输出

热度 2已有 5160 次阅读| 2019-10-11 16:27 |个人分类:SKILL|系统分类:芯片设计| SKILL, 输入, 输出

Skill可以把输出卸载CIW窗口,同时还可以对文件进行读入和写入
(一)输出显示和输出到文件
(1)print()和println()
print() println() 两个函数都可以用来显示单个数据,println可以在显示的数据后多加一个回车。
for(i 1 3 print( "hello" ))     ;prints hello three times.
返回值是:"hello""hello""hello"
for(i 1 3 println( "hello" ))  ;prints hello three times.
返回值是:
"hello"
"hello"
"hello"

(2)printf ()函数是格式化的输出(对于格式化输出后面会讲),下面的例子是一定格式输出图形层的统计。
printf("\n%-15s %-15s %-10d %-10d %-10d %-10d"
layerNamepurpose rectCount labelCount lineCount miscCount
)
对应参数的意义如下,printf需要注意输出类型的对应,一般格式如下:
printf("%[-][width][.precision]"  conversion_code)
-表示左对齐,width表示位数,.precision表示精度 ,conversion_code部分一般是变量

对于精度
d表示整数,f表示浮点数,s表示string或者symbol,c表示字符,n表示数字,L表示list,P表示point list,B表示Bounding box。
(3)print( ) , println( ) , fprintf( )输出到接口文件
想输出内容到一个文件,首先用outfile来定义输出接口文件,然后用print println fprintf输出到接口文件, 最后close关闭打开的接口,具体见下面的例子。
例子一:
myPort= outfile( "/tmp/myFile1" )
for(i 1 3
println( list( "Number:" i) myPort )
)
close(myPort )
输出到文件/tmp/myFile1.
("Number:"1)
("Number:"2)
("Number:"3)
例子二:
myPort= outfile( "/tmp/myFile2" )
for(i 1 3
fprintf( myPort "Number: %d\n" i ) ;注意printf函数不能输出到port
)
close(myPort )
输出到文件/tmp/myFile2.
Number:1
Number:2
Number:3
上面两个例子一个是用的println,一个使用fprintf,注意二者的区别,并且注意printf函数不能输出到port。
(二)从文件读取数据
如果想读入文件的内容,首先用intfile定义输入接口文件,然后用gets一次从接口文件读取一行字符串,或者用fscanf根据指定的格式从接口文件读取,最后用close关闭打开的接口。
下面例子实现的功能是:打开~/.cshrc,输出文件的每一行到CIW窗口的目的:
inPort= infile( "~/.cshrc" )
when(inPort
while( gets( nextLine inPort )
println( nextLine )
)
close(inPort )
)
下面例子实现的功能是:打开~/.cshrc,输出文件中的每一个字符串到CIW窗口:
inPort = infile( "~/.cshrc" )
when( inPort
while( fscanf( inPort"%s" word )
println( word )
)
close( inPort )
)

点赞

发表评论 评论 (2 个评论)

回复 fengtang2332 2021-4-14 16:02
您好。请问,为什么不论写入,还是读出接口文件后,都需要 close 接口?我看文档里也事这样说的,但是不是很理解为什么。
回复 GanKuaiMaiChe 2022-1-5 15:42
fengtang2332: 您好。请问,为什么不论写入,还是读出接口文件后,都需要 close 接口?我看文档里也事这样说的,但是不是很理解为什么。 ...
不关闭也可以获取

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 6

    关注
  • 96

    粉丝
  • 29

    好友
  • 117

    获赞
  • 46

    评论
  • 11388

    访问数
关闭

站长推荐 上一条 /1 下一条


小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-7-11 19:18 , Processed in 0.022263 second(s), 10 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部