fortran formula translator -anand trivedi. history designed and written from scratch in 1954- 57 by...

20
FORTRAN FORmula TRANslator -Anand Trivedi

Upload: carmella-kelly

Post on 01-Jan-2016

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 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

FORTRAN

FORmula TRANslator

-Anand Trivedi

Page 2: 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

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

Page 3: 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

INTRODUCTION

Fortran is a general purpose programming language, mainly intended for engineering & scientific computation

Browse over its most popular version Fortran –77(in 1977)

Page 4: 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

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.

Page 5: 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

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

Page 6: 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

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+/’)

Page 7: 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

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)

Page 8: 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

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

Page 9: 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

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/

Page 10: 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

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.

Page 11: 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

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

Page 12: 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

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)

Page 13: 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

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

Page 14: 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

SUBROUTINES

Makes language modular No global variables. So subroutines helps to

pass it. Eg : subroutine iswap (a, b) integer a, bc Local variables integer tmp  tmp = a a = b b = tmp  return end

Page 15: 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

CALL BY REFERENCE PARADIGM

program callex integer m, n m = 1 n = 2   call iswap(m, n) write(*,*) m, n  stop end

subroutine iswap (a, b) integer a, bc Local variables integer tmp  tmp = a a = b b = tmp  return end

Fortran follows call by reference paradigm. Eg.

Page 16: 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

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)

Page 17: 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

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

Page 18: 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

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

Page 19: 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

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

Page 20: 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

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