Fortran 90 BasicsFortran 90 Basics

2y ago
8 Views
2 Downloads
275.07 KB
65 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Elisha Lemon
Transcription

Fortran 90 BasicsI don’tdon t know what the programming languageof the year 2000 will look like, but I know itwill be called FORTRAN.Charles Anthony Richard Hoare1Fall 2010

F90 Program StructurezAA Fortran 90 program has the following form: program-name is the name of that program specificationspecification-partpart, executionexecution-partpart, andsubprogram-part are optional. Althoughg IMPLICIT NONE is also optional,p, this isrequired in this course to write safe programs.PROGRAM program-nameIMPLICIT NONE[[specification-part]ifi rt]END PROGRAM program-name2

Program CommentszCommentsComments start with a !zEverything following ! will be ignoredzThis is similar to // in C/C ! This is an example!PROGRAM Comment.READ(*,*) Year! read in the value of Year.Year Year 1 ! add 1 to Year.END PROGRAM Comment3

Continuation LineszFortranFortran 90 is not completely formatformat-free!free!zA statement must starts with a new line.zIf a statementt tt iis ttoo llong tot fit on one line,li it hashto be continued.zThe continuation character is &, which is notpart of the statement.Total Total &Amount * Payments! Total Total Amount*PaymentsPROGRAM &ContinuationLineiii! PROGRAM ContinuationLine4

AlphabetszFortranFortran 90 alphabets include the following: Upper and lower cases letters Di it Digits Special charactersspace' "( ) * - / : ! & ; % ? , .5

Constants: 1/6zAA Fortran 90 constant may be an integer, real,logical, complex, and character string.zWe will not discuss complex constants.constantszAn integer constant is a string of digits with anoptional sign: 12345,12345 -345,345 789, 789 0. 06

Constants: 2/6zAA real constant has two forms, decimal andexponential: In the decimal form,form a real constant is astring of digits with exactly one decimalpoint A real constant may include anpoint.optional sign. Example: 2.45, .13, 13.,-00.12,12 -.12.127

Constants: 3/6z A real constant has two forms, decimal andexponential: In the exponential form,form a real constantstarts with an integer/real, followed by a E/e,followed by an integer (i(i.e.,e the exponent)exponent).Examples: 12E3 (12 103),) -12e312e3 (-12 10( 12 103),)3.45E-8 (3.45 10-8), -3.45e-8( 3 45 10-8).(-3.45 10) 0E0 (0 100 0). 12.34-5 is wrong!8

Constants: 4/6zA logicalgconstant is either .TRUE. or .FALSE.SzNote that the periods surrounding TRUE andFALSE are required!9

Constants: 5/6zAA character string or character constant is astring of characters enclosed between twodouble quotes or two single quotes. Examples:“abc”, ‘John Dow’, “# % ”, and ‘()()’.zThe content of a character string consists of allcharacters between the quotes. Example: Thecontent of ‘JohnJohn DowDow’ is John Dow.DowzThe length of a string is the number ofcharactershtbbetweentththe quotes.tThThe llengthth off‘John Dow’is 8, space included.10

Constants: 6/6zA stringg has lengthg zero (i.e.,( , no content)) is anempty string.g (or( double)) qquotes are used in a string,g,zIf singlethen use double (or single) quotes as delimiters.Examples: “Adam’s cat” and ‘I said“go away”’.zTwo consecutive quotes are treated as one!‘Lori’’s Apple’ is Lori’s Apple“double quote””” is double quote” abc’’def”x’’y’ is abc’def”x’yabc def x y is abcabc”def’x”ydef x y“abc””def’x””y”11

Identifiers: 1/2zAA Fortran 90 identifier can have no more than31 characters.zThe first one must be a letter.letter The remainingcharacters, if any, may be letters, digits, orunderscores.underscoreszFortran 90 identifiers are CASE INSENSITIVE.zExamples: A, Name, toTAL123, System ,myFile 01, my 1st F90 program X .zIdentifiers Name, nAmE, naME and NamE arethe same.12

