0% found this document useful (0 votes)
8 views36 pages

FORTRAN Programming Basics Guide

The document provides an overview of FORTRAN, a high-level programming language developed for numerical and scientific computation, highlighting its history, evolution, and key features. It discusses the importance of FORTRAN in modern programming, its advantages and disadvantages, and its structure, including basic elements and syntax rules. Additionally, it emphasizes FORTRAN's role in teaching programming fundamentals due to its logical structure and mathematical syntax.

Uploaded by

abdulaki488
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)
8 views36 pages

FORTRAN Programming Basics Guide

The document provides an overview of FORTRAN, a high-level programming language developed for numerical and scientific computation, highlighting its history, evolution, and key features. It discusses the importance of FORTRAN in modern programming, its advantages and disadvantages, and its structure, including basic elements and syntax rules. Additionally, it emphasizes FORTRAN's role in teaching programming fundamentals due to its logical structure and mathematical syntax.

Uploaded by

abdulaki488
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

Chapter 2: Programming basics

PROGRAMMING FUNDAMENTALS

Compiled by Abdulaki M.

1
Introduction
❑FORTRAN stands for Formula Translation.
❑ It is a high-level programming language developed for
numerical and scientific computation.
❑FORTRAN was one of the earliest programming languages,
designed to make coding mathematical and engineering
problems easier.
❑It allows programmers to focus on formulas and algorithms
instead of hardware details

2
History of FORTRAN
❑FORTRAN was developed by John Backus and his team at IBM in 1957
for the IBM 704 computer.

❑ It was the first widely used high-level language, revolutionizing


computer programming.

❑The original version was known as FORTRAN I, followed by improved


versions such as FORTRAN II, FORTRAN IV, and FORTRAN 66.

❑ Over time, the language evolved to support structured and modern


programming features.

3
Evolution of FORTRAN

❑FORTRAN 77 – Introduced structured


programming (IF, DO loops, etc.).
❑FORTRAN 90 – Added modern features like arrays,
recursion, and modules.
❑FORTRAN 95, 2003, 2008, and 2018 – Introduced
object-oriented programming, interoperability with
C, and parallel computing.
Today, FORTRAN remains popular in scientific
computing, numerical modeling, and engineering
simulations.
4
Evolution of FORTRAN
Version Year Main Features / Highlights
First high-level language; focused on mathematical
FORTRAN I 1957
formulas
FORTRAN II 1958 Added subroutines and functions

FORTRAN IV 1962 Machine-independent; improved logical statements

FORTRAN 66 1966 First standardized (ANSI) version

Structured programming (IF, DO); added character


FORTRAN 77 1978
type

FORTRAN 90 1991 Modern features: modules, arrays, free-form code

FORTRAN 95 1995 Enhanced FORTRAN 90; better performance

Added object-oriented programming, C


FORTRAN 2003 2004
interoperability
FORTRAN 2008 2010 Parallel computing (coarrays)

FORTRAN 2018 2018 Improved parallelism and modern compatibility

5
Features of FORTRAN
✓Simple and easy-to-learn syntax for mathematical operations.

✓ Efficient handling of arrays, loops, and numerical calculations.

✓ Compiled language — produces fast and optimized machine


code.

✓Supports modular programming using subroutines and functions.

✓Portable across many platforms (Windows, Linux, macOS).

6
Importance of FORTRAN
▪ FORTRAN played a historic role in shaping modern
programming languages.
▪ It introduced concepts like loops, conditionals, and modular
programming.
▪ Many scientific and mathematical libraries are still written
in FORTRAN because of its speed and reliability.
▪ It remains an essential language for physics, chemistry,
climate modeling, and engineering.

7
Why FORTRAN is a Good Choice for
Teaching Programming Fundamentals
❖FORTRAN emphasizes logical thinking and algorithm design.

❖ Its syntax closely matches mathematical notation, making it ideal


for students with a science background.

❖ It helps students understand:


❖Data types and variable declarations
❖Loops, conditions, and arrays
❖Compilation and execution process
❖ Builds a strong foundation for learning other high-level languages.

