PFC手册fish翻译中英文.讲义_第1页
PFC手册fish翻译中英文.讲义_第2页
PFC手册fish翻译中英文.讲义_第3页
PFC手册fish翻译中英文.讲义_第4页
PFC手册fish翻译中英文.讲义_第5页
已阅读5页,还剩102页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上精选优质文档-倾情为你奉上专心-专注-专业专心-专注-专业精选优质文档-倾情为你奉上专心-专注-专业2 FISH REFERENCE2.1 Introduction and Overview简介和概述This section contains a detailed reference to the FISH language. Following the introduction, Section2.2 describes the rules of the language and how variables and functions are used. Secti

2、on 2.3explains FISH statements and Section 2.4 describes how the FISH language links with PFC2D.Pre-defined FISH variables, functions and arrays are described in Section 2.5.这部分包含FISH语言的详细参考。接下来,2.2描述语言规则及如何运用变量和函数。2.3解释FISH陈述。2.4描述FISH语言如何与PFC联系在一起。2.5讲述如何预定义FISH变量、函数和数列。FISH is a programming langu

3、age embedded within PFC2D that enables the user to define newvariables and functions. These functions may be used to extend PFC2Ds usefulness or add user defined features. For example, new variables may be plotted or printed, special particle generatorsmay be implemented, servo-control may be applie

4、d to a numerical test, unusual distributions ofproperties may be specified, and parameter studies may be automated. FISH是PFC内置的一种编程语言,用户可以自定义变量和函数。这些函数可用来扩展PFC的功能,或者增加用户定义的特征。例如:输出或者打印新的变量、实现特殊的颗粒生成、数值测试中中应用伺服控制、定义特殊的颗粒分布以及自动研究参数。FISH is a “compiler” (rather than an “interpreter”). Programs entered

5、via a PFC2D data file aretranslated into a list of instructions (in “pseudo-code”) stored in PFC2Ds memory space; the original source program is not retained by PFC2D. Whenever a FISH function is invoked, its compiled pseudo-code is executed. The use of compiled code rather than interpreted source c

6、ode enables programs to run much faster. However, unlike a compiler, variable names and values are available for printing at any time; values may be modified by the user by using PFC2Ds SET command. FISH是一个编程员,而不是一个翻译员。通过PFC数据文件输入的程序转化成一连串命令(以“pseudo指令”的形式)储存在PFC的存储空间。PFC没有保留初始源程序。无论何时援引FISH函数,其编好的p

7、seudo指令执行。编好的指令不是翻译好的源指令的作用是使得程序更快的运行。然而,不像编程员那样,FISH在任何时间都可以打印变量的名字和数值,用户可以通过PFC中的SET命令修改数值。FISH programs are simply embedded in a normal PFC2D data file lines following the wordDEFINE are processed as a FISH function; the function terminates when the word END is encountered. Functions may invoke o

8、ther functions, which may invoke others, and so on. The order in which functions are defined does not matter, as long as they are all defined before they are used (e.g., invoked by a PFC2D command). Since the compiled form of a FISH function is stored in PFC2Ds memory space, the SAVE command saves t

9、he function and the current values of associated variables. FISH程序简单的包含在正常的PFC数据文件里DIFINE 后边的命令行按FISH函数处理;函数以遇到END为结尾。函数也许会援引其他函数,其它函数亦会援引其他函数等等。函数定义的顺序没有影响。因为FISH函数的程序形式储存在PFC的存储空间,SAVE命令会存储函数及相关变量的当值。A summary of FISH language and intrinsic names is provided in Section 2 in the Command andFISH Ref

10、erence Summary在Command andFISH Reference Summary.的第二章提供FISH语言及其内在名字的总结。 2.2 FISH Language Rules, Variables and Functions FISH语言规则,变量及函数2.2.1 Lines 命令行FISH programs can be embedded in a normal PFC2D data file or may be entered directly from the keyboard. Lines following the word DEFINE are taken to b

11、e statements of a FISH function; thefunction terminates when the word END is encountered. A valid line of FISH code must take one of the following forms. FISH程序包含在普通的PFC数据文件中或者直接从键盘键入。DIFINE 后边的命令行按FISH函数处理;函数以遇到END为结尾。FISH的有效命令行必须是下述格式中的一种。1. The line starts with a statement, such as IF, LOOP, etc.

