পৃষ্ঠাসমূহ

Search Your Article

CS

Pageviews

Showing posts with label Fortran Tutorial. Show all posts
Showing posts with label Fortran Tutorial. Show all posts

Wednesday, February 1, 2017

Fortran - Overview

Fortran, as derived from Formula Translating System, is a general-purpose, imperative programming language. It is used for numeric and scientific computing.
Fortran was originally developed by IBM in the 1950s for scientific and engineering applications. Fortran ruled this programming area for a long time and became very popular for high performance computing, because.

Fortran - Environment Setup

Try it Option Online

We have set up the Fortran Programming environment online, so that you can compile and execute all the available examples online. It gives you confidence in what you are reading and enables you to verify the programs with different options. Feel free to modify any example and execute it online.

Fortran - Basic Syntax

A Fortran program is made of a collection of program units like a main program, modules, and external subprograms or procedures.
Each program contains one main program and may or may not contain other program units. The syntax of the main program is as follows:

Fortran - Data Types

Fortran provides five intrinsic data types, however, you can derive your own data types as well. The five intrinsic types are:
  • Integer type
  • Real type
  • Complex type
  • Logical type
  • Character type

Fortran - Variables

A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable should have a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.
The name of a variable can be composed of letters, digits, and the underscore character. A name in Fortran must follow the following rules:

Fortran - Constants

The constants refer to the fixed values that the program cannot alter during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, a complex constant, or a string literal. There are only two logical constants : .true. and .false.
The constants are treated just like regular variables, except that their values cannot be modified after their definition.

Fortran - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Fortran provides the following types of operators:
  • Arithmetic Operators
  • Relational Operators
  • Logical Operators

Fortran - Decisions

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed, if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

Fortran - Loops

There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially : The first statement in a function is executed first, followed by the second, and so on.

Fortran - Numbers

Numbers in Fortran are represented by three intrinsic data types:
  • Integer type
  • Real type
  • Complex type

Fortran - Characters

The Fortran language can treat characters as single character or contiguous strings.
Characters could be any symbol taken from the basic character set, i.e., from the letters, the decimal digits, the underscore, and 21 special characters.
A character constant is a fixed valued character string.

Fortran - Strings

The Fortran language can treat characters as single character or contiguous strings.
A character string may be only one character in length, or it could even be of zero length. In Fortran, character constants are given between a pair of double or single quotes.

Fortran - Arrays

Arrays can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

Fortran - Dynamic Arrays

A dynamic array is an array, the size of which is not known at compile time, but will be known at execution time.
Dynamic arrays are declared with the attribute allocatable.
For example,
real, dimension (:,:), allocatable :: darray

Fortran - Derived Data Types

Fortran allows you to define derived data types. A derived data type is also called a structure, and it can consist of data objects of different types.
Derived data types are used to represent a record. E.g. you want to keep track of your books in a library, you might want to track the following attributes about each book:

Fortran - Pointers

In most programming languages, a pointer variable stores the memory address of an object. However, in Fortran, a pointer is a data object that has more functionalities than just storing the memory address. It contains more information about a particular object, like type, rank, extents, and memory address.
A pointer is associated with a target by allocation or pointer assignment.

Fortran - Basic Input Output

We have so far seen that we can read data from keyboard using the read * statement, and display output to the screen using the print* statement, respectively. This form of input-output is free format I/O, and it is called list-directed input-output.

Fortran - File Input Output

Fortran allows you to read data from, and write data into files.
In the last chapter, you have seen how to read data from, and write data to the terminal. In this chapter you will study file input and output functionalities provided by Fortran.
You can read and write to one or more files. The OPEN, WRITE, READ and CLOSE statements allow you to achieve this.

Fortran - Procedures

A procedure is a group of statements that perform a well-defined task and can be invoked from your program. Information (or data) is passed to the calling program, to the procedure as arguments.
There are two types of procedures:
  • Functions
  • Subroutines

Fortran - Modules

A module is like a package where you can keep your functions and subroutines, in case you are writing a very big program, or your functions or subroutines can be used in more than one program.
Modules provide you a way of splitting your programs between multiple files.