Identifiers: 2/2zUnlike Java,, C,, C ,, etc,, Fortran 90 does nothave reserved words. This means one may useFortran keywords as identifiers.zTherefore, PROGRAM, end, IF, then, DO, etcmay be used as identifiers. Fortran 90compilers are able to recognize keywords fromtheir “positions” in a statement.zYes, end program if/(goto –while) is legal!zHowever, avoid the use of Fortran 90 keywordsas identifiers to minimize confusion.13

Declarations: 1/3zFortranFortran 90 uses the following for variabledeclarations, where type-specifier is oneof the followingg keywords:yINTEGER,, REAL,,LOGICAL, COMPLEX and CHARACTER, andlist is a sequenceqof identifiers separatedpbyycommas.type-specifiertypespecifier :: , Total, counterAVERAGE, x, DifferenceCondition, OKConjugate14

Declarations: 2/3zCharacterCharacter variables require additionalinformation, the string length: Keyword CHARACTER must be followed bya length attribute (LEN l) , where l isthe length of the stringstring. The LEN part is optional. If the length of a string is 1, one may useCHARACTER without length attribute. Other length attributes will be discussedlater.15

Declarations: 3/3zExamples:Examples: CHARACTER(LEN 20) :: Answer, QuoteVariables Answer and Quote can holdstrings up to 20 characters. CHARACTER(20) :: Answer, Quote isthe same as above. CHARACTER :: Keypress means variableKeypress can only hold ONE character (i.e.,length 1).16

The PARAMETER Attribute: 1/4zA PARAMETER identifier is a name whose valuecannot be modified. In other words, it is anamed constant.zThe PARAMETER attribute is used after the typekeyword.keywordzEach identifier is followed by a and followedb a valuebyl forf ththatt ididentifier.tifiINTEGER, PARAMETER :: MAXIMUM 10INTEGERREAL, PARAMETER:: PI 3.1415926, E 2.17828LOGICAL, PARAMETER :: TRUE .true., FALSE .false.17

The PARAMETER Attribute: 2/4zSince CHARACTER identifiers have a lengthgattribute, it is a little more complex when usedwith PARAMETER.zUse (LEN *) if one does not want to countthe number of characters in a PARAMETERcharacter string, where * means the length ofthis string is determined elsewhereelsewhere.CHARACTER(LEN 3), PARAMETER :: YES “yes”y! Len 3CHARACTER(LEN 2), PARAMETER :: NO “no”! Len 2CHARACTER(LEN *), PARAMETER :: &PROMPT “What do you want?” ! Len 1718

The PARAMETER Attribute: 3/4zSinceSince Fortran 90 strings are of fixed length, onemust remember the following: If a string is longer than the PARAMETERlength, the right end is truncated. If a string is shorter than the PARAMETERlength, spaces will be added to the right.CHARACTER(LEN 4), PARAMETER :: ABC “abcdef”CHARACTER(LEN 4), PARAMETER :: XYZ “xy”ABC abcdXYZ xy19

The PARAMETER Attribute: 4/4zByy convention,, PARAMETER identifiers use allupper cases. However, this is not mandatory.zFor maximum flexibility,flexibility constants other than 0and 1 should be PARAMETERized.zA PARAMETER is an alias of a value and is not avariable. Hence, one cannot modify the content ofa PARAMETER identifier.identifierzOne can may a PARAMETER identifier anywherein a program. It is equivalent to replacing theidentifier with its value.zThe value part can use expressions.20

Variable Initialization: 1/2zAA variable receives its value with Initialization: It is done once before theprogram runs.runs Assignment: It is done when the programexecutest an assignmentit statement.t tt Input: It is done with a READ statement.21

