PFC手冊fish翻譯中英文.講義(共107頁)_第1頁
PFC手冊fish翻譯中英文.講義(共107頁)_第2頁
PFC手冊fish翻譯中英文.講義(共107頁)_第3頁
PFC手冊fish翻譯中英文.講義(共107頁)_第4頁
PFC手冊fish翻譯中英文.講義(共107頁)_第5頁
已閱讀5頁,還剩117頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

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. Section 2.3explains FISH statements and Section 2.4 describes how th

2、e FISH language links with PFC2D.Pre-defined FISH variables, functions and arrays are described in Section 2.5.這部分包含F(xiàn)ISH語言的詳細參考。接下來,2.2描述語言規(guī)則及如何運用變量和函數(shù)。2.3解釋FISH陳述。2.4描述FISH語言如何與PFC聯(lián)系在一起。2.5講述如何預定義FISH變量、函數(shù)和數(shù)列。FISH is a programming language embedded within PFC2D that enables the user to define newva

3、riables 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 applied to a numerical test, unusual distributions ofproperties may b

4、e specified, and parameter studies may be automated. FISH是PFC內(nèi)置的一種編程語言,用戶可以自定義變量和函數(shù)。這些函數(shù)可用來擴展PFC的功能,或者增加用戶定義的特征。例如:輸出或者打印新的變量、實現(xiàn)特殊的顆粒生成、數(shù)值測試中中應用伺服控制、定義特殊的顆粒分布以及自動研究參數(shù)。FISH is a “compiler” (rather than an “interpreter”). Programs entered via a PFC2D data file aretranslated into a list of instructions

5、 (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 code enables programs to run much faster. However, unlike a comp

6、iler, 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數(shù)據(jù)文件輸入的程序轉化成一連串命令(以“pseudo指令”的形式)儲存在PFC的存儲空間。PFC沒有保留初始源程序。無論何時援引FISH函數(shù),其編好的pseudo指令執(zhí)行。編好的指令不是翻譯好的源指令的作用是使得程序更快的運行。然而,不像編程員那樣,F(xiàn)ISH在任何時間都可以打印

7、變量的名字和數(shù)值,用戶可以通過PFC中的SET命令修改數(shù)值。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 other functions, which may invoke others, and so on. The order i

8、n 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 the function and the current values of associated variables. FIS

9、H程序簡單的包含在正常的PFC數(shù)據(jù)文件里DIFINE 后邊的命令行按FISH函數(shù)處理;函數(shù)以遇到END為結尾。函數(shù)也許會援引其他函數(shù),其它函數(shù)亦會援引其他函數(shù)等等。函數(shù)定義的順序沒有影響。因為FISH函數(shù)的程序形式儲存在PFC的存儲空間,SAVE命令會存儲函數(shù)及相關變量的當值。A summary of FISH language and intrinsic names is provided in Section 2 in the Command andFISH Reference Summary.在Command andFISH Reference Summary.的第二章提供FISH語言及

10、其內(nèi)在名字的總結。 2.2 FISH Language Rules, Variables and Functions FISH語言規(guī)則,變量及函數(shù)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 be statements of a FISH function; thefunction terminates when t

11、he word END is encountered. A valid line of FISH code must take one of the following forms. FISH程序包含在普通的PFC數(shù)據(jù)文件中或者直接從鍵盤鍵入。DIFINE 后邊的命令行按FISH函數(shù)處理;函數(shù)以遇到END為結尾。FISH的有效命令行必須是下述格式中的一種。1. The line starts with a statement, such as IF, LOOP, etc. (see Section 2.3).2. The line contains one or more names of u

12、ser-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 FISH code (i.e., forward references are allowed).3. The line

13、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 line is embedded in asection of FISH code delimited by the COMMAN

14、D ENDCOMMAND statements(see Section 2.3.3).5. The line is blank or starts with a semicolon.1.命令用IF,LOOP等開始。(見2.3)2.如果一行包含一個或更多用戶定義FISH函數(shù)的名字,以空格號隔開。例如 fun_1 fun_2 fun_3名字與用戶所寫的函數(shù)相對應,這些函數(shù)有序執(zhí)行。一行FISH指令中,函數(shù)沒有必要比其參考前定義。(即允許參考在前面)3.命令行包含指派聲明(例如等號右邊的數(shù)學式被運算且其值賦予給等號左邊的函數(shù)名稱或是變量)4.命令行由PFC命令組成,通過COMMANDENDCOMMA

15、ND 分隔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 used to split complex expressions. FISH is “case-insensitive” by

16、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 inFORTRAN) and serve to separate variables, keywords, and so on; no e