12、 (see Section 2.3).2. The line contains one or more names of user-defined FISH functions, separatedby spaces e.g.,fun 1 fun 2 fun 3where the names correspond to functions written by the user. These functionsare executed in order. The functions need not be defined prior to their referenceon a line of

13、 FISH code (i.e., forward references are allowed).3. The line consists of an assignment statement (i.e., the expression on the rightof the = sign is evaluated and the value given to the variable or function nameon the left of the = sign).4. The line consists of a PFC2D command, provided that the lin

14、e is embedded in asection of FISH code delimited by the COMMAND ENDCOMMAND statements(see Section 2.3.3).5. The line is blank or starts with a semicolon.1.命令用IF,LOOP等开始。(见2.3)2.如果一行包含一个或更多用户定义FISH函数的名字,以空格号隔开。例如 fun_1 fun_2 fun_3名字与用户所写的函数相对应,这些函数有序执行。一行FISH指令中,函数没有必要比其参考前定义。(即允许参考在前面)3.命令行包含指派声明(例如

15、等号右边的数学式被运算且其值赋予给等号左边的函数名称或是变量)4.命令行由PFC命令组成,通过COMMANDENDCOMMAND 分隔FISH 指令。命令行包含在FISH指令的一部分里面。5.命令行以分号开始或者结束。FISH variables, function names and statements must be spelled out in full; they cannot be truncated, as in PFC2D commands. No continuation lines are allowed; intermediate variables may be use

16、d to split complex expressions. FISH is “case-insensitive” by default i.e., it makes no distinction between upper case and lowercase letters; all names are converted to lowercase letters. (Note that this can be changed with the command SET case sensitivity on.) Spaces are significant (unlike inFORTR

17、AN) and serve to separate variables, keywords, and so on; no embedded blanks are allowed in variable or function names. Extra spaces may be used to improve readabilityfor example, by indenting loops and conditional clauses. Any characters following a semicolon ( ; ) are ignored; comments may be embe

18、dded in a FISH program by preceding them with a semicolon. Blank lines may be embedded in a FISH program. 函数的变量,函数名称或者声明必须完整拼写,在PFC命令中不能缩写。不允许有连续的命令行;可以利用中间变量分解复杂的表示式。FISH在默认状态下为“对情况不敏感”即大写与小写字母之间没有区别,所有的名字都转换为小写字母(注意可以通过(SET case sensitivity on)命令改变)。有相当大的空间来存储各自的变量、关键词等等(与FORTRAN不同)。在变量或是函数名中不允许含有

19、空格。还留有格外的空间来提高可读性-例如通过缩进循环或是假定子句。分号后面的所有字都被忽略;FISH程序中包含的注释放在分号后面;FISH程序中可以包含空白行。2.2.2 Reserved Names for Functions and Variables为函数和变量保留的名字Variable or function names must start with a non-number and must not contain any of the following symbols:. , * / + - = # ( ) ; 变量或函数名必须以非数字开始,并且不包含下列符号:. , * /

20、+ - = # ( ) ; User-defined names can be any length, but they are truncated in printout and in plot captions, due to line-length limitations. In general, names may be chosen arbitrarily, although they must not be the same as a FISH statement (see Section 2.3) or a pre-defined variable or function (se

21、e Section 2.5). There are also many other words used in PFC2D input that should be avoided. The list contained in Table 2.1 shows all words that could give rise to a conflict if used to name a FISH variable or function. However, the potential conflict depends on the way in which the chosen name is u

22、sed. For example, the word gravity could be used as a FISH variable, provided that it is simply referred to inside a FISH function; conflict would arise only if it is necessary to use the SET command to set its value, since gravity is a valid argument to the SET command. Similarly, it may be impossi

23、ble to print the value of a FISH variable if its name is the same as a parameter for the PRINT command. If in doubt, avoid any of the names listed in Table 2.1, or contractions of the names (since PFC2D allows of keywords and commands).用户定义的名字可以在任何长度,但是由于行的长度限制,在打印或输出加标题时会被截断。一般说来,名字是任意选择的,只要与FISH参数

24、或者预先定义的变量或函数不同就行,还应避免PFC输入时将要用的的词。表2.1列出的词,如果用来命名FISH变量或函数,便会引起冲突。但是,潜在的冲突决定于如何利用所选中的名字。例如:gravity可以用作FISH变量,只是简单的在FISH函数内部涉及。只有当用SET命令去设置它的值,冲突才会发生,因为对于SET命令来说,gravity是个有效的词语。类似的,当一个FISH变量的名字与PRINT命令的参数一样时,也不可能把这个变量的值打印出来。如果有疑问,避免表2.1中的所有词,或者缩写名字。(因为PFC允许关键词或者命令缩写)As an alternative strategy, the PF

