Example: dental hygienist

Lecture - People at VT Computer Science

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).p rogram<name>declarationsexecutablecodeend[program<name>]Opena \helloworld"program:!my rstFortranprogramprogramhelloprint ,'HelloWorld!

2 c Adrian Sandu, 1998-2001. In tro duction to F95 and Numerical Computing. Ac kno wledgemen ts The presen t lecture notes are based in part on the follo

Tags:

  Lecture, Computing, Conduit, In tro duction

Information

Domain:

Source:

Link to this page:

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

Other abuse

Advertisement

Transcription of Lecture - People at VT Computer Science

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).p rogram<name>declarationsexecutablecodeend[program<name>]Opena \helloworld"program:!my rstFortranprogramprogramhelloprint ,'HelloWorld!

2 ' ,whichdescribethe\freesourceform". statementscanbegininanycolumn; multiplestatementsonalineareallowed;they havetobeseparatedbysemicolon\;" anexclamationmark\!"inanycolumnisthebegi nningofacomment;therestofthelineisignore dbythecompiler; astatementcanbecontinuedonthefollowingli nebyappendinga\&" ,theabovecodefragmentcouldbewritteninfre esourceformas56c AdrianSandu, !Thisisfree formtemp=x;x=y;y=temp!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").

3 ,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\.f90"(forexample, ). ers,whichobeythefollowingrestrictions: containupto31characters; the rstcharactermustbealetter; namesarecase-insensitive(nodistictionbet weenupperandlowercase).

4 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) .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 ).

5 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!

6 ::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,. ).Adeclarationwithinitializationmaylookl ikelogical::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, !

7 InF90implicitdeclarationsarepermitted, ,theiruseisaverybadprogram-minghabit,asi tcanmaskprogrammingerrors, ,amisspellingofavariablenamewillresultin anewvariabledeclaration,whichcanbefurthe rassignedetc, ( )isdo30i= <statements>30continueInsteadofaDOloop,becauseofthem isprints,wewillendupwithanewrealvariable , ,wewillalwaysdisabletheimplicitdeclarati onsbyplacingthecommandimplicitnoneasthe rstlineafteranyUSEstatements( ).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.)

8 TheexpenentisprecededbyE)Y=X+ + +1 Fordoubleprecisionconstants,wealwaysuses cienti cnotation,butnowtheexponentmarkerEisrepl acedbyD,fromdouble:Y=X+ + +1 Forcomplexliteralconstantsweneedtospecif ya(realpart,imaginarypart) :25+4:1iwedoZ=( , )Logicalconstantscantakeoneoftwovalues,w rittenasQ=. ,characterliteralconstantsaredelimitedby singleordoublequotesC='A'orC="A"Ifthedel imiterispartofthestring,theconventionist owriteittwiceinsidethestring,forexampleC ='O"Malley'12c AdrianSandu, ::a,blogical::a<relationaloperator>bF77 > >= <= < (. ). ( ) ::a,blogical::[a]<logicaloperator> ( ,elseF). ( ,elseT). , ,ifoperandshavedi ::a,blogical::q1,q2q1=(. ).AND.( ) (len= ),parameter::school="michigantech"c AdrianSandu, (2:4)"ich"school(:8)"michigan"school(9:) "tech"school(4)error(stringisscalar)scho ol(4:4)"h"(correctform) (len= ),parameter::&state="michigan",name="tec h"character(len=12)::schoolschool=state/ /name!

9 Produces"michigantech" nedmonadichighest (tightestbinding) ;=.monadic+; .dyadic+; .==.relationaloperators(. ).. ,.NEQV.(weakestbinding)user-de neddyadiclowestFormultiplesame-leveloper atorsevaluationisdonelefttoright(exceptf or ).Paranthesiscanaltertheorderofevaluatio n, erences, C6=A=(B C)orA=2 29;B=1:999999 2 30;C=1:999998 2 30;X=A+B C!X=1;(over ow)Y=A+(B C)!Y= :NOT:A:AND:B:EQV:C:OR:D:AND:E:OR:x:GT:y: AND:y: (are\intrinsic"toFortran). AdrianSandu, :[hnamei:]IF(hlogicalexpri)THEN hthenblocki[ ELSEIF(hlogicalexpri)THEN[hnamei]helseif blocki ][ELSE[hnamei]helseblocki]ENDIF[hnamei] , ,theELSEIF-shlogicalexpriessionsareevalu atedsuccesively,untilthe ,theELSE branchistaken(ifpresent).

10 IftheELSE branchisnotpresentthecontrolistransferre dtothe (Discusscontrol owdiagramwithrombsandrectangles)if( )thenprint*,"i>17!"endifif( )thenprint*,"i>17!"elseprint*,"i<=17!"endifif( )thenprint*,"i>17!"elseif( )thenprint*,"i=17!"c AdrianSandu, ( )thenprint*,"i=16!"elseprint*,"i<16!" ::a,b,c!coe ::d!determinantreal::x1,x2!solutions,ifr eal(casesI,II)real::xre,xim!realandimagi narypartsofsolutions(caseIII)!readinthec oe cientsprint ,' .a,b,c:'read ,a,b,cd=b 2 a c!checkthecasesandtreatthemseperateif( )thenx1=( b SQRT(d))/( a)x2=( b+SQRT(d))/( a)print ,' :',&'x1=',x1,'x2=',x2elseif( )thenx1= b/( a)print ,' :',&'x1=x2=',x1else!d<0xre= b/( a)xim=SQRT( d)/( a)print ,' conjugateroots:',&xre,'+/ ',xim,'i'endifendprogramquadraticeqn1 Exampleofcomplexnumbersuse:solvingaquadr aticequation, ::a,b,ccomplex::d,x1,x2,sd!


Related search queries