Variable Initialization: 2/2zVariableVariable initialization is very similar to what welearned with PARAMETER.zA variable name is followed by a , followed byan expression in which all identifiers must beconstants or PARAMETERs defined previously.previouslyzUsing an un-initialized variable may cause unexpected,t d sometimestididisastroustresults.ltREAL :: Offset 0.1, Length 10.0, tolerance 1.E-7CHARACTER(LEN 2) :: State1 "MI", State2 "MD“INTEGER, PARAMETER :: Quantity 10, Amount 435INTEGER, PARAMETER :: Period 3INTEGER :: Pay Quantity*Amount, Received Period 522

Arithmetic OperatorszThereThere are four types of operators in Fortran 90:arithmetic, relational, logical and character.zThe following shows the first three types:TypeArithmeticRelational OperatorAssociativity**right to left*/left to right -left to right Logical.EQV. / none.NOT.rightg to leftf.AND.left to right.OR.left to right.NEQV.left to right23

Operator Priorityz** is the highest;g; * and / are the next,, followedby and -. All relational operators are next.zOf the 5 logical operatorsoperators, .EQV.EQV and .NEQV.NEQVare the lowest.TypeArithmeticRelational OperatorAssociativity**right to left*/left to right -left to right Logical.EQV. / none.NOT.right to left.AND.left to right.OR.left to right.NEQV.highesthihpriorityleft to right24

Expression EvaluationzExpressionsExpressions are evaluated from left to right.zIf an operator is encountered in the process ofevaluation its priority is compared with that ofevaluation,the next one if theth nextt one isi lower,levaluatel t theth currenttoperator with its operands; if the next one is equal to the current, theassociativity laws are used to determinewhich one should be evaluated; if the next one is higher, scanning continues25

Single Mode ExpressionzAA single mode arithmetic expression is anexpression all of whose operands are of thesame type.zIf the operands are INTEGERs (resp., REALs),the result is also an INTEGER (resp.,(resp REAL).REAL)1.0 2.0 * 3.0 / ( 6.0*6.0 5.0*44.0) ** 0.25-- 1.0 6.0 / (6.0*6.0 5.0*44.0) ** 0.25-- 1.0 6.0 / (36.0 5.0*44.0) ** 0.25-- 1.0 6.0 / (36.0 220.0) ** 0.25-- 1.01 0 6.06 0 / 256.0256 0 ** 00.2525-- 1.0 6.0 / 4.0-- 1.0 1.5-- 2.52 526

Mixed Mode Expression: 1/2zIfIf operands have different types, it is mixedmode.zINTEGER and REAL yields REAL,REAL and theINTEGER operand is converted to REAL beforeevaluation Example: 3.5evaluation.3 5*44 is converted to3.5*4.0 becoming single mode.zException: x**INTEGER: x**3 is x*x*x andx**(-3) is 1.0/(x*x*x).zx**REAL isi evaluatedld withi h log() andd exp().zLogical and character cannot be mixed witharithmetic operands.27

Mixed Mode Expression: 2/2zNote that a**b**c is a**(b**c)() instead of(a**b)**c, and a**(b**c) (a**b)**c.This can be a big trap!5 * (11.0 - 5) ** 2 / 4-- 5 * (11.0 - 5.0)-- 5 * 6.0 ** 2 / 4-- 5 * 36.0 / 4 9-- 5.0 * 36.0 / 4 -- 180.0 / 4 9-- 180.0180 0 / 4.04 0 9-- 45.0 9-- 45.0 9.0-- 54.054 0 9** 2 / 4 9 99red: type conversion6.0**2 is evaluated as 6.0*6.0rather than converted to 6.0**2.0!28

The Assignment Statement: 1/2zTheThe assignment statement has a form ofvariable expressionzIf the type of variableariable and expressione pression areidentical, the result is saved to variable.zIf the type of variable and expression arenot identical, the result of expression isconverted to the type off variable.zIf expression is REAL and variable isINTEGER, the result is truncated.29

The Assignment Statement: 2/2zTheThe left example uses an initialized variableUnit, and the right uses a PARAMETER PI.INTEGER :: Total, AmountINTEGER :: Unit 5Amount 100.99Total Unit * AmountREAL, PARAMETER :: PI 3.1415926REAL :: AreaINTEGER :: RadiusRadius 5Area (Radius ** 2) * PIThis one is equivalent to Radius ** 2 * PI30

