0% found this document useful (0 votes)
2 views75 pages

Gfortran Class Notes

The document provides a comprehensive guide on writing and executing Fortran programs using GFORTRAN in Ubuntu Linux, including instructions on file creation, compilation, and execution. It details the structure of Fortran code, including column usage, data types, identifiers, operators, and basic syntax rules. Additionally, it explains the use of arithmetic and relational operators, as well as built-in functions for mathematical operations.

Uploaded by

anky42541
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)
2 views75 pages

Gfortran Class Notes

The document provides a comprehensive guide on writing and executing Fortran programs using GFORTRAN in Ubuntu Linux, including instructions on file creation, compilation, and execution. It details the structure of Fortran code, including column usage, data types, identifiers, operators, and basic syntax rules. Additionally, it explains the use of arithmetic and relational operators, as well as built-in functions for mathematical operations.

Uploaded by

anky42541
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

Page:1

GFORTRAN Command (in UBUNTU Linux) (F77)

To start writing a program in GFORTRAN, first of all open a file


using Vi editor by using the command;
Physics/student/groupA$/ vi test1.f
Then an edit space will open where you can write the program using
insert / edit mode.
Hence i / a to go to the insert / edit mode and start writing.

After writing the program, you have to go the Command Mode by


pressing Esc key. Then you have to use the command;
Shift + ZZ

Then you have to compile the program by using the command


Physics/student/groupA$/ Gfortran test1.f –o [Link]

If the program writing is correct, then compilation will be done


successfully. However, if there is some error in the program,
then error indication with the types of error will be shown.
After successful compilation, you have to execute the program to get
the result. Then you have to use the command;
./ [Link]
Page:2

Some Basic Instructions about writing of Fortran Program.


Fortran program should be written between 7 th column to 72 nd
column. The columns are arranged as follows;
1 2-----5 6 7 72

1 st column is used for giving Remark (c) statement. If we put c in


the 1 st column of any line, then this line will become a non-
executable line. Anything we write in this line will not be executed.
This line will remain untouched. You may also use the command ’
for remark.
For example;
C We are the students.

This is a non-executable line because we use the command ‘c’ in the


first column of the line.
Also for Rem statement, we may use exclamation sign (!). we may
use this ! sign anywhere in a line and then the right hand side of the !
sign will be the Rem portion of the line that is that protion will be
non-executable and not the whole line.

2 - 5 columns are the columns where any number can be written


to specify the line number of that line.
For example
10 write(*,*) ‘my name is student’
Page:3

Here 10 is the line number. The line number is given between 2 nd


to 5 th column.

In 6 th column, line continuation number can be given. That is if we


write some sentence in the first line and it exceeds the 72 nd column
then we can continue the writing in the second line using a line
continuation number in the 6 th column of the second line.
For example;
1, 2 - 5 6 7 ----- ---- ---- 72

Write(*,*) ‘This program calculates -- the and so


8 and so on therefore’

In this writing we use a line continuation number 8 in the sixth


column of the second line of the writing.
Note: Once we use the number 8 to specify the number of a line,
then that number 8 cannot be used further to specify other line
number. We have to give another number then.
7 th – 72 nd columns space is used for writing the program. We
may also start writing the program on or after 7 th column.
Page:4

If any line exceeds the 72 nd column then we can continue the


writing in the second line using the line continuation number in
the 6 th column of the second line.
For example;
Write(*,*) ‘The program calculates -- the and so
8 and so on therefore’
Here 8 is the line continuation number.
Therefore, line continuation number should be given in column
number 6.

For writing the processed data in an output data file, say [Link],
the column used is;
1 st column to 132 column;
That is in the output file, we may use 1 st to 132 nd column of each
line to write data without any syntax error. Then we can save the
output data file.

Fortran Basic Syntax


Basic Character Set:
Basic Character Set of Fortran contains the following:
1. The letters A, B, …….Z and a, b, ……z
2. The digits 0,1,…..9
Page:5

3. The underscore ( _ ) character.


4. The special characters, = : + blank - * / ( ) [ ] , . $ ! ‘ “ & ; <
>?

Identifier:
An Identifier is a name used to identify a variable, procedure or any
other user-defined item. A name in Fortran must follow the
following rules:-
(i) It cannot be longer than 31 characters.
(ii) It must be composed of alphabet or alphanumeric characters (all
the letters of the alphabet and digits 0 - 9) and underscores ( _ ).
(iii) First character of a name must be a letter.
(iv) Names are case-insensitive.
For example;
Write(*,*) ‘what is the age of the boy?’
Read(*,*) age
Write(*,*) ‘The age of the boy is ‘ age
Stop
end
--------------------------------------------------
In this program age is used to count the age of the boy. Hence
here age is the identifier.
Page:6

Fortran Data Type:


Fortran provides five intrinsic data type; however you can derive
your own data types as well. The five intrinsic data types are: -
(i) Integer Type
(ii) Real Type
(iii) Complex Type
(iv) Logical Type
(v) Character Type

(i) Integer Type:


The Integer Type can hold only integer value. The Integer Type
should be declared first by using the following command;
Integer a, b
Here a and b are variables or constants and declared as integer.

Or we may write;
Real c, d
Here c and d are variables or constants and declared as real.

Note:
(i) Declaration statement must be given at the beginning of the
program.
(ii) If we write the command as
Integer a, b
Page:7

Then it will give 2 byte integer that is it can count upto 2 byte
numeric value.
There are 4 byte integer, 8 byte integer and 16 byte integer also.
For this purpose, we have to use the kind specifier. For example;
Integer (kind = 2) a , b
Integer (kind = 4) a , b
Integer (kind = 8) a , b
Integer (kind = 16) a , b

Numeric constants and Numeric variables


There are of three types; namely Integer, Real (or Floating point)
and Complex.
Here we will discuss only Integer and Real numeric constants and
variables.
Numeric constants are numbers whose values are to be assigned. For
example;
A=3
B=4
and others. But before writing any numeric constants, the numeric
types should be declared first. For examples declaration command
is;
Integer a, b
Real c, d
Page:8

and others.
Before writing any executable line in a program, Declaration
statement should be given.
Numeric variables:
First of all variables types must be Declared
Declaration of Numeric variables or Constants are as follows:
Integer a, b
Real c, d

After declaration of Variables / Constants, we have to assign the


