0% found this document useful (0 votes)
39 views10 pages

Fortran and Its Varients

Uploaded by

Waleed Tanoli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views10 pages

Fortran and Its Varients

Uploaded by

Waleed Tanoli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

MUHAMMAD AQEEL KHAN ABBASI

CS 20-03

Assignment No:2

Assignment Topic: Fortran and its Variants

Submitted To: Sir Zahid Alam

Subject: Theory of Programming Languages


Fortran?
• Short for formula translation
• Developed by IBM engineers in 1950s led by john W.Backus
• Initial version of Fortran is called Fortran-I was released in 1957
• Fortran (short for Formula Translation) is a high-level programming language that is
particularly well-suited for numeric computation and scientific computing. It is one of
the oldest programming languages and has undergone many revisions to adapt to
new computing paradigms and enhance its capabilities.

Main purpose:
• Fortran is a programming language designed for efficient execution of numerical and
scientific computations. It excels in areas such as:
• Mathematical, statistical, and engineering applications.
• High-performance computing (HPC) due to its efficient handling of arrays and
computational tasks.
• Numerical analysis, weather modelling, fluid dynamics, and computational physics

Fortran is a compiled language, not an interpreted one.

Fortran Variants
Fortran-I (1957)
• Developer: IBM, led by John W. Backus.
• Platform: IBM 704.
• Key Features:
• Introduced high-level programming for numerical computation.
• Supported basic arithmetic operations and expressions.
• Provided the DO loop for iteration.
• Included conditional statements (IF).
• Allowed simple I/O operations.

• No subroutine supports.
Fortran-II (1958)
Enhancements Over Fortran I:
• Subroutines and Functions: Introduced for modular programming.
• Common Blocks: For sharing data between subprograms.
• Input / Output Improvements: More robust I/O handling.
• Array Handling: Better support for array operations.
• Error Detection: Improved syntax checking.
• Machine Independence: More abstracted from specific hardware.

Fortran-IV (1962)
Enhancements Over Fortran II:
• Logical Data Type: New data type for boolean operations.
• IMPLICIT Statement: Allowed implicit typing of variables.
• External Functions: Support for linking with external libraries.
• More Control Structures: Expanded control structures.
• Standardization: First step towards standard Fortran.
• Improved Arithmetic: More complex mathematical functions.

Fortran-66 (1966)
Enhancements Over Fortran IV:
• Standardization: First ANSI standard (ANSI X3.9-1966) standardized by
American National Standard Institute.
• Parameter Passing: Improved method for passing parameters.
• Data Initialization: Allowed in DATA statements.
• Enhanced Array Handling: Improved multidimensional arrays.
• Format Specification: Better control over I/O formatting.
• Common Blocks: More flexible and powerful.

Fortran-77(1977)
Enhancements Over Fortran 66:
• BLOCK IF and END IF: More Structured programming constructs and decision
making.
• CHARACTER Data Type: Handling of strings and text.
• PARAMETER Statement: For defining constants. Allowed defining constants
that don't change, making programs easier to read and maintain.
• DO Loop Enhancements: Nested DO loops and loop control.
• IMPLICIT NONE: Enforced explicit variable declaration.
• Integer::a=30
• Enhanced I/O: More versatile input and output capabilities.
• Made input and output operations more flexible and powerful, allowing better
handling of data from different sources.

Fortran-90(1991)
Enhancements Over Fortran 77:
• Modules: For better code organization and reuse.
• Array Operations: Whole-array and array-section processing. Allows
operations on entire arrays or sections of arrays at once, simplifying complex
data manipulation.
• Dynamic Memory Allocation: Allocatable arrays and pointers.
• Recursion: Support for recursive procedures.
• Free-Form Source Code: More flexible coding format. Allowed a more flexible
coding format without fixed column positions, making the code easier to read
and write.
• New Intrinsics: Many new intrinsic functions and subroutines. Added many
new built-in functions and subroutines, expanding the language's capabilities
for mathematical, character, and array operations.

Fortran-95(1997)
Enhancements Over Fortran 90:
• FORALL Construct: For parallel array processing, allowing operations to be
performed simultaneously for efficiency.
• WHERE Construct Enhancements: Conditional array assignments.
• PURE and ELEMENTAL Procedures: For side-effect-free functions. functions
that operate element-wise on arrays (ELEMENTAL), enhancing reliability and
performance.
• User-Defined Precision: More control over numerical precision.
• Improved Interoperability: Better integration with C.
• Enhanced I/O: Non-advancing I/O and other I/O enhancements.

PROGRAM ForAll Example