Fortran Intrinsic Functions: 1/4zFortranFortran provides many commonly usedfunctions, referred to as intrinsic functions.zTo use an intrinsic functionfunction, we need to know: Name and meaning of the function (e.g.,SQRT() for square root) Number of arguments The type and range of each argument (e.g.,the argument of SQRT() must be nonnegative)ype oof thee returnede u ed functionu c o value.v ue. Thee type31

Fortran Intrinsic Functions: 2/4zSomeSome mathematical functions:FunctionMeaningArg. TypeReturn TypeINTEGERINTEGERREALREALABS(x)absoluteb lvaluel off xSQRT(x)square root of xREALREALSIN(x)sine of x radianREALREALCOS(x)cosine of x radianREALREALTAN(x)tangent of x radianREALREALASIN(x)arc sine of xREALREALACOS(x)arc cosine of xREALREALATAN(x)arc tangent of xREALREALEXP(x)exponential exREALREALLOG(x)natural logarithm of xREALREALLOG10(x) is the common logarithm of x!32

Fortran Intrinsic Functions: 3/4zSomeSome conversion functions:FunctionMeaningArg. TypeReturn TypeINT(x)truncate to integer part xREALINTEGERNINT(x)round nearest integer to xREALINTEGERFLOOR(x)greatest integer less than or equal to xREALINTEGERREALREALINTEGERREALFRACTION(x) the fractional part of xREAL(x)convert x to REALExamples:INT(-3.5) Æ -3NINT(3.5) Æ 4NINT(-3.4) Æ -3FLOOR(3.6) Æ 3FLOOR(-3.5) Æ -4FRACTION(12.3)C O (12 3) Æ 0.30 3REAL(-10) Æ -10.033

Fortran Intrinsic Functions: 4/4zOtherOther functions:FunctionMeaningMAX(x1, x2, ., xn) maximum of x1, x2, . xnMIN(x1 x2,MIN(x1,x2 ., xn) minimum of x1,x1 x2,x2 . xnMOD(x,y)remainder x - INT(x/y)*yArg. TypeReturn TEGERINTEGERREALREAL34

Expression EvaluationzFunctions have the highest priority.zFunction arguments are evaluated first.zThe returned function value is treated as avalue in the expression.REAL :: A 1.0, B -5.0,5.0, C 6.0, RR (-B SQRT(B*B - 4.0*A*C))/(2.0*A)(-B SQRT(B*B - 4.0*A*C))/(2.0*A)/-- (5.0 SQRT(B*B - 4.0*A*C))/(2.0*A)-- (5.0 SQRT(25.0 - 4.0*A*C))/(2.0*A)-- (5.0 SQRT(25.0 - 4.04.0*C))/(2.0*A)C))/(2.0 A)-- (5.0 SQRT(25.0 - 24.0))/(2.0*A)-- (5.0 SQRT(1.0))/(2.0*A)-- (5.0 1.0)/(2.0*A)-- 6.0/(2.0*A)6 0/(2 0* )-- 6.0/2.0-- 3.0R gets 3.035

What is IMPLICIT NONE?zFortran has an interestingg tradition: allvariables starting with i, j, k, l, m and n, ifnot declared, are of the INTEGER type bydefault.zThis handy feature can cause seriousconsequences if it is not used with care.zIMPLICIT NONE means all names must bedeclared and there is no implicitly assumedINTEGER type.zAll programs in this class must use IMPLICITNONE. Points will be deducted if you do not use it!it36

List-DirectedListDirected READ: 1/5zFortran 90 uses the READ(*,*)( , ) statement toread data into variables from keyboard:READ(*,*)READ() v1,v1 v2v2, , vnREAD(*,*)zThe second form has a special meaning that willbe discussed later.INTEGER:: AgeREAL:: Amount, RateCHARACTER(LEN 10) :: NameREAD(*,*)Name, Age, Rate, Amount37