values: - say for numeric constants we should assign the value as;
a=3
b=5
c = 3.0
d = 5.25
Note: For real values we should assign the values of constants using
decimal points.
Say, c = 3.0 or d = 5.25
For Integer values we should assign the values of constant without
using decimal point.
Say; a = 3 or b = 5
Here no decimal point is used.
Page:9

For Numeric variables we have to assign the values as;


Real P, Q
Integer R, S
Read(*,*) P, Q
Read(*,*) R, S
Stop
End
We may also write this as;
Real P, Q
Integer R, S
Write(*,*) ‘Give two real numbers’
Read(*,*) P, Q
Write(*,*) ‘Give two Integer numbers’
Read(*,*) R, S
Stop
End
Note that in this program writing we use string constant; namely;
Write(*,*) ‘Give two real numbers’
And also
Write(*,*) ‘Give two Integer numbers’
The sentences within single inverted coma are string constant.
Page:10

These string constants are used so that while the program is


executed, the data can be given systematically and meaningfully.

String Constants or Character Constants:


String Constant is any sentence or word within inverted comma
‘string constant’ is called String constant. For example;
Write(*,*) ‘We are the students’
The sentence written inverted comma is called string constant.
Note: 1. String constant may be a sentence or a word. It may be a
mixer of alphabet or any number or any special character and other.
2. The string constant that is the line within inverted comma will
only be displayed at the output.
3. It is important to use string constants in the program to write the
program in a meaningful way so that the program can be understood
while on executed.
Note: String variable or character variable will be discussed
later.

Fortran Operators:
An Operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulation. Fortran provides the
following types of operators.
Page:11

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
These are discussed below;
Arithmetic Operators:
Following tables shows all the Arithmetic Operators supported by
Fortran.
Assume the variables a = 5 and b = 3 then;
Operator Description Example
+ Addition Operator. It adds two a+b will give 8
operands
- Subtraction Operator. It a-b will give 2
subtracts two operands
* Multiplication Operator. It a*b will give 15
multiplies both operands.
/ Division Operator. It divides a/b will give 1 if a and b
numerator by denominator both are integer and will
give 1.6666 if both are
real.
** Exponential Operator. It raises a**b will give 125
one operand to the power of
other.
Page:12

() Parenthesis operator. It (a+b)*(a-b) will be 8*2 or


separates an expression from 16
the other expression
Operators Precedence in Fortran:
Operators precedence determines the grouping of terms in an
expression. This affects how an expression is evaluated. Certain
operators have higher precedence than the others. For example, the
multiplication operator has higher precedence than the addition
operator.
For example x = 7 + 3*2
Here, x is assigned as 13 and not 20, because operator * has higher
precedence than + . So it first gets multiplied with 3*2 and then adds
to 7.
Here in the table, operators with highest precedence appear at the top
of the table and those with the lowest appear at the bottom. Within
an expression higher precedence operator will be evaluated first.

Operator Name Operator Precedence


symbol
Parenthesis or bracket () First
Exponent (ab ) ** (a**b) Second
Multiplication and * Third
Page:13

Division /
Addition and + Fourth
Subtraction -
Consider the following example of a program to explain the
precedence of the arithmetic operators;
Problem question: obtain the value of the expression for different
values of the variables a, b, c where all are Integers.
Y=((a+b)*(a-b))**c
In this program there is one outer parenthesis (bracket) and two inner
parentheses (brackets). Therefore, first of all operations within
bracket will be performed. Then exponential operation (**) will be
performed.
For example; say a=3, b=2, c=2.
Then in the expression of Y, first within the inner brackets
operations will be done. That is (a+b) = 5 and (a-b) = 1
Then outer bracket operation will be done. That is;
(5*1)=5
And then exponential operation will be done. That is
5**2=25
The program for this expression may be written in the following
way;
Integer a, b, c, Y
Page:14

Write(*,*) ‘This program calculates the value of the


7 expression Y = ((a+b)*(a-b))**c where a , b, c are
8 integers’
Write(*,*) ‘give the values of a, b, c’
Read(*,*) a, b, c
Y=((a+b)*(a-b))**c
Write(*,*) ‘The value of Y is’, Y
Stop
End
Functions
Fortran functions are quite similar to mathematical functions: They
both take a set of input arguments (parameters) and return a value of
some type. Fortran also has some built-in functions. For example;
Abs(x) absolute value of x
Min(x) minimum value of x
Max(x) maximum value of x
Sqrt(x) square root of x
Sin(x) Sine(x) x is in radian.
Cos(x) Cosine(x) x is in radian
Tan(x) tan(x) x is in radian
Atan(x) arctangent(x) or tan inverse x., x is in radian.
Exp(x) exponential(x)
Page:15

Log(x) logarithm(x)
Int(x) integer value of x
Fix(x) Fixing the value of x
Relational Operators:
Following table shows all the relational operators supported by
Fortran. Assume a = 10 and b = 20. Both are integers. Then;
Operator Description Example
.eq. Equal to. Check if the values of two ([Link].b) is
operands are equal or not. If equal that is not true.
yes, then the condition becomes true.
.ne. Not equal to. Check if the values of two ([Link].b) is
operands are equal or not. If the values true.
are not equal then condition becomes
true.
.gt. Greater than. Check if the value of left ([Link].b) is
operand is greater than the value of right not true.
operand. If yes then condition becomes
true.
.lt. Less than. Check if the value of left ([Link].b) is
operand is less than the value of right true.
operand. If yes then condition becomes
true.
Page:16

.ge. Greater than or equal to. Check if the ([Link].b) is


value of the left operand is greater than or not true.
equal to the value of the right operand. If
yes then the condition becomes true.
.le. Less than or equal to. Check if the value ([Link].b) is
of the left operand is less than or equal to true
the value of the right operand. If yes then
the condition becomes true.

Consider an example to get a clear idea about the logical operator;

C This program checks whether the two variables a and b


C are equal or not
C If they are equal then write ‘a is equal to b’
C Else write ‘a is not equal to b’
real a,b
write(*,*) 'enter two numbers a,b'
read(*,*) a,b
if ([Link].b) then
write(*,*) 'a is equal to b'
else
Page:17

write(*,*) 'a is not equal to b'


endif
stop
end

In this program the relational operator “equal to’ (command is .eq.)