INTEGER, DIMENSION(5) :: array
INTEGER :: i
! Initialize the array with values 1 to 5
FORALL (i = 1:5)
array(i) = i
END FORALL
PRINT *, "Initial array:", array
! Square each element in the array
FORALL (i = 1:5)
array(i) = array(i) * array(i)
END FORALL
PRINT *, "Squared array:", array
END PROGRAM ForAll Example
PROGRAM Where Example
INTEGER, DIMENSION(5) :: array
INTEGER :: i
! Initialize the array with values 1 to 5
FORALL (i = 1:5)
array(i) = i
END FORALL
PRINT *, "Initial array:", array
! Double the values of elements that are greater than 3
WHERE (array > 3)
array = array * 2
END WHERE
PRINT *, "Modified array:", array
END PROGRAM Where Example

Fortran-2003(2004)
Enhancements Over Fortran 95:
• Object-Oriented Programming: Classes, inheritance, polymorphism.
• C Interoperability: ISO C Binding for better C integration.
• Enhanced I/O: Asynchronous I/O operations.
• Procedure Pointers: More flexible procedure referencing allowing dynamic
selection and invocation of different procedures at runtime.
• Finalization: Final procedures for clean-up, which are special routines
automatically called to clean up resources when objects go out of scope or are
no longer needed.
Fortran-2008(2010)
Enhancements Over Fortran 2003:
• Coarray Fortran: Native parallel programming model.
• Submodules: Enhanced modularity and code organization.
• DO CONCURRENT: More efficient parallel loops.
• Extended Intrinsics: Additional intrinsic functions.
• Error Handling: Improved error handling in I/O.
• Performance Enhancements: Various performance optimizations.
Implemented various optimizations to increase the speed and efficiency of
Fortran programs, making them run faster and more efficiently.

PROGRAM DoConcurrentExample
INTEGER, DIMENSION(1000000) :: array
INTEGER :: i
! Initialize the array in parallel
DO CONCURRENT (i = 1:1000000)
array(i) = i * 2
END DO CONCURRENT
PRINT *, 'First 10 elements of array:', array(1:10)
END PROGRAM Do Concurrent Example
The loop is set to run iteration from 1 to 1000000 concurrently

Fortran-2018(2018)
Enhancements Over Fortran 2008:
• Teams and Events: Improved parallel processing controls.
• Atomic Operations: Support for atomic operations in parallel programming.
• Additional Intrinsics: New and extended intrinsic procedures.
• Improved Coarray Features: Enhanced capabilities for coarrays.
• Bit Manipulation: More functions for bitwise operations. Added functions for
directly handling and manipulating individual bits in binary data, useful for low-
level programming tasks.
• Generic Programming: More robust support for generic programming
constructs. Improved ability to write code that works with different data types,
making it more flexible and reusable.

Fortran Building Blocks


Building blocks:
Building blocks of a programming language are the fundamental components, such as
variables, data types, control structures, and functions, that form the basic elements
needed to write programs. They serve as the essential constructs for creating more
complex code and applications.
Following are the building blocks of Fortran

Variables:
Variables are placeholders used to store data values.
They have a name, data type, and value.
Example: integer :: age = 25

Data Types:
Data types define the kind of data that can be stored in variables.
Common data types include integers, real numbers, characters, and logical values.
Example: integer, real, character(len=10)

Operators:
Operators are symbols used to perform operations on variables and values.
They include arithmetic operators (+, -, *, /), comparison operators (==, <, >), and
logical operators (.AND., .OR., .NOT.).
Example: x = y + z

Control Structure:
Control structures are used to control the flow of execution in a program.
They include conditional statements (IF, ELSEIF, ELSE) and looping constructs (DO, DO
WHILE, DO UNTIL).
Example: IF (x > 0) THEN
Function and Subroutines:
Functions and subroutines are reusable blocks of code that perform specific tasks.
Functions return a value, while subroutines do not.
Example: subroutine greet(name)

Arrays:
Arrays are collections of variables of the same data type.
They allow storing multiple values under a single name.
Example: real, dimension(10) :: temperatures

Code of simple calculator in Fortran


program simple_calculator
implicit none
integer :: num1, num2, result
character(len=1) :: operator

! Prompt user for input


print *, "Enter the first integer:"
read(*, *) num1
print *, "Enter the operator (+, -, *, /):"
read(*, *) operator
print *, "Enter the second integer:"
read(*, *) num2

! Perform arithmetic operation based on the operator


if (operator == '+') then
result = num1 + num2
else if (operator == '-') then
result = num1 - num2
else if (operator == '*') then
result = num1 * num2
else if (operator == '/') then
if (num2 /= 0) then
result = num1 / num2
else
print *, "Error: Division by zero!"
stop
end if
else
print *, "Error: Invalid operator!"
stop
end if

! Display the result


print *, "Result:", result
end program simple_calculator

<<<End>>>

You might also like