Fortran

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

FORTRAN (Formulating Translating System) originating in

1954. Formula Translation was design to allow easy translation of math formulas into code. FORTRAN was developed by a team of programmers at IBM LED by John Backus. Is the oldest and perhaps the strongest surviving high level language. Used language for scientific and engineering programming application. FORTRAN has shown durability and flexibility in keeping out with changing styles and demands of programming as they have developed.

FORTRAN I came into existence in 1954 and was implemented on the IBM 704 in 1956. Two years later, FORTRAN II appeared. It contain a number of significant enhancement to FORTRAN I, including the subroutine definition and invocation facility. Between 1958 and 1963, Fortran was implemented on a number of computers. Fortran III was developed during this period but, because it contain too many machine-dependent features, was never implemented for public use. In 1962,Fortran IV was developed for the IBM 7090/7094 computers. During the same year, the American Standards Association formed a committee to define a standard version of Fortran . This effort was a response to the differences that had begun to proliferate among the various Fortran implementations, which made impossible to transfer a program from one computer to another with confidence that the program would both run and run correctly. The committee produced two standard versions of Fortran in 1966

One was called BASIC FORTRAN and was similar to Fortran II. The other was called simply FORTRAN and was similar in its features to FORTRAN IV.

In 1977, major extension to Fortran were added, and the standard was accordingly revised. This version, known as Fortran 77, added features to the language that improved it structured programming, string processing, and file processing capabilities. Like the 1966 standard, Fortran 77 has distinguished subset define for it. Moreover, Fortran 77 properly includes the 1966 standard as a subset, so that upward compatibility is maintained for programs which were written before the new standard was installed.

Features of Fortran

Support for common language extensions in C and C++ Inter procedural optimization is now available in C, C++ ALLOCATABLE attribute, VALUE type declaration, STREAM I/O. VAX-style structures and unions are now supported in Fortran 95. Global Program Checking(GPC) The debugger, dbx, now supports a subset a subset of GDB commands. In dbx, the 8 mb limit in runtime checking for memory access errors and leaks on Ultra SPARC systems has been eliminated. The performance Analyzer features improved support for MPI programs and compiler commentary. Starting with the Solaris 7 Operating Environment, the linker(LD) accepts a construct allowing for symbols to be partially initialized. Euro Currency Symbol Support.

Basic component of the Fortran Language


The basic component of the Fortran language is its Character Set. Its members are:

the letters AZ and az (w/c are equivalent outside a character context); The numerals 09; The underscore_; and The special characters = : + blank - * / () [] , . $ ! % & ; <> ? Tokens that have a syntactic meaning to the compiler are built from those components. These are six classes of tokens: Label 123 Constant 123.456789_long Keyword ALLOCATABLE Operator .add. Name solve_equation (up to 31 characters, including_) Separator / ( ) (/ /) [ ] , = => : :: ; %

INTEGER constant is either written as a sequence of digits, possibly by a sign. REAL constant is written either in ordinary decimal notation or in exponential notation. Fortran has a DOUBLE PRECISION alternative for real values. It use doubles the amount of storage retained. Whenever a double precision value is written, the letter D is used in place of the letter E. In its exponential representation if it is written in ordinary decimal representation, Its number of significant digits implicitly whether or not double precision will be used. COMPLEX -denotes a complex number in the algebraic sense and its real
and imaginary parts are written as a pair of REALs enclosed in parenthesis and separated by a comma. Ex: COMPLEX VALUE (3.2, 1.5) represent the complex number 3.2 + 1.5i.

LOGICAL -

denotes the Boolean values True and False which are written in FORTRAN as .True . And .False. Logical Expression are formed using relational operators and logical operators, together with arithmetic expressions. The FORTRAN relational operators and their meaning are summarized below.
o

Relational Operator .LT. .LE. .GT. .GE. .EQ. .NE. .LLE. .LLT. .LGE. .LGT.

Operands Arithmetic

String

Meaning Less than Less than or equal Greater than Greater than or equal Equal Not equal Lexically less than or equal Lexically less than Lexically greater than or equal Lexically greater than