is used.
The program command is;
If ([Link].b) then
Similarly, other relational operators can be used depending on the
program.
Consider another program for more clarification on relational
operator;

C This program compares the two numbers a and b about


C which is greater.
C Write a program to read to two numbers and compare
C them. If a greater than b then write ‘a is greater than b’
C Else write ‘b is greater than a’

real a,b
Page:18

write(*,*) 'enter two numbers a,b'


read(*,*) a,b
if ([Link].b) then
write(*,*) 'a is greater than b'
else
write(*,*) 'b is greater than a'
endif
stop
end

In this program the relation operator “greater than’ (command is .gt.)


is used.
The program command is;
If ([Link].b) then
Similarly, other relational operators can be used depending on the
program.
Logical Operators:
Logical operators in Fortran work only on logical values true and
false
Assume the variable A holds .true. and variable B holds .false. then;
Show example:
Page:19

Operator Descriptions Examples


.And. Called Logical AND operator. If both ([Link].B)
the operands are non-zero, the is false
condition becomes true.
.OR. Called Logical OR operator. If any of ([Link].B) is
the two operands is non-zero, then the true
condition becomes true.
.NOT. Called Logical NOT operator. Used ([Link].B) is
to reverse the logical state of the true
operand. If a condition is true then
logical NOT operator will make false.
.EQV. Called Logical Equivalent operator ([Link].B) is
used to check equivalence of two false
logical value.
.NEQV. Called Logical Non-Equivalent ([Link].B)
operator used to check non- is true
equivalence of two logical values.
To get an idea about the logical operator consider the following;

C This program checks whether both the two real numbers


C a and b are greater than the third real number c.
Real a, b, c
Page:20

Write(*,*) ‘give three real numbers a, b, c’


Read(*,*) a, b, c
If (([Link].c).and.([Link].c)) then
Write(*,*) ‘both a and b are greater than c’
Else
Write(*,*) ‘ at least one of a & b is not greater than c’
Endif
stop
end
In this program the two relational operators ([Link].c), ([Link].c) are
connected by the logical operator ‘and’ as shown below.
If (([Link].c).and.([Link].c)) then
Proper logical operators are applied to many programs to connect
two or more relational operators.

Input / Output statement


To input a data in the program from the keyboard, we use the
command;
Read(*,*) a, b
Where a and b are numeric variables.
To write a data at the output, we have to use the command;
Write(*,*) a, b
Page:21

Here the values of a and b will be printed at the output.

Now also we may write;


Write(*,*) ‘Write two numbers’, a, b
Here, ‘write two numbers’ is string constant, which can be written
at the output using write(*,*) command.
Now both in Read(*,*) and Write(*,*) commands we use (*,*) in
the bracket. Where first * signifies the file specification number and
second * signifies the Format specification line number.
For example:
Write(1, 2) a, b
Here 1 means output file specification number and 2 means Format
specification line number.

When we use Output file specification number, it means the output


data will be saved in the output file having that particular
specification number. Input and output file specification process will
be discussed in a later section.

Format is used to write the data in a specified format. This will also
be discussed in a later section.
Page:22

Similarly, we may use the command to read the data;


Read(3, 4) a, b
Where ‘3’ is the Input file specification number. That is data is to be
taken from the specified Input file and not from the keyboard. And
‘4’ is the Format specification line number. That is in what format
data is to be read. But to do this you have to first of all create an
input file.

However when we give the command as Write(*,*) or Read(*,*) it


means open file and open format specification. That means data will
be displayed only at the computer screen and it will not be saved in
an output data file.
Similarly, data can be input only by typing at the keyboard and not
from any Input file.
Open format specification means no format specification and the
data will be displayed as usual without format.
Similarly Read(*,*) command, first * means data is to be input by
typing the keyboard. It is an open file specification. Second * means
open format specification for input of data.
Now when we give Read(3,4) command, then 3 is the input file
specification number. That is data can be input from an input file
having specification number 3.
Page:23

In this context, it must be noted that the input file is to be


generated first and connected to the program by giving
appropriate command (as discussed later).

4 is the Format specification line number that is the line where the
FORMAT command has been given by showing in what form the
data is to be input.
Opening of input and output file and link with the program will
be discussed in a later section.

Fortran Branching and Looping


Branching and Looping are important for any programming
language.
Branching is used to check whether any statement is True or False.
Consider the following example;

C Write a program to read to two numbers and compare


C them. If a greater than b then write ‘a is greater than b’
C Else write ‘b is greater than a’

real a,b
Page:24

write(*,*) 'enter two numbers a,b'


read(*,*) a,b
if ([Link].b) then
write(*,*) 'a is greater than b'
else
write(*,*) 'b is greater than a'
endif
stop
end

In this programming, branching has been created using the following


command;
If (condition or comparison command) then
Statement 1
Else
Statement 2
Endif

That is if the condition is true then program will go to the first


statement, else the program will go to the second statement.

Consider another program;

C Write a Program to Read two numbers a and b, compare


Page:25

C them. If a is equal to b then write “ a is equal to b”, If a is


C greater than b then write “ a is greater than b”, If is a is
C less than b then write
C “b is greater than a”

write(*,*) 'Enter two numbers'


read(*,*) a,b
if([Link].b)then
write(*,*) 'Both numbers are equal'
goto1
endif
if([Link].b)then
write(*,*) 'The greater number is' ,a
else
write(*,*) 'The greater number is' ,b
endif
1 stop
End
Page:26

In this program conditions are checked in two steps. In the first step,
the program is;

if([Link].b)then
write(*,*) 'Both numbers are equal'
goto1
endif

Here we checked whether a and b are equal. If they are equal then
after writing that both are equal, the program goes to the stop end by
using the command goto1 command. Where 1 is the line number of
stop command.

But if a and b are not equal, then after comparison, the program will
go directly to the endif command and there is no second statement.
When endif command is applied then it means the end of the if-
branching or if-looping.
Now in this program, after comparison of whether a and b are equal
or not, the end-if-branching stops.
Then the program again enters into the second branching;
if([Link].b)then
write(*,*) 'The greater number is' ,a
else
write(*,*) 'The greater number is' ,b
endif
Page:27

Thus; the comparison becomes complete. Using the two step


comparison, then it becomes possible to check whether a and b are
equal or a is greater than or less than b

This checking can also be done using nested branching, that is


