Example: biology

Lecture - Virginia Tech

LectureNotesIntroductiontoFortran95andNu mericalComputingAJump-StartforScientists andEngineersAdrianSanduComputerScienceDe partment,MichiganTechnologicalUniversity Reproductionof(partsof)thisdocumentisper missibleonlywithauthor' ,20012c AdrianSandu, :\Fortran90 Programming"byEllis,PhilipsandLahey,Addi son-Wesleypublishingcompany,1994;\Fortra n90 CourseNotes" , ,1997;\Elementarynumericalanalysis" ,2ndedition,JohnWiley&Sons,Inc, AdrianSandu, (optional),followedbytheprogramname(also otional);itendswiththekeywordend(require d),followedbyprogramNameProg(optional).

Lecture Notes In tro duction to F ortran 95 and Numerical Computing A Jump-Start for Scien tists and Engineers Adrian Sandu Computer Science Departmen t, Mic higan T

Tags:

  Lecture, M ichigan, Higan

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Lecture - Virginia Tech

1 LectureNotesIntroductiontoFortran95andNu mericalComputingAJump-StartforScientists andEngineersAdrianSanduComputerScienceDe partment,MichiganTechnologicalUniversity Reproductionof(partsof)thisdocumentisper missibleonlywithauthor' ,20012c AdrianSandu, :\Fortran90 Programming"byEllis,PhilipsandLahey,Addi son-Wesleypublishingcompany,1994;\Fortra n90 CourseNotes" , ,1997;\Elementarynumericalanalysis" ,2ndedition,JohnWiley&Sons,Inc, AdrianSandu, (optional),followedbytheprogramname(also otional);itendswiththekeywordend(require d),followedbyprogramNameProg(optional).

2 Program<name>declarationsexecutablecodeend[program<name>]Opena \helloworld"program:!my rstFortranprogramprogramhelloprint ,'HelloWorld!' ,whichdescribethe\freesourceform". statementscanbegininanycolumn; multiplestatementsonalineareallowed;they havetobeseparatedbysemicolon\;" anexclamationmark\!"inanycolumnisthebegi nningofacomment;therestofthelineisignore dbythecompiler; astatementcanbecontinuedonthefollowingli nebyappendinga\&" ,theabovecodefragmentcouldbewritteninfre esourceformas56c AdrianSandu, !Thisisfree formtemp=x;x=y;y=temp!

3 Swapxandywrite(6, )'xandyare=',&x,y!PrintxandyForback-comp atibilitywithFortran77,Fortran90acceptsa \ xedsourceform".Inshort,the xedsourceformrequirementsare: alllinesofcodestartinthe7th(orhigher)col umn;the rst6columnsarereservedforlabels,contin-u ationcharacters,etc. eachstatementiswrittenonaseparateline( ,statementsareseparatedbynewlines);astat ementcanbecontinuedonthenextlinebywritin g(any)characterinthe5thcolumnofthenewlin e; commentlinesstartwithaCinthe 's,wheneachlineofcodewaspunchedonapaperc ard(\punchedcard").

4 ,apunchedcardhadtobealigned,checkedifiti sanewstatementoracontinuationofthelast,i fitisacomment, rst6columns.(Amillion-linecode,quitecomm ontoday,onpunchedcards,neededatrucktobec arriedfromonecomputertoanother).Forexamp le,afragmentofaFortran90programin xedsourceform(infact,Fortran77program)ca nbe:C This is xed formC Swapxandytemp=xx=yy=tempC Printxandywrite(6, )'xandyare=', x,yOurcompiler(f90)willconsidertheprogra mtobein xedsourceformatifthesource lehastheextension\.f"(forexample, ).Thecompilerwillconsidertheprogramtobei nfreesourceformatifthesource lehastheextension\.

5 F90"(forexample, ). ers,whichobeythefollowingrestrictions: containupto31characters; the rstcharactermustbealetter; namesarecase-insensitive(nodistictionbet weenupperandlowercase).c AdrianSandu, , \bind"thevariablename(identi er)totheaddressofthereservedmemoryspace; thecontentofthereservedbyteswillholdthev ariable' (default)datatypesinFortran:character,lo gical,integer,real(singleprecision), :integerI,J,Korinteger::I,J,KAnintegerca nbedeclaredandinitializedwithinteger::I= 1 Normally,whentheprogramisloadedinmemory, thecontentsofthedeclaredvariablesareunde ned(somecompilersmaysetthemto0bydefault) .