List-DirectedListDirected READ: 2/5zDataData Preparation Guidelines READ(*,*) reads data from keyboard bydefault although one may use inputdefault,redirection to read from a file. If READ(*,*)READ(* *) has n variables,variables there mustbe n Fortran constants. Each constant must have the type of thecorresponding variable. Integers can bereadd iinto REAL variablesi bl butb not vicei versa. Data items are separated by spaces and mayspread into multiple lines.38

List-DirectedListDirected READ: 3/5zThe execution off READ(*,*)( , ) alwaysy starts witha new line!zThen it reads each constant into thezThen,corresponding variable.CHARACTER(LEN 5) :: NameREAL:: height, lengthINTEGER:: count, MaxLengthREAD(*,*) Name, height, count, length, MaxLengthInput:put: "Smith" 100.0 25 123.579 1000039

List-DirectedListDirected READ: 4/5zBeBe careful when input items are on multiple lines.INTEGER :: I,J,K,L,M,NInput:100 200300 400 500600READ(*,*) I, JREAD(*,*) K, L, MREAD(*,*) Nignored!INTEGER :: I,J,K,L,M,NREAD(*,*) I, J, KREAD(*,*) L, M, N100500900200600300700400800READ(*,*) always starts with a new line40

List-DirectedListDirected READ: 5/5zSince READ(*,*)( , ) alwaysy starts with a new line,,a READ(*,*) without any variable meansskipping the input line!INTEGER :: P, Q, R, SREAD(*,*) P, QREAD(*,*)( , )READ(*,*) R, S10040070020050080030060090041

List-DirectedListDirected WRITE: 1/3zFortran 90 uses the WRITE(*,*)( , ) statement towrite information to screen.zWRITE(*,*)zWRITE() has two formsforms, where exp1,exp1exp2, , expn are expressionsWRITE(* *) eWRITE(*,*)exp1,p1 exp2,e p2 , eexpnpnWRITE(*,*)zWRITE(*,*) evaluates the result of eachexpression and prints it on screen.zWRITE(*,*) always starts with a new line!42

List-DirectedListDirected WRITE: 2/3zHereHere is a simple example:means length is determined by actual countINTEGER :: TargetREAL :: Angle, DistanceCHARACTER(LEN *), PARAMETER ::&Time "The time to hit target “, &IS " is “,&UNIT " sec."continuationtiti lilinesTarget 10Angle Angle 20.0DistanceDistance 1350.0The timeWRITE(* *) 'AngleWRITE(*,*)'A l '', AAnglelWRITE(*,*) 'Distance ', DistanceWRITE(*,*)WRITE(* *) Time,WRITE(*,*)Time TargetTarget, ISIS,&Angle * Distance, UNITprint a blank lineOutput:20.0 1350.0to hit target10is27000.043sec.

List-DirectedListDirected WRITE: 3/3zThe pprevious examplep used LEN * , whichmeans the length of a CHARACTER constant isdetermined by actual count.zWRITE(*,*) without any expression advancesto the next line, producing a blank one.zA Fortran 90 compiler will use the best way toprint each value. Thus, indentation andalignment are difficult to achieve withWRITE(*,*).zOne must use the FORMAT statement to producegood looking output.44