8
Advantages of FORTRAN Disadvantages of FORTRAN
• Excellent for scientific and • Not ideal for modern GUI
engineering computations. or web development.
• Produces fast and efficient • Limited support for string
executable code. manipulation and graphics.
• Simple syntax, easy to read • Syntax can be less flexible
and debug. compared to modern
• Supports structured and languages like Python or
modular programming. Java.
• Portable — programs can • Not widely used outside
be compiled on many scientific and research
systems. communities.

9
FORTRAN IDEs
• There are several Integrated Development
Environments (IDEs) for writing and compiling
FORTRAN programs:
• Intel Fortran Compiler (IFORT)
• GFortran (GNU Fortran)
• Code::Blocks (with Fortran plugin)
• Photran (Eclipse-based IDE)
• Visual Studio with Intel Fortran Integration
• OnlineGDB or JDoodle (for quick online practice)
10
Fortran Program Structure
➤ Every Fortran program has a number of
components:
• Program Name
• Comments
• Declarations
• Executable Statements
• End Statement

11
Comments
Comments are remarks ignored by the compiler.
• They make programs easier to understand for you
and others.
• Use comments to:
• Explain the purpose of the program
• Describe what parts of the code do
• Keep notes about changes
• Record the programmer’s name or date
• To make text comment, we start ! Sign
Tip: Always include comments for clarity and future
reference.

12
Program Name
• The first line of every Fortran program starts with
the keyword program followed by a name.
• It identifies the beginning of the program.
• Example:
program simple_example

13
Declarations
• The declaration section defines variables and their
data types.
• It tells the compiler what kind of data will be used.
• The statement implicit none forces you to declare
all variables (good practice).
• Example:

14
Executable Statements
• These are the actual instructions that the
computer executes.
• They can include input/output, calculations, loops,
and decisions.
• Example:

15
End Statement
• Marks the end of the program.
• Written as end program program_name.
• We use end keyword and write program name
• Example:
end program simple_example

16
17
End Statement
• Marks the end of the program.
• Written as end program program_name.
• We use end keyword and write program name
• Example:
end program simple_example

18
Basic Elements of a Fortran
Program
❑Every Fortran program consists of several basic
building blocks. Students must understand these to
write correct and efficient programs.
• Keywords (Reserved Words)
• Words that have a special meaning in Fortran.
• Cannot be used as variable or function names.
• Always lowercase (standard practice).
Examples : program, end, integer, real, print, read, if,
then, else, do

19
Identifiers
❖Names given by the programmer to variables,
functions, subroutines, or arrays.
❖Rules:
❖Must start with a letter
❖Can contain letters, digits, and underscores (_)
❖Cannot be a reserve
Examples sum, average, counter, number1…

20
Literals
• Fixed constant values used in programs.
• Can be numbers, characters, or logical constants.
• Examples:
✓ 3.14 ! real literal
✓42 ! integer literal
✓'A' ! character literal
✓.TRUE. ! logical literal

21
Variables

• Named storage locations in memory that hold data.


• Must be declared with a type before use.
• Can change value during program execution.
• Declaration Examples:

22
Operators
• Operators are symbols used to perform operations
on variables and values.

Operator Meaning Example

+ Addition sum = a + b

- Subtraction diff = a - b

* Multiplication prod = a * b

/ Division quot = a / b

** Exponent power = a ** 2

23
Operators
➤ Relational (Comparison) Operators

Operator Meaning Example

== Equal if (a == b) then ...

/= Not equal if (a /= b) then ...

> Greater than if (a > b) then ...

< Less than if (a < b) then ...

>= Greater or equal if (a >= b) then ...

<= Less or equal if (a <= b) then ...

24
Operators
➤ Relational (Comparison) Operators

Operator Meaning Example

.AND. Logical AND if (a > 0 .AND. b > 0) then ...

.OR. Logical OR if (a > 0 .OR. b > 0) then ...

.NOT. Logical NOT if (.NOT. a) then ...