branching within branching.

Consider following example of a program of nested branching;

C Write a Program to Read two numbers a and b, compare


C them. If a is equal to b then write “ a is equal to b”, If a is
C greater than b then write “ a is greater than b”, If a is less
C than b then write “b is greater than a”
write(*,*) 'Enter two numbers'
read(*,*) a,b
if([Link].b)then
write(*,*) 'Both numbers are equal'
goto1
else
if([Link].b)then
write(*,*) 'The greater number is' ,a
Goto 1
else
write(*,*) 'The greater number is' ,b
Goto 1
endif
endif
Page:28

1 stop
End

In this program, a second branching program is used within the first


branching program. The second branching program is the following;

if([Link].b)then
write(*,*) 'The greater number is' ,a
Goto 1
else
write(*,*) 'The greater number is' ,b
Goto 1
endif

Also notice, that in this second branching program, after the first
statement Goto 1 command is used and same is used after the second
statement.

LOOP
In any programming Looping is an important part which is used for
performing the same task multiple times.
In Fortran Programming, four types of LOOPs are most commonly
used to different program;
1. If (condition) then
Statement
Goto 1
endif
This is called If-endif loop.
Page:29

Note: When you work in a LOOP you may go out of the loop by
using jumping command GOTO line number. But you can not
enter into the Loop without checking the condition. You must
remember this thing. Otherwise; there will be Syntax error.

2. Do i=1,10
Statement
enddo
This is called do-enddo loop

3. do 1 i=1,10
Statement
1 continue
This is called do-continue loop

4. dowhile(condition)
statement
enddo
This is called dowhile loop.

We are now explaining about how these Loops work, with


appropriate programs.

Consider the following example of looping using


If (condition) then
Statement
endif
Page:30

c Calculate the sum of first 10 natural numbers using if-endif


c looping.
Integer i,j,k
k=0
i=0
1 i=i+1
If ([Link].10) then
k=k+i
goto 1
endif
write(*,*) ‘the sum of 10 natural nomber’, k
stop
end

Here the looping is used in the following command;


1 i=i+1
If ([Link].10) then
k=k+i
goto 1
endif
Unless i=10 then Looping continues and thus sum of 10 natural
numbers is calculated using if-endif Looping
Page:31

Now we will show how 10 natural numbers can be calculated


using do-enddo Loop
C Calculate the sum of first 10 natural numbers using Do-
C Enddo Loop.
Integer i, k, j
K=0
Do i= 1,10
k=k+i
enddo
write(*,*) ‘ the sum of 10 natural number is’, k
stop
end
Now we will show how 10 natural numbers can be calculated
using do-continue Loop
C Calculate the sum of first 10 natural numbers using Do-
C Enddo Loop.
Integer i, k, j
K=0
Do 1 i= 1,10
k=k+i
1 continue
write(*,*) ‘ the sum of 10 natural number is’, k
Page:32

stop
end
Now we will show how 10 natural numbers can be calculated
using dowhile(condition)-enddo Loop

C Calculate the sum of first 10 natural numbers using Do-


C Enddo Loop.
Integer i, k, j
k=0
i=0
Dowhile ([Link].10)
I=i+1
k=k+i
enddo
write(*,*) ‘ the sum of 10 natural number is’, k
stop
end

Therefore, now we can use different types of Loops considering


the suitability of the program.

Some more discussions on do-enddo Loop.


Page:33

In the do-enddo Loop when we use the command;


Do i=1,10
It means data will be counted with an interval of 1 and starting from
i=1 to i=10.

Again when we consider the command;


Do i=1, 10, 2
It means data will be counted with an interval of 2 and starting from
i=1 to i= 10.
That is data will be counted at i = 1, 3, 5, 7, 9

Again; when we consider the command;


Do i=10, 1, -1
It means data will be counted with an interval of 1 in the reverse
direction and starting from i=10 to i= 1.
That is data will be counted at i = 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

To clarify this let us consider the following program;

C write a program to show all the odd numbers upto 20.


integer i
write(*,*) 'Odd numbers from 1 to 20'
Page:34

do i= 1, 20, 2
write(*,*) i
enddo
stop
end
Similarly consider another program for step jumping;

C write a program to show all the even numbers upto 20.


integer i
write(*,*) 'even numbers upto 20'
do i=2,20,2
write(*,*) i
enddo
stop
end
Let us discuss another program to show how reverse step can be
done using do-enddo Loop.
C Write a program to show all the odd numbers upto 20 in
C reverse order.
integer i
Page:35

write(*,1) ' odd numbers upto 20 in reverse order'