Complete Example: 1/4z This pprogramgcomputespthe pposition ((x and ycoordinates) and the velocity (magnitude and direction)of a projectile, given t, the time since launch, u, thelaunch velocity,i a, the initiali i i angle of launch (ini degree),and g 9.8, the acceleration due to gravity.z The horizontal and vertical displacements, x and y, arecomputed as follows:x u cos(a ) tg ty u sin(a ) t 2245

Complete Example: 2/4z The horizontal and vertical componentspof the velocityyvector are computed asVx u cos(a )Vy u sin((a ) g tz The magnitude of the velocity vector isV Vx2 V y2z The angle between the ground and the velocity vector isVxtan(θ ) Vy46

Complete Example: 3/4z Write a pprogramgto read in the launch angleg a,, the timesince launch t, and the launch velocity u, and computethe position, the velocity and the angle with the ground.PROGRAM ProjectileIMPLICIT NONEREAL, PARAMETER :: g 9.8REAL, PARAMETER :: PI 3.1415926REAL :: AngleREAL :: TimeREAL :: ThetaREAL :: UREAL :: VREAL :: VxREAL :: VyREAL :: XREAL :: Y Other executable statementsEND PROGRAM Projectile! acceleration due to gravity! you know this. don't you?! launch angle in degree! time to flight! direction at time in degree! launch velocity! resultant velocity! horizontal velocity! vertical velocity! horizontal displacement! vertical displacement 47

Complete Example: 4/4z Write a pprogramgto read in the launch angleg a,, the timesince launch t, and the launch velocity u, and computethe position, the velocity and the angle with the ground.READ(*,*) Angle, Time, UAngleXYVxVyVTheta Angle * PI / 180.0! convert to radianU * COS(Angle) * TimeU * SIN(Angle) * Time - g*Time*Time / 2.0U * COS(Angle)gU * SIN(Angle) - g * TimeSQRT(Vx*Vx Vy*Vy)ATAN(Vy/Vx) * 180.0 / PI ! convert to izontal displacement'Vertical displacement'Resultant velocity'Direction (in degree)::::',',',',XYVTheta48

CHARACTER Operator //zFortran 90 uses // to concatenate two strings.gzIf strings A and B have lengths m and n, theconcatenation A // B is a string of length m n.m nCHARACTER(LEN 4) :: John "John", Sam "Sam"CHARACTER(LEN 6) :: Lori "Lori", Reagan "Reagan"CHARACTER(LEN 10) :: Ans1, Ans2, Ans3, Ans4Ans1Ans2Ans3Ans4 John // LoriSam // ReaganReagan // SamLori // Sam!!!!Ans1Ans2Ans3Ans4 “JohnLori ”“Sam Reagan”“ReaganSam ”“Lori Sam ”49

CHARACTER Substring: 1/3zA consecutive pportion of a stringg is a substring.gzTo use substrings, one may add an extentspecifierp f to a CHARACTER variable.zAn extent specifier has the following form:( integer-exp1 : integer-exp2 )zThe first and the second expressions indicatethe start and end: (3:8) means 3 to 8,8zIf A “abcdefg” , then A(3:5) means A’ssubstring from position 3 to position 5 (i.e.,(i e“cde” ).50

CHARACTER Substring: 2/3zIn ((integer-exp1:integer-exp2),gpgp ), if thefirst exp1 is missing, the substring starts fromthe first character,, and if exp2p is missing,g, thesubstring ends at the last character.zIf A “12345678”12345678 , then A(:5) is “12345”12345and A(3 x:) is “5678” where x is 2.zAs a goodzAd programmingi practice,ti ini general,lthe first expression exp1 should be no less than1 and the second expression exp2 should be no1,greater than the length of the string.51

CHARACTER Substring: 3/3zSubstringsg can be used on either side of theassignment operator.ppLeftHand “123456789”zSuppose(length is 10) . LeftHand(3:5) "abc” yields LeftHand “12abc67890” LeftHand(4:) "lmnopqr” yieldsLeftHand "123lmnopqr“ LeftHand(3:8) "abc” yields LeftHand "12abc90“ LeftHand(4:7) "lmnopq” yieldsLeftHand "123lmno890"52

Example: 1/5zThis pprogramguses the DATE AND TIME()()Fortran 90 intrinsic function to retrieve thesystem date and system time. Then, it convertsthe date and time information to a readableformat. This program demonstrates the use ofconcatenation operator // and substring.zSystem date is a string ccyymmdd,ccyymmdd where cc century, yy year, mm month, and dd day.zSystem time is a string hhmmss.sss, where hh hour, mm minute, and ss.sss second.53

Example: 2/5zThe followingg shows the specificationpppart.Note the handy way of changing string length.PROGRAM DateTimeIMPLICIT ER(LEN 8)4)10)2)::::::::DateINFO! ccyymmddYear, Month*2, Day*2TimeINFO, PrettyTime*12 ! hhmmss.sssHour, Minute, Second*6CALL DATE AND TIME(DateINFO, TimeINFO) other executable statements END PROGRAM DateTimeThis is a handy way of changing string length54

