wangjicheng886的个人空间 https://blog.eetop.cn/1774723 [收藏] [复制] [分享] [RSS]

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

日志

skill language user guide 40--42

已有 390 次阅读| 2023-6-17 17:10 |系统分类:芯片设计

File Input/Output

This section introduces how to

■ Display values using default formats and application-specific formats 

■ Write UNIX text files 

■ Read UNIX text files


application-specific format  应用程序特定格式


Displaying Data

Display data using

■ The print and println functions

■ The printf function


The print and println Functions

The SKILL interpreter has a default display format for each kind of data. The print and  println functions use this format to display data.


the skill interpreter

Cadence Skill的解释器,它负责解析和执行Cadence Skill语言的代码。解释器会逐行读取代码,并按照其语法规则进行解释和执行,从而实现特定功能


Sample Display Formats

Data Type              Example of the Default Format

integer                   5 

floating point        1.3 

text string             "Mary learned SKILL" 

variable                 bBox 

list                         ( 1 2 3 )


The print and println functions display a single data value. 

println is the same as  print followed by a newline character. 


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"


注:

函数for是用来循环执行一段代码块多次的。

i:循环变量,用于迭代和计数。

1:循环变量的初始值,该值指定了循环的起始点。

3:循环条件,代表循环的结束点(不包括该值)。

println("hello"):要循环执行的代码块,即打印输出字符串"hello"

这个for循环将从i的初始值1开始,逐渐增加到3之前的数值。

在每次迭代中,会执行一次println("hello"),即打印输出字符串"hello"。

a newline character 换行符


The printf Function

The printf function writes formatted output. This example displays a line in a report.

printf( 

"\n%-15s %-15s %-10d %-10d %-10d %-10d" 

layerName purpose 

rectCount labelCount lineCount miscCount 

)

注:它使用 printf 函数来格式化输出字符串。

1)"\n%-15s %-15s %-10d %-10d %-10d %-10d" 是一个字符串模板,

       \n 表示换行

       %s 表示字符串,%-15s 要求输出左对齐最大长度为 15 的字符串,

      %d 表示整数,%-10d 要求输出左对齐最大长度为 10 的整数。

2)layerName, purpose, rectCount, labelCount, lineCount 和 miscCount 分别是需要输出的字符串和整数变量。

3)最终通过 printf 函数输出了一行数据,包括图层名称(layerName)、用途(purpose)、矩形数量(rectCount)、

     标签数量(labelCount)、线数量(lineCount)和杂项数量(miscCount)。


The first argument is a conversion control string containing directives.

%[-][width][.precision]conversion_code 

[-] = left justify 

[width] = minimum number of character positions 

[.precision] = number of characters to be printed 

conversion_code 

d - decimal(integer) 

f - floating point 

s - string or symbol 

c - character 

n - numeric 

L - list (Ignores width and precision fields.)

P - point list (Ignores width and precision fields.)

B - Bounding box list (Ignores width and precision fields.)


关于一些格式控制字符的解释,通常用于定义字符串格式化操作。其中每个控制字符一个字母表示一种类型的数据转换。

以下是单个字符控制符的含义:

d:代表十进制的整数。

f:代表浮点数。

s:代表字符串或标识符。

c:代表字符。

n:代表数字。

L:代表列表(忽略宽度和精度字段)。

P:代表点列表(忽略宽度和精度字段)。

B:代表边界框列表(也忽略宽度和精度字段)。

使用这些控制符可以指定输出结果的类型、格式和精度等信息,以便正确地将数据输出到需要处理的位置,如文件、屏幕等。例如,要将一个整数值以十进制形式输出到屏幕上,可以使用" %d "作为格式化字符串的一部分;而要在文件中写入一个字符串,则可以使用" %s "来指示该字符串应该被打印出来。

注:

1)控制字符串(control string)通常是一种由特殊字符组成的格式字符串,用于指定应该如何处理程序中的数据。在计算机编程中,控制字符串经常用于格式化输入和输出,并且它们使用不同的转换说明符来控制字符串的展示方式、格式、长度等。

2)“character positions”可以指文本串中的某个位置或索引,即字符串中单个字符的位置。通常,该术语在计算机编程和数据处理领域中使用,用于表示字符串或文本中所必需的最小字符数目。



format [ˈfɔːmæt] 格式化; 安排…的版式

directive [dəˈrektɪv] 指示; 命令;

a conversion control string 转换控制符

justify  [ˈdʒʌstɪfaɪ] vt 使每行排齐; 使齐行;


The %L directive specifies the default format. This directive is a convenient way to intersperse 

application-specific formats with default formats. The printf function returns t. For more 

information on directives, see Formatted Output on page 168.

%L指令指定默认格式。该指令是将应用程序特定格式与默认格式交错的一种便捷方式。printf函数返回t。有关指令的更多信息,请参阅第163页的Formatted Output。

convenient  [kənˈviːniənt] adj 实用的; 便利的; 方便的; 省事的; 附近的 

intersperse  [ˌɪntəˈspɜːs] vt   散布; 点缀; 散置;


aList = '(1 2 3) 

printf( "\nThis is a list: %L" aList ) => t 

This is a list: (1 2 3) 

aList = nil 

printf( "\nThis is a list: %L" aList ) => t 

This is a list: nil


If the conversion control directive is inappropriate for the data item, printf displays an error.

如果转换控制指令与数据项不匹配,则printf会显示错误。

printf( "%d %d" 5 nil ) 

Message: *Error* fprintf/sprintf: 

format spec. incompatible with data - nil


inappropriate  [ˌɪnəˈprəʊpriət]  adj 不恰; 不合适的;当的; 不适当的









点赞

评论 (0 个评论)

facelist

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

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

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 28

    粉丝
  • 7

    好友
  • 19

    获赞
  • 8

    评论
  • 130

    访问数

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

GMT+8, 2024-6-17 17:41 , Processed in 0.031250 second(s), 7 queries , Gzip On, Redis On.

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