do i=19,1,-2
write(*,*) i
1 format(///, a)
enddo
stop
end
Note: 1. In a program there may several loops depending on the
problem. Each loop is called a block.
2. We can enter the loop only after checking the condition. We can
not jump to anywhere in a loop from outside using jumping
command. Because each loop is an independent block and only after
checking the condition we can enter into the loop.
3. We can not use jumping command to go from one loop to another
loop.
4. But while the program is in a loop, we can use Jumping command
to go outside the loop.

Arrangement of a Program:
While writing a program using different loops, Branching,
Subroutine etc., we have to arrange the writing of the program in a
Page:36

suitable manner, so that when any other person check the program,
he / she can understand the program easily.
If a program has several loops, branching, subroutine, expression,
then these are called separate block.
Each Block should be written separately and distinctly. At the start
of a Block, we must mention the purpose of the Block. Also we have
to mark the end of that Block.
For example, while write a program on calculation of the sum of 10
natural numbers, we should write the program as follows;
C Calculate the sum of first 10 natural numbers using Do-
C Enddo Loop.
! Declaration statement
Integer i, k, j
K=0
! Loop starts for calculation of sum
Do 1 i= 1,10
k=k+i
1 continue

C Loop end for calculation of sum

C output statement
Page:37

write(*,*) ‘ the sum of 10 natural number is’, k


stop
end

Fortran Arrays or subscripted variables:


Arrays or subscripted variables can store data to a specific
location of computer memory (RAM). The stored data can later be
used for some calculations or for other purpose.
Although in general programming, single subscripted variables
and double subscripted variables are used, but Fortran allows to
create upto seven dimensional arrays.
For single array or single subscripted variables, column wise
data were specified in the memory location of the computer (RAM).
For example, consider the following program;

Integer x(5), i, j
Do i=1,5
Read(*,*) x(i)
Enddo
Stop
End
Page:38

In this program the subscripted variables x(5) have total 5 number of


subscripted variables, namely;
x(1)
x(2)
x(3)
x(4)
x(5)
These 5 memory spaces (RAM) have been subscripted to keep the
data for future use. These data can be used later as shown in the
following program;

Integer x(5), i, j
Do i=1,5
Read(*,*) x(i)
Enddo
Write(*,*) (x(i), i=1,5)
Stop
End
In this program, the command;
Write(*,*) (x(i), i=1,5)
Page:39

is used to write the values of x(i) in a single row format. The date of
x(i) are previously stored in the single array or single subscripted
positions.
If we want to write the data in a single column format then the
command is;

Do i=1,5
Write(*,*) x(i)
Enddo
This conception of writing the data either in row-wise format or in
column-wise format can be used in writing the data in a matrix
format.

Now consider some examples of using single subscripted


variables or single array in a program;

File name: sum9.f


Write an F77 program to calculate sum of the series upto N th term.
S = 1 + 3 + 5 + 7 + …….. upto N th term. Where N is given as
input.

! sum9.f
Page:40

! write an F77 program to calculate the sum of the following


! series s=1+3+5+7+9+...upto n terms n is given as input
integer n,i,t(1000),s
write(*,7) ' Program to calculate s=1+3+5+7+9+...
7 upto n terms'
write(*,1) ' Please enter the value of n'
read(*,*) n
s=0
do i=1,n
t(i)=2*i-1
s=s+t(i)
enddo
write(*,3) ' The sum is equal to',s
1 format(/,a)
3 format(/,a,i9,/)
stop
end

Consider another program of single subscripted variable;


Page:41

File name: sum11.f


Write an F77 program to calculate the sum of the following series
upto N th term.
S = 2 - 4 + 6 - 8 + 10 - ………..upto N th term where N is given as
input.
C sum11.f
C write an F77 program to calculate the sum of the following
C series s=2-4+6-8+...upto n terms, n is given as input
integer n,i,t(1000),s
write(*,1) ' Program to calculate s=2-4+6-8+...
1 upto n terms'
write(*,1) ' Please enter the value of n'
read(*,*) n
s=0
do i=1,n
t(i)=((-1)**(i+1)*2*i)
s=s+t(i)
enddo
write(*,3) ' The sum is equal to',s
1 format(/,a)
3 format(/,a,i9,/)
Page:42

stop
end
Discussion on double subscripted variables or double arrays:

Double subscripted variables are used to store the data in a matrix


format in the memory space (RAM) of the computer. Double
subscripted variables are denoted by X(5,5) where X is the variable
and it is doubly subscripted of (5,5). That is its values can be stored
as different elements of a matrix in the memory space as shown
below.
X(1,1) X(1,2) X(1,3) X(1,4) X(1,5)
X(2,1) X(2,2) X(2,3) X(2,4) X(2,5)
X(3,1) X(3,2) X(3,3) X(3,4) X(3,5)
X(4,1) X(4,2) X(4,3) X(4,4) X(4,5)
X(5,1) X(5,2) X(5,3) X(5,4) X(5,5)

Therefore the double subscripted variables X(5,5) can store 25 data


in the memory space in a 5x5 matrix format.
These data can be used later for further use.
Page:43

To get a clear idea about double subscripted variables or double


arrays let us consider some examples as follows;
Program: matrix1.f
C Write an F77 program to construct a 3X3 matrix where the
C matrix elements are given as input.
integer i,j,x(10,10)
write(*,*) ' Programme to construct a 3X3 matrix'
write(*,*) 'Enter matrix elements, 1st,2nd,3rd row'
do i=1,3
read(*,*) (x(i,j), j=1,3)
enddo
Write(*,*) ' The constructed matrix is'
do i=1,3
write(*,*) (x(i,j), j=1,3)
enddo
stop
end

In this program the data are initially stored in the double


subscripted variables and the elements occupy the memory space
Page:44

in a 3x3 matrix form. Then the elements are used to arrange in a


3x3 matrix form to display at the output.

Consider another program where double arrays or double


subscripted variables are used.

Program: matrix2.f
C Write an F77 program to construct mXn matrix where the
C matrix elements and row and column numbers are given s input.

integer i,j,x(10,10)
write(*,*) ' Programmed to construct a nXm matrix'
write(*,*) ' Enter row and column number respectively'
read(*,*) m,n
write(*,*) ' Enter the matrix elements, row by row'
do i=1,m
read(*,*) (x(i,j), j=1,n)
enddo
Write(*,*) ' The constructed matrix is'
do i=1,m
write(*,*) (x(i,j), j=1,n)
Page:45

enddo
stop
end
In this program, the number of rows and columns are assigned
first. Then data are stored in double subscripted variables.
Finally the data are arranged in a matrix form and display at
the output.

In the next program, it will be shown that how the data in single
subscripted variables can be converted to double subscripted
variables.

Program- : do8.f
C In this program it will be demonstrated that how the data
C in single subscripted variables can be converted to data in
C double subscripted variables
integer t(100),a(100,100), i
do i=1,25
t(i)=i
enddo
c single subscription to double subscription conversion
Page:46

i=1
do j=1,5
do k=1,5
a(j,k)=t(i)
i=i+1
enddo
enddo
do k=1,5
write(*,*)(a(j,k),j=1,5)
enddo
stop
end

In this program in the first step we input the data in the single
subscripted variables ;
do i=1,25
t(i)=i
enddo

Then in the second step we convert the data in single subscripted


variable to the data in double subscripted variable.
Page:47

i=1
do j=1,5
do k=1,5
a(j,k)=t(i)
i=i+1
enddo
enddo

As there are total of 25 data in single subscripted variable therefore,


we can convert the data into double subscripted variables in such a
way so that in the matrix form the total data must be exactly 25. This
can be done when we consider the double subscripted variable in the
form of 5x5 matrix.
Thus, all the 25 data can be stored in double subscripted variables in
the form of a 5x5 matrix.

Format statements
So far we have shown free format input/output. This uses a set of
default rules for how to output values of different types (integers,
reals, characters, etc.). Often the programmer wants to specify some
particular input or output format, e.g., how many decimals places in
real numbers. For this purpose, Fortran has the format statement.
Page:48

The same format statements may be used for both input and output
or in some cases different Format statements may be used.

Consider a simple program which demonstrate how the Format


statement works.
Integer k In this program, a variable k is
Read(*,*) k declared as integer. It’s value is
Write(*,7) k read without any format from
7 Format (I3) the keyboard. Then the value
Stop of k is written with Format. For
End Format of the data, the Format

command line no. is given in the write(*,7) command. In the write


command, within the first bracket, instead of second *, we specify
‘7’, which is the line number of the Format statement or Format
command.
Now in the Format statement we write
7 Format(I3)
Here the variable k is an integer and hence we write I3 where I
denotes integers and 3 denotes the number of digits that may have in
the integer variable k.
Also, you must note that the line number is to be written
between column no. 2 to column 5.
Page:49

We may also use line number as 100 or 200 etc. But it should be
written between column no. 2 to column no. 5.
Now consider another program;
Integer k,m In this program, a variable k and m
Read(*,*) k,m are declared as integers. Their
Write(*,7) k,m values are read without any format
7 Format (2I3) from the keyboard. Then the value
Stop of k and m are written with Format.
End For Format of the data, the

Format command line no. is given in the write(*,7) command. In


the write command, within the first bracket, instead of second *, we
specify ‘7’, which is the line number of the Format statement or
Format command.
Now in the Format statement we write
7 Format(2I3)
Here the variables k and m are integers and hence we write I3 where
I denotes integers and 3 denotes the number of digits that may have
in the integer variables k and m. Also 2 denotes there are two
variables k and m.
Also you must note that the line number is to be written
between column no. 2 to column 5.
Page:50

We may also use line number as 100 or 200 etc. But it should be
written between column no. 2 to column no. 5.

Consider another program where two variables k and m are


considered. One variable k is declared as Integer and another
variable m is declared as real, as shown in the program below.
Integer k The values of k and m are read
without any format from the
Real m
keyboard. Then the value of k
Read(*,*) k,m
and m are written with Format.
Write(*,7) k,m
For Format of the data, the
7 Format (I3, F6.2)
Format command line no. is
Stop
given in the write(*,7)
End

command. In the write command, within the first bracket, instead of


second *, we specify ‘7’, which is the line number of the Format
statement or Format command.
Now in the Format statement we write
7 Format(I3, F6.2)
Here the variables k is integer and m is real and hence we write I3
and the variable k, where I denotes integers and 3 denotes the
number of digits that may have in the integer variable k. Now for the
Page:51

real variable m, the format specification is F6.2. Where F denote


Float point or real number and 6 denotes the total number of digits in
the real variable, including the decimal point. And 2 denotes the
number of digits after the decimal point.

The format statement may be located anywhere within the


program unit. There are two programming styles: Either the
format statement follows directly after the read/write statement,
or all the format statements are grouped together at the end of
the (sub-) program.

Common format codes

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)