Example: 3/5zDecomposepDateINFO into yyear,, month andday. DateINFO has a form of ccyymmdd,where cc century,y, yy yyear,, mm month,,and dd day.Year DateINFO(1:4)Month DateINFO(5:6)Day DateINFO(7:8)WRITE(* *) 'DateWRITE(*,*)Date informationWRITE(*,*) 'YearWRITE(*,*) 'MonthWRITE(*,*) 'Day- - - - ',',',',DateINFOYearMonthDayOutput: Date information - 19970811Year - 1997Month - 08Day - 1155

Example: 4/5zNowNow do the same for )WRITE(*,*)WRITE(*,*)WRITE(*,*)WRITE(, )WRITE(*,*) TimeINFO(1:2)TimeINFO(3:4)TimeINFO(5:10)Hour // ':' // Minute // ':' // Second'Time Information' Hour' Minute' Second' Pretty Time- - - - - t: Time Information - 010717.620HourMinuteSSeconddPretty Time- - - - 010717 62017.62001:07:17.62056

Example: 5/5zWe mayy also use substringg to achieve the sameresult:PrettyTime “ “PrettyTime( :2) PrettyTime(3:3) PrettyTime(4:5) PrettyTime(6:6) PrettyTime(7: ) ! Initialize to all ITE(, ) ' Pretty Time - ',, PrettyTime57

What KIND Is It?zFortran 90 has a KIND attribute for selectinggthe precision of a numerical constant/variable.zThe KIND of a constant/variable is a positiveinteger (more on this later) that can be attachedto a constantconstant.zExample: 126 3 : 126 isi an integerioff KIND 3 3.1415926 8 : 3.1415926 is a real ofKIND 858

What KIND Is It (INTEGER)? 1/2zFunction SELECTED INT KIND(k)selects theKIND of an integer, where the value of k, apositive integer, means the selected integerKIND has a value between -10k and 10k.zThus, the value of k is approximately thenumber of digits of that KIND. For example,SELECTED INT KIND(10) means an integerKIND of no more than 10 digits.digitszIf SELECTED INT KIND() returns -1, thismeans theth hhardwaredddoes nott supportt ththerequested KIND.59

What KIND Is It (INTEGER)? 2/2zSELECTED INT KIND()is usuallyy used in thespecification part like the following:INTEGER, PARAMETER :: SHORT SELECTED INT KIND(2)INTEGER(KIND SHORT) :: x, yzThe above declares an INTEGER PARAMETERSHORT with SELECTED INT KIND(2), which isthe KIND of 2-digit integers.zThen, the KIND attribute specifies that INTEGERvariables x and y can hold 2-digit integers.zIn a program, one may use -12 SHORT and9 SHORT to write constants of that KIND.60

What KIND Is It (REAL)? 1/2zUse SSELECTED REAL KIND(k,e)( , ) to specifyp yaKIND for REAL constants/variables, where k isthe number of significant digits and e is thenumber of digits in the exponent. Both k and emust be positive integers.zNote that e is optional.zSELECTED REAL KIND(7 3) selects a REALzSELECTED REAL KIND(7,3)KIND of 7 significant digits and 3 digits for theexponent:t 0.xxxxxxx 10 0 10 yyy61

What KIND Is It (REAL)? 2/2zHereHere is an example:INTEGER, PARAMETER ::&SINGLE SELECTED REAL KIND(7,2), &SINGLE SELECTED REAL KIND(7,2),DOUBLE SELECTED REAL KIND(15,3)REAL(KIND SINGLE) :: xREAL(KIND DOUBLE) :: SumxSum 123.45E-5 SINGLE123 4 Sum 12345.67890 DOUBLE62