17、mbedded 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 embedded in a FISH program by preceding them with a semicolon. Bla

18、nk lines may be embedded in a FISH program. 函數(shù)的變量,函數(shù)名稱或者聲明必須完整拼寫,在PFC命令中不能縮寫。不允許有連續(xù)的命令行;可以利用中間變量分解復雜的表示式。FISH在默認狀態(tài)下為“對情況不敏感”即大寫與小寫字母之間沒有區(qū)別,所有的名字都轉換為小寫字母(注意可以通過(SET case sensitivity on)命令改變)。有相當大的空間來存儲各自的變量、關鍵詞等等(與FORTRAN不同)。在變量或是函數(shù)名中不允許含有空格。還留有格外的空間來提高可讀性-例如通過縮進循環(huán)或是假定子句。分號后面的所有字都被忽略;FISH程序中包含的注釋放在分號

19、后面;FISH程序中可以包含空白行。2.2.2 Reserved Names for Functions and Variables為函數(shù)和變量保留的名字Variable or function names must start with a non-number and must not contain any of the following symbols:. , * / + - = # ( ) ; 變量或函數(shù)名必須以非數(shù)字開始,并且不包含下列符號:. , * / + - = # ( ) ; User-defined names can be any length, but they a

20、re 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 (see Section 2.5). There are also many other words used in PFC2D

21、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 used. For example, the word gravity could be used as a FISH var

22、iable, 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 impossible to print the value of a FISH variable if its name is the s

23、ame 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參數(shù)或者預先定義的變量或函數(shù)不同就行,還應避免PFC輸入時將要用的的詞。表2.1列出的詞,如果用來命名FISH變量或函數(shù),便會引

24、起沖突。但是,潛在的沖突決定于如何利用所選中的名字。例如:gravity可以用作FISH變量,只是簡單的在FISH函數(shù)內(nèi)部涉及。只有當用SET命令去設置它的值,沖突才會發(fā)生,因為對于SET命令來說,gravity是個有效的詞語。類似的,當一個FISH變量的名字與PRINT命令的參數(shù)一樣時,也不可能把這個變量的值打印出來。如果有疑問,避免表2.1中的所有詞,或者縮寫名字。(因為PFC允許關鍵詞或者命令縮寫)As an alternative strategy, the PFC2D command SET safe conversion can be used to force the expli

25、cit 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 that a FISH function initial, as shown in Example 2.1, has be

26、en 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 us an unambiguous, correct interpretation.作為一個相對的策略,可以用PFC中的命令

27、SET safe conversion 強制FISH變量清晰的組織成為命令行說明。置于任何FISH變量之前都表示照這樣鑒定這個對象,強制命令行的語法分析器忽略任何其他可能的解釋。例如:假定例2.1中的FISH函數(shù)initial 已經(jīng)創(chuàng)建。試圖從命令提示中運行這個函數(shù)一般會引起錯誤。但是,在變量前面使用函數(shù)標識符,便會得到一個明白的,正確的解釋。 Example 2.1 Explicit identification of FISH variables;fname: fishr1.datdef initialxvel = 0.0yvel = 1.0end; these lines will bo

28、th result in errors. 這兩行均會引起錯誤initial ; . vainly hoping to initialize parameters. 欲將參數(shù)初始化ini xvel xvel yvel yvel ; .obviously ambiguous. 明顯的混亂; these lines would solve the problem. 這些命令行將解決問題set safe_conversion oninitialini xvel xvel yvel yvelBy default, user-defined variables represent single numbe

29、rs 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 for arrays, but functions may be written in FISH to perform thes