25、C2D command SET safe conversion can be used to force the explicit recognition of FISH variables in a command-line instruction. The symbol pre-pended to any FISH variable identifies the object as such and forces the command-line parser to ignore any other possible interpretation. For example, suppose

26、 that a FISH function initial, as shown in Example 2.1, has been created. Attempting to run the function from the command prompt would ordinarily produce an error, since the command INITIAL would take precedence over the FISH initial. However, using the FISH identifierin front of the variable gives

27、us an unambiguous, correct interpretation.作为一个相对的策略,可以用PFC中的命令SET safe conversion 强制FISH变量清晰的组织成为命令行说明。置于任何FISH变量之前都表示照这样鉴定这个对象,强制命令行的语法分析器忽略任何其他可能的解释。例如:假定例2.1中的FISH函数initial 已经创建。试图从命令提示中运行这个函数一般会引起错误。但是,在变量前面使用函数标识符,便会得到一个明白的,正确的解释。 Example 2.1 Explicit identification of FISH variables;fname: fis

28、hr1.datdef initialxvel = 0.0yvel = 1.0end; these lines will both result in errors. 这两行均会引起错误initial ; . vainly hoping to initialize parameters. 欲将参数初始化ini xvel xvel yvel yvel ; .obviously ambiguous. 明显的混乱; these lines would solve the problem. 这些命令行将解决问题set safe_conversion oninitialini xvel xvel yvel

29、 yvelBy default, user-defined variables represent single numbers or strings. Multi-dimensional arrays of numbers or strings may be stored if the ARRAY statement is used. Section 2.3.1 defines the way in which arrays are created and used. At present, there is no explicit printout or input facility fo

30、r arrays, but functions may be written in FISH to perform these operations. For example, the contents of a two-dimensional array (or matrix) may be initialized and printed, as shown in Example 2.2.默认状态下,用户自定义的变量只能代表单个数字或是字符串。如果使用ARRAY才能储存数字或字符串的多维数组。2.3.1定义了数组的创建和使用方法。目前,没有明确的数组输入或输出设备,但是可以在FISH中写函数

31、执行这些操作。例如:如例2.2所示,可以初始化和打印二位数组(或矩阵)的内容。Example 2.2 Initializing and printing FISH arrays;fname: fishr2.datnewdef afill ; fill matrix with random numbers 用任意数字填满矩阵 array var(4,3)loop m (1,4)loop n (1,3)var(m,n) = urandend_loopend_loopenddef ashow ; display contents of matrix 展示矩阵内容loop m (1,4)hed = m