Note that :
Page:52

1. For Real variable or real constant, the Floating point Format


command is;
Format(F6.2)
Format(F8.3)
And so on.
Here F6.2 denotes the Format command for a real variable having a
total of 6 digits including decimal point. After decimal point, there
are 2 digits and before decimal point there are 3 digits.

Here F8.3 denotes the Format command for a real variable having a
total of 8 digits including decimal point. After decimal point, there
are 3 digits and before decimal point there are 4 digits.

2. For Integer variable or Integer constant, the Integer Format


command is;
Format(I4)
Format(I3)
And so on.
Here I4 denotes the Format command for a Integer variable having a
total of 4 digits. Here I3 denotes the Format command for a Integer
variable having a total of 3 digits.
Page:53

3. If a number or string does not fill up the entire field width, spaces
will be added. Usually the text will be adjusted to the right, but the
exact rules vary among the different format codes.
For example, consider the following example;
Integer a
a=23
write(*,100) a
100 Format(I6)

In this program the entire field width of the numeric integer constant
a=23 is 6. But the number of digit is 2. Therefore 4 digits are left.
Therefore, you will find four blank spaces on the right side followed
by two digits. That is after four blanks then two digit will be written
as shown below;
####23

4. For horizontal spacing, the nX code is often used. This means n


horizontal spaces. If n is omitted, n=1 is assumed.
For vertical spacing (newlines), use the code /. Each slash
corresponds to one newline. Note that each read or write statement
by default ends with a newline (here Fortran differs from C).
Page:54

Consider an example;
Real X,Y
X=2.5
Y=3.5
Write(*,7) X, Y
7 Format(5x, F3.1, 10x, F3.1)
Stop
End

Here in the program, Format command is written as;


7 Format(5x, F3.1, 10x, F3.1)
In the Format command, first we write 5x, it means five spaces are
given. Then F3.1 means the real number X should be written as such
that after decimal point there is only one digit and total number of
digit is three including the decimal point.
Then 10x means again 10 spaces followed by again F3.1 format for
the real number Y.
Therefore; in this Format statement, the two real variables X
and Y are written on a single row (or line) but using blanks
(spaces) between them.
Again; consider another example; which explains the command for
line breaking (/ command).
Page:55

