200 likes | 232 Views
FORTRAN. FORmula TRANslator -Anand Trivedi. HISTORY. Designed and written from scratch in 1954-57 by an IBM team lead by John W. Backus as the first ever High Level Language Direct competition with assembler compelled it to have a fast, well optimized code. INTRODUCTION.
E N D
FORTRAN FORmula TRANslator -Anand Trivedi
HISTORY • Designed and written from scratch in 1954-57 by an IBM team lead by John W. Backus as the first ever High Level Language • Direct competition with assembler compelled it to have a fast, well optimized code
INTRODUCTION • Fortran is a general purpose programming language, mainly intended for engineering & scientific computation • Browse over its most popular version Fortran –77(in 1977)
LEXICAL ASPECTS • Input format : Formerly Punch cards • Not a free format language • Column position rules : • Col. 1 : Blank, or a "c" or "*" for comments • Col. 2-5 : Statement label (optional) • Col. 6 : Continuation of previous line (optional) • Col. 7-72 : Statements • Col. 73-80: Sequence number (optional, rarely used today) • Delimiters : End of the line • Blank space ignored • Variable names of 1-6 characters (A-Z, 0-9). The first character must be a letter.
EXPRESSIONS • Arithmetic Operators : • **, /, *, -, + • Relational Operators :.LT., .LE., .GE., .GT., .EQ., and .NE. • Logical Operators : .NOT., .AND., .OR., .EQV. , .NEQV. • eg: logical a, b a = .TRUE. b = a .AND. 3 .LT. 5/2 • Arithmetic expressions are evaluated first, then relational operators, and finally logical operators
DATA TYPES-I • Six data types are explicitly permitted: • INTEGER (0,25,+25,-25) • REAL (-1.5,3E5, +.123E-3) • DOUBLE PRECISION (1D2, 6.89D-8) • COMPLEX ((-10,5), (.4E2,-.31E-1) • LOGICAL(.TRUE., .FALSE.) • CHARACTER(‘Don’’t’, ’A1 PLC+/’)
DATA TYPES-II • Each variable has to be declared explicitly • Implicit rule : All variables starting with the letters i-n are integers and all others are real • CONSTANT : By using PARAMETER statement • eg. parameter (pi = 3.14159)
SAMPLE EXAMPLE- I • 1234567890123456789012345678901234567890 program circle real r, area pi parameter (pi = 3.14159) C write & read statements for I/p O/p write (*,*) 'Give radius r:' read (*,*) r area = pi*r*r write (*,*) 'Area = ', area stop end
DATA TYPES-III • Supports multiple assignments : • eg: data m,n/10,20/, x,y/2*2.5/ or • data m/10/, n/20/, x/2.5/, y/2.5/
DATA TYPES : ARRAYS • The only complex data structure • Index starts from 1 onwards : INTEGER i(10) , REAL a(12), REAL b(*) • However these are also valid : REAL b(0:19), REA: weird(-162:237) • Allows arrays of up to seven dimensions REAL a(3,5), REAL b(2,0:3) • By default values are not Zero. • Array values are not checked before being used.
CONTROL STATEMENTS-I • GOTO statement : GOTO label • IF statement : • Arithmetic if : IF (e)s1,s2,s3 • Eg. IF((A+B)*2)100,200,300 • Logical if : IF(e)statement • Eg.IF(A.LT.0.)a=0.0 • IF-THEN-ELSE Statement : If (e) THEN [statements] Else [statements] END IF • Nested IF allowed
CONTROL STATEMENTS-II • CONTINUE • Just one type of loop : DO loop • eg integer i, n, sum n = 10 DO 10 i = 0, n,2 write(*,*) 'i =', i 10 CONTINUE • No recursion (static allocation)
FUNCTIONS • Inbuilt functions like : abs, sin, cos etc • Define own functions : real function r(m,t) real t,m r = 0.1*t * (m**2 + 14*m) if (r .LT. 0) r = 0.0 return end
SUBROUTINES • Makes language modular • No global variables. So subroutines helps to pass it. Eg : subroutine iswap (a, b) integer a, b c Local variables integer tmp tmp = a a = b b = tmp return end
program callex integer m, n m = 1 n = 2 call iswap(m, n) write(*,*) m, n stop end subroutine iswap (a, b) integer a, b c Local variables integer tmp tmp = a a = b b = tmp return end CALL BY REFERENCE PARADIGM Fortran follows call by reference paradigm. Eg.
FORMAT STATEMENT • Used for particular input or output format • The most common format code letters are: • A - text string • D - double precision numbers, exponent notation • E - real numbers, exponent notation • F - real numbers, fixed point format • I - integer • X - horizontal skip (space) • / - vertical skip (newline)
THINGS NOT COVERED • Input and Output concepts • Input and Output statements • (READ, WRITE, PRINT, OPEN,CLOSE,INQUIRE..) • Format specifications • (Numeric editing, Logical editing, Character editing..)
PRESENT APPLICATIONS • Cosmology, fusion research, surface physics, molecular dynamics…. • Nasa’s Anisotropy probe (flown in 2000) used some legacy f-77 though mostly f-90 • US geological survey still uses f-77!...
PRESENT & FUTURE • F-90 has free format, dynamic allocation and pointers, user defined data type, modules, recursive functions, built-in arrays & operator overloading. • Fortran 2000 (delayed to 2004) hopes to have object orientation, interoperability with C, asynchronous I/o and lot more
REFERENCES • http://personal.cfw.com/~terry2/tutorial • http://www.ibiblio.org/pub/languages/fortran/unfp.html • http://physics.weber.edu/ostlie/phsx2300/future.pdf • http://macams1.bo.infn.it/tutorial/format.html • http://sunsite.univalle.edu.co/fortran/ch2-3.html • Fortran-77 - Harry Katzan • Structured Fortran77 Programming - Seymour Pollack