32、sg = +string(m)loop n (1,3)hed = hed + +string(n)msg = msg + +string(var(m,n)end_loopif m = 1dum = out(hed)end_ifdum = out(msg)end_loopendafillashowUpon execution, the following output is produced:Pfc2DafillPfc2Dashow1 2 31 5.e-001 6.e-001 7.e-0012 8.e-001 3.e-001 8.e-0013 6.e-001 5.e-002 1.e-0014 8

33、.e-001 9.e-001 9.e-0012.2.3 Scope of Variables 变量范围Variable and function names are recognized globally (as in the BASIC language). As soon as a name is mentioned in a valid FISH program line, it is thereafter recognized globally, both in FISH code and in PFC2D commands (for example, in place of a nu

34、mber); it also appears in the list of variables displayed when the PRINT fish command is given. A variable may be given a value in one FISH function and used in another function or in a PFC2D command. The value is retained until it is changed. The values of all variables are also saved by the SAVE c

35、ommand and restored by the RESTORE command.变量和函数的名字在全球均是可识别的(用 BASIC 语言)。只要在一个有效的FISH程序命令行中提到一个名字,便能普遍被认可,无论是以FISH指令形式还是PFC命令形式。当给出 PRINT fish 命令时就会输出一系列的变量。在一个FISH函数中赋值的变量可用于其他函数或PFC命令。变量的值如不改变就会一直保持。所有变量的值可以用SAVE命令保存,用RESTORE命令存储。2.2.4 Functions: Structure, Evaluation and Calling Scheme函数:结构,评价和引入

36、计划The only object in the FISH language that can be executed is the “function.” Functions have no arguments; communication of parameters is through the setting of variables prior to invoking the function. (Recall that variables have global scope.) The name of a function follows the DEFINEstatement, a

37、nd its scope terminates with the END statement. The END statement also serves to returncontrol to the caller when the function is executed. (Note that the EXIT statement also returns control see Section 2.3.2.) Consider Example 2.3, which shows function construction and use. 在FISH语言中唯一能够执行的对象便是函数。函数

38、没有参数。在援引函数前设置变量(记得变量具有广泛范围),完成参数之间的通信。函数名放在在DINIFE后边,遇见END时表示函数范围结束。END在函数执行过程中起返回控制的作用。(EXIT起相同作用)。参考例2.3,展示函数如何构建和使用。Example 2.3 Construction of a function;fname: fishr3.datnewdef xxxaa = 2 * 3xxx = aa + bbendThe value of xxx is changed when the function is executed. The variable aa is computed lo

39、cally, but the existing value of bb is used in the computation of xxx. If values are not explicitly given to variables, they default to zero (integer). It is not necessary for a function to assign a value to the variable corresponding to its name. The function xxx may be invoked in one of the follow

40、ing ways:(1) as a single word xxx on a FISH input line;(2) as the variable xxx in a FISH formula e.g.,new var = (sqrt(xxx) / 5.6)4;(3) as a single word xxx on a PFC2D input line;(4) as a symbolic replacement for a number on an input line (see Section 2.4.1);and(5) as a parameter to the SET, PRINT or

41、 HISTORY commands of PFC2D. 执行函数的时候,XXX的值被改变。变量aa在函数内部运算,但是 XXX 运算过程中用到bb已经存在的值。如果该变量的值没有明确给定,那么结果为零(整数)。一个函数没有必要赋值给相同名字的变量。可通过以下几种方法援引函数XXX。在FISH的输入命令行中直接简单的写XXX。在FISH方程中作为一个变量XXX例如new var = (sqrt(xxx) / 5.6)4;在PFC命令行中直接简单写XXX。在输入行中作为一个数的替代标志。作为PFC命令SET,PRINT或HISTORY的参数。A function may be referred t

42、o in another function before it is defined; the FISH compiler simply creates a symbol at the time of first mention and then links all references to the function when it is defined by a DEFINE command. A function can be deleted or redefined see Section 2.2.8.一个函数在定义之前可能被其他函数援引;FISH编程员在首次提到的时候先简单的创建一个

43、符号,用DINIFE 命令定义之后再引入整个函数。一个函数可以被删除或重定义。-见2.2.8Function calls may be nested to any leveli.e., functions may refer to other functions, which may refer to others, ad infinitum. However, recursive function calls are not allowed (i.e., execution of a function must not invoke that same function). Example

44、2.4 shows a recursive function call, which is not allowed, because the name of the defining function is used in such a way that the function will try to call itself. The example will produce an error on execution.函数可以在任何程度上嵌入,函数可以援引其它函数,而其它函数也可以无限援引。然而,不允许循环引入函数。(即函数执行是不能引入相同的函数)例2.4展示循环引入函数的例子,这是不允

45、许的,因为定义中的函数名称在函数引入自己的时候被使用了。这个例子在执行时会引发错误。Example 2.4 A recursive function call;fname: fishr4.datdef force_sumforce_sum = 0.0cp = contact_headloop while cp # nullforce_sum = force_sum + c_nforce(cp)cp = c_next(cp)end_loopendThe same function should be coded as shown in Example 2.5, below.类似的函数应该像例2.

46、5所示编程。Example 2.5 Removing recursion from the function shown in Example 2.4;fname: fishr5.datdef force_sumsum = 0.0cp = contact_headloop while cp # nullsum = sum + c_nforce(cp)cp = c_next(cp)end_loopforce_sum = sumendThe difference between variables and functions is that functions are always execute

47、d whenever their name is mentioned; variables simply convey their current values. However, the execution of a function may cause other variables (as opposed to functions) to be evaluated. This effect is useful, for example, when several histories of FISH variables are requiredonly one function is ne

48、cessary in order to evaluate several quantities, as in Example 2.6.变量与函数不同的地方在于,只要提到名字,函数必须一直运行;变量只是简单的输送它们当前的值。然而,函数运行时会评估其他变量(如果与函数相冲突)。这种效果是很有用的,例如,当需要若干个FISH变量记录时,只需一个函数便可评估几个量,见例2.6.Example 2.6 Evaluation of variables;fname: fishr6.datnewdef h_var_1; bp22 = pointer to ball with ID = 22, set dur

49、ing creation.指针指向ID为22的球; bp45 = pointer to ball with ID = 45, set during creation.指针指向ID为45的球;xx = b_x(bp45)h_var_1 = b_x(bp45)h_var_2 = b_x(bp22)h_var_3 = abs(h_var_2 - xx) ; use of xx here avoids recursion 使用xx以避免循环h_var_4 = b_xvel(bp45)h_var_5 = b_xvel(bp22)h_var_6 = abs(h_var_5 - h_var_4)endThe

50、 PFC2D commands to request histories might be:hist h var 1hist h var 2hist h var 3hist h var 4hist h var 5hist h var 6The function h var 1 would be executed by the PFC2Ds history logic every few steps but, as aside effect, the values of h var 2 through h var 6 would also be computed and used as hist

51、oryvariables.函数h var 1每隔几时步便被PFC记录理念执行一次,但是,因为侧面影响,h var 2到h var 6的值也能计算且用作记录变量。2.2.5 Data Types 数据类型There are four data types used for FISH variables or function values:1. Integer exact numbers in the range -2,147,483,648 to +2,147,483,647;2. Floating-point approximate numbers with about 15 decimal

52、 digits of precision, with arange of approximately 10300 to 10300;3. String packed sequence of any printable characters; the sequence may be any length,but it will be truncated on the printout. Strings are denoted in FISH and PFC2D by asequence of characters enclosed by single quotes e.g., Have a ni

53、ce day; and4. Pointer machine address used for scanning through linked lists. They have anassociated type from the object to which the pointer refers, except for the null pointer.FISH变量或函数值有四类数据类型:Integer:(-,+)范围内的准确的数字Floating-point:有精度为15位小数的大概数字,范围在(10-300,10,300)String:任何可打印的符号的一串集合体,串可以有任意的长度,但

54、是在输出时可能被截断。在FISH或PFC中的字符串包含在单引号内例如:Have a nice dayPointer:机器地址用来扫描相连的一系列符号。指针所指的符号,除了null 以外,都拥有一个相同的形式。A variable in FISH can change its type dynamically, depending on the type of the expression to which it is set. To make this clear, consider the assignment statementvar1 = var2If var1 and var2 are

55、 of different types, then two things are done: first, var1s type is converted to var2s type; second, var2s data are transferred to var1. In other languages, such as FORTRAN or C, the type of var1 is not changed, although data conversion is done. By default, all variables var1 = 3.4causes var1 to bec

56、ome a floating-point variable when it is executed. The current type of allvariables may be determined by giving the PFC2D command PRINT fish the types are denotedin the printout.FISH中的变量可以动态的改变它的类型,取决于表达类型和设置类型。为了更易懂,以如下指派命令为例:var1 = var2如果var1 和var2属不同类型,则会发生两件事情:一, var1 的类型转化为var2的类型;二,var2的值赋予给 v

57、ar1。在其他语言中,例如FORTRAN或C语言,var1的类型没有改变,虽然数值已经改变。默认状态下,所有FISH变量的初始类型为整数。但是,命令如var1=3.4在运行时,使得var1的类型变为Floating-point。所有变量的当前类型可由PFC的命令PRINT fish 确定变量类型将会在输出中说明。The dynamic typing mechanism in FISH was devised to make programming easier for nonprogrammers. In languages such as BASIC, numbers are stored

58、in floating-point format, which can cause difficulties when integers are needed for, say, loop counters. In FISH, the type of the variable adjusts naturally to the context in which it is used. For example, in the following code fragment,n = n + 2xx = xx + 3.5the variable n will be an integer and wil

59、l be incremented by exactly 2, and the variable xx will be a floating-point number, subject to the usual truncation error but capable of handling a much bigger dynamic range. The rules governing type conversion in arithmetic operations are explained in Section 2.2.6. The type of a variable is determ

60、ined by the type of the object on the right-hand side of an assignment statement. This applies both to FISH statements and to assignments done with the PFC2D SET command. Both types of assignment may be used to change the type of a variable according to the value specified, as follows.1. An integer

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论