30、e operations. For example, the contents of a two-dimensional array (or matrix) may be initialized and printed, as shown in Example 2.2.默認狀態(tài)下,用戶自定義的變量只能代表單個數(shù)字或是字符串。如果使用ARRAY才能儲存數(shù)字或字符串的多維數(shù)組。2.3.1定義了數(shù)組的創(chuàng)建和使用方法。目前,沒有明確的數(shù)組輸入或輸出設備,但是可以在FISH中寫函數(shù)執(zhí)行這些操作。例如:如例2.2所示,可以初始化和打印二位數(shù)組(或矩陣)的內(nèi)容。Example 2.2 Initializin

31、g and printing FISH arrays;fname: fishr2.datnewdef afill ; fill matrix with random numbers 用任意數(shù)字填滿矩陣 array var(4,3)loop m (1,4)loop n (1,3)var(m,n) = urandend_loopend_loopenddef ashow ; display contents of matrix 展示矩陣內(nèi)容loop m (1,4)hed = msg = +string(m)loop n (1,3)hed = hed + +string(n)msg = msg + +

32、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.77131092280e-001 6.23065859697e-001 7.69736401269e-0012 8.38073820221e-001 3.36399274746e-001 8.56969321222e-0013 6.32138908185e-001 5.4

33、1650756113e-002 1.82265148152e-0014 8.59740023776e-001 9.27965545082e-001 9.63324485278e-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,

34、both in FISH code and in PFC2D commands (for example, in place of a number); 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 i

35、t is changed. The values of all variables are also saved by the SAVE command and restored by the RESTORE command.變量和函數(shù)的名字在全球均是可識別的(用 BASIC 語言)。只要在一個有效的FISH程序命令行中提到一個名字,便能普遍被認可,無論是以FISH指令形式還是PFC命令形式。當給出 PRINT fish 命令時就會輸出一系列的變量。在一個FISH函數(shù)中賦值的變量可用于其他函數(shù)或PFC命令。變量的值如不改變就會一直保持。所有變量的值可以用SAVE命令保存,用RESTORE命令存

36、儲。2.2.4 Functions: Structure, Evaluation and Calling Scheme函數(shù):結構,評價和引入計劃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 hav

37、e global scope.) The name of a function follows the DEFINEstatement, and 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.

38、3, which shows function construction and use. 在FISH語言中唯一能夠執(zhí)行的對象便是函數(shù)。函數(shù)沒有參數(shù)。在援引函數(shù)前設置變量(記得變量具有廣泛范圍),完成參數(shù)之間的通信。函數(shù)名放在在DINIFE后邊,遇見END時表示函數(shù)范圍結束。END在函數(shù)執(zhí)行過程中起返回控制的作用。(EXIT起相同作用)。參考例2.3,展示函數(shù)如何構建和使用。Example 2.3 Construction of a function;fname: fishr3.datnewdef xxxaa = 2 * 3xxx = aa + bbendThe value of xxx is

39、 changed when the function is executed. The variable aa is computed locally, 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 correspon

40、ding to its name. The function xxx may be invoked in one of the following 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 inp

41、ut line (see Section 2.4.1);and(5) as a parameter to the SET, PRINT or HISTORY commands of PFC2D. 執(zhí)行函數(shù)的時候,XXX的值被改變。變量aa在函數(shù)內(nèi)部運算,但是 XXX 運算過程中用到bb已經(jīng)存在的值。如果該變量的值沒有明確給定,那么結果為零(整數(shù))。一個函數(shù)沒有必要賦值給相同名字的變量??赏ㄟ^以下幾種方法援引函數(shù)XXX。(1) 在FISH的輸入命令行中直接簡單的寫XXX。(2) 在FISH方程中作為一個變量XXX例如new var = (sqrt(xxx) / 5.6)4;(3) 在PFC命令行

42、中直接簡單寫XXX。(4) 在輸入行中作為一個數(shù)的替代標志。(5) 作為PFC命令SET,PRINT或HISTORY的參數(shù)。A function may be referred to 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 functio

43、n can be deleted or redefined see Section 2.2.8.一個函數(shù)在定義之前可能被其他函數(shù)援引;FISH編程員在首次提到的時候先簡單的創(chuàng)建一個符號,用DINIFE 命令定義之后再引入整個函數(shù)。一個函數(shù)可以被刪除或重定義。-見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 ar

