下载

5下载券

加入VIP
  • 专属下载券
  • 上传内容扩展
  • 资料优先审核
  • 免费资料无限下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 C++_Fortran90_Fortran77_Matlab 的详细语法比较

C++_Fortran90_Fortran77_Matlab 的详细语法比较.pdf

C++_Fortran90_Fortran77_Matlab …

drbbs
2011-04-19 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《C++_Fortran90_Fortran77_Matlab 的详细语法比较pdf》,可适用于工程科技领域

FortranOverviewJEAkin,CopyrightThisoverviewofFortran(F)featuresispresentedasaseriesoftablesthatillustratethesyntaxandabilitiesofFFrequentlycomparisonsaremadetosimilarfeaturesintheCandFlanguagesandtotheMatlabenvironmentThesetablesshowthatFhassignificantimprovementsoverFandmatchesorexceedsnewersoftwarecapabilitiesfoundinCandMatlabfordynamicmemorymanagement,userdefineddatastructures,matrixoperations,operatordefinitionandoverloading,intrinsicsforvectorandparallelprocessorsandthebasicrequirementsforobjectorientedprogrammingTheyareintendedtoserveasacondensedquickreferenceguideforprogramminginFandforunderstandingprogramsdevelopedbyothersListofTablesCommentsyntaxIntrinsicdatatypesofvariablesArithmeticoperatorsRelationaloperators(arithmeticandlogical)PrecedencepeckingorderColonOperatorSyntaxanditsApplicationsMathematicalfunctionsFlowControlStatementsBasicloopconstructsIFConstructsNestedIFConstructsLogicalIFELSEConstructsLogicalIFELSEIFConstructsCaseSelectionConstructsFOptionalLogicBlockNamesGOTOBreakoutofNestedLoopsSkipaSingleLoopCycleAbortaSingleLoopFDOsNamedforControlLoopingWhileaConditionisTrueFunctiondefinitionsArgumentsandreturnvaluesofsubprogramsDefiningandreferringtoglobalvariablesBitFunctionIntrinsicsTheACSIICharacterSetFCharacterFunctionsHowtotypenonprintingcharactersReferencingStructureComponentsDefiningNewTypesofDataStructureNestedDataStructureDefinitionsDeclaring,initializing,andassigningcomponentsofuserdefineddatatypesFDerivedTypeComponentInterpretationDefinitionofpointersandaccessingtheirtargetsifingaPointertoBreakAssociationwithTargetSpecialArrayCharactersArrayOperationsinProgrammingConstructsEquivalentFortranandMATLABIntrinsicFunctionsTruncatingNumbersFWHEREConstructsFArrayOperatorswithLogicMaskControlArrayinitializationconstructsArrayinitializationconstructsLISTOFTABLESElementarymatrixcomputationalroutinesDynamicallocationofarraysandpointersAutomaticmemorymanagementoflocalscopearraysFSingleInheritanceFormFSelectiveSingleInheritanceFormFSingleInheritanceForm,withLocalRenamingFMultipleSelectiveInheritancewithRenamingLISTOFTABLESLanguageSyntaxLocationMATLABcomment(toendofline)anywhereC*comment*anywhereF!comment(toendofline)anywhereF*comment(toendofline)columnTable:CommentsyntaxStorageMATLABaCFFbytecharcharacter::characterintegerintinteger::integersingleprecisionfloatreal::realdoubleprecisiondoublereal*::doubleprecisioncomplexbcomplex::complexBooleanboollogical::logicalargumentparameter::parameterpointer*pointer::structurestructtype::aMATLABrequiresnovariabletypedeclarationtheonlytwodistincttypesinMATLABarestringsandreals(whichincludecomplex)BooleansarejustsandstreatedasrealsMATLABallowstheusertoselectmoretypesbThereisnospecificdatatypeforacomplexvariableinCtheymustbecreatedbytheprogrammerTable:IntrinsicdatatypesofvariablesDescriptionMATLABaCFortranbadditionsubtractioncmultiplication*and***divisionandexponentiationˆandˆpowd**remainderincrementdecrementparentheses(expressiongrouping)()()()aWhendoingarithmeticoperationsonmatricesinMATLAB,aperiod(‘’)mustbeputbeforetheoperatorifscalararithmeticisdesiredOtherwise,MATLABassumesmatrixoperationsfigureoutthedifferencebetween‘*’and‘*’Notethatsincematrixandscalaradditioncoincide,no‘’operatorexists(sameholdsforsubtraction)bFortranallowstheusertochangeoperatorsandtodefinenewoperatorsymbolscInalllanguagestheminussignisusedfornegation(ie,changingsign)dInCtheexponentiationiscalculatedbyfunctionpow���������Table:ArithmeticoperatorsLISTOFTABLESDescriptionMATLABCFFEqualto======EQNotequalto˜=!==NELessthan<<<LTLessorequal<=<=<=LEGreaterthan>>>GTGreaterorequal>=>=>=GELogicalNOT˜!NOTNOTLogicalANDANDANDLogicalinclusiveOR!||ORORLogicalexclusiveORxorXORXORLogicalequivalent====EQVEQVLogicalnotequivalent˜=!=NEQVNEQVTable:Relationaloperators(arithmeticandlogical)MATLABOperatorsCOperatorsFOperatorsaFOperators()()>()()!*(type)sizeof********bbbb<<=>>=<<>>==˜=<<=>=>===<<=>>=EQNELTLEGTGE˜==!=NOTNOTANDAND|||OROR=|EQVNEQVEQVNEQV:===*====ˆ=|=<<=>>=,aUserdefinedunary(binary)operatorshavethehighest(lowest)precedenceinFbThesearebinaryoperatorsrepresentingadditionandsubtractionUnaryoperatorsandhavehigherprecedenceTable:PrecedencepeckingorderB=Beginning,E=Ending,I=IncrementSyntaxFMATLABDefaultB:E:IB:I:E�BB:B:�E:E:EFullrange::UseFMATLABArraysubscriptrangesyesyesCharacterpositionsinastringyesyesLoopcontrolnoyesArrayelementgenerationnoyesTable:ColonOperatorSyntaxanditsApplicationsLISTOFTABLESDescriptionMATLABCFFexponentialexp(x)exp(x)exp(x)exp(x)naturalloglog(x)log(x)log(x)log(x)baseloglog(x)log(x)log(x)log(x)squarerootsqrt(x)sqrt(x)sqrt(x)sqrt(x)raisetopower(���)xˆrpow(x,r)x**rx**rabsolutevalueabs(x)fabs(x)abs(x)abs(x)smallestinteger�xceil(x)ceil(x)ceiling(x)largestinteger�xfloor(x)floor(x)floor(x)divisionremainderrem(x,y)fmod(x,y)mod(x,y)�mod(x,y)modulomodulo(x,y)acomplexconjugateconj(z)conjg(z)conjg(z)imaginarypartimag(z)imag(z)aimag(z)dropfractionfix(x)aint(x)aint(x)roundnumberround(x)nint(x)nint(x)cosinecos(x)cos(x)cos(x)cos(x)sinesin(x)sin(x)sin(x)sin(x)tangenttan(x)tan(x)tan(x)tan(x)arccosineacos(x)acos(x)acos(x)acos(x)arcsineasin(x)asin(x)asin(x)asin(x)arctangentatan(x)atan(x)atan(x)atan(x)arctangentbatan(x,y)atan(x,y)atan(x,y)atan(x,y)hyperboliccosinecosh(x)cosh(x)cosh(x)cosh(x)hyperbolicsinesinh(x)sinh(x)sinh(x)sinh(x)hyperbolictangenttanh(x)tanh(x)tanh(x)tanh(x)hyperbolicarccosineacosh(x)hyperbolicarcsineasinh(x)hyperbolicarctanatanh(x)aDifferfor����batan(x,y)isusedtocalculatethearctangentof���intherange���������Theoneargumentfunctionatan(x)computesthearctangentof�intherange������������Table:MathematicalfunctionsLISTOFTABLESDescriptionCFFMATLABConditionallyexecutestatementsifififif���endifendifendLoopaspecificnumberoftimesfork=:ndok=,ndo#k=,nfork=:n���enddo#continueendLoopanindefinitenumberoftimeswhiledowhilewhile���enddoendTerminateandexitloopbreakexitgotobreakSkipacycleofloopcontinuecyclegotoDisplaymessageandaborterror()stopstoperrorReturntoinvokingfunctionreturnreturnreturnreturnConditionalarrayactionwhereifConditionalalternatestatementselseelseelseelseelseifelseifelseifelseifConditionalarrayalternativeselsewhereelseelseifConditionalcaseselectionsswitch���selectcaseififendselectendifendTable:FlowControlStatementsLoopMATLABCFortranIndexedloopforindex=matrixstatementsendfor(inittestinc)�statements�doindex=b,e,istatementsenddoPretestloopwhileteststatementsendwhile(test)�statements�dowhile(test)statementsenddoPosttestloopdo�statements�while(test)dostatementsif(test)exitenddoTable:BasicloopconstructsLISTOFTABLESMATLABFortranCiflexpressiontruegroupendIF(lexpression)THENtruegroupENDIFif(lexpression)�truegroup�IF(lexpression)truestatementif(lexpression)truestatementTable:IFConstructsThequantitylexpressionmeansalogicalexpressionhavingavaluethatiseitherTRUEofFALSEThetermtruestatementortruegroupmeansthatthestatementorgroupofstatements,respectively,areexecutediftheconditionalintheifstatementevaluatestoTRUEMATLABFortranCiflexpressiontruegroupAiflexpressiontruegroupBendtruegroupCendstatementgroupDIF(lexpression)THENtruegroupAIF(lexpression)THENtruegroupBENDIFtruegroupCENDIFstatementgroupDif(lexpression)�truegroupAif(lexpression)�truegroupB�truegroupC�statementgroupDTable:NestedIFConstructsMATLABFortranCiflexpressiontruegroupAelsefalsegroupBendIF(lexpression)THENtruegroupAELSEfalsegroupBENDIFif(lexpression)�truegroupA�else�falsegroupB�Table:LogicalIFELSEConstructsMATLABFortranCiflexpressiontruegroupAelseiflexpressiontruegroupBelseiflexpressiontruegroupCelsedefaultgroupDendIF(lexpression)THENtruegroupAELSEIF(lexpression)THENtruegroupBELSEIF(lexpression)THENtruegroupCELSEdefaultgroupDENDIFif(lexpression)�truegroupA�elseif(lexpression)�truegroupB�elseif(lexpression)�truegroupC�else�defaultgroupD�Table:LogicalIFELSEIFConstructsLISTOFTABLESFCSELECTCASE(expression)CASE(value)groupCASE(value)groupCASE(valuen)groupnCASEDEFAULTdefaultgroupENDSELECTswitch(expression)�casevalue:groupbreakcasevalue:groupbreakcasevaluen:groupnbreakdefault:defaultgroupbreak�Table:CaseSelectionConstructsFNamedIFFNamedSELECTname:IF(logical)THENtruegroupAELSEIF(logical)THENtruegroupBELSEdefaultgroupCENDIFnamename:SELECTCASE(expression)CASE(value)groupCASE(value)groupCASEDEFAULTdefaultgroupENDSELECTnameTable:FOptionalLogicBlockNamesFortranCDODOIF(disaster)THENGOTOENDIFENDDOENDDOnextstatementfor()�for()�if(disaster)gotoerror��error:Table:GOTOBreakoutofNestedLoopsThissituationcanbeanexceptiontothegeneralrecommendationtoavoidGOTOstatementsLISTOFTABLESFFCDOI=,NIF(skipcondition)THENGOTOELSEfalsegroupENDIFcontinueDOI=,NIF(skipcondition)THENCYCLE!tonextIELSEfalsegroupENDIFENDDOfor(i=i<ni)�if(skipcondition)continuetonextelseiffalsegroupend�Table:SkipaSingleLoopCycleFFCDOI=,NIF(exitcondition)THENGOTOELSEfalsegroupENDIFCONTINUEnextstatementDOI=,NIF(exitcondition)THENEXIT!thisdoELSEfalsegroupENDIFENDDOnextstatementfor(i=i<ni)�if(exitcondition)breakoutofloopelseiffalsegroupend�nextstatementTable:AbortaSingleLoopmain:DO!forevertest:DOk=,kmaxthird:DOm=mmax,mmin,IF(testcondition)THENCYCLEtest!looponkENDIFENDDOthird!looponmfourth:DOn=nmin,nmax,IF(maincondition)THENEXITmain!foreverloopENDDOfourth!onnENDDOtest!overkENDDOmainnextstatementTable:FDOsNamedforControlLISTOFTABLESMATLABCinitializetestwhilelexpressiontruegroupchangetestendinitializetestwhile(lexpression)�truegroupchangetest�FFinitializetest#continueIF(lexpression)THENtruegroupchangetestgoto#ENDIFinitializetestdowhile(lexpression)truegroupchangetestenddoTable:LoopingWhileaConditionisTrueFunctionTypeMATLABaCFortranprogramstatementsyyn=f(a,,am)endoffilemain(argc,char**argv)�statementsy=f(a,I,am)�programmaintypeytypea,,typeamstatementsy=f(a,,am)calls(a,,am)endprogramsubroutinevoidf(typea,,typeam)�statements�subroutines(a,,am)typea,,typeamstatementsendfunctionfunctionrrn=f(a,,am)statementstypef(typea,,typeam)�statements�functionf(a,,am)typeftypea,,typeamstatementsendaEveryfunctionorprograminMATLABmustbeinseparatefilesTable:FunctiondefinitionsIneachcase,thefunctionbeingdefinedisnamedfandiscalledwithmargumentsa,,amLISTOFTABLESOneInput,OneResultProceduresMATLABfunctionout=name(in)Ffunctionname(in)!name=outfunctionname(in)result(out)Cname(in,out)MultipleInput,MultipleResultProceduresMATLABfunctioninout,out=name(in,in,inout)Fsubroutinename(in,in,inout,out)Cname(in,in,inout,out)Table:ArgumentsandreturnvaluesofsubprogramsGlobalVariableDeclarationMATLABgloballistofvariablesFcommonsetnamelistofvariablesFmodulesetnamesavetype(typetag)::listofvariablesendmodulesetnameCexternlistofvariablesAccesstoGlobalVariablesMATLABgloballistofvariablesFcommonsetnamelistofvariablesFusesetname,onlysubsetofvariablesusesetnamelistofvariablesCexternlistofvariablesTable:DefiningandreferringtoglobalvariablesActionCFBitwiseANDiandBitwiseexclusiveOR�ieorBitwiseexclusiveOR�iorCircularbitshiftishftcClearbitibclrCombinationofbitsmvbitsExtractbitibitsLogicalcomplement�notNumberofbitsinintegersizeofbitsizeSetbitibsetShiftbitleft�ishftShiftbitright�ishftTestonoroffbtestTransferbitstointegertransferTable:BitFunctionIntrinsicsLISTOFTABLESNULSOHSTXETXEOTENQACKBELBSHTNLVTNPCRSOSIDLEDCDCDCDCNAKSYNETBCANEMSUBESCFSGSRSUSSP!"#$’()*,:<=>ABCDEFGHIJKLMNOPQRSTUVWXYZˆ‘abcdefghijklmnopqrstuvwxyz{|}˜DELTable:TheACSIICharacterSetACHAR(I)CharacternumberIinASCIIcollatingsetADJUSTL(STRING)AdjustleftADJUSTR(STRING)AdjustrightCHAR(I)�CharacterIinprocessorcollatingsetIACHAR(C)PositionofCinASCIIcollatingsetICHAR(C)PositionofCinprocessorcollatingsetINDEX(STRING,SUBSTRING)aStartingpositionofasubstringLEN(STRING)LengthofacharacterentityLENTRIM(STRING)LengthwithouttrailingblanksLGE(STRINGA,STRINGB)LexicallygreaterthanorequalLGT(STRINGA,STRINGB)LexicallygreaterthanLLE(STRINGA,STRINGB)LexicallylessthanorequalLLT(STRINGA,STRINGB)LexicallylessthanREPEAT(STRING,NCOPIES)RepeatedconcatenationSCAN(STRING,SET)aScanastringforacharacterinasetTRIM(STRING)RemovetrailingblankcharactersVERIFY(STRING,SET)aVerifythesetofcharactersinastringSTRINGASTRINGBConcatenatetwostringsaOptionalargumentsnotshownTable:FCharacterFunctionsActionASCIICharacterFInputaCInputAlert(Bell)CtrlG�aBackspaceCtrlH�bCarriageReturnCtrlM�rEndofTransmissionCtrlDCtrlDFormFeedCtrlL�fHorizontalTabCtrlI�tNewLineCtrlJ�nVerticalTabCtrlK�va“Ctrl”denotescontrolactionThatis,simultaneouspressingoftheCONTROLkeyandtheletterfollowingTable:HowtotypenonprintingcharactersLISTOFTABLESC,CVariablecomponentsubcomponentFVariablecomponentsubcomponentTable:ReferencingStructureComponentsC,Cstructdatatag�intrinsictypecomponentnamesintrinsictypecomponentnames�Ftypedatatagintrinsictype::componentnamesintrinsictype::componentnamesendtypedatatagTable:DefiningNewTypesofDataStructureC,Cstructdatatag�intrinsictypeco

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/22

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利