Introduction to Fortran 90/95

Download Introduction to Fortran 90/95

Post on 09-Jan-2016

81 views

Category:

Documents

6 download

DESCRIPTION

Introduction to Fortran 90/95. 1390. . : () : 3 : 1 : ( code ) () - PowerPoint PPT Presentation

TRANSCRIPT

  • *Introduction to Fortran 90/95 1390

  • : () : 3: 1 : (code) ()

    *

  • . :30 : 1389/9/15 70 : 1389/10/26 : Max{0.3midterm+0.7final, final} . *

  • * : 90 90 : : Fortran 90/95 Fortran 90/95 : :

  • * ( ) (codes) (compile) (*.exe)

  • * ()

    c=a+bd=a*b

  • *

  • FORmula TRANslation invented 19548 by John Backus and his team at IBMFORTRAN 66 (ISO Standard 1972)FORTRAN 77 (1980)Fortran 90 (1991)Fortran 95 (1996)Fortran 2003 (2004)Fortran 2008 (ongoing)

    *

  • *Fortran AlphabetsA B C D E Fa b c d e f .0 1 2 3 4 5 6 7 8 9 , ( ) * + - / : = - ! & $ ; < > ? . % _ blank

  • * . . 31 . . (underline) . . :Conut, AliX900g, I1025R2_D2, R2D2_ :M.t.u, R2-D26feet_system A_name_made_up_of_more_than_31_letterstoo long, 38 characters

  • * . 90 :

  • * integercorrect: 0, -345, 789, +1234incorrect: 12.0, --4, 5+realcorrect: 123.45, .123, 123., -0.12, +0.12incorrect: 65complexx+iy

  • * charactercorrect: 'Ali' or "Ali" (content: Ali and length: 3), 'Ali is #2' (content: Ali is #2 and length: 9)special case: 'Ali''s apple' (content: Alis apple and length: 11) incorrect: 'you and me, 'Tech's seminar', 'have a nice day"Correct: "Ali's apple" (string) .Logical .A
  • * . (syntax) :Integer :: j, icountReal :: wide, angleLogical :: tryCharacter(Len = 5) :: nameCharacter(Len = 10) :: city, nation*20, box, bug*1Character :: answer, marital_statusanswer and marital_status are each of length 1 :: integer real logical character .

  • * integer Real . i,j,k,l,m,n . :integeric, kzip, name, l_georealzip, code, geoNames starting with IN are INTEGEROnes with AH and OZ are REAL

  • implicit none implicit none . .implicit noneinteger :: ice, cokereal :: var, kind *

  • . parameterInteger :: count = 0, I = 5, J = 100Real :: max = 1005.25, min = -0.01Character(Len=10) :: light = AmberLogical :: red = .TRUE., blue = & .FALSE., green = .FALSE. *

  • * Parameter .integer, parameter :: limit = 100real, parameter :: pi = 3.14159, twopi = 2*piinteger, parameter :: month_in_a_year = 12: integer, real ... (::) (::) . Character(Len=*), parameter :: &error = 'unknown'

  • *

  • * 1:X + Y * Z is equivalent to X + (Y * Z)X + Y / 7.0 is equivalent to X + (Y / 7.0)A B + C is equivalent to (A B) + CA + B ** C is equivalent to A + (B ** C) A ** 2 is equivalent to (A ** 2)A ((( B + C))) is equivalent to A (B + C)You can force any order you like(X + Y) * ZAdds X to Y and then multiplies by Z

  • * 2:A / B * C is it A / (B * C) or (A / B) * C?A ** B ** C is it A ** (B ** C) or (A ** B) ** C?Fortran specifies that:A / B * C is equivalent to (A / B) * CA ** B ** C is equivalent to A ** (B ** C)Yes, ** binds from right to left!

  • * : .a+2b*b-4*a*cA>B (=) .Delta = b*b-4*a*cArea = pi*r**2count = count+1

  • Division always truncates towards zeroIf K = 4 and L = 5, then K+L/2 is 6(-7)/3 and 7/(-3) are both -2 INTEGER :: K = 5REAL :: X = 1.3X = X+K/2That will add 2.0 to X, not 2.5K/2 is still an INTEGER expression *

  • * N = 10./3(value of N is 3)X = 10/3(value of X is 3.0)Y = 10/3.(value of Y is 3.33333)10./33.33333 N310/3 3 X 3.10/3. 3.33333 Y 3.33333 .

  • * (1)

  • * (2)

  • * print write . :print*, expr_1, expr_2, (format) .write(*,*) expr_1, expr_2, . . .Print*write(*,*)

  • * (1) . read .read(*,*) var_1, var_2, write . read . read read*, var_1, var_2, (format) .

  • * (2) read . . read .

  • * Program solve_equationReal :: a,b,cReal :: dReal :: root1, root2! read in coefficient a,b,cPrint*,a,b,c please:read*,a,b,c! compute the square root of discriminant dd = sqrt(b*b-4*a*c)! solve equationroot1 = (-b+d)/(2*a) ! first rootroot2 = (-b-d)/(2*a) ! second root! display the resultswrite(*,*) Roots are, root1, and, root2End Program solve_equation

  • *Text EditorCompilerlinklibsystemPhase I: TranslationPhase II: LinkagePhase III: Execution

    *

Recommended

View more >