6 Withinitialization, (whosevaluecannotbechangedlaterintheprog ram)canbedeclaredwithintegerMAXIMUM parameter(MAXIMUM=340)orwithinteger,para meter::MAXIMUM=340 Theplainformofdeclaration,andthetwo-stat ementparameterdeclarationcomefromF77, \::"formisspeci ( ,whenisintegerandparameter, ) :characterCorcharacter::CForastringofcha racters,wecanspecifythelengthand(optiona lly)initializeitascharacter(len=7)::LOGI NA gainweseethat,ifwewanttospecifymorethano neattribute(here,characterandlength) (PARAMETER)characters/strings,inwhichcas eweusethedeclarationcharacter(len=8),par ameter::LOGIN="johndoe"8c AdrianSandu, (theF77two-statementformisalsoacceptable ).

7 Heretheinitializationvalueis6-characterl ong,soitwillbepaddedby2blanksto ,iftheinitializationvaluewastoolong, ,wemayletthecharactervariableassumethele ngthoftheinitializationstringwithcharact er(len= ),parameter::LOGIN="johndoe",PASSWORD="m ichigantech"HereLOGIN willbe7-character, (forback-compatibilitywithF77):character 8::LOGINTheLENattributecanbeoverridenbya attributeinastringdeclarationasfollows:c haracter(len=8)::LOGIN,PASSWORD 12 HereLOGIN isastringof8characters, ; ,itispossibletodeclarea10 10matrixwhoseelementsare6-characterlongs trings:character(len=6),dimension(10,10) ::AAstringcanbesplitaccrosslinesbyadding anampersand& "michig&n&antech" ,Y,PIorreal::X,Y,PIstatethatX,YandPIares ingleprecision (whosevaluecannotbechangedsubsequently)m aybedeclaredwithrealPIparameter(PI= )orwithreal,parameter::PI= (seeabove),orfordeclarationsplusinitial- izationsreal::X= AdrianSandu, rstimplicitnone!

8 ::R,Pi,a,pPi= ,'Pleasegiveradius:'read ,Ra=Pi R! isexponentationp= Pi Rprint ,'Area=',a,'Perimieter=',pendprogram ,Y,PIordoubleprecision::X,Y,PIstatethatX ,YandPIaredoubleprecision ,Worcomplex::Z,WAFortrancomplexvariablei s(andisstoredas)apairofreal(singleprecis ion oatingpoint)variables(therealandtheimagi narypart,ofcourse).Forexample,todeclarea ndinitializethecomplexconstant2+3iweusec omplex,parameter::Z=( , ) (Boolean)variablesaredeclaredaslogicalQ, Porlogical::Q,PTheycantakeonly(oneof)two possiblevalues:trueorfalse(written,inFor trannotation.)

9 Adeclarationwithinitializationmaylooklik elogical::Q=.TRUE.,P=. AdrianSandu, [;hattribute listi]::&[;hvariablei[=hvaluei]]<attribute list>containsattributeslikePARAMETER,SAVE,INT ENT,POINTER,TARGET,DI-MENSION, , ,J,X, ;rather,itwillautomaticallydeclareI,Jasi ntegersandX, rstletterI,J,K,L,MorNareconsideredINTEGE R-s, !InF90implicitdeclarationsarepermitted, ,theiruseisaverybadprogram-minghabit,asi tcanmaskprogrammingerrors, ,amisspellingofavariablenamewillresultin anewvariabledeclaration,whichcanbefurthe rassignedetc, ( )isdo30i= <statements>30continueInsteadofaDOloop,becauseofthem isprints,wewillendupwithanewrealvariable , ,wewillalwaysdisabletheimplicitdeclarati onsbyplacingthecommandimplicitnoneasthe rstlineafteranyUSEstatements( ).

10 Withthiscommandinplace, + , , ,Znew=Zold+2 erentmeaningthanmathematicalequality(her e,themathematicalrelationZ=Z+2:0isanequa tionwithoutsolution).c AdrianSandu, ::a,bNUMERICTYPE::[a]hnumericaloperatori bFortran,likeanyotherlanguage,de ,subtraction,multiplication,divisionande xponentiationoperatorsaredenoted+; ; ;=;and ( +2:1or 2:1)ordyadic( :1 3:4) , :3 3:14,butnot( 2:3) 3 erentnumericaltypescanbeused(willseelate r),butweusuallycannotmixnumericalandchar acter, ; ,anumbercanberaisedtoanintegerpowerY=X 4;Z=X ( 6)Bothexponentvalues4, ,weneedtouseeitherdecimalpointnotationor scienti cnotation(similarto oatingpointnotationbase10:wehaveamantiss a,followedbyanexponentof10;theexpenentis precededbyE)Y=X+ + +1 Fordoubleprecisionconstants,wealwaysuses cienti cnotation,butnowtheexponentmarkerEisrepl acedbyD,fromdouble:Y=X+ + +1 Forcomplexliteralconstantsweneedtospecif ya(realpart,imaginarypart) :25+4:1iwedoZ=( , )Logicalconstantscantakeoneoftwovalues,w rittenasQ=.


Related search queries