Why KIND, etc? 1/2zOld Fortran used INTEGER*2,, REAL*8,,DOUBLE PRECISION, etc to specify the“precision” of a variable. For example,REAL*8 means the use of 8 bytes to store a realvalue.zThis is not very portable because somecomputers may not use bytes as their basicstoragetunit,it whilehil some othersthcannott use 2bytes for a short integer (i.e., INTEGER*2).zMzMoreover,we alsol wantt tot havehmore andd finerfiprecision control.63

Why KIND, etc? 2/2zDueDue to the differences among computerhardware architectures, we have to be careful: The requested KIND may not be satisfiedsatisfied.For example, SELECTED INT KIND(100)may not be realistic on most computers.computers Compilers will find the best way good enough(i e larger) for the requested KIND.(i.e.,KIND If a “larger” KIND value is stored to a““smaller”ll ” KIND variable,i bl unpredictabledi blresult may occur.zUse KIND carefully for maximum portability. 64

The End65

F90 Program StructureF90 Program Structure zA Fortran 90 program has the following form:A Fortran 90 program has the following form: program-name is the name of that program specification-part, execution-part, and subprogram-part are optional. Although IMPLICIT NONEis also opp,tional, this is required i

Related Documents:

Course focus on Fortran 90 (called Fortran for simplicity) Changes in later versions (mostly) not important for us ‣ Fortran 95: Minor revision of Fortran 90 ‣ Fortran 2003: Major additions to Fortran 95 ‣ Fortran 2008: Minor revision of Fortran 2003 gfortran compiler: ‣ Fortran 95: Completely supported

Fortran Evolution Fortran stands for FORmula TRANslation. The first compiler appeared in 1957 and the first official standard in 1972 which was given the name of Fortran 66'. This was updated in 1980 to Fortran 77, updated in 1991 to Fortran 90, updated in 1997 to Fortran 95, and further updated in 2004 to Fortran 2003. At each update some

INTRODUCTION TO ABSOFT FORTRAN Absoft Fortran is a complete implementation of the FORTRAN programming languages: FORTRAN 77, Fortran 90, and Fortran 95. It also completely implements ISO Technical Reports TR15580 and TR15581. The microprocessor-based computers of today are vastly more powerful and sophisticated than their predecessors.

Fortran is short for FORmula TRANslation and this guide is based on Fortran 90, which is a version agreed in 1990. Fortran 95, a later standard, was a minor revision of Fortran 90. The latest standard, Fortran 2003, is now supported by some compilers as well. Fortran was developed for general scientific computing and is a very

Build with the Composer Edition (Continued) Boost Fortran Application Performance INTEL FORTRAN COMPILER on Linux* using Intel Fortran Compiler (Higher is Better) Deliver superior Fortran application performance. Get extensive support for the latest Fortran standards (including full Fortran

modern programming language. Fortran 95 is a small extension of Fortran 90. These latest versions of Fortran has many of the features we expect from a mod-ern programming languages. Now we have the Fortran 2003 which incorporates

This book covers modern Fortran array and pointer techniques, including facilities provided by Fortran 95, with attention to the subsets e-LF90 and F as well. It provides coverage of Fortran based data struc-tures and algorithm analysis. The principal data structure that has traditionally been provided by Fortran is the array. Data struc-turing .

Tulang Penyusun Sendi Siku .41 2. Tulang Penyusun Sendi Pergelangan Tangan .47 DAFTAR PUSTAKA . Anatomi dan Biomekanika Sendi dan Pergelangan Tangan 6 Al-Muqsith Ligamentum annularis membentuk cincin yang mengelilingi caput radii, melekat pada bagian tepi anterior dan posterior insicura radialis pada ulna. Bagian dari kondensasi annular pada caput radii disebut dengan “annular band .