25
Main parts of a Fortran 90 program

1. Program Statement
• Fortran 90:
• Every program starts with a named program statement:
• PROGRAM program_name
• Improves readability and allows multiple programs in one file.
• Before Fortran 90 (Fortran 77):
• Program could start directly with executable statements.
• Program names were optional.
• Example (F90):
• PROGRAM HelloWorld

26
Main parts of a Fortran 90 program

2. Implicit None
• Fortran 90:
• IMPLICIT NONE forces all variables to be declared explicitly.
• Prevents errors due to misspelled or undeclared variables.
• Before F90:
• Variables were typed automatically by first letter:
• I–N → INTEGER
• Others → REAL
• This often led to bugs.
• Example (F90):
• IMPLICIT NONE
• INTEGER :: age
• REAL :: height

27
Main parts of a Fortran 90 program

3. Declaration Section
• Fortran 90:
• Allows advanced variable declarations including arrays, derived types, and parameters.
• Before F90:
• Limited variable types and simple arrays.
• No modern derived types or dynamic arrays.
• Example (F90):
• INTEGER :: age
• REAL :: weight
• CHARACTER(len=20) :: name
• LOGICAL :: isStudent

28
Main parts of a Fortran 90 program
4. Executable Statements • Example (F90):
• Core part of program where • PRINT *, "Enter your age:"
actions are performed. • READ *, age
• Fortran 90: • IF (age >= 18) THEN
• Free-form layout, flexible
syntax, improved loops and • PRINT *, "You are an
conditionals. adult."
• Examples: DO loops, IF,
SELECT CASE, PRINT, READ. • ELSE
• Before F90: • PRINT *, "You are a
• Fixed-form layout; strict minor."
column rules. • END IF
• Limited loop and conditional
syntax; I/O was
cumbersome.

29
Main parts of a Fortran 90 program

• 5. End Program Statement


• Fortran 90:
• Ends program explicitly with name:
• END PROGRAM program_name
• Before F90:
• Simple END was sufficient; program name not required.

30
Layout of Fortran 90 Statements

• In Fortran 90, the layout of statements refers to the rules that determine how
statements are arranged and written in a program.
Unlike older versions (FORTRAN 77), Fortran 90 introduced a free-format layout,
which gives programmers more flexibility when writing code.
1. Free-Format Layout
▪ In Fortran 90, you can write code in a free-format style, meaning:
▪ Statements can begin anywhere on a line (no fixed columns).
▪ Multiple statements can appear on the same line (separated by a semicolon ;).
▪ Long statements can be continued on the next line using an ampersand &.
▪ Blank spaces and indentation are ignored (used only for readability).

31
Layout of Fortran 90 Statements
• Example (Free Format
Style)->

Explanation:
• The statements are
freely spaced.
• x = 5; y = 10 → two
statements on one line.
• Indentation is allowed
for readability.

32
Layout of Fortran 90 statements

2. Statement Continuation

• If a statement is too long, it can continue on the next line using the ampersand (&) symbol.

• Example:

• Explanation:
• The & at the end of the first line tells the compiler the statement continues.
• You can also place an & at the start of the next line (optional).

33
Layout of Fortran 90 statements

3. Comment Lines
• A comment starts with an exclamation mark (!).
• The compiler ignores everything after ! on that line.
• Example:

34
Layout of Fortran 90 statements

4. Case Sensitivity
• Fortran 90 is not case-sensitive.
Example: PRINT, print, and Print are all the same.
Summary
Element Table Rule / Description Example
Free Format Statements can start anywhere x = 10
Continuation Use & to continue a statement print *, "Hello" &
Multiple Statements Use ; to separate a = 1; b = 2
Comments Start with ! ! This is a comment
Case Sensitivity Not case-sensitive PRINT = print

35
Quiz(5%)
Give short answer
[Link] is Fortran stand for?
2. What was the original Fortran version? (write the
version name)
3. What are keywords? (explain with example).
4. What are Identifiers(explain with example).
5. In Fortran 90, how can you write two statements
on a single line?

36

You might also like