PFC手册fish翻译中英文讲义.docx
- 文档编号:29451051
- 上传时间:2023-07-23
- 格式:DOCX
- 页数:154
- 大小:119.59KB
PFC手册fish翻译中英文讲义.docx
《PFC手册fish翻译中英文讲义.docx》由会员分享,可在线阅读,更多相关《PFC手册fish翻译中英文讲义.docx(154页珍藏版)》请在冰豆网上搜索。
PFC手册fish翻译中英文讲义
2FISHREFERENCE
2.1IntroductionandOverview
简介和概述
ThissectioncontainsadetailedreferencetotheFISHlanguage.Followingtheintroduction,Section2.2describestherulesofthelanguageandhowvariablesandfunctionsareused.Section2.3explainsFISHstatementsandSection2.4describeshowtheFISHlanguagelinkswithPFC2D.
Pre-definedFISHvariables,functionsandarraysaredescribedinSection2.5.
这部分包含FISH语言的详细参考。
接下来,2.2描述语言规则及如何运用变量和函数。
2.3解释FISH陈述。
2.4描述FISH语言如何与PFC联系在一起。
2.5讲述如何预定义FISH变量、函数和数列。
FISHisaprogramminglanguageembeddedwithinPFC2Dthatenablestheusertodefinenew
variablesandfunctions.ThesefunctionsmaybeusedtoextendPFC2D’susefulnessoradduserdefinedfeatures.Forexample,newvariablesmaybeplottedorprinted,specialparticlegenerators
maybeimplemented,servo-controlmaybeappliedtoanumericaltest,unusualdistributionsof
propertiesmaybespecified,andparameterstudiesmaybeautomated.
FISH是PFC内置的一种编程语言,用户可以自定义变量和函数。
这些函数可用来扩展PFC的功能,或者增加用户定义的特征。
例如:
输出或者打印新的变量、实现特殊的颗粒生成、数值测试中中应用伺服控制、定义特殊的颗粒分布以及自动研究参数。
FISHisa“compiler”(ratherthanan“interpreter”).ProgramsenteredviaaPFC2Ddatafileare
translatedintoalistofinstructions(in“pseudo-code”)storedinPFC2D’smemoryspace;theoriginalsourceprogramisnotretainedbyPFC2D.WheneveraFISHfunctionisinvoked,itscompiledpseudo-codeisexecuted.Theuseofcompiledcode—ratherthaninterpretedsourcecode—enablesprogramstorunmuchfaster.However,unlikeacompiler,variablenamesandvaluesareavailableforprintingatanytime;valuesmaybemodifiedbytheuserbyusingPFC2D’sSETcommand.
FISH是一个编程员,而不是一个翻译员。
通过PFC数据文件输入的程序转化成一连串命令(以“pseudo指令”的形式)储存在PFC的存储空间。
PFC没有保留初始源程序。
无论何时援引FISH函数,其编好的pseudo指令执行。
编好的指令—不是翻译好的源指令—的作用是使得程序更快的运行。
然而,不像编程员那样,FISH在任何时间都可以打印变量的名字和数值,用户可以通过PFC中的SET命令修改数值。
FISHprogramsaresimplyembeddedinanormalPFC2Ddatafile—linesfollowingtheword
DEFINEareprocessedasaFISHfunction;thefunctionterminateswhenthewordENDisencountered.Functionsmayinvokeotherfunctions,whichmayinvokeothers,andsoon.Theorderinwhichfunctionsaredefineddoesnotmatter,aslongastheyarealldefinedbeforetheyareused(e.g.,invokedbyaPFC2Dcommand).SincethecompiledformofaFISHfunctionisstoredinPFC2D’smemoryspace,theSAVEcommandsavesthefunctionandthecurrentvaluesofassociatedvariables.
FISH程序简单的包含在正常的PFC数据文件里—DIFINE后边的命令行按FISH函数处理;函数以遇到END为结尾。
函数也许会援引其他函数,其它函数亦会援引其他函数等等。
函数定义的顺序没有影响。
因为FISH函数的程序形式储存在PFC的存储空间,SAVE命令会存储函数及相关变量的当值。
AsummaryofFISHlanguageandintrinsicnamesisprovidedinSection2intheCommandandFISHReferenceSummary.
在CommandandFISHReferenceSummary.的第二章提供FISH语言及其内在名字的总结。
2.2FISHLanguageRules,VariablesandFunctions
FISH语言规则,变量及函数
2.2.1Lines命令行
FISHprogramscanbeembeddedinanormalPFC2Ddatafileormaybeentereddirectlyfromthekeyboard.LinesfollowingthewordDEFINEaretakentobestatementsofaFISHfunction;the
functionterminateswhenthewordENDisencountered.AvalidlineofFISHcodemusttakeoneofthefollowingforms.
FISH程序包含在普通的PFC数据文件中或者直接从键盘键入。
DIFINE后边的命令行按FISH函数处理;函数以遇到END为结尾。
FISH的有效命令行必须是下述格式中的一种。
1.Thelinestartswithastatement,suchasIF,LOOP,etc.(seeSection2.3).
2.Thelinecontainsoneormorenamesofuser-definedFISHfunctions,separated
byspaces—e.g.,
fun1fun2fun3
wherethenamescorrespondtofunctionswrittenbytheuser.Thesefunctions
areexecutedinorder.Thefunctionsneednotbedefinedpriortotheirreference
onalineofFISHcode(i.e.,forwardreferencesareallowed).
3.Thelineconsistsofanassignmentstatement(i.e.,theexpressionontheright
ofthe=signisevaluatedandthevaluegiventothevariableorfunctionname
ontheleftofthe=sign).
4.ThelineconsistsofaPFC2Dcommand,providedthatthelineisembeddedina
sectionofFISHcodedelimitedbytheCOMMAND–ENDCOMMANDstatements
(seeSection2.3.3).
5.Thelineisblankorstartswithasemicolon.
1.命令用IF,LOOP等开始。
(见2.3)
2.如果一行包含一个或更多用户定义FISH函数的名字,以空格号隔开。
例如fun_1fun_2fun_3
名字与用户所写的函数相对应,这些函数有序执行。
一行FISH指令中,函数没有必要比其参考前定义。
(即允许参考在前面)
3.命令行包含指派声明(例如等号右边的数学式被运算且其值赋予给等号左边的函数名称或是变量)
4.命令行由PFC命令组成,通过COMMAND—ENDCOMMAND分隔FISH指令。
命令行包含在FISH指令的一部分里面。
5.命令行以分号开始或者结束。
FISHvariables,functionnamesandstatementsmustbespelledoutinfull;theycannotbetruncated,asinPFC2Dcommands.Nocontinuationlinesareallowed;intermediatevariablesmaybeusedtosplitcomplexexpressions.FISHis“case-insensitive”bydefault—i.e.,itmakesnodistinctionbetweenuppercaseandlowercaseletters;allnamesareconvertedtolowercaseletters.(NotethatthiscanbechangedwiththecommandSETcasesensitivityon.)Spacesaresignificant(unlikeinFORTRAN)andservetoseparatevariables,keywords,andsoon;noembeddedblanksareallowedinvariableorfunctionnames.Extraspacesmaybeusedtoimprovereadability—forexample,byindentingloopsandconditionalclauses.Anycharactersfollowingasemicolon(;)areignored;commentsmaybeembeddedinaFISHprogrambyprecedingthemwithasemicolon.BlanklinesmaybeembeddedinaFISHprogram.
函数的变量,函数名称或者声明必须完整拼写,在PFC命令中不能缩写。
不允许有连续的命令行;可以利用中间变量分解复杂的表示式。
FISH在默认状态下为“对情况不敏感”—即大写与小写字母之间没有区别,所有的名字都转换为小写字母(注意可以通过(SETcasesensitivityon)命令改变)。
有相当大的空间来存储各自的变量、关键词等等(与FORTRAN不同)。
在变量或是函数名中不允许含有空格。
还留有格外的空间来提高可读性--例如通过缩进循环或是假定子句。
分号后面的所有字都被忽略;FISH程序中包含的注释放在分号后面;FISH程序中可以包含空白行。
2.2.2ReservedNamesforFunctionsandVariables
为函数和变量保留的名字
Variableorfunctionnamesmuststartwithanon-numberandmustnotcontainanyofthefollowingsymbols:
.,*/+-ˆ=<>#()[]@;’"
变量或函数名必须以非数字开始,并且不包含下列符号:
.,*/+-ˆ=<>#()[]@;’"
User-definednamescanbeanylength,buttheyaretruncatedinprintoutandinplotcaptions,duetoline-lengthlimitations.Ingeneral,namesmaybechosenarbitrarily,althoughtheymustnotbethesameasaFISHstatement(seeSection2.3)orapre-definedvariableorfunction(seeSection2.5).TherearealsomanyotherwordsusedinPFC2Dinputthatshouldbeavoided.ThelistcontainedinTable2.1showsallwordsthatcouldgiverisetoaconflictifusedtonameaFISHvariableorfunction.However,thepotentialconflictdependsonthewayinwhichthechosennameisused.Forexample,thewordgravitycouldbeusedasaFISHvariable,providedthatitissimplyreferredtoinsideaFISHfunction;conflictwouldariseonlyifitisnecessarytousetheSETcommandtosetitsvalue,sincegravityisavalidargumenttotheSETcommand.Similarly,itmaybeimpossibletoprintthevalueofaFISHvariableifitsnameisthesameasaparameterforthePRINTcommand.Ifindoubt,avoidanyofthenameslistedinTable2.1,orcontractionsofthenames(sincePFC2Dallowsofkeywordsandcommands).
用户定义的名字可以在任何长度,但是由于行的长度限制,在打印或输出加标题时会被截断。
一般说来,名字是任意选择的,只要与FISH参数或者预先定义的变量或函数不同就行,还应避免PFC输入时将要用的的词。
表2.1列出的词,如果用来命名FISH变量或函数,便会引起冲突。
但是,潜在的冲突决定于如何利用所选中的名字。
例如:
gravity可以用作FISH变量,只是简单的在FISH函数内部涉及。
只有当用SET命令去设置它的值,冲突才会发生,因为对于SET命令来说,gravity是个有效的词语。
类似的,当一个FISH变量的名字与PRINT命令的参数一样时,也不可能把这个变量的值打印出来。
如果有疑问,避免表2.1中的所有词,或者缩写名字。
(因为PFC允许关键词或者命令缩写)
Asanalternativestrategy,thePFC2DcommandSETsafeconversioncanbeusedtoforcetheexplicitrecognitionofFISHvariablesinacommand-lineinstruction.The@symbolpre-pendedtoanyFISHvariableidentifiestheobjectassuchandforcesthecommand-lineparsertoignoreanyotherpossibleinterpretation.Forexample,supposethataFISHfunctioninitial,asshowninExample2.1,hasbeencreated.Attemptingtorunthefunctionfromthecommandpromptwouldordinarilyproduceanerror,sincethecommandINITIALwouldtakeprecedenceovertheFISHinitial.However,usingtheFISHidentifier@infrontofthevariablegivesusanunambiguous,correctinterpretation.
作为一个相对的策略,可以用PFC中的命令SETsafeconversion强制FISH变量清晰的组织成为命令行说明。
@置于任何FISH变量之前都表示照这样鉴定这个对象,强制命令行的语法分析器忽略任何其他可能的解释。
例如:
假定例2.1中的FISH函数initial已经创建。
试图从命令提示中运行这个函数一般会引起错误。
但是,在变量前面使用函数标识符@,便会得到一个明白的,正确的解释。
Example2.1ExplicitidentificationofFISHvariables
;fname:
fishr1.dat
definitial
xvel=0.0
yvel=1.0
end
;
;theselineswillbothresultinerrors...这两行均会引起错误
initial;...vainlyhopingtoinitializeparameters...欲将参数初始化
inixvelxvelyvelyvel;...obviouslyambiguous...明显的混乱
;
;theselineswouldsolvetheproblem...这些命令行将解决问题
setsafe_conversionon
@initial
inixvel@xvelyvel@yvel
Bydefault,user-definedvariablesrepresentsinglenumbersorstrings.Multi-dimensionalarraysofnumbersorstringsmaybestorediftheARRAYstatementisused.Section2.3.1definesthewayinwhicharraysarecreatedandused.Atpresent,thereisnoexplicitprintoutorinputfacilityforarrays,butfunctionsmaybewritteninFISHtoperformtheseoperations.Forexample,thecontentsofatwo-dimensionalarray(ormatrix)maybeinitializedandprinted,asshowninExample2.2.
默认状态下,用户自定义的变量只能代表单个数字或是字符串。
如果使用ARRAY才能储存数字或字符串的多维数组。
2.3.1定义了数组的创建和使用方法。
目前,没有明确的数组输入或输出设备,但是可以在FISH中写函数执行这些操作。
例如:
如例2.2所示,可以初始化和打印二位数组(或矩阵)的内容。
Example2.2InitializingandprintingFISHarrays
;fname:
fishr2.dat
new
defafill;fillmatrixwithrandomnumbers用任意数字填满矩阵
arrayvar(4,3)
loopm(1,4)
loopn(1,3)
var(m,n)=urand
end_loop
end_loop
end
defashow;displaycontentsofmatrix展示矩阵内容
loopm(1,4)
hed=’’
msg=’’+string(m)
loopn(1,3)
hed=hed+’’+string(n)
msg=msg+’’+string(var(m,n))
end_loop
ifm=1
dum=out(hed)
end_if
dum=out(msg)
end_loop
end
afill
ashow
Uponexecution,thefollowingoutputisproduced:
Pfc2D>afill
Pfc2D>ashow
123
15.77131092280e-0016.23065859697e-0017.69736401269e-001
28.38073820221e-0013.36399274746e-0018.56969321222e-001
36.32138908185e-0015.41650756113e-0021.82265148152e-001
48.59740023776e-0019.27965545082e-00
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PFC 手册 fish 翻译 中英文 讲义