You are on page 1of 20

Fortran Programming

Steps during compilation and execution

Who decides what Fortran is?


Standards are defined by a committee
(http://www.j3-fortran.org/)

Compilers are written


Commercial: e.g. Intel (ifort), many others
Non-commercial: g95, gfortran

May also have coding guidelines/standards

Standards
Fortran IV (1966)
Fortran 77 (old but popular version)
Fortran 90 (major revision to F77)
Fortran 95 (minor revision to F90)
Fortran 2003 (current standard)

Fortran 2008 (will be next standard)

Compilers
Some behaviour is compiler dependent (not
specified in standard) e.g.
Flags
Values of un-initialised variables
Warnings

Fortran 90 vs. Fortran 77


Fortran 90 was a major revision to Fortran 77
Fortran 77 is a complete sub-set of Fortran 90
F90 introduced major new features
Also introduced many useful minor features which
can be gradually introduced

How to connect to server using


putty

Basic options for putty

PuTTY Configuration

Login to server

Server connection

Changing directory

Locating your directory

Moving into your directory

Compilng and running a program


export MANPATH="/opt/intel/man
PATH=/opt/intel/bin:$PATH
ifort filename.for o f

Welcome

program welcome
write(*,*) "Welcome to IIT Gandhinagar for FEM short course"
end

Arithmetic- addition 1
program addition
real a,b,c
! declaration
write(*,*) 'enter first number'
READ*, a
write(*,*) 'enter second number'
READ*, b
c=a+b
write(*,*) 'Sum of two number is', c
end

Arithmetic- addition 2
program addition
real a,b,c
! declaration
open(unit=10,file='./input.txt',form='formatted')
read(10,*) a
read(10,*) b
c=a+b
write(*,*) c
open(unit=11,file='./output.txt')
write(11,*) c
close(11)
end
Input file
5
10

!value of a
!value of b

output file
15.00000

Array
program addition
real c
! declaration
write(*,*) 'enter one number'
read*, c
do i= 1,c
write(*,*) i
enddo
end

Formatting

102

program addition
real c
! declaration
do i= 1,10
c=i+1
write(*,102) c
format(1x,3f15.3)
enddo
end

You might also like