FORTRAN FORmula TRANslator Anand Trivedi HISTORY w Designed
- Slides: 20
FORTRAN FORmula TRANslator -Anand Trivedi
HISTORY w Designed and written from scratch in 195457 by an IBM team lead by John W. Backus as the first ever High Level Language w Direct competition with assembler compelled it to have a fast, well optimized code
INTRODUCTION w Fortran is a general purpose programming language, mainly intended for engineering & scientific computation w Browse over its most popular version Fortran – 77(in 1977)
LEXICAL ASPECTS w Input format : Formerly Punch cards w Not a free format language w Column position rules : n n n 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) w Delimiters : End of the line w Blank space ignored w Variable names of 1 -6 characters (A-Z, 0 -9). The first character must be a letter.
EXPRESSIONS w Arithmetic Operators : l **, /, *, -, + w Relational Operators : . LT. , . LE. , . GT. , . EQ. , and. NE. w Logical Operators : . NOT. , . AND. , . OR. , . EQV. , . NEQV. w eg: logical a, b a =. TRUE. b = a. AND. 3. LT. 5/2 w Arithmetic expressions are evaluated first, then relational operators, and finally logical operators
DATA TYPES-I w Six data types are explicitly permitted: § § § INTEGER (0, 25, +25, -25) REAL (-1. 5, 3 E 5, +. 123 E-3) DOUBLE PRECISION (1 D 2, 6. 89 D-8) COMPLEX ((-10, 5), (. 4 E 2, -. 31 E-1) LOGICAL(. TRUE. , . FALSE. ) CHARACTER(‘Don’’t’, ’A 1 PLC+/’)
DATA TYPES-II w Each variable has to be declared explicitly w Implicit rule : All variables starting with the letters i-n are integers and all others are real w CONSTANT : By using PARAMETER statement w eg. parameter (pi = 3. 14159)
SAMPLE EXAMPLE- I w 12345678901234567890 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 w Supports multiple assignments : n eg: data m, n/10, 20/, x, y/2*2. 5/ or n data m/10/, n/20/, x/2. 5/, y/2. 5/
DATA TYPES : ARRAYS w The only complex data structure w Index starts from 1 onwards : INTEGER i(10) , REAL a(12), REAL b(*) w However these are also valid : REAL b(0: 19), REA: weird(-162: 237) w Allows arrays of up to seven dimensions REAL a(3, 5), REAL b(2, 0: 3) w By default values are not Zero. w Array values are not checked before being used.
CONTROL STATEMENTS-I w w GOTO statement : GOTO label IF statement : Arithmetic if : IF (e)s 1, s 2, s 3 n l Logical if : IF(e)statement n l w Eg. IF((A+B)*2)100, 200, 300 Eg. IF(A. LT. 0. )a=0. 0 IF-THEN-ELSE Statement : If (e) THEN [statements] Else [statements] END IF w Nested IF allowed
CONTROL STATEMENTS-II w CONTINUE w Just one type of loop : DO loop w eg integer i, n, sum n = 10 DO 10 i = 0, n, 2 write(*, *) 'i =', i 10 CONTINUE w No recursion (static allocation)
FUNCTIONS w Inbuilt functions like : abs, sin, cos etc w 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 w Makes language modular w No global variables. So subroutines helps to pass it. Eg : c subroutine iswap (a, b) integer a, b Local variables integer tmp = a a=b b = tmp return end
CALL BY REFERENCE PARADIGM Fortran follows call by reference paradigm. Eg. program callex integer m, n m=1 n=2 call iswap(m, n) write(*, *) m, n stop end c subroutine iswap (a, b) integer a, b Local variables integer tmp = a a=b b = tmp return end
FORMAT STATEMENT w Used for particular input or output format w 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 w Input and Output concepts w Input and Output statements l (READ, WRITE, PRINT, OPEN, CLOSE, INQUIRE. . ) w Format specifications l (Numeric editing, Logical editing, Character editing. . )
PRESENT APPLICATIONS w Cosmology, fusion research, surface physics, molecular dynamics…. w Nasa’s Anisotropy probe (flown in 2000) used some legacy f-77 though mostly f-90 w US geological survey still uses f-77!. . .
PRESENT & FUTURE w F-90 has free format, dynamic allocation and pointers, user defined data type, modules, recursive functions, built-in arrays & operator overloading. w Fortran 2000 (delayed to 2004) hopes to have object orientation, interoperability with C, asynchronous I/o and lot more
REFERENCES w w w http: //personal. cfw. com/~terry 2/tutorial http: //www. ibiblio. org/pub/languages/fortran/unfp. html http: //physics. weber. edu/ostlie/phsx 2300/future. pdf http: //macams 1. bo. infn. it/tutorial/format. html http: //sunsite. univalle. edu. co/fortran/ch 2 -3. html w Fortran-77 - Harry Katzan w Structured Fortran 77 Programming - Seymour Pollack
- Compiler
- Chetan trivedi
- Rachna trivedi
- Dr bhushan trivedi
- Praja trivedi
- Praja trivedi
- Dr chetan trivedi pediatrician
- Formula translator
- Intra anand rathi
- Anand avati
- Anand bhatt md
- Sikh wedding shabads
- Silicon valley of india
- Kanwaljeet anand
- Starbucks anand
- Rummy glle
- Dr rishi anand
- Anand deshpande house
- Shreya anand caltech
- Tereth anand rao
- Anand natarajan dtu