CHARACTER data types allows the programmer to

store and manipulate non-numeric information such as headings and other documentation for program output.

A character string in FORTRAN is written as a sequence of a characters enclosed in apostrophes ().

Ex: SALES SUMMARY REPORT 5/15/84 MAY 15, 1984

Each character string has associated with it a LENGTH w/c is account of the total number of character (including blanks) that are enclosed w/in the apostrophes. The above examples, therefore, have lengths 20,7 & 12 respectively.

Alternative form for strings as preserved from older version of FORTRAN and known as the HOLLERITH CONSTANT Its written by placing the string length & the letter H in front of the string itself.

Ex:

20HSALES SUMMARY REPORT 7H5/15/84 12HMAY 15, 198

ARRAYS

To store lists of data, all of the same type, use arrays. e.g. lists of exam marks, or the elements of a position vector (x, y, z). A matrix is a two-dimensional array. In FORTRAN all elements of an array are of the same type and have the same name. They are distinguished by a subscript or array index. Subscripts are consecutive integers. Arrays are named in the same way and have the same types as scalar variables. Arrays are declared, like variables, in type statements. These give their dimensions (sizes). REAL, DIMENSION (20) :: L, B REAL, DIMENSION (4,20) :: F DOUBLE PRECISION, DIMENSION (2,3) :: A, B INTEGER, DIMENSION(31) :: Exam_Marks The first array element is 1, i.e. L(1) to L(20), etc. You may specify the first and last elements (lower and upper bounds) in each array dimension. e.g. REAL, DIMENSION(-5:14) :: L would define L(-5) to L(14). These declaration statements reserve space in computer memory. Array sizes must be specified by INTEGER constants. The Maximum number of dimensions (rank) is 7.

Ex.

The shape of an array is a list (1 dimensional array) of the number of elements in each dimension. The SHAPE function gives this. Try PRINT *, SHAPE(array_name). Empty for a scalar.

Basic Statements
The FORTRAN statements fall into two classes; non executable and executable. The non

executable statements are the declarations, the End statement, and certain other statements that are declarative in nature. The executable statements and a brief description of their purpose are summarize below:

Executable Statement Assignment statement GO TO statement IF statements DO statement STOP statement HEAD statement WRITE statement PRINT statement Call statement Return Statement

Purpose To perform arithmetic and assign the result as the new value of a variable or array entry. To transfer control to a statement which does not immediately follow. TO conditionally execute a series of statements or conditionally transfer control to a statement out of sequence. To repeat the execution of a sequence of statements which immediately follow To stop execution of the program. TO transfer data from input file(e.g. a terminal or punch card) to a series of variables in storage. To transfer data from storage to an output file(e.g., a terminal screen or printer) TO invoke a subprogram To return control from a subprogram to the invoking program.

WRITING FORTRAN PROGRAMS


Consist of a program statement, a series of declarations for variables and arrays, a series of executable statements, and finally the statement END which marks the physical end of the program.

The declarations and statements of a program are written one per line, and there is no explicit punctuation mark that can be used to de imit statements from each other.
When typing a FORTRAN program, rather strict formatting conventions must be followed. Any statement which is numbered must have its number placed

within positions 1-5 of the line. Position 6 is reserved for continuing a very long statement onto a second line. More that one statement on a line is not possible in standard FORTRAN. The body of the statement (or its continuation) must be entirely contained within positions 7-72 of the line. The program below suggests that the most statements begin exactly in the position 7, while the statements within a loop are indented to another tab position to set the loop apart.

SAMPLE PROGRAM
Program Average
C THIS PROGRAM COMPUTES THE AVERAGE (AV) OF N INPUT NUMBERS (X) REAL SUM, AV, X INTEGER N N=O SUM=0 10 READ(5, *, END=20) X N=N+1 SUM=SUM+X GO TO 10 20 AV=SUM/N PRINT *, N, NUMBERS WERE GIVEN PRINT *, N, IS THEIR AVERAGE END

You might also like