Consider an example;
Real X,Y
X=2.5
Y=3.5
Write(*,7) X, Y
7 Format(/, F3.1, //, F3.1)
Stop
End

Here in the program, Format command is written as;


7 Format(/, F3.1, //, F3.1)
Here after first line breaking, the first real number X is written in the
second line and then followed by two lines breaking. Then the
second real number Y is written.
Therefore the two numbers X and Y are written in a single
column with lines breaking.

5. Now we will discuss the format syntax for string constant and
string variable.
Consider the following example;

Write(*,8) ‘We are the students’


Page:56

7 Format (a)
Stop
End

Here the Format command for string constant is;


7 Format (a)

Also instead of specifying the format code in a separate format


statement, one can give the format code in the read/write statement
directly. For example, the statement

Write (*,'(A, F8.3)') 'The answer is x = ', x

is equivalent to

Write (*,990) 'The answer is x = ', x


990 Format (A, F8.3)
Sometimes text strings are given in the format statements, e.g. the
following version is also equivalent:
Write (*,999) x
999 Format ('The answer is x = ', F8.3)

Some More Examples


Page:57

This piece of Fortran code


x = 0.025
write(*,100) 'x=', x
100 Format (A,F)

The output gives x= 0.0250000

Again consider the Fortran code;


write(*,110) 'x=', x
110 Format (A,F5.3)

The output gives, x=0.025

Consider another Format code;


write(*,120) 'x=', x
120 Format (A,E)
The output gives; x= 0.2500000E-01

Consider another Format code;


write(*,130) 'x=', x
130 Format (A,E8.1)
The output gives; x= 0.3E-01
Page:58

Note that how blanks are automatically padded on the left and that
the default field width for real numbers is usually 14. We see that
Fortran follows the rounding rule that digits 0-4 are rounded
downwards while 5-9 are rounded upwards.
In this example each write statement use a different format
statement.
But it is perfectly fine to use the same format statement for many
different write statements. In fact, this is one of the main advantages
of using format statements. This feature is handy when you print
tables for instance, and want each row to have the same format.
Some more examples of how to use the Format command;

Program- : format1.f
integer i, j, k
write(*,*)'Give three 4 digit integers '
read(*,*) i, j, k
write(*,1) i, j, k
1 Format(3i4)
stop
end
Page:59

In this program three integers I, j, k are used. Therefore Format code


is used for three integers as follows; Format(3i4)

Program- : format2.f

integer i, j, k
write(*,*)'Enter 3 4 digit integers'
read(*,*) i,j,k
write(*,2) i,j,k
2 Format(4x,i4,4x,i4,4x,i4)
stop
end
In this program Format code for three integers are given separately,
Format(4x,i4,4x,i4,4x,i4). But this Format code is not good.
Actually we may write this Format code as; Format(3(4x,i4))
That is three integers are written with the same Format code namely
(4x, i4). That is each integer is of four digits length and four spaces
are given before each number. Also all the three numbers are
written on the same line or same row.
Page:60

Now in the following program we will show how the three numbers
(Integers) can be written on the single column using the Format
statement.
Program- : format3.f
integer i,j,k
write(*,*)'enter 3 4 digit integers '
read(*,*) i,j,k
write(*,1) i,j,k
1 format(3(/,i4))
stop
end
In this program the numbers (integers) i, j, k are written in a single
column using the Format statement, format(3(/,i4))
Where / command denotes breaking of line. Therefore after writing
one number, line breaking occurs and the again second number will
be written and then again line breaking followed by the third
number.

Therefore note that when the Format statement format(3(/,i4)) is


used then three numbers are arranged in a single column and while a
Format statement format(3(4x,i4)) then the three numbers are
arranged in a single row or single horizontal line.
Page:61

Therefore; using these two Format statements


simultaneously we can arrange the data in a matrix format at
the output.
To explain this, consider the following program;
c Program- : mat1.f
c This program arranges six data in a 2x3 matrix and show at
c the output
real x(6), i
write(*,*)'Give 6 real numbers to print in 2X3 mat'
do i=1,6
read(*,*) x(i)
enddo
write(*,7) (x(i), i=1,6)
7 format (2(2x,3f8.3,/))
stop
end

In this program first of all six data are read from keyboard using the
command;
do i=1,6
read(*,*) x(i)
Page:62

enddo
Then six data arranged and displayied at the output using the
command;
write(*,7) (x(i), i=1,6)
7 format (2(2x,3f8.3,/))

In this respect you must note that if we do not use the format
statement, then all the six data are arranged in a single row or single
line, because we use the command, (x(i), i=1,6) in the write
statement. This is the command for arrangement of data in a single
line.
But here we also use the Format statement as;
7 format (2(2x,3f8.3,/))
It states that first use 2 spaces (2x) and then print three real numbers
(3f8.3) on a single line and then one line breaking (/) to go to the
next line. Then again 2 spaces followed by the printing of three real
numbers in the second line.
Therefore; using this Format statement, the six numbers are
displayed in a 2x3 matrix at the output.
This is the technique for arrangement of single subscripted
variables in a matrix format.
We can also arrange double subscripted variables in matrix
format at the output. Consider the following program;
Page:63

Program: matrix1.f

C This is a program to take six data from the keyboard and


C store them in double subscripted variables and then
C arrange the six data in a 2x3 matrix at the output.

integer i,j,x(10,10)
write(*,*) ' Programmed to construct a 2X3 matrix'
write(*,*) ' Enter matrix elements, 1st,2nd,3rd row'
do i=1,2
read(*,*) (x(i,j), j=1,3)
enddo
Write(*,*) ' The constructed matrix is'
do i=1,2
write(*,7) (x(i,j), j=1,3)
7 Format(2x,3I3)
enddo
stop
end
In this programming first we consider an integer double subscripted
variables x(10,10). In this x(10,10) double subscripted variables we
Page:64

can store 10x10 = 100 data. Therefore now we can deal with the
number of data which is less than or equal to 100. But if the number
of data becomes greater than 100 then there will be syntax error.
In this program we use only six data therefore there is no problem to
use x(10,10) double subscipted variables. Offcourse we may also use
x(2,3) double subscripted variables.
Now in the next step, we read the data from the keyboard using the
program command;
do i=1,2
read(*,*) (x(i,j), j=1,3)
enddo
Here the six data are stored double subscripted variable x(i,j) in the
memory space (RAM) of the computer as shown below;
x(1,1) x(1,2) x(1,3)
x(2,1) x(2,2) x(2,3)
These six data can be arranged in a 2x3 matrix at the output as
shown in the following command;
do i=1,2
write(*,7) (x(i,j), j=1,3)
7 Format(2x,3I3)
enddo
Page:65

Here in the Format statement we use 3I3 that is three numbers


(integers) are arranged in a single line (or row). Then program will
bring the next three numbers to the next line.

Now we discuss some more programs where Format staments are


used in different manners.
Program- : format4.f
real a,b,c
write(*,*) 'Give three real numbers'
read(*,*) a,b,c
write(*,1) a,b,c
1 format(3(2x,f8.3))
stop
end
In this program the three real numbers a, b, c are arranged in a single
line (or single row) format following the Format command;
format(3(2x,f8.3))

Consider another program;


Program- : format5.f
real a,b,c
Page:66

write(*,*) 'Enter three real numbers'


read(*,*) a, b, c
write(*,1) a, b, c
1 format(3(/, f8.3))
stop
end
In this program the three real numbers a, b, c are arranged in a single
column (or single vertical line) format following the Format
command;
format(3(/, f8.3))
The command ‘/’ indicates line breaking.

Consider another program where Format statement is used for string


constant as well as numeric variables.
Program- : format6.f
real d,b,c
write(*,*) 'Give three real numbers in the form
7 ****.*** '
read(*,*) d,b,c
write(*,1) 'You entered the following numbers',d,b,c
1 Format(a,3(2x,f8.3))
Page:67

stop
end
In this program, in the Format statement
Format(a,3(2x,f8.3))
Both string constant (a) and numeric variables (f8.3)are used.

Fortran File manipulation: Input and Output Files


So far as we discuss how the data can be given as input using the
keyboard. Where we use the open file specification that is * as
shown below; Read(*,*)
The first * within bracket denotes that open file specification. That is
there is no input file from where data can be read.
But sometimes it is important to read data from an input file for
various types of calculation and for data analysis.
In Fortran programming, read data from an input file is an important
part. To read data from an input file, we give the command as
Read(1,*) where 1 is the input file specification number. This
command allows you to read data from an input file.
Also you must note that first of all you have to create a suitable input
file with suitable name (say [Link]) and keep it in a proper directory.
Also the data in the input file must be arranged properly. The data in
Page:68

the input file may be arranged in column wise or row wise or matrix
wise format or even the data may be kept in haphazard or random
manner.
Depending on the data arrangement, the data read command should
be written accordingly. That we will discuss soon.

Also in the program the processed data can also be stored in a


suitable output data file (say [Link]).
Also note that we need not have to create the output data file
initially. As you run the program with suitable command, the output
data file be automatically created and processed data will be stored
in the output file.
We can read data from one or more input file by using suitable
command and also we can write the processed data to one or more
output files using the suitable command.
But first of all we have to open the input file and output file by using
the command.

Open (unit=1, file = ‘[Link]’)


Open (unit=2, file = ‘[Link]’)
Page:69

Here 1 and 2 specify the file number of [Link] and [Link]


respectively.
Also it is that no two files should be given the same number. That is
for each file, file number (unit=1 or unit=2) should be specified.

Note.
1. The output file namely the [Link] need not have to be created
first. It is automatically created when the program is executed.

2. While running a program, [Link] file must be created first and


kept in the concerned directory where the program is executed.

Now let us consider the following example to understand how data


can be saved in a output data file
For output file see the example;
----------------------------------------------------------
Real a, b, c
Open (unit=1, file= ‘[Link]’)
Write(*,*) ‘Give two numbers’
Read(*,*) a, b
C = a+b
Write(1,*) ‘The sum is’ , c
Page:70

Stop
End
-------------------------------------------------------------------------------

In this program the processed data is saved in the output file using
the command; Write(1,*) ‘The sum is’ , c
Where 1 is the output file specification number as mentioned when
the output data file is open to connected to the programme.

Note.3: For Input file, data structure should match with the
program.
There are four types of data structure in the input file. Row-
wise, Column-wise, matrix-wise and random or haphazard
arrangement of data as shown in the figure.
Row-wise data format of input file:
File name: [Link]
1, 2, 3, 4, 5,
This is the row-wise data format.

Column-wise data format of input file:


File name: [Link]
Page:71

1
2
3
4
5
This is the column-wise data format.

Matrix-wise data format of input file:


File name: [Link]

1 2 3 4
5 6 7 8
9 10 11 12
This is the matrix-wise data format.

Random or haphazard arrangement of data format of input file:


1,2,3,4,5,6
4,5,6,7,8,9,10,11,12,13
7,6,5,4,3,2,1
This is the random data arrangement.
Page:72

Now for row-wise data format, to take the data from the input file,
the program should be written as follows:
-----------------------------------------------------------------------------
Integer x(10), y
Open (unit=1, file = ‘[Link]’)
Read(1,*) (x(i), i = 1,5)
Y=0
do i = 1,5
y = y+x(i)
enddo
write(*,*) ‘sum of numbers=’, y
stop
end
----------------------------------------------------------------------------
When the data in the input file are arrangement in a rowwise format,
then read command should be as follows;
Read(1,*) (x(i), i = 1,5)
Where (x(i), i=1,5) denotes that data are read along a single line or
row-wise from input file. The input file specification number is 1.
Now for column-wise data format, to take the data from the input
file, the program should be written as follows:
----------------------------------------------------------------------------
Page:73

Integer x(10), y
Open (unit=2, file = ‘[Link]’)
do i = 1, 5
Read(2,*) x(i)
enddo
y=0
do i = 1,5
y = y+x(i)
enddo
write(*,*) ‘sum of numbers=’, y
stop
end
----------------------------------------------------------------------------
When data in the input file are arrangement in a column-wise
format, then read command should be as follows;
do i = 1, 5
Read(2,*) x(i)
enddo
The statement denotes that data are read along a single column or
vertical line from the input file. The input file specification number
is 2.
Page:74

Now for matrix-wise data format, we have to use double arrays or


double subscription to take the data from the input file, the program
should be written as follows:
----------------------------------------------------------------------------
Integer x(10, 10), y
open (unit=3, file = ‘[Link]’)
open (unit = 4, file = ‘[Link]’)
do i = 1, 5
read(3,*) (x(i,j), j=1,5)
enddo
do i = 1,5
write(4,*) (x(i,j), j = 1, 5)
enddo
stop
end
----------------------------------------------------------------------------
When the data in the input file are arrangement in a matrix format,
then read command should be as follows;
do i = 1, 5
read(3,*) (x(i,j), j=1,5)
enddo
The statement denotes that data are read along row-wise and and
after completion of a single row, the data will be read from the
second row and so on. Thus data will be read from the input file
where the data are arranged matrix-wise.
Page:75

In this program we also save the data in a matrix format in an output


data file.

Now for random or haphazard data format, as shown below;


1,2,3,4,5,6
4,5,6,7,8,9,10,11,12,13
7,6,5,4,3,2,1
First of all you have to notice that the data are to be separated
by comma (,) and there should not be any comma after the last
data of a line.
The from the input file data can be read by using the following
command;
do i = 1, 5
read(3,*) (x(i,j), j=1,5)
enddo

That is the data can be read in a row-wise format. Also note that
instead of j=1,5 we may also use any number as j=1,10 or j=1,20 etc.
but remember that in the input file, there must be sufficient number
of data otherwise there will be syntax error.

You might also like