Fortran

Install gfortran in Ubuntu Linux :

Linux’s distributions are confusing and charming, Ubuntu and Debian are handy here but you could use kali, Redhat, mint, Scientific distributions either. In Linux we do almost everything with terminals or shells. First we need to be root by typing :
sudo -i
and there it will be necessary to enter root password. then update apt if it’s satisfy you and type :
sudo apt-get install gfortran
this code will install latest stable and trustable version of gfortran. We could check installed version by :
apt-cache policy gfortran
or
gfortran –version
or
dpkg -l | grep Fortran
if versions were different, don’t worry, we prefer apt-cache!


We could install python by (note : version 2 & 3 are different) :
sudo apt-get install python3
if versions were different, don’t worry, we prefer apt-cache!
We could install python by (note : version 2 & 3 are different) :
sudo apt-get install python3

Try gfortran (code 1 : Fibonacci series)

By simple right click in directory (simply Folder) and clicking on “Open in Terminal” or going to directory with “cd ~/Desktop/YourFolderName” from terminal, terminal gets into right directory!
Here we type:
nano
and we put our program here! by pressing “CTRL+X” we could exit and save file by typing “Y” then give a name like Fibo1.f90 or fibo1.py, etc. Here we use “*.f90” format for FORTRAN codes. Fibo1.f90 code is :

Program Fibonacci1
implicit none
integer a,b
a=0;b=1
print *,a
print *,b
do while (b .lt.5000)
	a=a+b	
	print *,a
	b=a+b
	print *,b
end do
end Program Fibonacci1

note : .lt. means lower than.
or we could use third variable instead of two “print” function in “do while” loop like below (Fibo2.f90) :

Program Fibonacci2
implicit none
integer a,b,c
c=0;a=0;b=1
print *,a
print *,b
do while (b .lt.5000)
	c=a+b	
	print *,c
	a=b
	b=c
end do
end Program Fibonacci2

now we have our code in text and we need to compile it by terminal code:
gfortran -o output1 Fibo1.f90
output file’s name is “output1″ and input file to compile is ” Fibo1.f90″, after this in directory we have output file and by typing it’s name in terminal it will run, here in this example we type :
./output1

Share this Page