44、e not allowed (i.e., execution of a function must not invoke that same function). Example 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 executi

45、on.函數(shù)可以在任何程度上嵌入,函數(shù)可以援引其它函數(shù),而其它函數(shù)也可以無限援引。然而,不允許循環(huán)引入函數(shù)。(即函數(shù)執(zhí)行是不能引入相同的函數(shù))例2.4展示循環(huán)引入函數(shù)的例子,這是不允許的,因為定義中的函數(shù)名稱在函數(shù)引入自己的時候被使用了。這個例子在執(zhí)行時會引發(fā)錯誤。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(

46、cp)end_loopendThe same function should be coded as shown in Example 2.5, below.類似的函數(shù)應該像例2.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 =

47、 sumendThe difference between variables and functions is that functions are always executed 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,

48、 for example, when several histories of FISH variables are requiredonly one function is necessary in order to evaluate several quantities, as in Example 2.6.變量與函數(shù)不同的地方在于,只要提到名字,函數(shù)必須一直運行;變量只是簡單的輸送它們當前的值。然而,函數(shù)運行時會評估其他變量(如果與函數(shù)相沖突)。這種效果是很有用的,例如,當需要若干個FISH變量記錄時,只需一個函數(shù)便可評估幾個量,見例2.6.Example 2.6 Evaluation

49、of variables;fname: fishr6.datnewdef h_var_1; bp22 = pointer to ball with ID = 22, set during 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 使

50、用xx以避免循環(huán)h_var_4 = b_xvel(bp45)h_var_5 = b_xvel(bp22)h_var_6 = abs(h_var_5 - h_var_4)endThe 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 a

51、side effect, the values of h var 2 through h var 6 would also be computed and used as historyvariables.函數(shù)h var 1每隔幾時步便被PFC記錄理念執(zhí)行一次,但是,因為側面影響,h var 2到h var 6的值也能計算且用作記錄變量。2.2.5 Data Types 數(shù)據(jù)類型There are four data types used for FISH variables or function values:1. Integer exact numbers in the range -2

52、,147,483,648 to +2,147,483,647;2. Floating-point approximate numbers with about 15 decimal 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 deno

53、ted in FISH and PFC2D by asequence of characters enclosed by single quotes e.g., Have a nice 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變量或函數(shù)值有四類數(shù)據(jù)類型:1. Integer:(-

54、2147483648,+2147483647)范圍內(nèi)的準確的數(shù)字2. Floating-point:有精度為15位小數(shù)的大概數(shù)字,范圍在(10-300,10,300)3. String:任何可打印的符號的一串集合體,串可以有任意的長度,但是在輸出時可能被截斷。在FISH或PFC中的字符串包含在單引號內(nèi)例如:Have a nice day4. Pointer:機器地址用來掃描相連的一系列符號。指針所指的符號,除了null 以外,都擁有一個相同的形式。A variable in FISH can change its type dynamically, depending on the type

55、of the expression to which it is set. To make this clear, consider the assignment statementvar1 = var2If var1 and var2 are 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,

56、 the type of var1 is not changed, although data conversion is done. By default, all variables in FISH start their life as integers. However, a statement such asvar1 = 3.4causes var1 to become a floating-point variable when it is executed. The current type of allvariables may be determined by giving

57、the PFC2D command PRINT fish the types are denotedin the printout.FISH中的變量可以動態(tài)的改變它的類型,取決于表達類型和設置類型。為了更易懂,以如下指派命令為例:var1 = var2如果var1 和var2屬不同類型,則會發(fā)生兩件事情:一, var1 的類型轉化為var2的類型;二,var2的值賦予給 var1。在其他語言中,例如FORTRAN或C語言,var1的類型沒有改變,雖然數(shù)值已經(jīng)改變。默認狀態(tài)下,所有FISH變量的初始類型為整數(shù)。但是,命令如var1=3.4在運行時,使得var1的類型變?yōu)镕loating-point。所有變量的當前類型可由PFC的命令PRINT fish 確定變量類型將會在輸出中說明。The dynamic typing mechanism in FISH was devised to make programming easier for nonprogrammers. In languages such as BASIC,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論